From bd8082e4355022f5b42c81a4bbb61f7f50856486 Mon Sep 17 00:00:00 2001 From: Maxime Santerre Date: Wed, 28 Feb 2024 14:24:45 -0800 Subject: [PATCH 1/3] Ignore #2 for kustomize --- main.go | 12 ++++++++---- pkg/helm/helm.go | 5 +++++ pkg/kustomize/kustomize.go | 7 +++++++ 3 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 pkg/kustomize/kustomize.go diff --git a/main.go b/main.go index 16bb007..b2381d8 100644 --- a/main.go +++ b/main.go @@ -13,14 +13,13 @@ import ( "time" "github.com/1debit/mani-diffy/pkg/helm" + "github.com/1debit/mani-diffy/pkg/kustomize" "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1" ) const InfiniteDepth = -1 -var ErrKustomizeNotSupported = errors.New("kustomize not supported") - // Renderer is a function that can render an Argo application. type Renderer func(*v1alpha1.Application, string) error @@ -127,8 +126,12 @@ func (w *Walker) walk(inputPath, outputPath string, depth, maxDepth int, visited if err != nil { return err } + hashGenerated, err := w.GenerateHash(crd) if err != nil { + if errors.Is(err, kustomize.ErrNotSupported) { + continue + } return err } @@ -136,10 +139,11 @@ func (w *Walker) walk(inputPath, outputPath string, depth, maxDepth int, visited if err != nil { return err } + if hashGenerated != hash || emptyManifest { log.Printf("No match detected. Render: %s\n", crd.ObjectMeta.Name) if err := w.Render(crd, path); err != nil { - if errors.Is(err, ErrKustomizeNotSupported) { + if errors.Is(err, kustomize.ErrNotSupported) { continue } return err @@ -169,7 +173,7 @@ func (w *Walker) Render(application *v1alpha1.Application, output string) error render = w.HelmTemplate case application.Spec.Source.Kustomize != nil: log.Println("WARNING: kustomize not supported") - return ErrKustomizeNotSupported + return kustomize.ErrNotSupported default: render = w.CopySource } diff --git a/pkg/helm/helm.go b/pkg/helm/helm.go index 7cf6b99..02bf0aa 100644 --- a/pkg/helm/helm.go +++ b/pkg/helm/helm.go @@ -17,6 +17,7 @@ import ( "strings" "sync" + "github.com/1debit/mani-diffy/pkg/kustomize" "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1" yamlutil "k8s.io/apimachinery/pkg/util/yaml" ) @@ -197,6 +198,10 @@ func GenerateHash(crd *v1alpha1.Application, ignoreValueFile string) (string, er } fmt.Fprintf(finalHash, "%x\n", crdHash) + if crd.Spec.Source.Kustomize != nil { + return "", kustomize.ErrNotSupported + } + if crd.Spec.Source.Path != "" { chartHash, err := generalHashFunction(crd.Spec.Source.Path) if err != nil { diff --git a/pkg/kustomize/kustomize.go b/pkg/kustomize/kustomize.go new file mode 100644 index 0000000..7868c0d --- /dev/null +++ b/pkg/kustomize/kustomize.go @@ -0,0 +1,7 @@ +package kustomize + +import ( + "errors" +) + +var ErrNotSupported = errors.New("kustomize not supported") From 9ce512202c48f0560c29bfd0e66c25448e792663 Mon Sep 17 00:00:00 2001 From: Maxime Santerre Date: Wed, 28 Feb 2024 14:29:23 -0800 Subject: [PATCH 2/3] Trigger Build From e00db1d2d5207614ee44c8e51459c3116b593c9a Mon Sep 17 00:00:00 2001 From: Maxime Santerre Date: Wed, 28 Feb 2024 20:58:46 -0800 Subject: [PATCH 3/3] Try fix ci lint --- .github/workflows/tests.yaml | 2 ++ .golangci.yaml | 1 + 2 files changed, 3 insertions(+) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 75d37b0..0327b9d 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -30,6 +30,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/setup-go@v3 + with: + go-version: '1.20' - uses: actions/checkout@v3 - name: golangci-lint uses: golangci/golangci-lint-action@v3 diff --git a/.golangci.yaml b/.golangci.yaml index d0dc07b..a6142af 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -3,6 +3,7 @@ run: allow-parallel-runners: true timeout: 5m go: '1.20' + skip-dirs-use-default: false linters: enable: