mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-20 18:31:15 +00:00
enable openapiv3 by default
This commit is contained in:
parent
de9ce03f19
commit
ce3385ab1f
@ -68,10 +68,6 @@ type ExplainOptions struct {
|
||||
Mapper meta.RESTMapper
|
||||
Schema openapi.Resources
|
||||
|
||||
// Toggles whether the OpenAPI v3 template-based renderer should be used to show
|
||||
// output.
|
||||
EnableOpenAPIV3 bool
|
||||
|
||||
// Name of the template to use with the openapiv3 template renderer. If
|
||||
// `EnableOpenAPIV3` is disabled, this does nothing
|
||||
OutputFormat string
|
||||
@ -84,7 +80,6 @@ func NewExplainOptions(parent string, streams genericclioptions.IOStreams) *Expl
|
||||
return &ExplainOptions{
|
||||
IOStreams: streams,
|
||||
CmdParent: parent,
|
||||
EnableOpenAPIV3: cmdutil.ExplainOpenapiV3.IsEnabled(),
|
||||
OutputFormat: plaintextTemplateName,
|
||||
}
|
||||
}
|
||||
@ -109,9 +104,7 @@ func NewCmdExplain(parent string, f cmdutil.Factory, streams genericclioptions.I
|
||||
cmd.Flags().StringVar(&o.APIVersion, "api-version", o.APIVersion, "Get different explanations for particular API version (API group/version)")
|
||||
|
||||
// Only enable --output as a valid flag if the feature is enabled
|
||||
if o.EnableOpenAPIV3 {
|
||||
cmd.Flags().StringVar(&o.OutputFormat, "output", plaintextTemplateName, "Format in which to render the schema (plaintext, plaintext-openapiv2)")
|
||||
}
|
||||
|
||||
return cmd
|
||||
}
|
||||
@ -128,13 +121,11 @@ func (o *ExplainOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []
|
||||
return err
|
||||
}
|
||||
|
||||
// Only openapi v3 needs the openapiv3client
|
||||
if o.EnableOpenAPIV3 {
|
||||
// Only openapi v3 needs the discovery client.
|
||||
o.OpenAPIV3Client, err = f.OpenAPIV3Client()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
o.args = args
|
||||
return nil
|
||||
@ -172,7 +163,6 @@ func (o *ExplainOptions) Run() error {
|
||||
}
|
||||
|
||||
// Fallback to openapiv2 implementation using special template name
|
||||
if o.EnableOpenAPIV3 {
|
||||
switch o.OutputFormat {
|
||||
case plaintextOpenAPIV2TemplateName:
|
||||
return o.renderOpenAPIV2(fullySpecifiedGVR, fieldsPath)
|
||||
@ -203,8 +193,6 @@ func (o *ExplainOptions) Run() error {
|
||||
o.OutputFormat,
|
||||
)
|
||||
}
|
||||
}
|
||||
return o.renderOpenAPIV2(fullySpecifiedGVR, fieldsPath)
|
||||
}
|
||||
|
||||
func (o *ExplainOptions) renderOpenAPIV2(
|
||||
|
@ -22,7 +22,6 @@ import (
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"k8s.io/apimachinery/pkg/api/meta"
|
||||
sptest "k8s.io/apimachinery/pkg/util/strategicpatch/testing"
|
||||
"k8s.io/cli-runtime/pkg/genericclioptions"
|
||||
@ -278,21 +277,3 @@ func runExplainTestCases(t *testing.T, cases []explainTestCase) {
|
||||
buf.Reset()
|
||||
}
|
||||
}
|
||||
|
||||
func TestAlphaEnablement(t *testing.T) {
|
||||
alphas := map[cmdutil.FeatureGate]string{
|
||||
cmdutil.ExplainOpenapiV3: "output",
|
||||
}
|
||||
for feature, flag := range alphas {
|
||||
f := cmdtesting.NewTestFactory()
|
||||
defer f.Cleanup()
|
||||
|
||||
cmd := explain.NewCmdExplain("kubectl", f, genericclioptions.NewTestIOStreamsDiscard())
|
||||
require.Nil(t, cmd.Flags().Lookup(flag), "flag %q should not be registered without the %q feature enabled", flag, feature)
|
||||
|
||||
cmdtesting.WithAlphaEnvs([]cmdutil.FeatureGate{feature}, t, func(t *testing.T) {
|
||||
cmd := explain.NewCmdExplain("kubectl", f, genericclioptions.NewTestIOStreamsDiscard())
|
||||
require.NotNil(t, cmd.Flags().Lookup(flag), "flag %q should be registered with the %q feature enabled", flag, feature)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user