mirror of
https://github.com/helm/helm.git
synced 2026-05-28 04:35:48 -04:00
fix(kube): generate k8s native scheme only once
Signed-off-by: Hidde Beydals <hello@hidde.co>
This commit is contained in:
parent
b55224ebb9
commit
e41184a585
1 changed files with 14 additions and 8 deletions
|
|
@ -17,16 +17,20 @@ limitations under the License.
|
|||
package kube // import "helm.sh/helm/v3/pkg/kube"
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
|
||||
apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
|
||||
"k8s.io/apimachinery/pkg/api/meta"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||
"k8s.io/cli-runtime/pkg/resource"
|
||||
"k8s.io/client-go/kubernetes/scheme"
|
||||
)
|
||||
|
||||
var k8sNativeScheme *runtime.Scheme
|
||||
var k8sNativeSchemeOnce sync.Once
|
||||
|
||||
// AsVersioned converts the given info into a runtime.Object with the correct
|
||||
// group and version set
|
||||
func AsVersioned(info *resource.Info) runtime.Object {
|
||||
|
|
@ -53,11 +57,13 @@ func convertWithMapper(obj runtime.Object, mapping *meta.RESTMapping) runtime.Ob
|
|||
// combination with e.g. a versioned kube client. If we would not do this, the client
|
||||
// may attempt to perform e.g. a 3-way-merge strategy patch for custom resources.
|
||||
func kubernetesNativeScheme() *runtime.Scheme {
|
||||
s := runtime.NewScheme()
|
||||
utilruntime.Must(scheme.AddToScheme(s))
|
||||
// API extensions are not in the above scheme set,
|
||||
// and must thus be added separately.
|
||||
utilruntime.Must(apiextensionsv1beta1.AddToScheme(s))
|
||||
utilruntime.Must(apiextensionsv1.AddToScheme(s))
|
||||
return s
|
||||
k8sNativeSchemeOnce.Do(func() {
|
||||
k8sNativeScheme = runtime.NewScheme()
|
||||
scheme.AddToScheme(k8sNativeScheme)
|
||||
// API extensions are not in the above scheme set,
|
||||
// and must thus be added separately.
|
||||
apiextensionsv1beta1.AddToScheme(k8sNativeScheme)
|
||||
apiextensionsv1.AddToScheme(k8sNativeScheme)
|
||||
})
|
||||
return k8sNativeScheme
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue