remove mapper dependency - PrintSuccess

This commit is contained in:
juanvallejo 2018-02-01 18:59:11 -05:00
parent 06472a054a
commit beb5ea641a
No known key found for this signature in database
GPG Key ID: 7D2C958002D6448D
67 changed files with 156 additions and 169 deletions

View File

@ -3732,7 +3732,7 @@ run_cmd_with_img_tests() {
# Test that a valid image reference value is provided as the value of --image in `kubectl run <name> --image` # Test that a valid image reference value is provided as the value of --image in `kubectl run <name> --image`
output_message=$(kubectl run test1 --image=validname) output_message=$(kubectl run test1 --image=validname)
kube::test::if_has_string "${output_message}" 'deployment "test1" created' kube::test::if_has_string "${output_message}" 'deployments "test1" created'
kubectl delete deployments test1 kubectl delete deployments test1
# test invalid image name # test invalid image name
output_message=$(! kubectl run test2 --image=InvalidImageName 2>&1) output_message=$(! kubectl run test2 --image=InvalidImageName 2>&1)
@ -4410,7 +4410,7 @@ __EOF__
kube::test::if_has_string "${response}" 'must provide one or more resources' kube::test::if_has_string "${response}" 'must provide one or more resources'
# test=label matches our node # test=label matches our node
response=$(kubectl cordon --selector test=label) response=$(kubectl cordon --selector test=label)
kube::test::if_has_string "${response}" 'node "127.0.0.1" cordoned' kube::test::if_has_string "${response}" 'nodes "127.0.0.1" cordoned'
# invalid=label does not match any nodes # invalid=label does not match any nodes
response=$(kubectl cordon --selector invalid=label) response=$(kubectl cordon --selector invalid=label)
kube::test::if_has_not_string "${response}" 'cordoned' kube::test::if_has_not_string "${response}" 'cordoned'

View File

@ -272,7 +272,7 @@ func (o AnnotateOptions) RunAnnotate(f cmdutil.Factory, cmd *cobra.Command) erro
if len(o.outputFormat) > 0 { if len(o.outputFormat) > 0 {
return f.PrintObject(cmd, o.local, mapper, outputObj, o.out) return f.PrintObject(cmd, o.local, mapper, outputObj, o.out)
} }
f.PrintSuccess(mapper, false, o.out, info.Mapping.Resource, info.Name, o.dryrun, "annotated") f.PrintSuccess(false, o.out, info.Mapping.Resource, info.Name, o.dryrun, "annotated")
return nil return nil
}) })
} }

View File

@ -297,7 +297,7 @@ func RunApply(f cmdutil.Factory, cmd *cobra.Command, out, errOut io.Writer, opti
if len(output) > 0 && !shortOutput { if len(output) > 0 && !shortOutput {
return f.PrintResourceInfoForCommand(cmd, info, out) return f.PrintResourceInfoForCommand(cmd, info, out)
} }
f.PrintSuccess(mapper, shortOutput, out, info.Mapping.Resource, info.Name, dryRun, "created") f.PrintSuccess(shortOutput, out, info.Mapping.Resource, info.Name, dryRun, "created")
return nil return nil
} }
@ -342,7 +342,7 @@ func RunApply(f cmdutil.Factory, cmd *cobra.Command, out, errOut io.Writer, opti
if string(patchBytes) == "{}" { if string(patchBytes) == "{}" {
count++ count++
f.PrintSuccess(mapper, shortOutput, out, info.Mapping.Resource, info.Name, false, "unchanged") f.PrintSuccess(shortOutput, out, info.Mapping.Resource, info.Name, false, "unchanged")
return nil return nil
} }
} }
@ -350,7 +350,7 @@ func RunApply(f cmdutil.Factory, cmd *cobra.Command, out, errOut io.Writer, opti
if len(output) > 0 && !shortOutput { if len(output) > 0 && !shortOutput {
return f.PrintResourceInfoForCommand(cmd, info, out) return f.PrintResourceInfoForCommand(cmd, info, out)
} }
f.PrintSuccess(mapper, shortOutput, out, info.Mapping.Resource, info.Name, dryRun, "configured") f.PrintSuccess(shortOutput, out, info.Mapping.Resource, info.Name, dryRun, "configured")
return nil return nil
}) })
@ -517,7 +517,7 @@ func (p *pruner) prune(f cmdutil.Factory, namespace string, mapping *meta.RESTMa
return err return err
} }
} }
f.PrintSuccess(p.mapper, shortOutput, p.out, mapping.Resource, name, p.dryRun, "pruned") f.PrintSuccess(shortOutput, p.out, mapping.Resource, name, p.dryRun, "pruned")
} }
return nil return nil
} }

View File

@ -188,14 +188,14 @@ func (o *SetLastAppliedOptions) RunSetLastApplied(f cmdutil.Factory, cmd *cobra.
info.Refresh(patchedObj, false) info.Refresh(patchedObj, false)
return f.PrintResourceInfoForCommand(cmd, info, o.Out) return f.PrintResourceInfoForCommand(cmd, info, o.Out)
} }
f.PrintSuccess(o.Mapper, o.ShortOutput, o.Out, info.Mapping.Resource, info.Name, o.DryRun, "configured") f.PrintSuccess(o.ShortOutput, o.Out, info.Mapping.Resource, info.Name, o.DryRun, "configured")
} else { } else {
err := o.formatPrinter(o.Output, patch.Patch, o.Out) err := o.formatPrinter(o.Output, patch.Patch, o.Out)
if err != nil { if err != nil {
return err return err
} }
f.PrintSuccess(o.Mapper, o.ShortOutput, o.Out, info.Mapping.Resource, info.Name, o.DryRun, "configured") f.PrintSuccess(o.ShortOutput, o.Out, info.Mapping.Resource, info.Name, o.DryRun, "configured")
} }
} }
return nil return nil

View File

