@@ -6,13 +6,15 @@ import (
66 "k8s.io/api/core/v1"
77 "k8s.io/apimachinery/pkg/fields"
88 "k8s.io/client-go/kubernetes"
9+ "k8s.io/client-go/rest"
910 "k8s.io/client-go/tools/cache"
1011 "k8s.io/client-go/tools/clientcmd"
1112 "net"
1213)
1314
1415type IK8sWatcher interface {
15- Start (kubeConfigFile string ) error
16+ StartWithConfig (kubeConfigFile string ) error
17+ StartInCluster () error
1618 Stop ()
1719}
1820
@@ -22,12 +24,25 @@ type k8sWatcherImpl struct {
2224 stop chan struct {}
2325}
2426
25- func (w * k8sWatcherImpl ) Start (kubeConfigFile string ) error {
27+ func (w * k8sWatcherImpl ) StartInCluster () error {
28+ config , err := rest .InClusterConfig ()
29+ if err != nil {
30+ return errors .Wrap (err , "Unable to load in-cluster config" )
31+ }
32+
33+ return w .startWithLoadedConfig (config )
34+ }
35+
36+ func (w * k8sWatcherImpl ) StartWithConfig (kubeConfigFile string ) error {
2637 config , err := clientcmd .BuildConfigFromFlags ("" , kubeConfigFile )
2738 if err != nil {
2839 return errors .Wrap (err , "Could not load kube config file" )
2940 }
3041
42+ return w .startWithLoadedConfig (config )
43+ }
44+
45+ func (w * k8sWatcherImpl ) startWithLoadedConfig (config * rest.Config ) error {
3146 clientset , err := kubernetes .NewForConfig (config )
3247 if err != nil {
3348 return errors .Wrap (err , "Could not create kube clientset" )
0 commit comments