From 6a770c9547ba43b73b9213918c78a10a38b2899d Mon Sep 17 00:00:00 2001 From: encalada Date: Tue, 9 Jan 2024 12:43:49 -0500 Subject: [PATCH] Move to v1beta1 pkg/reconciler/build pkg/validate/ pkg/reconciler/buildrun --- pkg/apis/build/v1beta1/build_types.go | 15 ++ pkg/reconciler/build/build.go | 2 +- pkg/reconciler/build/controller.go | 55 +++-- pkg/reconciler/buildrun/buildrun.go | 84 ++++---- pkg/reconciler/buildrun/resources/build.go | 16 +- .../buildrun/resources/conditions.go | 26 +-- .../buildrun/resources/credentials.go | 24 +-- .../buildrun/resources/credentials_test.go | 74 +++---- .../buildrun/resources/failure_details.go | 10 +- .../resources/failure_details_test.go | 14 +- .../buildrun/resources/image_processing.go | 8 +- .../resources/image_processing_test.go | 31 ++- pkg/reconciler/buildrun/resources/params.go | 18 +- .../buildrun/resources/params_test.go | 190 +++++++++--------- pkg/reconciler/buildrun/resources/results.go | 2 +- .../buildrun/resources/results_test.go | 4 +- .../buildrun/resources/service_accounts.go | 34 +--- .../resources/service_accounts_test.go | 7 +- pkg/reconciler/buildrun/resources/sources.go | 20 +- .../resources/steps/security_context.go | 4 +- .../buildrun/resources/strategies.go | 10 +- .../buildrun/resources/strategies_test.go | 8 +- pkg/reconciler/buildrun/resources/taskrun.go | 86 ++++---- .../buildrun/resources/taskrun_test.go | 60 +++--- pkg/validate/buildname.go | 2 +- pkg/validate/envvars.go | 2 +- pkg/validate/envvars_test.go | 2 +- pkg/validate/ownerreferences.go | 62 +++--- pkg/validate/params.go | 22 +- pkg/validate/params_test.go | 126 ++++++------ pkg/validate/secrets.go | 14 +- pkg/validate/sources.go | 48 ----- pkg/validate/sources_test.go | 73 ------- pkg/validate/sourceurl.go | 35 ++-- pkg/validate/strategies.go | 2 +- pkg/validate/trigger.go | 2 +- pkg/validate/trigger_test.go | 2 +- pkg/validate/validate.go | 13 +- pkg/validate/volumes.go | 16 +- pkg/volumes/volumes.go | 18 +- 40 files changed, 542 insertions(+), 699 deletions(-) delete mode 100644 pkg/validate/sources.go delete mode 100644 pkg/validate/sources_test.go diff --git a/pkg/apis/build/v1beta1/build_types.go b/pkg/apis/build/v1beta1/build_types.go index 0c2225e58f..a0e51f298b 100644 --- a/pkg/apis/build/v1beta1/build_types.go +++ b/pkg/apis/build/v1beta1/build_types.go @@ -275,3 +275,18 @@ type BuildRetention struct { func init() { SchemeBuilder.Register(&Build{}, &BuildList{}) } + +// GetSourceCredentials returns the secret name for a Build Source +func (b Build) GetSourceCredentials() *string { + switch b.Spec.Source.Type { + case OCIArtifactType: + if b.Spec.Source.OCIArtifact != nil && b.Spec.Source.OCIArtifact.PullSecret != nil { + return b.Spec.Source.OCIArtifact.PullSecret + } + default: + if b.Spec.Source.GitSource != nil && b.Spec.Source.GitSource.CloneSecret != nil { + return b.Spec.Source.GitSource.CloneSecret + } + } + return nil +} diff --git a/pkg/reconciler/build/build.go b/pkg/reconciler/build/build.go index ba9b2a9d2c..fabc69b6c7 100644 --- a/pkg/reconciler/build/build.go +++ b/pkg/reconciler/build/build.go @@ -15,7 +15,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/manager" "sigs.k8s.io/controller-runtime/pkg/reconcile" - build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/config" "github.com/shipwright-io/build/pkg/ctxlog" buildmetrics "github.com/shipwright-io/build/pkg/metrics" diff --git a/pkg/reconciler/build/controller.go b/pkg/reconciler/build/controller.go index a600894707..d8767a2d69 100644 --- a/pkg/reconciler/build/controller.go +++ b/pkg/reconciler/build/controller.go @@ -22,7 +22,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" "sigs.k8s.io/controller-runtime/pkg/source" - build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/config" "github.com/shipwright-io/build/pkg/ctxlog" ) @@ -62,27 +62,31 @@ func add(ctx context.Context, mgr manager.Manager, r reconcile.Reconciler, maxCo o := e.ObjectOld.(*build.Build) n := e.ObjectNew.(*build.Build) - buildRunDeletionAnnotation := false - // Check if the AnnotationBuildRunDeletion annotation is updated - oldAnnot := o.GetAnnotations() - newAnnot := n.GetAnnotations() - if !reflect.DeepEqual(oldAnnot, newAnnot) { - if oldAnnot[build.AnnotationBuildRunDeletion] != newAnnot[build.AnnotationBuildRunDeletion] { - ctxlog.Debug( - ctx, - "updating predicated passed, the annotation was modified.", - namespace, - n.GetNamespace(), - name, - n.GetName(), - ) - buildRunDeletionAnnotation = true + buildAtBuildDeletion := false + + // Check if the Build retention AtBuildDeletion is updated + oldBuildRetention := o.Spec.Retention + newBuildRetention := n.Spec.Retention + + if o.Spec.Retention != nil && n.Spec.Retention != nil { + if !reflect.DeepEqual(oldBuildRetention, newBuildRetention) { + if o.Spec.Retention.AtBuildDeletion != n.Spec.Retention.AtBuildDeletion { + ctxlog.Debug( + ctx, + "updating predicated passed, the build retention AtBuildDeletion was modified.", + namespace, + n.GetNamespace(), + name, + n.GetName(), + ) + buildAtBuildDeletion = true + } } } // Ignore updates to CR status in which case metadata.Generation does not change // or BuildRunDeletion annotation does not change - return o.GetGeneration() != n.GetGeneration() || buildRunDeletionAnnotation + return o.GetGeneration() != n.GetGeneration() || buildAtBuildDeletion }, DeleteFunc: func(e event.DeleteEvent) bool { // Never reconcile on deletion, there is nothing we have to do @@ -153,21 +157,16 @@ func add(ctx context.Context, mgr manager.Manager, r reconcile.Reconciler, maxCo flagReconcile := false for _, build := range buildList.Items { - if build.Spec.Source.Credentials != nil { - if build.Spec.Source.Credentials.Name == secret.Name { - flagReconcile = true - } + if build.GetSourceCredentials() != nil && build.GetSourceCredentials() == &secret.Name { + flagReconcile = true } - if build.Spec.Output.Credentials != nil { - if build.Spec.Output.Credentials.Name == secret.Name { - flagReconcile = true - } - } - if build.Spec.Builder != nil && build.Spec.Builder.Credentials != nil { - if build.Spec.Builder.Credentials.Name == secret.Name { + + if build.Spec.Output.PushSecret != nil { + if build.Spec.Output.PushSecret == &secret.Name { flagReconcile = true } } + if flagReconcile { reconcileList = append(reconcileList, reconcile.Request{ NamespacedName: types.NamespacedName{ diff --git a/pkg/reconciler/buildrun/buildrun.go b/pkg/reconciler/buildrun/buildrun.go index eb7ab6ba7f..156da5ad81 100644 --- a/pkg/reconciler/buildrun/buildrun.go +++ b/pkg/reconciler/buildrun/buildrun.go @@ -26,7 +26,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/manager" "sigs.k8s.io/controller-runtime/pkg/reconcile" - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/config" "github.com/shipwright-io/build/pkg/ctxlog" buildmetrics "github.com/shipwright-io/build/pkg/metrics" @@ -66,8 +66,8 @@ func NewReconciler(c *config.Config, mgr manager.Manager, ownerRef setOwnerRefer // Reconcile reads that state of the cluster for a Build object and makes changes based on the state read // and what is in the Build.Spec func (r *ReconcileBuildRun) Reconcile(ctx context.Context, request reconcile.Request) (reconcile.Result, error) { - var buildRun *buildv1alpha1.BuildRun - var build *buildv1alpha1.Build + var buildRun *buildv1beta1.BuildRun + var build *buildv1beta1.Build updateBuildRunRequired := false @@ -79,7 +79,7 @@ func (r *ReconcileBuildRun) Reconcile(ctx context.Context, request reconcile.Req // with build run cancel, it is now possible for a build run update to stem from something other than a task run update, // so we can no longer assume that a build run event will not come in after the build run has a task run ref in its status - buildRun = &buildv1alpha1.BuildRun{} + buildRun = &buildv1beta1.BuildRun{} getBuildRunErr := r.GetBuildRunObject(ctx, request.Name, request.Namespace, buildRun) lastTaskRun := &pipelineapi.TaskRun{} getTaskRunErr := r.client.Get(ctx, types.NamespacedName{Name: request.Name, Namespace: request.Namespace}, lastTaskRun) @@ -124,16 +124,16 @@ func (r *ReconcileBuildRun) Reconcile(ctx context.Context, request reconcile.Req } // if this is a build run event after we've set the task run ref, get the task run using the task run name stored in the build run - if getBuildRunErr == nil && apierrors.IsNotFound(getTaskRunErr) && buildRun.Status.LatestTaskRunRef != nil { - getTaskRunErr = r.client.Get(ctx, types.NamespacedName{Name: *buildRun.Status.LatestTaskRunRef, Namespace: request.Namespace}, lastTaskRun) + if getBuildRunErr == nil && apierrors.IsNotFound(getTaskRunErr) && buildRun.Status.TaskRunName != nil { + getTaskRunErr = r.client.Get(ctx, types.NamespacedName{Name: *buildRun.Status.TaskRunName, Namespace: request.Namespace}, lastTaskRun) } // for existing TaskRuns update the BuildRun Status, if there is no TaskRun, then create one if getTaskRunErr != nil { if apierrors.IsNotFound(getTaskRunErr) { - build = &buildv1alpha1.Build{} + build = &buildv1beta1.Build{} if err := resources.GetBuildObject(ctx, r.client, buildRun, build); err != nil { - if !resources.IsClientStatusUpdateError(err) && buildRun.Status.IsFailed(buildv1alpha1.Succeeded) { + if !resources.IsClientStatusUpdateError(err) && buildRun.Status.IsFailed(buildv1beta1.Succeeded) { return reconcile.Result{}, nil } // system call failure, reconcile again @@ -147,17 +147,17 @@ func (r *ReconcileBuildRun) Reconcile(ctx context.Context, request reconcile.Req // an actual resource in the cluster and _should_ have been // validated and registered by now ... // reconcile again until it gets a registration value - case buildRun.Spec.BuildRef != nil: + case buildRun.Spec.Build.Name != nil: return reconcile.Result{}, fmt.Errorf("the Build is not yet validated, build: %s", build.Name) // When the build(spec) is embedded in the buildrun, the now // transient/volatile build resource needs to be validated first - case buildRun.Spec.BuildSpec != nil: + case buildRun.Spec.Build.Build != nil: err := validate.All(ctx, validate.NewSourceURL(r.client, build), validate.NewCredentials(r.client, build), validate.NewStrategies(r.client, build), - validate.NewSourcesRef(build), + // validate.NewSourcesRef(build), validate.NewBuildName(build), validate.NewEnv(build), ) @@ -180,16 +180,16 @@ func (r *ReconcileBuildRun) Reconcile(ctx context.Context, request reconcile.Req } // mark transient build as "registered" and validated - build.Status.Registered = buildv1alpha1.ConditionStatusPtr(corev1.ConditionTrue) - build.Status.Reason = buildv1alpha1.BuildReasonPtr(buildv1alpha1.SucceedStatus) - build.Status.Message = pointer.String(buildv1alpha1.AllValidationsSucceeded) + build.Status.Registered = buildv1beta1.ConditionStatusPtr(corev1.ConditionTrue) + build.Status.Reason = buildv1beta1.BuildReasonPtr(buildv1beta1.SucceedStatus) + build.Status.Message = pointer.String(buildv1beta1.AllValidationsSucceeded) } } if *build.Status.Registered != corev1.ConditionTrue { // stop reconciling and mark the BuildRun as Failed // we only reconcile again if the status.Update call fails - var reason buildv1alpha1.BuildReason + var reason buildv1beta1.BuildReason if build.Status.Reason != nil { reason = *build.Status.Reason @@ -210,31 +210,33 @@ func (r *ReconcileBuildRun) Reconcile(ctx context.Context, request reconcile.Req // make sure the BuildRun has not already been cancelled if buildRun.IsCanceled() { - if updateErr := resources.UpdateConditionWithFalseStatus(ctx, r.client, buildRun, "the BuildRun is marked canceled.", buildv1alpha1.BuildRunStateCancel); updateErr != nil { + if updateErr := resources.UpdateConditionWithFalseStatus(ctx, r.client, buildRun, "the BuildRun is marked canceled.", buildv1beta1.BuildRunStateCancel); updateErr != nil { return reconcile.Result{}, updateErr } return reconcile.Result{}, nil } - // Set OwnerReference for Build and BuildRun only when build.shipwright.io/build-run-deletion is set "true" - if build.GetAnnotations()[buildv1alpha1.AnnotationBuildRunDeletion] == "true" && !resources.IsOwnedByBuild(build, buildRun.OwnerReferences) { - if err := r.setOwnerReferenceFunc(build, buildRun, r.scheme); err != nil { - build.Status.Reason = buildv1alpha1.BuildReasonPtr(buildv1alpha1.SetOwnerReferenceFailed) - build.Status.Message = pointer.String(fmt.Sprintf("unexpected error when trying to set the ownerreference: %v", err)) - if err := r.client.Status().Update(ctx, build); err != nil { - return reconcile.Result{}, err + // Set OwnerReference for Build and BuildRun only when build retention AtBuildDeletion is set to "true" + if build.Spec.Retention != nil && build.Spec.Retention.AtBuildDeletion != nil { + if *build.Spec.Retention.AtBuildDeletion && !resources.IsOwnedByBuild(build, buildRun.OwnerReferences) { + if err := r.setOwnerReferenceFunc(build, buildRun, r.scheme); err != nil { + build.Status.Reason = buildv1beta1.BuildReasonPtr(buildv1beta1.SetOwnerReferenceFailed) + build.Status.Message = pointer.String(fmt.Sprintf("unexpected error when trying to set the ownerreference: %v", err)) + if err := r.client.Status().Update(ctx, build); err != nil { + return reconcile.Result{}, err + } } + ctxlog.Info(ctx, fmt.Sprintf("updating BuildRun %s OwnerReferences, owner is Build %s", buildRun.Name, build.Name), namespace, request.Namespace, name, request.Name) + updateBuildRunRequired = true } - ctxlog.Info(ctx, fmt.Sprintf("updating BuildRun %s OwnerReferences, owner is Build %s", buildRun.Name, build.Name), namespace, request.Namespace, name, request.Name) - updateBuildRunRequired = true } // Add missing build name and generation labels to BuildRun (unless it is an embedded build) if build.Name != "" && build.Generation != 0 { buildGeneration := strconv.FormatInt(build.Generation, 10) - if buildRun.GetLabels()[buildv1alpha1.LabelBuild] != build.Name || buildRun.GetLabels()[buildv1alpha1.LabelBuildGeneration] != buildGeneration { - buildRun.Labels[buildv1alpha1.LabelBuild] = build.Name - buildRun.Labels[buildv1alpha1.LabelBuildGeneration] = buildGeneration + if buildRun.GetLabels()[buildv1beta1.LabelBuild] != build.Name || buildRun.GetLabels()[buildv1beta1.LabelBuildGeneration] != buildGeneration { + buildRun.Labels[buildv1beta1.LabelBuild] = build.Name + buildRun.Labels[buildv1beta1.LabelBuildGeneration] = buildGeneration ctxlog.Info(ctx, "updating BuildRun labels", namespace, request.Namespace, name, request.Name) updateBuildRunRequired = true } @@ -257,7 +259,7 @@ func (r *ReconcileBuildRun) Reconcile(ctx context.Context, request reconcile.Req // Choose a service account to use svcAccount, err := resources.RetrieveServiceAccount(ctx, r.client, build, buildRun) if err != nil { - if !resources.IsClientStatusUpdateError(err) && buildRun.Status.IsFailed(buildv1alpha1.Succeeded) { + if !resources.IsClientStatusUpdateError(err) && buildRun.Status.IsFailed(buildv1beta1.Succeeded) { return reconcile.Result{}, nil } // system call failure, reconcile again @@ -266,7 +268,7 @@ func (r *ReconcileBuildRun) Reconcile(ctx context.Context, request reconcile.Req strategy, err := r.getReferencedStrategy(ctx, build, buildRun) if err != nil { - if !resources.IsClientStatusUpdateError(err) && buildRun.Status.IsFailed(buildv1alpha1.Succeeded) { + if !resources.IsClientStatusUpdateError(err) && buildRun.Status.IsFailed(buildv1beta1.Succeeded) { return reconcile.Result{}, nil } return reconcile.Result{}, err @@ -293,7 +295,7 @@ func (r *ReconcileBuildRun) Reconcile(ctx context.Context, request reconcile.Req // Create the TaskRun, this needs to be the last step in this block to be idempotent generatedTaskRun, err := r.createTaskRun(ctx, svcAccount, strategy, build, buildRun) if err != nil { - if !resources.IsClientStatusUpdateError(err) && buildRun.Status.IsFailed(buildv1alpha1.Succeeded) { + if !resources.IsClientStatusUpdateError(err) && buildRun.Status.IsFailed(buildv1beta1.Succeeded) { ctxlog.Info(ctx, "taskRun generation failed", namespace, request.Namespace, name, request.Name) return reconcile.Result{}, nil } @@ -305,7 +307,7 @@ func (r *ReconcileBuildRun) Reconcile(ctx context.Context, request reconcile.Req // if resource is not found, fais the build run if err != nil { if apierrors.IsNotFound(err) { - if err := resources.UpdateConditionWithFalseStatus(ctx, r.client, buildRun, err.Error(), string(buildv1alpha1.VolumeDoesNotExist)); err != nil { + if err := resources.UpdateConditionWithFalseStatus(ctx, r.client, buildRun, err.Error(), string(buildv1beta1.VolumeDoesNotExist)); err != nil { return reconcile.Result{}, err } @@ -324,7 +326,7 @@ func (r *ReconcileBuildRun) Reconcile(ctx context.Context, request reconcile.Req } // Set the LastTaskRunRef in the BuildRun status - buildRun.Status.LatestTaskRunRef = &generatedTaskRun.Name + buildRun.Status.TaskRunName = &generatedTaskRun.Name ctxlog.Info(ctx, "updating BuildRun status with TaskRun name", namespace, request.Namespace, name, request.Name, "TaskRun", generatedTaskRun.Name) if err = r.client.Status().Update(ctx, buildRun); err != nil { // we ignore the error here to prevent another reconciliation that would create another TaskRun, @@ -359,7 +361,7 @@ func (r *ReconcileBuildRun) Reconcile(ctx context.Context, request reconcile.Req return reconcile.Result{}, getBuildRunErr } else if apierrors.IsNotFound(getBuildRunErr) { // this is a TR event, try getting the br from the label on the tr - err := r.GetBuildRunObject(ctx, lastTaskRun.Labels[buildv1alpha1.LabelBuildRun], request.Namespace, buildRun) + err := r.GetBuildRunObject(ctx, lastTaskRun.Labels[buildv1beta1.LabelBuildRun], request.Namespace, buildRun) if err != nil && !apierrors.IsNotFound(err) { return reconcile.Result{}, err } @@ -408,7 +410,7 @@ func (r *ReconcileBuildRun) Reconcile(ctx context.Context, request reconcile.Req } } - buildRun.Status.LatestTaskRunRef = &lastTaskRun.Name + buildRun.Status.TaskRunName = &lastTaskRun.Name if buildRun.Status.StartTime == nil && lastTaskRun.Status.StartTime != nil { buildRun.Status.StartTime = lastTaskRun.Status.StartTime @@ -479,13 +481,13 @@ func (r *ReconcileBuildRun) Reconcile(ctx context.Context, request reconcile.Req } // GetBuildRunObject retrieves an existing BuildRun based on a name and namespace -func (r *ReconcileBuildRun) GetBuildRunObject(ctx context.Context, objectName string, objectNS string, buildRun *buildv1alpha1.BuildRun) error { +func (r *ReconcileBuildRun) GetBuildRunObject(ctx context.Context, objectName string, objectNS string, buildRun *buildv1beta1.BuildRun) error { return r.client.Get(ctx, types.NamespacedName{Name: objectName, Namespace: objectNS}, buildRun) } // VerifyRequestName parse a Reconcile request name and looks for an associated BuildRun name // If the BuildRun object exists and is not yet completed, it will update it with an error. -func (r *ReconcileBuildRun) VerifyRequestName(ctx context.Context, request reconcile.Request, buildRun *buildv1alpha1.BuildRun) { +func (r *ReconcileBuildRun) VerifyRequestName(ctx context.Context, request reconcile.Request, buildRun *buildv1beta1.BuildRun) { regxBuildRun, _ := regexp.Compile(generatedNameRegex) @@ -506,7 +508,7 @@ func (r *ReconcileBuildRun) VerifyRequestName(ctx context.Context, request recon } } -func (r *ReconcileBuildRun) getReferencedStrategy(ctx context.Context, build *buildv1alpha1.Build, buildRun *buildv1alpha1.BuildRun) (strategy buildv1alpha1.BuilderStrategy, err error) { +func (r *ReconcileBuildRun) getReferencedStrategy(ctx context.Context, build *buildv1beta1.Build, buildRun *buildv1beta1.BuildRun) (strategy buildv1beta1.BuilderStrategy, err error) { if build.Spec.Strategy.Kind == nil { // If the strategy Kind is not specified, we default to a namespaced-scope strategy ctxlog.Info(ctx, "missing strategy Kind, defaulting to a namespaced-scope one", buildRun.Name, build.Name, namespace) @@ -522,7 +524,7 @@ func (r *ReconcileBuildRun) getReferencedStrategy(ctx context.Context, build *bu } switch *build.Spec.Strategy.Kind { - case buildv1alpha1.NamespacedBuildStrategyKind: + case buildv1beta1.NamespacedBuildStrategyKind: strategy, err = resources.RetrieveBuildStrategy(ctx, r.client, build) if err != nil { if apierrors.IsNotFound(err) { @@ -531,7 +533,7 @@ func (r *ReconcileBuildRun) getReferencedStrategy(ctx context.Context, build *bu } } } - case buildv1alpha1.ClusterBuildStrategyKind: + case buildv1beta1.ClusterBuildStrategyKind: strategy, err = resources.RetrieveClusterBuildStrategy(ctx, r.client, build) if err != nil { if apierrors.IsNotFound(err) { @@ -550,7 +552,7 @@ func (r *ReconcileBuildRun) getReferencedStrategy(ctx context.Context, build *bu return strategy, err } -func (r *ReconcileBuildRun) createTaskRun(ctx context.Context, serviceAccount *corev1.ServiceAccount, strategy buildv1alpha1.BuilderStrategy, build *buildv1alpha1.Build, buildRun *buildv1alpha1.BuildRun) (*pipelineapi.TaskRun, error) { +func (r *ReconcileBuildRun) createTaskRun(ctx context.Context, serviceAccount *corev1.ServiceAccount, strategy buildv1beta1.BuilderStrategy, build *buildv1beta1.Build, buildRun *buildv1beta1.BuildRun) (*pipelineapi.TaskRun, error) { var ( generatedTaskRun *pipelineapi.TaskRun ) diff --git a/pkg/reconciler/buildrun/resources/build.go b/pkg/reconciler/buildrun/resources/build.go index 72e8e419d1..612d05c541 100644 --- a/pkg/reconciler/buildrun/resources/build.go +++ b/pkg/reconciler/buildrun/resources/build.go @@ -13,19 +13,19 @@ import ( "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" ) // GetBuildObject retrieves an existing Build based on a name and namespace -func GetBuildObject(ctx context.Context, client client.Client, buildRun *buildv1alpha1.BuildRun, build *buildv1alpha1.Build) error { +func GetBuildObject(ctx context.Context, client client.Client, buildRun *buildv1beta1.BuildRun, build *buildv1beta1.Build) error { // Option #1: BuildRef is specified // An actual Build resource is specified by name and needs to be looked up in the cluster. - if buildRun.Spec.BuildRef != nil { + if buildRun.Spec.Build.Name != nil { err := client.Get(ctx, types.NamespacedName{Name: buildRun.Spec.BuildName(), Namespace: buildRun.Namespace}, build) if apierrors.IsNotFound(err) { // stop reconciling and mark the BuildRun as Failed // we only reconcile again if the status.Update call fails - if updateErr := UpdateConditionWithFalseStatus(ctx, client, buildRun, fmt.Sprintf("build.shipwright.io %q not found", buildRun.Spec.BuildRef.Name), ConditionBuildNotFound); updateErr != nil { + if updateErr := UpdateConditionWithFalseStatus(ctx, client, buildRun, fmt.Sprintf("build.shipwright.io %q not found", buildRun.Spec.Build.Name), ConditionBuildNotFound); updateErr != nil { return HandleError("build object not found", err, updateErr) } } @@ -35,11 +35,11 @@ func GetBuildObject(ctx context.Context, client client.Client, buildRun *buildv1 // Option #2: BuildSpec is specified // The build specification is embedded in the BuildRun itself, create a transient Build resource. - if buildRun.Spec.BuildSpec != nil { + if buildRun.Spec.Build.Build != nil { build.Name = "" build.Namespace = buildRun.Namespace - build.Status = buildv1alpha1.BuildStatus{} - buildRun.Spec.BuildSpec.DeepCopyInto(&build.Spec) + build.Status = buildv1beta1.BuildStatus{} + buildRun.Spec.Build.Build.DeepCopyInto(&build.Spec) return nil } @@ -48,7 +48,7 @@ func GetBuildObject(ctx context.Context, client client.Client, buildRun *buildv1 } // IsOwnedByBuild checks if the controllerReferences contains a well known owner Kind -func IsOwnedByBuild(build *buildv1alpha1.Build, controlledReferences []metav1.OwnerReference) bool { +func IsOwnedByBuild(build *buildv1beta1.Build, controlledReferences []metav1.OwnerReference) bool { for _, ref := range controlledReferences { if ref.Kind == build.Kind && ref.Name == build.Name { return true diff --git a/pkg/reconciler/buildrun/resources/conditions.go b/pkg/reconciler/buildrun/resources/conditions.go index 3478096212..4671afee01 100644 --- a/pkg/reconciler/buildrun/resources/conditions.go +++ b/pkg/reconciler/buildrun/resources/conditions.go @@ -16,7 +16,7 @@ import ( apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/ctxlog" ) @@ -47,7 +47,7 @@ const ( ) // UpdateBuildRunUsingTaskRunCondition updates the BuildRun Succeeded Condition -func UpdateBuildRunUsingTaskRunCondition(ctx context.Context, client client.Client, buildRun *buildv1alpha1.BuildRun, taskRun *pipelineapi.TaskRun, trCondition *apis.Condition) error { +func UpdateBuildRunUsingTaskRunCondition(ctx context.Context, client client.Client, buildRun *buildv1beta1.BuildRun, taskRun *pipelineapi.TaskRun, trCondition *apis.Condition) error { var reason, message string = trCondition.Reason, trCondition.Message status := trCondition.Status @@ -57,13 +57,13 @@ func UpdateBuildRunUsingTaskRunCondition(ctx context.Context, client client.Clie case pipelineapi.TaskRunReasonRunning: if buildRun.IsCanceled() { status = corev1.ConditionUnknown // in practice the taskrun status is already unknown in this case, but we are making sure here - reason = buildv1alpha1.BuildRunStateCancel + reason = buildv1beta1.BuildRunStateCancel message = "The user requested the BuildRun to be canceled. This BuildRun controller has requested the TaskRun be canceled. That request has not been process by Tekton's TaskRun controller yet." } case pipelineapi.TaskRunReasonCancelled: if buildRun.IsCanceled() { status = corev1.ConditionFalse // in practice the taskrun status is already false in this case, bue we are making sure here - reason = buildv1alpha1.BuildRunStateCancel + reason = buildv1beta1.BuildRunStateCancel message = "The BuildRun and underlying TaskRun were canceled successfully." } @@ -95,18 +95,18 @@ func UpdateBuildRunUsingTaskRunCondition(ctx context.Context, client client.Clie } //nolint:staticcheck // SA1019 we want to give users some time to adopt to failureDetails - buildRun.Status.FailedAt = &buildv1alpha1.FailedAt{Pod: pod.Name} + buildRun.Status.FailureDetails.Location = &buildv1beta1.Location{Pod: pod.Name} if pod.Status.Reason == "Evicted" { message = pod.Status.Message - reason = buildv1alpha1.BuildRunStatePodEvicted + reason = buildv1beta1.BuildRunStatePodEvicted if failedContainer != nil { //nolint:staticcheck // SA1019 we want to give users some time to adopt to failureDetails - buildRun.Status.FailedAt.Container = failedContainer.Name + buildRun.Status.FailureDetails.Location.Container = failedContainer.Name } } else if failedContainer != nil { //nolint:staticcheck // SA1019 we want to give users some time to adopt to failureDetails - buildRun.Status.FailedAt.Container = failedContainer.Name + buildRun.Status.FailureDetails.Location.Container = failedContainer.Name message = fmt.Sprintf("buildrun step %s failed in pod %s, for detailed information: kubectl --namespace %s logs %s --container=%s", failedContainer.Name, pod.Name, @@ -124,9 +124,9 @@ func UpdateBuildRunUsingTaskRunCondition(ctx context.Context, client client.Clie } } - buildRun.Status.SetCondition(&buildv1alpha1.Condition{ + buildRun.Status.SetCondition(&buildv1beta1.Condition{ LastTransitionTime: metav1.Now(), - Type: buildv1alpha1.Succeeded, + Type: buildv1beta1.Succeeded, Status: status, Reason: reason, Message: message, @@ -138,12 +138,12 @@ func UpdateBuildRunUsingTaskRunCondition(ctx context.Context, client client.Clie // UpdateConditionWithFalseStatus sets the Succeeded condition fields and mark // the condition as Status False. It also updates the object in the cluster by // calling client Status Update -func UpdateConditionWithFalseStatus(ctx context.Context, client client.Client, buildRun *buildv1alpha1.BuildRun, errorMessage string, reason string) error { +func UpdateConditionWithFalseStatus(ctx context.Context, client client.Client, buildRun *buildv1beta1.BuildRun, errorMessage string, reason string) error { now := metav1.Now() buildRun.Status.CompletionTime = &now - buildRun.Status.SetCondition(&buildv1alpha1.Condition{ + buildRun.Status.SetCondition(&buildv1beta1.Condition{ LastTransitionTime: now, - Type: buildv1alpha1.Succeeded, + Type: buildv1beta1.Succeeded, Status: corev1.ConditionFalse, Reason: reason, Message: errorMessage, diff --git a/pkg/reconciler/buildrun/resources/credentials.go b/pkg/reconciler/buildrun/resources/credentials.go index 2836acbf79..60f4479476 100644 --- a/pkg/reconciler/buildrun/resources/credentials.go +++ b/pkg/reconciler/buildrun/resources/credentials.go @@ -9,30 +9,24 @@ import ( corev1 "k8s.io/api/core/v1" - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/ctxlog" ) // ApplyCredentials adds all credentials that are referenced by the build and adds them to the service account. // The function returns true if the service account was modified. -func ApplyCredentials(ctx context.Context, build *buildv1alpha1.Build, buildRun *buildv1alpha1.BuildRun, serviceAccount *corev1.ServiceAccount) bool { +func ApplyCredentials(ctx context.Context, build *buildv1beta1.Build, buildRun *buildv1beta1.BuildRun, serviceAccount *corev1.ServiceAccount) bool { modified := false - // credentials of the 'Builder' image registry - builderImage := build.Spec.Builder - if builderImage != nil && builderImage.Credentials != nil { - modified = updateServiceAccountIfSecretNotLinked(ctx, builderImage.Credentials, serviceAccount) || modified - } - // if output is overridden by buildrun, and if this override has credentials, // it should be added to the sa - if buildRun.Spec.Output != nil && buildRun.Spec.Output.Credentials != nil { - modified = updateServiceAccountIfSecretNotLinked(ctx, buildRun.Spec.Output.Credentials, serviceAccount) || modified + if buildRun.Spec.Output != nil && buildRun.Spec.Output.PushSecret != nil { + modified = updateServiceAccountIfSecretNotLinked(ctx, buildRun.Spec.Output.PushSecret, serviceAccount) || modified } else { // otherwise, if buildrun does not override the output credentials, // we should use the ones provided by the build - outputSecret := build.Spec.Output.Credentials + outputSecret := build.Spec.Output.PushSecret if outputSecret != nil { modified = updateServiceAccountIfSecretNotLinked(ctx, outputSecret, serviceAccount) || modified } @@ -41,19 +35,19 @@ func ApplyCredentials(ctx context.Context, build *buildv1alpha1.Build, buildRun return modified } -func updateServiceAccountIfSecretNotLinked(ctx context.Context, sourceSecret *corev1.LocalObjectReference, serviceAccount *corev1.ServiceAccount) bool { +func updateServiceAccountIfSecretNotLinked(ctx context.Context, sourceSecret *string, serviceAccount *corev1.ServiceAccount) bool { isSecretPresent := false for _, credentialSecret := range serviceAccount.Secrets { - if credentialSecret.Name == sourceSecret.Name { + if credentialSecret.Name == *sourceSecret { isSecretPresent = true break } } if !isSecretPresent { - ctxlog.Debug(ctx, "adding secret to serviceAccount", "secret", sourceSecret.Name, "serviceAccount", serviceAccount.Name) + ctxlog.Debug(ctx, "adding secret to serviceAccount", "secret", *sourceSecret, "serviceAccount", serviceAccount.Name) serviceAccount.Secrets = append(serviceAccount.Secrets, corev1.ObjectReference{ - Name: sourceSecret.Name, + Name: *sourceSecret, }) return true } diff --git a/pkg/reconciler/buildrun/resources/credentials_test.go b/pkg/reconciler/buildrun/resources/credentials_test.go index 95d02aafa9..7aa9f750b6 100644 --- a/pkg/reconciler/buildrun/resources/credentials_test.go +++ b/pkg/reconciler/buildrun/resources/credentials_test.go @@ -13,14 +13,14 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/utils/pointer" - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/reconciler/buildrun/resources" ) var _ = Describe("Credentials", func() { var ( - build *buildv1alpha1.Build - buildRun *buildv1alpha1.BuildRun + build *buildv1beta1.Build + buildRun *buildv1beta1.BuildRun beforeServiceAccount *corev1.ServiceAccount expectedAfterServiceAccount *corev1.ServiceAccount ) @@ -35,36 +35,24 @@ var _ = Describe("Credentials", func() { Context("when secrets were not present in the service account", func() { BeforeEach(func() { - build = &buildv1alpha1.Build{ - Spec: buildv1alpha1.BuildSpec{ - Source: buildv1alpha1.Source{ - URL: pointer.String("a/b/c"), - Credentials: &corev1.LocalObjectReference{ - Name: "secret_a", - }, - }, - Builder: &buildv1alpha1.Image{ - Image: "quay.io/namespace/image", - Credentials: &corev1.LocalObjectReference{ - Name: "secret_docker.io", - }, + build = &buildv1beta1.Build{ + Spec: buildv1beta1.BuildSpec{ + Source: buildv1beta1.Source{ + URL: pointer.String("a/b/c"), + PushSecret: pointer.String("secret_a"), }, - Output: buildv1alpha1.Image{ - Image: "quay.io/namespace/image", - Credentials: &corev1.LocalObjectReference{ - Name: "secret_quay.io", - }, + Output: buildv1beta1.Image{ + Image: "quay.io/namespace/image", + PushSecret: pointer.String("secret_quay.io"), }, }, } - buildRun = &buildv1alpha1.BuildRun{ - Spec: buildv1alpha1.BuildRunSpec{ - Output: &buildv1alpha1.Image{ - Image: "quay.io/namespace/brImage", - Credentials: &corev1.LocalObjectReference{ - Name: "secret_buildrun.io", - }, + buildRun = &buildv1beta1.BuildRun{ + Spec: buildv1beta1.BuildRunSpec{ + Output: &buildv1beta1.Image{ + Image: "quay.io/namespace/brImage", + PushSecret: pointer.String("secret_buildrun.io"), }, }, } @@ -91,24 +79,22 @@ var _ = Describe("Credentials", func() { Context("when secrets were already in the service account", func() { BeforeEach(func() { - build = &buildv1alpha1.Build{ - Spec: buildv1alpha1.BuildSpec{ - Source: buildv1alpha1.Source{ + build = &buildv1beta1.Build{ + Spec: buildv1beta1.BuildSpec{ + Source: buildv1beta1.Source{ URL: pointer.String("a/b/c"), }, - Output: buildv1alpha1.Image{ - Credentials: &corev1.LocalObjectReference{ - Name: "secret_b", - }, + Output: buildv1beta1.Image{ + PushSecret: pointer.String("secret_b"), }, }, } // This is just a placeholder BuildRun with no // SecretRef added to the ones from the Build - buildRun = &buildv1alpha1.BuildRun{ - Spec: buildv1alpha1.BuildRunSpec{ - Output: &buildv1alpha1.Image{ + buildRun = &buildv1beta1.BuildRun{ + Spec: buildv1beta1.BuildRunSpec{ + Output: &buildv1beta1.Image{ Image: "https://image.url/", }, }, @@ -128,9 +114,9 @@ var _ = Describe("Credentials", func() { Context("when build does not reference any secret", func() { BeforeEach(func() { - build = &buildv1alpha1.Build{ - Spec: buildv1alpha1.BuildSpec{ - Source: buildv1alpha1.Source{ + build = &buildv1beta1.Build{ + Spec: buildv1beta1.BuildSpec{ + Source: buildv1beta1.Source{ URL: pointer.String("a/b/c"), Credentials: nil, }, @@ -139,9 +125,9 @@ var _ = Describe("Credentials", func() { // This is just a placeholder BuildRun with no // SecretRef added to the ones from the Build - buildRun = &buildv1alpha1.BuildRun{ - Spec: buildv1alpha1.BuildRunSpec{ - Output: &buildv1alpha1.Image{ + buildRun = &buildv1beta1.BuildRun{ + Spec: buildv1beta1.BuildRunSpec{ + Output: &buildv1beta1.Image{ Image: "https://image.url/", }, }, diff --git a/pkg/reconciler/buildrun/resources/failure_details.go b/pkg/reconciler/buildrun/resources/failure_details.go index b96451abaf..3be2dc272e 100644 --- a/pkg/reconciler/buildrun/resources/failure_details.go +++ b/pkg/reconciler/buildrun/resources/failure_details.go @@ -13,7 +13,7 @@ import ( "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/ctxlog" pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" "github.com/tektoncd/pipeline/pkg/result" @@ -28,7 +28,7 @@ const ( ) // UpdateBuildRunUsingTaskFailures is extracting failures from taskRun steps and adding them to buildRun (mutates) -func UpdateBuildRunUsingTaskFailures(ctx context.Context, client client.Client, buildRun *buildv1alpha1.BuildRun, taskRun *pipelineapi.TaskRun) { +func UpdateBuildRunUsingTaskFailures(ctx context.Context, client client.Client, buildRun *buildv1beta1.BuildRun, taskRun *pipelineapi.TaskRun) { trCondition := taskRun.Status.GetCondition(apis.ConditionSucceeded) // only extract failures when failing condition is present @@ -91,12 +91,12 @@ func extractFailedPodAndContainer(ctx context.Context, client client.Client, tas return &pod, failedContainer, nil } -func extractFailureDetails(ctx context.Context, client client.Client, taskRun *pipelineapi.TaskRun) (failure *buildv1alpha1.FailureDetails) { - failure = &buildv1alpha1.FailureDetails{} +func extractFailureDetails(ctx context.Context, client client.Client, taskRun *pipelineapi.TaskRun) (failure *buildv1beta1.FailureDetails) { + failure = &buildv1beta1.FailureDetails{} failure.Reason, failure.Message = extractFailureReasonAndMessage(taskRun) - failure.Location = &buildv1alpha1.FailedAt{Pod: taskRun.Status.PodName} + failure.Location = &buildv1beta1.Location{Pod: taskRun.Status.PodName} pod, container, _ := extractFailedPodAndContainer(ctx, client, taskRun) if pod != nil && container != nil { diff --git a/pkg/reconciler/buildrun/resources/failure_details_test.go b/pkg/reconciler/buildrun/resources/failure_details_test.go index dbae3cc308..225e3dc0dc 100644 --- a/pkg/reconciler/buildrun/resources/failure_details_test.go +++ b/pkg/reconciler/buildrun/resources/failure_details_test.go @@ -16,7 +16,7 @@ import ( corev1 "k8s.io/api/core/v1" "knative.dev/pkg/apis" - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" buildfakes "github.com/shipwright-io/build/pkg/controller/fakes" ) @@ -46,7 +46,7 @@ var _ = Describe("Surfacing errors", func() { followUpStep := pipelineapi.StepState{} redTaskRun.Status.Steps = append(redTaskRun.Status.Steps, failedStep, followUpStep) - redBuild := buildv1alpha1.BuildRun{} + redBuild := buildv1beta1.BuildRun{} UpdateBuildRunUsingTaskFailures(ctx, client, &redBuild, &redTaskRun) @@ -67,7 +67,7 @@ var _ = Describe("Surfacing errors", func() { failedStep.Terminated = &corev1.ContainerStateTerminated{Message: string(message)} redTaskRun.Status.Steps = append(redTaskRun.Status.Steps, failedStep) - redBuild := buildv1alpha1.BuildRun{} + redBuild := buildv1beta1.BuildRun{} UpdateBuildRunUsingTaskFailures(ctx, client, &redBuild, &redTaskRun) @@ -93,7 +93,7 @@ var _ = Describe("Surfacing errors", func() { failedStep.Terminated = &corev1.ContainerStateTerminated{Message: string(message)} greenTaskRun.Status.Steps = append(greenTaskRun.Status.Steps, failedStep) - greenBuildRun := buildv1alpha1.BuildRun{} + greenBuildRun := buildv1beta1.BuildRun{} UpdateBuildRunUsingTaskFailures(ctx, client, &greenBuildRun, &greenTaskRun) @@ -103,7 +103,7 @@ var _ = Describe("Surfacing errors", func() { It("should not surface errors for a successful TaskRun", func() { greenTaskRun := pipelineapi.TaskRun{} greenTaskRun.Status.Conditions = append(greenTaskRun.Status.Conditions, apis.Condition{Type: apis.ConditionSucceeded}) - greenBuildRun := buildv1alpha1.BuildRun{} + greenBuildRun := buildv1beta1.BuildRun{} UpdateBuildRunUsingTaskFailures(ctx, client, &greenBuildRun, &greenTaskRun) @@ -113,7 +113,7 @@ var _ = Describe("Surfacing errors", func() { It("should not surface errors if the TaskRun does not have a Succeeded condition", func() { unfinishedTaskRun := pipelineapi.TaskRun{} unfinishedTaskRun.Status.Conditions = append(unfinishedTaskRun.Status.Conditions, apis.Condition{Type: apis.ConditionReady}) - unfinishedBuildRun := buildv1alpha1.BuildRun{} + unfinishedBuildRun := buildv1beta1.BuildRun{} UpdateBuildRunUsingTaskFailures(ctx, client, &unfinishedBuildRun, &unfinishedTaskRun) Expect(unfinishedBuildRun.Status.FailureDetails).To(BeNil()) @@ -122,7 +122,7 @@ var _ = Describe("Surfacing errors", func() { It("should not surface errors if the TaskRun is in progress", func() { unknownTaskRun := pipelineapi.TaskRun{} unknownTaskRun.Status.Conditions = append(unknownTaskRun.Status.Conditions, apis.Condition{Type: apis.ConditionSucceeded, Reason: "random"}) - unknownBuildRun := buildv1alpha1.BuildRun{} + unknownBuildRun := buildv1beta1.BuildRun{} UpdateBuildRunUsingTaskFailures(ctx, client, &unknownBuildRun, &unknownTaskRun) Expect(unknownBuildRun.Status.FailureDetails).To(BeNil()) diff --git a/pkg/reconciler/buildrun/resources/image_processing.go b/pkg/reconciler/buildrun/resources/image_processing.go index 349ed6af63..6ad80852e2 100644 --- a/pkg/reconciler/buildrun/resources/image_processing.go +++ b/pkg/reconciler/buildrun/resources/image_processing.go @@ -7,7 +7,7 @@ package resources import ( "fmt" - build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/config" "github.com/shipwright-io/build/pkg/reconciler/buildrun/resources/sources" pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" @@ -117,14 +117,14 @@ func SetupImageProcessing(taskRun *pipelineapi.TaskRun, cfg *config.Config, buil }) } - if buildOutput.Credentials != nil { - sources.AppendSecretVolume(taskRun.Spec.TaskSpec, buildOutput.Credentials.Name) + if buildOutput.PushSecret != nil { + sources.AppendSecretVolume(taskRun.Spec.TaskSpec, *buildOutput.PushSecret) secretMountPath := fmt.Sprintf("/workspace/%s-push-secret", prefixParamsResultsVolumes) // define the volume mount on the container imageProcessingStep.VolumeMounts = append(imageProcessingStep.VolumeMounts, core.VolumeMount{ - Name: sources.SanitizeVolumeNameForSecretName(buildOutput.Credentials.Name), + Name: sources.SanitizeVolumeNameForSecretName(*buildOutput.PushSecret), MountPath: secretMountPath, ReadOnly: true, }) diff --git a/pkg/reconciler/buildrun/resources/image_processing_test.go b/pkg/reconciler/buildrun/resources/image_processing_test.go index 0e7853a854..bbb267244f 100644 --- a/pkg/reconciler/buildrun/resources/image_processing_test.go +++ b/pkg/reconciler/buildrun/resources/image_processing_test.go @@ -8,9 +8,7 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - corev1 "k8s.io/api/core/v1" - - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/config" "github.com/shipwright-io/build/pkg/reconciler/buildrun/resources" utils "github.com/shipwright-io/build/test/utils/v1alpha1" @@ -38,9 +36,9 @@ var _ = Describe("Image Processing overrides", func() { Context("for a build without labels and annotation in the output", func() { BeforeEach(func() { processedTaskRun = taskRun.DeepCopy() - resources.SetupImageProcessing(processedTaskRun, config, buildv1alpha1.Image{ + resources.SetupImageProcessing(processedTaskRun, config, buildv1beta1.Image{ Image: "some-registry/some-namespace/some-image", - }, buildv1alpha1.Image{}) + }, buildv1beta1.Image{}) }) It("does not add the image-processing step", func() { @@ -52,12 +50,12 @@ var _ = Describe("Image Processing overrides", func() { Context("for a build with a label in the output", func() { BeforeEach(func() { processedTaskRun = taskRun.DeepCopy() - resources.SetupImageProcessing(processedTaskRun, config, buildv1alpha1.Image{ + resources.SetupImageProcessing(processedTaskRun, config, buildv1beta1.Image{ Image: "some-registry/some-namespace/some-image", Labels: map[string]string{ "aKey": "aLabel", }, - }, buildv1alpha1.Image{}) + }, buildv1beta1.Image{}) }) It("adds the image-processing step", func() { @@ -103,12 +101,12 @@ var _ = Describe("Image Processing overrides", func() { Context("for a build with label and annotation in the output", func() { BeforeEach(func() { processedTaskRun = taskRun.DeepCopy() - resources.SetupImageProcessing(processedTaskRun, config, buildv1alpha1.Image{ + resources.SetupImageProcessing(processedTaskRun, config, buildv1beta1.Image{ Image: "some-registry/some-namespace/some-image", Labels: map[string]string{ "a-label": "a-value", }, - }, buildv1alpha1.Image{ + }, buildv1beta1.Image{ Annotations: map[string]string{ "an-annotation": "some-value", }, @@ -151,9 +149,9 @@ var _ = Describe("Image Processing overrides", func() { Context("for a build without labels and annotation in the output", func() { BeforeEach(func() { processedTaskRun = taskRun.DeepCopy() - resources.SetupImageProcessing(processedTaskRun, config, buildv1alpha1.Image{ + resources.SetupImageProcessing(processedTaskRun, config, buildv1beta1.Image{ Image: "some-registry/some-namespace/some-image", - }, buildv1alpha1.Image{}) + }, buildv1beta1.Image{}) }) It("adds the output-directory parameter", func() { @@ -189,12 +187,11 @@ var _ = Describe("Image Processing overrides", func() { Context("for a build with an output with a secret", func() { BeforeEach(func() { processedTaskRun = taskRun.DeepCopy() - resources.SetupImageProcessing(processedTaskRun, config, buildv1alpha1.Image{ - Image: "some-registry/some-namespace/some-image", - Credentials: &corev1.LocalObjectReference{ - Name: "some-secret", - }, - }, buildv1alpha1.Image{}) + someSecret := "some-secret" + resources.SetupImageProcessing(processedTaskRun, config, buildv1beta1.Image{ + Image: "some-registry/some-namespace/some-image", + PushSecret: &someSecret, + }, buildv1beta1.Image{}) }) It("adds the output-directory parameter", func() { diff --git a/pkg/reconciler/buildrun/resources/params.go b/pkg/reconciler/buildrun/resources/params.go index 3e5b9f8205..16c79c2dbf 100644 --- a/pkg/reconciler/buildrun/resources/params.go +++ b/pkg/reconciler/buildrun/resources/params.go @@ -12,7 +12,7 @@ import ( corev1 "k8s.io/api/core/v1" - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" ) @@ -31,7 +31,7 @@ var ( // OverrideParams allows to override an existing list of parameters with a second list, // as long as their entry names matches -func OverrideParams(originalParams []buildv1alpha1.ParamValue, overrideParams []buildv1alpha1.ParamValue) []buildv1alpha1.ParamValue { +func OverrideParams(originalParams []buildv1beta1.ParamValue, overrideParams []buildv1beta1.ParamValue) []buildv1beta1.ParamValue { if len(overrideParams) == 0 { return originalParams } @@ -41,7 +41,7 @@ func OverrideParams(originalParams []buildv1alpha1.ParamValue, overrideParams [] } // Build a map from originalParams - originalMap := make(map[string]buildv1alpha1.ParamValue) + originalMap := make(map[string]buildv1beta1.ParamValue) for _, p := range originalParams { originalMap[p.Name] = p } @@ -53,7 +53,7 @@ func OverrideParams(originalParams []buildv1alpha1.ParamValue, overrideParams [] } // drop results on a slice and return - paramsList := []buildv1alpha1.ParamValue{} + paramsList := []buildv1beta1.ParamValue{} for k := range originalMap { paramsList = append(paramsList, originalMap[k]) @@ -68,7 +68,7 @@ func IsSystemReservedParameter(param string) bool { } // FindParameterByName returns the first entry in a Parameter array with a specified name, or nil -func FindParameterByName(parameters []buildv1alpha1.Parameter, name string) *buildv1alpha1.Parameter { +func FindParameterByName(parameters []buildv1beta1.Parameter, name string) *buildv1beta1.Parameter { for _, candidate := range parameters { if candidate.Name == name { return &candidate @@ -79,7 +79,7 @@ func FindParameterByName(parameters []buildv1alpha1.Parameter, name string) *bui } // FindParamValueByName returns the first entry in a ParamValue array with a specified name, or nil -func FindParamValueByName(paramValues []buildv1alpha1.ParamValue, name string) *buildv1alpha1.ParamValue { +func FindParamValueByName(paramValues []buildv1beta1.ParamValue, name string) *buildv1beta1.ParamValue { for _, candidate := range paramValues { if candidate.Name == name { return &candidate @@ -90,7 +90,7 @@ func FindParamValueByName(paramValues []buildv1alpha1.ParamValue, name string) * } // HandleTaskRunParam makes the necessary changes to a TaskRun for a parameter -func HandleTaskRunParam(taskRun *pipelineapi.TaskRun, parameterDefinition *buildv1alpha1.Parameter, paramValue buildv1alpha1.ParamValue) error { +func HandleTaskRunParam(taskRun *pipelineapi.TaskRun, parameterDefinition *buildv1beta1.Parameter, paramValue buildv1beta1.ParamValue) error { taskRunParam := pipelineapi.Param{ Name: paramValue.Name, Value: pipelineapi.ParamValue{}, @@ -99,7 +99,7 @@ func HandleTaskRunParam(taskRun *pipelineapi.TaskRun, parameterDefinition *build switch parameterDefinition.Type { case "": // string is default fallthrough - case buildv1alpha1.ParameterTypeString: + case buildv1beta1.ParameterTypeString: taskRunParam.Value.Type = pipelineapi.ParamTypeString switch { @@ -145,7 +145,7 @@ func HandleTaskRunParam(taskRun *pipelineapi.TaskRun, parameterDefinition *build } - case buildv1alpha1.ParameterTypeArray: + case buildv1beta1.ParameterTypeArray: taskRunParam.Value.Type = pipelineapi.ParamTypeArray switch { diff --git a/pkg/reconciler/buildrun/resources/params_test.go b/pkg/reconciler/buildrun/resources/params_test.go index b42bc50606..3e95fb9d65 100644 --- a/pkg/reconciler/buildrun/resources/params_test.go +++ b/pkg/reconciler/buildrun/resources/params_test.go @@ -14,59 +14,59 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/utils/pointer" - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" ) var _ = Describe("Params overrides", func() { DescribeTable("original params can be overridden", - func(buildParams []buildv1alpha1.ParamValue, buildRunParams []buildv1alpha1.ParamValue, expected types.GomegaMatcher) { + func(buildParams []buildv1beta1.ParamValue, buildRunParams []buildv1beta1.ParamValue, expected types.GomegaMatcher) { Expect(OverrideParams(buildParams, buildRunParams)).To(expected) }, Entry("override a single parameter", - []buildv1alpha1.ParamValue{ - {Name: "a", SingleValue: &buildv1alpha1.SingleValue{ + []buildv1beta1.ParamValue{ + {Name: "a", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("2"), }}, - }, []buildv1alpha1.ParamValue{ - {Name: "a", SingleValue: &buildv1alpha1.SingleValue{ + }, []buildv1beta1.ParamValue{ + {Name: "a", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("3"), }}, - }, ContainElements([]buildv1alpha1.ParamValue{ - {Name: "a", SingleValue: &buildv1alpha1.SingleValue{ + }, ContainElements([]buildv1beta1.ParamValue{ + {Name: "a", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("3"), }}, })), Entry("override two parameters", - []buildv1alpha1.ParamValue{ - {Name: "a", SingleValue: &buildv1alpha1.SingleValue{ + []buildv1beta1.ParamValue{ + {Name: "a", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("2"), }}, - {Name: "b", SingleValue: &buildv1alpha1.SingleValue{ - SecretValue: &buildv1alpha1.ObjectKeyRef{ + {Name: "b", SingleValue: &buildv1beta1.SingleValue{ + SecretValue: &buildv1beta1.ObjectKeyRef{ Name: "a-secret", Key: "a-key", }, }}, - }, []buildv1alpha1.ParamValue{ - {Name: "a", SingleValue: &buildv1alpha1.SingleValue{ + }, []buildv1beta1.ParamValue{ + {Name: "a", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("3"), }}, - {Name: "b", SingleValue: &buildv1alpha1.SingleValue{ - ConfigMapValue: &buildv1alpha1.ObjectKeyRef{ + {Name: "b", SingleValue: &buildv1beta1.SingleValue{ + ConfigMapValue: &buildv1beta1.ObjectKeyRef{ Name: "a-config-map", Key: "a-cm-key", }, }}, - }, ContainElements([]buildv1alpha1.ParamValue{ - {Name: "a", SingleValue: &buildv1alpha1.SingleValue{ + }, ContainElements([]buildv1beta1.ParamValue{ + {Name: "a", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("3"), }}, - {Name: "b", SingleValue: &buildv1alpha1.SingleValue{ - ConfigMapValue: &buildv1alpha1.ObjectKeyRef{ + {Name: "b", SingleValue: &buildv1beta1.SingleValue{ + ConfigMapValue: &buildv1beta1.ObjectKeyRef{ Name: "a-config-map", Key: "a-cm-key", }, @@ -74,116 +74,116 @@ var _ = Describe("Params overrides", func() { })), Entry("override multiple parameters", - []buildv1alpha1.ParamValue{ - {Name: "a", SingleValue: &buildv1alpha1.SingleValue{ + []buildv1beta1.ParamValue{ + {Name: "a", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("2"), }}, - {Name: "b", SingleValue: &buildv1alpha1.SingleValue{ + {Name: "b", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("2"), }}, - {Name: "c", SingleValue: &buildv1alpha1.SingleValue{ + {Name: "c", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("2"), }}, - }, []buildv1alpha1.ParamValue{ - {Name: "a", SingleValue: &buildv1alpha1.SingleValue{ + }, []buildv1beta1.ParamValue{ + {Name: "a", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("6"), }}, - {Name: "c", SingleValue: &buildv1alpha1.SingleValue{ + {Name: "c", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("6"), }}, - }, ContainElements([]buildv1alpha1.ParamValue{ - {Name: "a", SingleValue: &buildv1alpha1.SingleValue{ + }, ContainElements([]buildv1beta1.ParamValue{ + {Name: "a", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("6"), }}, - {Name: "b", SingleValue: &buildv1alpha1.SingleValue{ + {Name: "b", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("2"), }}, - {Name: "c", SingleValue: &buildv1alpha1.SingleValue{ + {Name: "c", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("6"), }}, })), Entry("dont override when second list is empty", - []buildv1alpha1.ParamValue{ - {Name: "t", SingleValue: &buildv1alpha1.SingleValue{ + []buildv1beta1.ParamValue{ + {Name: "t", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("2"), }}, - {Name: "z", SingleValue: &buildv1alpha1.SingleValue{ + {Name: "z", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("2"), }}, - {Name: "g", SingleValue: &buildv1alpha1.SingleValue{ + {Name: "g", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("2"), }}, }, - []buildv1alpha1.ParamValue{ + []buildv1beta1.ParamValue{ // no overrides }, - ContainElements([]buildv1alpha1.ParamValue{ - {Name: "t", SingleValue: &buildv1alpha1.SingleValue{ + ContainElements([]buildv1beta1.ParamValue{ + {Name: "t", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("2"), }}, - {Name: "z", SingleValue: &buildv1alpha1.SingleValue{ + {Name: "z", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("2"), }}, - {Name: "g", SingleValue: &buildv1alpha1.SingleValue{ + {Name: "g", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("2"), }}, })), Entry("override when first list is empty but not the second list", - []buildv1alpha1.ParamValue{ + []buildv1beta1.ParamValue{ // no original values - }, []buildv1alpha1.ParamValue{ - {Name: "a", SingleValue: &buildv1alpha1.SingleValue{ + }, []buildv1beta1.ParamValue{ + {Name: "a", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("6"), }}, - {Name: "c", SingleValue: &buildv1alpha1.SingleValue{ + {Name: "c", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("6"), }}, - }, ContainElements([]buildv1alpha1.ParamValue{ - {Name: "a", SingleValue: &buildv1alpha1.SingleValue{ + }, ContainElements([]buildv1beta1.ParamValue{ + {Name: "a", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("6"), }}, - {Name: "c", SingleValue: &buildv1alpha1.SingleValue{ + {Name: "c", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("6"), }}, })), Entry("override multiple parameters if the match and add them if not present in first list", - []buildv1alpha1.ParamValue{ - {Name: "a", SingleValue: &buildv1alpha1.SingleValue{ + []buildv1beta1.ParamValue{ + {Name: "a", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("2"), }}, - }, []buildv1alpha1.ParamValue{ - {Name: "a", SingleValue: &buildv1alpha1.SingleValue{ + }, []buildv1beta1.ParamValue{ + {Name: "a", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("22"), }}, - {Name: "b", SingleValue: &buildv1alpha1.SingleValue{ + {Name: "b", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("20"), }}, - {Name: "c", SingleValue: &buildv1alpha1.SingleValue{ + {Name: "c", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("10"), }}, - {Name: "d", SingleValue: &buildv1alpha1.SingleValue{ + {Name: "d", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("8"), }}, - {Name: "e", SingleValue: &buildv1alpha1.SingleValue{ + {Name: "e", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("4"), }}, - }, ContainElements([]buildv1alpha1.ParamValue{ - {Name: "a", SingleValue: &buildv1alpha1.SingleValue{ + }, ContainElements([]buildv1beta1.ParamValue{ + {Name: "a", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("22"), }}, - {Name: "b", SingleValue: &buildv1alpha1.SingleValue{ + {Name: "b", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("20"), }}, - {Name: "c", SingleValue: &buildv1alpha1.SingleValue{ + {Name: "c", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("10"), }}, - {Name: "d", SingleValue: &buildv1alpha1.SingleValue{ + {Name: "d", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("8"), }}, - {Name: "e", SingleValue: &buildv1alpha1.SingleValue{ + {Name: "e", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("4"), }}, })), @@ -211,7 +211,7 @@ var _ = Describe("FindParameterByName", func() { Context("For a list of three parameters", func() { - parameters := []buildv1alpha1.Parameter{{ + parameters := []buildv1beta1.Parameter{{ Name: "some-parameter", Type: "string", }, { @@ -229,7 +229,7 @@ var _ = Describe("FindParameterByName", func() { It("returns the correct parameter with a matching name", func() { parameter := FindParameterByName(parameters, "another-parameter") Expect(parameter).ToNot(BeNil()) - Expect(parameter).To(BeEquivalentTo(&buildv1alpha1.Parameter{ + Expect(parameter).To(BeEquivalentTo(&buildv1beta1.Parameter{ Name: "another-parameter", Type: "array", })) @@ -241,19 +241,19 @@ var _ = Describe("FindParamValueByName", func() { Context("For a list of three parameter values", func() { - paramValues := []buildv1alpha1.ParamValue{{ + paramValues := []buildv1beta1.ParamValue{{ Name: "some-parameter", - SingleValue: &buildv1alpha1.SingleValue{ + SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("some-value"), }, }, { Name: "another-parameter", - Values: []buildv1alpha1.SingleValue{ + Values: []buildv1beta1.SingleValue{ { Value: pointer.String("item"), }, { - ConfigMapValue: &buildv1alpha1.ObjectKeyRef{ + ConfigMapValue: &buildv1beta1.ObjectKeyRef{ Name: "a-configmap", Key: "a-key", }, @@ -261,7 +261,7 @@ var _ = Describe("FindParamValueByName", func() { }, }, { Name: "last-parameter", - SingleValue: &buildv1alpha1.SingleValue{ + SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("last-value"), }, }} @@ -273,14 +273,14 @@ var _ = Describe("FindParamValueByName", func() { It("returns the correct parameter with a matching name", func() { parameter := FindParamValueByName(paramValues, "another-parameter") Expect(parameter).ToNot(BeNil()) - Expect(parameter).To(BeEquivalentTo(&buildv1alpha1.ParamValue{ + Expect(parameter).To(BeEquivalentTo(&buildv1beta1.ParamValue{ Name: "another-parameter", - Values: []buildv1alpha1.SingleValue{ + Values: []buildv1beta1.SingleValue{ { Value: pointer.String("item"), }, { - ConfigMapValue: &buildv1alpha1.ObjectKeyRef{ + ConfigMapValue: &buildv1beta1.ObjectKeyRef{ Name: "a-configmap", Key: "a-key", }, @@ -374,15 +374,15 @@ var _ = Describe("HandleTaskRunParam", func() { Context("for a string parameter", func() { - parameterDefinition := &buildv1alpha1.Parameter{ + parameterDefinition := &buildv1beta1.Parameter{ Name: "string-parameter", - Type: buildv1alpha1.ParameterTypeString, + Type: buildv1beta1.ParameterTypeString, } It("adds a simple value", func() { - err := HandleTaskRunParam(taskRun, parameterDefinition, buildv1alpha1.ParamValue{ + err := HandleTaskRunParam(taskRun, parameterDefinition, buildv1beta1.ParamValue{ Name: "string-parameter", - SingleValue: &buildv1alpha1.SingleValue{ + SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("My value"), }, }) @@ -400,10 +400,10 @@ var _ = Describe("HandleTaskRunParam", func() { }) It("adds a configmap value without a format", func() { - err := HandleTaskRunParam(taskRun, parameterDefinition, buildv1alpha1.ParamValue{ + err := HandleTaskRunParam(taskRun, parameterDefinition, buildv1beta1.ParamValue{ Name: "string-parameter", - SingleValue: &buildv1alpha1.SingleValue{ - ConfigMapValue: &buildv1alpha1.ObjectKeyRef{ + SingleValue: &buildv1beta1.SingleValue{ + ConfigMapValue: &buildv1beta1.ObjectKeyRef{ Name: "config-map-name", Key: "my-key", }, @@ -443,10 +443,10 @@ var _ = Describe("HandleTaskRunParam", func() { }) It("adds a configmap value with a format", func() { - err := HandleTaskRunParam(taskRun, parameterDefinition, buildv1alpha1.ParamValue{ + err := HandleTaskRunParam(taskRun, parameterDefinition, buildv1beta1.ParamValue{ Name: "string-parameter", - SingleValue: &buildv1alpha1.SingleValue{ - ConfigMapValue: &buildv1alpha1.ObjectKeyRef{ + SingleValue: &buildv1beta1.SingleValue{ + ConfigMapValue: &buildv1beta1.ObjectKeyRef{ Name: "config-map-name", Key: "my-key", Format: pointer.String("The value from the config map is '${CONFIGMAP_VALUE}'."), @@ -487,10 +487,10 @@ var _ = Describe("HandleTaskRunParam", func() { }) It("adds a secret value without a format", func() { - err := HandleTaskRunParam(taskRun, parameterDefinition, buildv1alpha1.ParamValue{ + err := HandleTaskRunParam(taskRun, parameterDefinition, buildv1beta1.ParamValue{ Name: "string-parameter", - SingleValue: &buildv1alpha1.SingleValue{ - SecretValue: &buildv1alpha1.ObjectKeyRef{ + SingleValue: &buildv1beta1.SingleValue{ + SecretValue: &buildv1beta1.ObjectKeyRef{ Name: "secret-name", Key: "secret-key", }, @@ -530,10 +530,10 @@ var _ = Describe("HandleTaskRunParam", func() { }) It("adds a secret value with a format", func() { - err := HandleTaskRunParam(taskRun, parameterDefinition, buildv1alpha1.ParamValue{ + err := HandleTaskRunParam(taskRun, parameterDefinition, buildv1beta1.ParamValue{ Name: "string-parameter", - SingleValue: &buildv1alpha1.SingleValue{ - SecretValue: &buildv1alpha1.ObjectKeyRef{ + SingleValue: &buildv1beta1.SingleValue{ + SecretValue: &buildv1beta1.ObjectKeyRef{ Name: "secret-name", Key: "secret-key", Format: pointer.String("secret-value: ${SECRET_VALUE}"), @@ -576,15 +576,15 @@ var _ = Describe("HandleTaskRunParam", func() { Context("for an array parameter", func() { - parameterDefinition := &buildv1alpha1.Parameter{ + parameterDefinition := &buildv1beta1.Parameter{ Name: "array-parameter", - Type: buildv1alpha1.ParameterTypeArray, + Type: buildv1beta1.ParameterTypeArray, } It("adds simple values correctly", func() { - err := HandleTaskRunParam(taskRun, parameterDefinition, buildv1alpha1.ParamValue{ + err := HandleTaskRunParam(taskRun, parameterDefinition, buildv1beta1.ParamValue{ Name: "array-parameter", - Values: []buildv1alpha1.SingleValue{ + Values: []buildv1beta1.SingleValue{ { Value: pointer.String("first entry"), }, @@ -617,20 +617,20 @@ var _ = Describe("HandleTaskRunParam", func() { }) It("adds values from different sources correctly", func() { - err := HandleTaskRunParam(taskRun, parameterDefinition, buildv1alpha1.ParamValue{ + err := HandleTaskRunParam(taskRun, parameterDefinition, buildv1beta1.ParamValue{ Name: "array-parameter", - Values: []buildv1alpha1.SingleValue{ + Values: []buildv1beta1.SingleValue{ { Value: pointer.String("first entry"), }, { - SecretValue: &buildv1alpha1.ObjectKeyRef{ + SecretValue: &buildv1beta1.ObjectKeyRef{ Name: "secret-name", Key: "secret-key", }, }, { - SecretValue: &buildv1alpha1.ObjectKeyRef{ + SecretValue: &buildv1beta1.ObjectKeyRef{ Name: "secret-name", Key: "secret-key", Format: pointer.String("The secret value is ${SECRET_VALUE}"), diff --git a/pkg/reconciler/buildrun/resources/results.go b/pkg/reconciler/buildrun/resources/results.go index 61b31a9d3c..a801e4b243 100644 --- a/pkg/reconciler/buildrun/resources/results.go +++ b/pkg/reconciler/buildrun/resources/results.go @@ -9,7 +9,7 @@ import ( "fmt" "strconv" - build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/ctxlog" pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" diff --git a/pkg/reconciler/buildrun/resources/results_test.go b/pkg/reconciler/buildrun/resources/results_test.go index 5196d8da4b..fcba2b8dfc 100644 --- a/pkg/reconciler/buildrun/resources/results_test.go +++ b/pkg/reconciler/buildrun/resources/results_test.go @@ -10,9 +10,9 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/reconciler/buildrun/resources" - test "github.com/shipwright-io/build/test/v1alpha1_samples" + test "github.com/shipwright-io/build/test/v1beta1_samples" pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" "k8s.io/apimachinery/pkg/types" diff --git a/pkg/reconciler/buildrun/resources/service_accounts.go b/pkg/reconciler/buildrun/resources/service_accounts.go index 38cd815f3d..fcec898ad4 100644 --- a/pkg/reconciler/buildrun/resources/service_accounts.go +++ b/pkg/reconciler/buildrun/resources/service_accounts.go @@ -8,7 +8,7 @@ import ( "context" "fmt" - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/ctxlog" corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" @@ -30,17 +30,12 @@ const ( ) // GetGeneratedServiceAccountName returns the name of the generated service account for a build run -func GetGeneratedServiceAccountName(buildRun *buildv1alpha1.BuildRun) string { +func GetGeneratedServiceAccountName(buildRun *buildv1beta1.BuildRun) string { return buildRun.Name } -// IsGeneratedServiceAccountUsed checks if a build run uses a generated service account -func IsGeneratedServiceAccountUsed(buildRun *buildv1alpha1.BuildRun) bool { - return buildRun.Spec.ServiceAccount != nil && buildRun.Spec.ServiceAccount.Generate != nil && *buildRun.Spec.ServiceAccount.Generate -} - // GenerateSA generates a new service account on the fly -func GenerateSA(ctx context.Context, client client.Client, build *buildv1alpha1.Build, buildRun *buildv1alpha1.BuildRun) (serviceAccount *corev1.ServiceAccount, err error) { +func GenerateSA(ctx context.Context, client client.Client, build *buildv1beta1.Build, buildRun *buildv1beta1.BuildRun) (serviceAccount *corev1.ServiceAccount, err error) { serviceAccount = &corev1.ServiceAccount{} err = client.Get( ctx, @@ -60,9 +55,9 @@ func GenerateSA(ctx context.Context, client client.Client, build *buildv1alpha1. ObjectMeta: metav1.ObjectMeta{ Name: GetGeneratedServiceAccountName(buildRun), Namespace: buildRun.Namespace, - Labels: map[string]string{buildv1alpha1.LabelBuildRun: buildRun.Name}, + Labels: map[string]string{buildv1beta1.LabelBuildRun: buildRun.Name}, OwnerReferences: []metav1.OwnerReference{ - *metav1.NewControllerRef(buildRun, buildv1alpha1.SchemeGroupVersion.WithKind("BuildRun")), + *metav1.NewControllerRef(buildRun, buildv1beta1.SchemeGroupVersion.WithKind("BuildRun")), }, }, AutomountServiceAccountToken: pointer.Bool(false), @@ -87,11 +82,7 @@ func GenerateSA(ctx context.Context, client client.Client, build *buildv1alpha1. // DeleteServiceAccount deletes the service account of a completed BuildRun if the service account // was generated -func DeleteServiceAccount(ctx context.Context, client client.Client, completedBuildRun *buildv1alpha1.BuildRun) error { - if !IsGeneratedServiceAccountUsed(completedBuildRun) { - return nil - } - +func DeleteServiceAccount(ctx context.Context, client client.Client, completedBuildRun *buildv1beta1.BuildRun) error { serviceAccount := &corev1.ServiceAccount{} serviceAccount.Name = GetGeneratedServiceAccountName(completedBuildRun) serviceAccount.Namespace = completedBuildRun.Namespace @@ -106,7 +97,7 @@ func DeleteServiceAccount(ctx context.Context, client client.Client, completedBu // getDefaultNamespaceSA retrieves a pipeline or default sa per namespace. This is used when users do not specify a service account // to use on BuildRuns -func getDefaultNamespaceSA(ctx context.Context, client client.Client, buildRun *buildv1alpha1.BuildRun) (*corev1.ServiceAccount, error) { +func getDefaultNamespaceSA(ctx context.Context, client client.Client, buildRun *buildv1beta1.BuildRun) (*corev1.ServiceAccount, error) { // Note: If the default SA is not in the namespace, the controller will be always reconciling until if finds it or until the // BuildRun gets deleted serviceAccount := &corev1.ServiceAccount{} @@ -127,14 +118,9 @@ func getDefaultNamespaceSA(ctx context.Context, client client.Client, buildRun * // RetrieveServiceAccount provides either a default sa with a referenced secret or it will generate a new sa on the fly. // When not using the generate feature, it will modify and return the default sa from a k8s namespace, which is "default" // or the default sa inside an openshift namespace, which is "pipeline". -func RetrieveServiceAccount(ctx context.Context, client client.Client, build *buildv1alpha1.Build, buildRun *buildv1alpha1.BuildRun) (serviceAccount *corev1.ServiceAccount, err error) { - // generate or retrieve an existing autogenerated sa - if IsGeneratedServiceAccountUsed(buildRun) { - return GenerateSA(ctx, client, build, buildRun) - } - - if buildRun.Spec.ServiceAccount != nil && buildRun.Spec.ServiceAccount.Name != nil { - serviceAccountName := *buildRun.Spec.ServiceAccount.Name +func RetrieveServiceAccount(ctx context.Context, client client.Client, build *buildv1beta1.Build, buildRun *buildv1beta1.BuildRun) (serviceAccount *corev1.ServiceAccount, err error) { + if buildRun.Spec.ServiceAccount != nil && buildRun.Spec.ServiceAccount != nil { + serviceAccountName := *buildRun.Spec.ServiceAccount // here we might need to update Status Conditions and Fail the BR serviceAccount = &corev1.ServiceAccount{} diff --git a/pkg/reconciler/buildrun/resources/service_accounts_test.go b/pkg/reconciler/buildrun/resources/service_accounts_test.go index 2e36bdfefb..9842590ddf 100644 --- a/pkg/reconciler/buildrun/resources/service_accounts_test.go +++ b/pkg/reconciler/buildrun/resources/service_accounts_test.go @@ -11,9 +11,10 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/controller/fakes" "github.com/shipwright-io/build/pkg/reconciler/buildrun/resources" - test "github.com/shipwright-io/build/test/v1alpha1_samples" + test "github.com/shipwright-io/build/test/v1beta1_samples" corev1 "k8s.io/api/core/v1" k8serrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime/schema" @@ -26,7 +27,7 @@ var _ = Describe("Operating service accounts", func() { client *fakes.FakeClient ctl test.Catalog buildName, buildRunName string - buildRunSample *buildv1alpha1.BuildRun + buildRunSample *buildv1beta1.BuildRun ) BeforeEach(func() { @@ -147,7 +148,7 @@ var _ = Describe("Operating service accounts", func() { case *corev1.ServiceAccount: Expect(len(object.Secrets)).To(Equal(1)) Expect(len(object.OwnerReferences)).To(Equal(1)) - Expect(object.Labels[buildv1alpha1.LabelBuildRun]).To(Equal(buildRunName)) + Expect(object.Labels[buildv1beta1.LabelBuildRun]).To(Equal(buildRunName)) Expect(object.Secrets[0].Name).To(Equal("foosecret")) Expect(object.AutomountServiceAccountToken).To(Equal(&mountTokenVal)) } diff --git a/pkg/reconciler/buildrun/resources/sources.go b/pkg/reconciler/buildrun/resources/sources.go index 37e94a7c60..000ce4914e 100644 --- a/pkg/reconciler/buildrun/resources/sources.go +++ b/pkg/reconciler/buildrun/resources/sources.go @@ -5,7 +5,7 @@ package resources import ( - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/config" "github.com/shipwright-io/build/pkg/reconciler/buildrun/resources/sources" @@ -17,16 +17,16 @@ const defaultSourceName = "default" // isLocalCopyBuildSource appends all "Sources" in a single slice, and if any entry is typed // "LocalCopy" it returns first LocalCopy typed BuildSource found, or nil. func isLocalCopyBuildSource( - build *buildv1alpha1.Build, - buildRun *buildv1alpha1.BuildRun, -) *buildv1alpha1.BuildSource { - sources := []buildv1alpha1.BuildSource{} + build *buildv1beta1.Build, + buildRun *buildv1beta1.BuildRun, +) *buildv1beta1.BuildSource { + sources := []buildv1beta1.BuildSource{} sources = append(sources, build.Spec.Sources...) sources = append(sources, buildRun.Spec.Sources...) for _, source := range sources { - if source.Type == buildv1alpha1.LocalCopy { + if source.Type == buildv1beta1.LocalCopy { return &source } } @@ -38,8 +38,8 @@ func isLocalCopyBuildSource( func AmendTaskSpecWithSources( cfg *config.Config, taskSpec *pipelineapi.TaskSpec, - build *buildv1alpha1.Build, - buildRun *buildv1alpha1.BuildRun, + build *buildv1beta1.Build, + buildRun *buildv1beta1.BuildRun, ) { if localCopy := isLocalCopyBuildSource(build, buildRun); localCopy != nil { sources.AppendLocalCopyStep(cfg, taskSpec, localCopy.Timeout) @@ -56,13 +56,13 @@ func AmendTaskSpecWithSources( // inspecting .spec.sources looking for "http" typed sources to generate the TaskSpec items // in order to handle remote artifacts for _, source := range build.Spec.Sources { - if source.Type == buildv1alpha1.HTTP { + if source.Type == buildv1beta1.HTTP { sources.AppendHTTPStep(cfg, taskSpec, source) } } } -func updateBuildRunStatusWithSourceResult(buildrun *buildv1alpha1.BuildRun, results []pipelineapi.TaskRunResult) { +func updateBuildRunStatusWithSourceResult(buildrun *buildv1beta1.BuildRun, results []pipelineapi.TaskRunResult) { buildSpec := buildrun.Status.BuildSpec switch { diff --git a/pkg/reconciler/buildrun/resources/steps/security_context.go b/pkg/reconciler/buildrun/resources/steps/security_context.go index 4cc0af4302..20b5eab3cb 100644 --- a/pkg/reconciler/buildrun/resources/steps/security_context.go +++ b/pkg/reconciler/buildrun/resources/steps/security_context.go @@ -7,7 +7,7 @@ package steps import ( "fmt" - buildapi "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1" pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" corev1 "k8s.io/api/core/v1" "k8s.io/utils/pointer" @@ -28,7 +28,7 @@ const ( // UpdateSecurityContext updates the security context of a step based on the build strategy steps. If all build strategy steps run as the same user and group, // then the step is configured to also run as this user and group. This ensures that the supporting steps run as the same user as the build strategy and file // permissions created by source steps match the user that runs the build strategy steps. -func UpdateSecurityContext(taskSpec *pipelineapi.TaskSpec, taskRunAnnotations map[string]string, buildStrategySteps []buildapi.BuildStep, buildStrategySecurityContext *buildapi.BuildStrategySecurityContext) { +func UpdateSecurityContext(taskSpec *pipelineapi.TaskSpec, taskRunAnnotations map[string]string, buildStrategySteps []buildapi.Step, buildStrategySecurityContext *buildapi.BuildStrategySecurityContext) { if buildStrategySecurityContext == nil { return } diff --git a/pkg/reconciler/buildrun/resources/strategies.go b/pkg/reconciler/buildrun/resources/strategies.go index 536b031467..8d1ae1fbdc 100644 --- a/pkg/reconciler/buildrun/resources/strategies.go +++ b/pkg/reconciler/buildrun/resources/strategies.go @@ -7,7 +7,7 @@ package resources import ( "context" - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "sigs.k8s.io/controller-runtime/pkg/client" "github.com/shipwright-io/build/pkg/ctxlog" @@ -15,8 +15,8 @@ import ( ) // RetrieveBuildStrategy returns a namespace scoped strategy -func RetrieveBuildStrategy(ctx context.Context, client client.Client, build *buildv1alpha1.Build) (*buildv1alpha1.BuildStrategy, error) { - buildStrategyInstance := &buildv1alpha1.BuildStrategy{} +func RetrieveBuildStrategy(ctx context.Context, client client.Client, build *buildv1beta1.Build) (*buildv1beta1.BuildStrategy, error) { + buildStrategyInstance := &buildv1beta1.BuildStrategy{} ctxlog.Debug(ctx, "retrieving BuildStrategy", namespace, build.Namespace, name, build.Name) @@ -25,8 +25,8 @@ func RetrieveBuildStrategy(ctx context.Context, client client.Client, build *bui } // RetrieveClusterBuildStrategy returns a cluster scoped strategy -func RetrieveClusterBuildStrategy(ctx context.Context, client client.Client, build *buildv1alpha1.Build) (*buildv1alpha1.ClusterBuildStrategy, error) { - clusterBuildStrategyInstance := &buildv1alpha1.ClusterBuildStrategy{} +func RetrieveClusterBuildStrategy(ctx context.Context, client client.Client, build *buildv1beta1.Build) (*buildv1beta1.ClusterBuildStrategy, error) { + clusterBuildStrategyInstance := &buildv1beta1.ClusterBuildStrategy{} ctxlog.Debug(ctx, "retrieving ClusterBuildStrategy", namespace, build.Namespace, name, build.Name) diff --git a/pkg/reconciler/buildrun/resources/strategies_test.go b/pkg/reconciler/buildrun/resources/strategies_test.go index 8e6a5f5f25..14d64132bc 100644 --- a/pkg/reconciler/buildrun/resources/strategies_test.go +++ b/pkg/reconciler/buildrun/resources/strategies_test.go @@ -9,10 +9,10 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/controller/fakes" "github.com/shipwright-io/build/pkg/reconciler/buildrun/resources" - test "github.com/shipwright-io/build/test/v1alpha1_samples" + test "github.com/shipwright-io/build/test/v1beta1_samples" k8serrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/types" @@ -33,7 +33,7 @@ var _ = Describe("Operating Build strategies", func() { // stub a GET API call with a cluster strategy getClientStub := func(_ context.Context, nn types.NamespacedName, object crc.Object, _ ...crc.GetOption) error { switch object := object.(type) { - case *buildv1alpha1.ClusterBuildStrategy: + case *buildv1beta1.ClusterBuildStrategy: ctl.DefaultClusterBuildStrategy().DeepCopyInto(object) return nil } @@ -51,7 +51,7 @@ var _ = Describe("Operating Build strategies", func() { // stub a GET API call with a namespace strategy getClientStub := func(_ context.Context, nn types.NamespacedName, object crc.Object, _ ...crc.GetOption) error { switch object := object.(type) { - case *buildv1alpha1.BuildStrategy: + case *buildv1beta1.BuildStrategy: ctl.DefaultNamespacedBuildStrategy().DeepCopyInto(object) return nil } diff --git a/pkg/reconciler/buildrun/resources/taskrun.go b/pkg/reconciler/buildrun/resources/taskrun.go index cf91c0a606..046001f03c 100644 --- a/pkg/reconciler/buildrun/resources/taskrun.go +++ b/pkg/reconciler/buildrun/resources/taskrun.go @@ -13,7 +13,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/config" "github.com/shipwright-io/build/pkg/env" "github.com/shipwright-io/build/pkg/reconciler/buildrun/resources/steps" @@ -62,11 +62,11 @@ func getStringTransformations(fullText string) string { // GenerateTaskSpec creates Tekton TaskRun spec to be used for a build run func GenerateTaskSpec( cfg *config.Config, - build *buildv1alpha1.Build, - buildRun *buildv1alpha1.BuildRun, - buildSteps []buildv1alpha1.BuildStep, - parameterDefinitions []buildv1alpha1.Parameter, - buildStrategyVolumes []buildv1alpha1.BuildStrategyVolume, + build *buildv1beta1.Build, + buildRun *buildv1beta1.BuildRun, + buildSteps []buildv1beta1.Step, + parameterDefinitions []buildv1beta1.Parameter, + buildStrategyVolumes []buildv1beta1.BuildStrategyVolume, ) (*pipelineapi.TaskSpec, error) { generatedTaskSpec := pipelineapi.TaskSpec{ Params: []pipelineapi.ParamSpec{ @@ -119,17 +119,18 @@ func GenerateTaskSpec( generatedTaskSpec.Results = append(getTaskSpecResults(), getFailureDetailsTaskSpecResults()...) - if build.Spec.Builder != nil { - InputBuilder := pipelineapi.ParamSpec{ - Description: "Image containing the build tools/logic", - Name: inputParamBuilder, - Default: &pipelineapi.ParamValue{ - Type: pipelineapi.ParamTypeString, - StringVal: build.Spec.Builder.Image, - }, - } - generatedTaskSpec.Params = append(generatedTaskSpec.Params, InputBuilder) - } + //TODO: double check this + // if build.Spec.Builder != nil { + // InputBuilder := pipelineapi.ParamSpec{ + // Description: "Image containing the build tools/logic", + // Name: inputParamBuilder, + // Default: &pipelineapi.ParamValue{ + // Type: pipelineapi.ParamTypeString, + // StringVal: build.Spec.Builder.Image, + // }, + // } + // generatedTaskSpec.Params = append(generatedTaskSpec.Params, InputBuilder) + // } // define the results, steps and volumes for sources, or alternatively, wait for user upload AmendTaskSpecWithSources(cfg, &generatedTaskSpec, build, buildRun) @@ -145,7 +146,7 @@ func GenerateTaskSpec( switch parameterDefinition.Type { case "": // string is default fallthrough - case buildv1alpha1.ParameterTypeString: + case buildv1beta1.ParameterTypeString: param.Type = pipelineapi.ParamTypeString if parameterDefinition.Default != nil { param.Default = &pipelineapi.ParamValue{ @@ -154,7 +155,7 @@ func GenerateTaskSpec( } } - case buildv1alpha1.ParameterTypeArray: + case buildv1beta1.ParameterTypeArray: param.Type = pipelineapi.ParamTypeArray if parameterDefinition.Defaults != nil { param.Default = &pipelineapi.ParamValue{ @@ -239,10 +240,10 @@ func GenerateTaskSpec( // GenerateTaskRun creates a Tekton TaskRun to be used for a build run func GenerateTaskRun( cfg *config.Config, - build *buildv1alpha1.Build, - buildRun *buildv1alpha1.BuildRun, + build *buildv1beta1.Build, + buildRun *buildv1beta1.BuildRun, serviceAccountName string, - strategy buildv1alpha1.BuilderStrategy, + strategy buildv1beta1.BuilderStrategy, ) (*pipelineapi.TaskRun, error) { // retrieve expected imageURL form build or buildRun @@ -274,14 +275,14 @@ func GenerateTaskRun( // Add BuildRun name reference to the TaskRun labels taskRunLabels := map[string]string{ - buildv1alpha1.LabelBuildRun: buildRun.Name, - buildv1alpha1.LabelBuildRunGeneration: strconv.FormatInt(buildRun.Generation, 10), + buildv1beta1.LabelBuildRun: buildRun.Name, + buildv1beta1.LabelBuildRunGeneration: strconv.FormatInt(buildRun.Generation, 10), } // Add Build name reference unless it is an embedded Build (empty build name) if build.Name != "" { - taskRunLabels[buildv1alpha1.LabelBuild] = build.Name - taskRunLabels[buildv1alpha1.LabelBuildGeneration] = strconv.FormatInt(build.Generation, 10) + taskRunLabels[buildv1beta1.LabelBuild] = build.Name + taskRunLabels[buildv1beta1.LabelBuildGeneration] = strconv.FormatInt(build.Generation, 10) } expectedTaskRun := &pipelineapi.TaskRun{ @@ -349,24 +350,7 @@ func GenerateTaskRun( }, }, } - if build.Spec.Builder != nil { - params = append(params, pipelineapi.Param{ - Name: inputParamBuilder, - Value: pipelineapi.ParamValue{ - Type: pipelineapi.ParamTypeString, - StringVal: build.Spec.Builder.Image, - }, - }) - } - if build.Spec.Dockerfile != nil && *build.Spec.Dockerfile != "" { - params = append(params, pipelineapi.Param{ - Name: inputParamDockerfile, - Value: pipelineapi.ParamValue{ - Type: pipelineapi.ParamTypeString, - StringVal: *build.Spec.Dockerfile, - }, - }) - } + if build.Spec.Source.ContextDir != nil { params = append(params, pipelineapi.Param{ Name: inputParamContextDir, @@ -415,14 +399,14 @@ func GenerateTaskRun( // and if the strategy is pushing the image by not using $(params.shp-output-directory) buildRunOutput := buildRun.Spec.Output if buildRunOutput == nil { - buildRunOutput = &buildv1alpha1.Image{} + buildRunOutput = &buildv1beta1.Image{} } SetupImageProcessing(expectedTaskRun, cfg, build.Spec.Output, *buildRunOutput) return expectedTaskRun, nil } -func effectiveTimeout(build *buildv1alpha1.Build, buildRun *buildv1alpha1.BuildRun) *metav1.Duration { +func effectiveTimeout(build *buildv1beta1.Build, buildRun *buildv1beta1.BuildRun) *metav1.Duration { if buildRun.Spec.Timeout != nil { return buildRun.Spec.Timeout @@ -437,13 +421,13 @@ func effectiveTimeout(build *buildv1alpha1.Build, buildRun *buildv1alpha1.BuildR // also, annotations using our own custom resource domains are filtered out because we have no annotations with a semantic for both TaskRun and Pod func isPropagatableAnnotation(key string) bool { return key != "kubectl.kubernetes.io/last-applied-configuration" && - !strings.HasPrefix(key, buildv1alpha1.ClusterBuildStrategyDomain+"/") && - !strings.HasPrefix(key, buildv1alpha1.BuildStrategyDomain+"/") && - !strings.HasPrefix(key, buildv1alpha1.BuildDomain+"/") && - !strings.HasPrefix(key, buildv1alpha1.BuildRunDomain+"/") + !strings.HasPrefix(key, buildv1beta1.ClusterBuildStrategyDomain+"/") && + !strings.HasPrefix(key, buildv1beta1.BuildStrategyDomain+"/") && + !strings.HasPrefix(key, buildv1beta1.BuildDomain+"/") && + !strings.HasPrefix(key, buildv1beta1.BuildRunDomain+"/") } -func toVolumeMap(strategyVolumes []buildv1alpha1.BuildStrategyVolume) map[string]bool { +func toVolumeMap(strategyVolumes []buildv1beta1.BuildStrategyVolume) map[string]bool { res := make(map[string]bool) for _, v := range strategyVolumes { res[v.Name] = true diff --git a/pkg/reconciler/buildrun/resources/taskrun_test.go b/pkg/reconciler/buildrun/resources/taskrun_test.go index 3a4f21a5fd..4e6017ae36 100644 --- a/pkg/reconciler/buildrun/resources/taskrun_test.go +++ b/pkg/reconciler/buildrun/resources/taskrun_test.go @@ -18,24 +18,24 @@ import ( "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/config" "github.com/shipwright-io/build/pkg/env" "github.com/shipwright-io/build/pkg/reconciler/buildrun/resources" - utils "github.com/shipwright-io/build/test/utils/v1alpha1" - test "github.com/shipwright-io/build/test/v1alpha1_samples" + utils "github.com/shipwright-io/build/test/utils/v1beta1" + test "github.com/shipwright-io/build/test/v1beta1_samples" ) var _ = Describe("GenerateTaskrun", func() { var ( - build *buildv1alpha1.Build - buildWithEnvs *buildv1alpha1.Build - buildRun *buildv1alpha1.BuildRun - buildRunWithEnvs *buildv1alpha1.BuildRun - buildStrategy *buildv1alpha1.BuildStrategy + build *buildv1beta1.Build + buildWithEnvs *buildv1beta1.Build + buildRun *buildv1beta1.BuildRun + buildRunWithEnvs *buildv1beta1.BuildRun + buildStrategy *buildv1beta1.BuildStrategy buildStrategyStepNames map[string]struct{} - buildStrategyWithEnvs *buildv1alpha1.BuildStrategy - builderImage *buildv1alpha1.Image + buildStrategyWithEnvs *buildv1beta1.BuildStrategy + builderImage *buildv1beta1.Image dockerfile, buildpacks string ctl test.Catalog ) @@ -52,7 +52,7 @@ var _ = Describe("GenerateTaskrun", func() { err error ) BeforeEach(func() { - builderImage = &buildv1alpha1.Image{ + builderImage = &buildv1beta1.Image{ Image: "quay.io/builder/image", } }) @@ -67,7 +67,7 @@ var _ = Describe("GenerateTaskrun", func() { buildStrategy, err = ctl.LoadBuildStrategyFromBytes([]byte(test.MinimalBuildahBuildStrategy)) Expect(err).To(BeNil()) - buildStrategy.Spec.BuildSteps[0].ImagePullPolicy = "Always" + buildStrategy.Spec.Steps[0].ImagePullPolicy = "Always" expectedCommandOrArg = []string{ "bud", "--tag=$(params.shp-output-image)", fmt.Sprintf("--file=$(inputs.params.%s)", "DOCKERFILE"), "$(params.shp-source-context)", @@ -85,7 +85,7 @@ var _ = Describe("GenerateTaskrun", func() { Expect(got.Steps[0].Command[0]).To(Equal("/ko-app/git")) Expect(got.Steps[0].Args).To(Equal([]string{ "--url", - *build.Spec.Source.URL, + *&build.Spec.Source.GitSource.URL, "--target", "$(params.shp-source-root)", "--result-file-commit-sha", @@ -240,9 +240,9 @@ var _ = Describe("GenerateTaskrun", func() { buildStrategy, err = ctl.LoadBuildStrategyFromBytes([]byte(test.MinimalBuildahBuildStrategy)) Expect(err).To(BeNil()) - buildStrategy.Spec.BuildSteps[0].ImagePullPolicy = "Always" + buildStrategy.Spec.Steps[0].ImagePullPolicy = "Always" buildStrategyStepNames = make(map[string]struct{}) - for _, step := range buildStrategy.Spec.BuildSteps { + for _, step := range buildStrategy.Spec.Steps { buildStrategyStepNames[step.Name] = struct{}{} } @@ -255,7 +255,7 @@ var _ = Describe("GenerateTaskrun", func() { }) It("should contain env vars specified in Build in every BuildStrategy step", func() { - got, err = resources.GenerateTaskSpec(config.NewDefaultConfig(), buildWithEnvs, buildRun, buildStrategy.Spec.BuildSteps, []buildv1alpha1.Parameter{}, buildStrategy.GetVolumes()) + got, err = resources.GenerateTaskSpec(config.NewDefaultConfig(), buildWithEnvs, buildRun, buildStrategy.Spec.Steps, []buildv1beta1.Parameter{}, buildStrategy.GetVolumes()) Expect(err).To(BeNil()) combinedEnvs, err := env.MergeEnvVars(buildRun.Spec.Env, buildWithEnvs.Spec.Env, true) @@ -272,7 +272,7 @@ var _ = Describe("GenerateTaskrun", func() { }) It("should contain env vars specified in BuildRun in every step", func() { - got, err = resources.GenerateTaskSpec(config.NewDefaultConfig(), build, buildRunWithEnvs, buildStrategy.Spec.BuildSteps, []buildv1alpha1.Parameter{}, buildStrategy.GetVolumes()) + got, err = resources.GenerateTaskSpec(config.NewDefaultConfig(), build, buildRunWithEnvs, buildStrategy.Spec.Steps, []buildv1beta1.Parameter{}, buildStrategy.GetVolumes()) Expect(err).To(BeNil()) combinedEnvs, err := env.MergeEnvVars(buildRunWithEnvs.Spec.Env, build.Spec.Env, true) @@ -289,7 +289,7 @@ var _ = Describe("GenerateTaskrun", func() { }) It("should override Build env vars with BuildRun env vars in every step", func() { - got, err = resources.GenerateTaskSpec(config.NewDefaultConfig(), buildWithEnvs, buildRunWithEnvs, buildStrategy.Spec.BuildSteps, []buildv1alpha1.Parameter{}, buildStrategy.GetVolumes()) + got, err = resources.GenerateTaskSpec(config.NewDefaultConfig(), buildWithEnvs, buildRunWithEnvs, buildStrategy.Spec.Steps, []buildv1beta1.Parameter{}, buildStrategy.GetVolumes()) Expect(err).To(BeNil()) combinedEnvs, err := env.MergeEnvVars(buildRunWithEnvs.Spec.Env, buildWithEnvs.Spec.Env, true) @@ -307,7 +307,7 @@ var _ = Describe("GenerateTaskrun", func() { }) It("should fail attempting to override an env var in a BuildStrategy", func() { - got, err = resources.GenerateTaskSpec(config.NewDefaultConfig(), buildWithEnvs, buildRunWithEnvs, buildStrategyWithEnvs.Spec.BuildSteps, []buildv1alpha1.Parameter{}, buildStrategy.GetVolumes()) + got, err = resources.GenerateTaskSpec(config.NewDefaultConfig(), buildWithEnvs, buildRunWithEnvs, buildStrategyWithEnvs.Spec.Steps, []buildv1beta1.Parameter{}, buildStrategy.GetVolumes()) Expect(err).NotTo(BeNil()) Expect(err.Error()).To(Equal("error(s) occurred merging environment variables into BuildStrategy \"buildah\" steps: [environment variable \"MY_VAR_1\" already exists, environment variable \"MY_VAR_2\" already exists]")) }) @@ -323,14 +323,14 @@ var _ = Describe("GenerateTaskrun", func() { buildStrategy, err = ctl.LoadBuildStrategyFromBytes([]byte(test.MinimalBuildahBuildStrategy)) Expect(err).To(BeNil()) - buildStrategy.Spec.BuildSteps[0].ImagePullPolicy = "Always" + buildStrategy.Spec.Steps[0].ImagePullPolicy = "Always" expectedCommandOrArg = []string{ "bud", "--tag=$(params.shp-output-image)", fmt.Sprintf("--file=$(inputs.params.%s)", "DOCKERFILE"), "$(params.shp-source-context)", } JustBeforeEach(func() { - got, err = resources.GenerateTaskSpec(config.NewDefaultConfig(), build, buildRun, buildStrategy.Spec.BuildSteps, []buildv1alpha1.Parameter{}, buildStrategy.GetVolumes()) + got, err = resources.GenerateTaskSpec(config.NewDefaultConfig(), build, buildRun, buildStrategy.Spec.Steps, []buildv1beta1.Parameter{}, buildStrategy.GetVolumes()) Expect(err).To(BeNil()) }) @@ -364,14 +364,14 @@ var _ = Describe("GenerateTaskrun", func() { buildStrategy, err = ctl.LoadBuildStrategyFromBytes([]byte(test.MinimalBuildahBuildStrategy)) Expect(err).To(BeNil()) - buildStrategy.Spec.BuildSteps[0].ImagePullPolicy = "Always" + buildStrategy.Spec.Steps[0].ImagePullPolicy = "Always" expectedCommandOrArg = []string{ "bud", "--tag=$(params.shp-output-image)", fmt.Sprintf("--file=$(inputs.params.%s)", "DOCKERFILE"), "$(params.shp-source-context)", } JustBeforeEach(func() { - got, err = resources.GenerateTaskSpec(config.NewDefaultConfig(), build, buildRun, buildStrategy.Spec.BuildSteps, []buildv1alpha1.Parameter{}, buildStrategy.GetVolumes()) + got, err = resources.GenerateTaskSpec(config.NewDefaultConfig(), build, buildRun, buildStrategy.Spec.Steps, []buildv1beta1.Parameter{}, buildStrategy.GetVolumes()) Expect(err).To(BeNil()) }) @@ -420,7 +420,7 @@ var _ = Describe("GenerateTaskrun", func() { namespace = "build-test" contextDir = "docker-build" - builderImage = &buildv1alpha1.Image{ + builderImage = &buildv1beta1.Image{ Image: "heroku/builder:22", } outputPath = "image-registry.openshift-image-registry.svc:5000/example/buildpacks-app" @@ -450,10 +450,10 @@ var _ = Describe("GenerateTaskrun", func() { Expect(strings.Contains(got.GenerateName, buildRun.Name+"-")).To(Equal(true)) Expect(got.Namespace).To(Equal(namespace)) Expect(got.Spec.ServiceAccountName).To(Equal(buildpacks + "-serviceaccount")) - Expect(got.Labels[buildv1alpha1.LabelBuild]).To(Equal(build.Name)) - Expect(got.Labels[buildv1alpha1.LabelBuildRun]).To(Equal(buildRun.Name)) - Expect(got.Labels[buildv1alpha1.LabelBuildStrategyName]).To(Equal(build.Spec.Strategy.Name)) - Expect(got.Labels[buildv1alpha1.LabelBuildStrategyGeneration]).To(Equal("0")) + Expect(got.Labels[buildv1beta1.LabelBuild]).To(Equal(build.Name)) + Expect(got.Labels[buildv1beta1.LabelBuildRun]).To(Equal(buildRun.Name)) + Expect(got.Labels[buildv1beta1.LabelBuildStrategyName]).To(Equal(build.Spec.Strategy.Name)) + Expect(got.Labels[buildv1beta1.LabelBuildStrategyGeneration]).To(Equal("0")) }) It("should filter out certain annotations when propagating them to the TaskRun", func() { @@ -502,8 +502,8 @@ var _ = Describe("GenerateTaskrun", func() { Expect(strings.Contains(got.GenerateName, buildRun.Name+"-")).To(Equal(true)) Expect(got.Namespace).To(Equal(namespace)) Expect(got.Spec.ServiceAccountName).To(Equal(buildpacks + "-serviceaccount")) - Expect(got.Labels[buildv1alpha1.LabelBuild]).To(Equal(build.Name)) - Expect(got.Labels[buildv1alpha1.LabelBuildRun]).To(Equal(buildRun.Name)) + Expect(got.Labels[buildv1beta1.LabelBuild]).To(Equal(build.Name)) + Expect(got.Labels[buildv1beta1.LabelBuildRun]).To(Equal(buildRun.Name)) }) It("should ensure generated TaskRun's spec special input params are correct", func() { diff --git a/pkg/validate/buildname.go b/pkg/validate/buildname.go index 1eaa83c1f5..8f810d2dcf 100644 --- a/pkg/validate/buildname.go +++ b/pkg/validate/buildname.go @@ -11,7 +11,7 @@ import ( "k8s.io/apimachinery/pkg/util/validation" "k8s.io/utils/pointer" - build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" ) // BuildNameRef contains all required fields diff --git a/pkg/validate/envvars.go b/pkg/validate/envvars.go index 6d116b78ad..aacea4a8a9 100644 --- a/pkg/validate/envvars.go +++ b/pkg/validate/envvars.go @@ -12,7 +12,7 @@ import ( kerrors "k8s.io/apimachinery/pkg/util/errors" "k8s.io/utils/pointer" - build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" ) // Env implements the Env interface to add validations for the `build.spec.env` slice. diff --git a/pkg/validate/envvars_test.go b/pkg/validate/envvars_test.go index 293de3e5ac..9dc921ff99 100644 --- a/pkg/validate/envvars_test.go +++ b/pkg/validate/envvars_test.go @@ -13,7 +13,7 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/utils/pointer" - build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/validate" ) diff --git a/pkg/validate/ownerreferences.go b/pkg/validate/ownerreferences.go index 2a39c8fe83..04601f62e8 100644 --- a/pkg/validate/ownerreferences.go +++ b/pkg/validate/ownerreferences.go @@ -15,7 +15,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" - build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/ctxlog" ) @@ -35,42 +35,42 @@ func (o OwnerRef) ValidatePath(ctx context.Context) error { return err } - switch o.Build.GetAnnotations()[build.AnnotationBuildRunDeletion] { - case "true": - // if the buildRun does not have an ownerreference to the Build, lets add it. - for i := range buildRunList.Items { - buildRun := buildRunList.Items[i] - - if index := o.validateBuildOwnerReference(buildRun.OwnerReferences); index == -1 { - if err := controllerutil.SetControllerReference(o.Build, &buildRun, o.Scheme); err != nil { - o.Build.Status.Reason = build.BuildReasonPtr(build.SetOwnerReferenceFailed) - o.Build.Status.Message = pointer.String(fmt.Sprintf("unexpected error when trying to set the ownerreference: %v", err)) - } - if err = o.Client.Update(ctx, &buildRun); err != nil { - return err + if o.Build.Spec.Retention != nil && o.Build.Spec.Retention.AtBuildDeletion != nil { + switch *o.Build.Spec.Retention.AtBuildDeletion { + case true: + // if the buildRun does not have an ownerreference to the Build, lets add it. + for i := range buildRunList.Items { + buildRun := buildRunList.Items[i] + + if index := o.validateBuildOwnerReference(buildRun.OwnerReferences); index == -1 { + if err := controllerutil.SetControllerReference(o.Build, &buildRun, o.Scheme); err != nil { + o.Build.Status.Reason = build.BuildReasonPtr(build.SetOwnerReferenceFailed) + o.Build.Status.Message = pointer.String(fmt.Sprintf("unexpected error when trying to set the ownerreference: %v", err)) + } + if err = o.Client.Update(ctx, &buildRun); err != nil { + return err + } + ctxlog.Info(ctx, fmt.Sprintf("successfully updated BuildRun %s", buildRun.Name), namespace, buildRun.Namespace, name, buildRun.Name) } - ctxlog.Info(ctx, fmt.Sprintf("successfully updated BuildRun %s", buildRun.Name), namespace, buildRun.Namespace, name, buildRun.Name) } - } - case "", "false": - // if the buildRun have an ownerreference to the Build, lets remove it - for i := range buildRunList.Items { - buildRun := buildRunList.Items[i] - - if index := o.validateBuildOwnerReference(buildRun.OwnerReferences); index != -1 { - buildRun.OwnerReferences = removeOwnerReferenceByIndex(buildRun.OwnerReferences, index) - if err := o.Client.Update(ctx, &buildRun); err != nil { - return err + case false: + // if the buildRun have an ownerreference to the Build, lets remove it + for i := range buildRunList.Items { + buildRun := buildRunList.Items[i] + + if index := o.validateBuildOwnerReference(buildRun.OwnerReferences); index != -1 { + buildRun.OwnerReferences = removeOwnerReferenceByIndex(buildRun.OwnerReferences, index) + if err := o.Client.Update(ctx, &buildRun); err != nil { + return err + } + ctxlog.Info(ctx, fmt.Sprintf("successfully updated BuildRun %s", buildRun.Name), namespace, buildRun.Namespace, name, buildRun.Name) } - ctxlog.Info(ctx, fmt.Sprintf("successfully updated BuildRun %s", buildRun.Name), namespace, buildRun.Namespace, name, buildRun.Name) } + default: + ctxlog.Info(ctx, fmt.Sprintf("the build retention AtBuildDeletion was not properly defined"), namespace, o.Build.Namespace, name, o.Build.Name) + return fmt.Errorf("the build retention AtBuildDeletion was not properly defined") } - - default: - ctxlog.Info(ctx, fmt.Sprintf("the annotation %s was not properly defined, supported values are true or false", build.AnnotationBuildRunDeletion), namespace, o.Build.Namespace, name, o.Build.Name) - return fmt.Errorf("the annotation %s was not properly defined, supported values are true or false", build.AnnotationBuildRunDeletion) } - return nil } diff --git a/pkg/validate/params.go b/pkg/validate/params.go index 17fb4a8be9..34a4e4d29c 100644 --- a/pkg/validate/params.go +++ b/pkg/validate/params.go @@ -8,23 +8,23 @@ import ( "fmt" "strings" - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/reconciler/buildrun/resources" ) // BuildParameters validates that the parameter values specified in Build are suitable for what is defined in the BuildStrategy -func BuildParameters(parameterDefinitions []buildv1alpha1.Parameter, buildParamValues []buildv1alpha1.ParamValue) (bool, buildv1alpha1.BuildReason, string) { +func BuildParameters(parameterDefinitions []buildv1beta1.Parameter, buildParamValues []buildv1beta1.ParamValue) (bool, buildv1beta1.BuildReason, string) { valid, reason, message := validateParameters(parameterDefinitions, buildParamValues, true) - return valid, buildv1alpha1.BuildReason(reason), message + return valid, buildv1beta1.BuildReason(reason), message } // BuildRunParameters validates that the parameter values specified in Build and BuildRun are suitable for what is defined in the BuildStrategy -func BuildRunParameters(parameterDefinitions []buildv1alpha1.Parameter, buildParamValues []buildv1alpha1.ParamValue, buildRunParamValues []buildv1alpha1.ParamValue) (bool, string, string) { +func BuildRunParameters(parameterDefinitions []buildv1beta1.Parameter, buildParamValues []buildv1beta1.ParamValue, buildRunParamValues []buildv1beta1.ParamValue) (bool, string, string) { paramValues := resources.OverrideParams(buildParamValues, buildRunParamValues) return validateParameters(parameterDefinitions, paramValues, false) } -func validateParameters(parameterDefinitions []buildv1alpha1.Parameter, paramValues []buildv1alpha1.ParamValue, ignoreMissingParameters bool) (bool, string, string) { +func validateParameters(parameterDefinitions []buildv1beta1.Parameter, paramValues []buildv1beta1.ParamValue, ignoreMissingParameters bool) (bool, string, string) { // list of params that collide with reserved system strategy parameters undesiredParams := []string{} @@ -76,7 +76,7 @@ func validateParameters(parameterDefinitions []buildv1alpha1.Parameter, paramVal switch parameterDefinition.Type { case "": // string is default fallthrough - case buildv1alpha1.ParameterTypeString: + case buildv1beta1.ParameterTypeString: if paramValue != nil { // check if a string value contains array values if paramValue.Values != nil { @@ -107,7 +107,7 @@ func validateParameters(parameterDefinitions []buildv1alpha1.Parameter, paramVal continue } - case buildv1alpha1.ParameterTypeArray: + case buildv1beta1.ParameterTypeArray: if paramValue != nil { // check if an array value contains a single value if paramValue.SingleValue != nil { @@ -180,7 +180,7 @@ func validateParameters(parameterDefinitions []buildv1alpha1.Parameter, paramVal } // hasMoreThanOneValue checks if a SingleValue has more than one value set (plain text, secret, and config map key reference) -func hasMoreThanOneValue(singleValue buildv1alpha1.SingleValue) bool { +func hasMoreThanOneValue(singleValue buildv1beta1.SingleValue) bool { if singleValue.Value != nil && (singleValue.ConfigMapValue != nil || singleValue.SecretValue != nil) { return true } @@ -195,7 +195,7 @@ func hasMoreThanOneValue(singleValue buildv1alpha1.SingleValue) bool { } // hasNoValue checks if a SingleValue has no value set (plain text, secret, and config map key reference) -func hasNoValue(singleValue buildv1alpha1.SingleValue) bool { +func hasNoValue(singleValue buildv1beta1.SingleValue) bool { if singleValue.ConfigMapValue == nil && singleValue.SecretValue == nil && singleValue.Value == nil { return true } @@ -204,7 +204,7 @@ func hasNoValue(singleValue buildv1alpha1.SingleValue) bool { } // hasIncompleteConfigMapValue checks if a SingleValue has a ConfigMap value with an empty name or key -func hasIncompleteConfigMapValue(singleValue buildv1alpha1.SingleValue) bool { +func hasIncompleteConfigMapValue(singleValue buildv1beta1.SingleValue) bool { if singleValue.ConfigMapValue != nil && (singleValue.ConfigMapValue.Name == "" || singleValue.ConfigMapValue.Key == "") { return true } @@ -213,7 +213,7 @@ func hasIncompleteConfigMapValue(singleValue buildv1alpha1.SingleValue) bool { } // hasIncompleteSecretValue checks if a SingleValue has a Secret value with an empty name or key -func hasIncompleteSecretValue(singleValue buildv1alpha1.SingleValue) bool { +func hasIncompleteSecretValue(singleValue buildv1beta1.SingleValue) bool { if singleValue.SecretValue != nil && (singleValue.SecretValue.Name == "" || singleValue.SecretValue.Key == "") { return true } diff --git a/pkg/validate/params_test.go b/pkg/validate/params_test.go index 9b97130e6e..494badf7c9 100644 --- a/pkg/validate/params_test.go +++ b/pkg/validate/params_test.go @@ -9,46 +9,46 @@ import ( . "github.com/onsi/gomega" "k8s.io/utils/pointer" - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/validate" ) var _ = Describe("ValidateBuildRunParameters", func() { Context("for a set of parameter definitions", func() { - parameterDefinitions := []buildv1alpha1.Parameter{ + parameterDefinitions := []buildv1beta1.Parameter{ { Name: "string-param-no-default", }, { Name: "string-param-with-default", - Type: buildv1alpha1.ParameterTypeString, + Type: buildv1beta1.ParameterTypeString, Default: pointer.String("default value"), }, { Name: "array-param-no-defaults", - Type: buildv1alpha1.ParameterTypeArray, + Type: buildv1beta1.ParameterTypeArray, }, { Name: "array-param-with-defaults", - Type: buildv1alpha1.ParameterTypeArray, + Type: buildv1beta1.ParameterTypeArray, Defaults: &[]string{}, }, } Context("for parameters just for the required fields", func() { - buildParamValues := []buildv1alpha1.ParamValue{ + buildParamValues := []buildv1beta1.ParamValue{ { Name: "string-param-no-default", - SingleValue: &buildv1alpha1.SingleValue{ + SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("a value"), }, }, } - buildRunParamValues := []buildv1alpha1.ParamValue{ + buildRunParamValues := []buildv1beta1.ParamValue{ { Name: "array-param-no-defaults", - Values: []buildv1alpha1.SingleValue{}, + Values: []buildv1beta1.SingleValue{}, }, } @@ -59,11 +59,11 @@ var _ = Describe("ValidateBuildRunParameters", func() { }) Context("for parameter values from different sources", func() { - buildParamValues := []buildv1alpha1.ParamValue{ + buildParamValues := []buildv1beta1.ParamValue{ { Name: "string-param-no-default", - SingleValue: &buildv1alpha1.SingleValue{ - ConfigMapValue: &buildv1alpha1.ObjectKeyRef{ + SingleValue: &buildv1beta1.SingleValue{ + ConfigMapValue: &buildv1beta1.ObjectKeyRef{ Name: "a-config-map", Key: "some-key", }, @@ -72,16 +72,16 @@ var _ = Describe("ValidateBuildRunParameters", func() { { Name: "string-param-with-default", // This is invalid but will be corrected in the BuildRun - Values: []buildv1alpha1.SingleValue{}, + Values: []buildv1beta1.SingleValue{}, }, } - buildRunParamValues := []buildv1alpha1.ParamValue{ + buildRunParamValues := []buildv1beta1.ParamValue{ { Name: "array-param-no-defaults", - Values: []buildv1alpha1.SingleValue{ + Values: []buildv1beta1.SingleValue{ { - SecretValue: &buildv1alpha1.ObjectKeyRef{ + SecretValue: &buildv1beta1.ObjectKeyRef{ Name: "a-secret", Key: "my-credential-key", }, @@ -90,7 +90,7 @@ var _ = Describe("ValidateBuildRunParameters", func() { }, { Name: "string-param-with-default", - SingleValue: &buildv1alpha1.SingleValue{ + SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String(""), }, }, @@ -105,7 +105,7 @@ var _ = Describe("ValidateBuildRunParameters", func() { Context("for parameter values that are missing", func() { It("validates with the correct validation error", func() { - valid, reason, message := validate.BuildRunParameters(parameterDefinitions, []buildv1alpha1.ParamValue{}, []buildv1alpha1.ParamValue{}) + valid, reason, message := validate.BuildRunParameters(parameterDefinitions, []buildv1beta1.ParamValue{}, []buildv1beta1.ParamValue{}) Expect(valid).To(BeFalse()) Expect(reason).To(Equal("MissingParameterValues")) Expect(message).To(HavePrefix("The following parameters are required but no value has been provided:")) @@ -115,17 +115,17 @@ var _ = Describe("ValidateBuildRunParameters", func() { }) Context("for a parameter value that is defined but contains no value", func() { - buildParamValues := []buildv1alpha1.ParamValue{ + buildParamValues := []buildv1beta1.ParamValue{ { Name: "string-param-no-default", - SingleValue: &buildv1alpha1.SingleValue{}, + SingleValue: &buildv1beta1.SingleValue{}, }, } - buildRunParamValues := []buildv1alpha1.ParamValue{ + buildRunParamValues := []buildv1beta1.ParamValue{ { Name: "array-param-no-defaults", - Values: []buildv1alpha1.SingleValue{}, + Values: []buildv1beta1.SingleValue{}, }, } @@ -138,23 +138,23 @@ var _ = Describe("ValidateBuildRunParameters", func() { }) Context("for parameter values that contain a value for a system parameter", func() { - buildParamValues := []buildv1alpha1.ParamValue{ + buildParamValues := []buildv1beta1.ParamValue{ { Name: "string-param-no-default", - SingleValue: &buildv1alpha1.SingleValue{ + SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("a value"), }, }, { Name: "array-param-no-defaults", - Values: []buildv1alpha1.SingleValue{}, + Values: []buildv1beta1.SingleValue{}, }, } - buildRunParamValues := []buildv1alpha1.ParamValue{ + buildRunParamValues := []buildv1beta1.ParamValue{ { Name: "shp-source-context", - SingleValue: &buildv1alpha1.SingleValue{ + SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("/my-source"), }, }, @@ -169,27 +169,27 @@ var _ = Describe("ValidateBuildRunParameters", func() { }) Context("for parameter values that are not defined in the build strategy", func() { - buildParamValues := []buildv1alpha1.ParamValue{ + buildParamValues := []buildv1beta1.ParamValue{ { Name: "string-param-no-default", - SingleValue: &buildv1alpha1.SingleValue{ + SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("a value"), }, }, { Name: "array-param-no-defaults", - Values: []buildv1alpha1.SingleValue{}, + Values: []buildv1beta1.SingleValue{}, }, { Name: "non-existing-parameter-on-build", - Values: []buildv1alpha1.SingleValue{}, + Values: []buildv1beta1.SingleValue{}, }, } - buildRunParamValues := []buildv1alpha1.ParamValue{ + buildRunParamValues := []buildv1beta1.ParamValue{ { Name: "non-existing-parameter", - SingleValue: &buildv1alpha1.SingleValue{ + SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("my value"), }, }, @@ -206,12 +206,12 @@ var _ = Describe("ValidateBuildRunParameters", func() { }) Context("for parameter values that contain more than one value", func() { - buildParamValues := []buildv1alpha1.ParamValue{ + buildParamValues := []buildv1beta1.ParamValue{ { Name: "string-param-no-default", - SingleValue: &buildv1alpha1.SingleValue{ + SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("a value"), - ConfigMapValue: &buildv1alpha1.ObjectKeyRef{ + ConfigMapValue: &buildv1beta1.ObjectKeyRef{ Name: "a-config-map", Key: "a-key", }, @@ -219,19 +219,19 @@ var _ = Describe("ValidateBuildRunParameters", func() { }, } - buildRunParamValues := []buildv1alpha1.ParamValue{ + buildRunParamValues := []buildv1beta1.ParamValue{ { Name: "array-param-no-defaults", - Values: []buildv1alpha1.SingleValue{ + Values: []buildv1beta1.SingleValue{ { Value: pointer.String("a good item"), }, { - ConfigMapValue: &buildv1alpha1.ObjectKeyRef{ + ConfigMapValue: &buildv1beta1.ObjectKeyRef{ Name: "a-config-map", Key: "a-key", }, - SecretValue: &buildv1alpha1.ObjectKeyRef{ + SecretValue: &buildv1beta1.ObjectKeyRef{ Name: "a-secret", Key: "a-key", }, @@ -251,15 +251,15 @@ var _ = Describe("ValidateBuildRunParameters", func() { }) Context("for parameter values that use the wrong type", func() { - buildParamValues := []buildv1alpha1.ParamValue{ + buildParamValues := []buildv1beta1.ParamValue{ { Name: "string-param-no-default", - Values: []buildv1alpha1.SingleValue{ + Values: []buildv1beta1.SingleValue{ { Value: pointer.String("an item"), }, { - ConfigMapValue: &buildv1alpha1.ObjectKeyRef{ + ConfigMapValue: &buildv1beta1.ObjectKeyRef{ Name: "a-config-map", Key: "a-key", }, @@ -268,10 +268,10 @@ var _ = Describe("ValidateBuildRunParameters", func() { }, } - buildRunParamValues := []buildv1alpha1.ParamValue{ + buildRunParamValues := []buildv1beta1.ParamValue{ { Name: "array-param-no-defaults", - SingleValue: &buildv1alpha1.SingleValue{ + SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("a value"), }, }, @@ -288,16 +288,16 @@ var _ = Describe("ValidateBuildRunParameters", func() { }) Context("for array parameter values that contain empty items", func() { - buildParamValues := []buildv1alpha1.ParamValue{ + buildParamValues := []buildv1beta1.ParamValue{ { Name: "string-param-no-default", - SingleValue: &buildv1alpha1.SingleValue{ + SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String(" some value"), }, }, { Name: "array-param-with-defaults", - Values: []buildv1alpha1.SingleValue{ + Values: []buildv1beta1.SingleValue{ { // the bad item without any value }, @@ -305,10 +305,10 @@ var _ = Describe("ValidateBuildRunParameters", func() { }, } - buildRunParamValues := []buildv1alpha1.ParamValue{ + buildRunParamValues := []buildv1beta1.ParamValue{ { Name: "array-param-no-defaults", - Values: []buildv1alpha1.SingleValue{ + Values: []buildv1beta1.SingleValue{ { Value: pointer.String("a good item"), }, @@ -316,7 +316,7 @@ var _ = Describe("ValidateBuildRunParameters", func() { // the bad item without any value }, { - ConfigMapValue: &buildv1alpha1.ObjectKeyRef{ + ConfigMapValue: &buildv1beta1.ObjectKeyRef{ Name: "a-configmap", Key: "a-key", }, @@ -336,26 +336,26 @@ var _ = Describe("ValidateBuildRunParameters", func() { }) Context("for parameter values that contain incomplete configMapValues", func() { - buildParamValues := []buildv1alpha1.ParamValue{ + buildParamValues := []buildv1beta1.ParamValue{ { Name: "string-param-no-default", - SingleValue: &buildv1alpha1.SingleValue{ - ConfigMapValue: &buildv1alpha1.ObjectKeyRef{ + SingleValue: &buildv1beta1.SingleValue{ + ConfigMapValue: &buildv1beta1.ObjectKeyRef{ Name: "a-config-map", }, }, }, } - buildRunParamValues := []buildv1alpha1.ParamValue{ + buildRunParamValues := []buildv1beta1.ParamValue{ { Name: "array-param-no-defaults", - Values: []buildv1alpha1.SingleValue{ + Values: []buildv1beta1.SingleValue{ { Value: pointer.String("an item"), }, { - ConfigMapValue: &buildv1alpha1.ObjectKeyRef{ + ConfigMapValue: &buildv1beta1.ObjectKeyRef{ Key: "a-key", }, }, @@ -374,26 +374,26 @@ var _ = Describe("ValidateBuildRunParameters", func() { }) Context("for parameter values that contain incomplete secretValues", func() { - buildParamValues := []buildv1alpha1.ParamValue{ + buildParamValues := []buildv1beta1.ParamValue{ { Name: "string-param-no-default", - SingleValue: &buildv1alpha1.SingleValue{ - SecretValue: &buildv1alpha1.ObjectKeyRef{ + SingleValue: &buildv1beta1.SingleValue{ + SecretValue: &buildv1beta1.ObjectKeyRef{ Name: "a-secret", }, }, }, } - buildRunParamValues := []buildv1alpha1.ParamValue{ + buildRunParamValues := []buildv1beta1.ParamValue{ { Name: "array-param-no-defaults", - Values: []buildv1alpha1.SingleValue{ + Values: []buildv1beta1.SingleValue{ { Value: pointer.String("an item"), }, { - SecretValue: &buildv1alpha1.ObjectKeyRef{ + SecretValue: &buildv1beta1.ObjectKeyRef{ Key: "a-key", }, }, diff --git a/pkg/validate/secrets.go b/pkg/validate/secrets.go index 5e3692e0c6..26ed154f2e 100644 --- a/pkg/validate/secrets.go +++ b/pkg/validate/secrets.go @@ -16,7 +16,7 @@ import ( "k8s.io/utils/pointer" "sigs.k8s.io/controller-runtime/pkg/client" - build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" ) // Credentials contains all required fields @@ -61,14 +61,12 @@ func (s Credentials) ValidatePath(ctx context.Context) error { func (s Credentials) buildCredentialserences() map[string]build.BuildReason { // Validate if the referenced secrets exist in the namespace secretRefMap := map[string]build.BuildReason{} - if s.Build.Spec.Output.Credentials != nil && s.Build.Spec.Output.Credentials.Name != "" { - secretRefMap[s.Build.Spec.Output.Credentials.Name] = build.SpecOutputSecretRefNotFound + if s.Build.Spec.Output.PushSecret != nil && *s.Build.Spec.Output.PushSecret != "" { + secretRefMap[*s.Build.Spec.Output.PushSecret] = build.SpecOutputSecretRefNotFound } - if s.Build.Spec.Source.Credentials != nil && s.Build.Spec.Source.Credentials.Name != "" { - secretRefMap[s.Build.Spec.Source.Credentials.Name] = build.SpecSourceSecretRefNotFound - } - if s.Build.Spec.Builder != nil && s.Build.Spec.Builder.Credentials != nil && s.Build.Spec.Builder.Credentials.Name != "" { - secretRefMap[s.Build.Spec.Builder.Credentials.Name] = build.SpecBuilderSecretRefNotFound + + if s.Build.GetSourceCredentials() != nil { + secretRefMap[*s.Build.GetSourceCredentials()] = build.SpecSourceSecretRefNotFound } return secretRefMap } diff --git a/pkg/validate/sources.go b/pkg/validate/sources.go deleted file mode 100644 index 8e8d37055e..0000000000 --- a/pkg/validate/sources.go +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright The Shipwright Contributors -// -// SPDX-License-Identifier: Apache-2.0 - -package validate - -import ( - "context" - "fmt" - "net/url" - - build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" -) - -// SourcesRef implements RuntimeRef interface to add validations for `build.spec.sources` slice. -type SourcesRef struct { - Build *build.Build // build instance for analysis -} - -// ValidatePath executes the validation routine, inspecting the `build.spec.sources` path, which -// contains a slice of BuildSource. -func (s *SourcesRef) ValidatePath(_ context.Context) error { - for _, source := range s.Build.Spec.Sources { - if err := s.validateSourceEntry(source); err != nil { - return err - } - } - return nil -} - -// validateSourceEntry inspect informed entry, probes all required attributes. -func (s *SourcesRef) validateSourceEntry(source build.BuildSource) error { - if source.Name == "" { - return fmt.Errorf("name must be informed") - } - if source.URL == "" { - return fmt.Errorf("URL must be informed") - } - if _, err := url.ParseRequestURI(source.URL); err != nil { - return err - } - return nil -} - -// NewSourcesRef instantiate a new SourcesRef passing the build object pointer along. -func NewSourcesRef(b *build.Build) *SourcesRef { - return &SourcesRef{Build: b} -} diff --git a/pkg/validate/sources_test.go b/pkg/validate/sources_test.go deleted file mode 100644 index ab68bb3efb..0000000000 --- a/pkg/validate/sources_test.go +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright The Shipwright Contributors -// -// SPDX-License-Identifier: Apache-2.0 - -package validate_test - -import ( - "context" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - - build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" - "github.com/shipwright-io/build/pkg/validate" -) - -var _ = Describe("SourcesRef", func() { - Context("ValidatePath", func() { - It("should successfully validate an empty sources slice", func() { - srcRef := validate.NewSourcesRef(&build.Build{}) - - Expect(srcRef.ValidatePath(context.TODO())).To(BeNil()) - }) - - It("should successfully validate a build with a valid URL", func() { - srcRef := validate.NewSourcesRef(&build.Build{ - Spec: build.BuildSpec{ - Sources: []build.BuildSource{ - {Name: "name", URL: "https://github.com/shipwright-io/build"}, - }, - }, - }) - - Expect(srcRef.ValidatePath(context.TODO())).To(BeNil()) - }) - - It("should fail to validate if the name is not informed", func() { - srcRef := validate.NewSourcesRef(&build.Build{ - Spec: build.BuildSpec{ - Sources: []build.BuildSource{ - {Name: ""}, - }, - }, - }) - - Expect(srcRef.ValidatePath(context.TODO())).To(HaveOccurred()) - }) - - It("should fail to validate if the URL is not informed", func() { - srcRef := validate.NewSourcesRef(&build.Build{ - Spec: build.BuildSpec{ - Sources: []build.BuildSource{ - {Name: "name", URL: ""}, - }, - }, - }) - - Expect(srcRef.ValidatePath(context.TODO())).To(HaveOccurred()) - }) - - It("should fail to validate a build with an invalid URL", func() { - srcRef := validate.NewSourcesRef(&build.Build{ - Spec: build.BuildSpec{ - Sources: []build.BuildSource{ - {Name: "name", URL: "invalid URL"}, - }, - }, - }) - - Expect(srcRef.ValidatePath(context.TODO())).To(HaveOccurred()) - }) - }) -}) diff --git a/pkg/validate/sourceurl.go b/pkg/validate/sourceurl.go index c724d423b7..c85e81aaa7 100644 --- a/pkg/validate/sourceurl.go +++ b/pkg/validate/sourceurl.go @@ -11,7 +11,7 @@ import ( "k8s.io/utils/pointer" "sigs.k8s.io/controller-runtime/pkg/client" - build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/ctxlog" "github.com/shipwright-io/build/pkg/git" ) @@ -31,22 +31,25 @@ func NewSourceURL(client client.Client, build *build.Build) *SourceURLRef { // that the spec.source.url exists. This validation only applies // to endpoints that do not require authentication. func (s SourceURLRef) ValidatePath(ctx context.Context) error { - if s.Build.Spec.Source.Credentials == nil && s.Build.Spec.Source.URL != nil { - switch s.Build.GetAnnotations()[build.AnnotationBuildVerifyRepository] { - case "true": - if err := git.ValidateGitURLExists(ctx, *s.Build.Spec.Source.URL); err != nil { - s.MarkBuildStatus(s.Build, build.RemoteRepositoryUnreachable, err.Error()) - return err + // TODO: double check this new code + if s.Build.Spec.Source.Type == build.GitType { + gitSource := s.Build.Spec.Source.GitSource + if gitSource.CloneSecret == nil && gitSource.URL != "" { + switch s.Build.GetAnnotations()[build.AnnotationBuildVerifyRepository] { + case "true": + if err := git.ValidateGitURLExists(ctx, gitSource.URL); err != nil { + s.MarkBuildStatus(s.Build, build.RemoteRepositoryUnreachable, err.Error()) + return err + } + case "", "false": + ctxlog.Info(ctx, fmt.Sprintf("the annotation %s is set to %s, nothing to do", build.AnnotationBuildVerifyRepository, s.Build.GetAnnotations()[build.AnnotationBuildVerifyRepository]), namespace, s.Build.Namespace, name, s.Build.Name) + + default: + var annoErr = fmt.Errorf("the annotation %s was not properly defined, supported values are true or false", build.AnnotationBuildVerifyRepository) + ctxlog.Error(ctx, annoErr, namespace, s.Build.Namespace, name, s.Build.Name) + s.MarkBuildStatus(s.Build, build.RemoteRepositoryUnreachable, annoErr.Error()) + return annoErr } - - case "", "false": - ctxlog.Info(ctx, fmt.Sprintf("the annotation %s is set to %s, nothing to do", build.AnnotationBuildVerifyRepository, s.Build.GetAnnotations()[build.AnnotationBuildVerifyRepository]), namespace, s.Build.Namespace, name, s.Build.Name) - - default: - var annoErr = fmt.Errorf("the annotation %s was not properly defined, supported values are true or false", build.AnnotationBuildVerifyRepository) - ctxlog.Error(ctx, annoErr, namespace, s.Build.Namespace, name, s.Build.Name) - s.MarkBuildStatus(s.Build, build.RemoteRepositoryUnreachable, annoErr.Error()) - return annoErr } } diff --git a/pkg/validate/strategies.go b/pkg/validate/strategies.go index 56a24d253a..3ecbcc2706 100644 --- a/pkg/validate/strategies.go +++ b/pkg/validate/strategies.go @@ -13,7 +13,7 @@ import ( "k8s.io/utils/pointer" "sigs.k8s.io/controller-runtime/pkg/client" - build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/ctxlog" ) diff --git a/pkg/validate/trigger.go b/pkg/validate/trigger.go index 562aafea1f..d25d39d863 100644 --- a/pkg/validate/trigger.go +++ b/pkg/validate/trigger.go @@ -7,7 +7,7 @@ import ( "context" "fmt" - build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" kerrors "k8s.io/apimachinery/pkg/util/errors" "k8s.io/utils/pointer" ) diff --git a/pkg/validate/trigger_test.go b/pkg/validate/trigger_test.go index 728e8e35d8..7d99745fbe 100644 --- a/pkg/validate/trigger_test.go +++ b/pkg/validate/trigger_test.go @@ -8,7 +8,7 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/validate" ) diff --git a/pkg/validate/validate.go b/pkg/validate/validate.go index 408fee1042..2134c6abc1 100644 --- a/pkg/validate/validate.go +++ b/pkg/validate/validate.go @@ -11,7 +11,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" "sigs.k8s.io/controller-runtime/pkg/client" - build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/reconciler/buildrun/resources" ) @@ -63,8 +63,6 @@ func NewValidation( return &SourceURLRef{Build: build, Client: client}, nil case OwnerReferences: return &OwnerRef{Build: build, Client: client, Scheme: scheme}, nil - case Sources: - return &SourcesRef{Build: build}, nil case BuildName: return &BuildNameRef{Build: build}, nil case Envs: @@ -90,13 +88,14 @@ func All(ctx context.Context, validations ...BuildPath) error { // BuildRunFields runs field validations against a BuildRun to detect // disallowed field combinations func BuildRunFields(buildRun *build.BuildRun) (string, string) { - if buildRun.Spec.BuildSpec == nil && buildRun.Spec.BuildRef == nil { + + if buildRun.Spec.Build.Build == nil && buildRun.Spec.Build.Name == nil { return resources.BuildRunNoRefOrSpec, "no build referenced or specified, either 'buildRef' or 'buildSpec' has to be set" } - if buildRun.Spec.BuildSpec != nil { - if buildRun.Spec.BuildRef != nil { + if buildRun.Spec.Build.Build != nil { + if buildRun.Spec.Build.Name != nil { return resources.BuildRunAmbiguousBuild, "fields 'buildRef' and 'buildSpec' are mutually exclusive" } @@ -121,7 +120,7 @@ func BuildRunFields(buildRun *build.BuildRun) (string, string) { "cannot use 'timeout' override and 'buildSpec' simultaneously" } - if buildRun.Spec.BuildSpec.Trigger != nil { + if buildRun.Spec.Build.Build.Trigger != nil { return resources.BuildRunBuildFieldOverrideForbidden, "cannot use 'triggers' override in the 'BuildRun', only allowed in the 'Build'" } diff --git a/pkg/validate/volumes.go b/pkg/validate/volumes.go index f71aaa55db..8b152cc9fc 100644 --- a/pkg/validate/volumes.go +++ b/pkg/validate/volumes.go @@ -7,16 +7,16 @@ package validate import ( "fmt" - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" ) // BuildVolumes is used to validate volumes in the Build object -func BuildVolumes(strategyVolumes []buildv1alpha1.BuildStrategyVolume, buildVolumes []buildv1alpha1.BuildVolume) (bool, buildv1alpha1.BuildReason, string) { +func BuildVolumes(strategyVolumes []buildv1beta1.BuildStrategyVolume, buildVolumes []buildv1beta1.BuildVolume) (bool, buildv1beta1.BuildReason, string) { return validateVolumes(strategyVolumes, buildVolumes) } // BuildRunVolumes is used to validate volumes in the BuildRun object -func BuildRunVolumes(strategyVolumes []buildv1alpha1.BuildStrategyVolume, buildVolumes []buildv1alpha1.BuildVolume) (bool, string, string) { +func BuildRunVolumes(strategyVolumes []buildv1beta1.BuildStrategyVolume, buildVolumes []buildv1beta1.BuildVolume) (bool, string, string) { valid, reason, msg := validateVolumes(strategyVolumes, buildVolumes) return valid, string(reason), msg } @@ -24,18 +24,18 @@ func BuildRunVolumes(strategyVolumes []buildv1alpha1.BuildStrategyVolume, buildV // validateBuildVolumes validates build overriding the build strategy volumes. in case it tries // to override the non-overridable volume, or volume that does not exist in the strategy, it is // good to fail early -func validateVolumes(strategyVolumes []buildv1alpha1.BuildStrategyVolume, buildVolumes []buildv1alpha1.BuildVolume) (bool, buildv1alpha1.BuildReason, string) { +func validateVolumes(strategyVolumes []buildv1beta1.BuildStrategyVolume, buildVolumes []buildv1beta1.BuildVolume) (bool, buildv1beta1.BuildReason, string) { strategyVolumesMap := toVolumeMap(strategyVolumes) for _, buildVolume := range buildVolumes { strategyVolume, ok := strategyVolumesMap[buildVolume.Name] if !ok { - return false, buildv1alpha1.UndefinedVolume, fmt.Sprintf("Volume %q is not defined in the Strategy", buildVolume.Name) + return false, buildv1beta1.UndefinedVolume, fmt.Sprintf("Volume %q is not defined in the Strategy", buildVolume.Name) } // nil for overridable is equal to false if strategyVolume.Overridable == nil || !*strategyVolume.Overridable { - return false, buildv1alpha1.VolumeNotOverridable, fmt.Sprintf("Volume %q is not overridable in the Strategy", buildVolume.Name) + return false, buildv1beta1.VolumeNotOverridable, fmt.Sprintf("Volume %q is not overridable in the Strategy", buildVolume.Name) } } @@ -43,8 +43,8 @@ func validateVolumes(strategyVolumes []buildv1alpha1.BuildStrategyVolume, buildV } // toVolumeMap coverts slice of build strategy volumes to map of build strategy volumes, in order to later search them quickly by name -func toVolumeMap(strategyVolumes []buildv1alpha1.BuildStrategyVolume) map[string]buildv1alpha1.BuildStrategyVolume { - res := make(map[string]buildv1alpha1.BuildStrategyVolume) +func toVolumeMap(strategyVolumes []buildv1beta1.BuildStrategyVolume) map[string]buildv1beta1.BuildStrategyVolume { + res := make(map[string]buildv1beta1.BuildStrategyVolume) for _, vol := range strategyVolumes { res[vol.Name] = vol } diff --git a/pkg/volumes/volumes.go b/pkg/volumes/volumes.go index 691fda794f..89168db1a2 100644 --- a/pkg/volumes/volumes.go +++ b/pkg/volumes/volumes.go @@ -7,7 +7,7 @@ package volumes import ( "fmt" - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" corev1 "k8s.io/api/core/v1" kerrors "k8s.io/apimachinery/pkg/util/errors" ) @@ -16,9 +16,9 @@ import ( // checks for some erroneous situations around volumes and volume mounts func TaskSpecVolumes( existingVolumeMounts map[string]bool, - strategyVolumes []buildv1alpha1.BuildStrategyVolume, - buildVolumes []buildv1alpha1.BuildVolume, - buildrunVolumes []buildv1alpha1.BuildVolume, + strategyVolumes []buildv1beta1.BuildStrategyVolume, + buildVolumes []buildv1beta1.BuildVolume, + buildrunVolumes []buildv1beta1.BuildVolume, ) ([]corev1.Volume, error) { res := []corev1.Volume{} @@ -59,7 +59,7 @@ func TaskSpecVolumes( return res, nil } -func isReadOnlyVolume(strategyVolume *buildv1alpha1.BuildStrategyVolume) bool { +func isReadOnlyVolume(strategyVolume *buildv1beta1.BuildStrategyVolume) bool { return strategyVolume.VolumeSource.ConfigMap != nil || strategyVolume.VolumeSource.Secret != nil || strategyVolume.VolumeSource.DownwardAPI != nil || @@ -69,15 +69,15 @@ func isReadOnlyVolume(strategyVolume *buildv1alpha1.BuildStrategyVolume) bool { // MergeBuildVolumes merges Build Volumes from one list into the other. It only allows to merge those that have property // Overridable set to true. In case it is empty or false, it is not allowed to be overridden, so Volume cannot be merged // Merging in this context means copying the VolumeSource from one object to the other. -func MergeBuildVolumes(into []buildv1alpha1.BuildStrategyVolume, new []buildv1alpha1.BuildVolume) ([]buildv1alpha1.BuildStrategyVolume, error) { +func MergeBuildVolumes(into []buildv1beta1.BuildStrategyVolume, new []buildv1beta1.BuildVolume) ([]buildv1beta1.BuildStrategyVolume, error) { if len(new) == 0 && len(into) == 0 { - return []buildv1alpha1.BuildStrategyVolume{}, nil + return []buildv1beta1.BuildStrategyVolume{}, nil } if len(new) == 0 { return into, nil } - mergeMap := make(map[string]buildv1alpha1.BuildStrategyVolume) + mergeMap := make(map[string]buildv1beta1.BuildStrategyVolume) var errors []error for _, vol := range into { @@ -105,7 +105,7 @@ func MergeBuildVolumes(into []buildv1alpha1.BuildStrategyVolume, new []buildv1al mergeMap[merger.Name] = original } - result := make([]buildv1alpha1.BuildStrategyVolume, 0, len(mergeMap)) + result := make([]buildv1beta1.BuildStrategyVolume, 0, len(mergeMap)) for _, v := range mergeMap { result = append(result, v) }