@@ -17,95 +17,96 @@ limitations under the License.
17
17
package commands
18
18
19
19
import (
20
- "errors"
21
- "fmt"
22
- "regexp"
23
- "strings"
20
+ // "errors"
21
+ // "fmt"
22
+ // "regexp"
23
+ // "strings"
24
24
25
25
"github.com/spf13/cobra"
26
26
27
- "github.com/kubernetes-sigs/kustomize/pkg/constants"
27
+ // "github.com/kubernetes-sigs/kustomize/pkg/constants"
28
28
"github.com/kubernetes-sigs/kustomize/pkg/fs"
29
29
)
30
30
31
- type addAnnotationOptions struct {
32
- annotations string
33
- }
31
+ // type addAnnotationOptions struct {
32
+ // annotations string
33
+ // }
34
34
35
35
// newCmdAddAnnotation adds one or more commonAnnotations to the kustomization file.
36
36
func newCmdAddAnnotation (fsys fs.FileSystem ) * cobra.Command {
37
- var o addAnnotationOptions
37
+ var o addMetadataOptions
38
38
39
39
cmd := & cobra.Command {
40
40
Use : "annotation" ,
41
41
Short : "Adds one or more commonAnnotations to the kustomization.yaml in current directory" ,
42
42
Example : `
43
43
add annotation {annotationKey1:annotationValue1},{annotationKey2:annotationValue2}` ,
44
44
RunE : func (cmd * cobra.Command , args []string ) error {
45
- err := o .Validate (args )
45
+ mdKind := "annotation"
46
+ err := o .Validate (args , mdKind )
46
47
if err != nil {
47
48
return err
48
49
}
49
50
err = o .Complete (cmd , args )
50
51
if err != nil {
51
52
return err
52
53
}
53
- return o .RunAddAnnotation (fsys )
54
+ return o .RunAddMetadata (fsys , mdKind )
54
55
},
55
56
}
56
57
return cmd
57
58
}
58
59
59
- // Validate validates addAnnotation command.
60
- func (o * addAnnotationOptions ) Validate (args []string ) error {
61
- if len (args ) < 1 {
62
- return errors .New ("must specify an annotation" )
63
- }
64
- if len (args ) > 1 {
65
- return errors .New ("annotations must be comma-separated, with no spaces. See help text for example." )
66
- }
67
- inputs := strings .Split (args [0 ], "," )
68
- for _ , input := range inputs {
69
- ok , err := regexp .MatchString (`\A([a-zA-Z0-9_.-]+):([a-zA-Z0-9_.-]+)\z` , input )
70
- if err != nil {
71
- return err
72
- }
73
- if ! ok {
74
- return fmt .Errorf ("invalid annotation format: %s" , input )
75
- }
76
- }
77
- o .annotations = args [0 ]
78
- return nil
79
- }
80
-
81
- // Complete completes addAnnotation command.
82
- func (o * addAnnotationOptions ) Complete (cmd * cobra.Command , args []string ) error {
83
- return nil
84
- }
85
-
86
- // RunAddAnnotation runs addAnnotation command (do real work).
87
- func (o * addAnnotationOptions ) RunAddAnnotation (fsys fs.FileSystem ) error {
88
- mf , err := newKustomizationFile (constants .KustomizationFileName , fsys )
89
- if err != nil {
90
- return err
91
- }
92
-
93
- m , err := mf .read ()
94
- if err != nil {
95
- return err
96
- }
97
-
98
- if m .CommonAnnotations == nil {
99
- m .CommonAnnotations = make (map [string ]string )
100
- }
101
- annotations := strings .Split (o .annotations , "," )
102
- for _ , ann := range annotations {
103
- kv := strings .Split (ann , ":" )
104
- if _ , ok := m .CommonAnnotations [kv [0 ]]; ok {
105
- return fmt .Errorf ("annotation %s already in kustomization file" , kv [0 ])
106
- }
107
- m .CommonAnnotations [kv [0 ]] = kv [1 ]
108
- }
109
-
110
- return mf .write (m )
111
- }
60
+ // // Validate validates addAnnotation command.
61
+ // func (o *addAnnotationOptions) Validate(args []string) error {
62
+ // if len(args) < 1 {
63
+ // return errors.New("must specify an annotation")
64
+ // }
65
+ // if len(args) > 1 {
66
+ // return errors.New("annotations must be comma-separated, with no spaces. See help text for example.")
67
+ // }
68
+ // inputs := strings.Split(args[0], ",")
69
+ // for _, input := range inputs {
70
+ // ok, err := regexp.MatchString(`\A([a-zA-Z0-9_.-]+):([a-zA-Z0-9_.-]+)\z`, input)
71
+ // if err != nil {
72
+ // return err
73
+ // }
74
+ // if !ok {
75
+ // return fmt.Errorf("invalid annotation format: %s", input)
76
+ // }
77
+ // }
78
+ // o.annotations = args[0]
79
+ // return nil
80
+ // }
81
+
82
+ // // Complete completes addAnnotation command.
83
+ // func (o *addAnnotationOptions) Complete(cmd *cobra.Command, args []string) error {
84
+ // return nil
85
+ // }
86
+
87
+ // // RunAddAnnotation runs addAnnotation command (do real work).
88
+ // func (o *addAnnotationOptions) RunAddAnnotation(fsys fs.FileSystem) error {
89
+ // mf, err := newKustomizationFile(constants.KustomizationFileName, fsys)
90
+ // if err != nil {
91
+ // return err
92
+ // }
93
+
94
+ // m, err := mf.read()
95
+ // if err != nil {
96
+ // return err
97
+ // }
98
+
99
+ // if m.CommonAnnotations == nil {
100
+ // m.CommonAnnotations = make(map[string]string)
101
+ // }
102
+ // annotations := strings.Split(o.annotations, ",")
103
+ // for _, ann := range annotations {
104
+ // kv := strings.Split(ann, ":")
105
+ // if _, ok := m.CommonAnnotations[kv[0]]; ok {
106
+ // return fmt.Errorf("annotation %s already in kustomization file", kv[0])
107
+ // }
108
+ // m.CommonAnnotations[kv[0]] = kv[1]
109
+ // }
110
+
111
+ // return mf.write(m)
112
+ // }
0 commit comments