Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat (UI): Delete UI ConfigMap upon cloud-manager disable #337

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions pkg/skr/cloudresources/deleteUiCms.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package cloudresources

import (
"context"
"fmt"
"github.com/kyma-project/cloud-manager/pkg/composed"
"github.com/kyma-project/cloud-manager/pkg/util"
)

func deleteUiCms(ctx context.Context, st composed.State) (error, context.Context) {

state := st.(*State)
logger := composed.LoggerFromCtx(ctx)

uiCmList := util.NewUiCmListUnstructured()
err := state.Cluster().ApiReader().List(ctx, uiCmList)
if err != nil {
return composed.LogErrorAndReturn(err, "Error listing UI CMs", composed.StopWithRequeue, ctx)
}

logger.Info("Checking UI ConfigMaps to uninstall")

// Loop through the uiCmList
uiKey := "cloud-manager"

for _, uiCm := range uiCmList.Items {

labels := uiCm.GetLabels()
value, hasUiKey := labels[uiKey]
if hasUiKey && value == "ui-cm" {
u := util.NewUiCmUnstructured()
u.SetName(uiCm.GetName())
err = state.Cluster().K8sClient().Delete(ctx, u)
if err != nil {
return composed.LogErrorAndReturn(err, fmt.Sprintf("Error deleting ConfigMap %s", uiCm.GetName()), composed.StopWithRequeue, ctx)
}
} else {
continue
}
}

return nil, nil
}
2 changes: 1 addition & 1 deletion pkg/skr/cloudresources/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (r *reconciler) newAction() composed.Action {
checkIfResourcesExist,
deleteCrds,
removeFinalizer,

deleteUiCms,
composed.StopAndForgetAction,
),
nil,
Expand Down
23 changes: 23 additions & 0 deletions pkg/util/uiCm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package util

import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
)

func NewUiCmListUnstructured() *unstructured.UnstructuredList {
u := &unstructured.UnstructuredList{}
u.SetAPIVersion("v1")
u.SetKind("ConfigMapList")

return u
}

func NewUiCmUnstructured() *unstructured.Unstructured {
u := &unstructured.Unstructured{}
u.SetAPIVersion("v1")
u.SetKind("ConfigMap")
u.SetNamespace("kyma-system")

return u

}
Loading