From ee3063a88195e642cd5ff82c7c58e94edc8bd57c 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 | 3 +- pkg/reconciler/build/build_test.go | 93 ++------- pkg/reconciler/build/controller.go | 55 +++-- pkg/reconciler/buildrun/buildrun.go | 85 ++++---- pkg/reconciler/buildrun/buildrun_test.go | 64 +++--- pkg/reconciler/buildrun/controller.go | 14 +- pkg/reconciler/buildrun/resources/build.go | 16 +- .../buildrun/resources/build_test.go | 14 +- .../buildrun/resources/conditions.go | 30 +-- .../buildrun/resources/conditions_test.go | 4 +- .../buildrun/resources/credentials.go | 27 +-- .../buildrun/resources/credentials_test.go | 88 ++++---- .../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 | 3 +- .../buildrun/resources/results_test.go | 49 +++-- .../buildrun/resources/service_accounts.go | 30 ++- .../resources/service_accounts_test.go | 12 +- pkg/reconciler/buildrun/resources/sources.go | 54 +++-- .../buildrun/resources/sources/bundle.go | 29 +-- .../buildrun/resources/sources/git.go | 30 ++- .../buildrun/resources/sources/git_test.go | 15 +- .../buildrun/resources/sources/http.go | 56 ------ .../buildrun/resources/sources/http_test.go | 107 ---------- .../resources/steps/security_context.go | 4 +- .../resources/steps/security_context_test.go | 28 +-- .../buildrun/resources/strategies.go | 10 +- .../buildrun/resources/strategies_test.go | 8 +- pkg/reconciler/buildrun/resources/taskrun.go | 88 +++----- .../buildrun/resources/taskrun_test.go | 67 +++--- 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 | 12 +- pkg/validate/volumes.go | 16 +- pkg/volumes/volumes.go | 18 +- pkg/volumes/volumes_test.go | 119 ++++++----- test/e2e/v1alpha1/common_test.go | 56 +++++- test/e2e/v1beta1/common_test.go | 5 +- test/v1beta1_samples/buildstrategy_samples.go | 24 ++- test/v1beta1_samples/catalog.go | 14 +- 56 files changed, 847 insertions(+), 1178 deletions(-) delete mode 100644 pkg/reconciler/buildrun/resources/sources/http.go delete mode 100644 pkg/reconciler/buildrun/resources/sources/http_test.go 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..88f61ea479 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" @@ -28,7 +28,6 @@ var validationTypes = [...]string{ validate.SourceURL, validate.Secrets, validate.Strategies, - validate.Sources, validate.BuildName, validate.Envs, validate.Triggers, diff --git a/pkg/reconciler/build/build_test.go b/pkg/reconciler/build/build_test.go index c399ee49e7..aecd01c8d2 100644 --- a/pkg/reconciler/build/build_test.go +++ b/pkg/reconciler/build/build_test.go @@ -20,11 +20,11 @@ import ( "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" "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/controller/fakes" buildController "github.com/shipwright-io/build/pkg/reconciler/build" - test "github.com/shipwright-io/build/test/v1alpha1_samples" + test "github.com/shipwright-io/build/test/v1beta1_samples" ) var _ = Describe("Reconcile Build", func() { @@ -83,10 +83,9 @@ var _ = Describe("Reconcile Build", func() { Describe("Reconcile", func() { Context("when source secret is specified", func() { It("fails when the secret does not exist", func() { - buildSample.Spec.Source.Credentials = &corev1.LocalObjectReference{ - Name: "non-existing", - } - buildSample.Spec.Output.Credentials = nil + buildSample.Spec.Source.GitSource.CloneSecret = pointer.String("non-existing") + + buildSample.Spec.Output.PushSecret = nil statusCall := ctl.StubFunc(corev1.ConditionFalse, build.SpecSourceSecretRefNotFound, "referenced secret non-existing not found") statusWriter.UpdateCalls(statusCall) @@ -97,62 +96,8 @@ var _ = Describe("Reconcile Build", func() { }) It("succeeds when the secret exists foobar", func() { - buildSample.Spec.Source.Credentials = &corev1.LocalObjectReference{ - Name: "existing", - } - buildSample.Spec.Output.Credentials = nil - - // Fake some client Get calls and ensure we populate all - // different resources we could get during reconciliation - client.GetCalls(func(_ context.Context, nn types.NamespacedName, object crc.Object, getOptions ...crc.GetOption) error { - switch object := object.(type) { - case *build.Build: - buildSample.DeepCopyInto(object) - case *build.ClusterBuildStrategy: - clusterBuildStrategySample.DeepCopyInto(object) - case *corev1.Secret: - secretSample = ctl.SecretWithoutAnnotation("existing", namespace) - secretSample.DeepCopyInto(object) - } - return nil - }) - - statusCall := ctl.StubFunc(corev1.ConditionTrue, build.SucceedStatus, "all validations succeeded") - statusWriter.UpdateCalls(statusCall) - - result, err := reconciler.Reconcile(context.TODO(), request) - Expect(err).ToNot(HaveOccurred()) - Expect(statusWriter.UpdateCallCount()).To(Equal(1)) - Expect(reconcile.Result{}).To(Equal(result)) - }) - }) - - Context("when builder image secret is specified", func() { - It("fails when the secret does not exist", func() { - buildSample.Spec.Builder = &build.Image{ - Image: "busybox", - Credentials: &corev1.LocalObjectReference{ - Name: "non-existing", - }, - } - buildSample.Spec.Output.Credentials = nil - - statusCall := ctl.StubFunc(corev1.ConditionFalse, build.SpecBuilderSecretRefNotFound, "referenced secret non-existing not found") - statusWriter.UpdateCalls(statusCall) - - _, err := reconciler.Reconcile(context.TODO(), request) - Expect(err).To(BeNil()) - Expect(statusWriter.UpdateCallCount()).To(Equal(1)) - }) - - It("succeeds when the secret exists", func() { - buildSample.Spec.Builder = &build.Image{ - Image: "busybox", - Credentials: &corev1.LocalObjectReference{ - Name: "existing", - }, - } - buildSample.Spec.Output.Credentials = nil + buildSample.Spec.Source.GitSource.CloneSecret = pointer.String("existing") + buildSample.Spec.Output.PushSecret = nil // Fake some client Get calls and ensure we populate all // different resources we could get during reconciliation @@ -217,12 +162,8 @@ var _ = Describe("Reconcile Build", func() { Context("when source secret and output secret are specified", func() { It("fails when both secrets do not exist", func() { - buildSample.Spec.Source.Credentials = &corev1.LocalObjectReference{ - Name: "non-existing-source", - } - buildSample.Spec.Output.Credentials = &corev1.LocalObjectReference{ - Name: "non-existing-output", - } + buildSample.Spec.Source.GitSource.CloneSecret = pointer.String("non-existing-source") + buildSample.Spec.Output.PushSecret = pointer.String("non-existing-output") statusCall := ctl.StubFunc(corev1.ConditionFalse, build.MultipleSecretRefNotFound, "missing secrets are non-existing-output,non-existing-source") statusWriter.UpdateCalls(statusCall) @@ -371,7 +312,7 @@ var _ = Describe("Reconcile Build", func() { Context("when source URL is specified", func() { // validate file protocol It("fails when source URL is invalid", func() { - buildSample.Spec.Source.URL = pointer.String("foobar") + buildSample.Spec.Source.GitSource.URL = "foobar" buildSample.SetAnnotations(map[string]string{ build.AnnotationBuildVerifyRepository: "true", }) @@ -385,7 +326,7 @@ var _ = Describe("Reconcile Build", func() { // validate https protocol It("fails when public source URL is unreachable", func() { - buildSample.Spec.Source.URL = pointer.String("https://github.com/shipwright-io/sample-go-fake") + buildSample.Spec.Source.GitSource.URL = "https://github.com/shipwright-io/sample-go-fake" buildSample.SetAnnotations(map[string]string{ build.AnnotationBuildVerifyRepository: "true", }) @@ -400,7 +341,7 @@ var _ = Describe("Reconcile Build", func() { // skip validation because of empty sourceURL annotation It("succeed when source URL is invalid because source annotation is empty", func() { - buildSample.Spec.Source.URL = pointer.String("foobar") + buildSample.Spec.Source.GitSource.URL = "foobar" // Fake some client Get calls and ensure we populate all // different resources we could get during reconciliation @@ -451,8 +392,8 @@ var _ = Describe("Reconcile Build", func() { // skip validation because build references a sourceURL secret It("succeed when source URL is fake private URL because build reference a sourceURL secret", func() { buildSample := ctl.BuildWithClusterBuildStrategyAndSourceSecret(buildName, namespace, buildStrategyName) - buildSample.Spec.Source.URL = pointer.String("https://github.yourco.com/org/build-fake") - buildSample.Spec.Source.Credentials.Name = registrySecret + buildSample.Spec.Source.GitSource.URL = "https://github.yourco.com/org/build-fake" + buildSample.Spec.Source.GitSource.CloneSecret = pointer.String(registrySecret) // Fake some client Get calls and ensure we populate all // different resources we could get during reconciliation @@ -479,10 +420,8 @@ var _ = Describe("Reconcile Build", func() { Context("when environment variables are specified", func() { JustBeforeEach(func() { - buildSample.Spec.Source.Credentials = &corev1.LocalObjectReference{ - Name: "existing", - } - buildSample.Spec.Output.Credentials = nil + buildSample.Spec.Source.GitSource.CloneSecret = pointer.String("existing") + buildSample.Spec.Output.PushSecret = nil // Fake some client Get calls and ensure we populate all // different resources we could get during reconciliation 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..d4f247494a 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,16 @@ 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.NewBuildName(build), validate.NewEnv(build), ) @@ -178,18 +177,17 @@ func (r *ReconcileBuildRun) Reconcile(ctx context.Context, request reconcile.Req resources.ConditionBuildRegistrationFailed, ) } - // 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 +208,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 } @@ -253,11 +253,10 @@ func (r *ReconcileBuildRun) Reconcile(ctx context.Context, request reconcile.Req if err := r.client.Status().Update(ctx, buildRun); err != nil { return reconcile.Result{}, err } - // 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 +265,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 +292,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 +304,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 +323,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 +358,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 +407,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 +478,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 +505,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 +521,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 +530,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 +549,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/buildrun_test.go b/pkg/reconciler/buildrun/buildrun_test.go index 1f95f07649..527da60b41 100644 --- a/pkg/reconciler/buildrun/buildrun_test.go +++ b/pkg/reconciler/buildrun/buildrun_test.go @@ -29,12 +29,12 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" "github.com/shipwright-io/build/pkg/apis" - 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/controller/fakes" buildrunctl "github.com/shipwright-io/build/pkg/reconciler/buildrun" "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" ) var _ = Describe("Reconcile BuildRun", func() { @@ -1329,8 +1329,10 @@ var _ = Describe("Reconcile BuildRun", func() { Name: buildRunName, }, Spec: build.BuildRunSpec{ - BuildRef: &build.BuildRef{}, - BuildSpec: &build.BuildSpec{}, + Build: build.ReferencedBuild{ + Build: &build.BuildSpec{}, + Name: pointer.String("foobar"), + }, }, } @@ -1346,8 +1348,10 @@ var _ = Describe("Reconcile BuildRun", func() { Name: buildRunName, }, Spec: build.BuildRunSpec{ - Output: &build.Image{Image: "foo:bar"}, - BuildSpec: &build.BuildSpec{}, + Output: &build.Image{Image: "foo:bar"}, + Build: build.ReferencedBuild{ + Build: &build.BuildSpec{}, + }, }, } @@ -1367,7 +1371,9 @@ var _ = Describe("Reconcile BuildRun", func() { Name: "foo", SingleValue: &build.SingleValue{Value: pointer.String("bar")}, }}, - BuildSpec: &build.BuildSpec{}, + Build: build.ReferencedBuild{ + Build: &build.BuildSpec{}, + }, }, } @@ -1383,8 +1389,10 @@ var _ = Describe("Reconcile BuildRun", func() { Name: buildRunName, }, Spec: build.BuildRunSpec{ - Env: []corev1.EnvVar{{Name: "foo", Value: "bar"}}, - BuildSpec: &build.BuildSpec{}, + Env: []corev1.EnvVar{{Name: "foo", Value: "bar"}}, + Build: build.ReferencedBuild{ + Build: &build.BuildSpec{}, + }, }, } @@ -1400,8 +1408,10 @@ var _ = Describe("Reconcile BuildRun", func() { Name: buildRunName, }, Spec: build.BuildRunSpec{ - Timeout: &metav1.Duration{Duration: time.Second}, - BuildSpec: &build.BuildSpec{}, + Timeout: &metav1.Duration{Duration: time.Second}, + Build: build.ReferencedBuild{ + Build: &build.BuildSpec{}, + }, }, } @@ -1419,22 +1429,24 @@ var _ = Describe("Reconcile BuildRun", func() { Name: buildRunName, }, Spec: build.BuildRunSpec{ - BuildSpec: &build.BuildSpec{ - Source: build.Source{ - URL: pointer.String("https://github.com/shipwright-io/sample-go.git"), - ContextDir: pointer.String("source-build"), + Build: build.ReferencedBuild{ + Build: &build.BuildSpec{ + Source: build.Source{ + GitSource: &build.Git{ + URL: "https://github.com/shipwright-io/sample-go.git", + }, + ContextDir: pointer.String("source-build"), + }, + Strategy: build.Strategy{ + Kind: &clusterBuildStrategy, + Name: strategyName, + }, + Output: build.Image{ + Image: "foo/bar:latest", + }, }, - Strategy: build.Strategy{ - Kind: &clusterBuildStrategy, - Name: strategyName, - }, - Output: build.Image{ - Image: "foo/bar:latest", - }, - }, - ServiceAccount: &build.ServiceAccount{ - Generate: pointer.Bool(true), }, + ServiceAccount: pointer.String(".generated"), }, } @@ -1443,7 +1455,6 @@ var _ = Describe("Reconcile BuildRun", func() { case *build.BuildRun: buildRunSample.DeepCopyInto(object) return nil - case *build.ClusterBuildStrategy: ctl.ClusterBuildStrategy(strategyName).DeepCopyInto(object) return nil @@ -1468,7 +1479,6 @@ var _ = Describe("Reconcile BuildRun", func() { switch taskRun := o.(type) { case *pipelineapi.TaskRun: taskRunCreates++ - Expect(taskRun.Labels).ToNot(HaveKey(build.LabelBuild), "no build name label is suppose to be set") Expect(taskRun.Labels).ToNot(HaveKey(build.LabelBuildGeneration), "no build generation label is suppose to be set") } diff --git a/pkg/reconciler/buildrun/controller.go b/pkg/reconciler/buildrun/controller.go index 034c19906b..bc47d21fc9 100644 --- a/pkg/reconciler/buildrun/controller.go +++ b/pkg/reconciler/buildrun/controller.go @@ -23,7 +23,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" "sigs.k8s.io/controller-runtime/pkg/source" - 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" ) @@ -53,16 +53,16 @@ func add(mgr manager.Manager, r reconcile.Reconciler, maxConcurrentReconciles in predBuildRun := predicate.Funcs{ CreateFunc: func(e event.CreateEvent) bool { - o := e.Object.(*buildv1alpha1.BuildRun) + o := e.Object.(*buildv1beta1.BuildRun) // The CreateFunc is also called when the controller is started and iterates over all objects. For those BuildRuns that have a TaskRun referenced already, // we do not need to do a further reconciliation. BuildRun updates then only happen from the TaskRun. - return o.Status.LatestTaskRunRef == nil && o.Status.CompletionTime == nil + return o.Status.TaskRunName == nil && o.Status.CompletionTime == nil }, UpdateFunc: func(e event.UpdateEvent) bool { // Ignore updates to CR status in which case metadata.Generation does not change - o := e.ObjectOld.(*buildv1alpha1.BuildRun) - n := e.ObjectNew.(*buildv1alpha1.BuildRun) + o := e.ObjectOld.(*buildv1beta1.BuildRun) + n := e.ObjectNew.(*buildv1beta1.BuildRun) // Only reconcile a BuildRun update when // - it is set to canceled @@ -107,7 +107,7 @@ func add(mgr manager.Manager, r reconcile.Reconciler, maxConcurrentReconciles in } // Watch for changes to primary resource BuildRun - if err = c.Watch(&source.Kind{Type: &buildv1alpha1.BuildRun{}}, &handler.EnqueueRequestForObject{}, predBuildRun); err != nil { + if err = c.Watch(&source.Kind{Type: &buildv1beta1.BuildRun{}}, &handler.EnqueueRequestForObject{}, predBuildRun); err != nil { return err } @@ -117,7 +117,7 @@ func add(mgr manager.Manager, r reconcile.Reconciler, maxConcurrentReconciles in taskRun := o.(*pipelineapi.TaskRun) // check if TaskRun is related to BuildRun - if taskRun.GetLabels() == nil || taskRun.GetLabels()[buildv1alpha1.LabelBuildRun] == "" { + if taskRun.GetLabels() == nil || taskRun.GetLabels()[buildv1beta1.LabelBuildRun] == "" { return []reconcile.Request{} } diff --git a/pkg/reconciler/buildrun/resources/build.go b/pkg/reconciler/buildrun/resources/build.go index 72e8e419d1..b58d8d6430 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/build_test.go b/pkg/reconciler/buildrun/resources/build_test.go index c559f1447f..9814c77dc0 100644 --- a/pkg/reconciler/buildrun/resources/build_test.go +++ b/pkg/reconciler/buildrun/resources/build_test.go @@ -17,10 +17,10 @@ import ( "k8s.io/apimachinery/pkg/types" crc "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/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" ) var _ = Describe("Build Resource", func() { @@ -39,8 +39,8 @@ var _ = Describe("Build Resource", func() { Namespace: "bar", }, Spec: build.BuildRunSpec{ - BuildRef: &build.BuildRef{ - Name: buildName, + Build: build.ReferencedBuild{ + Name: &buildName, }, }, } @@ -136,8 +136,10 @@ var _ = Describe("Build Resource", func() { Namespace: "bar", }, Spec: build.BuildRunSpec{ - BuildSpec: &build.BuildSpec{ - Env: []v1.EnvVar{{Name: "foo", Value: "bar"}}, + Build: build.ReferencedBuild{ + Build: &build.BuildSpec{ + Env: []v1.EnvVar{{Name: "foo", Value: "bar"}}, + }, }, }, } diff --git a/pkg/reconciler/buildrun/resources/conditions.go b/pkg/reconciler/buildrun/resources/conditions.go index 3478096212..0d3ef8380a 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,22 @@ 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 = &buildv1beta1.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 +128,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 +142,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/conditions_test.go b/pkg/reconciler/buildrun/resources/conditions_test.go index 84661792ad..06dbe2fbcc 100644 --- a/pkg/reconciler/buildrun/resources/conditions_test.go +++ b/pkg/reconciler/buildrun/resources/conditions_test.go @@ -9,10 +9,10 @@ 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/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" pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" corev1 "k8s.io/api/core/v1" k8serrors "k8s.io/apimachinery/pkg/api/errors" diff --git a/pkg/reconciler/buildrun/resources/credentials.go b/pkg/reconciler/buildrun/resources/credentials.go index 2836acbf79..960c6eba36 100644 --- a/pkg/reconciler/buildrun/resources/credentials.go +++ b/pkg/reconciler/buildrun/resources/credentials.go @@ -9,51 +9,44 @@ 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 - if outputSecret != nil { - modified = updateServiceAccountIfSecretNotLinked(ctx, outputSecret, serviceAccount) || modified + if build.Spec.Output.PushSecret != nil { + modified = updateServiceAccountIfSecretNotLinked(ctx, build.Spec.Output.PushSecret, serviceAccount) || modified } } 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..91d29006ff 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,27 @@ 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", + build = &buildv1beta1.Build{ + Spec: buildv1beta1.BuildSpec{ + Source: buildv1beta1.Source{ + Type: buildv1beta1.GitType, + GitSource: &buildv1beta1.Git{ + URL: "a/b/c", + CloneSecret: pointer.String("secret_a"), }, }, - Builder: &buildv1alpha1.Image{ - Image: "quay.io/namespace/image", - Credentials: &corev1.LocalObjectReference{ - Name: "secret_docker.io", - }, - }, - 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"), }, }, } @@ -74,7 +65,6 @@ var _ = Describe("Credentials", func() { Secrets: []corev1.ObjectReference{ {Name: "secret_b"}, {Name: "secret_c"}, - {Name: "secret_docker.io"}, {Name: "secret_buildrun.io"}, }, } @@ -91,24 +81,25 @@ 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{ - URL: pointer.String("a/b/c"), - }, - Output: buildv1alpha1.Image{ - Credentials: &corev1.LocalObjectReference{ - Name: "secret_b", + build = &buildv1beta1.Build{ + Spec: buildv1beta1.BuildSpec{ + Source: buildv1beta1.Source{ + Type: buildv1beta1.GitType, + GitSource: &buildv1beta1.Git{ + URL: "a/b/c", }, }, + 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,20 +119,23 @@ var _ = Describe("Credentials", func() { Context("when build does not reference any secret", func() { BeforeEach(func() { - build = &buildv1alpha1.Build{ - Spec: buildv1alpha1.BuildSpec{ - Source: buildv1alpha1.Source{ - URL: pointer.String("a/b/c"), - Credentials: nil, + build = &buildv1beta1.Build{ + Spec: buildv1beta1.BuildSpec{ + Source: buildv1beta1.Source{ + Type: buildv1beta1.GitType, + GitSource: &buildv1beta1.Git{ + URL: "a/b/c", + CloneSecret: nil, + }, }, }, } // 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..0edbb5da2d 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" @@ -29,6 +29,7 @@ func UpdateBuildRunUsingTaskResults( taskRunResult []pipelineapi.TaskRunResult, request reconcile.Request, ) { + buildRun.Status.Source = &build.SourceResult{} // Set source results updateBuildRunStatusWithSourceResult(buildRun, taskRunResult) diff --git a/pkg/reconciler/buildrun/resources/results_test.go b/pkg/reconciler/buildrun/resources/results_test.go index 5196d8da4b..6085e83643 100644 --- a/pkg/reconciler/buildrun/resources/results_test.go +++ b/pkg/reconciler/buildrun/resources/results_test.go @@ -10,13 +10,12 @@ 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" - "k8s.io/utils/pointer" "sigs.k8s.io/controller-runtime/pkg/reconcile" ) @@ -50,8 +49,14 @@ var _ = Describe("TaskRun results to BuildRun", func() { It("should surface the TaskRun results emitting from default(git) source step", func() { commitSha := "0e0583421a5e4bf562ffe33f3651e16ba0c78591" - br.Status.BuildSpec.Source.URL = pointer.String("https://github.com/shipwright-io/sample-go") - + br.Status.BuildSpec = &build.BuildSpec{ + Source: build.Source{ + Type: build.GitType, + GitSource: &build.Git{ + URL: "https://github.com/shipwright-io/sample-go", + }, + }, + } tr.Status.Results = append(tr.Status.Results, pipelineapi.TaskRunResult{ Name: "shp-source-default-commit-sha", @@ -70,15 +75,20 @@ var _ = Describe("TaskRun results to BuildRun", func() { resources.UpdateBuildRunUsingTaskResults(ctx, br, tr.Status.Results, taskRunRequest) - Expect(len(br.Status.Sources)).To(Equal(1)) - Expect(br.Status.Sources[0].Git.CommitSha).To(Equal(commitSha)) - Expect(br.Status.Sources[0].Git.CommitAuthor).To(Equal("foo bar")) + Expect(br.Status.Source).ToNot(Equal(nil)) + Expect(br.Status.Source.Git.CommitSha).To(Equal(commitSha)) + Expect(br.Status.Source.Git.CommitAuthor).To(Equal("foo bar")) }) It("should surface the TaskRun results emitting from default(bundle) source step", func() { bundleImageDigest := "sha256:fe1b73cd25ac3f11dec752755e2" - br.Status.BuildSpec.Source.BundleContainer = &build.BundleContainer{ - Image: "ghcr.io/shipwright-io/sample-go/source-bundle:latest", + br.Status.BuildSpec = &build.BuildSpec{ + Source: build.Source{ + Type: build.OCIArtifactType, + OCIArtifact: &build.OCIArtifact{ + Image: "ghcr.io/shipwright-io/sample-go/source-bundle:latest", + }, + }, } tr.Status.Results = append(tr.Status.Results, @@ -92,8 +102,8 @@ var _ = Describe("TaskRun results to BuildRun", func() { resources.UpdateBuildRunUsingTaskResults(ctx, br, tr.Status.Results, taskRunRequest) - Expect(len(br.Status.Sources)).To(Equal(1)) - Expect(br.Status.Sources[0].Bundle.Digest).To(Equal(bundleImageDigest)) + Expect(br.Status.Source).ToNot(Equal(nil)) + Expect(br.Status.Source.OciArtifact.Digest).To(Equal(bundleImageDigest)) }) It("should surface the TaskRun results emitting from output step", func() { @@ -124,7 +134,14 @@ var _ = Describe("TaskRun results to BuildRun", func() { It("should surface the TaskRun results emitting from source and output step", func() { commitSha := "0e0583421a5e4bf562ffe33f3651e16ba0c78591" imageDigest := "sha256:fe1b73cd25ac3f11dec752755e2" - br.Status.BuildSpec.Source.URL = pointer.String("https://github.com/shipwright-io/sample-go") + br.Status.BuildSpec = &build.BuildSpec{ + Source: build.Source{ + Type: build.GitType, + GitSource: &build.Git{ + URL: "https://github.com/shipwright-io/sample-go", + }, + }, + } tr.Status.Results = append(tr.Status.Results, pipelineapi.TaskRunResult{ @@ -158,9 +175,9 @@ var _ = Describe("TaskRun results to BuildRun", func() { resources.UpdateBuildRunUsingTaskResults(ctx, br, tr.Status.Results, taskRunRequest) - Expect(len(br.Status.Sources)).To(Equal(1)) - Expect(br.Status.Sources[0].Git.CommitSha).To(Equal(commitSha)) - Expect(br.Status.Sources[0].Git.CommitAuthor).To(Equal("foo bar")) + Expect(br.Status.Source).ToNot(Equal(nil)) + Expect(br.Status.Source.Git.CommitSha).To(Equal(commitSha)) + Expect(br.Status.Source.Git.CommitAuthor).To(Equal("foo bar")) Expect(br.Status.Output.Digest).To(Equal(imageDigest)) Expect(br.Status.Output.Size).To(Equal(int64(230))) }) diff --git a/pkg/reconciler/buildrun/resources/service_accounts.go b/pkg/reconciler/buildrun/resources/service_accounts.go index 38cd815f3d..3bfd61d773 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,17 @@ 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 +func IsGeneratedServiceAccountUsed(buildRun *buildv1beta1.BuildRun) bool { + return buildRun.Spec.ServiceAccount != nil && *buildRun.Spec.ServiceAccount == ".generated" } // 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 +60,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 +87,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 +102,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 +123,13 @@ 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) { +func RetrieveServiceAccount(ctx context.Context, client client.Client, build *buildv1beta1.Build, buildRun *buildv1beta1.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 + if buildRun.Spec.ServiceAccount != nil { + serviceAccountName := *buildRun.Spec.ServiceAccount // here we might need to update Status Conditions and Fail the BR serviceAccount = &corev1.ServiceAccount{} @@ -144,7 +139,6 @@ func RetrieveServiceAccount(ctx context.Context, client client.Client, build *bu return nil, HandleError("failed to retrieve service account", err, updateErr) } } - return nil, err } diff --git a/pkg/reconciler/buildrun/resources/service_accounts_test.go b/pkg/reconciler/buildrun/resources/service_accounts_test.go index 2e36bdfefb..2534fa3968 100644 --- a/pkg/reconciler/buildrun/resources/service_accounts_test.go +++ b/pkg/reconciler/buildrun/resources/service_accounts_test.go @@ -10,10 +10,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 +26,7 @@ var _ = Describe("Operating service accounts", func() { client *fakes.FakeClient ctl test.Catalog buildName, buildRunName string - buildRunSample *buildv1alpha1.BuildRun + buildRunSample *buildv1beta1.BuildRun ) BeforeEach(func() { @@ -113,7 +113,7 @@ var _ = Describe("Operating service accounts", func() { statusWriter := &fakes.FakeStatusWriter{} statusWriter.UpdateCalls(func(_ context.Context, object crc.Object, _ ...crc.SubResourceUpdateOption) error { switch object.(type) { - case *buildv1alpha1.BuildRun: + case *buildv1beta1.BuildRun: return fmt.Errorf("failed") } return nil @@ -128,7 +128,7 @@ var _ = Describe("Operating service accounts", func() { }) }) - Context("Retrieving autogenerated service accounts when the spec.serviceAccount.generate key is used", func() { + Context("Retrieving autogenerated service accounts when the spec.serviceAccount .generated value is used", func() { It("should provide a generated sa name", func() { Expect(resources.GetGeneratedServiceAccountName(buildRunSample)).To(Equal(buildRunSample.Name)) @@ -147,7 +147,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..93eb105708 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,19 +17,18 @@ 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.Local { - sources = append(sources, build.Spec.Sources...) - sources = append(sources, buildRun.Spec.Sources...) + if buildRun.Spec.Source != nil && buildRun.Spec.Source.Type == buildv1beta1.LocalType { + return buildRun.Spec.Source.LocalSource + } - for _, source := range sources { - if source.Type == buildv1alpha1.LocalCopy { - return &source - } + if build.Spec.Source.Type == buildv1beta1.LocalType { + return build.Spec.Source.LocalSource } + return nil } @@ -38,40 +37,33 @@ 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) } else { - // create the step for spec.source, either Git or Bundle - switch { - case build.Spec.Source.BundleContainer != nil: - sources.AppendBundleStep(cfg, taskSpec, build.Spec.Source, defaultSourceName) - case build.Spec.Source.URL != nil: - sources.AppendGitStep(cfg, taskSpec, build.Spec.Source, defaultSourceName) - } - } - // 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 { - sources.AppendHTTPStep(cfg, taskSpec, source) + // create the step for spec.source, either Git or Bundle + switch build.Spec.Source.Type { + case buildv1beta1.OCIArtifactType: + if build.Spec.Source.OCIArtifact != nil { + sources.AppendBundleStep(cfg, taskSpec, build.Spec.Source.OCIArtifact, defaultSourceName) + } + case buildv1beta1.GitType: + sources.AppendGitStep(cfg, taskSpec, *build.Spec.Source.GitSource, defaultSourceName) } } } -func updateBuildRunStatusWithSourceResult(buildrun *buildv1alpha1.BuildRun, results []pipelineapi.TaskRunResult) { +func updateBuildRunStatusWithSourceResult(buildrun *buildv1beta1.BuildRun, results []pipelineapi.TaskRunResult) { buildSpec := buildrun.Status.BuildSpec switch { - case buildSpec.Source.BundleContainer != nil: + case buildSpec.Source.Type == buildv1beta1.OCIArtifactType && buildSpec.Source.OCIArtifact != nil: sources.AppendBundleResult(buildrun, defaultSourceName, results) - case buildSpec.Source.URL != nil: + case buildSpec.Source.Type == buildv1beta1.GitType && buildSpec.Source.GitSource != nil: sources.AppendGitResult(buildrun, defaultSourceName, results) } - - // no results for HTTP sources yet } diff --git a/pkg/reconciler/buildrun/resources/sources/bundle.go b/pkg/reconciler/buildrun/resources/sources/bundle.go index 8b7eda6402..97d06e9242 100644 --- a/pkg/reconciler/buildrun/resources/sources/bundle.go +++ b/pkg/reconciler/buildrun/resources/sources/bundle.go @@ -10,19 +10,14 @@ import ( core "k8s.io/api/core/v1" - 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" pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" ) // AppendBundleStep appends the bundle step to the TaskSpec -func AppendBundleStep( - cfg *config.Config, - taskSpec *pipelineapi.TaskSpec, - source build.Source, - name string, -) { +func AppendBundleStep(cfg *config.Config, taskSpec *pipelineapi.TaskSpec, oci *build.OCIArtifact, name string) { // append the result taskSpec.Results = append(taskSpec.Results, pipelineapi.TaskResult{ Name: fmt.Sprintf("%s-source-%s-image-digest", prefixParamsResultsVolumes, name), @@ -36,7 +31,7 @@ func AppendBundleStep( ImagePullPolicy: cfg.BundleContainerTemplate.ImagePullPolicy, Command: cfg.BundleContainerTemplate.Command, Args: []string{ - "--image", source.BundleContainer.Image, + "--image", oci.Image, "--target", fmt.Sprintf("$(params.%s-%s)", prefixParamsResultsVolumes, paramSourceRoot), "--result-file-image-digest", fmt.Sprintf("$(results.%s-source-%s-image-digest.path)", prefixParamsResultsVolumes, name), }, @@ -47,14 +42,14 @@ func AppendBundleStep( } // add credentials mount, if provided - if source.Credentials != nil { - AppendSecretVolume(taskSpec, source.Credentials.Name) + if oci.PullSecret != nil { + AppendSecretVolume(taskSpec, *oci.PullSecret) secretMountPath := fmt.Sprintf("/workspace/%s-pull-secret", prefixParamsResultsVolumes) // define the volume mount on the container bundleStep.VolumeMounts = append(bundleStep.VolumeMounts, core.VolumeMount{ - Name: SanitizeVolumeNameForSecretName(source.Credentials.Name), + Name: SanitizeVolumeNameForSecretName(*oci.PullSecret), MountPath: secretMountPath, ReadOnly: true, }) @@ -66,7 +61,7 @@ func AppendBundleStep( } // add prune flag in when prune after pull is configured - if source.BundleContainer.Prune != nil && *source.BundleContainer.Prune == build.PruneAfterPull { + if oci.Prune != nil && *oci.Prune == build.PruneAfterPull { bundleStep.Args = append(bundleStep.Args, "--prune") } @@ -76,13 +71,9 @@ func AppendBundleStep( // AppendBundleResult append bundle source result to build run func AppendBundleResult(buildRun *build.BuildRun, name string, results []pipelineapi.TaskRunResult) { imageDigest := findResultValue(results, fmt.Sprintf("%s-source-%s-image-digest", prefixParamsResultsVolumes, name)) - if strings.TrimSpace(imageDigest) != "" { - buildRun.Status.Sources = append(buildRun.Status.Sources, build.SourceResult{ - Name: name, - Bundle: &build.BundleSourceResult{ - Digest: imageDigest, - }, - }) + buildRun.Status.Source.OciArtifact = &build.OciArtifactSourceResult{ + Digest: imageDigest, + } } } diff --git a/pkg/reconciler/buildrun/resources/sources/git.go b/pkg/reconciler/buildrun/resources/sources/git.go index 640e2c7af2..e88b7e1fec 100644 --- a/pkg/reconciler/buildrun/resources/sources/git.go +++ b/pkg/reconciler/buildrun/resources/sources/git.go @@ -8,7 +8,8 @@ import ( "fmt" "strings" - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/config" pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" corev1 "k8s.io/api/core/v1" @@ -24,7 +25,7 @@ const ( func AppendGitStep( cfg *config.Config, taskSpec *pipelineapi.TaskSpec, - source buildv1alpha1.Source, + git buildv1alpha1.Git, name string, ) { // append the result @@ -47,7 +48,7 @@ func AppendGitStep( Command: cfg.GitContainerTemplate.Command, Args: []string{ "--url", - *source.URL, + git.URL, "--target", fmt.Sprintf("$(params.%s-%s)", prefixParamsResultsVolumes, paramSourceRoot), "--result-file-commit-sha", @@ -68,12 +69,12 @@ func AppendGitStep( } // Check if a revision is defined - if source.Revision != nil { + if git.Revision != nil { // append the argument gitStep.Args = append( gitStep.Args, "--revision", - *source.Revision, + *git.Revision, ) } @@ -82,15 +83,15 @@ func AppendGitStep( gitStep.Args = append(gitStep.Args, "--git-url-rewrite") } - if source.Credentials != nil { + if git.CloneSecret != nil { // ensure the value is there - AppendSecretVolume(taskSpec, source.Credentials.Name) + AppendSecretVolume(taskSpec, *git.CloneSecret) secretMountPath := fmt.Sprintf("/workspace/%s-source-secret", prefixParamsResultsVolumes) // define the volume mount on the container gitStep.VolumeMounts = append(gitStep.VolumeMounts, corev1.VolumeMount{ - Name: SanitizeVolumeNameForSecretName(source.Credentials.Name), + Name: SanitizeVolumeNameForSecretName(*git.CloneSecret), MountPath: secretMountPath, ReadOnly: true, }) @@ -114,13 +115,10 @@ func AppendGitResult(buildRun *buildv1alpha1.BuildRun, name string, results []pi branchName := findResultValue(results, fmt.Sprintf("%s-source-%s-%s", prefixParamsResultsVolumes, name, branchName)) if strings.TrimSpace(commitAuthor) != "" || strings.TrimSpace(commitSha) != "" || strings.TrimSpace(branchName) != "" { - buildRun.Status.Sources = append(buildRun.Status.Sources, buildv1alpha1.SourceResult{ - Name: name, - Git: &buildv1alpha1.GitSourceResult{ - CommitAuthor: commitAuthor, - CommitSha: commitSha, - BranchName: branchName, - }, - }) + buildRun.Status.Source.Git = &v1beta1.GitSourceResult{ + CommitAuthor: commitAuthor, + CommitSha: commitSha, + BranchName: branchName, + } } } diff --git a/pkg/reconciler/buildrun/resources/sources/git_test.go b/pkg/reconciler/buildrun/resources/sources/git_test.go index 2f97e64b57..69c951ecf6 100644 --- a/pkg/reconciler/buildrun/resources/sources/git_test.go +++ b/pkg/reconciler/buildrun/resources/sources/git_test.go @@ -8,12 +8,11 @@ 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/config" "github.com/shipwright-io/build/pkg/reconciler/buildrun/resources/sources" pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" - corev1 "k8s.io/api/core/v1" "k8s.io/utils/pointer" ) @@ -30,8 +29,8 @@ var _ = Describe("Git", func() { }) JustBeforeEach(func() { - sources.AppendGitStep(cfg, taskSpec, buildv1alpha1.Source{ - URL: pointer.String("https://github.com/shipwright-io/build"), + sources.AppendGitStep(cfg, taskSpec, buildv1beta1.Git{ + URL: "https://github.com/shipwright-io/build", }, "default") }) @@ -74,11 +73,9 @@ var _ = Describe("Git", func() { }) JustBeforeEach(func() { - sources.AppendGitStep(cfg, taskSpec, buildv1alpha1.Source{ - URL: pointer.String("git@github.com:shipwright-io/build.git"), - Credentials: &corev1.LocalObjectReference{ - Name: "a.secret", - }, + sources.AppendGitStep(cfg, taskSpec, buildv1beta1.Git{ + URL: "git@github.com:shipwright-io/build.git", + CloneSecret: pointer.String("a.secret"), }, "default") }) diff --git a/pkg/reconciler/buildrun/resources/sources/http.go b/pkg/reconciler/buildrun/resources/sources/http.go deleted file mode 100644 index 28bbf1805e..0000000000 --- a/pkg/reconciler/buildrun/resources/sources/http.go +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright The Shipwright Contributors -// -// SPDX-License-Identifier: Apache-2.0 - -package sources - -import ( - "fmt" - - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" - "github.com/shipwright-io/build/pkg/config" - pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" -) - -// RemoteArtifactsContainerName name for the container dealing with remote artifacts download. -const RemoteArtifactsContainerName = "sources-http" - -// AppendHTTPStep appends the step for a HTTP source to the TaskSpec -func AppendHTTPStep( - cfg *config.Config, - taskSpec *pipelineapi.TaskSpec, - source buildv1alpha1.BuildSource, -) { - // HTTP is done currently all in a single step, see if there is already one - httpStep := findExistingHTTPSourcesStep(taskSpec) - if httpStep != nil { - httpStep.Args[3] = fmt.Sprintf("%s ; wget %q", httpStep.Args[3], source.URL) - } else { - httpStep := pipelineapi.Step{ - Name: RemoteArtifactsContainerName, - Image: cfg.RemoteArtifactsContainerImage, - WorkingDir: fmt.Sprintf("$(params.%s-%s)", prefixParamsResultsVolumes, paramSourceRoot), - Command: []string{ - "/bin/sh", - }, - Args: []string{ - "-e", - "-x", - "-c", - fmt.Sprintf("wget %q", source.URL), - }, - } - - // append the git step - taskSpec.Steps = append(taskSpec.Steps, httpStep) - } -} - -func findExistingHTTPSourcesStep(taskSpec *pipelineapi.TaskSpec) *pipelineapi.Step { - for _, candidateStep := range taskSpec.Steps { - if candidateStep.Name == RemoteArtifactsContainerName { - return &candidateStep - } - } - return nil -} diff --git a/pkg/reconciler/buildrun/resources/sources/http_test.go b/pkg/reconciler/buildrun/resources/sources/http_test.go deleted file mode 100644 index b2f8083be9..0000000000 --- a/pkg/reconciler/buildrun/resources/sources/http_test.go +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright The Shipwright Contributors -// -// SPDX-License-Identifier: Apache-2.0 - -package sources_test - -import ( - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" - "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" -) - -var _ = Describe("HTTP", func() { - - cfg := config.NewDefaultConfig() - - Context("when a TaskSpec does not contain an step", func() { - var taskSpec *pipelineapi.TaskSpec - - BeforeEach(func() { - taskSpec = &pipelineapi.TaskSpec{} - }) - - It("adds the first step", func() { - sources.AppendHTTPStep(cfg, taskSpec, buildv1alpha1.BuildSource{ - Name: "logo", - URL: "https://shipwright.io/icons/logo.svg", - }) - - Expect(len(taskSpec.Steps)).To(Equal(1)) - Expect(taskSpec.Steps[0].Name).To(Equal(sources.RemoteArtifactsContainerName)) - Expect(taskSpec.Steps[0].Image).To(Equal(cfg.RemoteArtifactsContainerImage)) - Expect(taskSpec.Steps[0].WorkingDir).To(Equal("$(params.shp-source-root)")) - Expect(taskSpec.Steps[0].Args[3]).To(Equal("wget \"https://shipwright.io/icons/logo.svg\"")) - }) - }) - - Context("when a TaskSpec already contains the http step", func() { - var taskSpec *pipelineapi.TaskSpec - - BeforeEach(func() { - taskSpec = &pipelineapi.TaskSpec{ - Steps: []pipelineapi.Step{ - { - Name: sources.RemoteArtifactsContainerName, - Image: cfg.RemoteArtifactsContainerImage, - WorkingDir: "$(params.shp-source-root)", - Command: []string{ - "/bin/sh", - }, - Args: []string{ - "-e", - "-x", - "-c", - "wget \"https://tekton.dev/images/tekton-horizontal-color.png\"", - }, - }, - }, - } - }) - - It("updates the existing step", func() { - sources.AppendHTTPStep(cfg, taskSpec, buildv1alpha1.BuildSource{ - Name: "logo", - URL: "https://shipwright.io/icons/logo.svg", - }) - - Expect(len(taskSpec.Steps)).To(Equal(1)) - Expect(taskSpec.Steps[0].Name).To(Equal(sources.RemoteArtifactsContainerName)) - Expect(taskSpec.Steps[0].Image).To(Equal(cfg.RemoteArtifactsContainerImage)) - Expect(taskSpec.Steps[0].WorkingDir).To(Equal("$(params.shp-source-root)")) - Expect(taskSpec.Steps[0].Args[3]).To(Equal("wget \"https://tekton.dev/images/tekton-horizontal-color.png\" ; wget \"https://shipwright.io/icons/logo.svg\"")) - }) - }) - - Context("when a TaskSpec already another source step step", func() { - var taskSpec *pipelineapi.TaskSpec - - BeforeEach(func() { - taskSpec = &pipelineapi.TaskSpec{ - Steps: []pipelineapi.Step{ - { - Name: "source-something", - }, - }, - } - }) - - It("appends the http step", func() { - sources.AppendHTTPStep(cfg, taskSpec, buildv1alpha1.BuildSource{ - Name: "logo", - URL: "https://shipwright.io/icons/logo.svg", - }) - - Expect(len(taskSpec.Steps)).To(Equal(2)) - Expect(taskSpec.Steps[1].Name).To(Equal(sources.RemoteArtifactsContainerName)) - Expect(taskSpec.Steps[1].Image).To(Equal(cfg.RemoteArtifactsContainerImage)) - Expect(taskSpec.Steps[1].WorkingDir).To(Equal("$(params.shp-source-root)")) - Expect(taskSpec.Steps[1].Args[3]).To(Equal("wget \"https://shipwright.io/icons/logo.svg\"")) - }) - }) -}) 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/steps/security_context_test.go b/pkg/reconciler/buildrun/resources/steps/security_context_test.go index a3de510633..e8a0f48ca9 100644 --- a/pkg/reconciler/buildrun/resources/steps/security_context_test.go +++ b/pkg/reconciler/buildrun/resources/steps/security_context_test.go @@ -9,7 +9,7 @@ import ( "github.com/shipwright-io/build/pkg/reconciler/buildrun/resources/steps" - 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" @@ -21,30 +21,24 @@ import ( var _ = Describe("UpdateSecurityContext", func() { var buildStrategySecurityContext *buildapi.BuildStrategySecurityContext - var buildStrategySteps []buildapi.BuildStep + var buildStrategySteps []buildapi.Step var taskRunSpec *pipelineapi.TaskSpec var taskRunAnnotations map[string]string BeforeEach(func() { - buildStrategySteps = []buildapi.BuildStep{{ - Container: corev1.Container{ - Name: "first-step", - SecurityContext: &corev1.SecurityContext{ - RunAsUser: pointer.Int64(891), - RunAsGroup: pointer.Int64(1210), - }, + buildStrategySteps = []buildapi.Step{{ + Name: "first-step", + SecurityContext: &corev1.SecurityContext{ + RunAsUser: pointer.Int64(891), + RunAsGroup: pointer.Int64(1210), }, }, { - Container: corev1.Container{ - Name: "second-step", - SecurityContext: &corev1.SecurityContext{ - RunAsUser: pointer.Int64(891), - }, + Name: "second-step", + SecurityContext: &corev1.SecurityContext{ + RunAsUser: pointer.Int64(891), }, }, { - Container: corev1.Container{ - Name: "third-step", - }, + Name: "third-step", }} taskRunSpec = &pipelineapi.TaskSpec{ 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..0fd3d69a78 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" @@ -31,8 +31,6 @@ const ( workspaceSource = "source" - inputParamBuilder = "BUILDER_IMAGE" - inputParamDockerfile = "DOCKERFILE" inputParamContextDir = "CONTEXT_DIR" ) @@ -44,9 +42,6 @@ func getStringTransformations(fullText string) string { // this will be removed, build strategy author should use $(params.shp-output-image) directly "$(build.output.image)": fmt.Sprintf("$(params.%s-%s)", prefixParamsResultsVolumes, paramOutputImage), - "$(build.builder.image)": fmt.Sprintf("$(inputs.params.%s)", inputParamBuilder), - "$(build.dockerfile)": fmt.Sprintf("$(inputs.params.%s)", inputParamDockerfile), - // this will be removed, build strategy author should use $(params.shp-source-context); it is still needed by the ko build // strategy that mis-uses this setting to store the path to the main package; requires strategy parameter support to get rid "$(build.source.contextDir)": fmt.Sprintf("$(inputs.params.%s)", inputParamContextDir), @@ -62,22 +57,14 @@ 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{ - { - Description: "Path to the Dockerfile", - Name: inputParamDockerfile, - Default: &pipelineapi.ParamValue{ - Type: pipelineapi.ParamTypeString, - StringVal: "Dockerfile", - }, - }, { // CONTEXT_DIR comes from the git source specification // in the Build object @@ -119,18 +106,6 @@ 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) - } - // define the results, steps and volumes for sources, or alternatively, wait for user upload AmendTaskSpecWithSources(cfg, &generatedTaskSpec, build, buildRun) @@ -145,7 +120,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 +129,7 @@ func GenerateTaskSpec( } } - case buildv1alpha1.ParameterTypeArray: + case buildv1beta1.ParameterTypeArray: param.Type = pipelineapi.ParamTypeArray if parameterDefinition.Defaults != nil { param.Default = &pipelineapi.ParamValue{ @@ -239,10 +214,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 +249,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 +324,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 +373,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 +395,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..b6ce5a4bd7 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,10 +67,10 @@ 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)", + "bud", "--tag=$(params.shp-output-image)", "--file=$(params.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", @@ -147,7 +147,6 @@ var _ = Describe("GenerateTaskrun", func() { // legacy params Expect(got.Params).ToNot(utils.ContainNamedElement("BUILDER_IMAGE")) // test build has no builder image Expect(got.Params).To(utils.ContainNamedElement("CONTEXT_DIR")) - Expect(got.Params).To(utils.ContainNamedElement("DOCKERFILE")) Expect(len(got.Params)).To(Equal(6)) }) @@ -240,9 +239,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 +254,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 +271,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 +288,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 +306,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 +322,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 +363,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 +419,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 +449,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 +501,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() { @@ -537,11 +536,11 @@ var _ = Describe("GenerateTaskrun", func() { paramOutputInsecureFound = true Expect(param.Value.StringVal).To(Equal("false")) - case "BUILDER_IMAGE": + case "builder-image": paramBuilderImageFound = true Expect(param.Value.StringVal).To(Equal(builderImage.Image)) - case "DOCKERFILE": + case "dockerfile": paramDockerfileFound = true Expect(param.Value.StringVal).To(Equal(dockerfile)) 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..169d835cc5 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,13 @@ 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 +119,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) } diff --git a/pkg/volumes/volumes_test.go b/pkg/volumes/volumes_test.go index 8daafca3b5..a40ebb8c03 100644 --- a/pkg/volumes/volumes_test.go +++ b/pkg/volumes/volumes_test.go @@ -8,7 +8,7 @@ import ( "reflect" "testing" - 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/volumes" corev1 "k8s.io/api/core/v1" ) @@ -55,11 +55,10 @@ func createVolumeSource(vt volumeType, vsName string) *corev1.VolumeSource { case emptyDirVT: vs = createEmptyDirVolumeSource() } - return vs } -func createBuildStrategyVolume(name string, description string, vt volumeType, vsName string, overridable bool) buildv1alpha1.BuildStrategyVolume { +func createBuildStrategyVolume(name string, description string, vt volumeType, vsName string, overridable bool) buildv1beta1.BuildStrategyVolume { vs := createVolumeSource(vt, vsName) var descr *string @@ -67,7 +66,7 @@ func createBuildStrategyVolume(name string, description string, vt volumeType, v descr = &description } - bv := buildv1alpha1.BuildStrategyVolume{ + bv := buildv1beta1.BuildStrategyVolume{ Name: name, Description: descr, VolumeSource: *vs, @@ -76,7 +75,7 @@ func createBuildStrategyVolume(name string, description string, vt volumeType, v return bv } -func createBuildStrategyVolumeEmptyOverridable(name string, description string, vt volumeType, vsName string) buildv1alpha1.BuildStrategyVolume { +func createBuildStrategyVolumeEmptyOverridable(name string, description string, vt volumeType, vsName string) buildv1beta1.BuildStrategyVolume { vs := createVolumeSource(vt, vsName) var descr *string @@ -84,7 +83,7 @@ func createBuildStrategyVolumeEmptyOverridable(name string, description string, descr = &description } - bv := buildv1alpha1.BuildStrategyVolume{ + bv := buildv1beta1.BuildStrategyVolume{ Name: name, Description: descr, VolumeSource: *vs, @@ -92,17 +91,11 @@ func createBuildStrategyVolumeEmptyOverridable(name string, description string, return bv } -func createBuildVolume(name string, description string, vt volumeType, vsName string) buildv1alpha1.BuildVolume { +func createBuildVolume(name string, vt volumeType, vsName string) buildv1beta1.BuildVolume { vs := createVolumeSource(vt, vsName) - var descr *string - if len(description) > 0 { - descr = &description - } - - bv := buildv1alpha1.BuildVolume{ + bv := buildv1beta1.BuildVolume{ Name: name, - Description: descr, VolumeSource: *vs, } return bv @@ -112,90 +105,90 @@ func TestMergeVolumes(t *testing.T) { testingData := []struct { name string - into []buildv1alpha1.BuildStrategyVolume - mergers []buildv1alpha1.BuildVolume - expected []buildv1alpha1.BuildStrategyVolume + into []buildv1beta1.BuildStrategyVolume + mergers []buildv1beta1.BuildVolume + expected []buildv1beta1.BuildStrategyVolume expectErr bool }{ { name: "both empty", - into: []buildv1alpha1.BuildStrategyVolume{}, - mergers: []buildv1alpha1.BuildVolume{}, - expected: []buildv1alpha1.BuildStrategyVolume{}, + into: []buildv1beta1.BuildStrategyVolume{}, + mergers: []buildv1beta1.BuildVolume{}, + expected: []buildv1beta1.BuildStrategyVolume{}, expectErr: false, }, { name: "mergers empty", - into: []buildv1alpha1.BuildStrategyVolume{ + into: []buildv1beta1.BuildStrategyVolume{ createBuildStrategyVolume("bvname", "bv description", "ConfigMap", "my-config", true), }, - mergers: []buildv1alpha1.BuildVolume{}, - expected: []buildv1alpha1.BuildStrategyVolume{ + mergers: []buildv1beta1.BuildVolume{}, + expected: []buildv1beta1.BuildStrategyVolume{ createBuildStrategyVolume("bvname", "bv description", "ConfigMap", "my-config", true), }, expectErr: false, }, { name: "into empty must fail", - into: []buildv1alpha1.BuildStrategyVolume{}, - mergers: []buildv1alpha1.BuildVolume{ - createBuildVolume("bvname", "bv description", "ConfigMap", "my-config"), + into: []buildv1beta1.BuildStrategyVolume{}, + mergers: []buildv1beta1.BuildVolume{ + createBuildVolume("bvname", "ConfigMap", "my-config"), }, - expected: []buildv1alpha1.BuildStrategyVolume{ + expected: []buildv1beta1.BuildStrategyVolume{ createBuildStrategyVolume("bvname", "bv description", "ConfigMap", "my-config", true), }, expectErr: true, }, { name: "override one emptyDir with secret", - into: []buildv1alpha1.BuildStrategyVolume{ + into: []buildv1beta1.BuildStrategyVolume{ createBuildStrategyVolume("bvname", "bv description", "EmptyDir", "", true), }, - mergers: []buildv1alpha1.BuildVolume{ - createBuildVolume("bvname", "bv description 2", "ConfigMap", "my-config"), + mergers: []buildv1beta1.BuildVolume{ + createBuildVolume("bvname", "ConfigMap", "my-config"), }, - expected: []buildv1alpha1.BuildStrategyVolume{ + expected: []buildv1beta1.BuildStrategyVolume{ createBuildStrategyVolume("bvname", "bv description", "ConfigMap", "my-config", true), }, expectErr: false, }, { name: "connot override - not overridable, expecting error", - into: []buildv1alpha1.BuildStrategyVolume{ + into: []buildv1beta1.BuildStrategyVolume{ createBuildStrategyVolume("bvname", "bv description", "EmptyDir", "", false), }, - mergers: []buildv1alpha1.BuildVolume{ - createBuildVolume("bvname", "bv description 2", "ConfigMap", "my-config"), + mergers: []buildv1beta1.BuildVolume{ + createBuildVolume("bvname", "ConfigMap", "my-config"), }, - expected: []buildv1alpha1.BuildStrategyVolume{ + expected: []buildv1beta1.BuildStrategyVolume{ createBuildStrategyVolume("bvname", "bv description", "ConfigMap", "my-config", true), }, expectErr: true, }, { name: "connot override - volume does not exist, must produce err", - into: []buildv1alpha1.BuildStrategyVolume{ + into: []buildv1beta1.BuildStrategyVolume{ createBuildStrategyVolume("bvname", "bv description", "EmptyDir", "", true), }, - mergers: []buildv1alpha1.BuildVolume{ - createBuildVolume("bvname2", "bv description 2", "ConfigMap", "my-config"), + mergers: []buildv1beta1.BuildVolume{ + createBuildVolume("bvname2", "ConfigMap", "my-config"), }, - expected: []buildv1alpha1.BuildStrategyVolume{ + expected: []buildv1beta1.BuildStrategyVolume{ createBuildStrategyVolume("bvname", "bv description", "EmptyDir", "", true), }, expectErr: true, }, { name: "override second", - into: []buildv1alpha1.BuildStrategyVolume{ + into: []buildv1beta1.BuildStrategyVolume{ createBuildStrategyVolume("bvname", "bv description", "EmptyDir", "", false), createBuildStrategyVolume("bvname2", "bv description 2", "ConfigMap", "config-name", true), createBuildStrategyVolume("bvname3", "bv description 3", "Secret", "very-secret-name", true), }, - mergers: []buildv1alpha1.BuildVolume{ - createBuildVolume("bvname2", "bv description 4", "Secret", "secret-name"), + mergers: []buildv1beta1.BuildVolume{ + createBuildVolume("bvname2", "Secret", "secret-name"), }, - expected: []buildv1alpha1.BuildStrategyVolume{ + expected: []buildv1beta1.BuildStrategyVolume{ createBuildStrategyVolume("bvname", "bv description", "EmptyDir", "", false), createBuildStrategyVolume("bvname2", "bv description 2", "Secret", "secret-name", true), createBuildStrategyVolume("bvname3", "bv description 3", "Secret", "very-secret-name", true), @@ -204,15 +197,15 @@ func TestMergeVolumes(t *testing.T) { }, { name: "override first", - into: []buildv1alpha1.BuildStrategyVolume{ + into: []buildv1beta1.BuildStrategyVolume{ createBuildStrategyVolume("bvname", "bv description", "EmptyDir", "", true), createBuildStrategyVolume("bvname2", "bv description 2", "ConfigMap", "config-name", false), createBuildStrategyVolume("bvname3", "bv description 3", "Secret", "very-secret-name", false), }, - mergers: []buildv1alpha1.BuildVolume{ - createBuildVolume("bvname", "bv description 4", "Secret", "secret-name"), + mergers: []buildv1beta1.BuildVolume{ + createBuildVolume("bvname", "Secret", "secret-name"), }, - expected: []buildv1alpha1.BuildStrategyVolume{ + expected: []buildv1beta1.BuildStrategyVolume{ createBuildStrategyVolume("bvname", "bv description", "Secret", "secret-name", true), createBuildStrategyVolume("bvname2", "bv description 2", "ConfigMap", "config-name", false), createBuildStrategyVolume("bvname3", "bv description 3", "Secret", "very-secret-name", false), @@ -221,15 +214,15 @@ func TestMergeVolumes(t *testing.T) { }, { name: "override third", - into: []buildv1alpha1.BuildStrategyVolume{ + into: []buildv1beta1.BuildStrategyVolume{ createBuildStrategyVolume("bvname", "bv description", "EmptyDir", "", true), createBuildStrategyVolume("bvname2", "bv description 2", "ConfigMap", "config-name", false), createBuildStrategyVolume("bvname3", "bv description 3", "Secret", "very-secret-name", true), }, - mergers: []buildv1alpha1.BuildVolume{ - createBuildVolume("bvname3", "bv description 4", "EmptyDir", ""), + mergers: []buildv1beta1.BuildVolume{ + createBuildVolume("bvname3", "EmptyDir", ""), }, - expected: []buildv1alpha1.BuildStrategyVolume{ + expected: []buildv1beta1.BuildStrategyVolume{ createBuildStrategyVolume("bvname", "bv description", "EmptyDir", "", true), createBuildStrategyVolume("bvname2", "bv description 2", "ConfigMap", "config-name", false), createBuildStrategyVolume("bvname3", "bv description 3", "EmptyDir", "", true), @@ -238,16 +231,16 @@ func TestMergeVolumes(t *testing.T) { }, { name: "override second and third", - into: []buildv1alpha1.BuildStrategyVolume{ + into: []buildv1beta1.BuildStrategyVolume{ createBuildStrategyVolume("bvname", "bv description", "EmptyDir", "", false), createBuildStrategyVolume("bvname2", "bv description 2", "ConfigMap", "config-name", true), createBuildStrategyVolume("bvname3", "bv description 3", "Secret", "very-secret-name", true), }, - mergers: []buildv1alpha1.BuildVolume{ - createBuildVolume("bvname2", "bv description 655", "Secret", "very-very-secret"), - createBuildVolume("bvname3", "bv description 4", "EmptyDir", ""), + mergers: []buildv1beta1.BuildVolume{ + createBuildVolume("bvname2", "Secret", "very-very-secret"), + createBuildVolume("bvname3", "EmptyDir", ""), }, - expected: []buildv1alpha1.BuildStrategyVolume{ + expected: []buildv1beta1.BuildStrategyVolume{ createBuildStrategyVolume("bvname", "bv description", "EmptyDir", "", false), createBuildStrategyVolume("bvname2", "bv description 2", "Secret", "very-very-secret", true), createBuildStrategyVolume("bvname3", "bv description 3", "EmptyDir", "", true), @@ -256,15 +249,15 @@ func TestMergeVolumes(t *testing.T) { }, { name: "empty overridable cant be ovirriden", - into: []buildv1alpha1.BuildStrategyVolume{ + into: []buildv1beta1.BuildStrategyVolume{ createBuildStrategyVolumeEmptyOverridable("bvname", "desc", "EmptyDir", ""), createBuildStrategyVolume("bvname2", "bv description 2", "ConfigMap", "config-name", true), }, - mergers: []buildv1alpha1.BuildVolume{ - createBuildVolume("bvname", "bv description 111", "Secret", "very-very-secret"), - createBuildVolume("bvname2", "bv description 4", "Secret", "very-secret-2"), + mergers: []buildv1beta1.BuildVolume{ + createBuildVolume("bvname", "Secret", "very-very-secret"), + createBuildVolume("bvname2", "Secret", "very-secret-2"), }, - expected: []buildv1alpha1.BuildStrategyVolume{}, + expected: []buildv1beta1.BuildStrategyVolume{}, expectErr: true, }, } @@ -309,8 +302,8 @@ func TestMergeVolumes(t *testing.T) { } } -func toVolMap(expected []buildv1alpha1.BuildStrategyVolume) map[string]buildv1alpha1.BuildStrategyVolume { - res := make(map[string]buildv1alpha1.BuildStrategyVolume) +func toVolMap(expected []buildv1beta1.BuildStrategyVolume) map[string]buildv1beta1.BuildStrategyVolume { + res := make(map[string]buildv1beta1.BuildStrategyVolume) for _, v := range expected { res[v.Name] = v diff --git a/test/e2e/v1alpha1/common_test.go b/test/e2e/v1alpha1/common_test.go index 4c3c9ba7ce..43111cecee 100644 --- a/test/e2e/v1alpha1/common_test.go +++ b/test/e2e/v1alpha1/common_test.go @@ -6,6 +6,7 @@ package e2e_test import ( "bytes" + "context" "encoding/json" "fmt" "io" @@ -16,15 +17,18 @@ import ( . "github.com/onsi/gomega" knativeapis "knative.dev/pkg/apis" + "sigs.k8s.io/controller-runtime/pkg/client" corev1 "k8s.io/api/core/v1" + apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/rand" buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" - "github.com/shipwright-io/build/pkg/reconciler/buildrun/resources" + "github.com/shipwright-io/build/pkg/ctxlog" + resources "github.com/shipwright-io/build/pkg/reconciler/buildrun/resources" utils "github.com/shipwright-io/build/test/utils/v1alpha1" ) @@ -143,7 +147,7 @@ func retrieveBuildAndBuildRun(testBuild *utils.TestBuild, namespace string, buil } var build buildv1alpha1.Build - if err := resources.GetBuildObject(testBuild.Context, testBuild.ControllerRuntimeClient, buildRun, &build); err != nil { + if err := GetBuildObject(testBuild.Context, testBuild.ControllerRuntimeClient, buildRun, &build); err != nil { Logf("Failed to get Build from BuildRun %s: %s", buildRunName, err) return nil, buildRun, err } @@ -246,3 +250,51 @@ func printTestFailureDebugInfo(testBuild *utils.TestBuild, namespace string, bui } } } + +// 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 { + // 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.Name != "" { + 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.BuildName()), resources.ConditionBuildNotFound); updateErr != nil { + return resources.HandleError("build object not found", err, updateErr) + } + } + + return err + } + + // Option #2: BuildSpec is specified + // The build specification is embedded in the BuildRun itself, create a transient Build resource. + if buildRun.Spec.BuildSpec != nil { + build.Name = "" + build.Namespace = buildRun.Namespace + build.Status = buildv1alpha1.BuildStatus{} + buildRun.Spec.BuildSpec.DeepCopyInto(&build.Spec) + return nil + } + + // Bail out hard in case of an invalid state + return fmt.Errorf("invalid BuildRun resource that neither has a BuildRef nor an embedded BuildSpec") +} + +func UpdateConditionWithFalseStatus(ctx context.Context, client client.Client, buildRun *buildv1alpha1.BuildRun, errorMessage string, reason string) error { + now := metav1.Now() + buildRun.Status.CompletionTime = &now + buildRun.Status.SetCondition(&buildv1alpha1.Condition{ + LastTransitionTime: now, + Type: buildv1alpha1.Succeeded, + Status: corev1.ConditionFalse, + Reason: reason, + Message: errorMessage, + }) + ctxlog.Debug(ctx, "updating buildRun status", "namespace", buildRun.Namespace, "name", buildRun.Name, "reason", reason) + if err := client.Status().Update(ctx, buildRun); err != nil { + return err + } + return nil +} diff --git a/test/e2e/v1beta1/common_test.go b/test/e2e/v1beta1/common_test.go index 29b81e637d..1ab129c4ef 100644 --- a/test/e2e/v1beta1/common_test.go +++ b/test/e2e/v1beta1/common_test.go @@ -24,7 +24,6 @@ import ( "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/rand" - 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" utils "github.com/shipwright-io/build/test/utils/v1beta1" @@ -144,7 +143,7 @@ func retrieveBuildAndBuildRun(testBuild *utils.TestBuild, namespace string, buil return nil, nil, err } - var alphaBuild buildv1alpha1.Build + var alphaBuild buildv1beta1.Build var obj unstructured.Unstructured buildRun.ConvertTo(testBuild.Context, &obj) @@ -153,7 +152,7 @@ func retrieveBuildAndBuildRun(testBuild *utils.TestBuild, namespace string, buil Logf("Failed to convert the buildRun to v1alpha1: %s", err) } - var alphaBuildRun buildv1alpha1.BuildRun + var alphaBuildRun buildv1beta1.BuildRun json.Unmarshal(jsonData, &alphaBuildRun) if err := resources.GetBuildObject(testBuild.Context, testBuild.ControllerRuntimeClient, &alphaBuildRun, &alphaBuild); err != nil { diff --git a/test/v1beta1_samples/buildstrategy_samples.go b/test/v1beta1_samples/buildstrategy_samples.go index c74eb85ac5..d1fba62987 100644 --- a/test/v1beta1_samples/buildstrategy_samples.go +++ b/test/v1beta1_samples/buildstrategy_samples.go @@ -27,7 +27,7 @@ spec: args: - bud - --tag=$(params.shp-output-image) - - --file=$(build.dockerfile) + - --file=$(params.dockerfile) - $(params.shp-source-context) resources: limits: @@ -59,6 +59,11 @@ spec: volumeMounts: - name: buildah-images mountPath: /var/lib/containers/storage + parameters: + - name: dockerfile + description: The path to the Dockerfile to be used for building the image. + type: string + default: "Dockerfile" ` // MinimalBuildahBuildStrategyWithEnvs defines a @@ -153,7 +158,7 @@ spec: - --tls-verify=false - --layers - -f - - $(build.dockerfile) + - $(params.dockerfile) - -t - $(params.shp-output-image) - $(params.shp-source-context) @@ -167,6 +172,11 @@ spec: volumeMounts: - name: varlibcontainers mountPath: /var/lib/containers + parameters: + - name: dockerfile + description: The path to the Dockerfile to be used for building the image. + type: string + default: "Dockerfile" ` // BuildpacksBuildStrategySingleStep defines a @@ -183,7 +193,7 @@ spec: emptyDir: {} steps: - name: build - image: "$(build.builder.image)" + image: "$(params.builder-image)" workingDir: $(params.shp-source-root) command: - /cnb/lifecycle/builder @@ -205,6 +215,14 @@ spec: volumeMounts: - name: varlibcontainers mountPath: /var/lib/containers + parameters: + - name: dockerfile + description: The path to the Dockerfile to be used for building the image. + type: string + default: "Dockerfile" + - name: builder-image + description: The builder image. + type: string ` // BuildStrategyWithParameters is a strategy that uses a diff --git a/test/v1beta1_samples/catalog.go b/test/v1beta1_samples/catalog.go index 7834b10a43..74c1a0e64c 100644 --- a/test/v1beta1_samples/catalog.go +++ b/test/v1beta1_samples/catalog.go @@ -252,8 +252,8 @@ func (c *Catalog) FakeClusterBuildStrategyNotFound(name string) error { // StubFunc is used to simulate the status of the Build // after a .Status().Update() call in the controller. This // receives a parameter to return an specific status state -func (c *Catalog) StubFunc(status corev1.ConditionStatus, reason build.BuildReason, message string) func(context context.Context, object client.Object, _ ...client.UpdateOption) error { - return func(context context.Context, object client.Object, _ ...client.UpdateOption) error { +func (c *Catalog) StubFunc(status corev1.ConditionStatus, reason build.BuildReason, message string) func(context context.Context, object client.Object, _ ...client.SubResourceUpdateOption) error { + return func(context context.Context, object client.Object, _ ...client.SubResourceUpdateOption) error { switch object := object.(type) { case *build.Build: Expect(*object.Status.Registered).To(Equal(status)) @@ -334,8 +334,8 @@ func (c *Catalog) StubBuildAndTaskRun( } // StubBuildStatusReason asserts Status fields on a Build resource -func (c *Catalog) StubBuildStatusReason(reason build.BuildReason, message string) func(context context.Context, object client.Object, _ ...client.UpdateOption) error { - return func(context context.Context, object client.Object, _ ...client.UpdateOption) error { +func (c *Catalog) StubBuildStatusReason(reason build.BuildReason, message string) func(context context.Context, object client.Object, _ ...client.SubResourceUpdateOption) error { + return func(context context.Context, object client.Object, _ ...client.SubResourceUpdateOption) error { switch object := object.(type) { case *build.Build: if object.Status.Message != nil && *object.Status.Message != "" { @@ -350,8 +350,8 @@ func (c *Catalog) StubBuildStatusReason(reason build.BuildReason, message string } // StubBuildRunStatus asserts Status fields on a BuildRun resource -func (c *Catalog) StubBuildRunStatus(reason string, name *string, condition build.Condition, status corev1.ConditionStatus, buildSpec build.BuildSpec, tolerateEmptyStatus bool) func(context context.Context, object client.Object, _ ...client.UpdateOption) error { - return func(context context.Context, object client.Object, _ ...client.UpdateOption) error { +func (c *Catalog) StubBuildRunStatus(reason string, name *string, condition build.Condition, status corev1.ConditionStatus, buildSpec build.BuildSpec, tolerateEmptyStatus bool) func(context context.Context, object client.Object, _ ...client.SubResourceUpdateOption) error { + return func(context context.Context, object client.Object, _ ...client.SubResourceUpdateOption) error { switch object := object.(type) { case *build.BuildRun: if !tolerateEmptyStatus { @@ -1000,7 +1000,7 @@ func (c *Catalog) BuildRunWithSAGenerate(buildRunName string, buildName string) Build: build.ReferencedBuild{ Name: &buildName, }, - ServiceAccount: pointer.String(".generate"), + ServiceAccount: pointer.String(".generated"), }, } }