Skip to content

Commit

Permalink
Merge pull request #13 from 1debit/kustomize-ignore-2
Browse files Browse the repository at this point in the history
Ignores generating the hash for custom path if the source is kustomize
  • Loading branch information
msanterre authored Feb 29, 2024
2 parents 39a84d3 + e00db1d commit 6997b7d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ run:
allow-parallel-runners: true
timeout: 5m
go: '1.20'
skip-dirs-use-default: false

linters:
enable:
Expand Down
12 changes: 8 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -127,19 +126,24 @@ 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
}

emptyManifest, err := helm.EmptyManifest(filepath.Join(path, "manifest.yaml"))
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
Expand Down Expand Up @@ -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
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions pkg/kustomize/kustomize.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package kustomize

import (
"errors"
)

var ErrNotSupported = errors.New("kustomize not supported")

0 comments on commit 6997b7d

Please sign in to comment.