Skip to content

Commit 7eafff8

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). Previously the annotation was only checked on the rendered kustomize template (in PostRender), not on the live object — so deploy.sh patches to the AuthPolicy were immediately reverted by the next Tenant reconcile. Signed-off-by: Wen Liang <liangwen12year@gmail.com>
1 parent d0c59fd commit 7eafff8

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

  • maas-controller/pkg/platform/tenantreconcile

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

Lines changed: 25 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,20 @@ func ApplyRendered(ctx context.Context, c client.Client, scheme *runtime.Scheme,
140151
return nil
141152
}
142153

154+
func isLiveResourceUnmanaged(ctx context.Context, c client.Client, rendered *unstructured.Unstructured) bool {
155+
live := &unstructured.Unstructured{}
156+
live.SetGroupVersionKind(rendered.GroupVersionKind())
157+
key := client.ObjectKeyFromObject(rendered)
158+
if key.Name == "" {
159+
return false
160+
}
161+
if err := c.Get(ctx, key, live); err != nil {
162+
return false
163+
}
164+
ann := live.GetAnnotations()
165+
return ann != nil && ann["opendatahub.io/managed"] == "false"
166+
}
167+
143168
func setTenantTrackingLabels(obj *unstructured.Unstructured, tenant *maasv1alpha1.Tenant) {
144169
labels := obj.GetLabels()
145170
if labels == nil {

0 commit comments

Comments
 (0)