From 0965859dec1e059f3e0c8d88c1c1ef8e742717f5 Mon Sep 17 00:00:00 2001 From: vijeyash Date: Tue, 21 Nov 2023 15:33:22 +0530 Subject: [PATCH 1/3] pvc changes --- agent/kubviz/kubePreUpgrade.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agent/kubviz/kubePreUpgrade.go b/agent/kubviz/kubePreUpgrade.go index 11ec310f..20da065f 100644 --- a/agent/kubviz/kubePreUpgrade.go +++ b/agent/kubviz/kubePreUpgrade.go @@ -81,7 +81,7 @@ func publishK8sDepricated_Deleted_Api(result *model.Result, js nats.JetStreamCon func KubePreUpgradeDetector(config *rest.Config, js nats.JetStreamContext) error { pvcMountPath := "/mnt/agent/kbz" uniqueDir := fmt.Sprintf("%s/kubepug", pvcMountPath) - err := os.Mkdir(uniqueDir, 0755) + err := os.MkdirAll(uniqueDir, 0755) if err != nil { return err } From 030407fd4362494319d87e2eaafc6b0791281e08 Mon Sep 17 00:00:00 2001 From: vijeyash Date: Tue, 28 Nov 2023 16:42:09 +0530 Subject: [PATCH 2/3] changed image to get shell access --- dockerfiles/client/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dockerfiles/client/Dockerfile b/dockerfiles/client/Dockerfile index 31af58c8..fd9f5b18 100644 --- a/dockerfiles/client/Dockerfile +++ b/dockerfiles/client/Dockerfile @@ -11,7 +11,7 @@ RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o k8smetri # Use distroless as minimal base image to package the manager binary # Refer to https://github.com/GoogleContainerTools/distroless for more details -FROM gcr.io/distroless/static:nonroot +FROM golang:alpine WORKDIR / COPY --from=builder /workspace/k8smetrics_client . USER 65532:65532 From 318eadb249c79bdb46e13a003f86ebf5ac4af26a Mon Sep 17 00:00:00 2001 From: an1l4 <1995anila@gmail.com> Date: Tue, 5 Dec 2023 14:24:13 +0530 Subject: [PATCH 3/3] error-handle-changes-added --- client/pkg/clickhouse/db_client.go | 90 ++++++++++-------------------- 1 file changed, 30 insertions(+), 60 deletions(-) diff --git a/client/pkg/clickhouse/db_client.go b/client/pkg/clickhouse/db_client.go index 011fc0ff..82fd4359 100644 --- a/client/pkg/clickhouse/db_client.go +++ b/client/pkg/clickhouse/db_client.go @@ -136,14 +136,12 @@ func (c *DBClient) InsertContainerEventAzure(pushEvent model.AzureContainerPushE tx, err := c.conn.Begin() if err != nil { - log.Printf("error beginning transaction: %v", err) - return + log.Fatalf("error beginning transaction, clickhouse connection not available: %v", err) } stmt, err := tx.Prepare(string(InsertAzureContainerPushEvent)) if err != nil { - log.Printf("error preparing statement: %v", err) - return + log.Fatalf("error preparing statement: %v", err) } defer stmt.Close() @@ -187,14 +185,12 @@ func (c *DBClient) InsertContainerEventAzure(pushEvent model.AzureContainerPushE func (c *DBClient) InsertContainerEventQuay(pushEvent model.QuayImagePushPayload) { tx, err := c.conn.Begin() if err != nil { - log.Printf("error beginning transaction: %v", err) - return + log.Fatalf("error beginning transaction, clickhouse connection not available: %v", err) } stmt, err := tx.Prepare(string(InsertQuayContainerPushEvent)) if err != nil { - log.Printf("error preparing statement: %v", err) - return + log.Fatalf("error preparing statement: %v", err) } defer stmt.Close() @@ -240,14 +236,12 @@ func (c *DBClient) InsertContainerEventQuay(pushEvent model.QuayImagePushPayload func (c *DBClient) InsertContainerEventJfrog(pushEvent model.JfrogContainerPushEventPayload) { tx, err := c.conn.Begin() if err != nil { - log.Printf("error beginning transaction: %v", err) - return + log.Fatalf("error beginning transaction, clickhouse connection not available: %v", err) } stmt, err := tx.Prepare(string(InsertJfrogContainerPushEvent)) if err != nil { - log.Printf("error preparing statement: %v", err) - return + log.Fatalf("error preparing statement: %v", err) } defer stmt.Close() @@ -293,13 +287,11 @@ func (c *DBClient) InsertContainerEventJfrog(pushEvent model.JfrogContainerPushE func (c *DBClient) InsertRakeesMetrics(metrics model.RakeesMetrics) { tx, err := c.conn.Begin() if err != nil { - log.Printf("error beginning transaction: %v", err) - return + log.Fatalf("error beginning transaction, clickhouse connection not available: %v", err) } stmt, err := tx.Prepare(string(InsertRakees)) if err != nil { - log.Printf("error preparing statement: %v", err) - return + log.Fatalf("error preparing statement: %v", err) } defer stmt.Close() @@ -325,13 +317,11 @@ func (c *DBClient) InsertRakeesMetrics(metrics model.RakeesMetrics) { func (c *DBClient) InsertKetallEvent(metrics model.Resource) { tx, err := c.conn.Begin() if err != nil { - log.Printf("error beginning transaction: %v", err) - return + log.Fatalf("error beginning transaction, clickhouse connection not available: %v", err) } stmt, err := tx.Prepare(string(InsertKetall)) if err != nil { - log.Printf("error preparing statement: %v", err) - return + log.Fatalf("error preparing statement: %v", err) } defer stmt.Close() @@ -356,13 +346,11 @@ func (c *DBClient) InsertKetallEvent(metrics model.Resource) { func (c *DBClient) InsertOutdatedEvent(metrics model.CheckResultfinal) { tx, err := c.conn.Begin() if err != nil { - log.Printf("error beginning transaction: %v", err) - return + log.Fatalf("error beginning transaction, clickhouse connection not available: %v", err) } stmt, err := tx.Prepare(string(InsertOutdated)) if err != nil { - log.Printf("error preparing statement: %v", err) - return + log.Fatalf("error preparing statement: %v", err) } defer stmt.Close() @@ -389,13 +377,11 @@ func (c *DBClient) InsertOutdatedEvent(metrics model.CheckResultfinal) { func (c *DBClient) InsertDeprecatedAPI(deprecatedAPI model.DeprecatedAPI) { tx, err := c.conn.Begin() if err != nil { - log.Printf("error beginning transaction: %v", err) - return + log.Fatalf("error beginning transaction, clickhouse connection not available: %v", err) } stmt, err := tx.Prepare(string(InsertDepricatedApi)) if err != nil { - log.Printf("error preparing statement: %v", err) - return + log.Fatalf("error preparing statement: %v", err) } defer stmt.Close() @@ -429,13 +415,11 @@ func (c *DBClient) InsertDeprecatedAPI(deprecatedAPI model.DeprecatedAPI) { func (c *DBClient) InsertDeletedAPI(deletedAPI model.DeletedAPI) { tx, err := c.conn.Begin() if err != nil { - log.Printf("error beginning transaction: %v", err) - return + log.Fatalf("error beginning transaction, clickhouse connection not available: %v", err) } stmt, err := tx.Prepare(string(InsertDeletedApi)) if err != nil { - log.Printf("error preparing statement: %v", err) - return + log.Fatalf("error preparing statement: %v", err) } defer stmt.Close() @@ -470,13 +454,11 @@ func (c *DBClient) InsertDeletedAPI(deletedAPI model.DeletedAPI) { func (c *DBClient) InsertKubvizEvent(metrics model.Metrics) { tx, err := c.conn.Begin() if err != nil { - log.Printf("error beginning transaction: %v", err) - return + log.Fatalf("error beginning transaction, clickhouse connection not available: %v", err) } stmt, err := tx.Prepare(string(InsertKubvizEvent)) if err != nil { - log.Printf("error preparing statement: %v", err) - return + log.Fatalf("error preparing statement: %v", err) } defer stmt.Close() @@ -539,13 +521,11 @@ func (c *DBClient) InsertContainerEvent(event string) { func (c *DBClient) InsertKubeScoreMetrics(metrics model.KubeScoreRecommendations) { tx, err := c.conn.Begin() if err != nil { - log.Printf("error beginning transaction: %v", err) - return + log.Fatalf("error beginning transaction, clickhouse connection not available: %v", err) } stmt, err := tx.Prepare(InsertKubeScore) if err != nil { - log.Printf("error preparing statement: %v", err) - return + log.Fatalf("error preparing statement: %v", err) } defer stmt.Close() @@ -571,13 +551,11 @@ func (c *DBClient) InsertTrivyMetrics(metrics model.Trivy) { for _, vulnerability := range result.Vulnerabilities { tx, err := c.conn.Begin() if err != nil { - log.Printf("error beginning transaction: %v", err) - return + log.Fatalf("error beginning transaction, clickhouse connection not available: %v", err) } stmt, err := tx.Prepare(InsertTrivyVul) if err != nil { - log.Printf("error preparing statement: %v", err) - return + log.Fatalf("error preparing statement: %v", err) } if _, err := stmt.Exec( metrics.ID, @@ -608,13 +586,11 @@ func (c *DBClient) InsertTrivyMetrics(metrics model.Trivy) { for _, misconfiguration := range result.Misconfigurations { tx, err := c.conn.Begin() if err != nil { - log.Printf("error beginning transaction: %v", err) - return + log.Fatalf("error beginning transaction, clickhouse connection not available: %v", err) } stmt, err := tx.Prepare(InsertTrivyMisconfig) if err != nil { - log.Printf("error preparing statement: %v", err) - return + log.Fatalf("error preparing statement: %v", err) } defer stmt.Close() @@ -654,13 +630,11 @@ func (c *DBClient) InsertTrivyImageMetrics(metrics model.TrivyImage) { for _, vulnerability := range result.Vulnerabilities { tx, err := c.conn.Begin() if err != nil { - log.Printf("error beginning transaction: %v", err) - return + log.Fatalf("error beginning transaction, clickhouse connection not available: %v", err) } stmt, err := tx.Prepare(InsertTrivyImage) if err != nil { - log.Printf("error preparing statement: %v", err) - return + log.Fatalf("error preparing statement: %v", err) } if _, err := stmt.Exec( @@ -700,13 +674,11 @@ func (c *DBClient) InsertTrivySbomMetrics(metrics model.Sbom) { if result.CycloneDX != nil { tx, err := c.conn.Begin() if err != nil { - log.Printf("error beginning transaction: %v", err) - return + log.Fatalf("error beginning transaction, clickhouse connection not available: %v", err) } stmt, err := tx.Prepare(InsertTrivySbom) if err != nil { - log.Printf("error preparing statement: %v", err) - return + log.Fatalf("error preparing statement: %v", err) } if _, err := stmt.Exec( @@ -834,14 +806,12 @@ func (c *DBClient) RetrieveKubvizEvent() ([]model.DbEvent, error) { func (c *DBClient) InsertContainerEventDockerHub(build model.DockerHubBuild) { tx, err := c.conn.Begin() if err != nil { - log.Printf("error beginning transaction: %v", err) - return + log.Fatalf("error beginning transaction, clickhouse connection not available: %v", err) } stmt, err := tx.Prepare(string(InsertDockerHubBuild)) if err != nil { - log.Printf("error preparing statement: %v", err) - return + log.Fatalf("error preparing statement: %v", err) } defer stmt.Close()