Record kubectl commands

This commit is contained in:
Janet Kuo
2016-01-22 10:33:23 -08:00
parent 210bac10c9
commit 5088d0e147
38 changed files with 277 additions and 11 deletions

View File

@@ -46,6 +46,9 @@ type AnnotateOptions struct {
all bool
resourceVersion string
changeCause string
recordFlag bool
f *cmdutil.Factory
out io.Writer
cmd *cobra.Command
@@ -111,6 +114,7 @@ func NewCmdAnnotate(f *cmdutil.Factory, out io.Writer) *cobra.Command {
cmd.Flags().StringVar(&options.resourceVersion, "resource-version", "", "If non-empty, the annotation update will only succeed if this is the current resource-version for the object. Only valid when specifying a single resource.")
usage := "Filename, directory, or URL to a file identifying the resource to update the annotation"
kubectl.AddJsonFilenameFlag(cmd, &options.filenames, usage)
cmdutil.AddRecordFlag(cmd)
return cmd
}
@@ -151,6 +155,9 @@ func (o *AnnotateOptions) Complete(f *cmdutil.Factory, out io.Writer, cmd *cobra
return err
}
o.recordFlag = cmdutil.GetRecordFlag(cmd)
o.changeCause = f.Command()
mapper, typer := f.Object()
o.builder = resource.NewBuilder(mapper, typer, resource.ClientMapperFunc(f.ClientForMapping), f.Decoder(true)).
ContinueOnError().
@@ -199,6 +206,10 @@ func (o AnnotateOptions) RunAnnotate() error {
if err != nil {
return err
}
// If we should record change-cause, add it to new annotations
if cmdutil.ContainsChangeCause(info) || o.recordFlag {
o.newAnnotations[kubectl.ChangeCauseAnnotation] = o.changeCause
}
if err := o.updateAnnotations(obj); err != nil {
return err
}
@@ -292,6 +303,10 @@ func validateAnnotations(removeAnnotations []string, newAnnotations map[string]s
func validateNoAnnotationOverwrites(meta *api.ObjectMeta, annotations map[string]string) error {
var buf bytes.Buffer
for key := range annotations {
// change-cause annotation can always be overwritten
if key == kubectl.ChangeCauseAnnotation {
continue
}
if value, found := meta.Annotations[key]; found {
if buf.Len() > 0 {
buf.WriteString("; ")