Skip to content

Commit 88b5b0f

Browse files
authored
feat: support annotations (#91)
1 parent 37fa654 commit 88b5b0f

File tree

8 files changed

+74
-15
lines changed

8 files changed

+74
-15
lines changed

.github/workflows/go-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ jobs:
6464
id: windows
6565
steps:
6666
- name: Get Cached Artifacts
67-
uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4
67+
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
6868
with:
6969
path: dist
7070
key: dist-${{ github.run_id }}

.github/workflows/sec-codeql.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
go-version-file: go.mod
2929
cache: false
3030
- name: Setup Golang Caches
31-
uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4
31+
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
3232
with:
3333
path: |
3434
~/.cache/go-build

.github/workflows/tpl-packaging.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
go-version-file: go.mod
4545
cache: false
4646
- name: Setup Golang Caches
47-
uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4
47+
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
4848
with:
4949
path: |
5050
~/.cache/go-build
@@ -88,7 +88,7 @@ jobs:
8888
docker push ${docker_image_dst}
8989
done
9090
- name: Cache Artifacts
91-
uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4
91+
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
9292
if: ${{ inputs.artifacts-cache }}
9393
with:
9494
path: "${{ inputs.artifacts-cache-path }}"

.golangci.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ linters-settings:
66
min-complexity: 15
77
goimports:
88
local-prefixes: github.com/DevOpsHiveHQ/kustomize-plugin-merger
9-
govet:
10-
check-shadowing: true
119
misspell:
1210
locale: US
1311
nolintlint:
@@ -25,7 +23,6 @@ linters:
2523
- dogsled
2624
- dupl
2725
- errcheck
28-
- exportloopref
2926
- funlen
3027
- gochecknoinits
3128
- gocritic
@@ -58,5 +55,9 @@ issues:
5855
# https://golangci-lint.run/usage/false-positives/#default-exclusions
5956
exclude-use-default: false
6057
exclude:
61-
- "package-comments: .+"
62-
- "ST1000: package comment should be of the form"
58+
- "package-comments: .+"
59+
- "ST1000: package comment should be of the form"
60+
exclude-rules:
61+
- path: _test\.go
62+
linters:
63+
- dupl

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ spec:
113113
output:
114114
# Available options: raw,configmap,secret
115115
format: raw
116+
# Optional: Add custom annotations to output manifest.
117+
annotations:
118+
app.kubernetes.io/created-by: "kustomize-merger"
116119
```
117120
118121

pkg/merger/merge.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,9 @@ func (r *mergerResource) export() []*yaml.RNode {
8585
rNode, err := yaml.FromMap(map[string]interface{}{
8686
"apiVersion": "v1",
8787
"kind": "ConfigMap",
88-
"metadata": map[string]string{
89-
"name": r.Name,
88+
"metadata": map[string]interface{}{
89+
"name": r.Name,
90+
"annotations": r.Output.Annotations,
9091
},
9192
})
9293
if err != nil {
@@ -101,8 +102,9 @@ func (r *mergerResource) export() []*yaml.RNode {
101102
rNode, err := yaml.FromMap(map[string]interface{}{
102103
"apiVersion": "v1",
103104
"kind": "Secret",
104-
"metadata": map[string]string{
105-
"name": r.Name,
105+
"metadata": map[string]interface{}{
106+
"name": r.Name,
107+
"annotations": r.Output.Annotations,
106108
},
107109
})
108110
if err != nil {

pkg/merger/merge_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,32 @@ func TestOutputConfigMap(t *testing.T) {
431431
{"src01.3", "prom.yaml", "evaluation_interval", ""},
432432
},
433433
},
434+
{
435+
name: "Test ConfigMap output with overlay+annotations",
436+
desc: "The number of the outputs in 'ConfigMap+overlay' should be the same as input sources",
437+
actual: mergerResource{
438+
Name: "test-output-configmap",
439+
Output: resourceOutput{
440+
Format: "configmap",
441+
Annotations: map[string]string{
442+
"kustomize.config.k8s.io/needs-hash": "true",
443+
},
444+
items: map[string]string{
445+
"prom.yaml": `
446+
global:
447+
scrape_interval: 15s
448+
evaluation_interval: 15s
449+
`,
450+
},
451+
},
452+
},
453+
expected: []testMergeCase{
454+
{"src01.1", "prom.yaml", "kind: ConfigMap", ""},
455+
{"src01.2", "prom.yaml", "name: test-output-configmap", ""},
456+
{"src01.3", "prom.yaml", "evaluation_interval", ""},
457+
{"src01.4", "prom.yaml", "kustomize.config.k8s.io/needs-hash: \"true\"", ""},
458+
},
459+
},
434460
}
435461

436462
for _, tt := range tests {
@@ -478,6 +504,32 @@ func TestOutputSecret(t *testing.T) {
478504
{"src01.3", "prom.yaml", "CgkJCQkJCQlnbG9iYWw6CgkJCQkJCQkJc2NyYXBlX2ludGVydmFsOiAxNXMKCQkJCQkJCQ", ""},
479505
},
480506
},
507+
{
508+
name: "Test Secret output with overlay+annotations",
509+
desc: "The number of the outputs in 'Secret+overlay' should be the same as input sources",
510+
actual: mergerResource{
511+
Name: "test-output-secret",
512+
Output: resourceOutput{
513+
Format: "secret",
514+
Annotations: map[string]string{
515+
"kustomize.config.k8s.io/needs-hash": "false",
516+
},
517+
items: map[string]string{
518+
"prom.yaml": `
519+
global:
520+
scrape_interval: 15s
521+
evaluation_interval: 15s
522+
`,
523+
},
524+
},
525+
},
526+
expected: []testMergeCase{
527+
{"src01.2", "prom.yaml", "kind: Secret", ""},
528+
{"src01.2", "prom.yaml", "name: test-output-secret", ""},
529+
{"src01.3", "prom.yaml", "CgkJCQkJCQlnbG9iYWw6CgkJCQkJCQkJc2NyYXBlX2ludGVydmFsOiAxNXMKCQkJCQkJCQ", ""},
530+
{"src01.4", "prom.yaml", "kustomize.config.k8s.io/needs-hash: \"false\"", ""},
531+
},
532+
},
481533
}
482534

483535
for _, tt := range tests {

pkg/merger/types.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ const (
106106
)
107107

108108
type resourceOutput struct {
109-
Format resourceOutputFormat `yaml:"format" json:"format"`
110-
items map[string]string
109+
Format resourceOutputFormat `yaml:"format" json:"format"`
110+
items map[string]string
111+
Annotations map[string]string `yaml:"annotations,omitempty" json:"annotations,omitempty"`
111112
}

0 commit comments

Comments
 (0)