diff --git a/staging/src/k8s.io/kubectl/pkg/cmd/apply/apply.go b/staging/src/k8s.io/kubectl/pkg/cmd/apply/apply.go index 0370f0e0e21..7b3baa7c242 100644 --- a/staging/src/k8s.io/kubectl/pkg/cmd/apply/apply.go +++ b/staging/src/k8s.io/kubectl/pkg/cmd/apply/apply.go @@ -381,6 +381,11 @@ func (o *ApplyOptions) Validate() error { return fmt.Errorf("--force cannot be used with --prune") } + // Currently do not support pruning objects which are server-side applied. + if o.Prune && o.ServerSideApply { + return fmt.Errorf("--prune is in alpha and doesn't currently work on objects created by server-side apply") + } + return nil } diff --git a/staging/src/k8s.io/kubectl/pkg/cmd/apply/apply_test.go b/staging/src/k8s.io/kubectl/pkg/cmd/apply/apply_test.go index b0cf1fd6972..583969da226 100644 --- a/staging/src/k8s.io/kubectl/pkg/cmd/apply/apply_test.go +++ b/staging/src/k8s.io/kubectl/pkg/cmd/apply/apply_test.go @@ -147,6 +147,14 @@ func TestApplyFlagValidation(t *testing.T) { }, expectedErr: "--force cannot be used with --prune", }, + { + args: [][]string{ + {"server-side", "true"}, + {"prune", "true"}, + {"all", "true"}, + }, + expectedErr: "--prune is in alpha and doesn't currently work on objects created by server-side apply", + }, } for _, test := range tests {