Skip to content

Commit 17e04ec

Browse files
fix(tenant): respect opendatahub.io/managed=false on live resources during SSA
ApplyRendered now checks the live cluster object's opendatahub.io/managed annotation before applying via SSA. Resources marked managed=false on the cluster are skipped, preventing the Tenant reconciler from overwriting AuthPolicy changes made by deploy.sh (e.g. OIDC patch). Signed-off-by: Wen Liang <liangwen12year@gmail.com>
1 parent a2f6b14 commit 17e04ec

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

  • maas-controller/pkg/platform/tenantreconcile

maas-controller/pkg/platform/tenantreconcile/apply.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
1212
"k8s.io/apimachinery/pkg/runtime"
13+
ctrl "sigs.k8s.io/controller-runtime"
1314
"sigs.k8s.io/controller-runtime/pkg/client"
1415
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
1516

@@ -116,9 +117,19 @@ func ApplyParams(componentPath, file string, imageParamsMap map[string]string, e
116117
// Same-namespace children get a standard ownerReference; cluster-scoped and cross-namespace children
117118
// get tracking labels instead (Kubernetes forbids cross-namespace and namespaced-to-cluster ownerReferences).
118119
func ApplyRendered(ctx context.Context, c client.Client, scheme *runtime.Scheme, tenant *maasv1alpha1.Tenant, objs []unstructured.Unstructured) error {
120+
log := ctrl.LoggerFrom(ctx)
119121
for i := range objs {
120122
u := objs[i].DeepCopy()
121123

124+
// Skip resources whose live cluster copy has opendatahub.io/managed=false.
125+
// This allows deploy scripts to opt-out specific resources (e.g. AuthPolicy
126+
// patched with OIDC config) from being overwritten on each reconcile.
127+
if isLiveResourceUnmanaged(ctx, c, u) {
128+
log.V(1).Info("Skipping SSA for resource with opendatahub.io/managed=false on cluster",
129+
"kind", u.GetKind(), "name", u.GetName(), "namespace", u.GetNamespace())
130+
continue
131+
}
132+
122133
childNs := u.GetNamespace()
123134
if childNs != "" && childNs == tenant.Namespace {
124135
if err := controllerutil.SetControllerReference(tenant, u, scheme); err != nil {
@@ -140,6 +151,22 @@ func ApplyRendered(ctx context.Context, c client.Client, scheme *runtime.Scheme,
140151
return nil
141152
}
142153

154+
// isLiveResourceUnmanaged checks if the live cluster copy of a resource has
155+
// the opendatahub.io/managed=false annotation.
156+
func isLiveResourceUnmanaged(ctx context.Context, c client.Client, rendered *unstructured.Unstructured) bool {
157+
live := &unstructured.Unstructured{}
158+
live.SetGroupVersionKind(rendered.GroupVersionKind())
159+
key := client.ObjectKeyFromObject(rendered)
160+
if key.Name == "" {
161+
return false
162+
}
163+
if err := c.Get(ctx, key, live); err != nil {
164+
return false
165+
}
166+
ann := live.GetAnnotations()
167+
return ann != nil && ann["opendatahub.io/managed"] == "false"
168+
}
169+
143170
func setTenantTrackingLabels(obj *unstructured.Unstructured, tenant *maasv1alpha1.Tenant) {
144171
labels := obj.GetLabels()
145172
if labels == nil {

0 commit comments

Comments
 (0)