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

cleanup legacy context after delete cluster #1231

Merged

Conversation

RainbowMango
Copy link
Contributor

@RainbowMango RainbowMango commented May 15, 2020

What this PR does / why we need it:
Kube config context didn't be removed after delete clusters, that would block creating cluster next time as same context is already exist. You can reproduce it by following command.

# ./scripts/create-clusters.sh
# ./scripts/delete-clusters.sh
# kubectl config view
apiVersion: v1
clusters: null
contexts:
- context:
    cluster: kind-cluster1
    user: kind-cluster1
  name: cluster1
- context:
    cluster: kind-cluster2
    user: kind-cluster2
  name: cluster2
current-context: cluster1
kind: Config
preferences: {}
users: null

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #

Special notes for your reviewer:
With this patch, we can get a clean config as follows:

# kubectl config view
apiVersion: v1
clusters: null
contexts: null
current-context: ""
kind: Config
preferences: {}
users: null

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels May 15, 2020
@RainbowMango
Copy link
Contributor Author

/assign @pmorie @hectorj2f

@RainbowMango
Copy link
Contributor Author

If you want check what exactly the error is, see below:

[root@ecs-d8b6 kubefed]# ./scripts/delete-clusters.sh 
Deleting 2 clusters
Deleting cluster "cluster1" ...
Deleting cluster "cluster2" ...
Complete
[root@ecs-d8b6 kubefed]# ./scripts/create-clusters.sh 
Creating 2 clusters
Creating cluster "cluster1" ...
 ✓ Ensuring node image (kindest/node:v1.17.0) 🖼
 ✓ Preparing nodes 📦  
 ✓ Writing configuration 📜 
 ✓ Starting control-plane 🕹️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️ 
 ✓ Installing CNI 🔌 
 ✓ Installing StorageClass 💾 
Set kubectl context to "kind-cluster1"
You can now use your cluster with:

kubectl cluster-info --context kind-cluster1

Thanks for using kind! 😊
Cluster "kind-cluster1" set.
error: cannot rename the context "kind-cluster1", the context "cluster1" already exists in /root/.kube/config

Copy link
Contributor

@hectorj2f hectorj2f left a comment

Choose a reason for hiding this comment

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

I'd test it as soon as possible in my environment 👍.

@hectorj2f
Copy link
Contributor

I tested and it works 👍
/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm Indicates that a PR is ready to be merged. label May 19, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hectorj2f, RainbowMango

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 19, 2020
@k8s-ci-robot k8s-ci-robot merged commit 6386f4e into kubernetes-retired:master May 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm Indicates that a PR is ready to be merged. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants