cloud-ark / kubeplus

Kubernetes Operator for multi-instance multi-tenancy
https://cloudark.io/
Apache License 2.0
662 stars 82 forks source link

Support for forced delete #1258

Closed devdattakulkarni closed 5 months ago

devdattakulkarni commented 6 months ago

Application instance creation status is stored in the status field of the CRD instance. If for some reason the status field remains empty after the creation, KubePlus denies the request to delete such an instance. For example,

kubectl delete helloworldservices hs1
Error from server: admission webhook "platform-as-code.crd-binding.v1" denied the request: Error: Custom Resource instance cannot be deleted. It is not ready yet.

Here the status of hs1 is empty.

It is should be possible to force delete such instances.

devdattakulkarni commented 6 months ago

One way to implement this will be to use labels. Add a label ("delete=true") to the application instance. In the mutating webhook, skip any checks for deleting the instance, if this flag is set on the instance.

devdattakulkarni commented 5 months ago

Steps to re-create:

  1. cd tests
  2. kubectl create ns tenant1
  3. kubectl create -f wordpress-service-composition-chart-nopodpolicies.yaml --kubeconfig=../kubeplus-saas-provider.json
  4. kubectl create -f tenant1.yaml --kubeconfig=../kubeplus-saas-provider.json
  5. kubectl delete -f tenant1.yaml --kubeconfig=../kubeplus-saas-provider.json
  6. kubectl delete -f wordpress-service-composition-chart-nopodpolicies.yaml --kubeconfig=../kubeplus-saas-provider.json

These steps trigger this behavior because if an NS already exists KubePlus tries to run 'helm upgrade'. But since there is not helm release, helm upgrade fails. Consequently, the status of the CR instance is empty. This causes KubePlus to prevent delete of the CR instance (in step 5). Step 6 also fails as KubePlus looks at all the CR instances and only if none of them are empty, it deletes the CRD instance.

devdattakulkarni commented 5 months ago

Fixed in https://github.com/cloud-ark/kubeplus/pull/1298