use OpenAPIV3 for kubectl diff

Kubernetes-commit: e7216c6623049d713fbf7cc04e2c42eb957a607e
This commit is contained in:
Jefftree 2023-09-15 17:53:10 -04:00 committed by Kubernetes Publisher
parent 8b0ab9a40e
commit 03a47d93ec
2 changed files with 11 additions and 0 deletions

View File

@ -222,6 +222,7 @@ func (p *Patcher) buildMergePatch(original, modified, current []byte) ([]byte, e
// gvkSupportsPatchOpenAPIV3 checks if a particular GVK supports the patch operation.
// It returns an error if the OpenAPI V3 could not be downloaded.
func (p *Patcher) gvkSupportsPatchOpenAPIV3(gvk schema.GroupVersionKind) (bool, error) {
// Bypassing root to save apiserver memory.
gvSpec, err := p.OpenAPIV3Root.GVSpec(schema.GroupVersion{
Group: p.Mapping.GroupVersionKind.Group,
Version: p.Mapping.GroupVersionKind.Version,

View File

@ -35,6 +35,7 @@ import (
"k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/cli-runtime/pkg/resource"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/openapi3"
"k8s.io/klog/v2"
"k8s.io/kubectl/pkg/cmd/apply"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
@ -110,6 +111,7 @@ type DiffOptions struct {
Concurrency int
Selector string
OpenAPISchema openapi.Resources
OpenAPIV3Root openapi3.Root
DynamicClient dynamic.Interface
CmdNamespace string
EnforceNamespace bool
@ -324,6 +326,7 @@ type InfoObject struct {
Info *resource.Info
Encoder runtime.Encoder
OpenAPI openapi.Resources
OpenAPIV3Root openapi3.Root
Force bool
ServerSideApply bool
FieldManager string
@ -396,6 +399,7 @@ func (obj InfoObject) Merged() (runtime.Object, error) {
Overwrite: true,
BackOff: clockwork.NewRealClock(),
OpenapiSchema: obj.OpenAPI,
OpenAPIV3Root: obj.OpenAPIV3Root,
ResourceVersion: resourceVersion,
}
@ -641,6 +645,11 @@ func (o *DiffOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []str
if err != nil {
return err
}
openAPIV3Client, err := f.OpenAPIV3Client()
if err != nil {
return err
}
o.OpenAPIV3Root = openapi3.NewRoot(openAPIV3Client)
}
o.DynamicClient, err = f.DynamicClient()
@ -722,6 +731,7 @@ func (o *DiffOptions) Run() error {
Info: info,
Encoder: scheme.DefaultJSONEncoder(),
OpenAPI: o.OpenAPISchema,
OpenAPIV3Root: o.OpenAPIV3Root,
Force: force,
ServerSideApply: o.ServerSideApply,
FieldManager: o.FieldManager,