Skip to content

Commit

Permalink
Resourcecomposition upgrade update (#1211)
Browse files Browse the repository at this point in the history
* Resourcecomposition upgrade update

Added a field ('error') to the status object.
This is used by helmer to store any errors that
are encountered when performing helm upgrade.
  • Loading branch information
devdattakulkarni authored Feb 16, 2024
1 parent 8e0a898 commit f6849dc
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion deploy/kubeconfiggenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ def registercrd():
openAPIV3SchemaPropertiesInner['type'] = 'object'
openAPIV3SchemaPropertiesInner['properties'] = openAPIV3SchemaPropertiesInnerDetails
openAPIV3SchemaProperties['spec'] = openAPIV3SchemaPropertiesInner
openAPIV3SchemaProperties['status'] = {"type": "object", "properties": {"helmrelease": {"type": "string"}}}
openAPIV3SchemaProperties['status'] = {"type": "object", "properties": {"helmrelease": {"type": "string"}, "error": {"type": "string"}}}
openAPIV3SchemaObj['type'] = 'object'
openAPIV3SchemaObj['properties'] = openAPIV3SchemaProperties
attr_types['openAPIV3Schema'] = openAPIV3SchemaObj
Expand Down
1 change: 1 addition & 0 deletions deploy/versions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@
3.0.24
3.0.25
3.0.26
3.0.27
Binary file modified platform-operator/helm-pod/helm-pod
Binary file not shown.
21 changes: 17 additions & 4 deletions platform-operator/helm-pod/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,24 +459,36 @@ func updateCRDInstances(request *restful.Request, response *restful.Response) {
helmreleaseNS, helmrelease := getHelmReleaseName(status)
fmt.Printf("Helm release:%s, %s\n", helmreleaseNS, helmrelease)
if helmreleaseNS != "" && helmrelease != "" {
go upgradeHelmRelease(helmreleaseNS, helmrelease, chartName)
fmt.Printf("Helm release updated...\n")
_, output := upgradeHelmRelease(helmreleaseNS, helmrelease, chartName)
output = strings.ReplaceAll(output, "\n", "")
fmt.Printf("Helm release updated...%s\n", output)
helmReleaseFQDN := status.(map[string]interface{})["helmrelease"]
helmReleaseFQDN_str := helmReleaseFQDN.(string)
//helmrelease["helmrelease"] = targetNS + ":" + releaseName
//status1 := helmReleaseFQDN_str + "\n" + output + "\n" + "Update complete."
helmreleaseUpdate := make(map[string]string)
helmreleaseUpdate["helmrelease"] = helmReleaseFQDN_str
helmreleaseUpdate["error"] = chartURL + " upgrade output:" + output
objData["status"] = helmreleaseUpdate
fmt.Printf("objData:%v\n",objData)
instanceObj.SetUnstructuredContent(objData)
dynamicClient.Resource(ownerRes).Namespace(namespace).Update(context.Background(), &instanceObj, metav1.UpdateOptions{})
}
}
}

response.Write([]byte(execOutput))
}

func upgradeHelmRelease(helmreleaseNS, helmrelease, chartName string) bool {
func upgradeHelmRelease(helmreleaseNS, helmrelease, chartName string) (bool, string) {
fmt.Printf("Helm release:%s\n", helmrelease)
cmd := "helm upgrade " + helmrelease + " /" + chartName + " -n " + helmreleaseNS
fmt.Printf("Helm upgrade cmd:%s\n", cmd)
var output string
cmdRunnerPod := getKubePlusPod()
ok, output := executeExecCall(cmdRunnerPod, cmd)
fmt.Printf("Helm upgrade o/p:%v\n", output)
return ok
return ok, output
}

func annotateCRD(request *restful.Request, response *restful.Response) {
Expand Down Expand Up @@ -1116,6 +1128,7 @@ func updateStatus(kind, group, version, plural, instance, crdObjNS, targetNS, re
helmrelease := make(map[string]interface{},0)
// Helm release will be done in the target namespace where the customresource instance
// is deployed.
releaseName = strings.ReplaceAll(releaseName, "\n", "")
helmrelease["helmrelease"] = targetNS + ":" + releaseName
objData["status"] = helmrelease
//fmt.Printf("objData:%v\n",objData)
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 @@ -30,3 +30,4 @@
3.0.14
3.0.15
3.0.16
3.0.17

0 comments on commit f6849dc

Please sign in to comment.