mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 18:24:07 +00:00
use OpenAPIV3 for kubectl diff
This commit is contained in:
parent
4f3b0b1518
commit
e7216c6623
@ -183,7 +183,7 @@ func resolve(l *PatchMetaFromOpenAPIV3) error {
|
|||||||
if ok {
|
if ok {
|
||||||
l.Schema = sch
|
l.Schema = sch
|
||||||
} else {
|
} else {
|
||||||
return fmt.Errorf("Unable to resolve %s in OpenAPI V3", refString)
|
return fmt.Errorf("unable to resolve %s in OpenAPI V3", refString)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -225,7 +225,7 @@ func (s PatchMetaFromOpenAPIV3) LookupPatchMetadataForSlice(key string) (LookupP
|
|||||||
if l.Schema.Items != nil {
|
if l.Schema.Items != nil {
|
||||||
l.Schema = l.Schema.Items.Schema
|
l.Schema = l.Schema.Items.Schema
|
||||||
}
|
}
|
||||||
resolve(&l)
|
err = resolve(&l)
|
||||||
return l, p, err
|
return l, p, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -222,6 +222,7 @@ func (p *Patcher) buildMergePatch(original, modified, current []byte) ([]byte, e
|
|||||||
// gvkSupportsPatchOpenAPIV3 checks if a particular GVK supports the patch operation.
|
// gvkSupportsPatchOpenAPIV3 checks if a particular GVK supports the patch operation.
|
||||||
// It returns an error if the OpenAPI V3 could not be downloaded.
|
// It returns an error if the OpenAPI V3 could not be downloaded.
|
||||||
func (p *Patcher) gvkSupportsPatchOpenAPIV3(gvk schema.GroupVersionKind) (bool, error) {
|
func (p *Patcher) gvkSupportsPatchOpenAPIV3(gvk schema.GroupVersionKind) (bool, error) {
|
||||||
|
// Bypassing root to save apiserver memory.
|
||||||
gvSpec, err := p.OpenAPIV3Root.GVSpec(schema.GroupVersion{
|
gvSpec, err := p.OpenAPIV3Root.GVSpec(schema.GroupVersion{
|
||||||
Group: p.Mapping.GroupVersionKind.Group,
|
Group: p.Mapping.GroupVersionKind.Group,
|
||||||
Version: p.Mapping.GroupVersionKind.Version,
|
Version: p.Mapping.GroupVersionKind.Version,
|
||||||
|
@ -35,6 +35,7 @@ import (
|
|||||||
"k8s.io/cli-runtime/pkg/genericiooptions"
|
"k8s.io/cli-runtime/pkg/genericiooptions"
|
||||||
"k8s.io/cli-runtime/pkg/resource"
|
"k8s.io/cli-runtime/pkg/resource"
|
||||||
"k8s.io/client-go/dynamic"
|
"k8s.io/client-go/dynamic"
|
||||||
|
"k8s.io/client-go/openapi3"
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
"k8s.io/kubectl/pkg/cmd/apply"
|
"k8s.io/kubectl/pkg/cmd/apply"
|
||||||
cmdutil "k8s.io/kubectl/pkg/cmd/util"
|
cmdutil "k8s.io/kubectl/pkg/cmd/util"
|
||||||
@ -110,6 +111,7 @@ type DiffOptions struct {
|
|||||||
Concurrency int
|
Concurrency int
|
||||||
Selector string
|
Selector string
|
||||||
OpenAPISchema openapi.Resources
|
OpenAPISchema openapi.Resources
|
||||||
|
OpenAPIV3Root openapi3.Root
|
||||||
DynamicClient dynamic.Interface
|
DynamicClient dynamic.Interface
|
||||||
CmdNamespace string
|
CmdNamespace string
|
||||||
EnforceNamespace bool
|
EnforceNamespace bool
|
||||||
@ -324,6 +326,7 @@ type InfoObject struct {
|
|||||||
Info *resource.Info
|
Info *resource.Info
|
||||||
Encoder runtime.Encoder
|
Encoder runtime.Encoder
|
||||||
OpenAPI openapi.Resources
|
OpenAPI openapi.Resources
|
||||||
|
OpenAPIV3Root openapi3.Root
|
||||||
Force bool
|
Force bool
|
||||||
ServerSideApply bool
|
ServerSideApply bool
|
||||||
FieldManager string
|
FieldManager string
|
||||||
@ -396,6 +399,7 @@ func (obj InfoObject) Merged() (runtime.Object, error) {
|
|||||||
Overwrite: true,
|
Overwrite: true,
|
||||||
BackOff: clockwork.NewRealClock(),
|
BackOff: clockwork.NewRealClock(),
|
||||||
OpenapiSchema: obj.OpenAPI,
|
OpenapiSchema: obj.OpenAPI,
|
||||||
|
OpenAPIV3Root: obj.OpenAPIV3Root,
|
||||||
ResourceVersion: resourceVersion,
|
ResourceVersion: resourceVersion,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -641,6 +645,11 @@ func (o *DiffOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []str
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
openAPIV3Client, err := f.OpenAPIV3Client()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
o.OpenAPIV3Root = openapi3.NewRoot(openAPIV3Client)
|
||||||
}
|
}
|
||||||
|
|
||||||
o.DynamicClient, err = f.DynamicClient()
|
o.DynamicClient, err = f.DynamicClient()
|
||||||
@ -722,6 +731,7 @@ func (o *DiffOptions) Run() error {
|
|||||||
Info: info,
|
Info: info,
|
||||||
Encoder: scheme.DefaultJSONEncoder(),
|
Encoder: scheme.DefaultJSONEncoder(),
|
||||||
OpenAPI: o.OpenAPISchema,
|
OpenAPI: o.OpenAPISchema,
|
||||||
|
OpenAPIV3Root: o.OpenAPIV3Root,
|
||||||
Force: force,
|
Force: force,
|
||||||
ServerSideApply: o.ServerSideApply,
|
ServerSideApply: o.ServerSideApply,
|
||||||
FieldManager: o.FieldManager,
|
FieldManager: o.FieldManager,
|
||||||
|
Loading…
Reference in New Issue
Block a user