-
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
Conversation
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.
A few things I'd like to see changed... please see inline comments.
Thanks!
-jay
version string | ||
version string | ||
kubeconfig string | ||
master string |
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 apiServerAddr
please instead of master
?
@@ -31,20 +32,28 @@ const ( | |||
) | |||
|
|||
var ( | |||
version string | |||
version string | |||
kubeconfig string |
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?
@@ -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 comment
The 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:
# github.com/aws/amazon-vpc-cni-k8s/cni-metrics-helper
cni-metrics-helper/cni-metrics-helper.go:82:44: not enough arguments in call to k8sapi.CreateKubeClient
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Frankly, client-go/tools/clientcmd.BuildConfigFromFlags
is able to accept empty kube API server URL and config path:
and if it does, loads the inClusterConfig appropriately, which is what the k8sclient.GetKubeClient
call does. So, I would rather just remove the whole operator-sdk k8sclient pkg dependency here and just use client-go's clientcmd for this.
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.
@jaypipes I would change as you advise, but there are some other questions need to discuss. I found it more difficult than I imagined. For now, the we need to
Based on this precondition, there are two workflows we can follow: Option 1
The YAML of pod looks like this:
I would like this way, this pattern is more clear. but the question is: now we have some hardcode paths in our main.go: Lines 78 to 90 in 3b4fd50
all those paths are prepared by /app/install-aws.sh in init container and then used by the main container, however, the init container and main container have different rootfs and can not share files. the main container would not found all these files and failed to run. we need to add a HostPath volume to let those two container transfer files. Option 2
this option would be easier to achieve. Any thought? |
Instead of using a shell script as the entrypoint for the CNI image and relying on that shell script to copy the CNI plugin binary to a host volume, perform those steps using an initContainer and set the CNI aws-k8s-agent binary to be the CNI image's CMD. This has the benefit of not embedding setup steps in either a shell script that needs to be copied into the target image /app directory nor hard-coded into the aws-k8s-agent's main.go file (which was performing the copy of the CNI plugin binary to a host volume). See discussion in aws#706 (comment) for more details.
I went with your first suggestion, which I thought was excellent: |
Instead of using a shell script as the entrypoint for the CNI image and relying on that shell script to copy the CNI plugin binary to a host volume, perform those steps using an initContainer and set the CNI aws-k8s-agent binary to be the CNI image's CMD. This has the benefit of not embedding setup steps in either a shell script that needs to be copied into the target image /app directory nor hard-coded into the aws-k8s-agent's main.go file (which was performing the copy of the CNI plugin binary to a host volume). See discussion in aws#706 (comment) for more details.
@jaypipes Sorry for the late reply. We have bypassed this issue. Besides, My account of the aws cluster has run out of crash and been destroyed, I’m sorry that I can not continue to work on this. |
No problem @gaorong. I'll pick up your work on this and drive to completion. Thanks! |
Now we can talk to apiserver by specifying
--kubeconfig
or--master
flag other than default in-cluster config, so we can remove the dependence on kube-proxy, that is to say,aws-k8s-agent
can start successfully without kube-proxy.Have verified in our aws environment and everything works fine.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.