@ -415,7 +415,7 @@ func TestApplyObjectWithoutAnnotation(t *testing.T) {
cmd.Run(cmd, []string{}) cmd.Run(cmd, []string{})
// uses the name from the file, not the response // uses the name from the file, not the response
expectRC := "replicationcontroller/" + nameRC + "\n" expectRC := "replicationcontrollers/" + nameRC + "\n"
expectWarning := fmt.Sprintf(warningNoLastAppliedConfigAnnotation, "kubectl") expectWarning := fmt.Sprintf(warningNoLastAppliedConfigAnnotation, "kubectl")
if errBuf.String() != expectWarning { if errBuf.String() != expectWarning {
t.Fatalf("unexpected non-warning: %s\nexpected: %s", errBuf.String(), expectWarning) t.Fatalf("unexpected non-warning: %s\nexpected: %s", errBuf.String(), expectWarning)
@ -461,7 +461,7 @@ func TestApplyObject(t *testing.T) {
cmd.Run(cmd, []string{}) cmd.Run(cmd, []string{})
// uses the name from the file, not the response // uses the name from the file, not the response
expectRC := "replicationcontroller/" + nameRC + "\n" expectRC := "replicationcontrollers/" + nameRC + "\n"
if buf.String() != expectRC { if buf.String() != expectRC {
t.Fatalf("unexpected output: %s\nexpected: %s", buf.String(), expectRC) t.Fatalf("unexpected output: %s\nexpected: %s", buf.String(), expectRC)
} }
@ -586,7 +586,7 @@ func TestApplyRetry(t *testing.T) {
} }
// uses the name from the file, not the response // uses the name from the file, not the response
expectRC := "replicationcontroller/" + nameRC + "\n" expectRC := "replicationcontrollers/" + nameRC + "\n"
if buf.String() != expectRC { if buf.String() != expectRC {
t.Fatalf("unexpected output: %s\nexpected: %s", buf.String(), expectRC) t.Fatalf("unexpected output: %s\nexpected: %s", buf.String(), expectRC)
} }
@ -630,7 +630,7 @@ func TestApplyNonExistObject(t *testing.T) {
cmd.Run(cmd, []string{}) cmd.Run(cmd, []string{})
// uses the name from the file, not the response // uses the name from the file, not the response
expectRC := "replicationcontroller/" + nameRC + "\n" expectRC := "replicationcontrollers/" + nameRC + "\n"
if buf.String() != expectRC { if buf.String() != expectRC {
t.Errorf("unexpected output: %s\nexpected: %s", buf.String(), expectRC) t.Errorf("unexpected output: %s\nexpected: %s", buf.String(), expectRC)
} }
@ -683,7 +683,7 @@ func TestApplyEmptyPatch(t *testing.T) {
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
cmd.Run(cmd, []string{}) cmd.Run(cmd, []string{})
expectRC := "replicationcontroller/" + nameRC + "\n" expectRC := "replicationcontrollers/" + nameRC + "\n"
if buf.String() != expectRC { if buf.String() != expectRC {
t.Fatalf("unexpected output: %s\nexpected: %s", buf.String(), expectRC) t.Fatalf("unexpected output: %s\nexpected: %s", buf.String(), expectRC)
} }
@ -764,8 +764,8 @@ func testApplyMultipleObjects(t *testing.T, asList bool) {
cmd.Run(cmd, []string{}) cmd.Run(cmd, []string{})
// Names should come from the REST response, NOT the files // Names should come from the REST response, NOT the files
expectRC := "replicationcontroller/" + nameRC + "\n" expectRC := "replicationcontrollers/" + nameRC + "\n"
expectSVC := "service/" + nameSVC + "\n" expectSVC := "services/" + nameSVC + "\n"
// Test both possible orders since output is non-deterministic. // Test both possible orders since output is non-deterministic.
expectOne := expectRC + expectSVC expectOne := expectRC + expectSVC
expectTwo := expectSVC + expectRC expectTwo := expectSVC + expectRC
@ -855,7 +855,7 @@ func TestApplyNULLPreservation(t *testing.T) {
cmd.Run(cmd, []string{}) cmd.Run(cmd, []string{})
expected := "deployment/" + deploymentName + "\n" expected := "deployments/" + deploymentName + "\n"
if buf.String() != expected { if buf.String() != expected {
t.Fatalf("unexpected output: %s\nexpected: %s", buf.String(), expected) t.Fatalf("unexpected output: %s\nexpected: %s", buf.String(), expected)
} }
@ -918,7 +918,7 @@ func TestUnstructuredApply(t *testing.T) {
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
cmd.Run(cmd, []string{}) cmd.Run(cmd, []string{})
expected := "widget/" + name + "\n" expected := "widgets/" + name + "\n"
if buf.String() != expected { if buf.String() != expected {
t.Fatalf("unexpected output: %s\nexpected: %s", buf.String(), expected) t.Fatalf("unexpected output: %s\nexpected: %s", buf.String(), expected)
} }
@ -1009,7 +1009,7 @@ func TestUnstructuredIdempotentApply(t *testing.T) {
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
cmd.Run(cmd, []string{}) cmd.Run(cmd, []string{})
expected := "widget/widget\n" expected := "widgets/widget\n"
if buf.String() != expected { if buf.String() != expected {
t.Fatalf("unexpected output: %s\nexpected: %s", buf.String(), expected) t.Fatalf("unexpected output: %s\nexpected: %s", buf.String(), expected)
} }
@ -1040,7 +1040,7 @@ func TestRunApplySetLastApplied(t *testing.T) {
name: "set with exist object", name: "set with exist object",
filePath: filenameRC, filePath: filenameRC,
expectedErr: "", expectedErr: "",
expectedOut: "replicationcontroller/test-rc\n", expectedOut: "replicationcontrollers/test-rc\n",
output: "name", output: "name",
}, },
{ {
@ -1061,14 +1061,14 @@ func TestRunApplySetLastApplied(t *testing.T) {
name: "set with exist object output json", name: "set with exist object output json",
filePath: filenameRCJSON, filePath: filenameRCJSON,
expectedErr: "", expectedErr: "",
expectedOut: "replicationcontroller/test-rc\n", expectedOut: "replicationcontrollers/test-rc\n",
output: "name", output: "name",
}, },
{ {
name: "set test for a directory of files", name: "set test for a directory of files",
filePath: dirName, filePath: dirName,
expectedErr: "", expectedErr: "",
expectedOut: "replicationcontroller/test-rc\nreplicationcontroller/test-rc\n", expectedOut: "replicationcontrollers/test-rc\nreplicationcontrollers/test-rc\n",
output: "name", output: "name",
}, },
} }
@ -1243,7 +1243,7 @@ func TestForceApply(t *testing.T) {
} }
} }
if expected := "replicationcontroller/" + nameRC + "\n"; buf.String() != expected { if expected := "replicationcontrollers/" + nameRC + "\n"; buf.String() != expected {
t.Fatalf("unexpected output: %s\nexpected: %s", buf.String(), expected) t.Fatalf("unexpected output: %s\nexpected: %s", buf.String(), expected)
} }
if errBuf.String() != "" { if errBuf.String() != "" {

View File

@ -114,7 +114,6 @@ func (o *ReconcileOptions) Complete(cmd *cobra.Command, f cmdutil.Factory, args
o.RBACClient = client.Rbac() o.RBACClient = client.Rbac()
o.NamespaceClient = client.Core().Namespaces() o.NamespaceClient = client.Core().Namespaces()
mapper, _ := f.Object()
dryRun := false dryRun := false
output := cmdutil.GetFlagString(cmd, "output") output := cmdutil.GetFlagString(cmd, "output")
shortOutput := output == "name" shortOutput := output == "name"
@ -122,7 +121,7 @@ func (o *ReconcileOptions) Complete(cmd *cobra.Command, f cmdutil.Factory, args
if len(output) > 0 && !shortOutput { if len(output) > 0 && !shortOutput {
return f.PrintResourceInfoForCommand(cmd, info, o.Out) return f.PrintResourceInfoForCommand(cmd, info, o.Out)
} }
f.PrintSuccess(mapper, shortOutput, o.Out, info.Mapping.Resource, info.Name, dryRun, "reconciled") f.PrintSuccess(shortOutput, o.Out, info.Mapping.Resource, info.Name, dryRun, "reconciled")
return nil return nil
} }

View File

@ -173,7 +173,7 @@ func RunAutoscale(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []s
return f.PrintObject(cmd, false, mapper, object, out) return f.PrintObject(cmd, false, mapper, object, out)
} }
f.PrintSuccess(mapper, false, out, info.Mapping.Resource, info.Name, cmdutil.GetDryRunFlag(cmd), "autoscaled") f.PrintSuccess(false, out, info.Mapping.Resource, info.Name, cmdutil.GetDryRunFlag(cmd), "autoscaled")
return nil return nil
}) })
if err != nil { if err != nil {

View File

@ -165,7 +165,6 @@ func (options *CertificateOptions) RunCertificateDeny(f cmdutil.Factory, out io.
func (options *CertificateOptions) modifyCertificateCondition(f cmdutil.Factory, out io.Writer, modify func(csr *certificates.CertificateSigningRequest) (*certificates.CertificateSigningRequest, string)) error { func (options *CertificateOptions) modifyCertificateCondition(f cmdutil.Factory, out io.Writer, modify func(csr *certificates.CertificateSigningRequest) (*certificates.CertificateSigningRequest, string)) error {
var found int var found int
mapper, _ := f.Object()
c, err := f.ClientSet() c, err := f.ClientSet()
if err != nil { if err != nil {
return err return err
@ -192,7 +191,7 @@ func (options *CertificateOptions) modifyCertificateCondition(f cmdutil.Factory,
return err return err
} }
found++ found++
f.PrintSuccess(mapper, options.outputStyle == "name", out, info.Mapping.Resource, info.Name, false, verb) f.PrintSuccess(options.outputStyle == "name", out, info.Mapping.Resource, info.Name, false, verb)
return nil return nil
}) })
if found == 0 { if found == 0 {

View File

@ -185,7 +185,6 @@ func (o *CreateOptions) RunCreate(f cmdutil.Factory, cmd *cobra.Command) error {
dryRun := cmdutil.GetDryRunFlag(cmd) dryRun := cmdutil.GetDryRunFlag(cmd)
output := cmdutil.GetFlagString(cmd, "output") output := cmdutil.GetFlagString(cmd, "output")
mapper := r.Mapper().RESTMapper
count := 0 count := 0
err = r.Visit(func(info *resource.Info, err error) error { err = r.Visit(func(info *resource.Info, err error) error {
@ -218,7 +217,7 @@ func (o *CreateOptions) RunCreate(f cmdutil.Factory, cmd *cobra.Command) error {
f.PrintObjectSpecificMessage(info.Object, o.Out) f.PrintObjectSpecificMessage(info.Object, o.Out)
} }
f.PrintSuccess(mapper, shortOutput, o.Out, info.Mapping.Resource, info.Name, dryRun, "created") f.PrintSuccess(shortOutput, o.Out, info.Mapping.Resource, info.Name, dryRun, "created")
return nil return nil
}) })
if err != nil { if err != nil {
@ -357,7 +356,7 @@ func RunCreateSubcommand(f cmdutil.Factory, cmd *cobra.Command, out io.Writer, o
} }
if useShortOutput := options.OutputFormat == "name"; useShortOutput || len(options.OutputFormat) == 0 { if useShortOutput := options.OutputFormat == "name"; useShortOutput || len(options.OutputFormat) == 0 {
f.PrintSuccess(mapper, useShortOutput, out, mapping.Resource, info.Name, options.DryRun, "created") f.PrintSuccess(useShortOutput, out, mapping.Resource, info.Name, options.DryRun, "created")
return nil return nil
} }

View File

@ -173,7 +173,7 @@ func (c *CreateClusterRoleOptions) RunCreateRole() error {
} }
if useShortOutput := c.OutputFormat == "name"; useShortOutput || len(c.OutputFormat) == 0 { if useShortOutput := c.OutputFormat == "name"; useShortOutput || len(c.OutputFormat) == 0 {
c.PrintSuccess(c.Mapper, useShortOutput, c.Out, "clusterroles", c.Name, c.DryRun, "created") c.PrintSuccess(useShortOutput, c.Out, "clusterroles", c.Name, c.DryRun, "created")
return nil return nil
} }

View File

@ -107,7 +107,7 @@ func TestCreateClusterRoleBinding(t *testing.T) {
}, },
} }
expectedOutput := "clusterrolebinding/" + expectBinding.Name + "\n" expectedOutput := "clusterrolebindings/" + expectBinding.Name + "\n"
buf := bytes.NewBuffer([]byte{}) buf := bytes.NewBuffer([]byte{})
cmd := NewCmdCreateClusterRoleBinding(f, buf) cmd := NewCmdCreateClusterRoleBinding(f, buf)
cmd.Flags().Set("clusterrole", "fake-clusterrole") cmd.Flags().Set("clusterrole", "fake-clusterrole")

View File

@ -50,7 +50,7 @@ func TestCreateConfigMap(t *testing.T) {
cmd := NewCmdCreateConfigMap(f, buf) cmd := NewCmdCreateConfigMap(f, buf)
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
cmd.Run(cmd, []string{configMap.Name}) cmd.Run(cmd, []string{configMap.Name})
expectedOutput := "configmap/" + configMap.Name + "\n" expectedOutput := "configmaps/" + configMap.Name + "\n"
if buf.String() != expectedOutput { if buf.String() != expectedOutput {
t.Errorf("expected output: %s, but got: %s", expectedOutput, buf.String()) t.Errorf("expected output: %s, but got: %s", expectedOutput, buf.String())
} }

View File

@ -93,7 +93,7 @@ func TestCreateDeployment(t *testing.T) {
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
cmd.Flags().Set("image", "hollywood/jonny.depp:v2") cmd.Flags().Set("image", "hollywood/jonny.depp:v2")
cmd.Run(cmd, []string{depName}) cmd.Run(cmd, []string{depName})
expectedOutput := "deployment/" + depName + "\n" expectedOutput := "deployments/" + depName + "\n"
if buf.String() != expectedOutput { if buf.String() != expectedOutput {
t.Errorf("expected output: %s, but got: %s", expectedOutput, buf.String()) t.Errorf("expected output: %s, but got: %s", expectedOutput, buf.String())
} }

View File

@ -49,7 +49,7 @@ func TestCreateNamespace(t *testing.T) {
cmd := NewCmdCreateNamespace(f, buf) cmd := NewCmdCreateNamespace(f, buf)
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
cmd.Run(cmd, []string{namespaceObject.Name}) cmd.Run(cmd, []string{namespaceObject.Name})
expectedOutput := "namespace/" + namespaceObject.Name + "\n" expectedOutput := "namespaces/" + namespaceObject.Name + "\n"
if buf.String() != expectedOutput { if buf.String() != expectedOutput {
t.Errorf("expected output: %s, but got: %s", expectedOutput, buf.String()) t.Errorf("expected output: %s, but got: %s", expectedOutput, buf.String())
} }

View File

@ -52,7 +52,7 @@ func TestCreatePdb(t *testing.T) {
cmd.Flags().Set("dry-run", "true") cmd.Flags().Set("dry-run", "true")
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
CreatePodDisruptionBudget(f, buf, cmd, []string{pdbName}) CreatePodDisruptionBudget(f, buf, cmd, []string{pdbName})
expectedOutput := "poddisruptionbudget/" + pdbName + "\n" expectedOutput := "poddisruptionbudgets/" + pdbName + "\n"
if buf.String() != expectedOutput { if buf.String() != expectedOutput {
t.Errorf("expected output: %s, but got: %s", expectedOutput, buf.String()) t.Errorf("expected output: %s, but got: %s", expectedOutput, buf.String())
} }

View File

@ -52,7 +52,7 @@ func TestCreatePriorityClass(t *testing.T) {
cmd.Flags().Set("dry-run", "true") cmd.Flags().Set("dry-run", "true")
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
CreatePriorityClass(f, buf, cmd, []string{pcName}) CreatePriorityClass(f, buf, cmd, []string{pcName})
expectedOutput := "priorityclass/" + pcName + "\n" expectedOutput := "priorityclasses/" + pcName + "\n"
if buf.String() != expectedOutput { if buf.String() != expectedOutput {
t.Errorf("expected output: %s, but got: %s", expectedOutput, buf.String()) t.Errorf("expected output: %s, but got: %s", expectedOutput, buf.String())
} }

View File

@ -53,19 +53,19 @@ func TestCreateQuota(t *testing.T) {
}{ }{
"single resource": { "single resource": {
flags: []string{"--hard=cpu=1"}, flags: []string{"--hard=cpu=1"},
expectedOutput: "resourcequota/" + resourceQuotaObject.Name + "\n", expectedOutput: "resourcequotas/" + resourceQuotaObject.Name + "\n",
}, },
"single resource with a scope": { "single resource with a scope": {
flags: []string{"--hard=cpu=1", "--scopes=BestEffort"}, flags: []string{"--hard=cpu=1", "--scopes=BestEffort"},
expectedOutput: "resourcequota/" + resourceQuotaObject.Name + "\n", expectedOutput: "resourcequotas/" + resourceQuotaObject.Name + "\n",
}, },
"multiple resources": { "multiple resources": {
flags: []string{"--hard=cpu=1,pods=42", "--scopes=BestEffort"}, flags: []string{"--hard=cpu=1,pods=42", "--scopes=BestEffort"},
expectedOutput: "resourcequota/" + resourceQuotaObject.Name + "\n", expectedOutput: "resourcequotas/" + resourceQuotaObject.Name + "\n",
}, },
"single resource with multiple scopes": { "single resource with multiple scopes": {
flags: []string{"--hard=cpu=1", "--scopes=BestEffort,NotTerminating"}, flags: []string{"--hard=cpu=1", "--scopes=BestEffort,NotTerminating"},
expectedOutput: "resourcequota/" + resourceQuotaObject.Name + "\n", expectedOutput: "resourcequotas/" + resourceQuotaObject.Name + "\n",
}, },
} }
for name, test := range tests { for name, test := range tests {

View File

@ -112,7 +112,7 @@ type CreateRoleOptions struct {
Mapper meta.RESTMapper Mapper meta.RESTMapper
Out io.Writer Out io.Writer
PrintObject func(obj runtime.Object) error PrintObject func(obj runtime.Object) error
PrintSuccess func(mapper meta.RESTMapper, shortOutput bool, out io.Writer, resource, name string, dryRun bool, operation string) PrintSuccess func(shortOutput bool, out io.Writer, resource, name string, dryRun bool, operation string)
} }
// Role is a command to ease creating Roles. // Role is a command to ease creating Roles.
@ -295,7 +295,7 @@ func (c *CreateRoleOptions) RunCreateRole() error {
} }
if useShortOutput := c.OutputFormat == "name"; useShortOutput || len(c.OutputFormat) == 0 { if useShortOutput := c.OutputFormat == "name"; useShortOutput || len(c.OutputFormat) == 0 {
c.PrintSuccess(c.Mapper, useShortOutput, c.Out, "roles", c.Name, c.DryRun, "created") c.PrintSuccess(useShortOutput, c.Out, "roles", c.Name, c.DryRun, "created")
return nil return nil
} }

View File

@ -57,7 +57,7 @@ func TestCreateSecretGeneric(t *testing.T) {
cmd.Flags().Set("from-literal", "password=includes,comma") cmd.Flags().Set("from-literal", "password=includes,comma")
cmd.Flags().Set("from-literal", "username=test_user") cmd.Flags().Set("from-literal", "username=test_user")
cmd.Run(cmd, []string{secretObject.Name}) cmd.Run(cmd, []string{secretObject.Name})
expectedOutput := "secret/" + secretObject.Name + "\n" expectedOutput := "secrets/" + secretObject.Name + "\n"
if buf.String() != expectedOutput { if buf.String() != expectedOutput {
t.Errorf("expected output: %s, but got: %s", expectedOutput, buf.String()) t.Errorf("expected output: %s, but got: %s", expectedOutput, buf.String())
} }
@ -89,7 +89,7 @@ func TestCreateSecretDockerRegistry(t *testing.T) {
cmd.Flags().Set("docker-email", "test-email") cmd.Flags().Set("docker-email", "test-email")
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
cmd.Run(cmd, []string{secretObject.Name}) cmd.Run(cmd, []string{secretObject.Name})
expectedOutput := "secret/" + secretObject.Name + "\n" expectedOutput := "secrets/" + secretObject.Name + "\n"
if buf.String() != expectedOutput { if buf.String() != expectedOutput {
t.Errorf("expected output: %s, but got: %s", buf.String(), expectedOutput) t.Errorf("expected output: %s, but got: %s", buf.String(), expectedOutput)
} }

View File

@ -51,7 +51,7 @@ func TestCreateService(t *testing.T) {
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
cmd.Flags().Set("tcp", "8080:8000") cmd.Flags().Set("tcp", "8080:8000")
cmd.Run(cmd, []string{service.Name}) cmd.Run(cmd, []string{service.Name})
expectedOutput := "service/" + service.Name + "\n" expectedOutput := "services/" + service.Name + "\n"
if buf.String() != expectedOutput { if buf.String() != expectedOutput {
t.Errorf("expected output: %s, but got: %s", expectedOutput, buf.String()) t.Errorf("expected output: %s, but got: %s", expectedOutput, buf.String())
} }
@ -81,7 +81,7 @@ func TestCreateServiceNodePort(t *testing.T) {
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
cmd.Flags().Set("tcp", "30000:8000") cmd.Flags().Set("tcp", "30000:8000")
cmd.Run(cmd, []string{service.Name}) cmd.Run(cmd, []string{service.Name})
expectedOutput := "service/" + service.Name + "\n" expectedOutput := "services/" + service.Name + "\n"
if buf.String() != expectedOutput { if buf.String() != expectedOutput {
t.Errorf("expected output: %s, but got: %s", expectedOutput, buf.String()) t.Errorf("expected output: %s, but got: %s", expectedOutput, buf.String())
} }
@ -111,7 +111,7 @@ func TestCreateServiceExternalName(t *testing.T) {
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
cmd.Flags().Set("external-name", "name") cmd.Flags().Set("external-name", "name")
cmd.Run(cmd, []string{service.Name}) cmd.Run(cmd, []string{service.Name})
expectedOutput := "service/" + service.Name + "\n" expectedOutput := "services/" + service.Name + "\n"
if buf.String() != expectedOutput { if buf.String() != expectedOutput {
t.Errorf("expected output: %s, but got: %s", expectedOutput, buf.String()) t.Errorf("expected output: %s, but got: %s", expectedOutput, buf.String())
} }

View File

@ -50,7 +50,7 @@ func TestCreateServiceAccount(t *testing.T) {
cmd := NewCmdCreateServiceAccount(f, buf) cmd := NewCmdCreateServiceAccount(f, buf)
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
cmd.Run(cmd, []string{serviceAccountObject.Name}) cmd.Run(cmd, []string{serviceAccountObject.Name})
expectedOutput := "serviceaccount/" + serviceAccountObject.Name + "\n" expectedOutput := "serviceaccounts/" + serviceAccountObject.Name + "\n"
if buf.String() != expectedOutput { if buf.String() != expectedOutput {
t.Errorf("expected output: %s, but got: %s", expectedOutput, buf.String()) t.Errorf("expected output: %s, but got: %s", expectedOutput, buf.String())
} }

View File

@ -69,7 +69,7 @@ func TestCreateObject(t *testing.T) {
cmd.Run(cmd, []string{}) cmd.Run(cmd, []string{})
// uses the name from the file, not the response // uses the name from the file, not the response
if buf.String() != "replicationcontroller/redis-master-controller\n" { if buf.String() != "replicationcontrollers/redis-master-controller\n" {
t.Errorf("unexpected output: %s", buf.String()) t.Errorf("unexpected output: %s", buf.String())
} }
} }
@ -106,7 +106,7 @@ func TestCreateMultipleObject(t *testing.T) {
cmd.Run(cmd, []string{}) cmd.Run(cmd, []string{})
// Names should come from the REST response, NOT the files // Names should come from the REST response, NOT the files
if buf.String() != "replicationcontroller/rc1\nservice/baz\n" { if buf.String() != "replicationcontrollers/rc1\nservices/baz\n" {
t.Errorf("unexpected output: %s", buf.String()) t.Errorf("unexpected output: %s", buf.String())
} }
} }
@ -140,7 +140,7 @@ func TestCreateDirectory(t *testing.T) {
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
cmd.Run(cmd, []string{}) cmd.Run(cmd, []string{})
if buf.String() != "replicationcontroller/name\nreplicationcontroller/name\nreplicationcontroller/name\n" { if buf.String() != "replicationcontrollers/name\nreplicationcontrollers/name\nreplicationcontrollers/name\n" {
t.Errorf("unexpected output: %s", buf.String()) t.Errorf("unexpected output: %s", buf.String())
} }
} }

View File

@ -259,7 +259,7 @@ func ReapResult(r *resource.Result, f cmdutil.Factory, out io.Writer, isDefaultD
} }
} }
if !quiet { if !quiet {
f.PrintSuccess(mapper, shortOutput, out, info.Mapping.Resource, info.Name, false, "deleted") f.PrintSuccess(shortOutput, out, info.Mapping.Resource, info.Name, false, "deleted")
} }
return nil return nil
}) })
@ -311,7 +311,7 @@ func deleteResource(info *resource.Info, f cmdutil.Factory, out io.Writer, short
if err := resource.NewHelper(info.Client, info.Mapping).DeleteWithOptions(info.Namespace, info.Name, deleteOptions); err != nil { if err := resource.NewHelper(info.Client, info.Mapping).DeleteWithOptions(info.Namespace, info.Name, deleteOptions); err != nil {
return cmdutil.AddSourceToErr("deleting", info.Source, err) return cmdutil.AddSourceToErr("deleting", info.Source, err)
} }
f.PrintSuccess(mapper, shortOutput, out, info.Mapping.Resource, info.Name, false, "deleted") f.PrintSuccess(shortOutput, out, info.Mapping.Resource, info.Name, false, "deleted")
return nil return nil
} }

View File

@ -84,7 +84,7 @@ func TestDeleteObjectByTuple(t *testing.T) {
cmd.Flags().Set("cascade", "false") cmd.Flags().Set("cascade", "false")
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
cmd.Run(cmd, []string{"replicationcontrollers/redis-master-controller"}) cmd.Run(cmd, []string{"replicationcontrollers/redis-master-controller"})
if buf.String() != "replicationcontroller/redis-master-controller\n" { if buf.String() != "replicationcontrollers/redis-master-controller\n" {
t.Errorf("unexpected output: %s", buf.String()) t.Errorf("unexpected output: %s", buf.String())
} }
@ -94,7 +94,7 @@ func TestDeleteObjectByTuple(t *testing.T) {
cmd.Flags().Set("namespace", "test") cmd.Flags().Set("namespace", "test")
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
cmd.Run(cmd, []string{"secrets/mysecret"}) cmd.Run(cmd, []string{"secrets/mysecret"})
if buf.String() != "secret/mysecret\n" { if buf.String() != "secrets/mysecret\n" {
t.Errorf("unexpected output: %s", buf.String()) t.Errorf("unexpected output: %s", buf.String())
} }
} }
@ -143,7 +143,7 @@ func TestOrphanDependentsInDeleteObject(t *testing.T) {
cmd.Flags().Set("namespace", "test") cmd.Flags().Set("namespace", "test")
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
cmd.Run(cmd, []string{"secrets/mysecret"}) cmd.Run(cmd, []string{"secrets/mysecret"})
if buf.String() != "secret/mysecret\n" { if buf.String() != "secrets/mysecret\n" {
t.Errorf("unexpected output: %s", buf.String()) t.Errorf("unexpected output: %s", buf.String())
} }
@ -156,7 +156,7 @@ func TestOrphanDependentsInDeleteObject(t *testing.T) {
cmd.Flags().Set("cascade", "false") cmd.Flags().Set("cascade", "false")
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
cmd.Run(cmd, []string{"secrets/mysecret"}) cmd.Run(cmd, []string{"secrets/mysecret"})
if buf.String() != "secret/mysecret\n" { if buf.String() != "secrets/mysecret\n" {
t.Errorf("unexpected output: %s", buf.String()) t.Errorf("unexpected output: %s", buf.String())
} }
} }
@ -196,7 +196,7 @@ func TestDeleteNamedObject(t *testing.T) {
cmd.Flags().Set("cascade", "false") cmd.Flags().Set("cascade", "false")
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
cmd.Run(cmd, []string{"replicationcontrollers", "redis-master-controller"}) cmd.Run(cmd, []string{"replicationcontrollers", "redis-master-controller"})
if buf.String() != "replicationcontroller/redis-master-controller\n" { if buf.String() != "replicationcontrollers/redis-master-controller\n" {
t.Errorf("unexpected output: %s", buf.String()) t.Errorf("unexpected output: %s", buf.String())
} }
@ -207,7 +207,7 @@ func TestDeleteNamedObject(t *testing.T) {
cmd.Flags().Set("cascade", "false") cmd.Flags().Set("cascade", "false")
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
cmd.Run(cmd, []string{"secrets", "mysecret"}) cmd.Run(cmd, []string{"secrets", "mysecret"})
if buf.String() != "secret/mysecret\n" { if buf.String() != "secrets/mysecret\n" {
t.Errorf("unexpected output: %s", buf.String()) t.Errorf("unexpected output: %s", buf.String())
} }
} }
@ -240,7 +240,7 @@ func TestDeleteObject(t *testing.T) {
cmd.Run(cmd, []string{}) cmd.Run(cmd, []string{})
// uses the name from the file, not the response // uses the name from the file, not the response
if buf.String() != "replicationcontroller/redis-master\n" { if buf.String() != "replicationcontrollers/redis-master\n" {
t.Errorf("unexpected output: %s", buf.String()) t.Errorf("unexpected output: %s", buf.String())
} }
} }
@ -310,7 +310,7 @@ func TestDeleteObjectGraceZero(t *testing.T) {
cmd.Run(cmd, []string{"pod/nginx"}) cmd.Run(cmd, []string{"pod/nginx"})
// uses the name from the file, not the response // uses the name from the file, not the response
if buf.String() != "pod/nginx\n" { if buf.String() != "pods/nginx\n" {
t.Errorf("unexpected output: %s\n---\n%s", buf.String(), errBuf.String()) t.Errorf("unexpected output: %s\n---\n%s", buf.String(), errBuf.String())
} }
if reaper.deleteOptions == nil || reaper.deleteOptions.GracePeriodSeconds == nil || *reaper.deleteOptions.GracePeriodSeconds != 1 { if reaper.deleteOptions == nil || reaper.deleteOptions.GracePeriodSeconds == nil || *reaper.deleteOptions.GracePeriodSeconds != 1 {
@ -473,7 +473,7 @@ func TestDeleteAllIgnoreNotFound(t *testing.T) {
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
cmd.Run(cmd, []string{"services"}) cmd.Run(cmd, []string{"services"})
if buf.String() != "service/baz\n" { if buf.String() != "services/baz\n" {
t.Errorf("unexpected output: %s", buf.String()) t.Errorf("unexpected output: %s", buf.String())
} }
} }
@ -508,7 +508,7 @@ func TestDeleteMultipleObject(t *testing.T) {
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
cmd.Run(cmd, []string{}) cmd.Run(cmd, []string{})
if buf.String() != "replicationcontroller/redis-master\nservice/frontend\n" { if buf.String() != "replicationcontrollers/redis-master\nservices/frontend\n" {
t.Errorf("unexpected output: %s", buf.String()) t.Errorf("unexpected output: %s", buf.String())
} }
} }
@ -553,7 +553,7 @@ func TestDeleteMultipleObjectContinueOnMissing(t *testing.T) {
t.Errorf("unexpected error: expected NotFound, got %v", err) t.Errorf("unexpected error: expected NotFound, got %v", err)
} }
if buf.String() != "service/frontend\n" { if buf.String() != "services/frontend\n" {
t.Errorf("unexpected output: %s", buf.String()) t.Errorf("unexpected output: %s", buf.String())
} }
} }
@ -590,7 +590,7 @@ func TestDeleteMultipleResourcesWithTheSameName(t *testing.T) {
cmd.Flags().Set("cascade", "false") cmd.Flags().Set("cascade", "false")
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
cmd.Run(cmd, []string{"replicationcontrollers,services", "baz", "foo"}) cmd.Run(cmd, []string{"replicationcontrollers,services", "baz", "foo"})
if buf.String() != "replicationcontroller/baz\nreplicationcontroller/foo\nservice/baz\nservice/foo\n" { if buf.String() != "replicationcontrollers/baz\nreplicationcontrollers/foo\nservices/baz\nservices/foo\n" {
t.Errorf("unexpected output: %s", buf.String()) t.Errorf("unexpected output: %s", buf.String())
} }
} }
@ -622,7 +622,7 @@ func TestDeleteDirectory(t *testing.T) {
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
cmd.Run(cmd, []string{}) cmd.Run(cmd, []string{})
if buf.String() != "replicationcontroller/frontend\nreplicationcontroller/redis-master\nreplicationcontroller/redis-slave\n" { if buf.String() != "replicationcontrollers/frontend\nreplicationcontrollers/redis-master\nreplicationcontrollers/redis-slave\n" {
t.Errorf("unexpected output: %s", buf.String()) t.Errorf("unexpected output: %s", buf.String())
} }
} }
@ -666,7 +666,7 @@ func TestDeleteMultipleSelector(t *testing.T) {
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
cmd.Run(cmd, []string{"pods,services"}) cmd.Run(cmd, []string{"pods,services"})
if buf.String() != "pod/foo\npod/bar\nservice/baz\n" { if buf.String() != "pods/foo\npods/bar\nservices/baz\n" {
t.Errorf("unexpected output: %s", buf.String()) t.Errorf("unexpected output: %s", buf.String())
} }
} }

