-
Notifications
You must be signed in to change notification settings - Fork 750
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
support pass in kubeconfig and master to client-go by flag #706
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
package main | ||
|
||
import ( | ||
"flag" | ||
"io" | ||
"os" | ||
|
||
|
@@ -31,20 +32,28 @@ const ( | |
) | ||
|
||
var ( | ||
version string | ||
version string | ||
kubeconfig string | ||
master string | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we call this variable |
||
) | ||
|
||
func init() { | ||
flag.StringVar(&master, "master", "", "The address of the Kubernetes API server (overrides any value in kubeconfig).") | ||
flag.StringVar(&kubeconfig, "kubeconfig", "", "Path to kubeconfig file with authorization and master location information.") | ||
} | ||
|
||
func main() { | ||
os.Exit(_main()) | ||
} | ||
|
||
func _main() int { | ||
defer log.Flush() | ||
flag.Parse() | ||
logger.SetupLogger(logger.GetLogFileLocation(defaultLogFilePath)) | ||
|
||
log.Infof("Starting L-IPAMD %s ...", version) | ||
|
||
kubeClient, err := k8sapi.CreateKubeClient() | ||
kubeClient, err := k8sapi.CreateKubeClient(kubeconfig, master) | ||
if err != nil { | ||
log.Errorf("Failed to create client: %v", err) | ||
return 1 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,19 +8,20 @@ import ( | |
"sync" | ||
"time" | ||
|
||
"github.com/operator-framework/operator-sdk/pkg/k8sclient" | ||
"github.com/pkg/errors" | ||
|
||
log "github.com/cihub/seelog" | ||
|
||
clientset "k8s.io/client-go/kubernetes" | ||
|
||
"github.com/operator-framework/operator-sdk/pkg/k8sclient" | ||
v1 "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/tools/cache" | ||
"k8s.io/client-go/tools/clientcmd" | ||
"k8s.io/client-go/util/workqueue" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
@@ -80,8 +81,21 @@ func NewController(clientset kubernetes.Interface) *Controller { | |
} | ||
|
||
// CreateKubeClient creates a k8s client | ||
func CreateKubeClient() (clientset.Interface, error) { | ||
kubeClient := k8sclient.GetKubeClient() | ||
func CreateKubeClient(kubeconfig, master string) (clientset.Interface, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is called from cni-metrics-helper, and is the reason your unit tests are failing:
|
||
var kubeClient clientset.Interface | ||
if master == "" && kubeconfig == "" { | ||
kubeClient = k8sclient.GetKubeClient() | ||
} else { | ||
config, err := clientcmd.BuildConfigFromFlags(master, kubeconfig) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Frankly, and if it does, loads the inClusterConfig appropriately, which is what the The dependency amazon-vpc-cni-k8s has on operator-sdk is ancient (0.0.7 which was released >1 year ago) and modern releases of operator-sdk don't even have a k8sclient package at all. |
||
if err != nil { | ||
panic(err) | ||
} | ||
kubeClient, err = clientset.NewForConfig(config) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
// 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. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we call this variable
kubeconfigPath
please, to indicate it is a filepath not a config object?