Skip to content

Commit 72a8b07

Browse files
authored
Merge pull request #36 from chime/skip-application
Add support for skipping Applications via annotation
2 parents 3fdc849 + df8e3ac commit 72a8b07

File tree

6 files changed

+57
-3
lines changed

6 files changed

+57
-3
lines changed

.github/workflows/generate-manifests-demos.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Generate manifests for demo
22
on: [push]
33

44
env:
5-
USE_RELEASE: true
5+
USE_RELEASE: false
66
RELEASE_TAG: v0.1.1
77

88
jobs:

demo/.zz.auto-generated/test-app-group-1/manifest.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,29 @@ spec:
7070
- ../../overrides/service/foo/test.yaml
7171
syncPolicy:
7272
automated: {}
73+
---
74+
# Source: app-of-apps/templates/apps.yaml
75+
apiVersion: argoproj.io/v1alpha1
76+
kind: Application
77+
metadata:
78+
name: test-service-skipped
79+
annotations:
80+
mani-diffy.chime.com/skip: "true"
81+
spec:
82+
destination:
83+
namespace: argocd
84+
server: https://kubernetes.default.svc
85+
project: default
86+
source:
87+
repoURL: https://github.com/chime/mani-diffy.git
88+
path: charts/service
89+
helm:
90+
version: v3
91+
parameters:
92+
- name: env
93+
value: test
94+
valueFiles:
95+
- ../../overrides/service/skipped/base.yaml
96+
- ../../overrides/service/skipped/test.yaml
97+
syncPolicy:
98+
automated: {}

demo/charts/app-of-apps/templates/service.tpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ apiVersion: argoproj.io/v1alpha1
55
kind: Application
66
metadata:
77
name: {{ .root.env }}-service-{{ $appName }}
8+
{{- if .childParams.skipManiDiffy }}
9+
annotations:
10+
mani-diffy.chime.com/skip: "true"
11+
{{- end }}
812
spec:
913
destination:
1014
namespace: argocd

demo/overrides/app-of-apps/test-app-group-1.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ children:
55
chart: service
66
baz:
77
chart: service
8+
skipped:
9+
chart: service
10+
skipManiDiffy: true

main.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,27 @@ import (
2020

2121
const InfiniteDepth = -1
2222

23+
const skipAnnotation = "mani-diffy.chime.com/skip"
24+
25+
// shouldSkipRender checks if an Application should be skipped based on:
26+
// 1. The application name suffix (ignoreSuffix)
27+
// 2. The mani-diffy.chime.com/skip annotation set to "true"
28+
func shouldSkipRender(app *v1alpha1.Application, ignoreSuffix string) bool {
29+
// Check if the application name has the ignore suffix
30+
if strings.HasSuffix(app.ObjectMeta.Name, ignoreSuffix) {
31+
return true
32+
}
33+
34+
// Check if the skip annotation is set to "true"
35+
if app.ObjectMeta.Annotations != nil {
36+
if value, ok := app.ObjectMeta.Annotations[skipAnnotation]; ok && value == "true" {
37+
return true
38+
}
39+
}
40+
41+
return false
42+
}
43+
2344
// Renderer is a function that can render an Argo application.
2445
type Renderer func(*v1alpha1.Application, string) error
2546

@@ -114,7 +135,7 @@ func (w *Walker) walk(inputPath, outputPath string, depth, maxDepth int, visited
114135
continue
115136
}
116137

117-
if strings.HasSuffix(crd.ObjectMeta.Name, w.ignoreSuffix) {
138+
if shouldSkipRender(crd, w.ignoreSuffix) {
118139
continue
119140
}
120141

pkg/helm/helm_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ kind: Application
321321
t.Run("GenerateHashOnChart", func(t *testing.T) {
322322
hash, _ := generalHashFunction("demo/charts/app-of-apps")
323323
h := hex.EncodeToString(hash)
324-
actualHash := "13aa148adefa3d633e5ce95584d3c95297a4417977837040cd67f0afbca17b5a"
324+
actualHash := "f57ffb63de221520249492e247beb6d6f61cd378e7c246909cca9c5110a6bb28"
325325
if h != actualHash {
326326
t.Errorf("Failed to generate a generic hash on a chart. got: %s wanted: %s", h, actualHash)
327327
}

0 commit comments

Comments
 (0)