Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignores generating the hash for custom path if the source is kustomize #13

Merged
merged 3 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
Loading