View File

@ -242,7 +242,6 @@ func (o *DrainOptions) SetupDrain(cmd *cobra.Command, args []string) error {
} }
o.nodeInfos = []*resource.Info{} o.nodeInfos = []*resource.Info{}
o.mapper, o.typer = o.Factory.Object()
cmdNamespace, _, err := o.Factory.DefaultNamespace() cmdNamespace, _, err := o.Factory.DefaultNamespace()
if err != nil { if err != nil {
@ -296,7 +295,7 @@ func (o *DrainOptions) RunDrain() error {
} }
if err == nil || o.DryRun { if err == nil || o.DryRun {
drainedNodes.Insert(info.Name) drainedNodes.Insert(info.Name)
o.Factory.PrintSuccess(o.mapper, false, o.Out, "node", info.Name, o.DryRun, "drained") o.Factory.PrintSuccess(false, o.Out, "node", info.Name, o.DryRun, "drained")
} else { } else {
fmt.Fprintf(o.ErrOut, "error: unable to drain node %q, aborting command...\n\n", info.Name) fmt.Fprintf(o.ErrOut, "error: unable to drain node %q, aborting command...\n\n", info.Name)
remainingNodes := []string{} remainingNodes := []string{}
@ -617,7 +616,7 @@ func (o *DrainOptions) waitForDelete(pods []corev1.Pod, interval, timeout time.D
for i, pod := range pods { for i, pod := range pods {
p, err := getPodFn(pod.Namespace, pod.Name) p, err := getPodFn(pod.Namespace, pod.Name)
if apierrors.IsNotFound(err) || (p != nil && p.ObjectMeta.UID != pod.ObjectMeta.UID) { if apierrors.IsNotFound(err) || (p != nil && p.ObjectMeta.UID != pod.ObjectMeta.UID) {
o.Factory.PrintSuccess(o.mapper, false, o.Out, "pod", pod.Name, false, verbStr) o.Factory.PrintSuccess(false, o.Out, "pod", pod.Name, false, verbStr)
continue continue
} else if err != nil { } else if err != nil {
return false, err return false, err
@ -698,7 +697,7 @@ func (o *DrainOptions) RunCordonOrUncordon(desired bool) error {
} }
unsched := node.Spec.Unschedulable unsched := node.Spec.Unschedulable
if unsched == desired { if unsched == desired {
o.Factory.PrintSuccess(o.mapper, false, o.Out, nodeInfo.Mapping.Resource, nodeInfo.Name, o.DryRun, already(desired)) o.Factory.PrintSuccess(false, o.Out, nodeInfo.Mapping.Resource, nodeInfo.Name, o.DryRun, already(desired))
} else { } else {
if !o.DryRun { if !o.DryRun {
helper := resource.NewHelper(o.restClient, nodeInfo.Mapping) helper := resource.NewHelper(o.restClient, nodeInfo.Mapping)
@ -719,10 +718,10 @@ func (o *DrainOptions) RunCordonOrUncordon(desired bool) error {
continue continue
} }
} }
o.Factory.PrintSuccess(o.mapper, false, o.Out, nodeInfo.Mapping.Resource, nodeInfo.Name, o.DryRun, changed(desired)) o.Factory.PrintSuccess(false, o.Out, nodeInfo.Mapping.Resource, nodeInfo.Name, o.DryRun, changed(desired))
} }
} else { } else {
o.Factory.PrintSuccess(o.mapper, false, o.Out, nodeInfo.Mapping.Resource, nodeInfo.Name, o.DryRun, "skipped") o.Factory.PrintSuccess(false, o.Out, nodeInfo.Mapping.Resource, nodeInfo.Name, o.DryRun, "skipped")
} }
} }

View File

@ -257,7 +257,7 @@ func RunExpose(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []stri
if len(cmdutil.GetFlagString(cmd, "output")) > 0 { if len(cmdutil.GetFlagString(cmd, "output")) > 0 {
return f.PrintObject(cmd, false, mapper, object, out) return f.PrintObject(cmd, false, mapper, object, out)
} }
f.PrintSuccess(mapper, false, out, info.Mapping.Resource, info.Name, true, "exposed") f.PrintSuccess(false, out, info.Mapping.Resource, info.Name, true, "exposed")
return nil return nil
} }
if err := kubectl.CreateOrUpdateAnnotation(cmdutil.GetFlagBool(cmd, cmdutil.ApplyAnnotationsFlag), info, f.JSONEncoder()); err != nil { if err := kubectl.CreateOrUpdateAnnotation(cmdutil.GetFlagBool(cmd, cmdutil.ApplyAnnotationsFlag), info, f.JSONEncoder()); err != nil {
@ -274,7 +274,7 @@ func RunExpose(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []stri
return f.PrintObject(cmd, false, mapper, object, out) return f.PrintObject(cmd, false, mapper, object, out)
} }
f.PrintSuccess(mapper, false, out, info.Mapping.Resource, info.Name, false, "exposed") f.PrintSuccess(false, out, info.Mapping.Resource, info.Name, false, "exposed")
return nil return nil
}) })
if err != nil { if err != nil {

View File

@ -79,7 +79,7 @@ func TestRunExposeService(t *testing.T) {
Selector: map[string]string{"app": "go"}, Selector: map[string]string{"app": "go"},
}, },
}, },
expected: "service \"foo\" exposed", expected: "services \"foo\" exposed",
status: 200, status: 200,
}, },
{ {
@ -110,7 +110,7 @@ func TestRunExposeService(t *testing.T) {
Selector: map[string]string{"func": "stream"}, Selector: map[string]string{"func": "stream"},
}, },
}, },
expected: "service \"foo\" exposed", expected: "services \"foo\" exposed",
status: 200, status: 200,
}, },
{ {
@ -142,7 +142,7 @@ func TestRunExposeService(t *testing.T) {
Selector: map[string]string{"run": "this"}, Selector: map[string]string{"run": "this"},
}, },
}, },
expected: "service \"mayor\" exposed", expected: "services \"mayor\" exposed",
status: 200, status: 200,
}, },
{ {
@ -237,7 +237,7 @@ func TestRunExposeService(t *testing.T) {
ClusterIP: "10.10.10.10", ClusterIP: "10.10.10.10",
}, },
}, },
expected: "service \"foo\" exposed", expected: "services \"foo\" exposed",
status: 200, status: 200,
}, },
{ {
@ -269,7 +269,7 @@ func TestRunExposeService(t *testing.T) {
ClusterIP: api.ClusterIPNone, ClusterIP: api.ClusterIPNone,
}, },
}, },
expected: "service \"foo\" exposed", expected: "services \"foo\" exposed",
status: 200, status: 200,
}, },
{ {
@ -295,7 +295,7 @@ func TestRunExposeService(t *testing.T) {
ClusterIP: api.ClusterIPNone, ClusterIP: api.ClusterIPNone,
}, },
}, },
expected: "service \"foo\" exposed", expected: "services \"foo\" exposed",
status: 200, status: 200,
}, },
{ {
@ -353,7 +353,7 @@ func TestRunExposeService(t *testing.T) {
Selector: map[string]string{"svc": "frompod"}, Selector: map[string]string{"svc": "frompod"},
}, },
}, },
expected: "service \"a-name-that-is-toooo-big-for-a-service-because-it-can-only-hand\" exposed", expected: "services \"a-name-that-is-toooo-big-for-a-service-because-it-can-only-hand\" exposed",
status: 200, status: 200,
}, },
{ {
@ -501,7 +501,7 @@ func TestRunExposeService(t *testing.T) {
continue continue
} }
test.expected = fmt.Sprintf("service %q exposed (dry run)", test.flags["name"]) test.expected = fmt.Sprintf("services %q exposed (dry run)", test.flags["name"])
} }
if !strings.Contains(out, test.expected) { if !strings.Contains(out, test.expected) {

View File

@ -293,7 +293,7 @@ func (o *LabelOptions) RunLabel(f cmdutil.Factory, cmd *cobra.Command) error {
if o.outputFormat != "" { if o.outputFormat != "" {
return f.PrintObject(cmd, o.local, r.Mapper().RESTMapper, outputObj, o.out) return f.PrintObject(cmd, o.local, r.Mapper().RESTMapper, outputObj, o.out)
} }
f.PrintSuccess(r.Mapper().RESTMapper, false, o.out, info.Mapping.Resource, info.Name, o.dryrun, dataChangeMsg) f.PrintSuccess(false, o.out, info.Mapping.Resource, info.Name, o.dryrun, dataChangeMsg)
return nil return nil
}) })
} }

