Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
Signed-off-by: Coleen Iona Quadros <[email protected]>
  • Loading branch information
coleenquadros committed Aug 29, 2024
1 parent 9366c0c commit 79d9d8d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,25 +95,6 @@ func (r *PlacementRuleReconciler) Reconcile(ctx context.Context, req ctrl.Reques
reqLogger := log.WithValues("Request.Namespace", req.Namespace, "Request.Name", req.Name)
reqLogger.Info("Reconciling PlacementRule")

// ACM 8509: Special case for hub/local cluster metrics collection
// We want to ensure that the local-cluster is always in the managedClusterList
// In the case when hubSelfManagement is enabled, we will delete it from the list and modify the object
// to cater to the use case of deploying in open-cluster-management-observability namespace
delete(managedClusterList, "local-cluster")
if _, ok := managedClusterList["local-cluster"]; !ok {
obj := &clusterv1.ManagedCluster{
ObjectMeta: metav1.ObjectMeta{
Name: "local-cluster",
Namespace: config.GetDefaultNamespace(),
Labels: map[string]string{
"openshiftVersion": "mimical",
},
},
}
installMetricsWithoutAddon = true
updateManagedClusterList(obj)
}

if config.GetMonitoringCRName() == "" {
reqLogger.Info("multicluster observability resource is not available")
return ctrl.Result{}, nil
Expand Down Expand Up @@ -142,6 +123,13 @@ func (r *PlacementRuleReconciler) Reconcile(ctx context.Context, req ctrl.Reques
return ctrl.Result{}, nil
}

// ACM 8509: Special case for hub/local cluster metrics collection
// We want to ensure that the local-cluster is always in the managedClusterList
// In the case when hubSelfManagement is enabled, we will delete it from the list and modify the object
// to cater to the use case of deploying in open-cluster-management-observability namespace
if req.Name == "local-cluster" {
installMetricsWithoutAddon = true
}
if !deleteAll && !mco.Spec.ObservabilityAddonSpec.EnableMetrics {
reqLogger.Info("EnableMetrics is set to false. Delete Observability addons")
deleteAll = true
Expand Down Expand Up @@ -182,24 +170,12 @@ func (r *PlacementRuleReconciler) Reconcile(ctx context.Context, req ctrl.Reques
}

if !deleteAll && installMetricsWithoutAddon {
obsAddonList.Items = append(obsAddonList.Items, mcov1beta1.ObservabilityAddon{
ObjectMeta: metav1.ObjectMeta{
Name: obsAddonName,
Namespace: config.GetDefaultNamespace(),
Labels: map[string]string{
ownerLabelKey: ownerLabelValue,
},
},
})
err = deleteObsAddon(r.Client, localClusterName)
if err != nil {
log.Error(err, "Failed to delete observabilityaddon")
return ctrl.Result{}, err
}
}
if operatorconfig.IsMCOTerminating {
delete(managedClusterList, "local-cluster")
}

if !deleteAll {
if err := createAllRelatedRes(
Expand Down Expand Up @@ -241,6 +217,7 @@ func (r *PlacementRuleReconciler) Reconcile(ctx context.Context, req ctrl.Reques
latestClusters = append(latestClusters, addon.Namespace)
staleAddons = append(staleAddons, addon.Namespace)
}

for _, work := range workList.Items {
if work.Name != work.Namespace+workNameSuffix {
// ACM 8509: Special case for hub metrics collector
Expand Down Expand Up @@ -301,7 +278,7 @@ func (r *PlacementRuleReconciler) Reconcile(ctx context.Context, req ctrl.Reques

if deleteAll {
// delete managedclusteraddon for local-cluster
err = deleteManagedClusterRes(r.Client, localClusterName)
err = deleteManagedClusterRes(r.Client, config.GetDefaultNamespace())
if err != nil {
return ctrl.Result{}, err
}
Expand Down Expand Up @@ -458,12 +435,10 @@ func createAllRelatedRes(

failedDeleteOba := false
for _, cluster := range clustersToCleanup {
if cluster != config.GetDefaultNamespace() {
err = deleteObsAddon(c, cluster)
if err != nil {
failedDeleteOba = true
log.Error(err, "Failed to delete observabilityaddon", "namespace", cluster)
}
err = deleteObsAddon(c, cluster)
if err != nil {
failedDeleteOba = true
log.Error(err, "Failed to delete observabilityaddon", "namespace", cluster)
}
}

Expand Down Expand Up @@ -622,6 +597,12 @@ func areManagedClusterLabelsReady(obj client.Object) bool {
func updateManagedClusterList(obj client.Object) {
managedClusterListMutex.Lock()
defer managedClusterListMutex.Unlock()
//ACM 8509: Special case for local-cluster, we deploy endpoint and metrics collector in the hub
//whether hubSelfManagement is enabled or not
if obj.GetName() == localClusterName {
managedClusterList[obj.GetName()] = "mimical"
return
}
if version, ok := obj.GetLabels()["openshiftVersion"]; ok {
managedClusterList[obj.GetName()] = version
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@ func getClusterPreds() predicate.Funcs {
createFunc := func(e event.CreateEvent) bool {
log.Info("CreateFunc", "managedCluster", e.Object.GetName())

//ACM 8509: Special case for local-cluster, we do not react changes to
//local-cluster as it is expected to be always present in the managed cluster list
//whether hubSelfManagement is enabled or not
if e.Object.GetName() == "local-cluster" {
return false
}

if isAutomaticAddonInstallationDisabled(e.Object) {
return false
}
Expand All @@ -46,10 +39,6 @@ func getClusterPreds() predicate.Funcs {
updateFunc := func(e event.UpdateEvent) bool {
log.Info("UpdateFunc", "managedCluster", e.ObjectNew.GetName())

if e.ObjectNew.GetName() == "local-cluster" {
return false
}

if e.ObjectNew.GetResourceVersion() == e.ObjectOld.GetResourceVersion() {
return false
}
Expand Down Expand Up @@ -79,10 +68,6 @@ func getClusterPreds() predicate.Funcs {
deleteFunc := func(e event.DeleteEvent) bool {
log.Info("DeleteFunc", "managedCluster", e.Object.GetName())

if e.Object.GetName() == "local-cluster" {
return false
}

if isAutomaticAddonInstallationDisabled(e.Object) {
return false
}
Expand Down
2 changes: 1 addition & 1 deletion proxy/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ WORKDIR /workspace
COPY go.sum go.mod ./
COPY ./proxy ./proxy

RUN CGO_ENABLED=1 go build -a -installsuffix cgo -v -o main proxy/cmd/main.go
RUN CGO_ENABLED=1 GOFLAGS="" go build -a -installsuffix cgo -v -o main proxy/cmd/main.go

FROM registry.access.redhat.com/ubi9/ubi-minimal:latest

Expand Down

0 comments on commit 79d9d8d

Please sign in to comment.