-
Notifications
You must be signed in to change notification settings - Fork 51
/
main.go
74 lines (61 loc) · 2.04 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"fmt"
"os"
"github.com/jenkins-x-plugins/jx-gitops/pkg/rootcmd"
"github.com/jenkins-x/jx-helpers/v3/pkg/cobras/templates"
"github.com/jenkins-x/jx-logging/v3/pkg/log"
"sigs.k8s.io/kustomize/kyaml/fn/framework"
"sigs.k8s.io/kustomize/kyaml/yaml"
)
var (
labelLong = templates.LongDesc(`
Updates all kubernetes resources in the given directory tree to add/override the given label
`)
labelExample = templates.Examples(`
# updates recursively labels all resources in the current directory
%s step update label mylabel=cheese another=thing
# updates recursively all resources
%s step update label --dir myresource-dir foo=bar
`)
)
func main() {
//o := &Options{}
resourceList := &framework.ResourceList{}
cmd := framework.Command(resourceList, func() error {
fmt.Println("TODO: starting up....")
// cmd.Execute() will parse the ResourceList.functionConfig into cmd.Flags from
// the ResourceList.functionConfig.data field.
args := resourceList.Flags.Args()
log.Logger().Infof("invoked with args %#v", args)
for i := range resourceList.Items {
// modify the resources using the kyaml/yaml library:
// https://pkg.go.dev/sigs.k8s.io/kustomize/kyaml/yaml
filter := yaml.SetLabel("value", "dummy")
if err := resourceList.Items[i].PipeE(filter); err != nil {
return err
}
}
return nil
})
cmd.Use = "label"
cmd.Short = "Updates all kubernetes resources in the given directory tree to add/override the given label"
cmd.Long = labelLong
cmd.Example = fmt.Sprintf(labelExample, rootcmd.BinaryName, rootcmd.BinaryName)
/*
cmd := &cobra.Command{
Use: "label",
Short: ,
Long: labelLong,
Example: fmt.Sprintf(labelExample, common.BinaryName, common.BinaryName),
Run: func(cmd *cobra.Command, args []string) {
err := UpdateLabelArgsInYamlFiles(o.Dir, args)
helper.CheckErr(err)
},
}
//cmd.Flags().StringVarP(&o.Dir, "dir", "", ".", "the directory to recursively look for the *.yaml or *.yml files")
*/
if err := cmd.Execute(); err != nil {
os.Exit(1)
}
}