Skip to content

Commit 6997b7d

Browse files
authored
Merge pull request #13 from 1debit/kustomize-ignore-2
Ignores generating the hash for custom path if the source is kustomize
2 parents 39a84d3 + e00db1d commit 6997b7d

File tree

5 files changed

+23
-4
lines changed

5 files changed

+23
-4
lines changed

.github/workflows/tests.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ jobs:
3030
runs-on: ubuntu-latest
3131
steps:
3232
- uses: actions/setup-go@v3
33+
with:
34+
go-version: '1.20'
3335
- uses: actions/checkout@v3
3436
- name: golangci-lint
3537
uses: golangci/golangci-lint-action@v3

.golangci.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ run:
33
allow-parallel-runners: true
44
timeout: 5m
55
go: '1.20'
6+
skip-dirs-use-default: false
67

78
linters:
89
enable:

main.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,13 @@ import (
1313
"time"
1414

1515
"github.com/1debit/mani-diffy/pkg/helm"
16+
"github.com/1debit/mani-diffy/pkg/kustomize"
1617

1718
"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
1819
)
1920

2021
const InfiniteDepth = -1
2122

22-
var ErrKustomizeNotSupported = errors.New("kustomize not supported")
23-
2423
// Renderer is a function that can render an Argo application.
2524
type Renderer func(*v1alpha1.Application, string) error
2625

@@ -127,19 +126,24 @@ func (w *Walker) walk(inputPath, outputPath string, depth, maxDepth int, visited
127126
if err != nil {
128127
return err
129128
}
129+
130130
hashGenerated, err := w.GenerateHash(crd)
131131
if err != nil {
132+
if errors.Is(err, kustomize.ErrNotSupported) {
133+
continue
134+
}
132135
return err
133136
}
134137

135138
emptyManifest, err := helm.EmptyManifest(filepath.Join(path, "manifest.yaml"))
136139
if err != nil {
137140
return err
138141
}
142+
139143
if hashGenerated != hash || emptyManifest {
140144
log.Printf("No match detected. Render: %s\n", crd.ObjectMeta.Name)
141145
if err := w.Render(crd, path); err != nil {
142-
if errors.Is(err, ErrKustomizeNotSupported) {
146+
if errors.Is(err, kustomize.ErrNotSupported) {
143147
continue
144148
}
145149
return err
@@ -169,7 +173,7 @@ func (w *Walker) Render(application *v1alpha1.Application, output string) error
169173
render = w.HelmTemplate
170174
case application.Spec.Source.Kustomize != nil:
171175
log.Println("WARNING: kustomize not supported")
172-
return ErrKustomizeNotSupported
176+
return kustomize.ErrNotSupported
173177
default:
174178
render = w.CopySource
175179
}

pkg/helm/helm.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"strings"
1818
"sync"
1919

20+
"github.com/1debit/mani-diffy/pkg/kustomize"
2021
"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
2122
yamlutil "k8s.io/apimachinery/pkg/util/yaml"
2223
)
@@ -197,6 +198,10 @@ func GenerateHash(crd *v1alpha1.Application, ignoreValueFile string) (string, er
197198
}
198199
fmt.Fprintf(finalHash, "%x\n", crdHash)
199200

201+
if crd.Spec.Source.Kustomize != nil {
202+
return "", kustomize.ErrNotSupported
203+
}
204+
200205
if crd.Spec.Source.Path != "" {
201206
chartHash, err := generalHashFunction(crd.Spec.Source.Path)
202207
if err != nil {

pkg/kustomize/kustomize.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package kustomize
2+
3+
import (
4+
"errors"
5+
)
6+
7+
var ErrNotSupported = errors.New("kustomize not supported")

0 commit comments

Comments
 (0)