Skip to content

Commit

Permalink
remove mapper dependency - PrintSuccess
Browse files Browse the repository at this point in the history
  • Loading branch information
juanvallejo committed Feb 7, 2018
1 parent 06472a0 commit beb5ea6
Show file tree
Hide file tree
Showing 67 changed files with 156 additions and 169 deletions.
4 changes: 2 additions & 2 deletions hack/make-rules/test-cmd-util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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`
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
# test invalid image name
output_message=$(! kubectl run test2 --image=InvalidImageName 2>&1)
Expand Down Expand Up @@ -4410,7 +4410,7 @@ __EOF__
kube::test::if_has_string "${response}" 'must provide one or more resources'
# test=label matches our node
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
response=$(kubectl cordon --selector invalid=label)
kube::test::if_has_not_string "${response}" 'cordoned'
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubectl/cmd/annotate.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ func (o AnnotateOptions) RunAnnotate(f cmdutil.Factory, cmd *cobra.Command) erro
if len(o.outputFormat) > 0 {
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
})
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/kubectl/cmd/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ func RunApply(f cmdutil.Factory, cmd *cobra.Command, out, errOut io.Writer, opti
if len(output) > 0 && !shortOutput {
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
}

Expand Down Expand Up @@ -342,15 +342,15 @@ func RunApply(f cmdutil.Factory, cmd *cobra.Command, out, errOut io.Writer, opti

if string(patchBytes) == "{}" {
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
}
}
count++
if len(output) > 0 && !shortOutput {
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
})

Expand Down Expand Up @@ -517,7 +517,7 @@ func (p *pruner) prune(f cmdutil.Factory, namespace string, mapping *meta.RESTMa
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
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/kubectl/cmd/apply_set_last_applied.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,14 @@ func (o *SetLastAppliedOptions) RunSetLastApplied(f cmdutil.Factory, cmd *cobra.
info.Refresh(patchedObj, false)
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 {
err := o.formatPrinter(o.Output, patch.Patch, o.Out)
if err != nil {
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
Expand Down
28 changes: 14 additions & 14 deletions pkg/kubectl/cmd/apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ func TestApplyObjectWithoutAnnotation(t *testing.T) {
cmd.Run(cmd, []string{})

// uses the name from the file, not the response
expectRC := "replicationcontroller/" + nameRC + "\n"
expectRC := "replicationcontrollers/" + nameRC + "\n"
expectWarning := fmt.Sprintf(warningNoLastAppliedConfigAnnotation, "kubectl")
if errBuf.String() != expectWarning {
t.Fatalf("unexpected non-warning: %s\nexpected: %s", errBuf.String(), expectWarning)
Expand Down Expand Up @@ -461,7 +461,7 @@ func TestApplyObject(t *testing.T) {
cmd.Run(cmd, []string{})

// uses the name from the file, not the response
expectRC := "replicationcontroller/" + nameRC + "\n"
expectRC := "replicationcontrollers/" + nameRC + "\n"
if buf.String() != expectRC {
t.Fatalf("unexpected output: %s\nexpected: %s", buf.String(), expectRC)
}
Expand Down Expand Up @@ -586,7 +586,7 @@ func TestApplyRetry(t *testing.T) {
}

// uses the name from the file, not the response
expectRC := "replicationcontroller/" + nameRC + "\n"
expectRC := "replicationcontrollers/" + nameRC + "\n"
if buf.String() != expectRC {
t.Fatalf("unexpected output: %s\nexpected: %s", buf.String(), expectRC)
}
Expand Down Expand Up @@ -630,7 +630,7 @@ func TestApplyNonExistObject(t *testing.T) {
cmd.Run(cmd, []string{})

// uses the name from the file, not the response
expectRC := "replicationcontroller/" + nameRC + "\n"
expectRC := "replicationcontrollers/" + nameRC + "\n"
if buf.String() != expectRC {
t.Errorf("unexpected output: %s\nexpected: %s", buf.String(), expectRC)
}
Expand Down Expand Up @@ -683,7 +683,7 @@ func TestApplyEmptyPatch(t *testing.T) {
cmd.Flags().Set("output", "name")
cmd.Run(cmd, []string{})

expectRC := "replicationcontroller/" + nameRC + "\n"
expectRC := "replicationcontrollers/" + nameRC + "\n"
if buf.String() != expectRC {
t.Fatalf("unexpected output: %s\nexpected: %s", buf.String(), expectRC)
}
Expand Down Expand Up @@ -764,8 +764,8 @@ func testApplyMultipleObjects(t *testing.T, asList bool) {
cmd.Run(cmd, []string{})

// Names should come from the REST response, NOT the files
expectRC := "replicationcontroller/" + nameRC + "\n"
expectSVC := "service/" + nameSVC + "\n"
expectRC := "replicationcontrollers/" + nameRC + "\n"
expectSVC := "services/" + nameSVC + "\n"
// Test both possible orders since output is non-deterministic.
expectOne := expectRC + expectSVC
expectTwo := expectSVC + expectRC
Expand Down Expand Up @@ -855,7 +855,7 @@ func TestApplyNULLPreservation(t *testing.T) {

cmd.Run(cmd, []string{})

expected := "deployment/" + deploymentName + "\n"
expected := "deployments/" + deploymentName + "\n"
if buf.String() != expected {
t.Fatalf("unexpected output: %s\nexpected: %s", buf.String(), expected)
}
Expand Down Expand Up @@ -918,7 +918,7 @@ func TestUnstructuredApply(t *testing.T) {
cmd.Flags().Set("output", "name")
cmd.Run(cmd, []string{})

expected := "widget/" + name + "\n"
expected := "widgets/" + name + "\n"
if buf.String() != expected {
t.Fatalf("unexpected output: %s\nexpected: %s", buf.String(), expected)
}
Expand Down Expand Up @@ -1009,7 +1009,7 @@ func TestUnstructuredIdempotentApply(t *testing.T) {
cmd.Flags().Set("output", "name")
cmd.Run(cmd, []string{})

expected := "widget/widget\n"
expected := "widgets/widget\n"
if buf.String() != expected {
t.Fatalf("unexpected output: %s\nexpected: %s", buf.String(), expected)
}
Expand Down Expand Up @@ -1040,7 +1040,7 @@ func TestRunApplySetLastApplied(t *testing.T) {
name: "set with exist object",
filePath: filenameRC,
expectedErr: "",
expectedOut: "replicationcontroller/test-rc\n",
expectedOut: "replicationcontrollers/test-rc\n",
output: "name",
},
{
Expand All @@ -1061,14 +1061,14 @@ func TestRunApplySetLastApplied(t *testing.T) {
name: "set with exist object output json",
filePath: filenameRCJSON,
expectedErr: "",
expectedOut: "replicationcontroller/test-rc\n",
expectedOut: "replicationcontrollers/test-rc\n",
output: "name",
},
{
name: "set test for a directory of files",
filePath: dirName,
expectedErr: "",
expectedOut: "replicationcontroller/test-rc\nreplicationcontroller/test-rc\n",
expectedOut: "replicationcontrollers/test-rc\nreplicationcontrollers/test-rc\n",
output: "name",
},
}
Expand Down Expand Up @@ -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)
}
if errBuf.String() != "" {
Expand Down
3 changes: 1 addition & 2 deletions pkg/kubectl/cmd/auth/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,14 @@ func (o *ReconcileOptions) Complete(cmd *cobra.Command, f cmdutil.Factory, args
o.RBACClient = client.Rbac()
o.NamespaceClient = client.Core().Namespaces()

mapper, _ := f.Object()
dryRun := false
output := cmdutil.GetFlagString(cmd, "output")
shortOutput := output == "name"
o.Print = func(info *resource.Info) error {
if len(output) > 0 && !shortOutput {
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
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/kubectl/cmd/autoscale.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

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
})
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions pkg/kubectl/cmd/certificates.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
var found int
mapper, _ := f.Object()
c, err := f.ClientSet()
if err != nil {
return err
Expand All @@ -192,7 +191,7 @@ func (options *CertificateOptions) modifyCertificateCondition(f cmdutil.Factory,
return err
}
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
})
if found == 0 {
Expand Down
5 changes: 2 additions & 3 deletions pkg/kubectl/cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ func (o *CreateOptions) RunCreate(f cmdutil.Factory, cmd *cobra.Command) error {

dryRun := cmdutil.GetDryRunFlag(cmd)
output := cmdutil.GetFlagString(cmd, "output")
mapper := r.Mapper().RESTMapper

count := 0
err = r.Visit(func(info *resource.Info, err error) error {
Expand Down Expand Up @@ -218,7 +217,7 @@ func (o *CreateOptions) RunCreate(f cmdutil.Factory, cmd *cobra.Command) error {
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
})
if err != nil {
Expand Down Expand Up @@ -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 {
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
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/kubectl/cmd/create_clusterrole.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (c *CreateClusterRoleOptions) RunCreateRole() error {
}

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
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/kubectl/cmd/create_clusterrolebinding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func TestCreateClusterRoleBinding(t *testing.T) {
},
}

expectedOutput := "clusterrolebinding/" + expectBinding.Name + "\n"
expectedOutput := "clusterrolebindings/" + expectBinding.Name + "\n"
buf := bytes.NewBuffer([]byte{})
cmd := NewCmdCreateClusterRoleBinding(f, buf)
cmd.Flags().Set("clusterrole", "fake-clusterrole")
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubectl/cmd/create_configmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestCreateConfigMap(t *testing.T) {
cmd := NewCmdCreateConfigMap(f, buf)
cmd.Flags().Set("output", "name")
cmd.Run(cmd, []string{configMap.Name})
expectedOutput := "configmap/" + configMap.Name + "\n"
expectedOutput := "configmaps/" + configMap.Name + "\n"
if buf.String() != expectedOutput {
t.Errorf("expected output: %s, but got: %s", expectedOutput, buf.String())
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubectl/cmd/create_deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func TestCreateDeployment(t *testing.T) {
cmd.Flags().Set("output", "name")
cmd.Flags().Set("image", "hollywood/jonny.depp:v2")
cmd.Run(cmd, []string{depName})
expectedOutput := "deployment/" + depName + "\n"
expectedOutput := "deployments/" + depName + "\n"
if buf.String() != expectedOutput {
t.Errorf("expected output: %s, but got: %s", expectedOutput, buf.String())
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubectl/cmd/create_namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestCreateNamespace(t *testing.T) {
cmd := NewCmdCreateNamespace(f, buf)
cmd.Flags().Set("output", "name")
cmd.Run(cmd, []string{namespaceObject.Name})
expectedOutput := "namespace/" + namespaceObject.Name + "\n"
expectedOutput := "namespaces/" + namespaceObject.Name + "\n"
if buf.String() != expectedOutput {
t.Errorf("expected output: %s, but got: %s", expectedOutput, buf.String())
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubectl/cmd/create_pdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestCreatePdb(t *testing.T) {
cmd.Flags().Set("dry-run", "true")
cmd.Flags().Set("output", "name")
CreatePodDisruptionBudget(f, buf, cmd, []string{pdbName})
expectedOutput := "poddisruptionbudget/" + pdbName + "\n"
expectedOutput := "poddisruptionbudgets/" + pdbName + "\n"
if buf.String() != expectedOutput {
t.Errorf("expected output: %s, but got: %s", expectedOutput, buf.String())
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubectl/cmd/create_priorityclass_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestCreatePriorityClass(t *testing.T) {
cmd.Flags().Set("dry-run", "true")
cmd.Flags().Set("output", "name")
CreatePriorityClass(f, buf, cmd, []string{pcName})
expectedOutput := "priorityclass/" + pcName + "\n"
expectedOutput := "priorityclasses/" + pcName + "\n"
if buf.String() != expectedOutput {
t.Errorf("expected output: %s, but got: %s", expectedOutput, buf.String())
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/kubectl/cmd/create_quota_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,19 @@ func TestCreateQuota(t *testing.T) {
}{
"single resource": {
flags: []string{"--hard=cpu=1"},
expectedOutput: "resourcequota/" + resourceQuotaObject.Name + "\n",
expectedOutput: "resourcequotas/" + resourceQuotaObject.Name + "\n",
},
"single resource with a scope": {
flags: []string{"--hard=cpu=1", "--scopes=BestEffort"},
expectedOutput: "resourcequota/" + resourceQuotaObject.Name + "\n",
expectedOutput: "resourcequotas/" + resourceQuotaObject.Name + "\n",
},
"multiple resources": {
flags: []string{"--hard=cpu=1,pods=42", "--scopes=BestEffort"},
expectedOutput: "resourcequota/" + resourceQuotaObject.Name + "\n",
expectedOutput: "resourcequotas/" + resourceQuotaObject.Name + "\n",
},
"single resource with multiple scopes": {
flags: []string{"--hard=cpu=1", "--scopes=BestEffort,NotTerminating"},
expectedOutput: "resourcequota/" + resourceQuotaObject.Name + "\n",
expectedOutput: "resourcequotas/" + resourceQuotaObject.Name + "\n",
},
}
for name, test := range tests {
Expand Down
4 changes: 2 additions & 2 deletions pkg/kubectl/cmd/create_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ type CreateRoleOptions struct {
Mapper meta.RESTMapper
Out io.Writer
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.
Expand Down Expand Up @@ -295,7 +295,7 @@ func (c *CreateRoleOptions) RunCreateRole() error {
}

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
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/kubectl/cmd/create_secret_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestCreateSecretGeneric(t *testing.T) {
cmd.Flags().Set("from-literal", "password=includes,comma")
cmd.Flags().Set("from-literal", "username=test_user")
cmd.Run(cmd, []string{secretObject.Name})
expectedOutput := "secret/" + secretObject.Name + "\n"
expectedOutput := "secrets/" + secretObject.Name + "\n"
if buf.String() != expectedOutput {
t.Errorf("expected output: %s, but got: %s", expectedOutput, buf.String())
}
Expand Down Expand Up @@ -89,7 +89,7 @@ func TestCreateSecretDockerRegistry(t *testing.T) {
cmd.Flags().Set("docker-email", "test-email")
cmd.Flags().Set("output", "name")
cmd.Run(cmd, []string{secretObject.Name})
expectedOutput := "secret/" + secretObject.Name + "\n"
expectedOutput := "secrets/" + secretObject.Name + "\n"
if buf.String() != expectedOutput {
t.Errorf("expected output: %s, but got: %s", buf.String(), expectedOutput)
}
Expand Down
Loading

0 comments on commit beb5ea6

Please sign in to comment.