Skip to content

Commit

Permalink
Merge pull request #2086 from tecarter94/enforce-dependency-build-own…
Browse files Browse the repository at this point in the history
…ership-of-build-recipe

Enforce dependency build ownership of build recipe config map
  • Loading branch information
rnc authored Sep 12, 2024
2 parents 53fe140 + 3bc7a68 commit f7814cb
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
1 change: 1 addition & 0 deletions deploy/operator/base/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ rules:
verbs:
- get
- create
- update
- apiGroups:
- ""
resources:
Expand Down
39 changes: 39 additions & 0 deletions openshift-with-appstudio-test/e2e/basictests.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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))
}
})
}
}

Expand Down
16 changes: 15 additions & 1 deletion pkg/reconciler/dependencybuild/dependencybuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit f7814cb

Please sign in to comment.