Skip to content

Commit d8185e5

Browse files
authored
Merge pull request kubernetes#91934 from SataQiu/fix-kubectl-20200609
kubectl: improve the warning message when doing kubectl apply to the resource without expected annotation
2 parents 90c9f7b + 9c163f0 commit d8185e5

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

staging/src/k8s.io/kubectl/pkg/cmd/apply/apply.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ var (
132132
# Apply the configuration in manifest.yaml and delete all the other configmaps that are not in the file.
133133
kubectl apply --prune -f manifest.yaml --all --prune-whitelist=core/v1/ConfigMap`))
134134

135-
warningNoLastAppliedConfigAnnotation = "Warning: %[1]s apply should be used on resource created by either %[1]s create --save-config or %[1]s apply\n"
135+
warningNoLastAppliedConfigAnnotation = "Warning: resource %[1]s is missing the %[2]s annotation which is required by %[3]s apply. %[3]s apply should only be used on resources created declaratively by either %[3]s create --save-config or %[3]s apply. The missing annotation will be patched automatically.\n"
136136
)
137137

138138
// NewApplyOptions creates new ApplyOptions for the `apply` command
@@ -542,7 +542,7 @@ See http://k8s.io/docs/reference/using-api/api-concepts/#conflicts`, err)
542542
metadata, _ := meta.Accessor(info.Object)
543543
annotationMap := metadata.GetAnnotations()
544544
if _, ok := annotationMap[corev1.LastAppliedConfigAnnotation]; !ok {
545-
fmt.Fprintf(o.ErrOut, warningNoLastAppliedConfigAnnotation, o.cmdBaseName)
545+
fmt.Fprintf(o.ErrOut, warningNoLastAppliedConfigAnnotation, info.ObjectName(), corev1.LastAppliedConfigAnnotation, o.cmdBaseName)
546546
}
547547

548548
patcher, err := newPatcher(o, info, helper)

staging/src/k8s.io/kubectl/pkg/cmd/apply/apply_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ func TestApplyObjectWithoutAnnotation(t *testing.T) {
504504

505505
// uses the name from the file, not the response
506506
expectRC := "replicationcontroller/" + nameRC + "\n"
507-
expectWarning := fmt.Sprintf(warningNoLastAppliedConfigAnnotation, "kubectl")
507+
expectWarning := fmt.Sprintf(warningNoLastAppliedConfigAnnotation, "replicationcontrollers/test-rc", corev1.LastAppliedConfigAnnotation, "kubectl")
508508
if errBuf.String() != expectWarning {
509509
t.Fatalf("unexpected non-warning: %s\nexpected: %s", errBuf.String(), expectWarning)
510510
}

0 commit comments

Comments
 (0)