66 "strings"
77 "time"
88
9+ "github.com/openmcp-project/controller-utils/pkg/resources"
910 corev1 "k8s.io/api/core/v1"
1011 apierrors "k8s.io/apimachinery/pkg/api/errors"
1112 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -19,7 +20,6 @@ import (
1920 "sigs.k8s.io/controller-runtime/pkg/predicate"
2021 "sigs.k8s.io/controller-runtime/pkg/reconcile"
2122
22- "github.com/openmcp-project/controller-utils/pkg/clusteraccess"
2323 "github.com/openmcp-project/controller-utils/pkg/clusters"
2424 "github.com/openmcp-project/controller-utils/pkg/collections"
2525 "github.com/openmcp-project/controller-utils/pkg/collections/filters"
@@ -197,7 +197,15 @@ func (r *ManagedControlPlaneReconciler) handleCreateOrUpdate(ctx context.Context
197197 createCon (corev2alpha1 .ConditionMeta , metav1 .ConditionFalse , rr .ReconcileError .Reason (), rr .ReconcileError .Error ())
198198 return rr
199199 }
200- _ , err = clusteraccess .EnsureNamespace (ctx , r .PlatformCluster .Client (), platformNamespace , pairs .MapToPairs (mcpLabels )... )
200+ // TODO: changed from clusteraccess.EnsureNamespace to a namespace mutator
201+ // because the MCP namespace might be created by another controller first (e.g. another service provider).
202+ // Failing in this case is not desired as the MCP reconciliation would be stuck.
203+ // Instead, we ensure that the labels are correct on the namespace.gi
204+ // In the future, we might want to refactor this further to have a more generic way of ensuring that the namespace exists with the correct labels,
205+ // regardless of which controller created it first.
206+ nsMutator := resources .NewNamespaceMutator (platformNamespace )
207+ nsMutator .MetadataMutator ().WithLabels (mcpLabels )
208+ err = resources .CreateOrUpdateResource (ctx , r .PlatformCluster .Client (), nsMutator )
201209 if err != nil {
202210 rr .ReconcileError = errutils .WithReason (fmt .Errorf ("error ensuring namespace '%s' on platform cluster: %w" , platformNamespace , err ), cconst .ReasonPlatformClusterInteractionProblem )
203211 createCon (corev2alpha1 .ConditionMeta , metav1 .ConditionFalse , rr .ReconcileError .Reason (), rr .ReconcileError .Error ())
0 commit comments