Skip to content
This repository has been archived by the owner on Jun 28, 2023. It is now read-only.

Introduces ExistingClusterKubeconfig option to unmanaged-cluster #2918

Merged
merged 1 commit into from
Jan 27, 2022

Conversation

jpmcb
Copy link
Contributor

@jpmcb jpmcb commented Jan 24, 2022

What this PR does / why we need it

This PR introduces the ExistingClusterKubeconfig config option which is supported by the --existing-cluster-kubeconfig flag during create.

This enables users to bring their own clusters that already exist and already have a kubeconfig on the filesystem.

Why not just use KubeconfigPath?

This would have required a greater refactor since the config.KubeconfigPath is used to create and set the context of new created kind clusters:

clusterConfig := kindcluster.CreateWithkubeconfigPath(c.KubeconfigPath)

...

err = kindProvider.Create(c.ClusterName, clusterConfig, kindConfig)

This means that we would have been overloading the use of KubeconfigPath: it would both be the path to the kubeconfig for some arbitrary created cluster or used in logic to determine if a user is attempting to provide an existing cluster.

Instead, introducing a new option allows us to keep Kubeconfig just as it is: the file path to a kubeconfig.

Deeper in the implementation, we actually take advantage of this by setting the Kubeconfig to the what is provided by a user when using ExistingClusterKubeconfig. This enables existing program flow to stay in place without creating extra logic around a separate kubeconfig.

Details for the Release Notes (PLEASE PROVIDE)

introduce ExistingclusterKubeconfig option for unmanaged-cluster

Which issue(s) this PR fixes

Fixes: #2890

Describe testing done for PR

Existing functionality intact, still able to create cluster and target it:

Screen Shot 2022-01-24 at 11 09 30 AM

  • create some arbitrary cluster. Used kind for this example:
$ kind create cluster --name already-exists
...
  • Get the cluster's kubeconfig:
$ kind get kubeconfig --name already-exists > /tmp/kubeconfig.yaml
  • Give unmanaged-cluster the kubeconfig as an option:

Screen Shot 2022-01-24 at 1 34 56 PM

Check the stats of the cluster:

❯ k get pods -A --kubeconfig kubeconfig.yaml
NAMESPACE            NAME                                                   READY   STATUS    RESTARTS   AGE
kube-system          coredns-558bd4d5db-j72jw                               1/1     Running   0          2m52s
kube-system          coredns-558bd4d5db-psrm9                               1/1     Running   0          2m52s
kube-system          etcd-already-exists-control-plane                      1/1     Running   0          2m55s
kube-system          kindnet-gx8v4                                          1/1     Running   0          2m52s
kube-system          kube-apiserver-already-exists-control-plane            1/1     Running   0          2m55s
kube-system          kube-controller-manager-already-exists-control-plane   1/1     Running   0          2m54s
kube-system          kube-proxy-8lgm2                                       1/1     Running   0          2m52s
kube-system          kube-scheduler-already-exists-control-plane            1/1     Running   0          2m55s
local-path-storage   local-path-provisioner-547f784dff-rfhv8                1/1     Running   0          2m52s
tkg-system           kapp-controller-f7dbbcb4f-nrpbz                        1/1     Running   0          89s

Special notes for your reviewer

N/a

@jpmcb jpmcb requested review from stmcginnis and joshrosso January 24, 2022 18:15
@jpmcb jpmcb requested a review from a team as a code owner January 24, 2022 18:15
Copy link
Contributor

@joshrosso joshrosso left a comment

Choose a reason for hiding this comment

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

exciting! putting this blocker in so i remember to review/validate today.

@jpmcb jpmcb force-pushed the unmanaged-kubeconfig branch from 335b5a2 to 41deb0a Compare January 24, 2022 20:42
Copy link
Contributor

@joshrosso joshrosso left a comment

Choose a reason for hiding this comment

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

Validated this works great against Rancher Desktop.

I also added an update to support --cni=none, which I forsee being common for some of these existing cluster deployments.

Ready to approve once we remove the old KubeconfigPath field.

- Enables users to bring their own cluster with the
  --existing-cluster-kubeconfig option. Also supported in the config
  file. `unmanaged-cluster` will skip creating a new cluster and use
  this one instead

Signed-off-by: John McBride <jmcbride@vmware.com>
@jpmcb jpmcb force-pushed the unmanaged-kubeconfig branch from 41deb0a to 90f64a6 Compare January 26, 2022 17:45
@jpmcb jpmcb requested a review from joshrosso January 26, 2022 18:51
@joshrosso joshrosso merged commit 53ee7b2 into vmware-tanzu:main Jan 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

unmanaged-clusters create should have a --existing-cluster-kubeconfig flag
3 participants