View File

@ -212,7 +212,7 @@ func RunPatch(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []strin
if len(options.OutputFormat) > 0 && options.OutputFormat != "name" { if len(options.OutputFormat) > 0 && options.OutputFormat != "name" {
return f.PrintResourceInfoForCommand(cmd, info, out) return f.PrintResourceInfoForCommand(cmd, info, out)
} }
f.PrintSuccess(r.Mapper().RESTMapper, options.OutputFormat == "name", out, info.Mapping.Resource, info.Name, false, dataChangedMsg) f.PrintSuccess(options.OutputFormat == "name", out, info.Mapping.Resource, info.Name, false, dataChangedMsg)
// if object was not successfully patched, exit with error code 1 // if object was not successfully patched, exit with error code 1
if !didPatch { if !didPatch {

View File

@ -60,7 +60,7 @@ func TestPatchObject(t *testing.T) {
cmd.Run(cmd, []string{"services/frontend"}) cmd.Run(cmd, []string{"services/frontend"})
// uses the name from the response // uses the name from the response
if buf.String() != "service/baz\n" { if buf.String() != "services/baz\n" {
t.Errorf("unexpected output: %s", buf.String()) t.Errorf("unexpected output: %s", buf.String())
} }
} }
@ -92,7 +92,7 @@ func TestPatchObjectFromFile(t *testing.T) {
cmd.Run(cmd, []string{}) cmd.Run(cmd, []string{})
// uses the name from the response // uses the name from the response
if buf.String() != "service/baz\n" { if buf.String() != "services/baz\n" {
t.Errorf("unexpected output: %s", buf.String()) t.Errorf("unexpected output: %s", buf.String())
} }
} }
@ -131,7 +131,7 @@ func TestPatchNoop(t *testing.T) {
cmd.Flags().Set("namespace", "test") cmd.Flags().Set("namespace", "test")
cmd.Flags().Set("patch", `{"metadata":{"annotations":{"foo":"bar"}}}`) cmd.Flags().Set("patch", `{"metadata":{"annotations":{"foo":"bar"}}}`)
cmd.Run(cmd, []string{"services", "frontend"}) cmd.Run(cmd, []string{"services", "frontend"})
if buf.String() != "service \"baz\" patched\n" { if buf.String() != "services \"baz\" patched\n" {
t.Errorf("unexpected output: %s", buf.String()) t.Errorf("unexpected output: %s", buf.String())
} }
} }

