Merge pull request #7249 from jabielecki/addtoscheme-once

fix(kube) only add to scheme.Scheme once
pull/7435/head
Matthew Fisher 5 years ago committed by GitHub
commit 1d9007d087
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -57,20 +57,23 @@ type Client struct {
Log func(string, ...interface{}) Log func(string, ...interface{})
} }
var addToScheme sync.Once
// New creates a new Client. // New creates a new Client.
func New(getter genericclioptions.RESTClientGetter) *Client { func New(getter genericclioptions.RESTClientGetter) *Client {
if getter == nil { if getter == nil {
getter = genericclioptions.NewConfigFlags(true) getter = genericclioptions.NewConfigFlags(true)
} }
// Add CRDs to the scheme. They are missing by default. // Add CRDs to the scheme. They are missing by default.
addToScheme.Do(func() {
if err := apiextv1.AddToScheme(scheme.Scheme); err != nil { if err := apiextv1.AddToScheme(scheme.Scheme); err != nil {
// This should never happen. // This should never happen.
panic(err) panic(err)
} }
if err := apiextv1beta1.AddToScheme(scheme.Scheme); err != nil { if err := apiextv1beta1.AddToScheme(scheme.Scheme); err != nil {
// This should never happen.
panic(err) panic(err)
} }
})
return &Client{ return &Client{
Factory: cmdutil.NewFactory(getter), Factory: cmdutil.NewFactory(getter),
Log: nopLogger, Log: nopLogger,

Loading…
Cancel
Save