mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-04 15:05:20 +00:00
Merge pull request #34199 from asalkeld/annotate-label
Automatic merge from submit-queue Make kubectl label and annotate more consistent **What this PR does / why we need it**: This makes the label and annotate cmd files more consistent which should help with code maintenance. Some of the main changes: - add dryrun to annotate (can push this in a different PR if requested) - use Complete(), Validate() and RunX() - don't place dynamic variables in the options (only user options and args) - call the NewBuilder() in the Run function. **Which issue this PR fixes** fixes #34151 **Special notes for your reviewer**: Note: you *can* now diff the two files and the changes make sense. **Release note**: ```release-note kubectl annotate now supports --dry-run ```
This commit is contained in:
@@ -323,7 +323,14 @@ func TestLabelErrors(t *testing.T) {
|
||||
for k, v := range testCase.flags {
|
||||
cmd.Flags().Set(k, v)
|
||||
}
|
||||
err := RunLabel(f, buf, cmd, testCase.args, &resource.FilenameOptions{})
|
||||
opts := LabelOptions{}
|
||||
err := opts.Complete(f, buf, cmd, testCase.args)
|
||||
if err == nil {
|
||||
err = opts.Validate()
|
||||
}
|
||||
if err == nil {
|
||||
err = opts.RunLabel(f, cmd)
|
||||
}
|
||||
if !testCase.errFn(err) {
|
||||
t.Errorf("%s: unexpected error: %v", k, err)
|
||||
continue
|
||||
@@ -371,10 +378,15 @@ func TestLabelForResourceFromFile(t *testing.T) {
|
||||
|
||||
buf := bytes.NewBuffer([]byte{})
|
||||
cmd := NewCmdLabel(f, buf)
|
||||
options := &resource.FilenameOptions{}
|
||||
options.Filenames = []string{"../../../examples/storage/cassandra/cassandra-controller.yaml"}
|
||||
|
||||
err := RunLabel(f, buf, cmd, []string{"a=b"}, options)
|
||||
opts := LabelOptions{FilenameOptions: resource.FilenameOptions{
|
||||
Filenames: []string{"../../../examples/storage/cassandra/cassandra-controller.yaml"}}}
|
||||
err := opts.Complete(f, buf, cmd, []string{"a=b"})
|
||||
if err == nil {
|
||||
err = opts.Validate()
|
||||
}
|
||||
if err == nil {
|
||||
err = opts.RunLabel(f, cmd)
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
@@ -398,11 +410,15 @@ func TestLabelLocal(t *testing.T) {
|
||||
buf := bytes.NewBuffer([]byte{})
|
||||
cmd := NewCmdLabel(f, buf)
|
||||
cmd.Flags().Set("local", "true")
|
||||
options := &resource.FilenameOptions{
|
||||
Filenames: []string{"../../../examples/storage/cassandra/cassandra-controller.yaml"},
|
||||
opts := LabelOptions{FilenameOptions: resource.FilenameOptions{
|
||||
Filenames: []string{"../../../examples/storage/cassandra/cassandra-controller.yaml"}}}
|
||||
err := opts.Complete(f, buf, cmd, []string{"a=b"})
|
||||
if err == nil {
|
||||
err = opts.Validate()
|
||||
}
|
||||
if err == nil {
|
||||
err = opts.RunLabel(f, cmd)
|
||||
}
|
||||
|
||||
err := RunLabel(f, buf, cmd, []string{"a=b"}, options)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
@@ -449,7 +465,15 @@ func TestLabelMultipleObjects(t *testing.T) {
|
||||
cmd := NewCmdLabel(f, buf)
|
||||
cmd.Flags().Set("all", "true")
|
||||
|
||||
if err := RunLabel(f, buf, cmd, []string{"pods", "a=b"}, &resource.FilenameOptions{}); err != nil {
|
||||
opts := LabelOptions{}
|
||||
err := opts.Complete(f, buf, cmd, []string{"pods", "a=b"})
|
||||
if err == nil {
|
||||
err = opts.Validate()
|
||||
}
|
||||
if err == nil {
|
||||
err = opts.RunLabel(f, cmd)
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if strings.Count(buf.String(), "labeled") != len(pods.Items) {
|
||||
|
||||
Reference in New Issue
Block a user