Skip to content

Commit 35bd961

Browse files
Addressing issues related to multiple apps with same name and different kinds (#1427)
1 parent 37c31a9 commit 35bd961

File tree

4 files changed

+43
-10
lines changed

4 files changed

+43
-10
lines changed

mutating-webhook/versions.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@
3333
3.0.19
3434
3.0.20
3535
3.1.0
36+
3.1.1

mutating-webhook/webhook.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,6 +1482,40 @@ func handleCustomAPIs(ar *v1.AdmissionReview, httpMethod string) *v1.AdmissionRe
14821482
},
14831483
}
14841484
}
1485+
nsAnnotations := nsObj.Annotations
1486+
releaseNameAnnotation := ""
1487+
if nsAnnotations != nil {
1488+
fmt.Printf("Annotations of namespace %s:\n", crname)
1489+
for key, value := range nsAnnotations {
1490+
fmt.Printf("%s: %s\n", key, value)
1491+
if key == "meta.helm.sh/release-name" {
1492+
releaseNameAnnotation = value
1493+
}
1494+
}
1495+
if releaseNameAnnotation != "" {
1496+
releaseNameAnnotation = strings.Replace(releaseNameAnnotation, `"`,"",-1)
1497+
releaseNameAnnotation = strings.Replace(releaseNameAnnotation, `\`, "",-1)
1498+
fmt.Printf("Release name annotation:%s\n", releaseNameAnnotation)
1499+
prts := strings.Split(releaseNameAnnotation, "-")
1500+
kindInRelease := ""
1501+
if len(prts) > 0 {
1502+
kindInRelease = prts[0]
1503+
fmt.Printf("Kind in release:%s\n", kindInRelease)
1504+
fmt.Printf("Kind in Rescomp:%s\n", kind)
1505+
if strings.ToLower(kindInRelease) != strings.ToLower(kind) {
1506+
msg := fmt.Sprintf("App with name %s already exists for Kind %s. Use different app name.\n", crname, kindInRelease)
1507+
return &v1.AdmissionResponse{
1508+
Result: &metav1.Status{
1509+
Message: msg,
1510+
},
1511+
}
1512+
}
1513+
}
1514+
}
1515+
} else {
1516+
fmt.Println("No annotations found.")
1517+
}
1518+
14851519
}
14861520

14871521
lengthCheck := kind + "-" + crname

platform-operator/helm-pod/main.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -339,15 +339,12 @@ func deleteCRDInstances(request *restful.Request, response *restful.Response) {
339339
if helmreleaseNS != "" && helmrelease != "" {
340340
// Do in the background as 'helm delete' and deleting NS are time consuming actions
341341
go func() {
342-
deleteHelmRelease(helmreleaseNS, helmrelease)
343-
342+
op := deleteHelmRelease(helmreleaseNS, helmrelease)
344343
fmt.Printf("Helm release deleted...\n")
345-
fmt.Printf("Deleting the namespace...\n")
346344

347-
// The namespace created to deploy the Helm chart
348-
// needs to be deleted only if the helmreleaseNS does not match namespace.
349-
// For managed app use-case, namespace and helmreleaseNS will be same.
350-
if helmreleaseNS != namespace {
345+
// Delete the Namespace only if there is no error.
346+
if !strings.Contains(strings.ToLower(op), "error") {
347+
fmt.Printf("Deleting the namespace...\n")
351348
namespaceDeleteCmd := "./root/kubectl delete ns " + helmreleaseNS
352349
cmdRunnerPod := getKubePlusPod()
353350
_, op := executeExecCall(cmdRunnerPod, namespaceDeleteCmd)
@@ -382,15 +379,15 @@ func deleteCRDInstances(request *restful.Request, response *restful.Response) {
382379
//sync.mutex.Unlock()
383380
}
384381

385-
func deleteHelmRelease(helmreleaseNS, helmrelease string) bool {
382+
func deleteHelmRelease(helmreleaseNS, helmrelease string) string {
386383
//fmt.Printf("Helm release:%s\n", helmrelease)
387384
cmd := "helm delete " + helmrelease + " -n " + helmreleaseNS
388385
fmt.Printf("Helm delete cmd:%s\n", cmd)
389386
var output string
390387
cmdRunnerPod := getKubePlusPod()
391-
ok, output := executeExecCall(cmdRunnerPod, cmd)
388+
_, output = executeExecCall(cmdRunnerPod, cmd)
392389
fmt.Printf("Helm delete o/p:%v\n", output)
393-
return ok
390+
return output
394391
}
395392

396393
func updateCRDInstances(request *restful.Request, response *restful.Response) {

platform-operator/helm-pod/versions.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,4 @@
3838
3.0.22
3939
3.0.23
4040
3.1.0
41+
3.1.1

0 commit comments

Comments
 (0)