Skip to content

Commit

Permalink
[operator] replenish k8s clientcmd util
Browse files Browse the repository at this point in the history
  • Loading branch information
mfordjody committed Dec 8, 2024
1 parent c56d188 commit 690a0fa
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
15 changes: 15 additions & 0 deletions pkg/util/kube/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package kube

import (
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
kubescheme "k8s.io/client-go/kubernetes/scheme"
)

func dubboScheme() *runtime.Scheme {
scheme := runtime.NewScheme()
utilruntime.Must(kubescheme.AddToScheme(scheme))
utilruntime.Must(apiextensionsv1.AddToScheme(scheme))

}

Check failure on line 15 in pkg/util/kube/client.go

View workflow job for this annotation

GitHub Actions / Go Test

missing return
16 changes: 13 additions & 3 deletions pkg/util/kube/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,33 @@ package kube

import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"

"os"
)

func DefaultRestConfig(kubeconfig, context string, fns ...func(config *rest.Config)) (*rest.Config, error) {
bcc, err := BuildClientConfig(kubeconfig, context)
if err != nil {
return nil, err
}
for _, fn := range fns {
fn(bcc)
}
return bcc, nil
}

func BuildClientConfig(kubeconfig, context string) (*rest.Config, error) {
c, err := BuildClientCmd(kubeconfig, context).ClientConfig()
if err != nil {
return nil, err
}
return
return c, nil
}

func SetRestDefaults(config *rest.Config) (*rest.Config) {
func SetRestDefaults(config *rest.Config) *rest.Config {
if config.GroupVersion == nil || config.GroupVersion.Empty() {
config.GroupVersion = &corev1.SchemeGroupVersion
}
Expand All @@ -31,6 +40,7 @@ func SetRestDefaults(config *rest.Config) (*rest.Config) {
}
}
if config.NegotiatedSerializer == nil {
config.NegotiatedSerializer = serializer.NewCodecFactory(dubboScheme()).WithoutConversion()
}
return config
}
Expand All @@ -53,4 +63,4 @@ func BuildClientCmd(kubeconfig, context string, overrides ...func(configOverride
fn(configOverrides)
}
return clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, configOverrides)
}
}

0 comments on commit 690a0fa

Please sign in to comment.