terraform-provider-kind icon indicating copy to clipboard operation
terraform-provider-kind copied to clipboard

k8s-context not cleaned up after terraform destroy

Open tim-hilt opened this issue 2 years ago • 5 comments

Shouldn't the k8s context be deleted after issuing terraform destroy? I can see that it's still there for me.

To reproduce:

  1. clone https://github.com/tim-hilt/lcb
  2. cd lcb
  3. terraform init
  4. terraform apply
  5. terraform destroy
  6. kubectl config get-contexts

You should still see, that the current context is kind-lcb.

tim-hilt avatar Feb 08 '23 19:02 tim-hilt

Shouldn't the k8s context be deleted after issuing terraform destroy? I can see that it's still there for me.

The only leftover should be an empty file. The content of the file is being deleted.

tehcyx avatar Feb 08 '23 20:02 tehcyx

I adapted the description to add reproduction steps. Is this behavior expected?

tim-hilt avatar Feb 08 '23 21:02 tim-hilt

I'll have to dig a little bit into that. This might be kind itself, or the provider not calling a cleanup function on kind. Since the provider itself does not create the context, this is handled by invoking kind.

Thanks for adding the steps to reproduce.

tehcyx avatar Feb 08 '23 23:02 tehcyx

I tried destroying the kind-cluster with kind delete cluster --name lcb and it also removed the k8s-context. No idea about the Go sdk though

tim-hilt avatar Feb 09 '23 08:02 tim-hilt

I can reproduce it, still figuring out how to best delete the context. kind, minikube and other tools all have their own kubeconfig wrapper, see e.g. here: https://github.com/anencore94/minikube/blob/2c08f62ed21489cfd5db89289b4306b84b39868d/pkg/minikube/kubeconfig/context.go#L66

Wondering how I could delete the context without implementing my own wrapper. kind is packing it into an internal package, though I'm already using one internal package of kind.

tehcyx avatar Feb 13 '23 04:02 tehcyx