-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add 'cluster', 'namespace', and 'user' options to delete command. Enhance delete to load provider components from cluster. #384
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
Add 'cluster', 'namespace', and 'user' options to delete command. Enhance delete to load provider components from cluster. #384
Conversation
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: spew The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
eef7f3c
to
03ca60d
Compare
/assign @roberthbailey @mkjelland @k4leung4 |
84c2870
to
28a7872
Compare
@@ -65,15 +67,16 @@ func (c *clusterClient) removeKubeconfigFile() error { | |||
return os.Remove(c.kubeconfigFile) | |||
} | |||
|
|||
func NewClusterClientFromFile(kubeconfigFile string) (*clusterClient, error) { | |||
c, err := clientcmd.NewClusterApiClientForDefaultSearchPath(kubeconfigFile) | |||
func NewClusterClientFromDefaultSearchPath(kubeconfigFile string, overrides tcmd.ConfigOverrides) (*clusterClient, 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 one treats the first param as a string and the prior treats it as the actual config? That seems backwards to me, but maybe that's because the libraries you are calling need to do the file handling....
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.
Both versions of this function treat the kubeconfigFile argument as a string. With the addition of the ability to select a specific Context in the Kubeconfig search path, I chose to rename the method to more accurately reflect reality, namely, if an empty string is passed in for kubeconfigFile then when iclientcmd.NewClusterApiClientForDefaultSearchPath(...) is called it will search for all kubeconfigs in the default search path (
What do you think?
@@ -65,15 +67,16 @@ func (c *clusterClient) removeKubeconfigFile() error { | |||
return os.Remove(c.kubeconfigFile) | |||
} | |||
|
|||
func NewClusterClientFromFile(kubeconfigFile string) (*clusterClient, error) { | |||
c, err := clientcmd.NewClusterApiClientForDefaultSearchPath(kubeconfigFile) | |||
func NewClusterClientFromDefaultSearchPath(kubeconfigFile string, overrides tcmd.ConfigOverrides) (*clusterClient, 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.
I'm not sure I understand the name of this fn; why not name it NewFromFile(...)?
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.
Please see my reply on the other comment about parameters and function name.
clientSet clientset.Interface | ||
kubeconfigFile string | ||
configOverrides tcmd.ConfigOverrides | ||
closeFn func() error | ||
} | ||
|
||
func NewClusterClient(kubeconfig string) (*clusterClient, 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 should just be New(...)
so that people who import the package call clusterclient.New(...)
instead of clusterclient.NewClusterClient(...)
which is redundantly long (for go style).
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.
The reason why I think the original author named it NewClusterClient is because it lives in the clusterdeployer package which already has a New(...) method. Happy to move it to another package in another PR if you agree that is the thing to do (I think it probably is?)
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.
Moving it in another PR would be great. Want to open an issue and label it as help-wanted? That would be a good thing for someone who wants to start sending code to take a crack at.
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.
Created an issue here: #398
@@ -65,15 +67,16 @@ func (c *clusterClient) removeKubeconfigFile() error { | |||
return os.Remove(c.kubeconfigFile) |
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.
Does createTempFile handle removing the file automatically? I'm guessing not since we call os.Remove here. Which means that if there is an error creating the client we leak the file. We need to defer removing the file so that it gets cleaned up even on the error return paths.
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.
I created a PR here: #390, which addresses this issue in two places. Note that there is still an opportunity to leak files if the user prematurely terminates the program or an automated system kills the VM / container. So in any sort of automated system we will need cleanup processes that handle leaked files.
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.
PR #390 merged and I have rebased this commit on top.
@@ -164,15 +167,31 @@ func (c *clusterClient) WaitForClusterV1alpha1Ready() error { | |||
|
|||
func (c *clusterClient) kubectlApply(manifest string) error { | |||
r := strings.NewReader(manifest) |
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.
I'm not sure why r
is a separate variable instead of being inlined below (cmd.Stdin = strings.NewReader(manifest)
).
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.
Yeah, I should have changed this too in the refactor of the method. Will change.
@@ -164,15 +167,31 @@ func (c *clusterClient) WaitForClusterV1alpha1Ready() error { | |||
|
|||
func (c *clusterClient) kubectlApply(manifest string) error { | |||
r := strings.NewReader(manifest) | |||
cmd := exec.Command("kubectl", "apply", "--kubeconfig", c.kubeconfigFile, "-f", "-") | |||
args := c.buildKubectlArgs("apply") |
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.
Unless we are going to print args or do something else with it, just put the call inline below
cmd := exec.Command("kubectl", c.buildKubectlArgs("apply")...)
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.
Agree, changed.
@@ -3,8 +3,12 @@ Usage: | |||
clusterctl delete cluster [flags] | |||
|
|||
Flags: | |||
--cluster string The name of the kubeconfig cluster to use |
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 help text isn't super clear without reading the code. Maybe "The name of the cluster to use in the kubeconfig file"?
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.
We get this help text for 'free' from the libraries so it matches what kubectl has for help text (and actually the entire ecosystem of CLIs that are using the same client-go libraries). I do agree the message isn't super clear. However, there are some nice things about providing a consistent experience as users who are familiar with kubectl would know exactly what this means. So I see three options:
- Improve the message and diverge from what kubectl prints out, open PR upstream in client-go to improve the kubectl string.
- Leave message as it is (no custom code / message). Open PR to improve the messaging in client-go, wait for that to get vendored in.
- Run with our own message and diverge completely from the rest of the kubernetes community.
Of these options I think I like #2 the best as it is the least work and the only users right now are early adopters. It will be less work because we don't have to remember to remove our custom message later once client-go picks up the new messaging. However, I'm happy to do #1 if you think that is best. What do you think? (or do you have another idea?).
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.
Your second option seems reasonable to me.
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.
Will follow up with another PR in kube core -- I have an open issue here: #397
-h, --help help for cluster | ||
--kubeconfig string Path to the kubeconfig file to use for connecting to the cluster to be deleted, if empty, the default KUBECONFIG load path is used. | ||
-n, --namespace string If present, the namespace scope for this CLI request |
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 namespace for the kubectl apply commands, which isn't super clear from the help text.
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.
It is for kubectl apply true, but will also be the namespace for everything clusterctl delete cluster
does as the clients will be configured for this namespace.
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.
Addressed a couple of issues and left open some questions for @roberthbailey before I go implement changes.
clientSet clientset.Interface | ||
kubeconfigFile string | ||
configOverrides tcmd.ConfigOverrides | ||
closeFn func() error | ||
} | ||
|
||
func NewClusterClient(kubeconfig string) (*clusterClient, 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.
The reason why I think the original author named it NewClusterClient is because it lives in the clusterdeployer package which already has a New(...) method. Happy to move it to another package in another PR if you agree that is the thing to do (I think it probably is?)
@@ -65,15 +67,16 @@ func (c *clusterClient) removeKubeconfigFile() error { | |||
return os.Remove(c.kubeconfigFile) |
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.
I created a PR here: #390, which addresses this issue in two places. Note that there is still an opportunity to leak files if the user prematurely terminates the program or an automated system kills the VM / container. So in any sort of automated system we will need cleanup processes that handle leaked files.
@@ -65,15 +67,16 @@ func (c *clusterClient) removeKubeconfigFile() error { | |||
return os.Remove(c.kubeconfigFile) | |||
} | |||
|
|||
func NewClusterClientFromFile(kubeconfigFile string) (*clusterClient, error) { | |||
c, err := clientcmd.NewClusterApiClientForDefaultSearchPath(kubeconfigFile) | |||
func NewClusterClientFromDefaultSearchPath(kubeconfigFile string, overrides tcmd.ConfigOverrides) (*clusterClient, 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.
Both versions of this function treat the kubeconfigFile argument as a string. With the addition of the ability to select a specific Context in the Kubeconfig search path, I chose to rename the method to more accurately reflect reality, namely, if an empty string is passed in for kubeconfigFile then when iclientcmd.NewClusterApiClientForDefaultSearchPath(...) is called it will search for all kubeconfigs in the default search path (
What do you think?
@@ -164,15 +167,31 @@ func (c *clusterClient) WaitForClusterV1alpha1Ready() error { | |||
|
|||
func (c *clusterClient) kubectlApply(manifest string) error { | |||
r := strings.NewReader(manifest) |
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.
Yeah, I should have changed this too in the refactor of the method. Will change.
@@ -164,15 +167,31 @@ func (c *clusterClient) WaitForClusterV1alpha1Ready() error { | |||
|
|||
func (c *clusterClient) kubectlApply(manifest string) error { | |||
r := strings.NewReader(manifest) | |||
cmd := exec.Command("kubectl", "apply", "--kubeconfig", c.kubeconfigFile, "-f", "-") | |||
args := c.buildKubectlArgs("apply") |
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.
Agree, changed.
@@ -3,8 +3,12 @@ Usage: | |||
clusterctl delete cluster [flags] | |||
|
|||
Flags: | |||
--cluster string The name of the kubeconfig cluster to use |
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.
We get this help text for 'free' from the libraries so it matches what kubectl has for help text (and actually the entire ecosystem of CLIs that are using the same client-go libraries). I do agree the message isn't super clear. However, there are some nice things about providing a consistent experience as users who are familiar with kubectl would know exactly what this means. So I see three options:
- Improve the message and diverge from what kubectl prints out, open PR upstream in client-go to improve the kubectl string.
- Leave message as it is (no custom code / message). Open PR to improve the messaging in client-go, wait for that to get vendored in.
- Run with our own message and diverge completely from the rest of the kubernetes community.
Of these options I think I like #2 the best as it is the least work and the only users right now are early adopters. It will be less work because we don't have to remember to remove our custom message later once client-go picks up the new messaging. However, I'm happy to do #1 if you think that is best. What do you think? (or do you have another idea?).
-h, --help help for cluster | ||
--kubeconfig string Path to the kubeconfig file to use for connecting to the cluster to be deleted, if empty, the default KUBECONFIG load path is used. | ||
-n, --namespace string If present, the namespace scope for this CLI request |
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.
It is for kubectl apply true, but will also be the namespace for everything clusterctl delete cluster
does as the clients will be configured for this namespace.
28a7872
to
5f5ce5b
Compare
no additional beyond what @roberthbailey have pointed out. |
…ance delete to load provider components from cluster.
5f5ce5b
to
056eddb
Compare
/lgtm |
What this PR does / why we need it:
This PR adds the 'cluster', 'namespace', and 'user' options to the
clusterctl delete cluster
command. These options match what is available inkubectl
. Also, thedelete cluster
command is enhanced to load the provider components from cluster.Release note:
@kubernetes/kube-deploy-reviewers