diff --git a/.github/workflows/generate-manifests-demos.yaml b/.github/workflows/generate-manifests-demos.yaml index 1c53c8f..07c486f 100644 --- a/.github/workflows/generate-manifests-demos.yaml +++ b/.github/workflows/generate-manifests-demos.yaml @@ -2,7 +2,7 @@ name: Generate manifests for demo on: [push] env: - USE_RELEASE: true + USE_RELEASE: false RELEASE_TAG: v0.1.1 jobs: diff --git a/demo/.zz.auto-generated/test-app-group-1/manifest.yaml b/demo/.zz.auto-generated/test-app-group-1/manifest.yaml index f0338bc..f6909d5 100644 --- a/demo/.zz.auto-generated/test-app-group-1/manifest.yaml +++ b/demo/.zz.auto-generated/test-app-group-1/manifest.yaml @@ -70,3 +70,29 @@ spec: - ../../overrides/service/foo/test.yaml syncPolicy: automated: {} +--- +# Source: app-of-apps/templates/apps.yaml +apiVersion: argoproj.io/v1alpha1 +kind: Application +metadata: + name: test-service-skipped + annotations: + mani-diffy.chime.com/skip: "true" +spec: + destination: + namespace: argocd + server: https://kubernetes.default.svc + project: default + source: + repoURL: https://github.com/chime/mani-diffy.git + path: charts/service + helm: + version: v3 + parameters: + - name: env + value: test + valueFiles: + - ../../overrides/service/skipped/base.yaml + - ../../overrides/service/skipped/test.yaml + syncPolicy: + automated: {} diff --git a/demo/charts/app-of-apps/templates/service.tpl b/demo/charts/app-of-apps/templates/service.tpl index 35b1e41..1078716 100644 --- a/demo/charts/app-of-apps/templates/service.tpl +++ b/demo/charts/app-of-apps/templates/service.tpl @@ -5,6 +5,10 @@ apiVersion: argoproj.io/v1alpha1 kind: Application metadata: name: {{ .root.env }}-service-{{ $appName }} + {{- if .childParams.skipManiDiffy }} + annotations: + mani-diffy.chime.com/skip: "true" + {{- end }} spec: destination: namespace: argocd diff --git a/demo/overrides/app-of-apps/test-app-group-1.yaml b/demo/overrides/app-of-apps/test-app-group-1.yaml index bc5d5ab..46f33a2 100644 --- a/demo/overrides/app-of-apps/test-app-group-1.yaml +++ b/demo/overrides/app-of-apps/test-app-group-1.yaml @@ -5,3 +5,6 @@ children: chart: service baz: chart: service + skipped: + chart: service + skipManiDiffy: true diff --git a/main.go b/main.go index 212c071..03e65cb 100644 --- a/main.go +++ b/main.go @@ -20,6 +20,27 @@ import ( const InfiniteDepth = -1 +const skipAnnotation = "mani-diffy.chime.com/skip" + +// shouldSkipRender checks if an Application should be skipped based on: +// 1. The application name suffix (ignoreSuffix) +// 2. The mani-diffy.chime.com/skip annotation set to "true" +func shouldSkipRender(app *v1alpha1.Application, ignoreSuffix string) bool { + // Check if the application name has the ignore suffix + if strings.HasSuffix(app.ObjectMeta.Name, ignoreSuffix) { + return true + } + + // Check if the skip annotation is set to "true" + if app.ObjectMeta.Annotations != nil { + if value, ok := app.ObjectMeta.Annotations[skipAnnotation]; ok && value == "true" { + return true + } + } + + return false +} + // Renderer is a function that can render an Argo application. type Renderer func(*v1alpha1.Application, string) error @@ -114,7 +135,7 @@ func (w *Walker) walk(inputPath, outputPath string, depth, maxDepth int, visited continue } - if strings.HasSuffix(crd.ObjectMeta.Name, w.ignoreSuffix) { + if shouldSkipRender(crd, w.ignoreSuffix) { continue } diff --git a/pkg/helm/helm_test.go b/pkg/helm/helm_test.go index 2cf7073..7818cac 100644 --- a/pkg/helm/helm_test.go +++ b/pkg/helm/helm_test.go @@ -321,7 +321,7 @@ kind: Application t.Run("GenerateHashOnChart", func(t *testing.T) { hash, _ := generalHashFunction("demo/charts/app-of-apps") h := hex.EncodeToString(hash) - actualHash := "13aa148adefa3d633e5ce95584d3c95297a4417977837040cd67f0afbca17b5a" + actualHash := "f57ffb63de221520249492e247beb6d6f61cd378e7c246909cca9c5110a6bb28" if h != actualHash { t.Errorf("Failed to generate a generic hash on a chart. got: %s wanted: %s", h, actualHash) }