View File

@ -132,8 +132,6 @@ func RunReplace(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []str
return err return err
} }
mapper := r.Mapper().RESTMapper
return r.Visit(func(info *resource.Info, err error) error { return r.Visit(func(info *resource.Info, err error) error {
if err != nil { if err != nil {
return err return err
@ -157,7 +155,7 @@ func RunReplace(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []str
info.Refresh(obj, true) info.Refresh(obj, true)
f.PrintObjectSpecificMessage(obj, out) f.PrintObjectSpecificMessage(obj, out)
f.PrintSuccess(mapper, shortOutput, out, info.Mapping.Resource, info.Name, false, "replaced") f.PrintSuccess(shortOutput, out, info.Mapping.Resource, info.Name, false, "replaced")
return nil return nil
}) })
} }
@ -281,7 +279,7 @@ func forceReplace(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []s
count++ count++
info.Refresh(obj, true) info.Refresh(obj, true)
f.PrintObjectSpecificMessage(obj, out) f.PrintObjectSpecificMessage(obj, out)
f.PrintSuccess(mapper, shortOutput, out, info.Mapping.Resource, info.Name, false, "replaced") f.PrintSuccess(shortOutput, out, info.Mapping.Resource, info.Name, false, "replaced")
return nil return nil
}) })
if err != nil { if err != nil {

View File

@ -67,7 +67,7 @@ func TestReplaceObject(t *testing.T) {
cmd.Run(cmd, []string{}) cmd.Run(cmd, []string{})
// uses the name from the file, not the response // uses the name from the file, not the response
if buf.String() != "replicationcontroller/rc1\n" { if buf.String() != "replicationcontrollers/rc1\n" {
t.Errorf("unexpected output: %s", buf.String()) t.Errorf("unexpected output: %s", buf.String())
} }
@ -77,7 +77,7 @@ func TestReplaceObject(t *testing.T) {
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
cmd.Run(cmd, []string{}) cmd.Run(cmd, []string{})
if buf.String() != "replicationcontroller/redis-master\nreplicationcontroller/rc1\n" { if buf.String() != "replicationcontrollers/redis-master\nreplicationcontrollers/rc1\n" {
t.Errorf("unexpected output: %s", buf.String()) t.Errorf("unexpected output: %s", buf.String())
} }
} }
@ -136,7 +136,7 @@ func TestReplaceMultipleObject(t *testing.T) {
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
cmd.Run(cmd, []string{}) cmd.Run(cmd, []string{})
if buf.String() != "replicationcontroller/rc1\nservice/baz\n" { if buf.String() != "replicationcontrollers/rc1\nservices/baz\n" {
t.Errorf("unexpected output: %s", buf.String()) t.Errorf("unexpected output: %s", buf.String())
} }
@ -146,7 +146,7 @@ func TestReplaceMultipleObject(t *testing.T) {
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
cmd.Run(cmd, []string{}) cmd.Run(cmd, []string{})
if buf.String() != "replicationcontroller/redis-master\nservice/frontend\nreplicationcontroller/rc1\nservice/baz\n" { if buf.String() != "replicationcontrollers/redis-master\nservices/frontend\nreplicationcontrollers/rc1\nservices/baz\n" {
t.Errorf("unexpected output: %s", buf.String()) t.Errorf("unexpected output: %s", buf.String())
} }
} }
@ -192,7 +192,7 @@ func TestReplaceDirectory(t *testing.T) {
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
cmd.Run(cmd, []string{}) cmd.Run(cmd, []string{})
if buf.String() != "replicationcontroller/rc1\nreplicationcontroller/rc1\nreplicationcontroller/rc1\n" { if buf.String() != "replicationcontrollers/rc1\nreplicationcontrollers/rc1\nreplicationcontrollers/rc1\n" {
t.Errorf("unexpected output: %s", buf.String()) t.Errorf("unexpected output: %s", buf.String())
} }
@ -201,8 +201,8 @@ func TestReplaceDirectory(t *testing.T) {
cmd.Flags().Set("cascade", "false") cmd.Flags().Set("cascade", "false")
cmd.Run(cmd, []string{}) cmd.Run(cmd, []string{})
if buf.String() != "replicationcontroller/frontend\nreplicationcontroller/redis-master\nreplicationcontroller/redis-slave\n"+ if buf.String() != "replicationcontrollers/frontend\nreplicationcontrollers/redis-master\nreplicationcontrollers/redis-slave\n"+
"replicationcontroller/rc1\nreplicationcontroller/rc1\nreplicationcontroller/rc1\n" { "replicationcontrollers/rc1\nreplicationcontrollers/rc1\nreplicationcontrollers/rc1\n" {
t.Errorf("unexpected output: %s", buf.String()) t.Errorf("unexpected output: %s", buf.String())
} }
} }
@ -238,7 +238,7 @@ func TestForceReplaceObjectNotFound(t *testing.T) {
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
cmd.Run(cmd, []string{}) cmd.Run(cmd, []string{})
if buf.String() != "replicationcontroller/rc1\n" { if buf.String() != "replicationcontrollers/rc1\n" {
t.Errorf("unexpected output: %s", buf.String()) t.Errorf("unexpected output: %s", buf.String())
} }
} }

View File

@ -372,7 +372,7 @@ func RunRollingUpdate(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args
if outputFormat != "" { if outputFormat != "" {
return f.PrintObject(cmd, false, mapper, newRc, out) return f.PrintObject(cmd, false, mapper, newRc, out)
} }
f.PrintSuccess(mapper, false, out, "replicationcontrollers", oldName, dryrun, message) f.PrintSuccess(false, out, "replicationcontrollers", oldName, dryrun, message)
return nil return nil
} }

