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/openshift-with-appstudio-test/e2e/basictests.go b/openshift-with-appstudio-test/e2e/basictests.go index 83520e161..4a57bb694 100644 --- a/openshift-with-appstudio-test/e2e/basictests.go +++ b/openshift-with-appstudio-test/e2e/basictests.go @@ -7,6 +7,7 @@ import ( "github.com/redhat-appstudio/jvm-build-service/pkg/reconciler/util" portforward "github.com/swist/go-k8s-portforward" "io" + "k8s.io/apimachinery/pkg/api/errors" "knative.dev/pkg/apis" "net/http" "os" @@ -626,6 +627,44 @@ func runDbTests(path string, testSet string, ta *testArgs) { }) pf.Stop() + + ta.t.Run(fmt.Sprintf("buildrecipe is deleted with dependencybuild for %s", s), func(t *testing.T) { + defer GenerateStatusReport(ta.ns, jvmClient, kubeClient, tektonClient) + err = wait.PollUntilContextTimeout(context.TODO(), ta.interval, time.Hour, true, func(ctx context.Context) (done bool, err error) { + err = jvmClient.JvmbuildserviceV1alpha1().DependencyBuilds(ta.ns).Delete(context.TODO(), db.Name, metav1.DeleteOptions{}) + if err != nil { + ta.Logf(fmt.Sprintf("error deleting dependencybuild %s for repo %s: %s", db.Name, db.Spec.ScmInfo.SCMURL, err.Error())) + return false, err + } + retrievedDb, err := jvmClient.JvmbuildserviceV1alpha1().DependencyBuilds(ta.ns).Get(context.TODO(), db.Name, metav1.GetOptions{}) + if err != nil { + if errors.IsNotFound(err) { + ta.Logf(fmt.Sprintf("successfully deleted dependencybuild %s for repo %s", db.Name, db.Spec.ScmInfo.SCMURL)) + } else { + ta.Logf(fmt.Sprintf("error retrieving dependencybuild %s for repo %s: %s", db.Name, db.Spec.ScmInfo.SCMURL, err.Error())) + return false, err + } + } else if retrievedDb != nil { + ta.Logf(fmt.Sprintf("failed to delete dependencybuild %s for repo %s", retrievedDb.Name, retrievedDb.Spec.ScmInfo.SCMURL)) + } + retrievedCfgMap, err := kubeClient.CoreV1().ConfigMaps(ta.ns).Get(context.TODO(), cfgMap.Name, metav1.GetOptions{}) + if err != nil { + if errors.IsNotFound(err) { + ta.Logf(fmt.Sprintf("successfully deleted configmap %s for dependencybuild repo %s", cfgMap.Name, db.Spec.ScmInfo.SCMURL)) + return true, nil + } else { + ta.Logf(fmt.Sprintf("error retrieving configmap %s for dependencybuild repo %s: %s", cfgMap.Name, db.Spec.ScmInfo.SCMURL, err.Error())) + return false, err + } + } else if retrievedCfgMap != nil { + ta.Logf(fmt.Sprintf("failed to delete configmap %s for dependencybuild repo %s", retrievedCfgMap.Name, retrievedDb.Spec.ScmInfo.SCMURL)) + } + return false, nil + }) + if err != nil { + debugAndFailTest(ta, fmt.Sprintf("timed out waiting for deletion of configmap %s for dependencybuild repo %s", db.Name, db.Spec.ScmInfo.SCMURL)) + } + }) } } 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 }