From 53bdbfd9a003085d61d73562f0b6f1f645af77ac Mon Sep 17 00:00:00 2001
From: peng9808 <peng.lai@daocloud.io>
Date: Tue, 8 Oct 2024 10:50:26 +0800
Subject: [PATCH] Fixed the issue that UI cannot be automatically uninstalled

Signed-off-by: peng9808 <peng.lai@daocloud.io>
---
 pkg/install/ui/ui.go | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/pkg/install/ui/ui.go b/pkg/install/ui/ui.go
index 1e4f9df..00dba50 100644
--- a/pkg/install/ui/ui.go
+++ b/pkg/install/ui/ui.go
@@ -9,6 +9,7 @@ import (
 	corev1 "k8s.io/api/core/v1"
 	apierrors "k8s.io/apimachinery/pkg/api/errors"
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	"k8s.io/apimachinery/pkg/runtime/schema"
 	"k8s.io/apimachinery/pkg/types"
 	"sigs.k8s.io/controller-runtime/pkg/client"
 )
@@ -77,6 +78,7 @@ func SetUI(clusterInstance *operatorv1alpha1.Cluster) {
 	replicas := getUIReplicasFromClusterInstance(clusterInstance)
 	ui.Spec.Replicas = &replicas
 	ui.Spec.Template.Spec.ServiceAccountName = clusterInstance.Spec.RBAC.ServiceAccountName
+	ui.OwnerReferences = append(ui.OwnerReferences, *metav1.NewControllerRef(clusterInstance, schema.FromAPIVersionAndKind("hwameistor.io/v1alpha1", "Cluster")))
 	for i, container := range ui.Spec.Template.Spec.Containers {
 		if container.Name == uiContainerName {
 			container.Image = getUIContainerImageStringFromClusterInstance(clusterInstance)