From be58c5d0c3370cefdb3f2b2b25cd0752fb2a2c26 Mon Sep 17 00:00:00 2001 From: Tim Carter Date: Wed, 11 Sep 2024 17:29:29 +1000 Subject: [PATCH] Enforce dependency build ownership of build recipe config map. --- deploy/operator/base/rbac.yaml | 1 + .../dependencybuild/dependencybuild.go | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/deploy/operator/base/rbac.yaml b/deploy/operator/base/rbac.yaml index e8708c68f..2dc21da1b 100644 --- a/deploy/operator/base/rbac.yaml +++ b/deploy/operator/base/rbac.yaml @@ -151,6 +151,7 @@ rules: verbs: - get - create + - update - apiGroups: - "" resources: diff --git a/pkg/reconciler/dependencybuild/dependencybuild.go b/pkg/reconciler/dependencybuild/dependencybuild.go index f930d3924..f4773e4c3 100644 --- a/pkg/reconciler/dependencybuild/dependencybuild.go +++ b/pkg/reconciler/dependencybuild/dependencybuild.go @@ -215,8 +215,22 @@ func (r *ReconcileDependencyBuild) handleRedeployAnnotation(ctx context.Context, func (r *ReconcileDependencyBuild) handleStateNew(ctx context.Context, db *v1alpha1.DependencyBuild) (reconcile.Result, error) { log, _ := logr.FromContext(ctx) + var err error + if len(db.Spec.BuildRecipeConfigMap) > 0 { + configMap := v1.ConfigMap{} + err = r.client.Get(ctx, types.NamespacedName{Namespace: db.Namespace, Name: db.Spec.BuildRecipeConfigMap}, &configMap) + if err != nil { + return reconcile.Result{}, err + } + if err := controllerutil.SetOwnerReference(db, &configMap, r.scheme); err != nil { + return reconcile.Result{}, err + } + if err := r.client.Update(ctx, &configMap); err != nil { + return reconcile.Result{}, err + } + } jbsConfig := &v1alpha1.JBSConfig{} - err := r.client.Get(ctx, types.NamespacedName{Namespace: db.Namespace, Name: v1alpha1.JBSConfigName}, jbsConfig) + err = r.client.Get(ctx, types.NamespacedName{Namespace: db.Namespace, Name: v1alpha1.JBSConfigName}, jbsConfig) if err != nil && !errors.IsNotFound(err) { return reconcile.Result{}, err }