From 7efcc7e0ac84eeace7286d8ec0be1c130fe4f17f Mon Sep 17 00:00:00 2001 From: Sean Sullivan Date: Tue, 25 Oct 2022 21:59:31 +0000 Subject: [PATCH] Fixes prune for server-side applied objects Kubernetes-commit: 21393f1b1d859cecdcc9aeee01f7dbf9aab71120 --- pkg/cmd/apply/apply.go | 5 +++++ pkg/cmd/apply/apply_test.go | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/pkg/cmd/apply/apply.go b/pkg/cmd/apply/apply.go index 0370f0e0e..7b3baa7c2 100644 --- a/pkg/cmd/apply/apply.go +++ b/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/pkg/cmd/apply/apply_test.go b/pkg/cmd/apply/apply_test.go index b0cf1fd69..583969da2 100644 --- a/pkg/cmd/apply/apply_test.go +++ b/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 {