Skip to content

Commit

Permalink
Merge pull request #364 from tiffanyfay/inclusterconfig
Browse files Browse the repository at this point in the history
Update k8sapi to use operator-framework inClusterConfig
  • Loading branch information
mogren committed Mar 28, 2019
2 parents c35d67b + d8097bd commit 20b9b20
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 20 deletions.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func _main() int {

log.Infof("Starting L-IPAMD %s ...", version)

kubeClient, err := k8sapi.CreateKubeClient("", "")
kubeClient, err := k8sapi.CreateKubeClient()
if err != nil {
log.Errorf("Failed to create client: %v", err)
return 1
Expand Down
22 changes: 3 additions & 19 deletions pkg/k8sapi/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ import (
log "github.com/cihub/seelog"

clientset "k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"

"github.com/operator-framework/operator-sdk/pkg/k8sclient"
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/util/workqueue"

Expand Down Expand Up @@ -72,23 +71,8 @@ func NewController(clientset kubernetes.Interface) *Controller {
}

// CreateKubeClient creates a k8s client
func CreateKubeClient(apiserver string, kubeconfig string) (clientset.Interface, error) {
var config *rest.Config
var err error
if apiserver == "" && kubeconfig == "" {
config, err = rest.InClusterConfig()
} else {
config, err = clientcmd.BuildConfigFromFlags(apiserver, kubeconfig)
}
if err != nil {
return nil, err
}

kubeClient, err := clientset.NewForConfig(config)
if err != nil {
return nil, err
}

func CreateKubeClient() (clientset.Interface, error) {
kubeClient := k8sclient.GetKubeClient()
// Informers don't seem to do a good job logging error messages when it
// can't reach the server, making debugging hard. This makes it easier to
// figure out if apiserver is configured incorrectly.
Expand Down

0 comments on commit 20b9b20

Please sign in to comment.