View File

@ -45,7 +45,7 @@ type PauseConfig struct {
Encoder runtime.Encoder Encoder runtime.Encoder
Infos []*resource.Info Infos []*resource.Info
PrintSuccess func(mapper meta.RESTMapper, shortOutput bool, out io.Writer, resource, name string, dryRun bool, operation string) PrintSuccess func(shortOutput bool, out io.Writer, resource, name string, dryRun bool, operation string)
Out io.Writer Out io.Writer
} }
@ -145,7 +145,7 @@ func (o PauseConfig) RunPause() error {
} }
if string(patch.Patch) == "{}" || len(patch.Patch) == 0 { if string(patch.Patch) == "{}" || len(patch.Patch) == 0 {
o.PrintSuccess(o.Mapper, false, o.Out, info.Mapping.Resource, info.Name, false, "already paused") o.PrintSuccess(false, o.Out, info.Mapping.Resource, info.Name, false, "already paused")
continue continue
} }
@ -156,7 +156,7 @@ func (o PauseConfig) RunPause() error {
} }
info.Refresh(obj, true) info.Refresh(obj, true)
o.PrintSuccess(o.Mapper, false, o.Out, info.Mapping.Resource, info.Name, false, "paused") o.PrintSuccess(false, o.Out, info.Mapping.Resource, info.Name, false, "paused")
} }
return utilerrors.NewAggregate(allErrs) return utilerrors.NewAggregate(allErrs)

View File

@ -45,7 +45,7 @@ type ResumeConfig struct {
Encoder runtime.Encoder Encoder runtime.Encoder
Infos []*resource.Info Infos []*resource.Info
PrintSuccess func(mapper meta.RESTMapper, shortOutput bool, out io.Writer, resource, name string, dryRun bool, operation string) PrintSuccess func(shortOutput bool, out io.Writer, resource, name string, dryRun bool, operation string)
Out io.Writer Out io.Writer
} }
@ -150,7 +150,7 @@ func (o ResumeConfig) RunResume() error {
} }
if string(patch.Patch) == "{}" || len(patch.Patch) == 0 { if string(patch.Patch) == "{}" || len(patch.Patch) == 0 {
o.PrintSuccess(o.Mapper, false, o.Out, info.Mapping.Resource, info.Name, false, "already resumed") o.PrintSuccess(false, o.Out, info.Mapping.Resource, info.Name, false, "already resumed")
continue continue
} }
@ -161,7 +161,7 @@ func (o ResumeConfig) RunResume() error {
} }
info.Refresh(obj, true) info.Refresh(obj, true)
o.PrintSuccess(o.Mapper, false, o.Out, info.Mapping.Resource, info.Name, false, "resumed") o.PrintSuccess(false, o.Out, info.Mapping.Resource, info.Name, false, "resumed")
} }
return utilerrors.NewAggregate(allErrs) return utilerrors.NewAggregate(allErrs)

View File

@ -43,7 +43,7 @@ type UndoOptions struct {
ToRevision int64 ToRevision int64
DryRun bool DryRun bool
PrintSuccess func(mapper meta.RESTMapper, shortOutput bool, out io.Writer, resource, name string, dryRun bool, operation string) PrintSuccess func(shortOutput bool, out io.Writer, resource, name string, dryRun bool, operation string)
Out io.Writer Out io.Writer
} }
@ -150,7 +150,7 @@ func (o *UndoOptions) RunUndo() error {
allErrs = append(allErrs, cmdutil.AddSourceToErr("undoing", info.Source, err)) allErrs = append(allErrs, cmdutil.AddSourceToErr("undoing", info.Source, err))
continue continue
} }
o.PrintSuccess(o.Mapper, false, o.Out, info.Mapping.Resource, info.Name, false, result) o.PrintSuccess(false, o.Out, info.Mapping.Resource, info.Name, false, result)
} }
return utilerrors.NewAggregate(allErrs) return utilerrors.NewAggregate(allErrs)
} }

View File

@ -406,7 +406,7 @@ func RunRun(f cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer, cmd *c
if outputFormat != "" || cmdutil.GetDryRunFlag(cmd) { if outputFormat != "" || cmdutil.GetDryRunFlag(cmd) {
return f.PrintObject(cmd, false, runObject.Mapper, runObject.Object, cmdOut) return f.PrintObject(cmd, false, runObject.Mapper, runObject.Object, cmdOut)
} }
f.PrintSuccess(runObject.Mapper, false, cmdOut, runObject.Mapping.Resource, args[0], cmdutil.GetDryRunFlag(cmd), "created") f.PrintSuccess(false, cmdOut, runObject.Mapping.Resource, args[0], cmdutil.GetDryRunFlag(cmd), "created")
return nil return nil
} }
@ -561,7 +561,7 @@ func generateService(f cmdutil.Factory, cmd *cobra.Command, args []string, servi
} }
return runObject, nil return runObject, nil
} }
f.PrintSuccess(runObject.Mapper, false, out, runObject.Mapping.Resource, args[0], cmdutil.GetDryRunFlag(cmd), "created") f.PrintSuccess(false, out, runObject.Mapping.Resource, args[0], cmdutil.GetDryRunFlag(cmd), "created")
return runObject, nil return runObject, nil
} }

View File

@ -104,7 +104,6 @@ func RunScale(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []strin
selector := cmdutil.GetFlagString(cmd, "selector") selector := cmdutil.GetFlagString(cmd, "selector")
all := cmdutil.GetFlagBool(cmd, "all") all := cmdutil.GetFlagBool(cmd, "all")
mapper, _ := f.Object()
r := f.NewBuilder(). r := f.NewBuilder().
Internal(). Internal().
ContinueOnError(). ContinueOnError().
@ -181,7 +180,7 @@ func RunScale(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []strin
} }
} }
counter++ counter++
f.PrintSuccess(mapper, shortOutput, out, info.Mapping.Resource, info.Name, false, "scaled") f.PrintSuccess(shortOutput, out, info.Mapping.Resource, info.Name, false, "scaled")
return nil return nil
}) })
if err != nil { if err != nil {

View File

@ -440,7 +440,7 @@ func (o *EnvOptions) RunEnv(f cmdutil.Factory) error {
continue continue
} }
f.PrintSuccess(o.Mapper, o.ShortOutput, o.Out, info.Mapping.Resource, info.Name, false, "env updated") f.PrintSuccess(o.ShortOutput, o.Out, info.Mapping.Resource, info.Name, false, "env updated")
} }
return utilerrors.NewAggregate(allErrs) return utilerrors.NewAggregate(allErrs)
} }

View File

@ -54,7 +54,7 @@ type ImageOptions struct {
Cmd *cobra.Command Cmd *cobra.Command
ResolveImage func(in string) (string, error) ResolveImage func(in string) (string, error)
PrintSuccess func(mapper meta.RESTMapper, shortOutput bool, out io.Writer, resource, name string, dryRun bool, operation string) PrintSuccess func(shortOutput bool, out io.Writer, resource, name string, dryRun bool, operation string)
PrintObject func(cmd *cobra.Command, isLocal bool, mapper meta.RESTMapper, obj runtime.Object, out io.Writer) error PrintObject func(cmd *cobra.Command, isLocal bool, mapper meta.RESTMapper, obj runtime.Object, out io.Writer) error
UpdatePodSpecForObject func(obj runtime.Object, fn func(*v1.PodSpec) error) (bool, error) UpdatePodSpecForObject func(obj runtime.Object, fn func(*v1.PodSpec) error) (bool, error)
Resources []string Resources []string
@ -278,7 +278,7 @@ func (o *ImageOptions) Run() error {
} }
continue continue
} }
o.PrintSuccess(o.Mapper, o.ShortOutput, o.Out, info.Mapping.Resource, info.Name, o.DryRun, "image updated") o.PrintSuccess(o.ShortOutput, o.Out, info.Mapping.Resource, info.Name, o.DryRun, "image updated")
} }
return utilerrors.NewAggregate(allErrs) return utilerrors.NewAggregate(allErrs)
} }

View File

