Add feature toggle for OpenAPI V3 apply in kubectl

This commit is contained in:
Jefftree 2023-10-27 01:23:19 -04:00
parent e7216c6623
commit f23ab829be
4 changed files with 654 additions and 510 deletions

View File

@ -288,7 +288,7 @@ func (flags *ApplyFlags) ToOptions(f cmdutil.Factory, cmd *cobra.Command, baseNa
openAPISchema, _ := f.OpenAPISchema()
var openAPIV3Root openapi3.Root
openAPIV3Client, err := f.OpenAPIV3Client()
if err == nil {
if err == nil && !cmdutil.OpenAPIV3Apply.IsDisabled() {
cachedOpenAPIV3Client := cachedopenapi.NewClient(openAPIV3Client)
openAPIV3Root = openapi3.NewRoot(cachedOpenAPIV3Client)
}

File diff suppressed because it is too large Load Diff

View File

@ -195,3 +195,18 @@ func WithAlphaEnvs(features []cmdutil.FeatureGate, t *testing.T, f func(*testing
}
f(t)
}
// WithAlphaEnvs calls func f with the given env-var-based feature gates disabled,
// and then restores the original values of those variables.
func WithAlphaEnvsDisabled(features []cmdutil.FeatureGate, t *testing.T, f func(*testing.T)) {
for _, feature := range features {
key := string(feature)
if key != "" {
oldValue := os.Getenv(key)
err := os.Setenv(key, "false")
require.NoError(t, err, "unexpected error setting alpha env")
defer os.Setenv(key, oldValue)
}
}
f(t)
}

View File

@ -428,6 +428,7 @@ const (
ApplySet FeatureGate = "KUBECTL_APPLYSET"
CmdPluginAsSubcommand FeatureGate = "KUBECTL_ENABLE_CMD_SHADOW"
InteractiveDelete FeatureGate = "KUBECTL_INTERACTIVE_DELETE"
OpenAPIV3Apply FeatureGate = "KUBECTL_OPENAPIV3_APPLY"
RemoteCommandWebsockets FeatureGate = "KUBECTL_REMOTE_COMMAND_WEBSOCKETS"
)