From 485214076083461c717ce38b179068e2ae4ff174 Mon Sep 17 00:00:00 2001 From: clyang82 Date: Tue, 6 Feb 2024 17:52:07 +0800 Subject: [PATCH] modify endpoint operator Signed-off-by: clyang82 --- .../controllers/placementrule/manifestwork.go | 10 +++++++++- .../placementrule/placementrule_controller.go | 10 ++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/operators/multiclusterobservability/controllers/placementrule/manifestwork.go b/operators/multiclusterobservability/controllers/placementrule/manifestwork.go index 8ee013c4e..366410f6d 100644 --- a/operators/multiclusterobservability/controllers/placementrule/manifestwork.go +++ b/operators/multiclusterobservability/controllers/placementrule/manifestwork.go @@ -16,6 +16,7 @@ import ( "gopkg.in/yaml.v2" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" + rbacv1 "k8s.io/api/rbac/v1" apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1" k8serrors "k8s.io/apimachinery/pkg/api/errors" @@ -447,13 +448,20 @@ func createManifestWorks( func createUpdateResources(c client.Client, manifests []workv1.Manifest) error { for _, manifest := range manifests { obj := manifest.RawExtension.Object.(client.Object) + if obj.GetObjectKind().GroupVersionKind().Kind == "ObservabilityAddon" { + continue + } obj.SetNamespace(config.GetDefaultNamespace()) + if obj.GetObjectKind().GroupVersionKind().Kind == "ClusterRoleBinding" { + role := obj.(*rbacv1.ClusterRoleBinding) + role.Subjects[0].Namespace = config.GetDefaultNamespace() + } err := c.Create(context.TODO(), obj) if err != nil && !k8serrors.IsAlreadyExists(err) { log.Error(err, "Failed to create resource", "kind", obj.GetObjectKind().GroupVersionKind().Kind) - return err } } + return nil } diff --git a/operators/multiclusterobservability/controllers/placementrule/placementrule_controller.go b/operators/multiclusterobservability/controllers/placementrule/placementrule_controller.go index bd329815c..7d4f4c60f 100644 --- a/operators/multiclusterobservability/controllers/placementrule/placementrule_controller.go +++ b/operators/multiclusterobservability/controllers/placementrule/placementrule_controller.go @@ -413,10 +413,12 @@ func createAllRelatedRes( failedDeleteOba := false for _, cluster := range currentClusters { log.Info("To delete observabilityAddon", "namespace", cluster) - err = deleteObsAddon(c, cluster) - if err != nil { - failedDeleteOba = true - log.Error(err, "Failed to delete observabilityaddon", "namespace", cluster) + if cluster != config.GetDefaultNamespace() { + err = deleteObsAddon(c, cluster) + if err != nil { + failedDeleteOba = true + log.Error(err, "Failed to delete observabilityaddon", "namespace", cluster) + } } }