@ -80,7 +80,7 @@ type ResourcesOptions struct {
Requests string Requests string
ResourceRequirements v1.ResourceRequirements ResourceRequirements v1.ResourceRequirements
PrintSuccess func(mapper meta.RESTMapper, shortOutput bool, out io.Writer, resource, name string, dryRun bool, operation string) PrintSuccess func(shortOutput bool, out io.Writer, resource, name string, dryRun bool, operation string)
PrintObject func(cmd *cobra.Command, isLocal bool, mapper meta.RESTMapper, obj runtime.Object, out io.Writer) error PrintObject func(cmd *cobra.Command, isLocal bool, mapper meta.RESTMapper, obj runtime.Object, out io.Writer) error
UpdatePodSpecForObject func(obj runtime.Object, fn func(*v1.PodSpec) error) (bool, error) UpdatePodSpecForObject func(obj runtime.Object, fn func(*v1.PodSpec) error) (bool, error)
Resources []string Resources []string
@ -269,7 +269,7 @@ func (o *ResourcesOptions) Run() error {
} }
continue continue
} }
o.PrintSuccess(o.Mapper, shortOutput, o.Out, info.Mapping.Resource, info.Name, false, "resource requirements updated") o.PrintSuccess(shortOutput, o.Out, info.Mapping.Resource, info.Name, false, "resource requirements updated")
} }
return utilerrors.NewAggregate(allErrs) return utilerrors.NewAggregate(allErrs)
} }

View File

@ -49,7 +49,7 @@ type SelectorOptions struct {
selector *metav1.LabelSelector selector *metav1.LabelSelector
out io.Writer out io.Writer
PrintSuccess func(mapper meta.RESTMapper, shortOutput bool, out io.Writer, resource, name string, dryRun bool, operation string) PrintSuccess func(shortOutput bool, out io.Writer, resource, name string, dryRun bool, operation string)
PrintObject func(obj runtime.Object) error PrintObject func(obj runtime.Object) error
ClientForMapping func(mapping *meta.RESTMapping) (resource.RESTClient, error) ClientForMapping func(mapping *meta.RESTMapping) (resource.RESTClient, error)
@ -218,7 +218,7 @@ func (o *SelectorOptions) RunSelector() error {
if len(o.output) > 0 && !shortOutput { if len(o.output) > 0 && !shortOutput {
return o.PrintObject(patched) return o.PrintObject(patched)
} }
o.PrintSuccess(o.mapper, shortOutput, o.out, info.Mapping.Resource, info.Name, o.dryrun, "selector updated") o.PrintSuccess(shortOutput, o.out, info.Mapping.Resource, info.Name, o.dryrun, "selector updated")
return nil return nil
}) })
} }

View File

@ -70,7 +70,7 @@ type serviceAccountConfig struct {
local bool local bool
PrintObject func(cmd *cobra.Command, isLocal bool, mapper meta.RESTMapper, obj runtime.Object, out io.Writer) error PrintObject func(cmd *cobra.Command, isLocal bool, mapper meta.RESTMapper, obj runtime.Object, out io.Writer) error
updatePodSpecForObject func(runtime.Object, func(*v1.PodSpec) error) (bool, error) updatePodSpecForObject func(runtime.Object, func(*v1.PodSpec) error) (bool, error)
printSuccess func(mapper meta.RESTMapper, shortOutput bool, out io.Writer, resource, name string, dryRun bool, operation string) printSuccess func(shortOutput bool, out io.Writer, resource, name string, dryRun bool, operation string)
infos []*resource.Info infos []*resource.Info
serviceAccountName string serviceAccountName string
} }
@ -192,7 +192,7 @@ func (saConfig *serviceAccountConfig) Run() error {
} }
continue continue
} }
saConfig.printSuccess(saConfig.mapper, saConfig.shortOutput, saConfig.out, info.Mapping.Resource, info.Name, saConfig.dryRun, "serviceaccount updated") saConfig.printSuccess(saConfig.shortOutput, saConfig.out, info.Mapping.Resource, info.Name, saConfig.dryRun, "serviceaccount updated")
} }
return utilerrors.NewAggregate(patchErrs) return utilerrors.NewAggregate(patchErrs)
} }

View File

@ -257,7 +257,7 @@ func (o *SubjectOptions) Run(f cmdutil.Factory, fn updateSubjects) error {
if len(o.Output) > 0 && !shortOutput { if len(o.Output) > 0 && !shortOutput {
return o.PrintObject(o.Mapper, info.AsVersioned(), o.Out) return o.PrintObject(o.Mapper, info.AsVersioned(), o.Out)
} }
f.PrintSuccess(o.Mapper, shortOutput, o.Out, info.Mapping.Resource, info.Name, false, "subjects updated") f.PrintSuccess(shortOutput, o.Out, info.Mapping.Resource, info.Name, false, "subjects updated")
} }
return utilerrors.NewAggregate(allErrs) return utilerrors.NewAggregate(allErrs)
} }

View File

@ -280,7 +280,7 @@ func (o TaintOptions) RunTaint() error {
return o.f.PrintObject(o.cmd, false, mapper, outputObj, o.out) return o.f.PrintObject(o.cmd, false, mapper, outputObj, o.out)
} }
o.f.PrintSuccess(mapper, false, o.out, info.Mapping.Resource, info.Name, false, operation) o.f.PrintSuccess(false, o.out, info.Mapping.Resource, info.Name, false, operation)
return nil return nil
}) })
} }

View File

@ -5,8 +5,8 @@ args:
- service/svc1 - service/svc1
namespace: "myproject" namespace: "myproject"
expectedStdout: expectedStdout:
- configmap "cm1" edited - configmaps "cm1" edited
- service "svc1" edited - services "svc1" edited
expectedExitCode: 0 expectedExitCode: 0
steps: steps:
- type: request - type: request

View File

@ -5,8 +5,8 @@ args:
- service/svc1 - service/svc1
namespace: "myproject" namespace: "myproject"
expectedStdout: expectedStdout:
- configmap "cm1" edited - configmaps "cm1" edited
- service "svc1" edited - services "svc1" edited
expectedExitCode: 0 expectedExitCode: 0
steps: steps:
- type: request - type: request

View File

@ -4,7 +4,7 @@ args:
- service/svc1 - service/svc1
namespace: myproject namespace: myproject
expectedStdout: expectedStdout:
- "service \"svc1\" edited" - "services \"svc1\" edited"
expectedExitCode: 0 expectedExitCode: 0
steps: steps:
- type: request - type: request

View File

@ -6,7 +6,7 @@ args:
outputFormat: yaml outputFormat: yaml
namespace: myproject namespace: myproject
expectedStdout: expectedStdout:
- service "svc1" edited - services "svc1" edited
expectedExitCode: 0 expectedExitCode: 0
steps: steps:
- type: request - type: request

View File

@ -3,7 +3,7 @@ mode: create
filename: "svc.yaml" filename: "svc.yaml"
namespace: "edit-test" namespace: "edit-test"
expectedStdout: expectedStdout:
- "service \"svc1\" created" - "services \"svc1\" created"
expectedStderr: expectedStderr:
- "\"svc2\" is invalid" - "\"svc2\" is invalid"
expectedExitCode: 1 expectedExitCode: 1

View File

@ -3,8 +3,8 @@ mode: create
filename: "svc.yaml" filename: "svc.yaml"
namespace: "edit-test" namespace: "edit-test"
expectedStdout: expectedStdout:
- service "svc1" created - services "svc1" created
- service "svc2" created - services "svc2" created
expectedExitCode: 0 expectedExitCode: 0
steps: steps:
- type: edit - type: edit

View File

@ -5,7 +5,7 @@ args:
- svc1 - svc1
namespace: edit-test namespace: edit-test
expectedStdout: expectedStdout:
- service "svc1" edited - services "svc1" edited
expectedStderr: expectedStderr:
- "error: services \"svc1\" is invalid" - "error: services \"svc1\" is invalid"
expectedExitCode: 0 expectedExitCode: 0

View File

@ -11,7 +11,7 @@ outputPatch: "true"
namespace: edit-test namespace: edit-test
expectedStdout: expectedStdout:
- 'Patch: {"metadata":{"annotations":{"kubectl.kubernetes.io/last-applied-configuration":"{\"apiVersion\":\"v1\",\"kind\":\"Service\",\"metadata\":{\"annotations\":{},\"creationTimestamp\":\"2017-02-27T19:40:53Z\",\"labels\":{\"app\":\"svc1\",\"new-label\":\"new-value\"},\"name\":\"svc1\",\"namespace\":\"edit-test\",\"resourceVersion\":\"670\",\"selfLink\":\"/api/v1/namespaces/edit-test/services/svc1\",\"uid\":\"a6c11186-fd24-11e6-b53c-480fcf4a5275\"},\"spec\":{\"clusterIP\":\"10.0.0.204\",\"ports\":[{\"name\":\"80\",\"port\":80,\"protocol\":\"TCP\",\"targetPort\":80}],\"selector\":{\"app\":\"svc1\"},\"sessionAffinity\":\"None\",\"type\":\"ClusterIP\"},\"status\":{\"loadBalancer\":{}}}\n"},"labels":{"new-label":"new-value"}}}' - 'Patch: {"metadata":{"annotations":{"kubectl.kubernetes.io/last-applied-configuration":"{\"apiVersion\":\"v1\",\"kind\":\"Service\",\"metadata\":{\"annotations\":{},\"creationTimestamp\":\"2017-02-27T19:40:53Z\",\"labels\":{\"app\":\"svc1\",\"new-label\":\"new-value\"},\"name\":\"svc1\",\"namespace\":\"edit-test\",\"resourceVersion\":\"670\",\"selfLink\":\"/api/v1/namespaces/edit-test/services/svc1\",\"uid\":\"a6c11186-fd24-11e6-b53c-480fcf4a5275\"},\"spec\":{\"clusterIP\":\"10.0.0.204\",\"ports\":[{\"name\":\"80\",\"port\":80,\"protocol\":\"TCP\",\"targetPort\":80}],\"selector\":{\"app\":\"svc1\"},\"sessionAffinity\":\"None\",\"type\":\"ClusterIP\"},\"status\":{\"loadBalancer\":{}}}\n"},"labels":{"new-label":"new-value"}}}'
- service "svc1" edited - services "svc1" edited
expectedExitCode: 0 expectedExitCode: 0
steps: steps:
- type: request - type: request

View File

@ -4,8 +4,8 @@ args:
- configmaps,services - configmaps,services
namespace: "edit-test" namespace: "edit-test"
expectedStdout: expectedStdout:
- configmap "cm1" edited - configmaps "cm1" edited
- service "svc1" edited - services "svc1" edited
expectedExitCode: 0 expectedExitCode: 0
steps: steps:
- type: request - type: request

View File

