From a06bba9d57ebc70134053954dfd04892ba69d272 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arda=20G=C3=BC=C3=A7l=C3=BC?= Date: Thu, 18 Sep 2025 12:30:09 +0300 Subject: [PATCH] Remove KUBECTL_OPENAPIV3_PATCH feature gate as the feature is stable Kubernetes-commit: 9382fa8b70be73b0df83d7c2793cf8efd95ec773 --- pkg/cmd/apply/apply.go | 12 ++++---- pkg/cmd/apply/apply_test.go | 59 +------------------------------------ pkg/cmd/diff/diff.go | 12 ++++---- pkg/cmd/util/helpers.go | 6 ---- 4 files changed, 11 insertions(+), 78 deletions(-) diff --git a/pkg/cmd/apply/apply.go b/pkg/cmd/apply/apply.go index 1ecc7c9d8..d509b90f3 100644 --- a/pkg/cmd/apply/apply.go +++ b/pkg/cmd/apply/apply.go @@ -284,13 +284,11 @@ func (flags *ApplyFlags) ToOptions(f cmdutil.Factory, cmd *cobra.Command, baseNa } var openAPIV3Root openapi3.Root - if !cmdutil.OpenAPIV3Patch.IsDisabled() { - openAPIV3Client, err := f.OpenAPIV3Client() - if err == nil { - openAPIV3Root = openapi3.NewRoot(openAPIV3Client) - } else { - klog.V(4).Infof("warning: OpenAPI V3 Patch is enabled but is unable to be loaded. Will fall back to OpenAPI V2") - } + openAPIV3Client, err := f.OpenAPIV3Client() + if err == nil { + openAPIV3Root = openapi3.NewRoot(openAPIV3Client) + } else { + klog.V(4).Infof("warning: OpenAPI V3 Patch is enabled but is unable to be loaded. Will fall back to OpenAPI V2") } validationDirective, err := cmdutil.GetValidationDirective(cmd) diff --git a/pkg/cmd/apply/apply_test.go b/pkg/cmd/apply/apply_test.go index 66992cdda..50e1f5689 100644 --- a/pkg/cmd/apply/apply_test.go +++ b/pkg/cmd/apply/apply_test.go @@ -114,11 +114,8 @@ func (o *OpenAPIV3ClientAlwaysPanic) Paths() (map[string]openapiclient.GroupVers func noopOpenAPIV3Patch(t *testing.T, f func(t *testing.T)) { f(t) } -func disableOpenAPIV3Patch(t *testing.T, f func(t *testing.T)) { - cmdtesting.WithAlphaEnvsDisabled([]cmdutil.FeatureGate{cmdutil.OpenAPIV3Patch}, t, f) -} -var applyFeatureToggles = []func(*testing.T, func(t *testing.T)){noopOpenAPIV3Patch, disableOpenAPIV3Patch} +var applyFeatureToggles = []func(*testing.T, func(t *testing.T)){noopOpenAPIV3Patch} type testOpenAPISchema struct { OpenAPISchemaFn func() (openapi.Resources, error) @@ -742,60 +739,6 @@ func TestApplyObjectWithoutAnnotation(t *testing.T) { } } -func TestOpenAPIV3PatchFeatureFlag(t *testing.T) { - // OpenAPIV3 smp apply is on by default. - // Test that users can disable it to use OpenAPI V2 smp - // An OpenAPI V3 root that always panics is used to ensure - // the v3 code path is never exercised when the feature is disabled - cmdtesting.InitTestErrorHandler(t) - nameRC, currentRC := readAndAnnotateReplicationController(t, filenameRC) - pathRC := "/namespaces/test/replicationcontrollers/" + nameRC - - t.Run("test apply when a local object is specified - openapi v2 smp", func(t *testing.T) { - disableOpenAPIV3Patch(t, func(t *testing.T) { - tf := cmdtesting.NewTestFactory().WithNamespace("test") - defer tf.Cleanup() - - tf.UnstructuredClient = &fake.RESTClient{ - NegotiatedSerializer: resource.UnstructuredPlusDefaultContentConfig().NegotiatedSerializer, - Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { - switch p, m := req.URL.Path, req.Method; { - case p == pathRC && m == "GET": - bodyRC := io.NopCloser(bytes.NewReader(currentRC)) - return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil - case p == pathRC && m == "PATCH": - validatePatchApplication(t, req, types.StrategicMergePatchType) - bodyRC := io.NopCloser(bytes.NewReader(currentRC)) - return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil - default: - t.Fatalf("unexpected request: %#v\n%#v", req.URL, req) - return nil, nil - } - }), - } - tf.OpenAPISchemaFunc = FakeOpenAPISchema.OpenAPISchemaFn - tf.OpenAPIV3ClientFunc = AlwaysPanicSchema.OpenAPIV3ClientFunc - tf.ClientConfigVal = cmdtesting.DefaultClientConfig() - - ioStreams, _, buf, errBuf := genericiooptions.NewTestIOStreams() - cmd := NewCmdApply("kubectl", tf, ioStreams) - cmd.Flags().Set("filename", filenameRC) - cmd.Flags().Set("output", "name") - cmd.Run(cmd, []string{}) - - // uses the name from the file, not the response - expectRC := "replicationcontroller/" + nameRC + "\n" - if buf.String() != expectRC { - t.Fatalf("unexpected output: %s\nexpected: %s", buf.String(), expectRC) - } - if errBuf.String() != "" { - t.Fatalf("unexpected error output: %s", errBuf.String()) - } - }) - }) - -} - func TestOpenAPIV3DoesNotLoadV2(t *testing.T) { cmdtesting.InitTestErrorHandler(t) nameRC, currentRC := readAndAnnotateReplicationController(t, filenameRC) diff --git a/pkg/cmd/diff/diff.go b/pkg/cmd/diff/diff.go index b82e493ce..9448cdde5 100644 --- a/pkg/cmd/diff/diff.go +++ b/pkg/cmd/diff/diff.go @@ -642,13 +642,11 @@ func (o *DiffOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []str if !o.ServerSideApply { o.OpenAPIGetter = f - if !cmdutil.OpenAPIV3Patch.IsDisabled() { - openAPIV3Client, err := f.OpenAPIV3Client() - if err == nil { - o.OpenAPIV3Root = openapi3.NewRoot(openAPIV3Client) - } else { - klog.V(4).Infof("warning: OpenAPI V3 Patch is enabled but is unable to be loaded. Will fall back to OpenAPI V2") - } + openAPIV3Client, err := f.OpenAPIV3Client() + if err == nil { + o.OpenAPIV3Root = openapi3.NewRoot(openAPIV3Client) + } else { + klog.V(4).Infof("warning: OpenAPI V3 Patch is enabled but is unable to be loaded. Will fall back to OpenAPI V2") } } diff --git a/pkg/cmd/util/helpers.go b/pkg/cmd/util/helpers.go index 282682044..855f43ce6 100644 --- a/pkg/cmd/util/helpers.go +++ b/pkg/cmd/util/helpers.go @@ -437,12 +437,6 @@ const ( // Separate kubectl user preferences. KubeRC FeatureGate = "KUBECTL_KUBERC" - // owner: @soltysh - // kep: https://kep.k8s.io/3515 - // - // Improved kubectl apply --prune behavior. - OpenAPIV3Patch FeatureGate = "KUBECTL_OPENAPIV3_PATCH" - // owner: @justinb // kep: https://kep.k8s.io/3659 //