Skip to content

Commit

Permalink
Support for application force delete (cloud-ark#1298)
Browse files Browse the repository at this point in the history
  • Loading branch information
devdattakulkarni authored Jun 6, 2024
1 parent 6ab456e commit 4539fb4
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 5 deletions.
2 changes: 1 addition & 1 deletion deploy/kubeplus-chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ CRD_REGISTRATION_HELPER: gcr.io/cloudark-kubeplus/kubeconfiggenerator:3.0.28
MUTATING_WEBHOOK: gcr.io/cloudark-kubeplus/pac-mutating-admission-webhook:3.0.15
PLATFORM_OPERATOR: gcr.io/cloudark-kubeplus/platform-operator:3.0.6
CONSUMERUI: gcr.io/cloudark-kubeplus/consumerui:0.0.7
HELMER: gcr.io/cloudark-kubeplus/helm-pod:3.0.20
HELMER: gcr.io/cloudark-kubeplus/helm-pod:3.0.21
RESOURCE_CLEANER: gcr.io/cloudark-kubeplus/delete-kubeplus-resources:3.0.28
9 changes: 5 additions & 4 deletions platform-operator/helm-pod/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,8 @@ func deleteCRDInstances(request *restful.Request, response *restful.Response) {
//fmt.Printf("objData:%v\n", objData)
status := objData["status"]
//fmt.Printf("Status:%v\n", status)
//labels := instanceObj.GetLabels()
//forcedDelete, _ := labels["delete"]
labels := instanceObj.GetLabels()
forcedDelete, _ := labels["delete"]
if status != nil { //|| forcedDelete != "" {
helmreleaseNS, helmrelease := getHelmReleaseName(status)
fmt.Printf("Helm release NS and release name:%s, %s\n", helmreleaseNS, helmrelease)
Expand Down Expand Up @@ -360,8 +360,9 @@ func deleteCRDInstances(request *restful.Request, response *restful.Response) {
dynamicClient.Resource(ownerRes).Namespace(namespace).Delete(context.Background(), objName, metav1.DeleteOptions{})
}
}
//fmt.Printf("Deleting the object %s\n", objName)
//dynamicClient.Resource(ownerRes).Namespace(namespace).Delete(context.Background(), objName, metav1.DeleteOptions{})
} else if forcedDelete != "" {
fmt.Printf("Force delete the object %s\n", objName)
response.Write([]byte(""))
} else {
response.Write([]byte("Error: Custom Resource instance cannot be deleted. It is not ready yet."))
return
Expand Down
1 change: 1 addition & 0 deletions platform-operator/helm-pod/versions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@
3.0.18
3.0.19
3.0.20
3.0.21
47 changes: 47 additions & 0 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,53 @@ def _check_crd_installed(self, crd):
timer = timer + 1
return installed

def test_force_delete_application(self):
if not TestKubePlus._is_kubeplus_running():
print("KubePlus is not running. Deploy KubePlus and then run tests")
sys.exit(0)

start_clean = "kubectl delete ns tenant1"
TestKubePlus.run_command(start_clean)

create_ns = "kubectl create ns tenant1"
TestKubePlus.run_command(create_ns)

cmd1 = "kubectl create -f wordpress-service-composition-chart-nopodpolicies.yaml --kubeconfig=../kubeplus-saas-provider.json"
TestKubePlus.run_command(cmd1)

crd = "wordpressservices.platformapi.kubeplus"
crd_installed = self._check_crd_installed(crd)
if not crd_installed:
print("CRD " + crd + " not installed. Exiting this test.")
return

cmd = "kubectl create -f tenant1.yaml --kubeconfig=../kubeplus-saas-provider.json"
TestKubePlus.run_command(cmd)

cmd = "kubectl delete -f tenant1.yaml --kubeconfig=../kubeplus-saas-provider.json"
out, err = TestKubePlus.run_command(cmd)
#print("Out:" + out)
#print("Err:" + err)
self.assertTrue("Custom Resource instance cannot be deleted. It is not ready yet." in err)

cmd = "kubectl delete -f wordpress-service-composition-chart-nopodpolicies.yaml --kubeconfig=../kubeplus-saas-provider.json"
out, err = TestKubePlus.run_command(cmd)
self.assertTrue("ResourceComposition instance cannot be deleted. It has an application instance starting up." in err)

cmd = "kubectl label WordpressService tenant1 delete=true"
TestKubePlus.run_command(cmd)

cmd = "kubectl delete -f tenant1.yaml --kubeconfig=../kubeplus-saas-provider.json"
out, err = TestKubePlus.run_command(cmd)
self.assertTrue(err == "")

cmd = "kubectl delete -f wordpress-service-composition-chart-nopodpolicies.yaml --kubeconfig=../kubeplus-saas-provider.json"
out, err = TestKubePlus.run_command(cmd)
self.assertTrue(err == "")

clean_up = "kubectl delete ns tenant1"
TestKubePlus.run_command(clean_up)


def test_res_comp_with_no_podpolicies(self):
if not TestKubePlus._is_kubeplus_running():
Expand Down

0 comments on commit 4539fb4

Please sign in to comment.