mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 04:33:26 +00:00
Merge pull request #91934 from SataQiu/fix-kubectl-20200609
kubectl: improve the warning message when doing kubectl apply to the resource without expected annotation
This commit is contained in:
commit
d8185e583b
@ -132,7 +132,7 @@ var (
|
||||
# Apply the configuration in manifest.yaml and delete all the other configmaps that are not in the file.
|
||||
kubectl apply --prune -f manifest.yaml --all --prune-whitelist=core/v1/ConfigMap`))
|
||||
|
||||
warningNoLastAppliedConfigAnnotation = "Warning: %[1]s apply should be used on resource created by either %[1]s create --save-config or %[1]s apply\n"
|
||||
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"
|
||||
)
|
||||
|
||||
// NewApplyOptions creates new ApplyOptions for the `apply` command
|
||||
@ -542,7 +542,7 @@ See http://k8s.io/docs/reference/using-api/api-concepts/#conflicts`, err)
|
||||
metadata, _ := meta.Accessor(info.Object)
|
||||
annotationMap := metadata.GetAnnotations()
|
||||
if _, ok := annotationMap[corev1.LastAppliedConfigAnnotation]; !ok {
|
||||
fmt.Fprintf(o.ErrOut, warningNoLastAppliedConfigAnnotation, o.cmdBaseName)
|
||||
fmt.Fprintf(o.ErrOut, warningNoLastAppliedConfigAnnotation, info.ObjectName(), corev1.LastAppliedConfigAnnotation, o.cmdBaseName)
|
||||
}
|
||||
|
||||
patcher, err := newPatcher(o, info, helper)
|
||||
|
@ -504,7 +504,7 @@ func TestApplyObjectWithoutAnnotation(t *testing.T) {
|
||||
|
||||
// uses the name from the file, not the response
|
||||
expectRC := "replicationcontroller/" + nameRC + "\n"
|
||||
expectWarning := fmt.Sprintf(warningNoLastAppliedConfigAnnotation, "kubectl")
|
||||
expectWarning := fmt.Sprintf(warningNoLastAppliedConfigAnnotation, "replicationcontrollers/test-rc", corev1.LastAppliedConfigAnnotation, "kubectl")
|
||||
if errBuf.String() != expectWarning {
|
||||
t.Fatalf("unexpected non-warning: %s\nexpected: %s", errBuf.String(), expectWarning)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user