Skip to content

Commit

Permalink
Application upgrade improvements (#1206)
Browse files Browse the repository at this point in the history
Application upgrade improvements

Fixes: #1187
  • Loading branch information
devdattakulkarni authored Jan 10, 2024
1 parent a81f0e0 commit cd1fd87
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ The KubePlus Operator does not need any admin-level permissions on a cluster for
KubePlus provides controls to set per-namespace resource quotas. It also monitors usage of CPU, memory, storage, and network traffic at the application instance level. The collected metrics are available in different formats and can be pulled into Prometheus for historical usage tracking.

### Upgrades
A new version of an application can be deployed by updating the application Helm chart under the existing Kubernetes API or registering the new chart under a new Kubernetes API. If the existing Kubernetes API object is updated, KubePlus will deploy the new application instances using the new version of the application Helm chart.
A new version of an application can be deployed by updating the application Helm chart under the existing Kubernetes API or registering the new chart under a new Kubernetes API. If the existing Kubernetes API object is updated, KubePlus will update all the running application instances (helm releases) to the new version of the application Helm chart.

### Customization
The spec properties of the Kubernetes API wrapping the application Helm chart are the fields defined in the chart’s values.yaml file. Application deployments can be customized by specifying different values for these spec properties.
Expand Down
4 changes: 4 additions & 0 deletions deploy/mutatingwebhook.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ webhooks:
apiGroups: ["workflows.kubeplus", "platformapi.kubeplus"]
apiVersions: ["v1alpha1"]
resources: ["resourcepolicies", "resourcecompositions", "resourcemonitors", "resourceevents","*"]
- operations: [ "UPDATE"]
apiGroups: ["workflows.kubeplus"]
apiVersions: ["v1alpha1"]
resources: ["resourcepolicies", "resourcecompositions", "resourcemonitors", "resourceevents"]
Binary file modified examples/multitenancy/appday2ops/basicwebapp-0.0.1.tgz
Binary file not shown.
Binary file modified examples/multitenancy/appday2ops/basicwebapp-0.0.2.tgz
Binary file not shown.
8 changes: 5 additions & 3 deletions examples/multitenancy/appday2ops/steps.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ $ export PATH=$KUBEPLUS_HOME/plugins/:$PATH
$ kubectl kubeplus commands

Upload the charts to KubePlus:
$ $KUBEPLUS_HOME/plugins/kubectl-upload-chart basicwebapp-0.0.1.tgz provider.conf
$ $KUBEPLUS_HOME/plugins/kubectl-upload-chart basicwebapp-0.0.2.tgz provider.conf
$ kubectl upload chart basicwebapp-0.0.1.tgz provider.conf
$ kubectl upload chart basicwebapp-0.0.2.tgz provider.conf

Create basic web app API:
$ kubectl create -f basic-web-app-service-composition-localchart.yaml --kubeconfig=provider.conf
Expand All @@ -47,11 +47,12 @@ Check that the application instance Pods are created in a new namespace:
$ kubectl get pods -A

Connect to the application:
$ kubectl port-forward <name of the app instance> -n bwa-tenant1
$ kubectl port-forward <web-app-deploy-pod> -n bwa-tenant1 5000:5000
- get the name from the previous command

Verify that you can add users and try adding the same user again.
Go to "localhost:5000/users" to see the list of users in the database.
- curl -v http://localhost:5000/users

Change the ResourceComposition file "basic-web-app-service-composition-localchart.yaml"
Change the version of the chartURL from 0.0.1 to 0.0.2
Expand All @@ -69,6 +70,7 @@ Verify this by checking the pods once again:
$ kubectl get pods -A

Check the application once again. There should be a new user added.
- curl -v localhost:5000/users

Clean up:
$ kubectl delete -f basic-web-app-service-composition-localchart.yaml --kubeconfig=provider.conf
Expand Down
1 change: 1 addition & 0 deletions mutating-webhook/versions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@
3.0.10
3.0.11
3.0.12
3.0.13
56 changes: 56 additions & 0 deletions mutating-webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,25 @@ func (whsvr *WebhookServer) mutate(ar *v1.AdmissionReview, httpMethod string) *v

if req.Kind.Kind == "ResourceComposition" {
if strings.Contains(user, "kubeplus-saas-provider") {

message := checkChartExists(ar)
if message != "" {
return &v1.AdmissionResponse{
Result: &metav1.Status{
Message: message,
},
}
}

statusMessageToCheck := "New CRD defined in ResourceComposition created successfully."
statusMessage := getStatusMessage(ar)
if statusMessageToCheck == statusMessage {
fmt.Printf("Intercepted call from platform-controller. Nothing to do for this call..\n")
return &v1.AdmissionResponse{
Allowed: true,
}
}

errResponse := trackCustomAPIs(ar)
if errResponse != nil {
//fmt.Printf("111222333")
Expand Down Expand Up @@ -317,6 +336,18 @@ func (whsvr *WebhookServer) mutate(ar *v1.AdmissionReview, httpMethod string) *v
}
}

func getStatusMessage(ar *v1.AdmissionReview) string {
fmt.Println("Inside getStatusMessage")
req := ar.Request
body := req.Object.Raw
status, err := jsonparser.GetUnsafeString(body, "status","status")
if err != nil {
fmt.Errorf("Error:%s\n", err)
}
fmt.Printf("getStatusMessage:%s\n", status)
return status
}

func handleDelete(ar *v1.AdmissionReview) *v1.AdmissionResponse {
fmt.Println("Inside handleDelete...")
req := ar.Request
Expand Down Expand Up @@ -1248,6 +1279,31 @@ func getPaCAnnotation(ar *v1.AdmissionReview) map[string]string {
return annotations1
}

func checkChartExists(ar *v1.AdmissionReview) string {
fmt.Printf("Inside checkChartExists...\n")

req := ar.Request
body := req.Object.Raw
kind, err := jsonparser.GetUnsafeString(body, "kind")
if err != nil {
fmt.Errorf("Error:%s\n", err)
}

crname, err := jsonparser.GetUnsafeString(req.Object.Raw, "metadata", "name")
fmt.Printf("CR Name:%s\n", crname)
fmt.Printf("Kind:%s\n", kind)

chartURL, err := jsonparser.GetUnsafeString(req.Object.Raw, "spec", "newResource", "chartURL")

fmt.Printf("%%%%% CHART URL:%s %%%%%\n", chartURL)

message1 := string(CheckChartExists(chartURL))
fmt.Printf("After CheckChartExists - message:%s\n", message1)

return message1
}


func handleCustomAPIs(ar *v1.AdmissionReview) *v1.AdmissionResponse {
fmt.Printf("Inside handleCustomAPIs...\n")
req := ar.Request
Expand Down
Binary file modified platform-operator/artifacts/deployment/platform-operator
Binary file not shown.
Binary file modified platform-operator/platform-operator
Binary file not shown.
3 changes: 2 additions & 1 deletion platform-operator/platformcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,8 @@ func (c *Controller) updateResourceCompositionStatus(foo *platformworkflowv1alph
_, err := c.platformStackclientset.WorkflowsV1alpha1().ResourceCompositions(namespace).Update(context.Background(), fooCopy, metav1.UpdateOptions{})
//_, err := c.sampleclientset.MoodlecontrollerV1().Moodles(foo.Namespace).Update(fooCopy)
if err != nil {
fmt.Printf("Platformcontroller.go : ERROR in UpdateResourceCompositionStatus %e", err)
fmt.Printf("Platformcontroller.go : ERROR in UpdateResourceCompositionStatus %e\n", err)
fmt.Printf("Platformcontroller.go : ERROR %v\n", err)
time.Sleep(1 * time.Second)
count = count + 1
} else {
Expand Down
1 change: 1 addition & 0 deletions platform-operator/versions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
3.0.3
3.0.4
3.0.5
3.0.6

0 comments on commit cd1fd87

Please sign in to comment.