/
main.go
53 lines (45 loc) · 1.31 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package main
import (
"embed"
"fmt"
"os"
"github.com/spf13/cobra"
"sigs.k8s.io/kustomize/kyaml/fn/framework"
"sigs.k8s.io/kustomize/kyaml/fn/framework/command"
"sigs.k8s.io/kustomize/kyaml/fn/framework/parser"
)
//go:embed templates/*
var templateFS embed.FS
var annotationTemplate = `
metadata:
annotations:
value: {{ .Value }}
`
func buildProcessor(value *string) framework.ResourceListProcessor {
return framework.TemplateProcessor{
ResourceTemplates: []framework.ResourceTemplate{{
Templates: parser.TemplateFiles("templates").FromFS(templateFS),
}},
PatchTemplates: []framework.PatchTemplate{&framework.ResourcePatchTemplate{
Templates: parser.TemplateStrings(annotationTemplate),
}},
// This will be populated from the --value flag if provided,
// or the config file's `value` field if provided, with the latter taking precedence.
TemplateData: &struct {
Value *string `yaml:"value"`
}{Value: value}}
}
func buildCmd() *cobra.Command {
var value string
cmd := command.Build(buildProcessor(&value), command.StandaloneEnabled, false)
cmd.Flags().StringVar(&value, "value", "", "annotation value")
return cmd
}
func main() {
if err := buildCmd().Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}