Skip to content

Commit

Permalink
conflict fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
an1l4 committed Dec 13, 2023
2 parents e64b0c5 + f8691fa commit 54c6eb3
Show file tree
Hide file tree
Showing 34 changed files with 203 additions and 1,656 deletions.
16 changes: 9 additions & 7 deletions agent/kubviz/kubePreUpgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,25 +83,27 @@ func publishK8sDepricated_Deleted_Api(result *model.Result, js nats.JetStreamCon

func KubePreUpgradeDetector(config *rest.Config, js nats.JetStreamContext) error {

ctx:=context.Background()
ctx := context.Background()
tracer := otel.Tracer("kubepreupgrade")
_, span := tracer.Start(opentelemetry.BuildContext(ctx), "KubePreUpgradeDetector")
span.SetAttributes(attribute.String("kubepug-plugin", "kubepug-output"))
defer span.End()

swaggerdir, err := os.MkdirTemp("", "kubepug")

pvcMountPath := "/mnt/agent/kbz"
uniqueDir := fmt.Sprintf("%s/kubepug", pvcMountPath)
err := os.MkdirAll(uniqueDir, 0755)

if err != nil {
return err
}
filename := fmt.Sprintf("%s/swagger-%s.json", swaggerdir, k8sVersion)
filename := fmt.Sprintf("%s/swagger-%s.json", uniqueDir, k8sVersion)
url := fmt.Sprintf("%s/%s/%s", baseURL, k8sVersion, fileURL)
err = downloadFile(filename, url)
if err != nil {
return err
}
defer os.RemoveAll(swaggerdir)
swaggerfile := filename
kubernetesAPIs, err := PopulateKubeAPIMap(swaggerfile)
defer os.RemoveAll(filename)
kubernetesAPIs, err := PopulateKubeAPIMap(filename)
if err != nil {
return err
}
Expand Down
18 changes: 14 additions & 4 deletions agent/kubviz/trivy.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"bytes"
"context"
"encoding/json"
"fmt"
"log"
"os"
exec "os/exec"
"strings"

Expand All @@ -20,7 +22,7 @@ import (

func executeCommandTrivy(command string) ([]byte, error) {

ctx:=context.Background()
ctx := context.Background()
tracer := otel.Tracer("trivy-cluster")
_, span := tracer.Start(opentelemetry.BuildContext(ctx), "executeCommandTrivy")
span.SetAttributes(attribute.String("trivy-k8s", "command-running"))
Expand All @@ -40,16 +42,24 @@ func executeCommandTrivy(command string) ([]byte, error) {
return outc.Bytes(), err
}
func RunTrivyK8sClusterScan(js nats.JetStreamContext) error {

var report report.ConsolidatedReport

ctx:=context.Background()
ctx := context.Background()
tracer := otel.Tracer("trivy-cluster")
_, span := tracer.Start(opentelemetry.BuildContext(ctx), "RunTrivyK8sClusterScan")
span.SetAttributes(attribute.String("cluster-name", report.ClusterName))
defer span.End()

cmdString := "trivy k8s --report summary cluster --exclude-nodes kubernetes.io/arch:amd64 --timeout 60m -f json --cache-dir /tmp/.cache --debug"
pvcMountPath := "/mnt/agent/kbz"
trivyCacheDir := fmt.Sprintf("%s/trivy-cache", pvcMountPath)
err := os.MkdirAll(trivyCacheDir, 0755)
if err != nil {
log.Printf("Error creating Trivy cache directory: %v\n", err)
return err
}
cmdString := fmt.Sprintf("trivy k8s --report summary cluster --exclude-nodes kubernetes.io/arch:amd64 --timeout 60m -f json --cache-dir %s --debug", trivyCacheDir)

clearCacheCmd := "trivy k8s --clear-cache"
out, err := executeCommandTrivy(cmdString)
if err != nil {
Expand Down
20 changes: 10 additions & 10 deletions agent/kubviz/trivy_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"context"
"encoding/json"
"fmt"
"log"
"os"
"strings"
Expand All @@ -19,6 +20,13 @@ import (
)

func RunTrivyImageScans(config *rest.Config, js nats.JetStreamContext) error {
pvcMountPath := "/mnt/agent/kbz"
trivyImageCacheDir := fmt.Sprintf("%s/trivy-imagecache", pvcMountPath)
err := os.MkdirAll(trivyImageCacheDir, 0755)
if err != nil {
log.Printf("Error creating Trivy Image cache directory: %v\n", err)
return err
}
clearCacheCmd := "trivy image --clear-cache"

ctx:=context.Background()
Expand All @@ -35,7 +43,8 @@ func RunTrivyImageScans(config *rest.Config, js nats.JetStreamContext) error {

for _, image := range images {
var report types.Report
out, err := executeCommand("trivy image " + image.PullableImage + " --timeout 60m -f json -q --cache-dir /tmp/.cache")
scanCmd := fmt.Sprintf("trivy image %s --timeout 60m -f json -q --cache-dir %s", image.PullableImage, trivyImageCacheDir)
out, err := executeCommand(scanCmd)
if err != nil {
log.Printf("Error scanning image %s: %v", image.PullableImage, err)
continue // Move on to the next image in case of an error
Expand Down Expand Up @@ -84,12 +93,3 @@ func publishImageScanReports(report types.Report, js nats.JetStreamContext) erro
log.Printf("Trivy image report with ID:%s has been published\n", metrics.ID)
return nil
}

func cleanupCache(cacheDir string) {
err := os.RemoveAll(cacheDir)
if err != nil {
log.Printf("Failed to clean up cache directory %s: %v", cacheDir, err)
} else {
log.Printf("Cache directory %s cleaned up successfully", cacheDir)
}
}
12 changes: 10 additions & 2 deletions agent/kubviz/trivy_sbom.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/json"
"fmt"
"log"
"os"
"os/exec"

"github.com/aquasecurity/trivy/pkg/sbom/cyclonedx"
Expand Down Expand Up @@ -57,6 +58,13 @@ func executeCommandSbom(command string) ([]byte, error) {
}

func RunTrivySbomScan(config *rest.Config, js nats.JetStreamContext) error {
pvcMountPath := "/mnt/agent/kbz"
trivySbomCacheDir := fmt.Sprintf("%s/trivy-sbomcache", pvcMountPath)
err := os.MkdirAll(trivySbomCacheDir, 0755)
if err != nil {
log.Printf("Error creating Trivy cache directory: %v\n", err)
return err
}
clearCacheCmd := "trivy image --clear-cache"

log.Println("trivy sbom run started")
Expand All @@ -74,8 +82,8 @@ func RunTrivySbomScan(config *rest.Config, js nats.JetStreamContext) error {
}
for _, image := range images {

command := fmt.Sprintf("trivy image --format cyclonedx %s %s", image.PullableImage, "--cache-dir /tmp/.cache")
out, err := executeCommandSbom(command)
sbomcmd := fmt.Sprintf("trivy image --format cyclonedx %s --cache-dir %s", image.PullableImage, trivySbomCacheDir)
out, err := executeCommandSbom(sbomcmd)

if err != nil {
log.Printf("Error executing Trivy for image sbom %s: %v", image.PullableImage, err)
Expand Down
2 changes: 1 addition & 1 deletion charts/agent/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 1.1.7
version: 1.1.8

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand Down
60 changes: 57 additions & 3 deletions charts/agent/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,24 @@ spec:
value: "{{ .Values.schedule.kubepreupgradeInterval }}"
- name: TRIVY_INTERVAL
value: "{{ .Values.schedule.trivyInterval }}"
{{- if .Values.persistence.enabled }}
volumeMounts:
- name: data
mountPath: {{ .Values.persistence.mountPath }}
{{- end }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
limits:
cpu: {{ .Values.resources.limits.cpu }}
memory: {{ .Values.resources.limits.memory }}
{{- if not .Values.persistence.enabled }}
ephemeral-storage: {{ .Values.resources.limits.ephemeralstorage }}
{{- end }}
requests:
cpu: {{ .Values.resources.requests.cpu }}
memory: {{ .Values.resources.requests.memory }}
{{- if not .Values.persistence.enabled }}
ephemeral-storage: {{ .Values.resources.requests.ephemeralstorage }}
{{- end }}
{{- if .Values.git_bridge.enabled }}
- name: git-bridge
image: "{{ .Values.git_bridge.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
Expand All @@ -99,8 +115,24 @@ spec:
{{- end }}
- name: NATS_ADDRESS
value: {{ .Values.nats.host }}
{{- if .Values.git_bridge.persistence.enabled }}
volumeMounts:
- name: data
mountPath: {{ .Values.git_bridge.persistence.mountPath }}
{{- end }}
resources:
{{- toYaml .Values.git_bridge.resources | nindent 12 }}
limits:
cpu: {{ .Values.git_bridge.resources.limits.cpu }}
memory: {{ .Values.git_bridge.resources.limits.memory }}
{{- if not .Values.git_bridge.persistence.enabled }}
ephemeral-storage: {{ .Values.git_bridge.resources.limits.ephemeralstorage }}
{{- end }}
requests:
cpu: {{ .Values.git_bridge.resources.requests.cpu }}
memory: {{ .Values.git_bridge.resources.requests.memory }}
{{- if not .Values.git_bridge.persistence.enabled }}
ephemeral-storage: {{ .Values.git_bridge.resources.requests.ephemeralstorage }}
{{- end }}
{{- end }}
{{- if .Values.container_bridge.enabled }}
- name: container-bridge
Expand All @@ -124,9 +156,31 @@ spec:
{{- end }}
- name: NATS_ADDRESS
value: {{ .Values.nats.host }}
{{- if .Values.container_bridge.persistence.enabled }}
volumeMounts:
- name: data
mountPath: {{ .Values.container_bridge.persistence.mountPath }}
{{- end }}
resources:
{{- toYaml .Values.container_bridge.resources | nindent 12 }}
limits:
cpu: {{ .Values.container_bridge.resources.limits.cpu }}
memory: {{ .Values.container_bridge.resources.limits.memory }}
{{- if not .Values.container_bridge.persistence.enabled }}
ephemeral-storage: {{ .Values.container_bridge.resources.limits.ephemeralstorage }}
{{- end }}
requests:
cpu: {{ .Values.container_bridge.resources.requests.cpu }}
memory: {{ .Values.container_bridge.resources.requests.memory }}
{{- if not .Values.container_bridge.persistence.enabled }}
ephemeral-storage: {{ .Values.container_bridge.resources.requests.ephemeralstorage }}
{{- end }}
{{- end }}
{{- if .Values.persistence.enabled }}
volumes:
- name: data
persistentVolumeClaim:
claimName: {{ include "agent.fullname" . }}-data
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
Expand Down
13 changes: 13 additions & 0 deletions charts/agent/templates/pvc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{- if .Values.persistence.enabled }}
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: {{ include "agent.fullname" . }}-data
spec:
accessModes:
- {{ .Values.persistence.accessMode }}
storageClassName: {{ .Values.persistence.storageClass | default "" }}
resources:
requests:
storage: {{ .Values.persistence.size }}
{{- end }}
31 changes: 28 additions & 3 deletions charts/agent/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,18 @@ git_bridge:
limits:
cpu: 200m
memory: 256Mi
ephemeral-storage: 100Mi
ephemeralstorage: 100Mi
requests:
cpu: 200m
memory: 256Mi
ephemeralstorage: 100Mi
persistence:
enabled: true
existingClaim: ""
storageClass: ""
mountPath: /mnt/agent/gb
accessMode: ReadWriteOnce
size: 5Gi
ingress:
enabled: true
annotations:
Expand Down Expand Up @@ -87,10 +95,18 @@ container_bridge:
limits:
cpu: 200m
memory: 256Mi
ephemeral-storage: 100Mi
ephemeralstorage: 100Mi
requests:
cpu: 200m
memory: 256Mi
ephemeralstorage: 100Mi
persistence:
enabled: true
existingClaim: ""
storageClass: ""
mountPath: /mnt/agent/cb
accessMode: ReadWriteOnce
size: 5Gi
ingress:
enabled: true
annotations:
Expand Down Expand Up @@ -127,10 +143,19 @@ resources:
limits:
cpu: 2
memory: 2Gi
ephemeral-storage: 1Gi
ephemeralstorage: 1Gi
requests:
cpu: 200m
memory: 256Mi
ephemeralstorage: 256Mi

persistence:
enabled: true
existingClaim: ""
storageClass: ""
mountPath: /mnt/agent/kbz
accessMode: ReadWriteOnce
size: 5Gi

autoscaling:
enabled: false
Expand Down
21 changes: 0 additions & 21 deletions charts/clickhouse/.helmignore

This file was deleted.

16 changes: 0 additions & 16 deletions charts/clickhouse/Chart.yaml

This file was deleted.

Loading

0 comments on commit 54c6eb3

Please sign in to comment.