Skip to content

Commit

Permalink
feat(kbmc): support running in in-cluster or local mode
Browse files Browse the repository at this point in the history
  • Loading branch information
starbops committed Nov 16, 2023
1 parent a4fd97e commit 7a122d0
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions pkg/kbmc/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/sirupsen/logrus"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
kubevirtv1 "kubevirt.io/api/core/v1"

kubevirtv1type "zespre.com/kubebmc/pkg/generated/clientset/versioned/typed/core/v1"
Expand All @@ -22,21 +23,25 @@ func NewK8sClient(options Options) *kubevirtv1type.KubevirtV1Client {
err error
)

// if options.KubeconfigPath == "" {
// // creates the in-cluster config
// creates the in-cluster config
config, err = rest.InClusterConfig()
if err != nil {
if err == rest.ErrNotInCluster {
goto localConfig
}
panic(err.Error())
}
goto genClientset

localConfig:
// uses the current context in kubeconfig
// path-to-kubeconfig -- for example, /root/.kube/config
config, err = clientcmd.BuildConfigFromFlags("", options.KubeconfigPath)
if err != nil {
panic(err.Error())
}
// } else {
// // uses the current context in kubeconfig
// // path-to-kubeconfig -- for example, /root/.kube/config
// config, err = clientcmd.BuildConfigFromFlags("", options.KubeconfigPath)
// if err != nil {
// panic(err.Error())
// }
// }

genClientset:
clientset, err := kubevirtv1type.NewForConfig(config)
if err != nil {
panic(err.Error())
Expand Down

0 comments on commit 7a122d0

Please sign in to comment.