Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update k8sapi to use operator-framework inClusterConfig #364

Merged
merged 1 commit into from
Mar 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

// 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