@ -5,8 +5,8 @@ args:
- service/svc1 - service/svc1
namespace: "edit-test" namespace: "edit-test"
expectedStdout: expectedStdout:
- configmap "cm1" edited - configmaps "cm1" edited
- service "svc1" edited - services "svc1" edited
expectedExitCode: 0 expectedExitCode: 0
steps: steps:
- type: request - type: request

View File

@ -5,8 +5,8 @@ args:
- service/svc1 - service/svc1
namespace: "edit-test" namespace: "edit-test"
expectedStdout: expectedStdout:
- configmap "cm1" edited - configmaps "cm1" edited
- service "svc1" edited - services "svc1" edited
expectedExitCode: 0 expectedExitCode: 0
steps: steps:
- type: request - type: request

View File

@ -9,7 +9,7 @@ args:
saveConfig: "false" saveConfig: "false"
namespace: edit-test namespace: edit-test
expectedStdout: expectedStdout:
- service "svc1" edited - services "svc1" edited
expectedExitCode: 0 expectedExitCode: 0
steps: steps:
- type: request - type: request
@ -27,4 +27,4 @@ steps:
expectedContentType: application/strategic-merge-patch+json expectedContentType: application/strategic-merge-patch+json
expectedInput: 2.request expectedInput: 2.request
resultingStatusCode: 200 resultingStatusCode: 200
resultingOutput: 2.response resultingOutput: 2.response

View File

@ -6,9 +6,9 @@ args:
- bars/test2 - bars/test2
namespace: default namespace: default
expectedStdout: expectedStdout:
- "service \"kubernetes\" edited" - "services \"kubernetes\" edited"
- "bar \"test\" edited" - "bars \"test\" edited"
- "bar \"test2\" edited" - "bars \"test2\" edited"
expectedExitCode: 0 expectedExitCode: 0
steps: steps:
- type: request - type: request

View File

@ -8,7 +8,7 @@ args:
- svc1 - svc1
namespace: edit-test namespace: edit-test
expectedStdout: expectedStdout:
- service "svc1" edited - services "svc1" edited
expectedExitCode: 0 expectedExitCode: 0
steps: steps:
- type: request - type: request

View File

@ -4,7 +4,7 @@ args:
- service/kubernetes - service/kubernetes
namespace: default namespace: default
expectedStdout: expectedStdout:
- "service \"kubernetes\" edited" - "services \"kubernetes\" edited"
expectedExitCode: 0 expectedExitCode: 0
steps: steps:
- type: request - type: request

View File

@ -4,7 +4,7 @@ args:
- storageclasses.v1beta1.storage.k8s.io/foo - storageclasses.v1beta1.storage.k8s.io/foo
namespace: default namespace: default
expectedStdout: expectedStdout:
- "storageclass \"foo\" edited" - "storageclasses \"foo\" edited"
expectedExitCode: 0 expectedExitCode: 0
steps: steps:
- type: request - type: request

View File

@ -4,7 +4,7 @@ args:
- storageclasses.v0.storage.k8s.io/foo - storageclasses.v0.storage.k8s.io/foo
namespace: default namespace: default
expectedStdout: expectedStdout:
- "storageclass \"foo\" edited" - "storageclasses \"foo\" edited"
expectedExitCode: 0 expectedExitCode: 0
steps: steps:
- type: request - type: request

View File

@ -9,7 +9,7 @@ args:
saveConfig: "true" saveConfig: "true"
namespace: edit-test namespace: edit-test
expectedStdout: expectedStdout:
- service "svc1" edited - services "svc1" edited
expectedExitCode: 0 expectedExitCode: 0
steps: steps:
- type: request - type: request
@ -27,4 +27,4 @@ steps:
expectedContentType: application/strategic-merge-patch+json expectedContentType: application/strategic-merge-patch+json
expectedInput: 2.request expectedInput: 2.request
resultingStatusCode: 200 resultingStatusCode: 200
resultingOutput: 2.response resultingOutput: 2.response

View File

@ -376,8 +376,7 @@ func (f *FakeFactory) PrintResourceInfoForCommand(cmd *cobra.Command, info *reso
return printer.PrintObj(info.Object, out) return printer.PrintObj(info.Object, out)
} }
func (f *FakeFactory) PrintSuccess(mapper meta.RESTMapper, shortOutput bool, out io.Writer, resource, name string, dryRun bool, operation string) { func (f *FakeFactory) PrintSuccess(shortOutput bool, out io.Writer, resource, name string, dryRun bool, operation string) {
resource, _ = mapper.ResourceSingularizer(resource)
dryRunMsg := "" dryRunMsg := ""
if dryRun { if dryRun {
dryRunMsg = " (dry run)" dryRunMsg = " (dry run)"
@ -772,8 +771,7 @@ func (f *fakeAPIFactory) PrintResourceInfoForCommand(cmd *cobra.Command, info *r
return printer.PrintObj(info.Object, out) return printer.PrintObj(info.Object, out)
} }
func (f *fakeAPIFactory) PrintSuccess(mapper meta.RESTMapper, shortOutput bool, out io.Writer, resource, name string, dryRun bool, operation string) { func (f *fakeAPIFactory) PrintSuccess(shortOutput bool, out io.Writer, resource, name string, dryRun bool, operation string) {
resource, _ = mapper.ResourceSingularizer(resource)
dryRunMsg := "" dryRunMsg := ""
if dryRun { if dryRun {
dryRunMsg = " (dry run)" dryRunMsg = " (dry run)"

View File

@ -60,7 +60,6 @@ type EditOptions struct {
cmdutil.ValidateOptions cmdutil.ValidateOptions
Mapper meta.RESTMapper
ResourceMapper *resource.Mapper ResourceMapper *resource.Mapper
OriginalResult *resource.Result OriginalResult *resource.Result
Encoder runtime.Encoder Encoder runtime.Encoder
@ -107,7 +106,6 @@ func (o *EditOptions) Complete(f cmdutil.Factory, out, errOut io.Writer, args []
if err != nil { if err != nil {
return err return err
} }
mapper, _ := f.Object()
b := f.NewBuilder(). b := f.NewBuilder().
Unstructured() Unstructured()
if o.EditMode == NormalEditMode || o.EditMode == ApplyEditMode { if o.EditMode == NormalEditMode || o.EditMode == ApplyEditMode {
@ -138,7 +136,6 @@ func (o *EditOptions) Complete(f cmdutil.Factory, out, errOut io.Writer, args []
Do() Do()
} }
o.Mapper = mapper
o.CmdNamespace = cmdNamespace o.CmdNamespace = cmdNamespace
o.Encoder = f.JSONEncoder() o.Encoder = f.JSONEncoder()
o.f = f o.f = f
@ -408,14 +405,14 @@ func (o *EditOptions) visitToApplyEditPatch(originalInfos []*resource.Info, patc
} }
if reflect.DeepEqual(originalJS, editedJS) { if reflect.DeepEqual(originalJS, editedJS) {
o.f.PrintSuccess(o.Mapper, false, o.Out, info.Mapping.Resource, info.Name, false, "skipped") o.f.PrintSuccess(false, o.Out, info.Mapping.Resource, info.Name, false, "skipped")
return nil return nil
} else { } else {
err := o.annotationPatch(info) err := o.annotationPatch(info)
if err != nil { if err != nil {
return err return err
} }
o.f.PrintSuccess(o.Mapper, false, o.Out, info.Mapping.Resource, info.Name, false, "edited") o.f.PrintSuccess(false, o.Out, info.Mapping.Resource, info.Name, false, "edited")
return nil return nil
} }
}) })
@ -534,7 +531,7 @@ func (o *EditOptions) visitToPatch(originalInfos []*resource.Info, patchVisitor
if reflect.DeepEqual(originalJS, editedJS) { if reflect.DeepEqual(originalJS, editedJS) {
// no edit, so just skip it. // no edit, so just skip it.
o.f.PrintSuccess(o.Mapper, false, o.Out, info.Mapping.Resource, info.Name, false, "skipped") o.f.PrintSuccess(false, o.Out, info.Mapping.Resource, info.Name, false, "skipped")
return nil return nil
} }
@ -588,7 +585,7 @@ func (o *EditOptions) visitToPatch(originalInfos []*resource.Info, patchVisitor
return nil return nil
} }
info.Refresh(patched, true) info.Refresh(patched, true)
o.f.PrintSuccess(o.Mapper, false, o.Out, info.Mapping.Resource, info.Name, false, "edited") o.f.PrintSuccess(false, o.Out, info.Mapping.Resource, info.Name, false, "edited")
return nil return nil
}) })
return err return err
@ -599,7 +596,7 @@ func (o *EditOptions) visitToCreate(createVisitor resource.Visitor) error {
if err := resource.CreateAndRefresh(info); err != nil { if err := resource.CreateAndRefresh(info); err != nil {
return err return err
} }
o.f.PrintSuccess(o.Mapper, false, o.Out, info.Mapping.Resource, info.Name, false, "created") o.f.PrintSuccess(false, o.Out, info.Mapping.Resource, info.Name, false, "created")
return nil return nil
}) })
return err return err

View File

@ -248,7 +248,7 @@ type BuilderFactory interface {
// Requires that printer flags have been added to cmd (see AddPrinterFlags). // Requires that printer flags have been added to cmd (see AddPrinterFlags).
PrintResourceInfoForCommand(cmd *cobra.Command, info *resource.Info, out io.Writer) error PrintResourceInfoForCommand(cmd *cobra.Command, info *resource.Info, out io.Writer) error
// PrintSuccess prints message after finishing mutating operations // PrintSuccess prints message after finishing mutating operations
PrintSuccess(mapper meta.RESTMapper, shortOutput bool, out io.Writer, resource, name string, dryRun bool, operation string) PrintSuccess(shortOutput bool, out io.Writer, resource, name string, dryRun bool, operation string)
// NewBuilder returns an object that assists in loading objects from both disk and the server // NewBuilder returns an object that assists in loading objects from both disk and the server
// and which implements the common patterns for CLI interactions with generic resources. // and which implements the common patterns for CLI interactions with generic resources.
NewBuilder() *resource.Builder NewBuilder() *resource.Builder

View File

@ -82,8 +82,7 @@ func (f *ring2Factory) PrinterForMapping(options *printers.PrintOptions, mapping
return printer, nil return printer, nil
} }
func (f *ring2Factory) PrintSuccess(mapper meta.RESTMapper, shortOutput bool, out io.Writer, resource, name string, dryRun bool, operation string) { func (f *ring2Factory) PrintSuccess(shortOutput bool, out io.Writer, resource, name string, dryRun bool, operation string) {
resource, _ = mapper.ResourceSingularizer(resource)
dryRunMsg := "" dryRunMsg := ""
if dryRun { if dryRun {
dryRunMsg = " (dry run)" dryRunMsg = " (dry run)"