diff --git a/pkg/image/vulnerability_scan.go b/pkg/image/vulnerability_scan.go index 39d52807ee..a2b201bfb2 100644 --- a/pkg/image/vulnerability_scan.go +++ b/pkg/image/vulnerability_scan.go @@ -64,7 +64,7 @@ func RunVulnerabilityScan(ctx context.Context, imagePath string, settings builda return nil, err } - // Get the vulnerabilites from the trivy scan + // Get the vulnerabilities from the trivy scan vulnerabilities := parseTrivyResult(trivyResult, settings.Ignore) // Sort the vulnerabilities by severity diff --git a/pkg/reconciler/build/build.go b/pkg/reconciler/build/build.go index b45c376b7d..06fb23494a 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/v1beta1" + buildapi "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" @@ -64,7 +64,7 @@ func (r *ReconcileBuild) Reconcile(ctx context.Context, request reconcile.Reques ctxlog.Debug(ctx, "start reconciling Build", namespace, request.Namespace, name, request.Name) - b := &build.Build{} + b := &buildapi.Build{} if err := r.client.Get(ctx, request.NamespacedName, b); err != nil { if apierrors.IsNotFound(err) { ctxlog.Debug(ctx, "finish reconciling build. build was not found", namespace, request.Namespace, name, request.Name) @@ -75,8 +75,8 @@ func (r *ReconcileBuild) Reconcile(ctx context.Context, request reconcile.Reques } // Populate the status struct with default values - b.Status.Registered = build.ConditionStatusPtr(corev1.ConditionFalse) - b.Status.Reason = build.BuildReasonPtr(build.SucceedStatus) + b.Status.Registered = buildapi.ConditionStatusPtr(corev1.ConditionFalse) + b.Status.Reason = buildapi.BuildReasonPtr(buildapi.SucceedStatus) // trigger all current validations for _, validationType := range validationTypes { @@ -104,7 +104,7 @@ func (r *ReconcileBuild) Reconcile(ctx context.Context, request reconcile.Reques } } - if b.Status.Reason == nil || *b.Status.Reason != build.SucceedStatus { + if b.Status.Reason == nil || *b.Status.Reason != buildapi.SucceedStatus { if err := r.client.Status().Update(ctx, b); err != nil { return reconcile.Result{}, err } @@ -113,8 +113,8 @@ func (r *ReconcileBuild) Reconcile(ctx context.Context, request reconcile.Reques } } - b.Status.Registered = build.ConditionStatusPtr(corev1.ConditionTrue) - b.Status.Message = pointer.String(build.AllValidationsSucceeded) + b.Status.Registered = buildapi.ConditionStatusPtr(corev1.ConditionTrue) + b.Status.Message = pointer.String(buildapi.AllValidationsSucceeded) if err := r.client.Status().Update(ctx, b); err != nil { return reconcile.Result{}, err } diff --git a/pkg/reconciler/build/build_test.go b/pkg/reconciler/build/build_test.go index 3e49b426bb..d4623c0c52 100644 --- a/pkg/reconciler/build/build_test.go +++ b/pkg/reconciler/build/build_test.go @@ -20,7 +20,7 @@ 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/v1beta1" + buildapi "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" @@ -32,9 +32,9 @@ var _ = Describe("Reconcile Build", func() { manager *fakes.FakeManager reconciler reconcile.Reconciler request reconcile.Request - buildSample *build.Build + buildSample *buildapi.Build secretSample *corev1.Secret - clusterBuildStrategySample *build.ClusterBuildStrategy + clusterBuildStrategySample *buildapi.ClusterBuildStrategy client *fakes.FakeClient ctl test.Catalog statusWriter *fakes.FakeStatusWriter @@ -58,9 +58,9 @@ var _ = Describe("Reconcile Build", func() { client = &fakes.FakeClient{} client.GetCalls(func(_ context.Context, nn types.NamespacedName, object crc.Object, getOptions ...crc.GetOption) error { switch object := object.(type) { - case *build.Build: + case *buildapi.Build: buildSample.DeepCopyInto(object) - case *build.ClusterBuildStrategy: + case *buildapi.ClusterBuildStrategy: clusterBuildStrategySample.DeepCopyInto(object) default: return errors.NewNotFound(schema.GroupResource{}, "schema not found") @@ -87,7 +87,7 @@ var _ = Describe("Reconcile Build", func() { buildSample.Spec.Output.PushSecret = nil - statusCall := ctl.StubFunc(corev1.ConditionFalse, build.SpecSourceSecretRefNotFound, "referenced secret non-existing not found") + statusCall := ctl.StubFunc(corev1.ConditionFalse, buildapi.SpecSourceSecretRefNotFound, "referenced secret non-existing not found") statusWriter.UpdateCalls(statusCall) _, err := reconciler.Reconcile(context.TODO(), request) @@ -103,9 +103,9 @@ var _ = Describe("Reconcile Build", func() { // 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: + case *buildapi.Build: buildSample.DeepCopyInto(object) - case *build.ClusterBuildStrategy: + case *buildapi.ClusterBuildStrategy: clusterBuildStrategySample.DeepCopyInto(object) case *corev1.Secret: secretSample = ctl.SecretWithoutAnnotation("existing", namespace) @@ -114,7 +114,7 @@ var _ = Describe("Reconcile Build", func() { return nil }) - statusCall := ctl.StubFunc(corev1.ConditionTrue, build.SucceedStatus, "all validations succeeded") + statusCall := ctl.StubFunc(corev1.ConditionTrue, buildapi.SucceedStatus, "all validations succeeded") statusWriter.UpdateCalls(statusCall) result, err := reconciler.Reconcile(context.TODO(), request) @@ -127,7 +127,7 @@ var _ = Describe("Reconcile Build", func() { Context("when spec output registry secret is specified", func() { It("fails when the secret does not exist", func() { - statusCall := ctl.StubFunc(corev1.ConditionFalse, build.SpecOutputSecretRefNotFound, fmt.Sprintf("referenced secret %s not found", registrySecret)) + statusCall := ctl.StubFunc(corev1.ConditionFalse, buildapi.SpecOutputSecretRefNotFound, fmt.Sprintf("referenced secret %s not found", registrySecret)) statusWriter.UpdateCalls(statusCall) _, err := reconciler.Reconcile(context.TODO(), request) @@ -139,9 +139,9 @@ var _ = Describe("Reconcile Build", func() { // 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: + case *buildapi.Build: buildSample.DeepCopyInto(object) - case *build.ClusterBuildStrategy: + case *buildapi.ClusterBuildStrategy: clusterBuildStrategySample.DeepCopyInto(object) case *corev1.Secret: secretSample = ctl.SecretWithoutAnnotation("existing", namespace) @@ -150,7 +150,7 @@ var _ = Describe("Reconcile Build", func() { return nil }) - statusCall := ctl.StubFunc(corev1.ConditionTrue, build.SucceedStatus, "all validations succeeded") + statusCall := ctl.StubFunc(corev1.ConditionTrue, buildapi.SucceedStatus, "all validations succeeded") statusWriter.UpdateCalls(statusCall) result, err := reconciler.Reconcile(context.TODO(), request) @@ -165,7 +165,7 @@ var _ = Describe("Reconcile Build", func() { buildSample.Spec.Source.Git.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") + statusCall := ctl.StubFunc(corev1.ConditionFalse, buildapi.MultipleSecretRefNotFound, "missing secrets are non-existing-output,non-existing-source") statusWriter.UpdateCalls(statusCall) _, err := reconciler.Reconcile(context.TODO(), request) @@ -181,9 +181,9 @@ var _ = Describe("Reconcile Build", func() { // 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: + case *buildapi.Build: buildSample.DeepCopyInto(object) - case *build.ClusterBuildStrategy: + case *buildapi.ClusterBuildStrategy: return ctl.FakeClusterBuildStrategyNotFound("ss") case *corev1.Secret: secretSample = ctl.SecretWithoutAnnotation("existing", namespace) @@ -192,7 +192,7 @@ var _ = Describe("Reconcile Build", func() { return nil }) - statusCall := ctl.StubFunc(corev1.ConditionFalse, build.ClusterBuildStrategyNotFound, fmt.Sprintf("clusterBuildStrategy %s does not exist", buildStrategyName)) + statusCall := ctl.StubFunc(corev1.ConditionFalse, buildapi.ClusterBuildStrategyNotFound, fmt.Sprintf("clusterBuildStrategy %s does not exist", buildStrategyName)) statusWriter.UpdateCalls(statusCall) _, err := reconciler.Reconcile(context.TODO(), request) @@ -205,9 +205,9 @@ var _ = Describe("Reconcile Build", func() { // 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: + case *buildapi.Build: buildSample.DeepCopyInto(object) - case *build.ClusterBuildStrategy: + case *buildapi.ClusterBuildStrategy: clusterBuildStrategySample.DeepCopyInto(object) case *corev1.Secret: secretSample = ctl.SecretWithoutAnnotation("existing", namespace) @@ -216,7 +216,7 @@ var _ = Describe("Reconcile Build", func() { return nil }) - statusCall := ctl.StubFunc(corev1.ConditionTrue, build.SucceedStatus, "all validations succeeded") + statusCall := ctl.StubFunc(corev1.ConditionTrue, buildapi.SucceedStatus, "all validations succeeded") statusWriter.UpdateCalls(statusCall) result, err := reconciler.Reconcile(context.TODO(), request) @@ -236,7 +236,7 @@ var _ = Describe("Reconcile Build", func() { It("fails when the strategy does not exists", func() { - statusCall := ctl.StubFunc(corev1.ConditionFalse, build.BuildStrategyNotFound, fmt.Sprintf("buildStrategy %s does not exist in namespace %s", buildStrategyName, namespace)) + statusCall := ctl.StubFunc(corev1.ConditionFalse, buildapi.BuildStrategyNotFound, fmt.Sprintf("buildStrategy %s does not exist in namespace %s", buildStrategyName, namespace)) statusWriter.UpdateCalls(statusCall) _, err := reconciler.Reconcile(context.TODO(), request) @@ -249,16 +249,16 @@ var _ = Describe("Reconcile Build", func() { // 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: + case *buildapi.Build: buildSample.DeepCopyInto(object) - case *build.BuildStrategy: + case *buildapi.BuildStrategy: namespacedBuildStrategy := ctl.DefaultNamespacedBuildStrategy() namespacedBuildStrategy.DeepCopyInto(object) } return nil }) - statusCall := ctl.StubFunc(corev1.ConditionTrue, build.SucceedStatus, "all validations succeeded") + statusCall := ctl.StubFunc(corev1.ConditionTrue, buildapi.SucceedStatus, "all validations succeeded") statusWriter.UpdateCalls(statusCall) result, err := reconciler.Reconcile(context.TODO(), request) @@ -277,7 +277,7 @@ var _ = Describe("Reconcile Build", func() { }) It("default to BuildStrategy and fails when the strategy does not exists", func() { - statusCall := ctl.StubFunc(corev1.ConditionFalse, build.BuildStrategyNotFound, fmt.Sprintf("buildStrategy %s does not exist in namespace %s", buildStrategyName, namespace)) + statusCall := ctl.StubFunc(corev1.ConditionFalse, buildapi.BuildStrategyNotFound, fmt.Sprintf("buildStrategy %s does not exist in namespace %s", buildStrategyName, namespace)) statusWriter.UpdateCalls(statusCall) _, err := reconciler.Reconcile(context.TODO(), request) @@ -290,16 +290,16 @@ var _ = Describe("Reconcile Build", func() { // 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: + case *buildapi.Build: buildSample.DeepCopyInto(object) - case *build.BuildStrategy: + case *buildapi.BuildStrategy: namespacedBuildStrategy := ctl.DefaultNamespacedBuildStrategy() namespacedBuildStrategy.DeepCopyInto(object) } return nil }) - statusCall := ctl.StubFunc(corev1.ConditionTrue, build.SucceedStatus, "all validations succeeded") + statusCall := ctl.StubFunc(corev1.ConditionTrue, buildapi.SucceedStatus, "all validations succeeded") statusWriter.UpdateCalls(statusCall) result, err := reconciler.Reconcile(context.TODO(), request) @@ -314,9 +314,9 @@ var _ = Describe("Reconcile Build", func() { It("fails when source URL is invalid", func() { buildSample.Spec.Source.Git.URL = "foobar" buildSample.SetAnnotations(map[string]string{ - build.AnnotationBuildVerifyRepository: "true", + buildapi.AnnotationBuildVerifyRepository: "true", }) - statusCall := ctl.StubFunc(corev1.ConditionFalse, build.RemoteRepositoryUnreachable, "invalid source url") + statusCall := ctl.StubFunc(corev1.ConditionFalse, buildapi.RemoteRepositoryUnreachable, "invalid source url") statusWriter.UpdateCalls(statusCall) _, err := reconciler.Reconcile(context.TODO(), request) @@ -328,10 +328,10 @@ var _ = Describe("Reconcile Build", func() { It("fails when public source URL is unreachable", func() { buildSample.Spec.Source.Git.URL = "https://github.com/shipwright-io/sample-go-fake" buildSample.SetAnnotations(map[string]string{ - build.AnnotationBuildVerifyRepository: "true", + buildapi.AnnotationBuildVerifyRepository: "true", }) - statusCall := ctl.StubFunc(corev1.ConditionFalse, build.RemoteRepositoryUnreachable, "remote repository unreachable") + statusCall := ctl.StubFunc(corev1.ConditionFalse, buildapi.RemoteRepositoryUnreachable, "remote repository unreachable") statusWriter.UpdateCalls(statusCall) _, err := reconciler.Reconcile(context.TODO(), request) @@ -347,15 +347,15 @@ var _ = Describe("Reconcile Build", func() { // 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: + case *buildapi.Build: buildSample.DeepCopyInto(object) - case *build.ClusterBuildStrategy: + case *buildapi.ClusterBuildStrategy: clusterBuildStrategySample.DeepCopyInto(object) } return nil }) - statusCall := ctl.StubFunc(corev1.ConditionTrue, build.SucceedStatus, build.AllValidationsSucceeded) + statusCall := ctl.StubFunc(corev1.ConditionTrue, buildapi.SucceedStatus, buildapi.AllValidationsSucceeded) statusWriter.UpdateCalls(statusCall) result, err := reconciler.Reconcile(context.TODO(), request) @@ -372,15 +372,15 @@ var _ = Describe("Reconcile Build", func() { // 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: + case *buildapi.Build: buildSample.DeepCopyInto(object) - case *build.ClusterBuildStrategy: + case *buildapi.ClusterBuildStrategy: clusterBuildStrategySample.DeepCopyInto(object) } return nil }) - statusCall := ctl.StubFunc(corev1.ConditionTrue, build.SucceedStatus, build.AllValidationsSucceeded) + statusCall := ctl.StubFunc(corev1.ConditionTrue, buildapi.SucceedStatus, buildapi.AllValidationsSucceeded) statusWriter.UpdateCalls(statusCall) result, err := reconciler.Reconcile(context.TODO(), request) @@ -399,16 +399,16 @@ var _ = Describe("Reconcile Build", func() { // 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: + case *buildapi.Build: buildSample.DeepCopyInto(object) - case *build.ClusterBuildStrategy: + case *buildapi.ClusterBuildStrategy: clusterBuildStrategySample.DeepCopyInto(object) } return nil }) - statusCall := ctl.StubFunc(corev1.ConditionTrue, build.SucceedStatus, build.AllValidationsSucceeded) + statusCall := ctl.StubFunc(corev1.ConditionTrue, buildapi.SucceedStatus, buildapi.AllValidationsSucceeded) statusWriter.UpdateCalls(statusCall) result, err := reconciler.Reconcile(context.TODO(), request) @@ -427,9 +427,9 @@ var _ = Describe("Reconcile Build", func() { // 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: + case *buildapi.Build: buildSample.DeepCopyInto(object) - case *build.ClusterBuildStrategy: + case *buildapi.ClusterBuildStrategy: clusterBuildStrategySample.DeepCopyInto(object) case *corev1.Secret: secretSample = ctl.SecretWithoutAnnotation("existing", namespace) @@ -446,7 +446,7 @@ var _ = Describe("Reconcile Build", func() { }, } - statusCall := ctl.StubFunc(corev1.ConditionFalse, build.SpecEnvNameCanNotBeBlank, "name for environment variable must not be blank") + statusCall := ctl.StubFunc(corev1.ConditionFalse, buildapi.SpecEnvNameCanNotBeBlank, "name for environment variable must not be blank") statusWriter.UpdateCalls(statusCall) _, err := reconciler.Reconcile(context.TODO(), request) @@ -466,7 +466,7 @@ var _ = Describe("Reconcile Build", func() { }, } - statusCall := ctl.StubFunc(corev1.ConditionFalse, build.SpecEnvNameCanNotBeBlank, "name for environment variable must not be blank") + statusCall := ctl.StubFunc(corev1.ConditionFalse, buildapi.SpecEnvNameCanNotBeBlank, "name for environment variable must not be blank") statusWriter.UpdateCalls(statusCall) _, err := reconciler.Reconcile(context.TODO(), request) @@ -487,7 +487,7 @@ var _ = Describe("Reconcile Build", func() { }, } - statusCall := ctl.StubFunc(corev1.ConditionFalse, build.SpecEnvOnlyOneOfValueOrValueFromMustBeSpecified, "only one of value or valueFrom must be specified") + statusCall := ctl.StubFunc(corev1.ConditionFalse, buildapi.SpecEnvOnlyOneOfValueOrValueFromMustBeSpecified, "only one of value or valueFrom must be specified") statusWriter.UpdateCalls(statusCall) _, err := reconciler.Reconcile(context.TODO(), request) @@ -503,7 +503,7 @@ var _ = Describe("Reconcile Build", func() { }, } - statusCall := ctl.StubFunc(corev1.ConditionTrue, build.BuildReason(build.Succeeded), "all validations succeeded") + statusCall := ctl.StubFunc(corev1.ConditionTrue, buildapi.BuildReason(buildapi.Succeeded), "all validations succeeded") statusWriter.UpdateCalls(statusCall) _, err := reconciler.Reconcile(context.TODO(), request) @@ -523,7 +523,7 @@ var _ = Describe("Reconcile Build", func() { }, } - statusCall := ctl.StubFunc(corev1.ConditionTrue, build.BuildReason(build.Succeeded), "all validations succeeded") + statusCall := ctl.StubFunc(corev1.ConditionTrue, buildapi.BuildReason(buildapi.Succeeded), "all validations succeeded") statusWriter.UpdateCalls(statusCall) _, err := reconciler.Reconcile(context.TODO(), request) @@ -536,7 +536,7 @@ var _ = Describe("Reconcile Build", func() { Context("when build object is not in the cluster (anymore)", func() { It("should finish reconciling when the build cannot be found", func() { client.GetCalls(func(_ context.Context, nn types.NamespacedName, o crc.Object, getOptions ...crc.GetOption) error { - return errors.NewNotFound(build.Resource("build"), nn.Name) + return errors.NewNotFound(buildapi.Resource("build"), nn.Name) }) _, err := reconciler.Reconcile(context.TODO(), request) @@ -555,14 +555,14 @@ var _ = Describe("Reconcile Build", func() { Context("when build object has output timestamp defined", func() { It("should fail build validation due to unsupported combination of empty source with output image timestamp set to be the source timestamp", func() { - buildSample.Spec.Output.Timestamp = pointer.String(build.OutputImageSourceTimestamp) + buildSample.Spec.Output.Timestamp = pointer.String(buildapi.OutputImageSourceTimestamp) buildSample.Spec.Output.PushSecret = nil - buildSample.Spec.Source = &build.Source{} + buildSample.Spec.Source = &buildapi.Source{} statusWriter.UpdateCalls(func(ctx context.Context, o crc.Object, sruo ...crc.SubResourceUpdateOption) error { - Expect(o).To(BeAssignableToTypeOf(&build.Build{})) - b := o.(*build.Build) - Expect(*b.Status.Reason).To(BeEquivalentTo(build.OutputTimestampNotSupported)) + Expect(o).To(BeAssignableToTypeOf(&buildapi.Build{})) + b := o.(*buildapi.Build) + Expect(*b.Status.Reason).To(BeEquivalentTo(buildapi.OutputTimestampNotSupported)) Expect(*b.Status.Message).To(BeEquivalentTo("cannot use SourceTimestamp output image setting with an empty build source")) return nil @@ -577,9 +577,9 @@ var _ = Describe("Reconcile Build", func() { buildSample.Spec.Output.PushSecret = nil statusWriter.UpdateCalls(func(ctx context.Context, o crc.Object, sruo ...crc.SubResourceUpdateOption) error { - Expect(o).To(BeAssignableToTypeOf(&build.Build{})) - b := o.(*build.Build) - Expect(*b.Status.Reason).To(BeEquivalentTo(build.OutputTimestampNotValid)) + Expect(o).To(BeAssignableToTypeOf(&buildapi.Build{})) + b := o.(*buildapi.Build) + Expect(*b.Status.Reason).To(BeEquivalentTo(buildapi.OutputTimestampNotValid)) Expect(*b.Status.Message).To(BeEquivalentTo("output timestamp value is invalid, must be Zero, SourceTimestamp, BuildTimestamp, or number")) return nil diff --git a/pkg/reconciler/build/controller.go b/pkg/reconciler/build/controller.go index bc12a39759..54415de2db 100644 --- a/pkg/reconciler/build/controller.go +++ b/pkg/reconciler/build/controller.go @@ -23,7 +23,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/v1beta1" + buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/config" "github.com/shipwright-io/build/pkg/ctxlog" ) @@ -60,8 +60,8 @@ func add(ctx context.Context, mgr manager.Manager, r reconcile.Reconciler, maxCo pred := predicate.Funcs{ UpdateFunc: func(e event.UpdateEvent) bool { - o := e.ObjectOld.(*build.Build) - n := e.ObjectNew.(*build.Build) + o := e.ObjectOld.(*buildapi.Build) + n := e.ObjectNew.(*buildapi.Build) buildAtBuildDeletion := false @@ -119,7 +119,7 @@ func add(ctx context.Context, mgr manager.Manager, r reconcile.Reconciler, maxCo } // Watch for changes to primary resource Build - if err = c.Watch(source.Kind(mgr.GetCache(), &build.Build{}), &handler.EnqueueRequestForObject{}, pred); err != nil { + if err = c.Watch(source.Kind(mgr.GetCache(), &buildapi.Build{}), &handler.EnqueueRequestForObject{}, pred); err != nil { return err } @@ -160,7 +160,7 @@ func add(ctx context.Context, mgr manager.Manager, r reconcile.Reconciler, maxCo return c.Watch(source.Kind(mgr.GetCache(), &corev1.Secret{}), handler.EnqueueRequestsFromMapFunc(func(ctx context.Context, o client.Object) []reconcile.Request { secret := o.(*corev1.Secret) - buildList := &build.BuildList{} + buildList := &buildapi.BuildList{} // List all builds in the namespace of the current secret if err := mgr.GetClient().List(ctx, buildList, &client.ListOptions{Namespace: secret.Namespace}); err != nil { @@ -205,7 +205,7 @@ func add(ctx context.Context, mgr manager.Manager, r reconcile.Reconciler, maxCo } func buildCredentialsAnnotationExist(annotation map[string]string) (string, bool) { - if val, ok := annotation[build.AnnotationBuildRefSecret]; ok { + if val, ok := annotation[buildapi.AnnotationBuildRefSecret]; ok { return val, true } return "", false diff --git a/pkg/reconciler/buildlimitcleanup/build_limit_cleanup.go b/pkg/reconciler/buildlimitcleanup/build_limit_cleanup.go index 1d36c57189..1fd852f71a 100644 --- a/pkg/reconciler/buildlimitcleanup/build_limit_cleanup.go +++ b/pkg/reconciler/buildlimitcleanup/build_limit_cleanup.go @@ -8,7 +8,7 @@ import ( "context" "sort" - build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/config" "github.com/shipwright-io/build/pkg/ctxlog" corev1 "k8s.io/api/core/v1" @@ -43,7 +43,7 @@ func (r *ReconcileBuild) Reconcile(ctx context.Context, request reconcile.Reques ctxlog.Debug(ctx, "Start reconciling build-limit-cleanup", namespace, request.Namespace, name, request.Name) - b := &build.Build{} + b := &buildapi.Build{} err := r.client.Get(ctx, request.NamespacedName, b) if err != nil { @@ -65,13 +65,13 @@ func (r *ReconcileBuild) Reconcile(ctx context.Context, request reconcile.Reques } lbls := map[string]string{ - build.LabelBuild: b.Name, + buildapi.LabelBuild: b.Name, } opts := client.ListOptions{ Namespace: b.Namespace, LabelSelector: labels.SelectorFromSet(lbls), } - allBuildRuns := &build.BuildRunList{} + allBuildRuns := &buildapi.BuildRunList{} err = r.client.List(ctx, allBuildRuns, &opts) if err != nil { @@ -82,12 +82,12 @@ func (r *ReconcileBuild) Reconcile(ctx context.Context, request reconcile.Reques return reconcile.Result{}, nil } - var buildRunFailed []build.BuildRun - var buildRunSucceeded []build.BuildRun + var buildRunFailed []buildapi.BuildRun + var buildRunSucceeded []buildapi.BuildRun // Sort buildruns into successful ones and failed ones for _, br := range allBuildRuns.Items { - condition := br.Status.GetCondition(build.Succeeded) + condition := br.Status.GetCondition(buildapi.Succeeded) if condition != nil { if condition.Status == corev1.ConditionFalse { buildRunFailed = append(buildRunFailed, br) diff --git a/pkg/reconciler/buildlimitcleanup/controller.go b/pkg/reconciler/buildlimitcleanup/controller.go index eb23e139a3..dc1de6452a 100644 --- a/pkg/reconciler/buildlimitcleanup/controller.go +++ b/pkg/reconciler/buildlimitcleanup/controller.go @@ -7,7 +7,7 @@ package buildlimitcleanup import ( "context" - buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/config" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/types" @@ -49,12 +49,12 @@ func add(mgr manager.Manager, r reconcile.Reconciler, maxConcurrentReconciles in pred := predicate.Funcs{ CreateFunc: func(e event.CreateEvent) bool { - o := e.Object.(*buildv1beta1.Build) + o := e.Object.(*buildapi.Build) return o.Spec.Retention != nil && (o.Spec.Retention.FailedLimit != nil || o.Spec.Retention.SucceededLimit != nil) }, UpdateFunc: func(e event.UpdateEvent) bool { - n := e.ObjectNew.(*buildv1beta1.Build) - o := e.ObjectOld.(*buildv1beta1.Build) + n := e.ObjectNew.(*buildapi.Build) + o := e.ObjectOld.(*buildapi.Build) // Check to see if there are new retention parameters or whether the // limit values have decreased @@ -88,16 +88,16 @@ func add(mgr manager.Manager, r reconcile.Reconciler, maxConcurrentReconciles in }, // Reconcile the build the related buildrun has just completed UpdateFunc: func(e event.UpdateEvent) bool { - n := e.ObjectNew.(*buildv1beta1.BuildRun) + n := e.ObjectNew.(*buildapi.BuildRun) // check if Buildrun is related to a build if n.Spec.Build.Name == nil { return false } - o := e.ObjectOld.(*buildv1beta1.BuildRun) - oldCondition := o.Status.GetCondition(buildv1beta1.Succeeded) - newCondition := n.Status.GetCondition(buildv1beta1.Succeeded) + o := e.ObjectOld.(*buildapi.BuildRun) + oldCondition := o.Status.GetCondition(buildapi.Succeeded) + newCondition := n.Status.GetCondition(buildapi.Succeeded) if newCondition != nil { if (oldCondition == nil || oldCondition.Status == corev1.ConditionUnknown) && (newCondition.Status == corev1.ConditionFalse || newCondition.Status == corev1.ConditionTrue) { @@ -113,13 +113,13 @@ func add(mgr manager.Manager, r reconcile.Reconciler, maxConcurrentReconciles in } // Watch for changes to primary resource Build - if err = c.Watch(source.Kind(mgr.GetCache(), &buildv1beta1.Build{}), &handler.EnqueueRequestForObject{}, pred); err != nil { + if err = c.Watch(source.Kind(mgr.GetCache(), &buildapi.Build{}), &handler.EnqueueRequestForObject{}, pred); err != nil { return err } // Watch for changes to resource BuildRun - return c.Watch(source.Kind(mgr.GetCache(), &buildv1beta1.BuildRun{}), handler.EnqueueRequestsFromMapFunc(func(_ context.Context, o client.Object) []reconcile.Request { - buildRun := o.(*buildv1beta1.BuildRun) + return c.Watch(source.Kind(mgr.GetCache(), &buildapi.BuildRun{}), handler.EnqueueRequestsFromMapFunc(func(_ context.Context, o client.Object) []reconcile.Request { + buildRun := o.(*buildapi.BuildRun) return []reconcile.Request{ { diff --git a/pkg/reconciler/buildrun/buildrun.go b/pkg/reconciler/buildrun/buildrun.go index a15cbdeab7..66bd4fd46d 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" - buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "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 *buildv1beta1.BuildRun - var build *buildv1beta1.Build + var buildRun *buildapi.BuildRun + var build *buildapi.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 = &buildv1beta1.BuildRun{} + buildRun = &buildapi.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) @@ -131,9 +131,9 @@ func (r *ReconcileBuildRun) Reconcile(ctx context.Context, request reconcile.Req // for existing TaskRuns update the BuildRun Status, if there is no TaskRun, then create one if getTaskRunErr != nil { if apierrors.IsNotFound(getTaskRunErr) { - build = &buildv1beta1.Build{} + build = &buildapi.Build{} if err := resources.GetBuildObject(ctx, r.client, buildRun, build); err != nil { - if !resources.IsClientStatusUpdateError(err) && buildRun.Status.IsFailed(buildv1beta1.Succeeded) { + if !resources.IsClientStatusUpdateError(err) && buildRun.Status.IsFailed(buildapi.Succeeded) { return reconcile.Result{}, nil } // system call failure, reconcile again @@ -179,16 +179,16 @@ func (r *ReconcileBuildRun) Reconcile(ctx context.Context, request reconcile.Req ) } // mark transient build as "registered" and validated - build.Status.Registered = buildv1beta1.ConditionStatusPtr(corev1.ConditionTrue) - build.Status.Reason = buildv1beta1.BuildReasonPtr(buildv1beta1.SucceedStatus) - build.Status.Message = pointer.String(buildv1beta1.AllValidationsSucceeded) + build.Status.Registered = buildapi.ConditionStatusPtr(corev1.ConditionTrue) + build.Status.Reason = buildapi.BuildReasonPtr(buildapi.SucceedStatus) + build.Status.Message = pointer.String(buildapi.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 buildv1beta1.BuildReason + var reason buildapi.BuildReason if build.Status.Reason != nil { reason = *build.Status.Reason @@ -209,7 +209,7 @@ 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.", buildv1beta1.BuildRunStateCancel); updateErr != nil { + if updateErr := resources.UpdateConditionWithFalseStatus(ctx, r.client, buildRun, "the BuildRun is marked canceled.", buildapi.BuildRunStateCancel); updateErr != nil { return reconcile.Result{}, updateErr } return reconcile.Result{}, nil @@ -219,7 +219,7 @@ func (r *ReconcileBuildRun) Reconcile(ctx context.Context, request reconcile.Req 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.Reason = buildapi.BuildReasonPtr(buildapi.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 @@ -233,9 +233,9 @@ func (r *ReconcileBuildRun) Reconcile(ctx context.Context, request reconcile.Req // 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()[buildv1beta1.LabelBuild] != build.Name || buildRun.GetLabels()[buildv1beta1.LabelBuildGeneration] != buildGeneration { - buildRun.Labels[buildv1beta1.LabelBuild] = build.Name - buildRun.Labels[buildv1beta1.LabelBuildGeneration] = buildGeneration + if buildRun.GetLabels()[buildapi.LabelBuild] != build.Name || buildRun.GetLabels()[buildapi.LabelBuildGeneration] != buildGeneration { + buildRun.Labels[buildapi.LabelBuild] = build.Name + buildRun.Labels[buildapi.LabelBuildGeneration] = buildGeneration ctxlog.Info(ctx, "updating BuildRun labels", namespace, request.Namespace, name, request.Name) updateBuildRunRequired = true } @@ -257,7 +257,7 @@ func (r *ReconcileBuildRun) Reconcile(ctx context.Context, request reconcile.Req // Choose a service account to use svcAccount, err := resources.RetrieveServiceAccount(ctx, r.client, build, buildRun) if err != nil { - if !resources.IsClientStatusUpdateError(err) && buildRun.Status.IsFailed(buildv1beta1.Succeeded) { + if !resources.IsClientStatusUpdateError(err) && buildRun.Status.IsFailed(buildapi.Succeeded) { return reconcile.Result{}, nil } // system call failure, reconcile again @@ -266,7 +266,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(buildv1beta1.Succeeded) { + if !resources.IsClientStatusUpdateError(err) && buildRun.Status.IsFailed(buildapi.Succeeded) { return reconcile.Result{}, nil } return reconcile.Result{}, err @@ -293,7 +293,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(buildv1beta1.Succeeded) { + if !resources.IsClientStatusUpdateError(err) && buildRun.Status.IsFailed(buildapi.Succeeded) { ctxlog.Info(ctx, "taskRun generation failed", namespace, request.Namespace, name, request.Name) return reconcile.Result{}, nil } @@ -305,7 +305,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(buildv1beta1.VolumeDoesNotExist)); err != nil { + if err := resources.UpdateConditionWithFalseStatus(ctx, r.client, buildRun, err.Error(), string(buildapi.VolumeDoesNotExist)); err != nil { return reconcile.Result{}, err } @@ -359,7 +359,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[buildv1beta1.LabelBuildRun], request.Namespace, buildRun) + err := r.GetBuildRunObject(ctx, lastTaskRun.Labels[buildapi.LabelBuildRun], request.Namespace, buildRun) if err != nil && !apierrors.IsNotFound(err) { return reconcile.Result{}, err } @@ -473,7 +473,7 @@ func (r *ReconcileBuildRun) Reconcile(ctx context.Context, request reconcile.Req buildRun.Namespace, lastTaskRun.Status.PodName, ), - buildv1beta1.BuildRunStateVulnerabilitiesFound) + buildapi.BuildRunStateVulnerabilitiesFound) } ctxlog.Info(ctx, "updating buildRun status", namespace, request.Namespace, name, request.Name) @@ -489,13 +489,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 *buildv1beta1.BuildRun) error { +func (r *ReconcileBuildRun) GetBuildRunObject(ctx context.Context, objectName string, objectNS string, buildRun *buildapi.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 *buildv1beta1.BuildRun) { +func (r *ReconcileBuildRun) VerifyRequestName(ctx context.Context, request reconcile.Request, buildRun *buildapi.BuildRun) { regxBuildRun, _ := regexp.Compile(generatedNameRegex) @@ -516,7 +516,7 @@ func (r *ReconcileBuildRun) VerifyRequestName(ctx context.Context, request recon } } -func (r *ReconcileBuildRun) getReferencedStrategy(ctx context.Context, build *buildv1beta1.Build, buildRun *buildv1beta1.BuildRun) (strategy buildv1beta1.BuilderStrategy, err error) { +func (r *ReconcileBuildRun) getReferencedStrategy(ctx context.Context, build *buildapi.Build, buildRun *buildapi.BuildRun) (strategy buildapi.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) @@ -532,7 +532,7 @@ func (r *ReconcileBuildRun) getReferencedStrategy(ctx context.Context, build *bu } switch *build.Spec.Strategy.Kind { - case buildv1beta1.NamespacedBuildStrategyKind: + case buildapi.NamespacedBuildStrategyKind: strategy, err = resources.RetrieveBuildStrategy(ctx, r.client, build) if err != nil { if apierrors.IsNotFound(err) { @@ -541,7 +541,7 @@ func (r *ReconcileBuildRun) getReferencedStrategy(ctx context.Context, build *bu } } } - case buildv1beta1.ClusterBuildStrategyKind: + case buildapi.ClusterBuildStrategyKind: strategy, err = resources.RetrieveClusterBuildStrategy(ctx, r.client, build) if err != nil { if apierrors.IsNotFound(err) { @@ -560,7 +560,7 @@ func (r *ReconcileBuildRun) getReferencedStrategy(ctx context.Context, build *bu return strategy, err } -func (r *ReconcileBuildRun) createTaskRun(ctx context.Context, serviceAccount *corev1.ServiceAccount, strategy buildv1beta1.BuilderStrategy, build *buildv1beta1.Build, buildRun *buildv1beta1.BuildRun) (*pipelineapi.TaskRun, error) { +func (r *ReconcileBuildRun) createTaskRun(ctx context.Context, serviceAccount *corev1.ServiceAccount, strategy buildapi.BuilderStrategy, build *buildapi.Build, buildRun *buildapi.BuildRun) (*pipelineapi.TaskRun, error) { var ( generatedTaskRun *pipelineapi.TaskRun ) @@ -607,11 +607,11 @@ func (r *ReconcileBuildRun) patchTaskRun(ctx context.Context, tr *pipelineapi.Ta return r.client.Patch(ctx, tr, patch, &patchOpt) } -func failOnVulnerabilities(buildRun *buildv1beta1.BuildRun) bool { +func failOnVulnerabilities(buildRun *buildapi.BuildRun) bool { if buildRun.Status.Output == nil || len(buildRun.Status.Output.Vulnerabilities) == 0 { return false } - var buildRunOutput, buildOutput buildv1beta1.Image + var buildRunOutput, buildOutput buildapi.Image if buildRun.Spec.Output != nil { buildRunOutput = *buildRun.Spec.Output } diff --git a/pkg/reconciler/buildrun/buildrun_test.go b/pkg/reconciler/buildrun/buildrun_test.go index eb7d032e55..ebaae534c9 100644 --- a/pkg/reconciler/buildrun/buildrun_test.go +++ b/pkg/reconciler/buildrun/buildrun_test.go @@ -29,7 +29,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" "github.com/shipwright-io/build/pkg/apis" - build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "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" @@ -44,8 +44,8 @@ var _ = Describe("Reconcile BuildRun", func() { taskRunRequest, buildRunRequest reconcile.Request client *fakes.FakeClient ctl test.Catalog - buildSample *build.Build - buildRunSample *build.BuildRun + buildSample *buildapi.Build + buildRunSample *buildapi.BuildRun taskRunSample *pipelineapi.TaskRun statusWriter *fakes.FakeStatusWriter taskRunName, buildRunName, buildName, strategyName, ns string @@ -65,10 +65,10 @@ var _ = Describe("Reconcile BuildRun", func() { // This applies only for a Build and BuildRun client get. getClientStub := func(_ context.Context, nn types.NamespacedName, object crc.Object, getOptions ...crc.GetOption) error { switch object := object.(type) { - case *build.Build: + case *buildapi.Build: buildSample.DeepCopyInto(object) return nil - case *build.BuildRun: + case *buildapi.BuildRun: buildRunSample.DeepCopyInto(object) return nil case *pipelineapi.TaskRun: @@ -103,7 +103,7 @@ var _ = Describe("Reconcile BuildRun", func() { manager.GetClientReturns(client) // init the Build resource, this never change throughout this test suite - buildSample = ctl.DefaultBuild(buildName, strategyName, build.ClusterBuildStrategyKind) + buildSample = ctl.DefaultBuild(buildName, strategyName, buildapi.ClusterBuildStrategyKind) buildRunSample = ctl.DefaultBuildRun(buildRunName, buildName) taskRunSample = ctl.DefaultTaskRunWithStatus(taskRunName, buildRunName, ns, corev1.ConditionTrue, "Succeeded") }) @@ -171,8 +171,8 @@ var _ = Describe("Reconcile BuildRun", func() { statusCall := ctl.StubBuildRunStatus( "Succeeded", &taskRunName, - build.Condition{ - Type: build.Succeeded, + buildapi.Condition{ + Type: buildapi.Succeeded, Reason: "Succeeded", Status: corev1.ConditionTrue, }, @@ -215,11 +215,11 @@ var _ = Describe("Reconcile BuildRun", func() { It("deletes a generated service account when the task run ends", func() { // setup a buildrun to use a generated service account - buildSample = ctl.DefaultBuild(buildName, "foobar-strategy", build.ClusterBuildStrategyKind) + buildSample = ctl.DefaultBuild(buildName, "foobar-strategy", buildapi.ClusterBuildStrategyKind) buildRunSample = ctl.BuildRunWithSAGenerate(buildRunSample.Name, buildName) buildRunSample.Status.BuildSpec = &buildSample.Spec buildRunSample.Labels = make(map[string]string) - buildRunSample.Labels[build.LabelBuild] = buildName + buildRunSample.Labels[buildapi.LabelBuild] = buildName // Override Stub get calls to include a service account client.GetCalls(ctl.StubBuildRunGetWithTaskRunAndSA( @@ -267,8 +267,8 @@ var _ = Describe("Reconcile BuildRun", func() { statusCall := ctl.StubBuildRunStatus( "Pending", &taskRunName, - build.Condition{ - Type: build.Succeeded, + buildapi.Condition{ + Type: buildapi.Succeeded, Reason: "Pending", Status: corev1.ConditionUnknown, }, @@ -297,8 +297,8 @@ var _ = Describe("Reconcile BuildRun", func() { statusCall := ctl.StubBuildRunStatus( "Running", &taskRunName, - build.Condition{ - Type: build.Succeeded, + buildapi.Condition{ + Type: buildapi.Succeeded, Reason: "Running", Status: corev1.ConditionUnknown, }, @@ -324,8 +324,8 @@ var _ = Describe("Reconcile BuildRun", func() { statusCall := ctl.StubBuildRunStatus( "Succeeded", &taskRunName, - build.Condition{ - Type: build.Succeeded, + buildapi.Condition{ + Type: buildapi.Succeeded, Reason: "Succeeded", Status: corev1.ConditionTrue, }, @@ -345,8 +345,8 @@ var _ = Describe("Reconcile BuildRun", func() { It("updates the BuildRun status with a VulnerabilitiesFound reason if fail on finding is true", func() { taskRunSample = ctl.DefaultTaskRunWithStatus(taskRunName, buildRunName, ns, corev1.ConditionTrue, "Succeeded") - buildRunSample.Spec.Output = &build.Image{ - VulnerabilityScan: &build.VulnerabilityScanOptions{ + buildRunSample.Spec.Output = &buildapi.Image{ + VulnerabilityScan: &buildapi.VulnerabilityScanOptions{ Fail: true, }, } @@ -364,8 +364,8 @@ var _ = Describe("Reconcile BuildRun", func() { statusCall := ctl.StubBuildRunStatus( "Succeeded", &taskRunName, - build.Condition{ - Type: build.Succeeded, + buildapi.Condition{ + Type: buildapi.Succeeded, Reason: "VulnerabilitiesFound", Status: corev1.ConditionFalse, }, @@ -385,8 +385,8 @@ var _ = Describe("Reconcile BuildRun", func() { It("updates the BuildRun status with a SUCCEEDED reason if fail in vulnerabilities options is false", func() { taskRunSample = ctl.DefaultTaskRunWithStatus(taskRunName, buildRunName, ns, corev1.ConditionTrue, "Succeeded") - buildRunSample.Spec.Output = &build.Image{ - VulnerabilityScan: &build.VulnerabilityScanOptions{ + buildRunSample.Spec.Output = &buildapi.Image{ + VulnerabilityScan: &buildapi.VulnerabilityScanOptions{ Fail: false, }, } @@ -404,8 +404,8 @@ var _ = Describe("Reconcile BuildRun", func() { statusCall := ctl.StubBuildRunStatus( "Succeeded", &taskRunName, - build.Condition{ - Type: build.Succeeded, + buildapi.Condition{ + Type: buildapi.Succeeded, Reason: "Succeeded", Status: corev1.ConditionTrue, }, @@ -425,7 +425,7 @@ var _ = Describe("Reconcile BuildRun", func() { It("should recognize the BuildRun is canceled", func() { // set cancel buildRunSampleCopy := buildRunSample.DeepCopy() - buildRunSampleCopy.Spec.State = build.BuildRunRequestedStatePtr(build.BuildRunStateCancel) + buildRunSampleCopy.Spec.State = buildapi.BuildRunRequestedStatePtr(buildapi.BuildRunStateCancel) taskRunSample = ctl.DefaultTaskRunWithStatus(taskRunName, buildRunName, ns, corev1.ConditionUnknown, "Running") @@ -446,9 +446,9 @@ var _ = Describe("Reconcile BuildRun", func() { // override the updateClientStub so we can see the update on the BuildRun condition stubUpdateCalls := func(_ context.Context, object crc.Object, opts ...crc.SubResourceUpdateOption) error { switch v := object.(type) { - case *build.BuildRun: - c := v.Status.GetCondition(build.Succeeded) - if c != nil && c.Reason == build.BuildRunStateCancel && c.Status == corev1.ConditionFalse { + case *buildapi.BuildRun: + c := v.Status.GetCondition(buildapi.Succeeded) + if c != nil && c.Reason == buildapi.BuildRunStateCancel && c.Status == corev1.ConditionFalse { cancelUpdateCalled = true } @@ -499,8 +499,8 @@ var _ = Describe("Reconcile BuildRun", func() { statusCall := ctl.StubBuildRunStatus( "some message", &taskRunName, - build.Condition{ - Type: build.Succeeded, + buildapi.Condition{ + Type: buildapi.Succeeded, Reason: "something bad happened", Status: corev1.ConditionFalse, }, @@ -617,7 +617,7 @@ var _ = Describe("Reconcile BuildRun", func() { It("should recognize the BuildRun is canceled even with TaskRun missing", func() { // set cancel buildRunSampleCopy := buildRunSample.DeepCopy() - buildRunSampleCopy.Spec.State = build.BuildRunRequestedStatePtr(build.BuildRunStateCancel) + buildRunSampleCopy.Spec.State = buildapi.BuildRunRequestedStatePtr(buildapi.BuildRunStateCancel) client.GetCalls(ctl.StubBuildCRDs( buildSample, @@ -631,9 +631,9 @@ var _ = Describe("Reconcile BuildRun", func() { // override the updateClientStub so we can see the update on the BuildRun condition stubUpdateCalls := func(_ context.Context, object crc.Object, opts ...crc.SubResourceUpdateOption) error { switch v := object.(type) { - case *build.BuildRun: - c := v.Status.GetCondition(build.Succeeded) - if c != nil && c.Reason == build.BuildRunStateCancel { + case *buildapi.BuildRun: + c := v.Status.GetCondition(buildapi.Succeeded) + if c != nil && c.Reason == buildapi.BuildRunStateCancel { cancelUpdateCalled = true } @@ -656,9 +656,9 @@ var _ = Describe("Reconcile BuildRun", func() { // that only contains a Buildrun stubGetCalls := func(_ context.Context, nn types.NamespacedName, object crc.Object, getOptions ...crc.GetOption) error { switch object := object.(type) { - case *build.Build: + case *buildapi.Build: return k8serrors.NewNotFound(schema.GroupResource{}, nn.Name) - case *build.BuildRun: + case *buildapi.BuildRun: buildRunSample.DeepCopyInto(object) return nil } @@ -678,9 +678,9 @@ var _ = Describe("Reconcile BuildRun", func() { // that only contains a BuildRun stubGetCalls := func(_ context.Context, nn types.NamespacedName, object crc.Object, _ ...crc.GetOption) error { switch object := object.(type) { - case *build.Build: + case *buildapi.Build: return k8serrors.NewNotFound(schema.GroupResource{}, nn.Name) - case *build.BuildRun: + case *buildapi.BuildRun: buildRunSample.DeepCopyInto(object) return nil } @@ -690,8 +690,8 @@ var _ = Describe("Reconcile BuildRun", func() { statusWriter.UpdateCalls(func(_ context.Context, object crc.Object, _ ...crc.SubResourceUpdateOption) error { switch buildRun := object.(type) { - case *build.BuildRun: - if buildRun.Status.IsFailed(build.Succeeded) { + case *buildapi.BuildRun: + if buildRun.Status.IsFailed(buildapi.Succeeded) { return fmt.Errorf("failed miserably") } } @@ -708,10 +708,10 @@ var _ = Describe("Reconcile BuildRun", func() { // that only contains a Build and Buildrun, none TaskRun stubGetCalls := func(_ context.Context, nn types.NamespacedName, object crc.Object, _ ...crc.GetOption) error { switch object := object.(type) { - case *build.Build: + case *buildapi.Build: buildSample.DeepCopyInto(object) return nil - case *build.BuildRun: + case *buildapi.BuildRun: buildRunSample.DeepCopyInto(object) return nil } @@ -725,8 +725,8 @@ var _ = Describe("Reconcile BuildRun", func() { statusCall := ctl.StubBuildRunStatus( fmt.Sprintf("service account %s not found", saName), emptyTaskRunName, - build.Condition{ - Type: build.Succeeded, + buildapi.Condition{ + Type: buildapi.Succeeded, Reason: "ServiceAccountNotFound", Status: corev1.ConditionFalse, }, @@ -749,10 +749,10 @@ var _ = Describe("Reconcile BuildRun", func() { // retrieving a service account stubGetCalls := func(_ context.Context, nn types.NamespacedName, object crc.Object, _ ...crc.GetOption) error { switch object := object.(type) { - case *build.Build: + case *buildapi.Build: buildSample.DeepCopyInto(object) return nil - case *build.BuildRun: + case *buildapi.BuildRun: buildRunSample.DeepCopyInto(object) return nil case *corev1.ServiceAccount: @@ -773,7 +773,7 @@ var _ = Describe("Reconcile BuildRun", func() { It("fails on a TaskRun creation due to namespaced buildstrategy not found", func() { // override the Build to use a namespaced BuildStrategy - buildSample = ctl.DefaultBuild(buildName, strategyName, build.NamespacedBuildStrategyKind) + buildSample = ctl.DefaultBuild(buildName, strategyName, buildapi.NamespacedBuildStrategyKind) // Override Stub get calls to include a service account // but none BuildStrategy @@ -788,8 +788,8 @@ var _ = Describe("Reconcile BuildRun", func() { statusCall := ctl.StubBuildRunStatus( fmt.Sprintf(" %q not found", strategyName), emptyTaskRunName, - build.Condition{ - Type: build.Succeeded, + buildapi.Condition{ + Type: buildapi.Succeeded, Reason: "BuildStrategyNotFound", Status: corev1.ConditionFalse, }, @@ -806,21 +806,21 @@ var _ = Describe("Reconcile BuildRun", func() { It("fails on a TaskRun creation due to issues when retrieving the buildstrategy", func() { // override the Build to use a namespaced BuildStrategy - buildSample = ctl.DefaultBuild(buildName, strategyName, build.NamespacedBuildStrategyKind) + buildSample = ctl.DefaultBuild(buildName, strategyName, buildapi.NamespacedBuildStrategyKind) // stub get calls so that on namespaced strategy retrieval, we throw a random error stubGetCalls := func(_ context.Context, nn types.NamespacedName, object crc.Object, _ ...crc.GetOption) error { switch object := object.(type) { - case *build.Build: + case *buildapi.Build: buildSample.DeepCopyInto(object) return nil - case *build.BuildRun: + case *buildapi.BuildRun: buildRunSample.DeepCopyInto(object) return nil case *corev1.ServiceAccount: ctl.DefaultServiceAccount(saName).DeepCopyInto(object) return nil - case *build.BuildStrategy: + case *buildapi.BuildStrategy: return fmt.Errorf("something wrong happen") } return k8serrors.NewNotFound(schema.GroupResource{}, nn.Name) @@ -840,7 +840,7 @@ var _ = Describe("Reconcile BuildRun", func() { It("fails on a TaskRun creation due to cluster buildstrategy not found", func() { // override the Build to use a cluster BuildStrategy - buildSample = ctl.DefaultBuild(buildName, strategyName, build.ClusterBuildStrategyKind) + buildSample = ctl.DefaultBuild(buildName, strategyName, buildapi.ClusterBuildStrategyKind) // Override Stub get calls to include a service account // but none ClusterBuildStrategy @@ -855,8 +855,8 @@ var _ = Describe("Reconcile BuildRun", func() { statusCall := ctl.StubBuildRunStatus( fmt.Sprintf(" %q not found", strategyName), emptyTaskRunName, - build.Condition{ - Type: build.Succeeded, + buildapi.Condition{ + Type: buildapi.Succeeded, Reason: "ClusterBuildStrategyNotFound", Status: corev1.ConditionFalse, }, @@ -873,21 +873,21 @@ var _ = Describe("Reconcile BuildRun", func() { It("fails on a TaskRun creation due to issues when retrieving the clusterbuildstrategy", func() { // override the Build to use a namespaced BuildStrategy - buildSample = ctl.DefaultBuild(buildName, strategyName, build.ClusterBuildStrategyKind) + buildSample = ctl.DefaultBuild(buildName, strategyName, buildapi.ClusterBuildStrategyKind) // stub get calls so that on cluster strategy retrieval, we throw a random error stubGetCalls := func(_ context.Context, nn types.NamespacedName, object crc.Object, _ ...crc.GetOption) error { switch object := object.(type) { - case *build.Build: + case *buildapi.Build: buildSample.DeepCopyInto(object) return nil - case *build.BuildRun: + case *buildapi.BuildRun: buildRunSample.DeepCopyInto(object) return nil case *corev1.ServiceAccount: ctl.DefaultServiceAccount(saName).DeepCopyInto(object) return nil - case *build.ClusterBuildStrategy: + case *buildapi.ClusterBuildStrategy: return fmt.Errorf("something wrong happen") } return k8serrors.NewNotFound(schema.GroupResource{}, nn.Name) @@ -919,8 +919,8 @@ var _ = Describe("Reconcile BuildRun", func() { statusCall := ctl.StubBuildRunStatus( "unknown strategy foobar", emptyTaskRunName, - build.Condition{ - Type: build.Succeeded, + buildapi.Condition{ + Type: buildapi.Succeeded, Reason: "UnknownStrategyKind", Status: corev1.ConditionFalse, }, @@ -977,8 +977,8 @@ var _ = Describe("Reconcile BuildRun", func() { statusWriter.UpdateCalls(ctl.StubBuildRunStatus( " \"foobar-strategy\" not found", emptyTaskRunName, - build.Condition{ - Type: build.Succeeded, + buildapi.Condition{ + Type: buildapi.Succeeded, Reason: "BuildStrategyNotFound", Status: corev1.ConditionFalse, }, @@ -997,7 +997,7 @@ var _ = Describe("Reconcile BuildRun", func() { It("fails on a TaskRun creation due to owner references errors", func() { // override the Build to use a namespaced BuildStrategy - buildSample = ctl.DefaultBuild(buildName, strategyName, build.NamespacedBuildStrategyKind) + buildSample = ctl.DefaultBuild(buildName, strategyName, buildapi.NamespacedBuildStrategyKind) // Override Stub get calls to include a service account // and BuildStrategies @@ -1014,8 +1014,8 @@ var _ = Describe("Reconcile BuildRun", func() { statusCall := ctl.StubBuildRunStatus( "foobar error", emptyTaskRunName, - build.Condition{ - Type: build.Succeeded, + buildapi.Condition{ + Type: buildapi.Succeeded, Reason: "SetOwnerReferenceFailed", Status: corev1.ConditionFalse, }, @@ -1038,7 +1038,7 @@ var _ = Describe("Reconcile BuildRun", func() { It("succeeds creating a TaskRun from a namespaced buildstrategy", func() { // override the Build to use a namespaced BuildStrategy - buildSample = ctl.DefaultBuild(buildName, strategyName, build.NamespacedBuildStrategyKind) + buildSample = ctl.DefaultBuild(buildName, strategyName, buildapi.NamespacedBuildStrategyKind) // Override Stub get calls to include a service account // and BuildStrategies @@ -1067,7 +1067,7 @@ var _ = Describe("Reconcile BuildRun", func() { It("succeeds creating a TaskRun from a cluster buildstrategy", func() { // override the Build to use a cluster BuildStrategy - buildSample = ctl.DefaultBuild(buildName, strategyName, build.ClusterBuildStrategyKind) + buildSample = ctl.DefaultBuild(buildName, strategyName, buildapi.ClusterBuildStrategyKind) // Override Stub get calls to include a service account // and BuildStrategies @@ -1094,13 +1094,13 @@ var _ = Describe("Reconcile BuildRun", func() { It("stops creation when a FALSE registered status of the build occurs", func() { // Init the Build with registered status false - buildSample = ctl.DefaultBuildWithFalseRegistered(buildName, strategyName, build.ClusterBuildStrategyKind) + buildSample = ctl.DefaultBuildWithFalseRegistered(buildName, strategyName, buildapi.ClusterBuildStrategyKind) getClientStub := func(_ context.Context, nn types.NamespacedName, object crc.Object, _ ...crc.GetOption) error { switch object := object.(type) { - case *build.Build: + case *buildapi.Build: buildSample.DeepCopyInto(object) return nil - case *build.BuildRun: + case *buildapi.BuildRun: buildRunSample.DeepCopyInto(object) return nil } @@ -1114,8 +1114,8 @@ var _ = Describe("Reconcile BuildRun", func() { statusCall := ctl.StubBuildRunStatus( fmt.Sprintf("the Build is not registered correctly, build: %s, registered status: False, reason: something bad happened", buildName), emptyTaskRunName, - build.Condition{ - Type: build.Succeeded, + buildapi.Condition{ + Type: buildapi.Succeeded, Reason: "BuildRegistrationFailed", Status: corev1.ConditionFalse, }, @@ -1132,9 +1132,9 @@ var _ = Describe("Reconcile BuildRun", func() { }) It("delays creation if the registered status of the build is not yet set", func() { - buildSample = ctl.DefaultBuild(buildName, strategyName, build.ClusterBuildStrategyKind) - buildSample.Status.Registered = build.ConditionStatusPtr("") - buildSample.Status.Reason = build.BuildReasonPtr("") + buildSample = ctl.DefaultBuild(buildName, strategyName, buildapi.ClusterBuildStrategyKind) + buildSample.Status.Registered = buildapi.ConditionStatusPtr("") + buildSample.Status.Reason = buildapi.BuildReasonPtr("") client.GetCalls(ctl.StubBuildRunGetWithoutSA(buildSample, buildRunSample)) @@ -1150,7 +1150,7 @@ var _ = Describe("Reconcile BuildRun", func() { buildRunSample.Status.BuildSpec = &buildSample.Spec // override the Build to use a namespaced BuildStrategy - buildSample = ctl.DefaultBuild(buildName, strategyName, build.NamespacedBuildStrategyKind) + buildSample = ctl.DefaultBuild(buildName, strategyName, buildapi.NamespacedBuildStrategyKind) // Override Stub get calls to include a service account // and BuildStrategies @@ -1185,7 +1185,7 @@ var _ = Describe("Reconcile BuildRun", func() { buildRunSample.Status.BuildSpec = &buildSample.Spec // override the Build to use a namespaced BuildStrategy - buildSample = ctl.BuildWithBuildRunDeletions(buildName, strategyName, build.NamespacedBuildStrategyKind) + buildSample = ctl.BuildWithBuildRunDeletions(buildName, strategyName, buildapi.NamespacedBuildStrategyKind) // Override Stub get calls to include a service account // and BuildStrategies @@ -1197,7 +1197,7 @@ var _ = Describe("Reconcile BuildRun", func() { ctl.DefaultNamespacedBuildStrategy()), ) - statusCall := ctl.StubBuildStatusReason(build.SetOwnerReferenceFailed, + statusCall := ctl.StubBuildStatusReason(buildapi.SetOwnerReferenceFailed, fmt.Sprintf("unexpected error when trying to set the ownerreference: Object /%s is already owned by another %s controller ", buildRunName, fakeOwnerName), ) statusWriter.UpdateCalls(statusCall) @@ -1214,7 +1214,7 @@ var _ = Describe("Reconcile BuildRun", func() { buildRunSample.Status.BuildSpec = &buildSample.Spec // override the Build to use a namespaced BuildStrategy - buildSample = ctl.BuildWithBuildRunDeletionsAndFakeNS(buildName, strategyName, build.NamespacedBuildStrategyKind) + buildSample = ctl.BuildWithBuildRunDeletionsAndFakeNS(buildName, strategyName, buildapi.NamespacedBuildStrategyKind) // Override Stub get calls to include a service account // and BuildStrategies @@ -1226,7 +1226,7 @@ var _ = Describe("Reconcile BuildRun", func() { ctl.DefaultNamespacedBuildStrategy()), ) - statusCall := ctl.StubBuildStatusReason(build.SetOwnerReferenceFailed, + statusCall := ctl.StubBuildStatusReason(buildapi.SetOwnerReferenceFailed, fmt.Sprintf("unexpected error when trying to set the ownerreference: cross-namespace owner references are disallowed, owner's namespace %s, obj's namespace %s", buildSample.Namespace, buildRunSample.Namespace), ) statusWriter.UpdateCalls(statusCall) @@ -1240,7 +1240,7 @@ var _ = Describe("Reconcile BuildRun", func() { It("ensure the Build can own a BuildRun when using the proper annotation", func() { buildRunSample = ctl.BuildRunWithoutSA(buildRunName, buildName) - buildSample = ctl.BuildWithBuildRunDeletions(buildName, strategyName, build.NamespacedBuildStrategyKind) + buildSample = ctl.BuildWithBuildRunDeletions(buildName, strategyName, buildapi.NamespacedBuildStrategyKind) // Override Stub get calls to include a service account // and BuildStrategies @@ -1268,7 +1268,7 @@ var _ = Describe("Reconcile BuildRun", func() { It("should return an error and stop reconciling if buildstrategy is not found", func() { buildRunSample = ctl.BuildRunWithoutSA(buildRunName, buildName) - buildSample = ctl.BuildWithBuildRunDeletions(buildName, strategyName, build.ClusterBuildStrategyKind) + buildSample = ctl.BuildWithBuildRunDeletions(buildName, strategyName, buildapi.ClusterBuildStrategyKind) // Override Stub get calls to include a service account // but none BuildStrategy @@ -1280,8 +1280,8 @@ var _ = Describe("Reconcile BuildRun", func() { statusWriter.UpdateCalls(func(_ context.Context, object crc.Object, _ ...crc.SubResourceUpdateOption) error { switch buildRun := object.(type) { - case *build.BuildRun: - if buildRun.Status.IsFailed(build.Succeeded) { + case *buildapi.BuildRun: + if buildRun.Status.IsFailed(buildapi.Succeeded) { return fmt.Errorf("failed miserably") } } @@ -1300,10 +1300,10 @@ var _ = Describe("Reconcile BuildRun", func() { client.GetCalls(ctl.StubBuildRun(buildRunSample)) statusWriter.UpdateCalls(func(_ context.Context, o crc.Object, _ ...crc.SubResourceUpdateOption) error { - Expect(o).To(BeAssignableToTypeOf(&build.BuildRun{})) + Expect(o).To(BeAssignableToTypeOf(&buildapi.BuildRun{})) switch buildRun := o.(type) { - case *build.BuildRun: - condition := buildRun.Status.GetCondition(build.Succeeded) + case *buildapi.BuildRun: + condition := buildRun.Status.GetCondition(buildapi.Succeeded) Expect(condition.Reason).To(Equal(resources.BuildRunNameInvalid)) Expect(condition.Message).To(Equal("must be no more than 63 characters")) } @@ -1321,10 +1321,10 @@ var _ = Describe("Reconcile BuildRun", func() { client.GetCalls(ctl.StubBuildRun(buildRunSample)) statusWriter.UpdateCalls(func(_ context.Context, o crc.Object, _ ...crc.SubResourceUpdateOption) error { - Expect(o).To(BeAssignableToTypeOf(&build.BuildRun{})) + Expect(o).To(BeAssignableToTypeOf(&buildapi.BuildRun{})) switch buildRun := o.(type) { - case *build.BuildRun: - condition := buildRun.Status.GetCondition(build.Succeeded) + case *buildapi.BuildRun: + condition := buildRun.Status.GetCondition(buildapi.Succeeded) Expect(condition.Reason).To(Equal(resources.BuildRunNameInvalid)) Expect(condition.Message).To(ContainSubstring("a valid label must be an empty string or consist of alphanumeric characters")) } @@ -1352,20 +1352,20 @@ var _ = Describe("Reconcile BuildRun", func() { }) Context("from an existing BuildRun resource with embedded BuildSpec", func() { - var clusterBuildStrategy = build.ClusterBuildStrategyKind + var clusterBuildStrategy = buildapi.ClusterBuildStrategyKind BeforeEach(func() { buildRunRequest = newReconcileRequest(buildRunName, ns) }) Context("invalid BuildRun resource", func() { - simpleReconcileRunWithCustomUpdateCall := func(f func(*build.Condition)) { + simpleReconcileRunWithCustomUpdateCall := func(f func(*buildapi.Condition)) { client.GetCalls(ctl.StubBuildRun(buildRunSample)) statusWriter.UpdateCalls(func(_ context.Context, o crc.Object, _ ...crc.SubResourceUpdateOption) error { - Expect(o).To(BeAssignableToTypeOf(&build.BuildRun{})) + Expect(o).To(BeAssignableToTypeOf(&buildapi.BuildRun{})) switch buildRun := o.(type) { - case *build.BuildRun: - f(buildRun.Status.GetCondition(build.Succeeded)) + case *buildapi.BuildRun: + f(buildRun.Status.GetCondition(buildapi.Succeeded)) } return nil @@ -1390,112 +1390,112 @@ var _ = Describe("Reconcile BuildRun", func() { } It("should mark BuildRun as invalid if both BuildRef and BuildSpec are unspecified", func() { - buildRunSample = &build.BuildRun{ + buildRunSample = &buildapi.BuildRun{ ObjectMeta: metav1.ObjectMeta{ Name: buildRunName, }, - Spec: build.BuildRunSpec{}, + Spec: buildapi.BuildRunSpec{}, } - simpleReconcileRunWithCustomUpdateCall(func(condition *build.Condition) { + simpleReconcileRunWithCustomUpdateCall(func(condition *buildapi.Condition) { Expect(condition.Reason).To(Equal(resources.BuildRunNoRefOrSpec)) Expect(condition.Message).To(Equal("no build referenced or specified, either 'buildRef' or 'buildSpec' has to be set")) }) }) It("should mark BuildRun as invalid if Build name and BuildSpec are used", func() { - buildRunSample = &build.BuildRun{ + buildRunSample = &buildapi.BuildRun{ ObjectMeta: metav1.ObjectMeta{ Name: buildRunName, }, - Spec: build.BuildRunSpec{ - Build: build.ReferencedBuild{ - Spec: &build.BuildSpec{}, + Spec: buildapi.BuildRunSpec{ + Build: buildapi.ReferencedBuild{ + Spec: &buildapi.BuildSpec{}, Name: pointer.String("foobar"), }, }, } - simpleReconcileRunWithCustomUpdateCall(func(condition *build.Condition) { + simpleReconcileRunWithCustomUpdateCall(func(condition *buildapi.Condition) { Expect(condition.Reason).To(Equal(resources.BuildRunAmbiguousBuild)) Expect(condition.Message).To(Equal("fields 'buildRef' and 'buildSpec' are mutually exclusive")) }) }) It("should mark BuildRun as invalid if Output and BuildSpec are used", func() { - buildRunSample = &build.BuildRun{ + buildRunSample = &buildapi.BuildRun{ ObjectMeta: metav1.ObjectMeta{ Name: buildRunName, }, - Spec: build.BuildRunSpec{ - Output: &build.Image{Image: "foo:bar"}, - Build: build.ReferencedBuild{ - Spec: &build.BuildSpec{}, + Spec: buildapi.BuildRunSpec{ + Output: &buildapi.Image{Image: "foo:bar"}, + Build: buildapi.ReferencedBuild{ + Spec: &buildapi.BuildSpec{}, }, }, } - simpleReconcileRunWithCustomUpdateCall(func(condition *build.Condition) { + simpleReconcileRunWithCustomUpdateCall(func(condition *buildapi.Condition) { Expect(condition.Reason).To(Equal(resources.BuildRunBuildFieldOverrideForbidden)) Expect(condition.Message).To(Equal("cannot use 'output' override and 'buildSpec' simultaneously")) }) }) It("should mark BuildRun as invalid if ParamValues and BuildSpec are used", func() { - buildRunSample = &build.BuildRun{ + buildRunSample = &buildapi.BuildRun{ ObjectMeta: metav1.ObjectMeta{ Name: buildRunName, }, - Spec: build.BuildRunSpec{ - ParamValues: []build.ParamValue{{ + Spec: buildapi.BuildRunSpec{ + ParamValues: []buildapi.ParamValue{{ Name: "foo", - SingleValue: &build.SingleValue{Value: pointer.String("bar")}, + SingleValue: &buildapi.SingleValue{Value: pointer.String("bar")}, }}, - Build: build.ReferencedBuild{ - Spec: &build.BuildSpec{}, + Build: buildapi.ReferencedBuild{ + Spec: &buildapi.BuildSpec{}, }, }, } - simpleReconcileRunWithCustomUpdateCall(func(condition *build.Condition) { + simpleReconcileRunWithCustomUpdateCall(func(condition *buildapi.Condition) { Expect(condition.Reason).To(Equal(resources.BuildRunBuildFieldOverrideForbidden)) Expect(condition.Message).To(Equal("cannot use 'paramValues' override and 'buildSpec' simultaneously")) }) }) It("should mark BuildRun as invalid if Env and BuildSpec are used", func() { - buildRunSample = &build.BuildRun{ + buildRunSample = &buildapi.BuildRun{ ObjectMeta: metav1.ObjectMeta{ Name: buildRunName, }, - Spec: build.BuildRunSpec{ + Spec: buildapi.BuildRunSpec{ Env: []corev1.EnvVar{{Name: "foo", Value: "bar"}}, - Build: build.ReferencedBuild{ - Spec: &build.BuildSpec{}, + Build: buildapi.ReferencedBuild{ + Spec: &buildapi.BuildSpec{}, }, }, } - simpleReconcileRunWithCustomUpdateCall(func(condition *build.Condition) { + simpleReconcileRunWithCustomUpdateCall(func(condition *buildapi.Condition) { Expect(condition.Reason).To(Equal(resources.BuildRunBuildFieldOverrideForbidden)) Expect(condition.Message).To(Equal("cannot use 'env' override and 'buildSpec' simultaneously")) }) }) It("should mark BuildRun as invalid if Timeout and BuildSpec are used", func() { - buildRunSample = &build.BuildRun{ + buildRunSample = &buildapi.BuildRun{ ObjectMeta: metav1.ObjectMeta{ Name: buildRunName, }, - Spec: build.BuildRunSpec{ + Spec: buildapi.BuildRunSpec{ Timeout: &metav1.Duration{Duration: time.Second}, - Build: build.ReferencedBuild{ - Spec: &build.BuildSpec{}, + Build: buildapi.ReferencedBuild{ + Spec: &buildapi.BuildSpec{}, }, }, } - simpleReconcileRunWithCustomUpdateCall(func(condition *build.Condition) { + simpleReconcileRunWithCustomUpdateCall(func(condition *buildapi.Condition) { Expect(condition.Reason).To(Equal(resources.BuildRunBuildFieldOverrideForbidden)) Expect(condition.Message).To(Equal("cannot use 'timeout' override and 'buildSpec' simultaneously")) }) @@ -1504,25 +1504,25 @@ var _ = Describe("Reconcile BuildRun", func() { Context("valid BuildRun resource", func() { It("should reconcile a BuildRun with an embedded BuildSpec", func() { - buildRunSample = &build.BuildRun{ + buildRunSample = &buildapi.BuildRun{ ObjectMeta: metav1.ObjectMeta{ Name: buildRunName, }, - Spec: build.BuildRunSpec{ - Build: build.ReferencedBuild{ - Spec: &build.BuildSpec{ - Source: &build.Source{ - Type: build.GitType, - Git: &build.Git{ + Spec: buildapi.BuildRunSpec{ + Build: buildapi.ReferencedBuild{ + Spec: &buildapi.BuildSpec{ + Source: &buildapi.Source{ + Type: buildapi.GitType, + Git: &buildapi.Git{ URL: "https://github.com/shipwright-io/sample-go.git", }, ContextDir: pointer.String("source-build"), }, - Strategy: build.Strategy{ + Strategy: buildapi.Strategy{ Kind: &clusterBuildStrategy, Name: strategyName, }, - Output: build.Image{ + Output: buildapi.Image{ Image: "foo/bar:latest", }, }, @@ -1533,10 +1533,10 @@ var _ = Describe("Reconcile BuildRun", func() { client.GetCalls(func(_ context.Context, nn types.NamespacedName, o crc.Object, _ ...crc.GetOption) error { switch object := o.(type) { - case *build.BuildRun: + case *buildapi.BuildRun: buildRunSample.DeepCopyInto(object) return nil - case *build.ClusterBuildStrategy: + case *buildapi.ClusterBuildStrategy: ctl.ClusterBuildStrategy(strategyName).DeepCopyInto(object) return nil } @@ -1546,9 +1546,9 @@ var _ = Describe("Reconcile BuildRun", func() { statusWriter.UpdateCalls(func(_ context.Context, o crc.Object, _ ...crc.SubResourceUpdateOption) error { switch buildRun := o.(type) { - case *build.BuildRun: - Expect(buildRun.Labels).ToNot(HaveKey(build.LabelBuild), "no build name label is suppose to be set") - Expect(buildRun.Labels).ToNot(HaveKey(build.LabelBuildGeneration), "no build generation label is suppose to be set") + case *buildapi.BuildRun: + Expect(buildRun.Labels).ToNot(HaveKey(buildapi.LabelBuild), "no build name label is suppose to be set") + Expect(buildRun.Labels).ToNot(HaveKey(buildapi.LabelBuildGeneration), "no build generation label is suppose to be set") return nil } @@ -1560,8 +1560,8 @@ 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") + Expect(taskRun.Labels).ToNot(HaveKey(buildapi.LabelBuild), "no build name label is suppose to be set") + Expect(taskRun.Labels).ToNot(HaveKey(buildapi.LabelBuildGeneration), "no build generation label is suppose to be set") } return nil @@ -1584,7 +1584,7 @@ var _ = Describe("Reconcile BuildRun", func() { }, } - statusCall := ctl.StubFunc(corev1.ConditionFalse, build.SpecEnvNameCanNotBeBlank, "name for environment variable must not be blank") + statusCall := ctl.StubFunc(corev1.ConditionFalse, buildapi.SpecEnvNameCanNotBeBlank, "name for environment variable must not be blank") statusWriter.UpdateCalls(statusCall) _, err := reconciler.Reconcile(context.TODO(), buildRunRequest) @@ -1604,7 +1604,7 @@ var _ = Describe("Reconcile BuildRun", func() { }, } - statusCall := ctl.StubFunc(corev1.ConditionFalse, build.SpecEnvNameCanNotBeBlank, "name for environment variable must not be blank") + statusCall := ctl.StubFunc(corev1.ConditionFalse, buildapi.SpecEnvNameCanNotBeBlank, "name for environment variable must not be blank") statusWriter.UpdateCalls(statusCall) _, err := reconciler.Reconcile(context.TODO(), buildRunRequest) @@ -1625,7 +1625,7 @@ var _ = Describe("Reconcile BuildRun", func() { }, } - statusCall := ctl.StubFunc(corev1.ConditionFalse, build.SpecEnvOnlyOneOfValueOrValueFromMustBeSpecified, "only one of value or valueFrom must be specified") + statusCall := ctl.StubFunc(corev1.ConditionFalse, buildapi.SpecEnvOnlyOneOfValueOrValueFromMustBeSpecified, "only one of value or valueFrom must be specified") statusWriter.UpdateCalls(statusCall) _, err := reconciler.Reconcile(context.TODO(), buildRunRequest) @@ -1641,7 +1641,7 @@ var _ = Describe("Reconcile BuildRun", func() { }, } - statusCall := ctl.StubFunc(corev1.ConditionTrue, build.BuildReason(build.Succeeded), "all validations succeeded") + statusCall := ctl.StubFunc(corev1.ConditionTrue, buildapi.BuildReason(buildapi.Succeeded), "all validations succeeded") statusWriter.UpdateCalls(statusCall) _, err := reconciler.Reconcile(context.TODO(), buildRunRequest) @@ -1661,7 +1661,7 @@ var _ = Describe("Reconcile BuildRun", func() { }, } - statusCall := ctl.StubFunc(corev1.ConditionTrue, build.BuildReason(build.Succeeded), "all validations succeeded") + statusCall := ctl.StubFunc(corev1.ConditionTrue, buildapi.BuildReason(buildapi.Succeeded), "all validations succeeded") statusWriter.UpdateCalls(statusCall) _, err := reconciler.Reconcile(context.TODO(), buildRunRequest) diff --git a/pkg/reconciler/buildrun/controller.go b/pkg/reconciler/buildrun/controller.go index f6c0974868..f7c2dd310c 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" - buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/config" ) @@ -53,7 +53,7 @@ func add(mgr manager.Manager, r reconcile.Reconciler, maxConcurrentReconciles in predBuildRun := predicate.Funcs{ CreateFunc: func(e event.CreateEvent) bool { - o := e.Object.(*buildv1beta1.BuildRun) + o := e.Object.(*buildapi.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. @@ -61,8 +61,8 @@ func add(mgr manager.Manager, r reconcile.Reconciler, maxConcurrentReconciles in }, UpdateFunc: func(e event.UpdateEvent) bool { // Ignore updates to CR status in which case metadata.Generation does not change - o := e.ObjectOld.(*buildv1beta1.BuildRun) - n := e.ObjectNew.(*buildv1beta1.BuildRun) + o := e.ObjectOld.(*buildapi.BuildRun) + n := e.ObjectNew.(*buildapi.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(mgr.GetCache(), &buildv1beta1.BuildRun{}), &handler.EnqueueRequestForObject{}, predBuildRun); err != nil { + if err = c.Watch(source.Kind(mgr.GetCache(), &buildapi.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()[buildv1beta1.LabelBuildRun] == "" { + if taskRun.GetLabels() == nil || taskRun.GetLabels()[buildapi.LabelBuildRun] == "" { return []reconcile.Request{} } diff --git a/pkg/reconciler/buildrun/resources/build.go b/pkg/reconciler/buildrun/resources/build.go index fd04759916..0c09773278 100644 --- a/pkg/reconciler/buildrun/resources/build.go +++ b/pkg/reconciler/buildrun/resources/build.go @@ -13,11 +13,11 @@ import ( "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" - buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "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 *buildv1beta1.BuildRun, build *buildv1beta1.Build) error { +func GetBuildObject(ctx context.Context, client client.Client, buildRun *buildapi.BuildRun, build *buildapi.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.Build.Name != nil { @@ -38,7 +38,7 @@ func GetBuildObject(ctx context.Context, client client.Client, buildRun *buildv1 if buildRun.Spec.Build.Spec != nil { build.Name = "" build.Namespace = buildRun.Namespace - build.Status = buildv1beta1.BuildStatus{} + build.Status = buildapi.BuildStatus{} buildRun.Spec.Build.Spec.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 *buildv1beta1.Build, controlledReferences []metav1.OwnerReference) bool { +func IsOwnedByBuild(build *buildapi.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 00461f9c61..186bdb9b51 100644 --- a/pkg/reconciler/buildrun/resources/build_test.go +++ b/pkg/reconciler/buildrun/resources/build_test.go @@ -17,7 +17,7 @@ import ( "k8s.io/apimachinery/pkg/types" crc "sigs.k8s.io/controller-runtime/pkg/client" - build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "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/v1beta1_samples" @@ -33,25 +33,25 @@ var _ = Describe("Build Resource", func() { // init vars buildName := "foobuild" client = &fakes.FakeClient{} - buildRun := &build.BuildRun{ + buildRun := &buildapi.BuildRun{ ObjectMeta: metav1.ObjectMeta{ Name: "foo", Namespace: "bar", }, - Spec: build.BuildRunSpec{ - Build: build.ReferencedBuild{ + Spec: buildapi.BuildRunSpec{ + Build: buildapi.ReferencedBuild{ Name: &buildName, }, }, } It("should be able to retrieve a build object if exists", func() { - buildSample := ctl.DefaultBuild(buildName, "foostrategy", build.ClusterBuildStrategyKind) + buildSample := ctl.DefaultBuild(buildName, "foostrategy", buildapi.ClusterBuildStrategyKind) // stub a GET API call with buildSample contents getClientStub := func(_ context.Context, nn types.NamespacedName, object crc.Object, _ ...crc.GetOption) error { switch object := object.(type) { - case *build.Build: + case *buildapi.Build: buildSample.DeepCopyInto(object) return nil } @@ -61,7 +61,7 @@ var _ = Describe("Build Resource", func() { // fake the calls with the above stub definition client.GetCalls(getClientStub) - buildObject := &build.Build{} + buildObject := &buildapi.Build{} Expect(resources.GetBuildObject(context.TODO(), client, buildRun, buildObject)).To(BeNil()) }) @@ -75,14 +75,14 @@ var _ = Describe("Build Resource", func() { return &fakes.FakeStatusWriter{} }) - build := &build.Build{} + build := &buildapi.Build{} Expect(resources.GetBuildObject(context.TODO(), client, buildRun, build)).ToNot(BeNil()) }) It("should be able to verify valid ownerships", func() { managingController := true - buildSample := &build.Build{ + buildSample := &buildapi.Build{ TypeMeta: metav1.TypeMeta{ Kind: "fakekind", }, @@ -106,7 +106,7 @@ var _ = Describe("Build Resource", func() { It("should be able to verify invalid ownerships", func() { managingController := true - buildSample := &build.Build{ + buildSample := &buildapi.Build{ TypeMeta: metav1.TypeMeta{ Kind: "notthatkind", }, @@ -130,14 +130,14 @@ var _ = Describe("Build Resource", func() { Context("Operating on embedded Build(Spec) resources", func() { client = &fakes.FakeClient{} - buildRun := &build.BuildRun{ + buildRun := &buildapi.BuildRun{ ObjectMeta: metav1.ObjectMeta{ Name: "foo", Namespace: "bar", }, - Spec: build.BuildRunSpec{ - Build: build.ReferencedBuild{ - Spec: &build.BuildSpec{ + Spec: buildapi.BuildRunSpec{ + Build: buildapi.ReferencedBuild{ + Spec: &buildapi.BuildSpec{ Env: []v1.EnvVar{{Name: "foo", Value: "bar"}}, }, }, @@ -145,7 +145,7 @@ var _ = Describe("Build Resource", func() { } It("should be able to retrieve an embedded build object if it exists", func() { - build := &build.Build{} + build := &buildapi.Build{} err := resources.GetBuildObject(context.TODO(), client, buildRun, build) Expect(err).To(BeNil()) diff --git a/pkg/reconciler/buildrun/resources/conditions.go b/pkg/reconciler/buildrun/resources/conditions.go index 0d3ef8380a..ee9029f661 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" - buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "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 *buildv1beta1.BuildRun, taskRun *pipelineapi.TaskRun, trCondition *apis.Condition) error { +func UpdateBuildRunUsingTaskRunCondition(ctx context.Context, client client.Client, buildRun *buildapi.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 = buildv1beta1.BuildRunStateCancel + reason = buildapi.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 = buildv1beta1.BuildRunStateCancel + reason = buildapi.BuildRunStateCancel message = "The BuildRun and underlying TaskRun were canceled successfully." } @@ -95,15 +95,15 @@ func UpdateBuildRunUsingTaskRunCondition(ctx context.Context, client client.Clie } //nolint:staticcheck // SA1019 we want to give users some time to adopt to failureDetails - buildRun.Status.FailureDetails = &buildv1beta1.FailureDetails{ - Location: &buildv1beta1.Location{ + buildRun.Status.FailureDetails = &buildapi.FailureDetails{ + Location: &buildapi.Location{ Pod: pod.Name, }, } if pod.Status.Reason == "Evicted" { message = pod.Status.Message - reason = buildv1beta1.BuildRunStatePodEvicted + reason = buildapi.BuildRunStatePodEvicted if failedContainer != nil { //nolint:staticcheck // SA1019 we want to give users some time to adopt to failureDetails buildRun.Status.FailureDetails.Location.Container = failedContainer.Name @@ -128,9 +128,9 @@ func UpdateBuildRunUsingTaskRunCondition(ctx context.Context, client client.Clie } } - buildRun.Status.SetCondition(&buildv1beta1.Condition{ + buildRun.Status.SetCondition(&buildapi.Condition{ LastTransitionTime: metav1.Now(), - Type: buildv1beta1.Succeeded, + Type: buildapi.Succeeded, Status: status, Reason: reason, Message: message, @@ -142,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 *buildv1beta1.BuildRun, errorMessage string, reason string) error { +func UpdateConditionWithFalseStatus(ctx context.Context, client client.Client, buildRun *buildapi.BuildRun, errorMessage string, reason string) error { now := metav1.Now() buildRun.Status.CompletionTime = &now - buildRun.Status.SetCondition(&buildv1beta1.Condition{ + buildRun.Status.SetCondition(&buildapi.Condition{ LastTransitionTime: now, - Type: buildv1beta1.Succeeded, + Type: buildapi.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 06dbe2fbcc..d570b832a8 100644 --- a/pkg/reconciler/buildrun/resources/conditions_test.go +++ b/pkg/reconciler/buildrun/resources/conditions_test.go @@ -9,7 +9,7 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "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/v1beta1_samples" @@ -37,7 +37,7 @@ var _ = Describe("Conditions", func() { // BuildRun implements StatusConditions, therefore it can operate on // an existing Condition - msg := br.Status.GetCondition(build.Succeeded).GetMessage() + msg := br.Status.GetCondition(buildapi.Succeeded).GetMessage() Expect(msg).To(Equal("foo is not bar")) }) @@ -45,7 +45,7 @@ var _ = Describe("Conditions", func() { // BuildRun sample with an embedded condition of the type Succeeded br := ctl.BuildRunWithSucceededCondition() - reason := br.Status.GetCondition(build.Succeeded).GetReason() + reason := br.Status.GetCondition(buildapi.Succeeded).GetReason() Expect(reason).To(Equal("foobar")) }) @@ -53,7 +53,7 @@ var _ = Describe("Conditions", func() { // BuildRun sample with an embedded condition of the type Succeeded br := ctl.BuildRunWithSucceededCondition() - status := br.Status.GetCondition(build.Succeeded).GetStatus() + status := br.Status.GetCondition(buildapi.Succeeded).GetStatus() Expect(status).To(Equal(corev1.ConditionUnknown)) }) @@ -62,15 +62,15 @@ var _ = Describe("Conditions", func() { // when getting a condition that does not exists on the BuildRun, do not // panic but rather return a nil - cond := br.Status.GetCondition(build.Succeeded) + cond := br.Status.GetCondition(buildapi.Succeeded) Expect(cond).To(BeNil()) }) It("should be able to set a condition based on a type", func() { br := ctl.DefaultBuildRun("foo", "bar") // generate a condition of the type Succeeded - tmpCond := &build.Condition{ - Type: build.Succeeded, + tmpCond := &buildapi.Condition{ + Type: buildapi.Succeeded, Status: corev1.ConditionUnknown, Message: "foobar", Reason: "foo is bar", @@ -80,11 +80,11 @@ var _ = Describe("Conditions", func() { // set the condition on the BuildRun resource br.Status.SetCondition(tmpCond) - condition := br.Status.GetCondition(build.Succeeded) + condition := br.Status.GetCondition(buildapi.Succeeded) Expect(condition).ToNot(BeNil()) - Expect(condition.Type).To(Equal(build.Succeeded)) + Expect(condition.Type).To(Equal(buildapi.Succeeded)) - condMsg := br.Status.GetCondition(build.Succeeded).GetMessage() + condMsg := br.Status.GetCondition(buildapi.Succeeded).GetMessage() Expect(condMsg).To(Equal("foobar")) }) @@ -92,12 +92,12 @@ var _ = Describe("Conditions", func() { // BuildRun sample with an embedded condition of the type Succeeded br := ctl.BuildRunWithSucceededCondition() - reason := br.Status.GetCondition(build.Succeeded).GetReason() + reason := br.Status.GetCondition(buildapi.Succeeded).GetReason() Expect(reason).To(Equal("foobar")) // generate a condition in order to update the existing one - tmpCond := &build.Condition{ - Type: build.Succeeded, + tmpCond := &buildapi.Condition{ + Type: buildapi.Succeeded, Status: corev1.ConditionUnknown, Message: "foobar was updated", Reason: "foo is bar", @@ -107,7 +107,7 @@ var _ = Describe("Conditions", func() { // update the condition on the BuildRun resource br.Status.SetCondition(tmpCond) - condMsg := br.Status.GetCondition(build.Succeeded).GetMessage() + condMsg := br.Status.GetCondition(buildapi.Succeeded).GetMessage() Expect(condMsg).To(Equal("foobar was updated")) }) @@ -116,7 +116,7 @@ var _ = Describe("Conditions", func() { var ( client *fakes.FakeClient ctl test.Catalog - br *build.BuildRun + br *buildapi.BuildRun tr *pipelineapi.TaskRun ) @@ -277,8 +277,8 @@ var _ = Describe("Conditions", func() { // Finally, check the output of the buildRun Expect(br.Status.GetCondition( - build.Succeeded).Reason, - ).To(Equal(build.BuildRunStatePodEvicted)) + buildapi.Succeeded).Reason, + ).To(Equal(buildapi.BuildRunStatePodEvicted)) }) It("updates a BuildRun condition when the related TaskRun fails and pod containers are not available", func() { diff --git a/pkg/reconciler/buildrun/resources/credentials.go b/pkg/reconciler/buildrun/resources/credentials.go index 495154b410..4e6406f5bd 100644 --- a/pkg/reconciler/buildrun/resources/credentials.go +++ b/pkg/reconciler/buildrun/resources/credentials.go @@ -9,13 +9,13 @@ import ( corev1 "k8s.io/api/core/v1" - buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "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 *buildv1beta1.Build, buildRun *buildv1beta1.BuildRun, serviceAccount *corev1.ServiceAccount) bool { +func ApplyCredentials(ctx context.Context, build *buildapi.Build, buildRun *buildapi.BuildRun, serviceAccount *corev1.ServiceAccount) bool { modified := false diff --git a/pkg/reconciler/buildrun/resources/credentials_test.go b/pkg/reconciler/buildrun/resources/credentials_test.go index b2bdf4df8c..4fb8d04e49 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" - buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/reconciler/buildrun/resources" ) var _ = Describe("Credentials", func() { var ( - build *buildv1beta1.Build - buildRun *buildv1beta1.BuildRun + build *buildapi.Build + buildRun *buildapi.BuildRun beforeServiceAccount *corev1.ServiceAccount expectedAfterServiceAccount *corev1.ServiceAccount ) @@ -35,25 +35,25 @@ var _ = Describe("Credentials", func() { Context("when secrets were not present in the service account", func() { BeforeEach(func() { - build = &buildv1beta1.Build{ - Spec: buildv1beta1.BuildSpec{ - Source: &buildv1beta1.Source{ - Type: buildv1beta1.GitType, - Git: &buildv1beta1.Git{ + build = &buildapi.Build{ + Spec: buildapi.BuildSpec{ + Source: &buildapi.Source{ + Type: buildapi.GitType, + Git: &buildapi.Git{ URL: "a/b/c", CloneSecret: pointer.String("secret_a"), }, }, - Output: buildv1beta1.Image{ + Output: buildapi.Image{ Image: "quay.io/namespace/image", PushSecret: pointer.String("secret_quay.io"), }, }, } - buildRun = &buildv1beta1.BuildRun{ - Spec: buildv1beta1.BuildRunSpec{ - Output: &buildv1beta1.Image{ + buildRun = &buildapi.BuildRun{ + Spec: buildapi.BuildRunSpec{ + Output: &buildapi.Image{ Image: "quay.io/namespace/brImage", PushSecret: pointer.String("secret_buildrun.io"), }, @@ -81,15 +81,15 @@ var _ = Describe("Credentials", func() { Context("when secrets were already in the service account", func() { BeforeEach(func() { - build = &buildv1beta1.Build{ - Spec: buildv1beta1.BuildSpec{ - Source: &buildv1beta1.Source{ - Type: buildv1beta1.GitType, - Git: &buildv1beta1.Git{ + build = &buildapi.Build{ + Spec: buildapi.BuildSpec{ + Source: &buildapi.Source{ + Type: buildapi.GitType, + Git: &buildapi.Git{ URL: "a/b/c", }, }, - Output: buildv1beta1.Image{ + Output: buildapi.Image{ PushSecret: pointer.String("secret_b"), }, }, @@ -97,9 +97,9 @@ var _ = Describe("Credentials", func() { // This is just a placeholder BuildRun with no // SecretRef added to the ones from the Build - buildRun = &buildv1beta1.BuildRun{ - Spec: buildv1beta1.BuildRunSpec{ - Output: &buildv1beta1.Image{ + buildRun = &buildapi.BuildRun{ + Spec: buildapi.BuildRunSpec{ + Output: &buildapi.Image{ Image: "https://image.url/", }, }, @@ -119,11 +119,11 @@ var _ = Describe("Credentials", func() { Context("when build does not reference any secret", func() { BeforeEach(func() { - build = &buildv1beta1.Build{ - Spec: buildv1beta1.BuildSpec{ - Source: &buildv1beta1.Source{ - Type: buildv1beta1.GitType, - Git: &buildv1beta1.Git{ + build = &buildapi.Build{ + Spec: buildapi.BuildSpec{ + Source: &buildapi.Source{ + Type: buildapi.GitType, + Git: &buildapi.Git{ URL: "a/b/c", CloneSecret: nil, }, @@ -133,9 +133,9 @@ var _ = Describe("Credentials", func() { // This is just a placeholder BuildRun with no // SecretRef added to the ones from the Build - buildRun = &buildv1beta1.BuildRun{ - Spec: buildv1beta1.BuildRunSpec{ - Output: &buildv1beta1.Image{ + buildRun = &buildapi.BuildRun{ + Spec: buildapi.BuildRunSpec{ + Output: &buildapi.Image{ Image: "https://image.url/", }, }, diff --git a/pkg/reconciler/buildrun/resources/failure_details.go b/pkg/reconciler/buildrun/resources/failure_details.go index 3be2dc272e..d17bf13a9d 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" - buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "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 *buildv1beta1.BuildRun, taskRun *pipelineapi.TaskRun) { +func UpdateBuildRunUsingTaskFailures(ctx context.Context, client client.Client, buildRun *buildapi.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 *buildv1beta1.FailureDetails) { - failure = &buildv1beta1.FailureDetails{} +func extractFailureDetails(ctx context.Context, client client.Client, taskRun *pipelineapi.TaskRun) (failure *buildapi.FailureDetails) { + failure = &buildapi.FailureDetails{} failure.Reason, failure.Message = extractFailureReasonAndMessage(taskRun) - failure.Location = &buildv1beta1.Location{Pod: taskRun.Status.PodName} + failure.Location = &buildapi.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 225e3dc0dc..e581bef679 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" - buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "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 := buildv1beta1.BuildRun{} + redBuild := buildapi.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 := buildv1beta1.BuildRun{} + redBuild := buildapi.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 := buildv1beta1.BuildRun{} + greenBuildRun := buildapi.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 := buildv1beta1.BuildRun{} + greenBuildRun := buildapi.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 := buildv1beta1.BuildRun{} + unfinishedBuildRun := buildapi.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 := buildv1beta1.BuildRun{} + unknownBuildRun := buildapi.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 d63f18ae06..6f03d00577 100644 --- a/pkg/reconciler/buildrun/resources/image_processing.go +++ b/pkg/reconciler/buildrun/resources/image_processing.go @@ -12,7 +12,7 @@ import ( core "k8s.io/api/core/v1" - build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "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" "github.com/spf13/pflag" @@ -26,7 +26,7 @@ const ( ) type VulnerablilityScanParams struct { - build.VulnerabilityScanOptions + buildapi.VulnerabilityScanOptions } var _ pflag.Value = &VulnerablilityScanParams{} @@ -48,7 +48,7 @@ func (v *VulnerablilityScanParams) Type() string { } // SetupImageProcessing appends the image-processing step to a TaskRun if desired -func SetupImageProcessing(taskRun *pipelineapi.TaskRun, cfg *config.Config, creationTimestamp time.Time, buildOutput, buildRunOutput build.Image) error { +func SetupImageProcessing(taskRun *pipelineapi.TaskRun, cfg *config.Config, creationTimestamp time.Time, buildOutput, buildRunOutput buildapi.Image) error { stepArgs := []string{} // Check if any build step references the output-directory system parameter. If that is the case, @@ -120,23 +120,23 @@ func SetupImageProcessing(taskRun *pipelineapi.TaskRun, cfg *config.Config, crea // check if we need to set image timestamp if imageTimestamp := getImageTimestamp(buildOutput, buildRunOutput); imageTimestamp != nil { switch *imageTimestamp { - case build.OutputImageZeroTimestamp: + case buildapi.OutputImageZeroTimestamp: stepArgs = append(stepArgs, "--image-timestamp", "0") - case build.OutputImageSourceTimestamp: + case buildapi.OutputImageSourceTimestamp: if !hasTaskSpecResult(taskRun, "shp-source-default-source-timestamp") { return fmt.Errorf("cannot use SourceTimestamp setting, because there is no source timestamp available for this source") } stepArgs = append(stepArgs, "--image-timestamp-file", "$(results.shp-source-default-source-timestamp.path)") - case build.OutputImageBuildTimestamp: + case buildapi.OutputImageBuildTimestamp: stepArgs = append(stepArgs, "--image-timestamp", strconv.FormatInt(creationTimestamp.Unix(), 10)) default: if _, err := strconv.ParseInt(*imageTimestamp, 10, 64); err != nil { return fmt.Errorf("cannot parse output timestamp %s as a number, must be %s, %s, %s, or a an integer", - *imageTimestamp, build.OutputImageZeroTimestamp, build.OutputImageSourceTimestamp, build.OutputImageBuildTimestamp) + *imageTimestamp, buildapi.OutputImageZeroTimestamp, buildapi.OutputImageSourceTimestamp, buildapi.OutputImageBuildTimestamp) } stepArgs = append(stepArgs, "--image-timestamp", *imageTimestamp) @@ -227,7 +227,7 @@ func mergeMaps(first map[string]string, second map[string]string) map[string]str return first } -func GetVulnerabilityScanOptions(buildOutput, buildRunOutput build.Image) *build.VulnerabilityScanOptions { +func GetVulnerabilityScanOptions(buildOutput, buildRunOutput buildapi.Image) *buildapi.VulnerabilityScanOptions { switch { case buildRunOutput.VulnerabilityScan != nil: return buildRunOutput.VulnerabilityScan @@ -238,7 +238,7 @@ func GetVulnerabilityScanOptions(buildOutput, buildRunOutput build.Image) *build } } -func getImageTimestamp(buildOutput, buildRunOutput build.Image) *string { +func getImageTimestamp(buildOutput, buildRunOutput buildapi.Image) *string { switch { case buildRunOutput.Timestamp != nil: return buildRunOutput.Timestamp diff --git a/pkg/reconciler/buildrun/resources/image_processing_test.go b/pkg/reconciler/buildrun/resources/image_processing_test.go index faa178ee1d..7a6c0f3c91 100644 --- a/pkg/reconciler/buildrun/resources/image_processing_test.go +++ b/pkg/reconciler/buildrun/resources/image_processing_test.go @@ -100,7 +100,7 @@ var _ = Describe("Image Processing overrides", func() { Context("for a build with a vulnerability scan options in the output", func() { BeforeEach(func() { processedTaskRun = taskRun.DeepCopy() - resources.SetupImageProcessing(processedTaskRun, config, buildapi.Image{ + resources.SetupImageProcessing(processedTaskRun, config, refTimestamp, buildapi.Image{ Image: "some-registry/some-namespace/some-image", VulnerabilityScan: &buildapi.VulnerabilityScanOptions{ Enabled: true, diff --git a/pkg/reconciler/buildrun/resources/params.go b/pkg/reconciler/buildrun/resources/params.go index 16c79c2dbf..c6f59e3009 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" - buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "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 []buildv1beta1.ParamValue, overrideParams []buildv1beta1.ParamValue) []buildv1beta1.ParamValue { +func OverrideParams(originalParams []buildapi.ParamValue, overrideParams []buildapi.ParamValue) []buildapi.ParamValue { if len(overrideParams) == 0 { return originalParams } @@ -41,7 +41,7 @@ func OverrideParams(originalParams []buildv1beta1.ParamValue, overrideParams []b } // Build a map from originalParams - originalMap := make(map[string]buildv1beta1.ParamValue) + originalMap := make(map[string]buildapi.ParamValue) for _, p := range originalParams { originalMap[p.Name] = p } @@ -53,7 +53,7 @@ func OverrideParams(originalParams []buildv1beta1.ParamValue, overrideParams []b } // drop results on a slice and return - paramsList := []buildv1beta1.ParamValue{} + paramsList := []buildapi.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 []buildv1beta1.Parameter, name string) *buildv1beta1.Parameter { +func FindParameterByName(parameters []buildapi.Parameter, name string) *buildapi.Parameter { for _, candidate := range parameters { if candidate.Name == name { return &candidate @@ -79,7 +79,7 @@ func FindParameterByName(parameters []buildv1beta1.Parameter, name string) *buil } // FindParamValueByName returns the first entry in a ParamValue array with a specified name, or nil -func FindParamValueByName(paramValues []buildv1beta1.ParamValue, name string) *buildv1beta1.ParamValue { +func FindParamValueByName(paramValues []buildapi.ParamValue, name string) *buildapi.ParamValue { for _, candidate := range paramValues { if candidate.Name == name { return &candidate @@ -90,7 +90,7 @@ func FindParamValueByName(paramValues []buildv1beta1.ParamValue, name string) *b } // HandleTaskRunParam makes the necessary changes to a TaskRun for a parameter -func HandleTaskRunParam(taskRun *pipelineapi.TaskRun, parameterDefinition *buildv1beta1.Parameter, paramValue buildv1beta1.ParamValue) error { +func HandleTaskRunParam(taskRun *pipelineapi.TaskRun, parameterDefinition *buildapi.Parameter, paramValue buildapi.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 buildv1beta1.ParameterTypeString: + case buildapi.ParameterTypeString: taskRunParam.Value.Type = pipelineapi.ParamTypeString switch { @@ -145,7 +145,7 @@ func HandleTaskRunParam(taskRun *pipelineapi.TaskRun, parameterDefinition *build } - case buildv1beta1.ParameterTypeArray: + case buildapi.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 3e95fb9d65..8616551ab8 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" - buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "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 []buildv1beta1.ParamValue, buildRunParams []buildv1beta1.ParamValue, expected types.GomegaMatcher) { + func(buildParams []buildapi.ParamValue, buildRunParams []buildapi.ParamValue, expected types.GomegaMatcher) { Expect(OverrideParams(buildParams, buildRunParams)).To(expected) }, Entry("override a single parameter", - []buildv1beta1.ParamValue{ - {Name: "a", SingleValue: &buildv1beta1.SingleValue{ + []buildapi.ParamValue{ + {Name: "a", SingleValue: &buildapi.SingleValue{ Value: pointer.String("2"), }}, - }, []buildv1beta1.ParamValue{ - {Name: "a", SingleValue: &buildv1beta1.SingleValue{ + }, []buildapi.ParamValue{ + {Name: "a", SingleValue: &buildapi.SingleValue{ Value: pointer.String("3"), }}, - }, ContainElements([]buildv1beta1.ParamValue{ - {Name: "a", SingleValue: &buildv1beta1.SingleValue{ + }, ContainElements([]buildapi.ParamValue{ + {Name: "a", SingleValue: &buildapi.SingleValue{ Value: pointer.String("3"), }}, })), Entry("override two parameters", - []buildv1beta1.ParamValue{ - {Name: "a", SingleValue: &buildv1beta1.SingleValue{ + []buildapi.ParamValue{ + {Name: "a", SingleValue: &buildapi.SingleValue{ Value: pointer.String("2"), }}, - {Name: "b", SingleValue: &buildv1beta1.SingleValue{ - SecretValue: &buildv1beta1.ObjectKeyRef{ + {Name: "b", SingleValue: &buildapi.SingleValue{ + SecretValue: &buildapi.ObjectKeyRef{ Name: "a-secret", Key: "a-key", }, }}, - }, []buildv1beta1.ParamValue{ - {Name: "a", SingleValue: &buildv1beta1.SingleValue{ + }, []buildapi.ParamValue{ + {Name: "a", SingleValue: &buildapi.SingleValue{ Value: pointer.String("3"), }}, - {Name: "b", SingleValue: &buildv1beta1.SingleValue{ - ConfigMapValue: &buildv1beta1.ObjectKeyRef{ + {Name: "b", SingleValue: &buildapi.SingleValue{ + ConfigMapValue: &buildapi.ObjectKeyRef{ Name: "a-config-map", Key: "a-cm-key", }, }}, - }, ContainElements([]buildv1beta1.ParamValue{ - {Name: "a", SingleValue: &buildv1beta1.SingleValue{ + }, ContainElements([]buildapi.ParamValue{ + {Name: "a", SingleValue: &buildapi.SingleValue{ Value: pointer.String("3"), }}, - {Name: "b", SingleValue: &buildv1beta1.SingleValue{ - ConfigMapValue: &buildv1beta1.ObjectKeyRef{ + {Name: "b", SingleValue: &buildapi.SingleValue{ + ConfigMapValue: &buildapi.ObjectKeyRef{ Name: "a-config-map", Key: "a-cm-key", }, @@ -74,116 +74,116 @@ var _ = Describe("Params overrides", func() { })), Entry("override multiple parameters", - []buildv1beta1.ParamValue{ - {Name: "a", SingleValue: &buildv1beta1.SingleValue{ + []buildapi.ParamValue{ + {Name: "a", SingleValue: &buildapi.SingleValue{ Value: pointer.String("2"), }}, - {Name: "b", SingleValue: &buildv1beta1.SingleValue{ + {Name: "b", SingleValue: &buildapi.SingleValue{ Value: pointer.String("2"), }}, - {Name: "c", SingleValue: &buildv1beta1.SingleValue{ + {Name: "c", SingleValue: &buildapi.SingleValue{ Value: pointer.String("2"), }}, - }, []buildv1beta1.ParamValue{ - {Name: "a", SingleValue: &buildv1beta1.SingleValue{ + }, []buildapi.ParamValue{ + {Name: "a", SingleValue: &buildapi.SingleValue{ Value: pointer.String("6"), }}, - {Name: "c", SingleValue: &buildv1beta1.SingleValue{ + {Name: "c", SingleValue: &buildapi.SingleValue{ Value: pointer.String("6"), }}, - }, ContainElements([]buildv1beta1.ParamValue{ - {Name: "a", SingleValue: &buildv1beta1.SingleValue{ + }, ContainElements([]buildapi.ParamValue{ + {Name: "a", SingleValue: &buildapi.SingleValue{ Value: pointer.String("6"), }}, - {Name: "b", SingleValue: &buildv1beta1.SingleValue{ + {Name: "b", SingleValue: &buildapi.SingleValue{ Value: pointer.String("2"), }}, - {Name: "c", SingleValue: &buildv1beta1.SingleValue{ + {Name: "c", SingleValue: &buildapi.SingleValue{ Value: pointer.String("6"), }}, })), Entry("dont override when second list is empty", - []buildv1beta1.ParamValue{ - {Name: "t", SingleValue: &buildv1beta1.SingleValue{ + []buildapi.ParamValue{ + {Name: "t", SingleValue: &buildapi.SingleValue{ Value: pointer.String("2"), }}, - {Name: "z", SingleValue: &buildv1beta1.SingleValue{ + {Name: "z", SingleValue: &buildapi.SingleValue{ Value: pointer.String("2"), }}, - {Name: "g", SingleValue: &buildv1beta1.SingleValue{ + {Name: "g", SingleValue: &buildapi.SingleValue{ Value: pointer.String("2"), }}, }, - []buildv1beta1.ParamValue{ + []buildapi.ParamValue{ // no overrides }, - ContainElements([]buildv1beta1.ParamValue{ - {Name: "t", SingleValue: &buildv1beta1.SingleValue{ + ContainElements([]buildapi.ParamValue{ + {Name: "t", SingleValue: &buildapi.SingleValue{ Value: pointer.String("2"), }}, - {Name: "z", SingleValue: &buildv1beta1.SingleValue{ + {Name: "z", SingleValue: &buildapi.SingleValue{ Value: pointer.String("2"), }}, - {Name: "g", SingleValue: &buildv1beta1.SingleValue{ + {Name: "g", SingleValue: &buildapi.SingleValue{ Value: pointer.String("2"), }}, })), Entry("override when first list is empty but not the second list", - []buildv1beta1.ParamValue{ + []buildapi.ParamValue{ // no original values - }, []buildv1beta1.ParamValue{ - {Name: "a", SingleValue: &buildv1beta1.SingleValue{ + }, []buildapi.ParamValue{ + {Name: "a", SingleValue: &buildapi.SingleValue{ Value: pointer.String("6"), }}, - {Name: "c", SingleValue: &buildv1beta1.SingleValue{ + {Name: "c", SingleValue: &buildapi.SingleValue{ Value: pointer.String("6"), }}, - }, ContainElements([]buildv1beta1.ParamValue{ - {Name: "a", SingleValue: &buildv1beta1.SingleValue{ + }, ContainElements([]buildapi.ParamValue{ + {Name: "a", SingleValue: &buildapi.SingleValue{ Value: pointer.String("6"), }}, - {Name: "c", SingleValue: &buildv1beta1.SingleValue{ + {Name: "c", SingleValue: &buildapi.SingleValue{ Value: pointer.String("6"), }}, })), Entry("override multiple parameters if the match and add them if not present in first list", - []buildv1beta1.ParamValue{ - {Name: "a", SingleValue: &buildv1beta1.SingleValue{ + []buildapi.ParamValue{ + {Name: "a", SingleValue: &buildapi.SingleValue{ Value: pointer.String("2"), }}, - }, []buildv1beta1.ParamValue{ - {Name: "a", SingleValue: &buildv1beta1.SingleValue{ + }, []buildapi.ParamValue{ + {Name: "a", SingleValue: &buildapi.SingleValue{ Value: pointer.String("22"), }}, - {Name: "b", SingleValue: &buildv1beta1.SingleValue{ + {Name: "b", SingleValue: &buildapi.SingleValue{ Value: pointer.String("20"), }}, - {Name: "c", SingleValue: &buildv1beta1.SingleValue{ + {Name: "c", SingleValue: &buildapi.SingleValue{ Value: pointer.String("10"), }}, - {Name: "d", SingleValue: &buildv1beta1.SingleValue{ + {Name: "d", SingleValue: &buildapi.SingleValue{ Value: pointer.String("8"), }}, - {Name: "e", SingleValue: &buildv1beta1.SingleValue{ + {Name: "e", SingleValue: &buildapi.SingleValue{ Value: pointer.String("4"), }}, - }, ContainElements([]buildv1beta1.ParamValue{ - {Name: "a", SingleValue: &buildv1beta1.SingleValue{ + }, ContainElements([]buildapi.ParamValue{ + {Name: "a", SingleValue: &buildapi.SingleValue{ Value: pointer.String("22"), }}, - {Name: "b", SingleValue: &buildv1beta1.SingleValue{ + {Name: "b", SingleValue: &buildapi.SingleValue{ Value: pointer.String("20"), }}, - {Name: "c", SingleValue: &buildv1beta1.SingleValue{ + {Name: "c", SingleValue: &buildapi.SingleValue{ Value: pointer.String("10"), }}, - {Name: "d", SingleValue: &buildv1beta1.SingleValue{ + {Name: "d", SingleValue: &buildapi.SingleValue{ Value: pointer.String("8"), }}, - {Name: "e", SingleValue: &buildv1beta1.SingleValue{ + {Name: "e", SingleValue: &buildapi.SingleValue{ Value: pointer.String("4"), }}, })), @@ -211,7 +211,7 @@ var _ = Describe("FindParameterByName", func() { Context("For a list of three parameters", func() { - parameters := []buildv1beta1.Parameter{{ + parameters := []buildapi.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(&buildv1beta1.Parameter{ + Expect(parameter).To(BeEquivalentTo(&buildapi.Parameter{ Name: "another-parameter", Type: "array", })) @@ -241,19 +241,19 @@ var _ = Describe("FindParamValueByName", func() { Context("For a list of three parameter values", func() { - paramValues := []buildv1beta1.ParamValue{{ + paramValues := []buildapi.ParamValue{{ Name: "some-parameter", - SingleValue: &buildv1beta1.SingleValue{ + SingleValue: &buildapi.SingleValue{ Value: pointer.String("some-value"), }, }, { Name: "another-parameter", - Values: []buildv1beta1.SingleValue{ + Values: []buildapi.SingleValue{ { Value: pointer.String("item"), }, { - ConfigMapValue: &buildv1beta1.ObjectKeyRef{ + ConfigMapValue: &buildapi.ObjectKeyRef{ Name: "a-configmap", Key: "a-key", }, @@ -261,7 +261,7 @@ var _ = Describe("FindParamValueByName", func() { }, }, { Name: "last-parameter", - SingleValue: &buildv1beta1.SingleValue{ + SingleValue: &buildapi.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(&buildv1beta1.ParamValue{ + Expect(parameter).To(BeEquivalentTo(&buildapi.ParamValue{ Name: "another-parameter", - Values: []buildv1beta1.SingleValue{ + Values: []buildapi.SingleValue{ { Value: pointer.String("item"), }, { - ConfigMapValue: &buildv1beta1.ObjectKeyRef{ + ConfigMapValue: &buildapi.ObjectKeyRef{ Name: "a-configmap", Key: "a-key", }, @@ -374,15 +374,15 @@ var _ = Describe("HandleTaskRunParam", func() { Context("for a string parameter", func() { - parameterDefinition := &buildv1beta1.Parameter{ + parameterDefinition := &buildapi.Parameter{ Name: "string-parameter", - Type: buildv1beta1.ParameterTypeString, + Type: buildapi.ParameterTypeString, } It("adds a simple value", func() { - err := HandleTaskRunParam(taskRun, parameterDefinition, buildv1beta1.ParamValue{ + err := HandleTaskRunParam(taskRun, parameterDefinition, buildapi.ParamValue{ Name: "string-parameter", - SingleValue: &buildv1beta1.SingleValue{ + SingleValue: &buildapi.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, buildv1beta1.ParamValue{ + err := HandleTaskRunParam(taskRun, parameterDefinition, buildapi.ParamValue{ Name: "string-parameter", - SingleValue: &buildv1beta1.SingleValue{ - ConfigMapValue: &buildv1beta1.ObjectKeyRef{ + SingleValue: &buildapi.SingleValue{ + ConfigMapValue: &buildapi.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, buildv1beta1.ParamValue{ + err := HandleTaskRunParam(taskRun, parameterDefinition, buildapi.ParamValue{ Name: "string-parameter", - SingleValue: &buildv1beta1.SingleValue{ - ConfigMapValue: &buildv1beta1.ObjectKeyRef{ + SingleValue: &buildapi.SingleValue{ + ConfigMapValue: &buildapi.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, buildv1beta1.ParamValue{ + err := HandleTaskRunParam(taskRun, parameterDefinition, buildapi.ParamValue{ Name: "string-parameter", - SingleValue: &buildv1beta1.SingleValue{ - SecretValue: &buildv1beta1.ObjectKeyRef{ + SingleValue: &buildapi.SingleValue{ + SecretValue: &buildapi.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, buildv1beta1.ParamValue{ + err := HandleTaskRunParam(taskRun, parameterDefinition, buildapi.ParamValue{ Name: "string-parameter", - SingleValue: &buildv1beta1.SingleValue{ - SecretValue: &buildv1beta1.ObjectKeyRef{ + SingleValue: &buildapi.SingleValue{ + SecretValue: &buildapi.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 := &buildv1beta1.Parameter{ + parameterDefinition := &buildapi.Parameter{ Name: "array-parameter", - Type: buildv1beta1.ParameterTypeArray, + Type: buildapi.ParameterTypeArray, } It("adds simple values correctly", func() { - err := HandleTaskRunParam(taskRun, parameterDefinition, buildv1beta1.ParamValue{ + err := HandleTaskRunParam(taskRun, parameterDefinition, buildapi.ParamValue{ Name: "array-parameter", - Values: []buildv1beta1.SingleValue{ + Values: []buildapi.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, buildv1beta1.ParamValue{ + err := HandleTaskRunParam(taskRun, parameterDefinition, buildapi.ParamValue{ Name: "array-parameter", - Values: []buildv1beta1.SingleValue{ + Values: []buildapi.SingleValue{ { Value: pointer.String("first entry"), }, { - SecretValue: &buildv1beta1.ObjectKeyRef{ + SecretValue: &buildapi.ObjectKeyRef{ Name: "secret-name", Key: "secret-key", }, }, { - SecretValue: &buildv1beta1.ObjectKeyRef{ + SecretValue: &buildapi.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 f7d4aa1048..bae2b3642b 100644 --- a/pkg/reconciler/buildrun/resources/results.go +++ b/pkg/reconciler/buildrun/resources/results.go @@ -10,7 +10,7 @@ import ( "fmt" "strconv" - build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "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" @@ -27,7 +27,7 @@ const ( // to the buildrun func UpdateBuildRunUsingTaskResults( ctx context.Context, - buildRun *build.BuildRun, + buildRun *buildapi.BuildRun, taskRunResult []pipelineapi.TaskRunResult, request reconcile.Request, ) { @@ -38,9 +38,9 @@ func UpdateBuildRunUsingTaskResults( updateBuildRunStatusWithOutputResult(ctx, buildRun, taskRunResult, request) } -func updateBuildRunStatusWithOutputResult(ctx context.Context, buildRun *build.BuildRun, taskRunResult []pipelineapi.TaskRunResult, request reconcile.Request) { +func updateBuildRunStatusWithOutputResult(ctx context.Context, buildRun *buildapi.BuildRun, taskRunResult []pipelineapi.TaskRunResult, request reconcile.Request) { if buildRun.Status.Output == nil { - buildRun.Status.Output = &build.Output{} + buildRun.Status.Output = &buildapi.Output{} } for _, result := range taskRunResult { diff --git a/pkg/reconciler/buildrun/resources/results_test.go b/pkg/reconciler/buildrun/resources/results_test.go index 39fe17a664..514244c3d8 100644 --- a/pkg/reconciler/buildrun/resources/results_test.go +++ b/pkg/reconciler/buildrun/resources/results_test.go @@ -10,7 +10,7 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "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/v1beta1_samples" @@ -25,7 +25,7 @@ var _ = Describe("TaskRun results to BuildRun", func() { Context("when a BuildRun complete successfully", func() { var ( taskRunRequest reconcile.Request - br *build.BuildRun + br *buildapi.BuildRun tr *pipelineapi.TaskRun ) @@ -49,10 +49,10 @@ 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 = &build.BuildSpec{ - Source: &build.Source{ - Type: build.GitType, - Git: &build.Git{ + br.Status.BuildSpec = &buildapi.BuildSpec{ + Source: &buildapi.Source{ + Type: buildapi.GitType, + Git: &buildapi.Git{ URL: "https://github.com/shipwright-io/sample-go", }, }, @@ -82,10 +82,10 @@ var _ = Describe("TaskRun results to BuildRun", func() { It("should surface the TaskRun results emitting from default(bundle) source step", func() { bundleImageDigest := "sha256:fe1b73cd25ac3f11dec752755e2" - br.Status.BuildSpec = &build.BuildSpec{ - Source: &build.Source{ - Type: build.OCIArtifactType, - OCIArtifact: &build.OCIArtifact{ + br.Status.BuildSpec = &buildapi.BuildSpec{ + Source: &buildapi.Source{ + Type: buildapi.OCIArtifactType, + OCIArtifact: &buildapi.OCIArtifact{ Image: "ghcr.io/shipwright-io/sample-go/source-bundle:latest", }, }, @@ -142,10 +142,10 @@ 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 = &build.BuildSpec{ - Source: &build.Source{ - Type: build.GitType, - Git: &build.Git{ + br.Status.BuildSpec = &buildapi.BuildSpec{ + Source: &buildapi.Source{ + Type: buildapi.GitType, + Git: &buildapi.Git{ URL: "https://github.com/shipwright-io/sample-go", }, }, diff --git a/pkg/reconciler/buildrun/resources/service_accounts.go b/pkg/reconciler/buildrun/resources/service_accounts.go index d49f308258..21d82ba95a 100644 --- a/pkg/reconciler/buildrun/resources/service_accounts.go +++ b/pkg/reconciler/buildrun/resources/service_accounts.go @@ -8,7 +8,7 @@ import ( "context" "fmt" - buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "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 *buildv1beta1.BuildRun) string { +func GetGeneratedServiceAccountName(buildRun *buildapi.BuildRun) string { return buildRun.Name } // IsGeneratedServiceAccountUsed checks if a build run uses a generated service account -func IsGeneratedServiceAccountUsed(buildRun *buildv1beta1.BuildRun) bool { +func IsGeneratedServiceAccountUsed(buildRun *buildapi.BuildRun) bool { return buildRun.Spec.ServiceAccount != nil && *buildRun.Spec.ServiceAccount == ".generate" } // GenerateSA generates a new service account on the fly -func GenerateSA(ctx context.Context, client client.Client, build *buildv1beta1.Build, buildRun *buildv1beta1.BuildRun) (serviceAccount *corev1.ServiceAccount, err error) { +func GenerateSA(ctx context.Context, client client.Client, build *buildapi.Build, buildRun *buildapi.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 *buildv1beta1.B ObjectMeta: metav1.ObjectMeta{ Name: GetGeneratedServiceAccountName(buildRun), Namespace: buildRun.Namespace, - Labels: map[string]string{buildv1beta1.LabelBuildRun: buildRun.Name}, + Labels: map[string]string{buildapi.LabelBuildRun: buildRun.Name}, OwnerReferences: []metav1.OwnerReference{ - *metav1.NewControllerRef(buildRun, buildv1beta1.SchemeGroupVersion.WithKind("BuildRun")), + *metav1.NewControllerRef(buildRun, buildapi.SchemeGroupVersion.WithKind("BuildRun")), }, }, AutomountServiceAccountToken: pointer.Bool(false), @@ -87,7 +87,7 @@ func GenerateSA(ctx context.Context, client client.Client, build *buildv1beta1.B // DeleteServiceAccount deletes the service account of a completed BuildRun if the service account // was generated -func DeleteServiceAccount(ctx context.Context, client client.Client, completedBuildRun *buildv1beta1.BuildRun) error { +func DeleteServiceAccount(ctx context.Context, client client.Client, completedBuildRun *buildapi.BuildRun) error { if !IsGeneratedServiceAccountUsed(completedBuildRun) { return nil } @@ -105,7 +105,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 *buildv1beta1.BuildRun) (*corev1.ServiceAccount, error) { +func getDefaultNamespaceSA(ctx context.Context, client client.Client, buildRun *buildapi.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{} @@ -126,7 +126,7 @@ 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 *buildv1beta1.Build, buildRun *buildv1beta1.BuildRun) (serviceAccount *corev1.ServiceAccount, err error) { +func RetrieveServiceAccount(ctx context.Context, client client.Client, build *buildapi.Build, buildRun *buildapi.BuildRun) (serviceAccount *corev1.ServiceAccount, err error) { // generate or retrieve an existing autogenerated sa if IsGeneratedServiceAccountUsed(buildRun) { return GenerateSA(ctx, client, build, buildRun) diff --git a/pkg/reconciler/buildrun/resources/service_accounts_test.go b/pkg/reconciler/buildrun/resources/service_accounts_test.go index eb271f9e3c..312ffd4f7d 100644 --- a/pkg/reconciler/buildrun/resources/service_accounts_test.go +++ b/pkg/reconciler/buildrun/resources/service_accounts_test.go @@ -10,7 +10,7 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "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/v1beta1_samples" @@ -26,7 +26,7 @@ var _ = Describe("Operating service accounts", func() { client *fakes.FakeClient ctl test.Catalog buildName, buildRunName string - buildRunSample *buildv1beta1.BuildRun + buildRunSample *buildapi.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 *buildv1beta1.BuildRun: + case *buildapi.BuildRun: return fmt.Errorf("failed") } return nil @@ -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[buildv1beta1.LabelBuildRun]).To(Equal(buildRunName)) + Expect(object.Labels[buildapi.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 460a15c643..f3e60f8e67 100644 --- a/pkg/reconciler/buildrun/resources/sources.go +++ b/pkg/reconciler/buildrun/resources/sources.go @@ -11,7 +11,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "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" @@ -25,14 +25,14 @@ const sourceTimestampName = "source-timestamp" // 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 *buildv1beta1.Build, - buildRun *buildv1beta1.BuildRun, -) *buildv1beta1.Local { - if buildRun.Spec.Source != nil && buildRun.Spec.Source.Type == buildv1beta1.LocalType { + build *buildapi.Build, + buildRun *buildapi.BuildRun, +) *buildapi.Local { + if buildRun.Spec.Source != nil && buildRun.Spec.Source.Type == buildapi.LocalType { return buildRun.Spec.Source.Local } - if build.Spec.Source != nil && build.Spec.Source.Type == buildv1beta1.LocalType { + if build.Spec.Source != nil && build.Spec.Source.Type == buildapi.LocalType { return build.Spec.Source.Local } @@ -53,8 +53,8 @@ func appendSourceTimestampResult(taskSpec *pipelineapi.TaskSpec) { func AmendTaskSpecWithSources( cfg *config.Config, taskSpec *pipelineapi.TaskSpec, - build *buildv1beta1.Build, - buildRun *buildv1beta1.BuildRun, + build *buildapi.Build, + buildRun *buildapi.BuildRun, ) { if localCopy := isLocalCopyBuildSource(build, buildRun); localCopy != nil { sources.AppendLocalCopyStep(cfg, taskSpec, localCopy.Timeout) @@ -62,12 +62,12 @@ func AmendTaskSpecWithSources( // create the step for spec.source, either Git or Bundle switch build.Spec.Source.Type { - case buildv1beta1.OCIArtifactType: + case buildapi.OCIArtifactType: if build.Spec.Source.OCIArtifact != nil { appendSourceTimestampResult(taskSpec) sources.AppendBundleStep(cfg, taskSpec, build.Spec.Source.OCIArtifact, defaultSourceName) } - case buildv1beta1.GitType: + case buildapi.GitType: if build.Spec.Source.Git != nil { appendSourceTimestampResult(taskSpec) sources.AppendGitStep(cfg, taskSpec, *build.Spec.Source.Git, defaultSourceName) @@ -76,7 +76,7 @@ func AmendTaskSpecWithSources( } } -func updateBuildRunStatusWithSourceResult(buildrun *buildv1beta1.BuildRun, results []pipelineapi.TaskRunResult) { +func updateBuildRunStatusWithSourceResult(buildrun *buildapi.BuildRun, results []pipelineapi.TaskRunResult) { buildSpec := buildrun.Status.BuildSpec if buildSpec.Source == nil { @@ -84,10 +84,10 @@ func updateBuildRunStatusWithSourceResult(buildrun *buildv1beta1.BuildRun, resul } switch { - case buildSpec.Source.Type == buildv1beta1.OCIArtifactType && buildSpec.Source.OCIArtifact != nil: + case buildSpec.Source.Type == buildapi.OCIArtifactType && buildSpec.Source.OCIArtifact != nil: sources.AppendBundleResult(buildrun, defaultSourceName, results) - case buildSpec.Source.Type == buildv1beta1.GitType && buildSpec.Source.Git != nil: + case buildSpec.Source.Type == buildapi.GitType && buildSpec.Source.Git != nil: sources.AppendGitResult(buildrun, defaultSourceName, results) } diff --git a/pkg/reconciler/buildrun/resources/sources/bundle.go b/pkg/reconciler/buildrun/resources/sources/bundle.go index ec39f1ab69..eaff052e39 100644 --- a/pkg/reconciler/buildrun/resources/sources/bundle.go +++ b/pkg/reconciler/buildrun/resources/sources/bundle.go @@ -8,7 +8,7 @@ import ( "fmt" "strings" - build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/config" corev1 "k8s.io/api/core/v1" @@ -16,7 +16,7 @@ import ( ) // AppendBundleStep appends the bundle step to the TaskSpec -func AppendBundleStep(cfg *config.Config, taskSpec *pipelineapi.TaskSpec, oci *build.OCIArtifact, name string) { +func AppendBundleStep(cfg *config.Config, taskSpec *pipelineapi.TaskSpec, oci *buildapi.OCIArtifact, name string) { // append the result taskSpec.Results = append(taskSpec.Results, pipelineapi.TaskResult{ @@ -63,7 +63,7 @@ func AppendBundleStep(cfg *config.Config, taskSpec *pipelineapi.TaskSpec, oci *b } // add prune flag in when prune after pull is configured - if oci.Prune != nil && *oci.Prune == build.PruneAfterPull { + if oci.Prune != nil && *oci.Prune == buildapi.PruneAfterPull { bundleStep.Args = append(bundleStep.Args, "--prune") } @@ -71,14 +71,14 @@ func AppendBundleStep(cfg *config.Config, taskSpec *pipelineapi.TaskSpec, oci *b } // AppendBundleResult append bundle source result to build run -func AppendBundleResult(buildRun *build.BuildRun, name string, results []pipelineapi.TaskRunResult) { +func AppendBundleResult(buildRun *buildapi.BuildRun, name string, results []pipelineapi.TaskRunResult) { imageDigest := FindResultValue(results, name, "image-digest") if strings.TrimSpace(imageDigest) != "" { if buildRun.Status.Source == nil { - buildRun.Status.Source = &build.SourceResult{} + buildRun.Status.Source = &buildapi.SourceResult{} } - buildRun.Status.Source.OciArtifact = &build.OciArtifactSourceResult{ + buildRun.Status.Source.OciArtifact = &buildapi.OciArtifactSourceResult{ Digest: imageDigest, } } diff --git a/pkg/reconciler/buildrun/resources/sources/git.go b/pkg/reconciler/buildrun/resources/sources/git.go index 67c91b7ccc..74340be058 100644 --- a/pkg/reconciler/buildrun/resources/sources/git.go +++ b/pkg/reconciler/buildrun/resources/sources/git.go @@ -10,9 +10,7 @@ import ( corev1 "k8s.io/api/core/v1" - "github.com/shipwright-io/build/pkg/apis/build/v1beta1" - build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" - buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "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" @@ -28,7 +26,7 @@ const ( func AppendGitStep( cfg *config.Config, taskSpec *pipelineapi.TaskSpec, - source buildv1beta1.Git, + source buildapi.Git, name string, ) { // append the result @@ -110,16 +108,16 @@ func AppendGitStep( } // AppendGitResult append git source result to build run -func AppendGitResult(buildRun *buildv1beta1.BuildRun, name string, results []pipelineapi.TaskRunResult) { +func AppendGitResult(buildRun *buildapi.BuildRun, name string, results []pipelineapi.TaskRunResult) { commitAuthor := FindResultValue(results, name, commitAuthorResult) commitSha := FindResultValue(results, name, commitSHAResult) branchName := FindResultValue(results, name, branchName) if strings.TrimSpace(commitAuthor) != "" || strings.TrimSpace(commitSha) != "" || strings.TrimSpace(branchName) != "" { if buildRun.Status.Source == nil { - buildRun.Status.Source = &build.SourceResult{} + buildRun.Status.Source = &buildapi.SourceResult{} } - buildRun.Status.Source.Git = &v1beta1.GitSourceResult{ + buildRun.Status.Source.Git = &buildapi.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 361b01c3bb..6ad1d1b32c 100644 --- a/pkg/reconciler/buildrun/resources/sources/git_test.go +++ b/pkg/reconciler/buildrun/resources/sources/git_test.go @@ -8,7 +8,7 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "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" @@ -29,7 +29,7 @@ var _ = Describe("Git", func() { }) JustBeforeEach(func() { - sources.AppendGitStep(cfg, taskSpec, buildv1beta1.Git{ + sources.AppendGitStep(cfg, taskSpec, buildapi.Git{ URL: "https://github.com/shipwright-io/build", }, "default") }) @@ -67,7 +67,7 @@ var _ = Describe("Git", func() { }) JustBeforeEach(func() { - sources.AppendGitStep(cfg, taskSpec, buildv1beta1.Git{ + sources.AppendGitStep(cfg, taskSpec, buildapi.Git{ URL: "git@github.com:shipwright-io/build.git", CloneSecret: pointer.String("a.secret"), }, "default") diff --git a/pkg/reconciler/buildrun/resources/strategies.go b/pkg/reconciler/buildrun/resources/strategies.go index 8d1ae1fbdc..df04c5ba41 100644 --- a/pkg/reconciler/buildrun/resources/strategies.go +++ b/pkg/reconciler/buildrun/resources/strategies.go @@ -7,7 +7,7 @@ package resources import ( "context" - buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "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 *buildv1beta1.Build) (*buildv1beta1.BuildStrategy, error) { - buildStrategyInstance := &buildv1beta1.BuildStrategy{} +func RetrieveBuildStrategy(ctx context.Context, client client.Client, build *buildapi.Build) (*buildapi.BuildStrategy, error) { + buildStrategyInstance := &buildapi.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 *buildv1beta1.Build) (*buildv1beta1.ClusterBuildStrategy, error) { - clusterBuildStrategyInstance := &buildv1beta1.ClusterBuildStrategy{} +func RetrieveClusterBuildStrategy(ctx context.Context, client client.Client, build *buildapi.Build) (*buildapi.ClusterBuildStrategy, error) { + clusterBuildStrategyInstance := &buildapi.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 14d64132bc..3c5fd0cc03 100644 --- a/pkg/reconciler/buildrun/resources/strategies_test.go +++ b/pkg/reconciler/buildrun/resources/strategies_test.go @@ -9,7 +9,7 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "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/v1beta1_samples" @@ -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 *buildv1beta1.ClusterBuildStrategy: + case *buildapi.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 *buildv1beta1.BuildStrategy: + case *buildapi.BuildStrategy: ctl.DefaultNamespacedBuildStrategy().DeepCopyInto(object) return nil } diff --git a/pkg/reconciler/buildrun/resources/taskrun.go b/pkg/reconciler/buildrun/resources/taskrun.go index 10ee59d719..3e5957ebd1 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" - buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "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" @@ -35,11 +35,11 @@ const ( // GenerateTaskSpec creates Tekton TaskRun spec to be used for a build run func GenerateTaskSpec( cfg *config.Config, - build *buildv1beta1.Build, - buildRun *buildv1beta1.BuildRun, - buildSteps []buildv1beta1.Step, - parameterDefinitions []buildv1beta1.Parameter, - buildStrategyVolumes []buildv1beta1.BuildStrategyVolume, + build *buildapi.Build, + buildRun *buildapi.BuildRun, + buildSteps []buildapi.Step, + parameterDefinitions []buildapi.Parameter, + buildStrategyVolumes []buildapi.BuildStrategyVolume, ) (*pipelineapi.TaskSpec, error) { generatedTaskSpec := pipelineapi.TaskSpec{ Params: []pipelineapi.ParamSpec{ @@ -88,7 +88,7 @@ func GenerateTaskSpec( switch parameterDefinition.Type { case "": // string is default fallthrough - case buildv1beta1.ParameterTypeString: + case buildapi.ParameterTypeString: param.Type = pipelineapi.ParamTypeString if parameterDefinition.Default != nil { param.Default = &pipelineapi.ParamValue{ @@ -97,7 +97,7 @@ func GenerateTaskSpec( } } - case buildv1beta1.ParameterTypeArray: + case buildapi.ParameterTypeArray: param.Type = pipelineapi.ParamTypeArray if parameterDefinition.Defaults != nil { param.Default = &pipelineapi.ParamValue{ @@ -170,10 +170,10 @@ func GenerateTaskSpec( // GenerateTaskRun creates a Tekton TaskRun to be used for a build run func GenerateTaskRun( cfg *config.Config, - build *buildv1beta1.Build, - buildRun *buildv1beta1.BuildRun, + build *buildapi.Build, + buildRun *buildapi.BuildRun, serviceAccountName string, - strategy buildv1beta1.BuilderStrategy, + strategy buildapi.BuilderStrategy, ) (*pipelineapi.TaskRun, error) { // retrieve expected imageURL form build or buildRun @@ -205,14 +205,14 @@ func GenerateTaskRun( // Add BuildRun name reference to the TaskRun labels taskRunLabels := map[string]string{ - buildv1beta1.LabelBuildRun: buildRun.Name, - buildv1beta1.LabelBuildRunGeneration: strconv.FormatInt(buildRun.Generation, 10), + buildapi.LabelBuildRun: buildRun.Name, + buildapi.LabelBuildRunGeneration: strconv.FormatInt(buildRun.Generation, 10), } // Add Build name reference unless it is an embedded Build (empty build name) if build.Name != "" { - taskRunLabels[buildv1beta1.LabelBuild] = build.Name - taskRunLabels[buildv1beta1.LabelBuildGeneration] = strconv.FormatInt(build.Generation, 10) + taskRunLabels[buildapi.LabelBuild] = build.Name + taskRunLabels[buildapi.LabelBuildGeneration] = strconv.FormatInt(build.Generation, 10) } expectedTaskRun := &pipelineapi.TaskRun{ @@ -322,7 +322,7 @@ 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 = &buildv1beta1.Image{} + buildRunOutput = &buildapi.Image{} } // Make sure that image-processing is setup in case it is needed, which can fail with an error @@ -334,7 +334,7 @@ func GenerateTaskRun( return expectedTaskRun, nil } -func effectiveTimeout(build *buildv1beta1.Build, buildRun *buildv1beta1.BuildRun) *metav1.Duration { +func effectiveTimeout(build *buildapi.Build, buildRun *buildapi.BuildRun) *metav1.Duration { if buildRun.Spec.Timeout != nil { return buildRun.Spec.Timeout @@ -349,13 +349,13 @@ func effectiveTimeout(build *buildv1beta1.Build, buildRun *buildv1beta1.BuildRun // 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, buildv1beta1.ClusterBuildStrategyDomain+"/") && - !strings.HasPrefix(key, buildv1beta1.BuildStrategyDomain+"/") && - !strings.HasPrefix(key, buildv1beta1.BuildDomain+"/") && - !strings.HasPrefix(key, buildv1beta1.BuildRunDomain+"/") + !strings.HasPrefix(key, buildapi.ClusterBuildStrategyDomain+"/") && + !strings.HasPrefix(key, buildapi.BuildStrategyDomain+"/") && + !strings.HasPrefix(key, buildapi.BuildDomain+"/") && + !strings.HasPrefix(key, buildapi.BuildRunDomain+"/") } -func toVolumeMap(strategyVolumes []buildv1beta1.BuildStrategyVolume) map[string]bool { +func toVolumeMap(strategyVolumes []buildapi.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 237c6802fa..bac1f8b55e 100644 --- a/pkg/reconciler/buildrun/resources/taskrun_test.go +++ b/pkg/reconciler/buildrun/resources/taskrun_test.go @@ -18,7 +18,7 @@ import ( "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "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" @@ -28,13 +28,13 @@ import ( var _ = Describe("GenerateTaskrun", func() { var ( - build *buildv1beta1.Build - buildWithEnvs *buildv1beta1.Build - buildRun *buildv1beta1.BuildRun - buildRunWithEnvs *buildv1beta1.BuildRun - buildStrategy *buildv1beta1.BuildStrategy + build *buildapi.Build + buildWithEnvs *buildapi.Build + buildRun *buildapi.BuildRun + buildRunWithEnvs *buildapi.BuildRun + buildStrategy *buildapi.BuildStrategy buildStrategyStepNames map[string]struct{} - buildStrategyWithEnvs *buildv1beta1.BuildStrategy + buildStrategyWithEnvs *buildapi.BuildStrategy buildpacks string ctl test.Catalog ) @@ -245,7 +245,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.Steps, []buildv1beta1.Parameter{}, buildStrategy.GetVolumes()) + got, err = resources.GenerateTaskSpec(config.NewDefaultConfig(), buildWithEnvs, buildRun, buildStrategy.Spec.Steps, []buildapi.Parameter{}, buildStrategy.GetVolumes()) Expect(err).To(BeNil()) combinedEnvs, err := env.MergeEnvVars(buildRun.Spec.Env, buildWithEnvs.Spec.Env, true) @@ -262,7 +262,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.Steps, []buildv1beta1.Parameter{}, buildStrategy.GetVolumes()) + got, err = resources.GenerateTaskSpec(config.NewDefaultConfig(), build, buildRunWithEnvs, buildStrategy.Spec.Steps, []buildapi.Parameter{}, buildStrategy.GetVolumes()) Expect(err).To(BeNil()) combinedEnvs, err := env.MergeEnvVars(buildRunWithEnvs.Spec.Env, build.Spec.Env, true) @@ -279,7 +279,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.Steps, []buildv1beta1.Parameter{}, buildStrategy.GetVolumes()) + got, err = resources.GenerateTaskSpec(config.NewDefaultConfig(), buildWithEnvs, buildRunWithEnvs, buildStrategy.Spec.Steps, []buildapi.Parameter{}, buildStrategy.GetVolumes()) Expect(err).To(BeNil()) combinedEnvs, err := env.MergeEnvVars(buildRunWithEnvs.Spec.Env, buildWithEnvs.Spec.Env, true) @@ -297,7 +297,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.Steps, []buildv1beta1.Parameter{}, buildStrategy.GetVolumes()) + got, err = resources.GenerateTaskSpec(config.NewDefaultConfig(), buildWithEnvs, buildRunWithEnvs, buildStrategyWithEnvs.Spec.Steps, []buildapi.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]")) }) @@ -320,7 +320,7 @@ var _ = Describe("GenerateTaskrun", func() { } JustBeforeEach(func() { - got, err = resources.GenerateTaskSpec(config.NewDefaultConfig(), build, buildRun, buildStrategy.Spec.Steps, []buildv1beta1.Parameter{}, buildStrategy.GetVolumes()) + got, err = resources.GenerateTaskSpec(config.NewDefaultConfig(), build, buildRun, buildStrategy.Spec.Steps, []buildapi.Parameter{}, buildStrategy.GetVolumes()) Expect(err).To(BeNil()) }) @@ -361,7 +361,7 @@ var _ = Describe("GenerateTaskrun", func() { } JustBeforeEach(func() { - got, err = resources.GenerateTaskSpec(config.NewDefaultConfig(), build, buildRun, buildStrategy.Spec.Steps, []buildv1beta1.Parameter{}, buildStrategy.GetVolumes()) + got, err = resources.GenerateTaskSpec(config.NewDefaultConfig(), build, buildRun, buildStrategy.Spec.Steps, []buildapi.Parameter{}, buildStrategy.GetVolumes()) Expect(err).To(BeNil()) }) @@ -465,10 +465,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[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")) + Expect(got.Labels[buildapi.LabelBuild]).To(Equal(build.Name)) + Expect(got.Labels[buildapi.LabelBuildRun]).To(Equal(buildRun.Name)) + Expect(got.Labels[buildapi.LabelBuildStrategyName]).To(Equal(build.Spec.Strategy.Name)) + Expect(got.Labels[buildapi.LabelBuildStrategyGeneration]).To(Equal("0")) }) It("should filter out certain annotations when propagating them to the TaskRun", func() { @@ -517,8 +517,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[buildv1beta1.LabelBuild]).To(Equal(build.Name)) - Expect(got.Labels[buildv1beta1.LabelBuildRun]).To(Equal(buildRun.Name)) + Expect(got.Labels[buildapi.LabelBuild]).To(Equal(build.Name)) + Expect(got.Labels[buildapi.LabelBuildRun]).To(Equal(buildRun.Name)) }) It("should ensure generated TaskRun's spec special input params are correct", func() { diff --git a/pkg/reconciler/buildrunttlcleanup/buildrun_ttl_cleanup.go b/pkg/reconciler/buildrunttlcleanup/buildrun_ttl_cleanup.go index abe645b8a6..3a43d82c2e 100644 --- a/pkg/reconciler/buildrunttlcleanup/buildrun_ttl_cleanup.go +++ b/pkg/reconciler/buildrunttlcleanup/buildrun_ttl_cleanup.go @@ -8,7 +8,7 @@ import ( "context" "time" - buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/config" "github.com/shipwright-io/build/pkg/ctxlog" corev1 "k8s.io/api/core/v1" @@ -44,7 +44,7 @@ func (r *ReconcileBuildRun) Reconcile(ctx context.Context, request reconcile.Req ctxlog.Debug(ctx, "Start reconciling Buildrun-ttl", namespace, request.Namespace, name, request.Name) - br := &buildv1beta1.BuildRun{} + br := &buildapi.BuildRun{} err := r.client.Get(ctx, types.NamespacedName{Name: request.Name, Namespace: request.Namespace}, br) if err != nil { if apierrors.IsNotFound(err) { @@ -54,7 +54,7 @@ func (r *ReconcileBuildRun) Reconcile(ctx context.Context, request reconcile.Req return reconcile.Result{}, err } - condition := br.Status.GetCondition(buildv1beta1.Succeeded) + condition := br.Status.GetCondition(buildapi.Succeeded) if condition == nil || condition.Status == corev1.ConditionUnknown { return reconcile.Result{}, nil } diff --git a/pkg/reconciler/buildrunttlcleanup/controller.go b/pkg/reconciler/buildrunttlcleanup/controller.go index d21f0857e9..1e712311e7 100644 --- a/pkg/reconciler/buildrunttlcleanup/controller.go +++ b/pkg/reconciler/buildrunttlcleanup/controller.go @@ -7,7 +7,7 @@ package buildrunttlcleanup import ( "context" - buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/config" corev1 "k8s.io/api/core/v1" "sigs.k8s.io/controller-runtime/pkg/controller" @@ -31,7 +31,7 @@ func Add(_ context.Context, c *config.Config, mgr manager.Manager) error { } // reconcileCompletedBuildRun returns true if the object has the required TTL parameters -func reconcileCompletedBuildRun(condition *buildv1beta1.Condition, o *buildv1beta1.BuildRun) bool { +func reconcileCompletedBuildRun(condition *buildapi.Condition, o *buildapi.BuildRun) bool { if condition.Status == corev1.ConditionTrue { // check if a successful BuildRun has a TTL after succeeded value set if o.Spec.Retention != nil && o.Spec.Retention.TTLAfterSucceeded != nil { @@ -56,7 +56,7 @@ func reconcileCompletedBuildRun(condition *buildv1beta1.Condition, o *buildv1bet // reconcileAlreadyCompletedBuildRun returns true only if the TTL limit was introduced // or if it was lowered as the object was completed before the update -func reconcileAlreadyCompletedBuildRun(newCondition *buildv1beta1.Condition, n *buildv1beta1.BuildRun, o *buildv1beta1.BuildRun) bool { +func reconcileAlreadyCompletedBuildRun(newCondition *buildapi.Condition, n *buildapi.BuildRun, o *buildapi.BuildRun) bool { if newCondition.Status == corev1.ConditionTrue { // check if a successful BuildRun has a TTL that was lowered or introduced if (o.Spec.Retention == nil || o.Spec.Retention.TTLAfterSucceeded == nil) && n.Spec.Retention != nil && n.Spec.Retention.TTLAfterSucceeded != nil { @@ -98,10 +98,10 @@ func add(mgr manager.Manager, r reconcile.Reconciler, maxConcurrentReconciles in predBuildRun := predicate.Funcs{ CreateFunc: func(e event.CreateEvent) bool { // Reconcile if TTL values are set - o := e.Object.(*buildv1beta1.BuildRun) + o := e.Object.(*buildapi.BuildRun) // ignore a running BuildRun - condition := o.Status.GetCondition(buildv1beta1.Succeeded) + condition := o.Status.GetCondition(buildapi.Succeeded) if condition == nil || condition.Status == corev1.ConditionUnknown { return false } @@ -110,14 +110,14 @@ func add(mgr manager.Manager, r reconcile.Reconciler, maxConcurrentReconciles in }, UpdateFunc: func(e event.UpdateEvent) bool { // check if the updated object is completed - n := e.ObjectNew.(*buildv1beta1.BuildRun) - newCondition := n.Status.GetCondition(buildv1beta1.Succeeded) + n := e.ObjectNew.(*buildapi.BuildRun) + newCondition := n.Status.GetCondition(buildapi.Succeeded) if newCondition == nil || newCondition.Status == corev1.ConditionUnknown { return false } - o := e.ObjectOld.(*buildv1beta1.BuildRun) - oldCondition := o.Status.GetCondition(buildv1beta1.Succeeded) + o := e.ObjectOld.(*buildapi.BuildRun) + oldCondition := o.Status.GetCondition(buildapi.Succeeded) // for objects that failed or just completed, check if a matching TTL is set if oldCondition == nil || oldCondition.Status == corev1.ConditionUnknown { @@ -137,5 +137,5 @@ func add(mgr manager.Manager, r reconcile.Reconciler, maxConcurrentReconciles in }, } // Watch for changes to primary resource BuildRun - return c.Watch(source.Kind(mgr.GetCache(), &buildv1beta1.BuildRun{}), &handler.EnqueueRequestForObject{}, predBuildRun) + return c.Watch(source.Kind(mgr.GetCache(), &buildapi.BuildRun{}), &handler.EnqueueRequestForObject{}, predBuildRun) } diff --git a/pkg/reconciler/buildstrategy/controller.go b/pkg/reconciler/buildstrategy/controller.go index fc7d31363c..9251b3dd65 100644 --- a/pkg/reconciler/buildstrategy/controller.go +++ b/pkg/reconciler/buildstrategy/controller.go @@ -13,7 +13,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" "sigs.k8s.io/controller-runtime/pkg/source" - buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/config" ) @@ -40,5 +40,5 @@ func add(mgr manager.Manager, r reconcile.Reconciler, maxConcurrentReconciles in } // Watch for changes to primary resource BuildStrategy - return c.Watch(source.Kind(mgr.GetCache(), &buildv1beta1.BuildStrategy{}), &handler.EnqueueRequestForObject{}) + return c.Watch(source.Kind(mgr.GetCache(), &buildapi.BuildStrategy{}), &handler.EnqueueRequestForObject{}) } diff --git a/pkg/reconciler/clusterbuildstrategy/controller.go b/pkg/reconciler/clusterbuildstrategy/controller.go index 789bd26778..06ad2d662b 100644 --- a/pkg/reconciler/clusterbuildstrategy/controller.go +++ b/pkg/reconciler/clusterbuildstrategy/controller.go @@ -7,14 +7,13 @@ package clusterbuildstrategy import ( "context" + buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + "github.com/shipwright-io/build/pkg/config" "sigs.k8s.io/controller-runtime/pkg/controller" "sigs.k8s.io/controller-runtime/pkg/handler" "sigs.k8s.io/controller-runtime/pkg/manager" "sigs.k8s.io/controller-runtime/pkg/reconcile" "sigs.k8s.io/controller-runtime/pkg/source" - - buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" - "github.com/shipwright-io/build/pkg/config" ) // Add creates a new ClusterBuildStrategy Controller and adds it to the Manager. The Manager will set fields on the Controller @@ -40,5 +39,5 @@ func add(mgr manager.Manager, r reconcile.Reconciler, maxConcurrentReconciles in } // Watch for changes to primary resource ClusterBuildStrategy - return c.Watch(source.Kind(mgr.GetCache(), &buildv1beta1.ClusterBuildStrategy{}), &handler.EnqueueRequestForObject{}) + return c.Watch(source.Kind(mgr.GetCache(), &buildapi.ClusterBuildStrategy{}), &handler.EnqueueRequestForObject{}) } diff --git a/pkg/validate/buildname.go b/pkg/validate/buildname.go index 8f810d2dcf..1c4781d16b 100644 --- a/pkg/validate/buildname.go +++ b/pkg/validate/buildname.go @@ -11,16 +11,16 @@ import ( "k8s.io/apimachinery/pkg/util/validation" "k8s.io/utils/pointer" - build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1" ) // BuildNameRef contains all required fields // to validate a build name type BuildNameRef struct { - Build *build.Build // build instance for analysis + Build *buildapi.Build // build instance for analysis } -func NewBuildName(build *build.Build) *BuildNameRef { +func NewBuildName(build *buildapi.Build) *BuildNameRef { return &BuildNameRef{build} } @@ -28,7 +28,7 @@ func NewBuildName(build *build.Build) *BuildNameRef { // that build name is a valid label value func (b *BuildNameRef) ValidatePath(_ context.Context) error { if errs := validation.IsValidLabelValue(b.Build.Name); len(errs) > 0 { - b.Build.Status.Reason = build.BuildReasonPtr(build.BuildNameInvalid) + b.Build.Status.Reason = buildapi.BuildReasonPtr(buildapi.BuildNameInvalid) b.Build.Status.Message = pointer.String(strings.Join(errs, ", ")) } diff --git a/pkg/validate/envvars.go b/pkg/validate/envvars.go index aacea4a8a9..44615b1a8d 100644 --- a/pkg/validate/envvars.go +++ b/pkg/validate/envvars.go @@ -12,12 +12,12 @@ import ( kerrors "k8s.io/apimachinery/pkg/util/errors" "k8s.io/utils/pointer" - build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1" ) // Env implements the Env interface to add validations for the `build.spec.env` slice. type Env struct { - Build *build.Build + Build *buildapi.Build } // ValidatePath executes the validation routine, inspecting the `build.spec.env` path, which @@ -46,13 +46,13 @@ func (e *Env) validate(envVar corev1.EnvVar) []error { var allErrs []error if envVar.Name == "" { - e.Build.Status.Reason = build.BuildReasonPtr(build.SpecEnvNameCanNotBeBlank) + e.Build.Status.Reason = buildapi.BuildReasonPtr(buildapi.SpecEnvNameCanNotBeBlank) e.Build.Status.Message = pointer.String("name for environment variable must not be blank") allErrs = append(allErrs, fmt.Errorf("%s", *e.Build.Status.Message)) } if envVar.Value != "" && envVar.ValueFrom != nil { - e.Build.Status.Reason = build.BuildReasonPtr(build.SpecEnvOnlyOneOfValueOrValueFromMustBeSpecified) + e.Build.Status.Reason = buildapi.BuildReasonPtr(buildapi.SpecEnvOnlyOneOfValueOrValueFromMustBeSpecified) e.Build.Status.Message = pointer.String("only one of value or valueFrom must be specified") allErrs = append(allErrs, fmt.Errorf("%s", *e.Build.Status.Message)) } @@ -61,6 +61,6 @@ func (e *Env) validate(envVar corev1.EnvVar) []error { } // NewEnv instantiates a new Env passing the build object pointer along. -func NewEnv(b *build.Build) *Env { +func NewEnv(b *buildapi.Build) *Env { return &Env{Build: b} } diff --git a/pkg/validate/envvars_test.go b/pkg/validate/envvars_test.go index 9dc921ff99..deedbc6a00 100644 --- a/pkg/validate/envvars_test.go +++ b/pkg/validate/envvars_test.go @@ -13,15 +13,15 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/utils/pointer" - build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/validate" ) var _ = Describe("Env", func() { Context("ValidatePath", func() { It("should fail in case of empty env var name", func() { - b := &build.Build{ - Spec: build.BuildSpec{ + b := &buildapi.Build{ + Spec: buildapi.BuildSpec{ Env: []corev1.EnvVar{ { Name: "", @@ -33,13 +33,13 @@ var _ = Describe("Env", func() { err := validate.NewEnv(b).ValidatePath(context.TODO()) Expect(err).To(HaveOccurred()) - Expect(b.Status.Reason).To(Equal(build.BuildReasonPtr(build.SpecEnvNameCanNotBeBlank))) + Expect(b.Status.Reason).To(Equal(buildapi.BuildReasonPtr(buildapi.SpecEnvNameCanNotBeBlank))) Expect(b.Status.Message).To(Equal(pointer.String("name for environment variable must not be blank"))) }) It("should fail in case of specifying both value and valueFrom", func() { - b := &build.Build{ - Spec: build.BuildSpec{ + b := &buildapi.Build{ + Spec: buildapi.BuildSpec{ Env: []corev1.EnvVar{ { Name: "some-name", @@ -56,13 +56,13 @@ var _ = Describe("Env", func() { err := validate.NewEnv(b).ValidatePath(context.TODO()) Expect(err).To(HaveOccurred()) - Expect(b.Status.Reason).To(Equal(build.BuildReasonPtr(build.SpecEnvOnlyOneOfValueOrValueFromMustBeSpecified))) + Expect(b.Status.Reason).To(Equal(buildapi.BuildReasonPtr(buildapi.SpecEnvOnlyOneOfValueOrValueFromMustBeSpecified))) Expect(b.Status.Message).To(Equal(pointer.String("only one of value or valueFrom must be specified"))) }) It("should pass in case no env var are set", func() { - b := &build.Build{ - Spec: build.BuildSpec{}, + b := &buildapi.Build{ + Spec: buildapi.BuildSpec{}, } err := validate.NewEnv(b).ValidatePath(context.TODO()) @@ -70,8 +70,8 @@ var _ = Describe("Env", func() { }) It("should pass in case of compliant env var", func() { - b := &build.Build{ - Spec: build.BuildSpec{ + b := &buildapi.Build{ + Spec: buildapi.BuildSpec{ Env: []corev1.EnvVar{ { Name: "some-name", @@ -86,8 +86,8 @@ var _ = Describe("Env", func() { }) It("should pass in case of compliant env var using valueFrom", func() { - b := &build.Build{ - Spec: build.BuildSpec{ + b := &buildapi.Build{ + Spec: buildapi.BuildSpec{ Env: []corev1.EnvVar{ { Name: "some-name", diff --git a/pkg/validate/ownerreferences.go b/pkg/validate/ownerreferences.go index 27d38f2954..f9cffc8850 100644 --- a/pkg/validate/ownerreferences.go +++ b/pkg/validate/ownerreferences.go @@ -15,14 +15,14 @@ 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/v1beta1" + buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/ctxlog" ) // OwnerRef contains all required fields // to validate a Build OwnerReference definition type OwnerRef struct { - Build *build.Build + Build *buildapi.Build Client client.Client Scheme *runtime.Scheme } @@ -42,7 +42,7 @@ func (o OwnerRef) ValidatePath(ctx context.Context) error { 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.Reason = buildapi.BuildReasonPtr(buildapi.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 { @@ -69,11 +69,11 @@ func (o OwnerRef) ValidatePath(ctx context.Context) error { } // retrieveBuildRunsfromBuild returns a list of BuildRuns that are owned by a Build in the same namespace -func (o OwnerRef) retrieveBuildRunsfromBuild(ctx context.Context) (*build.BuildRunList, error) { - buildRunList := &build.BuildRunList{} +func (o OwnerRef) retrieveBuildRunsfromBuild(ctx context.Context) (*buildapi.BuildRunList, error) { + buildRunList := &buildapi.BuildRunList{} lbls := map[string]string{ - build.LabelBuild: o.Build.Name, + buildapi.LabelBuild: o.Build.Name, } opts := client.ListOptions{ Namespace: o.Build.Namespace, diff --git a/pkg/validate/params.go b/pkg/validate/params.go index 34a4e4d29c..984ff87a33 100644 --- a/pkg/validate/params.go +++ b/pkg/validate/params.go @@ -8,23 +8,23 @@ import ( "fmt" "strings" - buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "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 []buildv1beta1.Parameter, buildParamValues []buildv1beta1.ParamValue) (bool, buildv1beta1.BuildReason, string) { +func BuildParameters(parameterDefinitions []buildapi.Parameter, buildParamValues []buildapi.ParamValue) (bool, buildapi.BuildReason, string) { valid, reason, message := validateParameters(parameterDefinitions, buildParamValues, true) - return valid, buildv1beta1.BuildReason(reason), message + return valid, buildapi.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 []buildv1beta1.Parameter, buildParamValues []buildv1beta1.ParamValue, buildRunParamValues []buildv1beta1.ParamValue) (bool, string, string) { +func BuildRunParameters(parameterDefinitions []buildapi.Parameter, buildParamValues []buildapi.ParamValue, buildRunParamValues []buildapi.ParamValue) (bool, string, string) { paramValues := resources.OverrideParams(buildParamValues, buildRunParamValues) return validateParameters(parameterDefinitions, paramValues, false) } -func validateParameters(parameterDefinitions []buildv1beta1.Parameter, paramValues []buildv1beta1.ParamValue, ignoreMissingParameters bool) (bool, string, string) { +func validateParameters(parameterDefinitions []buildapi.Parameter, paramValues []buildapi.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 []buildv1beta1.Parameter, paramValu switch parameterDefinition.Type { case "": // string is default fallthrough - case buildv1beta1.ParameterTypeString: + case buildapi.ParameterTypeString: if paramValue != nil { // check if a string value contains array values if paramValue.Values != nil { @@ -107,7 +107,7 @@ func validateParameters(parameterDefinitions []buildv1beta1.Parameter, paramValu continue } - case buildv1beta1.ParameterTypeArray: + case buildapi.ParameterTypeArray: if paramValue != nil { // check if an array value contains a single value if paramValue.SingleValue != nil { @@ -180,7 +180,7 @@ func validateParameters(parameterDefinitions []buildv1beta1.Parameter, paramValu } // hasMoreThanOneValue checks if a SingleValue has more than one value set (plain text, secret, and config map key reference) -func hasMoreThanOneValue(singleValue buildv1beta1.SingleValue) bool { +func hasMoreThanOneValue(singleValue buildapi.SingleValue) bool { if singleValue.Value != nil && (singleValue.ConfigMapValue != nil || singleValue.SecretValue != nil) { return true } @@ -195,7 +195,7 @@ func hasMoreThanOneValue(singleValue buildv1beta1.SingleValue) bool { } // hasNoValue checks if a SingleValue has no value set (plain text, secret, and config map key reference) -func hasNoValue(singleValue buildv1beta1.SingleValue) bool { +func hasNoValue(singleValue buildapi.SingleValue) bool { if singleValue.ConfigMapValue == nil && singleValue.SecretValue == nil && singleValue.Value == nil { return true } @@ -204,7 +204,7 @@ func hasNoValue(singleValue buildv1beta1.SingleValue) bool { } // hasIncompleteConfigMapValue checks if a SingleValue has a ConfigMap value with an empty name or key -func hasIncompleteConfigMapValue(singleValue buildv1beta1.SingleValue) bool { +func hasIncompleteConfigMapValue(singleValue buildapi.SingleValue) bool { if singleValue.ConfigMapValue != nil && (singleValue.ConfigMapValue.Name == "" || singleValue.ConfigMapValue.Key == "") { return true } @@ -213,7 +213,7 @@ func hasIncompleteConfigMapValue(singleValue buildv1beta1.SingleValue) bool { } // hasIncompleteSecretValue checks if a SingleValue has a Secret value with an empty name or key -func hasIncompleteSecretValue(singleValue buildv1beta1.SingleValue) bool { +func hasIncompleteSecretValue(singleValue buildapi.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 494badf7c9..df33b88841 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" - buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "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 := []buildv1beta1.Parameter{ + parameterDefinitions := []buildapi.Parameter{ { Name: "string-param-no-default", }, { Name: "string-param-with-default", - Type: buildv1beta1.ParameterTypeString, + Type: buildapi.ParameterTypeString, Default: pointer.String("default value"), }, { Name: "array-param-no-defaults", - Type: buildv1beta1.ParameterTypeArray, + Type: buildapi.ParameterTypeArray, }, { Name: "array-param-with-defaults", - Type: buildv1beta1.ParameterTypeArray, + Type: buildapi.ParameterTypeArray, Defaults: &[]string{}, }, } Context("for parameters just for the required fields", func() { - buildParamValues := []buildv1beta1.ParamValue{ + buildParamValues := []buildapi.ParamValue{ { Name: "string-param-no-default", - SingleValue: &buildv1beta1.SingleValue{ + SingleValue: &buildapi.SingleValue{ Value: pointer.String("a value"), }, }, } - buildRunParamValues := []buildv1beta1.ParamValue{ + buildRunParamValues := []buildapi.ParamValue{ { Name: "array-param-no-defaults", - Values: []buildv1beta1.SingleValue{}, + Values: []buildapi.SingleValue{}, }, } @@ -59,11 +59,11 @@ var _ = Describe("ValidateBuildRunParameters", func() { }) Context("for parameter values from different sources", func() { - buildParamValues := []buildv1beta1.ParamValue{ + buildParamValues := []buildapi.ParamValue{ { Name: "string-param-no-default", - SingleValue: &buildv1beta1.SingleValue{ - ConfigMapValue: &buildv1beta1.ObjectKeyRef{ + SingleValue: &buildapi.SingleValue{ + ConfigMapValue: &buildapi.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: []buildv1beta1.SingleValue{}, + Values: []buildapi.SingleValue{}, }, } - buildRunParamValues := []buildv1beta1.ParamValue{ + buildRunParamValues := []buildapi.ParamValue{ { Name: "array-param-no-defaults", - Values: []buildv1beta1.SingleValue{ + Values: []buildapi.SingleValue{ { - SecretValue: &buildv1beta1.ObjectKeyRef{ + SecretValue: &buildapi.ObjectKeyRef{ Name: "a-secret", Key: "my-credential-key", }, @@ -90,7 +90,7 @@ var _ = Describe("ValidateBuildRunParameters", func() { }, { Name: "string-param-with-default", - SingleValue: &buildv1beta1.SingleValue{ + SingleValue: &buildapi.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, []buildv1beta1.ParamValue{}, []buildv1beta1.ParamValue{}) + valid, reason, message := validate.BuildRunParameters(parameterDefinitions, []buildapi.ParamValue{}, []buildapi.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 := []buildv1beta1.ParamValue{ + buildParamValues := []buildapi.ParamValue{ { Name: "string-param-no-default", - SingleValue: &buildv1beta1.SingleValue{}, + SingleValue: &buildapi.SingleValue{}, }, } - buildRunParamValues := []buildv1beta1.ParamValue{ + buildRunParamValues := []buildapi.ParamValue{ { Name: "array-param-no-defaults", - Values: []buildv1beta1.SingleValue{}, + Values: []buildapi.SingleValue{}, }, } @@ -138,23 +138,23 @@ var _ = Describe("ValidateBuildRunParameters", func() { }) Context("for parameter values that contain a value for a system parameter", func() { - buildParamValues := []buildv1beta1.ParamValue{ + buildParamValues := []buildapi.ParamValue{ { Name: "string-param-no-default", - SingleValue: &buildv1beta1.SingleValue{ + SingleValue: &buildapi.SingleValue{ Value: pointer.String("a value"), }, }, { Name: "array-param-no-defaults", - Values: []buildv1beta1.SingleValue{}, + Values: []buildapi.SingleValue{}, }, } - buildRunParamValues := []buildv1beta1.ParamValue{ + buildRunParamValues := []buildapi.ParamValue{ { Name: "shp-source-context", - SingleValue: &buildv1beta1.SingleValue{ + SingleValue: &buildapi.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 := []buildv1beta1.ParamValue{ + buildParamValues := []buildapi.ParamValue{ { Name: "string-param-no-default", - SingleValue: &buildv1beta1.SingleValue{ + SingleValue: &buildapi.SingleValue{ Value: pointer.String("a value"), }, }, { Name: "array-param-no-defaults", - Values: []buildv1beta1.SingleValue{}, + Values: []buildapi.SingleValue{}, }, { Name: "non-existing-parameter-on-build", - Values: []buildv1beta1.SingleValue{}, + Values: []buildapi.SingleValue{}, }, } - buildRunParamValues := []buildv1beta1.ParamValue{ + buildRunParamValues := []buildapi.ParamValue{ { Name: "non-existing-parameter", - SingleValue: &buildv1beta1.SingleValue{ + SingleValue: &buildapi.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 := []buildv1beta1.ParamValue{ + buildParamValues := []buildapi.ParamValue{ { Name: "string-param-no-default", - SingleValue: &buildv1beta1.SingleValue{ + SingleValue: &buildapi.SingleValue{ Value: pointer.String("a value"), - ConfigMapValue: &buildv1beta1.ObjectKeyRef{ + ConfigMapValue: &buildapi.ObjectKeyRef{ Name: "a-config-map", Key: "a-key", }, @@ -219,19 +219,19 @@ var _ = Describe("ValidateBuildRunParameters", func() { }, } - buildRunParamValues := []buildv1beta1.ParamValue{ + buildRunParamValues := []buildapi.ParamValue{ { Name: "array-param-no-defaults", - Values: []buildv1beta1.SingleValue{ + Values: []buildapi.SingleValue{ { Value: pointer.String("a good item"), }, { - ConfigMapValue: &buildv1beta1.ObjectKeyRef{ + ConfigMapValue: &buildapi.ObjectKeyRef{ Name: "a-config-map", Key: "a-key", }, - SecretValue: &buildv1beta1.ObjectKeyRef{ + SecretValue: &buildapi.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 := []buildv1beta1.ParamValue{ + buildParamValues := []buildapi.ParamValue{ { Name: "string-param-no-default", - Values: []buildv1beta1.SingleValue{ + Values: []buildapi.SingleValue{ { Value: pointer.String("an item"), }, { - ConfigMapValue: &buildv1beta1.ObjectKeyRef{ + ConfigMapValue: &buildapi.ObjectKeyRef{ Name: "a-config-map", Key: "a-key", }, @@ -268,10 +268,10 @@ var _ = Describe("ValidateBuildRunParameters", func() { }, } - buildRunParamValues := []buildv1beta1.ParamValue{ + buildRunParamValues := []buildapi.ParamValue{ { Name: "array-param-no-defaults", - SingleValue: &buildv1beta1.SingleValue{ + SingleValue: &buildapi.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 := []buildv1beta1.ParamValue{ + buildParamValues := []buildapi.ParamValue{ { Name: "string-param-no-default", - SingleValue: &buildv1beta1.SingleValue{ + SingleValue: &buildapi.SingleValue{ Value: pointer.String(" some value"), }, }, { Name: "array-param-with-defaults", - Values: []buildv1beta1.SingleValue{ + Values: []buildapi.SingleValue{ { // the bad item without any value }, @@ -305,10 +305,10 @@ var _ = Describe("ValidateBuildRunParameters", func() { }, } - buildRunParamValues := []buildv1beta1.ParamValue{ + buildRunParamValues := []buildapi.ParamValue{ { Name: "array-param-no-defaults", - Values: []buildv1beta1.SingleValue{ + Values: []buildapi.SingleValue{ { Value: pointer.String("a good item"), }, @@ -316,7 +316,7 @@ var _ = Describe("ValidateBuildRunParameters", func() { // the bad item without any value }, { - ConfigMapValue: &buildv1beta1.ObjectKeyRef{ + ConfigMapValue: &buildapi.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 := []buildv1beta1.ParamValue{ + buildParamValues := []buildapi.ParamValue{ { Name: "string-param-no-default", - SingleValue: &buildv1beta1.SingleValue{ - ConfigMapValue: &buildv1beta1.ObjectKeyRef{ + SingleValue: &buildapi.SingleValue{ + ConfigMapValue: &buildapi.ObjectKeyRef{ Name: "a-config-map", }, }, }, } - buildRunParamValues := []buildv1beta1.ParamValue{ + buildRunParamValues := []buildapi.ParamValue{ { Name: "array-param-no-defaults", - Values: []buildv1beta1.SingleValue{ + Values: []buildapi.SingleValue{ { Value: pointer.String("an item"), }, { - ConfigMapValue: &buildv1beta1.ObjectKeyRef{ + ConfigMapValue: &buildapi.ObjectKeyRef{ Key: "a-key", }, }, @@ -374,26 +374,26 @@ var _ = Describe("ValidateBuildRunParameters", func() { }) Context("for parameter values that contain incomplete secretValues", func() { - buildParamValues := []buildv1beta1.ParamValue{ + buildParamValues := []buildapi.ParamValue{ { Name: "string-param-no-default", - SingleValue: &buildv1beta1.SingleValue{ - SecretValue: &buildv1beta1.ObjectKeyRef{ + SingleValue: &buildapi.SingleValue{ + SecretValue: &buildapi.ObjectKeyRef{ Name: "a-secret", }, }, }, } - buildRunParamValues := []buildv1beta1.ParamValue{ + buildRunParamValues := []buildapi.ParamValue{ { Name: "array-param-no-defaults", - Values: []buildv1beta1.SingleValue{ + Values: []buildapi.SingleValue{ { Value: pointer.String("an item"), }, { - SecretValue: &buildv1beta1.ObjectKeyRef{ + SecretValue: &buildapi.ObjectKeyRef{ Key: "a-key", }, }, diff --git a/pkg/validate/secrets.go b/pkg/validate/secrets.go index 2e9ba6a5e1..40def3eee1 100644 --- a/pkg/validate/secrets.go +++ b/pkg/validate/secrets.go @@ -16,17 +16,17 @@ import ( "k8s.io/utils/pointer" "sigs.k8s.io/controller-runtime/pkg/client" - build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1" ) // Credentials contains all required fields // to validate a Build spec secrets definitions type Credentials struct { - Build *build.Build + Build *buildapi.Build Client client.Client } -func NewCredentials(client client.Client, build *build.Build) *Credentials { +func NewCredentials(client client.Client, build *buildapi.Build) *Credentials { return &Credentials{build, client} } @@ -42,7 +42,7 @@ func (s Credentials) ValidatePath(ctx context.Context) error { if err := s.Client.Get(ctx, types.NamespacedName{Name: refSecret, Namespace: s.Build.Namespace}, secret); err != nil && !apierrors.IsNotFound(err) { return err } else if apierrors.IsNotFound(err) { - s.Build.Status.Reason = build.BuildReasonPtr(secretType) + s.Build.Status.Reason = buildapi.BuildReasonPtr(secretType) s.Build.Status.Message = pointer.String(fmt.Sprintf("referenced secret %s not found", refSecret)) missingSecrets = append(missingSecrets, refSecret) } @@ -52,21 +52,21 @@ func (s Credentials) ValidatePath(ctx context.Context) error { sort.Strings(missingSecrets) if len(missingSecrets) > 1 { - s.Build.Status.Reason = build.BuildReasonPtr(build.MultipleSecretRefNotFound) + s.Build.Status.Reason = buildapi.BuildReasonPtr(buildapi.MultipleSecretRefNotFound) s.Build.Status.Message = pointer.String(fmt.Sprintf("missing secrets are %s", strings.Join(missingSecrets, ","))) } return nil } -func (s Credentials) buildCredentialReferences() map[string]build.BuildReason { +func (s Credentials) buildCredentialReferences() map[string]buildapi.BuildReason { // Validate if the referenced secrets exist in the namespace - secretRefMap := map[string]build.BuildReason{} + secretRefMap := map[string]buildapi.BuildReason{} if s.Build.Spec.Output.PushSecret != nil { - secretRefMap[*s.Build.Spec.Output.PushSecret] = build.SpecOutputSecretRefNotFound + secretRefMap[*s.Build.Spec.Output.PushSecret] = buildapi.SpecOutputSecretRefNotFound } if s.Build.GetSourceCredentials() != nil { - secretRefMap[*s.Build.GetSourceCredentials()] = build.SpecSourceSecretRefNotFound + secretRefMap[*s.Build.GetSourceCredentials()] = buildapi.SpecSourceSecretRefNotFound } return secretRefMap } diff --git a/pkg/validate/sources.go b/pkg/validate/sources.go index 593ec8c890..be55397194 100644 --- a/pkg/validate/sources.go +++ b/pkg/validate/sources.go @@ -8,12 +8,12 @@ import ( "context" "fmt" - build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1" ) // SourcesRef implements RuntimeRef interface to add validations for `build.spec.source`. type SourceRef struct { - Build *build.Build // build instance for analysis + Build *buildapi.Build // build instance for analysis } // ValidatePath executes the validation routine, inspecting the `build.spec.source` path @@ -26,7 +26,7 @@ func (s *SourceRef) ValidatePath(_ context.Context) error { } // validateSourceEntry inspect informed entry, probes all required attributes. -func (s *SourceRef) validateSourceEntry(source *build.Source) error { +func (s *SourceRef) validateSourceEntry(source *buildapi.Source) error { // dont bail out if the Source object is empty, we preserve the old behaviour as in v1alpha1 if source.Type == "" && source.Git == nil && @@ -54,6 +54,6 @@ func (s *SourceRef) validateSourceEntry(source *build.Source) error { } // NewSourcesRef instantiate a new SourcesRef passing the build object pointer along. -func NewSourceRef(b *build.Build) *SourceRef { +func NewSourceRef(b *buildapi.Build) *SourceRef { return &SourceRef{Build: b} } diff --git a/pkg/validate/sources_test.go b/pkg/validate/sources_test.go index 182b0693cb..2c3d90ce04 100644 --- a/pkg/validate/sources_test.go +++ b/pkg/validate/sources_test.go @@ -10,24 +10,24 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/validate" ) var _ = Describe("SourcesRef", func() { Context("ValidatePath", func() { It("should successfully validate an empty source", func() { - srcRef := validate.NewSourceRef(&build.Build{}) + srcRef := validate.NewSourceRef(&buildapi.Build{}) Expect(srcRef.ValidatePath(context.TODO())).To(BeNil()) }) It("should successfully validate a build with source", func() { - srcRef := validate.NewSourceRef(&build.Build{ - Spec: build.BuildSpec{ - Source: &build.Source{ + srcRef := validate.NewSourceRef(&buildapi.Build{ + Spec: buildapi.BuildSpec{ + Source: &buildapi.Source{ Type: "Git", - Git: &build.Git{}, + Git: &buildapi.Git{}, }, }, }) @@ -36,10 +36,10 @@ var _ = Describe("SourcesRef", func() { }) It("should fail to validate if the type is not defined", func() { - srcRef := validate.NewSourceRef(&build.Build{ - Spec: build.BuildSpec{ - Source: &build.Source{ - Git: &build.Git{}, + srcRef := validate.NewSourceRef(&buildapi.Build{ + Spec: buildapi.BuildSpec{ + Source: &buildapi.Source{ + Git: &buildapi.Git{}, }, }, }) @@ -48,11 +48,11 @@ var _ = Describe("SourcesRef", func() { }) It("should fail to validate if the type does not match the source git", func() { - srcRef := validate.NewSourceRef(&build.Build{ - Spec: build.BuildSpec{ - Source: &build.Source{ + srcRef := validate.NewSourceRef(&buildapi.Build{ + Spec: buildapi.BuildSpec{ + Source: &buildapi.Source{ Type: "OCI", - Git: &build.Git{}, + Git: &buildapi.Git{}, }, }, }) diff --git a/pkg/validate/sourceurl.go b/pkg/validate/sourceurl.go index a48ca20bb8..a60c6a4765 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/v1beta1" + buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/ctxlog" "github.com/shipwright-io/build/pkg/git" ) @@ -19,11 +19,11 @@ import ( // SourceURLRef contains all required fields // to validate a Build spec source definition type SourceURLRef struct { - Build *build.Build + Build *buildapi.Build Client client.Client } -func NewSourceURL(client client.Client, build *build.Build) *SourceURLRef { +func NewSourceURL(client client.Client, build *buildapi.Build) *SourceURLRef { return &SourceURLRef{build, client} } @@ -31,22 +31,22 @@ 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 != nil && s.Build.Spec.Source.Type == build.GitType && s.Build.Spec.Source.Git != nil { + if s.Build.Spec.Source != nil && s.Build.Spec.Source.Type == buildapi.GitType && s.Build.Spec.Source.Git != nil { Git := s.Build.Spec.Source.Git if Git.CloneSecret == nil { - switch s.Build.GetAnnotations()[build.AnnotationBuildVerifyRepository] { + switch s.Build.GetAnnotations()[buildapi.AnnotationBuildVerifyRepository] { case "true": if err := git.ValidateGitURLExists(ctx, Git.URL); err != nil { - s.MarkBuildStatus(s.Build, build.RemoteRepositoryUnreachable, err.Error()) + s.MarkBuildStatus(s.Build, buildapi.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) + ctxlog.Info(ctx, fmt.Sprintf("the annotation %s is set to %s, nothing to do", buildapi.AnnotationBuildVerifyRepository, s.Build.GetAnnotations()[buildapi.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) + var annoErr = fmt.Errorf("the annotation %s was not properly defined, supported values are true or false", buildapi.AnnotationBuildVerifyRepository) ctxlog.Error(ctx, annoErr, namespace, s.Build.Namespace, name, s.Build.Name) - s.MarkBuildStatus(s.Build, build.RemoteRepositoryUnreachable, annoErr.Error()) + s.MarkBuildStatus(s.Build, buildapi.RemoteRepositoryUnreachable, annoErr.Error()) return annoErr } } @@ -56,7 +56,7 @@ func (s SourceURLRef) ValidatePath(ctx context.Context) error { } // MarkBuildStatus updates a Build Status fields -func (s SourceURLRef) MarkBuildStatus(b *build.Build, reason build.BuildReason, msg string) { - b.Status.Reason = build.BuildReasonPtr(reason) +func (s SourceURLRef) MarkBuildStatus(b *buildapi.Build, reason buildapi.BuildReason, msg string) { + b.Status.Reason = buildapi.BuildReasonPtr(reason) b.Status.Message = pointer.String(msg) } diff --git a/pkg/validate/strategies.go b/pkg/validate/strategies.go index 3ecbcc2706..a1ecdeac39 100644 --- a/pkg/validate/strategies.go +++ b/pkg/validate/strategies.go @@ -13,18 +13,18 @@ import ( "k8s.io/utils/pointer" "sigs.k8s.io/controller-runtime/pkg/client" - build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/ctxlog" ) // Strategy contains all required fields // to validate a Build spec strategy definition type Strategy struct { - Build *build.Build + Build *buildapi.Build Client client.Client } -func NewStrategies(client client.Client, build *build.Build) *Strategy { +func NewStrategies(client client.Client, build *buildapi.Build) *Strategy { return &Strategy{build, client} } @@ -33,19 +33,19 @@ func NewStrategies(client client.Client, build *build.Build) *Strategy { // namespaced or cluster scoped strategies func (s Strategy) ValidatePath(ctx context.Context) error { var ( - builderStrategy build.BuilderStrategy + builderStrategy buildapi.BuilderStrategy strategyExists bool err error ) if s.Build.Spec.Strategy.Kind != nil { switch *s.Build.Spec.Strategy.Kind { - case build.NamespacedBuildStrategyKind: - buildStrategy := &build.BuildStrategy{} + case buildapi.NamespacedBuildStrategyKind: + buildStrategy := &buildapi.BuildStrategy{} strategyExists, err = s.validateBuildStrategy(ctx, s.Build.Spec.Strategy.Name, buildStrategy) builderStrategy = buildStrategy - case build.ClusterBuildStrategyKind: - clusterBuildStrategy := &build.ClusterBuildStrategy{} + case buildapi.ClusterBuildStrategyKind: + clusterBuildStrategy := &buildapi.ClusterBuildStrategy{} strategyExists, err = s.validateClusterBuildStrategy(ctx, s.Build.Spec.Strategy.Name, clusterBuildStrategy) builderStrategy = clusterBuildStrategy default: @@ -53,7 +53,7 @@ func (s Strategy) ValidatePath(ctx context.Context) error { } } else { ctxlog.Info(ctx, "buildStrategy kind is nil, use default NamespacedBuildStrategyKind", namespace, s.Build.Namespace, name, s.Build.Name) - buildStrategy := &build.BuildStrategy{} + buildStrategy := &buildapi.BuildStrategy{} strategyExists, err = s.validateBuildStrategy(ctx, s.Build.Spec.Strategy.Name, buildStrategy) builderStrategy = buildStrategy } @@ -70,42 +70,42 @@ func (s Strategy) ValidatePath(ctx context.Context) error { return nil } -func (s Strategy) validateBuildStrategy(ctx context.Context, strategyName string, buildStrategy *build.BuildStrategy) (bool, error) { +func (s Strategy) validateBuildStrategy(ctx context.Context, strategyName string, buildStrategy *buildapi.BuildStrategy) (bool, error) { if err := s.Client.Get(ctx, types.NamespacedName{Name: strategyName, Namespace: s.Build.Namespace}, buildStrategy); err != nil && !apierrors.IsNotFound(err) { return false, err } else if apierrors.IsNotFound(err) { - s.Build.Status.Reason = build.BuildReasonPtr(build.BuildStrategyNotFound) + s.Build.Status.Reason = buildapi.BuildReasonPtr(buildapi.BuildStrategyNotFound) s.Build.Status.Message = pointer.String(fmt.Sprintf("buildStrategy %s does not exist in namespace %s", s.Build.Spec.Strategy.Name, s.Build.Namespace)) return false, nil } return true, nil } -func (s Strategy) validateClusterBuildStrategy(ctx context.Context, strategyName string, clusterBuildStrategy *build.ClusterBuildStrategy) (bool, error) { +func (s Strategy) validateClusterBuildStrategy(ctx context.Context, strategyName string, clusterBuildStrategy *buildapi.ClusterBuildStrategy) (bool, error) { if err := s.Client.Get(ctx, types.NamespacedName{Name: strategyName}, clusterBuildStrategy); err != nil && !apierrors.IsNotFound(err) { return false, err } else if apierrors.IsNotFound(err) { - s.Build.Status.Reason = build.BuildReasonPtr(build.ClusterBuildStrategyNotFound) + s.Build.Status.Reason = buildapi.BuildReasonPtr(buildapi.ClusterBuildStrategyNotFound) s.Build.Status.Message = pointer.String(fmt.Sprintf("clusterBuildStrategy %s does not exist", s.Build.Spec.Strategy.Name)) return false, nil } return true, nil } -func (s Strategy) validateBuildParams(parameterDefinitions []build.Parameter) { +func (s Strategy) validateBuildParams(parameterDefinitions []buildapi.Parameter) { valid, reason, message := BuildParameters(parameterDefinitions, s.Build.Spec.ParamValues) if !valid { - s.Build.Status.Reason = build.BuildReasonPtr(reason) + s.Build.Status.Reason = buildapi.BuildReasonPtr(reason) s.Build.Status.Message = pointer.String(message) } } -func (s Strategy) validateBuildVolumes(strategyVolumes []build.BuildStrategyVolume) { +func (s Strategy) validateBuildVolumes(strategyVolumes []buildapi.BuildStrategyVolume) { valid, reason, message := BuildVolumes(strategyVolumes, s.Build.Spec.Volumes) if !valid { - s.Build.Status.Reason = build.BuildReasonPtr(reason) + s.Build.Status.Reason = buildapi.BuildReasonPtr(reason) s.Build.Status.Message = pointer.String(message) } } diff --git a/pkg/validate/trigger.go b/pkg/validate/trigger.go index d25d39d863..a46ef66e8e 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/v1beta1" + buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1" kerrors "k8s.io/apimachinery/pkg/util/errors" "k8s.io/utils/pointer" ) @@ -15,69 +15,69 @@ import ( // Trigger implements the interface BuildPath with the objective of applying validations against the // `.spec.trigger` related attributes. type Trigger struct { - build *build.Build // build instance + build *buildapi.Build // build instance } // validate goes through the trigger "when" conditions to validate each entry. -func (t *Trigger) validate(triggerWhen []build.TriggerWhen) []error { +func (t *Trigger) validate(triggerWhen []buildapi.TriggerWhen) []error { var allErrs []error for _, when := range triggerWhen { if when.Name == "" { - t.build.Status.Reason = build.BuildReasonPtr(build.TriggerNameCanNotBeBlank) + t.build.Status.Reason = buildapi.BuildReasonPtr(buildapi.TriggerNameCanNotBeBlank) t.build.Status.Message = pointer.String("name is not set on when trigger condition") allErrs = append(allErrs, fmt.Errorf("%s", *t.build.Status.Message)) } switch when.Type { - case build.GitHubWebHookTrigger: + case buildapi.GitHubWebHookTrigger: if when.GitHub == nil { - t.build.Status.Reason = build.BuildReasonPtr(build.TriggerInvalidGitHubWebHook) + t.build.Status.Reason = buildapi.BuildReasonPtr(buildapi.TriggerInvalidGitHubWebHook) t.build.Status.Message = pointer.String(fmt.Sprintf( "%q is missing required attribute `.github`", when.Name, )) allErrs = append(allErrs, fmt.Errorf("%s", *t.build.Status.Message)) } else { if len(when.GitHub.Events) == 0 { - t.build.Status.Reason = build.BuildReasonPtr(build.TriggerInvalidGitHubWebHook) + t.build.Status.Reason = buildapi.BuildReasonPtr(buildapi.TriggerInvalidGitHubWebHook) t.build.Status.Message = pointer.String(fmt.Sprintf( "%q is missing required attribute `.github.events`", when.Name, )) allErrs = append(allErrs, fmt.Errorf("%s", *t.build.Status.Message)) } } - case build.ImageTrigger: + case buildapi.ImageTrigger: if when.Image == nil { - t.build.Status.Reason = build.BuildReasonPtr(build.TriggerInvalidImage) + t.build.Status.Reason = buildapi.BuildReasonPtr(buildapi.TriggerInvalidImage) t.build.Status.Message = pointer.String(fmt.Sprintf( "%q is missing required attribute `.image`", when.Name, )) allErrs = append(allErrs, fmt.Errorf("%s", *t.build.Status.Message)) } else { if len(when.Image.Names) == 0 { - t.build.Status.Reason = build.BuildReasonPtr(build.TriggerInvalidImage) + t.build.Status.Reason = buildapi.BuildReasonPtr(buildapi.TriggerInvalidImage) t.build.Status.Message = pointer.String(fmt.Sprintf( "%q is missing required attribute `.image.names`", when.Name, )) allErrs = append(allErrs, fmt.Errorf("%s", *t.build.Status.Message)) } } - case build.PipelineTrigger: + case buildapi.PipelineTrigger: if when.ObjectRef == nil { - t.build.Status.Reason = build.BuildReasonPtr(build.TriggerInvalidPipeline) + t.build.Status.Reason = buildapi.BuildReasonPtr(buildapi.TriggerInvalidPipeline) t.build.Status.Message = pointer.String(fmt.Sprintf( "%q is missing required attribute `.objectRef`", when.Name, )) allErrs = append(allErrs, fmt.Errorf("%s", *t.build.Status.Message)) } else { if len(when.ObjectRef.Status) == 0 { - t.build.Status.Reason = build.BuildReasonPtr(build.TriggerInvalidPipeline) + t.build.Status.Reason = buildapi.BuildReasonPtr(buildapi.TriggerInvalidPipeline) t.build.Status.Message = pointer.String(fmt.Sprintf( "%q is missing required attribute `.objectRef.status`", when.Name, )) allErrs = append(allErrs, fmt.Errorf("%s", *t.build.Status.Message)) } if when.ObjectRef.Name == "" && len(when.ObjectRef.Selector) == 0 { - t.build.Status.Reason = build.BuildReasonPtr(build.TriggerInvalidPipeline) + t.build.Status.Reason = buildapi.BuildReasonPtr(buildapi.TriggerInvalidPipeline) t.build.Status.Message = pointer.String(fmt.Sprintf( "%q is missing required attributes `.objectRef.name` or `.objectRef.selector`", when.Name, @@ -85,7 +85,7 @@ func (t *Trigger) validate(triggerWhen []build.TriggerWhen) []error { allErrs = append(allErrs, fmt.Errorf("%s", *t.build.Status.Message)) } if when.ObjectRef.Name != "" && len(when.ObjectRef.Selector) > 0 { - t.build.Status.Reason = build.BuildReasonPtr(build.TriggerInvalidPipeline) + t.build.Status.Reason = buildapi.BuildReasonPtr(buildapi.TriggerInvalidPipeline) t.build.Status.Message = pointer.String(fmt.Sprintf( "%q contains `.objectRef.name` and `.objectRef.selector`, must be only one", when.Name, @@ -94,7 +94,7 @@ func (t *Trigger) validate(triggerWhen []build.TriggerWhen) []error { } } default: - t.build.Status.Reason = build.BuildReasonPtr(build.TriggerInvalidType) + t.build.Status.Reason = buildapi.BuildReasonPtr(buildapi.TriggerInvalidType) t.build.Status.Message = pointer.String( fmt.Sprintf("%q contains an invalid type %q", when.Name, when.Type)) allErrs = append(allErrs, fmt.Errorf("%s", *t.build.Status.Message)) @@ -116,6 +116,6 @@ func (t *Trigger) ValidatePath(_ context.Context) error { } // NewTrigger instantiate Trigger validation helper. -func NewTrigger(b *build.Build) *Trigger { +func NewTrigger(b *buildapi.Build) *Trigger { return &Trigger{build: b} } diff --git a/pkg/validate/trigger_test.go b/pkg/validate/trigger_test.go index 7d99745fbe..9c50689b4d 100644 --- a/pkg/validate/trigger_test.go +++ b/pkg/validate/trigger_test.go @@ -8,16 +8,16 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/validate" ) var _ = Describe("ValidateBuildTriggers", func() { Context("trigger name is not informed", func() { - b := &build.Build{ - Spec: build.BuildSpec{ - Trigger: &build.Trigger{ - When: []build.TriggerWhen{{ + b := &buildapi.Build{ + Spec: buildapi.BuildSpec{ + Trigger: &buildapi.Trigger{ + When: []buildapi.TriggerWhen{{ Name: "", }}, }, @@ -32,12 +32,12 @@ var _ = Describe("ValidateBuildTriggers", func() { Context("trigger type github", func() { It("should error when github attribute is not set", func() { - b := &build.Build{ - Spec: build.BuildSpec{ - Trigger: &build.Trigger{ - When: []build.TriggerWhen{{ + b := &buildapi.Build{ + Spec: buildapi.BuildSpec{ + Trigger: &buildapi.Trigger{ + When: []buildapi.TriggerWhen{{ Name: "github", - Type: build.GitHubWebHookTrigger, + Type: buildapi.GitHubWebHookTrigger, }}, }, }, @@ -48,14 +48,14 @@ var _ = Describe("ValidateBuildTriggers", func() { }) It("should error when github events attribute is empty", func() { - b := &build.Build{ - Spec: build.BuildSpec{ - Trigger: &build.Trigger{ - When: []build.TriggerWhen{{ + b := &buildapi.Build{ + Spec: buildapi.BuildSpec{ + Trigger: &buildapi.Trigger{ + When: []buildapi.TriggerWhen{{ Name: "github", - Type: build.GitHubWebHookTrigger, - GitHub: &build.WhenGitHub{ - Events: []build.GitHubEventName{}, + Type: buildapi.GitHubWebHookTrigger, + GitHub: &buildapi.WhenGitHub{ + Events: []buildapi.GitHubEventName{}, }, }}, }, @@ -67,15 +67,15 @@ var _ = Describe("ValidateBuildTriggers", func() { }) It("should pass when github type is complete", func() { - b := &build.Build{ - Spec: build.BuildSpec{ - Trigger: &build.Trigger{ - When: []build.TriggerWhen{{ + b := &buildapi.Build{ + Spec: buildapi.BuildSpec{ + Trigger: &buildapi.Trigger{ + When: []buildapi.TriggerWhen{{ Name: "github", - Type: build.GitHubWebHookTrigger, - GitHub: &build.WhenGitHub{ - Events: []build.GitHubEventName{ - build.GitHubPushEvent, + Type: buildapi.GitHubWebHookTrigger, + GitHub: &buildapi.WhenGitHub{ + Events: []buildapi.GitHubEventName{ + buildapi.GitHubPushEvent, }, }, }}, @@ -90,12 +90,12 @@ var _ = Describe("ValidateBuildTriggers", func() { Context("trigger type image", func() { It("should error when image attribute is not set", func() { - b := &build.Build{ - Spec: build.BuildSpec{ - Trigger: &build.Trigger{ - When: []build.TriggerWhen{{ + b := &buildapi.Build{ + Spec: buildapi.BuildSpec{ + Trigger: &buildapi.Trigger{ + When: []buildapi.TriggerWhen{{ Name: "image", - Type: build.ImageTrigger, + Type: buildapi.ImageTrigger, }}, }, }, @@ -106,13 +106,13 @@ var _ = Describe("ValidateBuildTriggers", func() { }) It("should error when image names attribute is empty", func() { - b := &build.Build{ - Spec: build.BuildSpec{ - Trigger: &build.Trigger{ - When: []build.TriggerWhen{{ + b := &buildapi.Build{ + Spec: buildapi.BuildSpec{ + Trigger: &buildapi.Trigger{ + When: []buildapi.TriggerWhen{{ Name: "image", - Type: build.ImageTrigger, - Image: &build.WhenImage{ + Type: buildapi.ImageTrigger, + Image: &buildapi.WhenImage{ Names: []string{}, }, }}, @@ -125,13 +125,13 @@ var _ = Describe("ValidateBuildTriggers", func() { }) It("should pass when github type is complete", func() { - b := &build.Build{ - Spec: build.BuildSpec{ - Trigger: &build.Trigger{ - When: []build.TriggerWhen{{ + b := &buildapi.Build{ + Spec: buildapi.BuildSpec{ + Trigger: &buildapi.Trigger{ + When: []buildapi.TriggerWhen{{ Name: "image", - Type: build.ImageTrigger, - Image: &build.WhenImage{ + Type: buildapi.ImageTrigger, + Image: &buildapi.WhenImage{ Names: []string{ "ghcr.io/shipwright-io/build:latest", }, @@ -148,12 +148,12 @@ var _ = Describe("ValidateBuildTriggers", func() { Context("trigger type pipeline", func() { It("should error when objectRef attribute is not set", func() { - b := &build.Build{ - Spec: build.BuildSpec{ - Trigger: &build.Trigger{ - When: []build.TriggerWhen{{ + b := &buildapi.Build{ + Spec: buildapi.BuildSpec{ + Trigger: &buildapi.Trigger{ + When: []buildapi.TriggerWhen{{ Name: "pipeline", - Type: build.PipelineTrigger, + Type: buildapi.PipelineTrigger, }}, }, }, @@ -164,13 +164,13 @@ var _ = Describe("ValidateBuildTriggers", func() { }) It("should error when status attribute is empty", func() { - b := &build.Build{ - Spec: build.BuildSpec{ - Trigger: &build.Trigger{ - When: []build.TriggerWhen{{ + b := &buildapi.Build{ + Spec: buildapi.BuildSpec{ + Trigger: &buildapi.Trigger{ + When: []buildapi.TriggerWhen{{ Name: "pipeline", - Type: build.PipelineTrigger, - ObjectRef: &build.WhenObjectRef{ + Type: buildapi.PipelineTrigger, + ObjectRef: &buildapi.WhenObjectRef{ Status: []string{}, }, }}, @@ -183,13 +183,13 @@ var _ = Describe("ValidateBuildTriggers", func() { }) It("should error when missing required attributes", func() { - b := &build.Build{ - Spec: build.BuildSpec{ - Trigger: &build.Trigger{ - When: []build.TriggerWhen{{ + b := &buildapi.Build{ + Spec: buildapi.BuildSpec{ + Trigger: &buildapi.Trigger{ + When: []buildapi.TriggerWhen{{ Name: "pipeline", - Type: build.PipelineTrigger, - ObjectRef: &build.WhenObjectRef{ + Type: buildapi.PipelineTrigger, + ObjectRef: &buildapi.WhenObjectRef{ Status: []string{"Succeed"}, }, }}, @@ -204,13 +204,13 @@ var _ = Describe("ValidateBuildTriggers", func() { }) It("should error when declaring conflicting attributes", func() { - b := &build.Build{ - Spec: build.BuildSpec{ - Trigger: &build.Trigger{ - When: []build.TriggerWhen{{ + b := &buildapi.Build{ + Spec: buildapi.BuildSpec{ + Trigger: &buildapi.Trigger{ + When: []buildapi.TriggerWhen{{ Name: "pipeline", - Type: build.PipelineTrigger, - ObjectRef: &build.WhenObjectRef{ + Type: buildapi.PipelineTrigger, + ObjectRef: &buildapi.WhenObjectRef{ Status: []string{"Succeed"}, Name: "name", Selector: map[string]string{ @@ -229,13 +229,13 @@ var _ = Describe("ValidateBuildTriggers", func() { }) It("should pass when objectRef type is complete", func() { - b := &build.Build{ - Spec: build.BuildSpec{ - Trigger: &build.Trigger{ - When: []build.TriggerWhen{{ + b := &buildapi.Build{ + Spec: buildapi.BuildSpec{ + Trigger: &buildapi.Trigger{ + When: []buildapi.TriggerWhen{{ Name: "pipeline", - Type: build.PipelineTrigger, - ObjectRef: &build.WhenObjectRef{ + Type: buildapi.PipelineTrigger, + ObjectRef: &buildapi.WhenObjectRef{ Status: []string{"Succeed"}, Name: "name", }, @@ -251,13 +251,13 @@ var _ = Describe("ValidateBuildTriggers", func() { Context("invalid trigger type", func() { It("should error when declaring a invalid trigger type", func() { - b := &build.Build{ - Spec: build.BuildSpec{ - Trigger: &build.Trigger{ - When: []build.TriggerWhen{{ + b := &buildapi.Build{ + Spec: buildapi.BuildSpec{ + Trigger: &buildapi.Trigger{ + When: []buildapi.TriggerWhen{{ Name: "pipeline", - Type: build.TriggerType("invalid"), - ObjectRef: &build.WhenObjectRef{ + Type: buildapi.TriggerType("invalid"), + ObjectRef: &buildapi.WhenObjectRef{ Name: "name", }, }}, diff --git a/pkg/validate/validate.go b/pkg/validate/validate.go index 91d15db46b..684f7b1d27 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/v1beta1" + buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/reconciler/buildrun/resources" ) @@ -52,7 +52,7 @@ type BuildPath interface { // BuildPath interface func NewValidation( validationType string, - build *build.Build, + build *buildapi.Build, client client.Client, scheme *runtime.Scheme, ) (BuildPath, error) { @@ -93,7 +93,7 @@ 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) { +func BuildRunFields(buildRun *buildapi.BuildRun) (string, string) { if buildRun.Spec.Build.Spec == nil && buildRun.Spec.Build.Name == nil { return resources.BuildRunNoRefOrSpec, "no build referenced or specified, either 'buildRef' or 'buildSpec' has to be set" diff --git a/pkg/validate/volumes.go b/pkg/validate/volumes.go index 8b152cc9fc..bb675b1d72 100644 --- a/pkg/validate/volumes.go +++ b/pkg/validate/volumes.go @@ -7,16 +7,16 @@ package validate import ( "fmt" - buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1" ) // BuildVolumes is used to validate volumes in the Build object -func BuildVolumes(strategyVolumes []buildv1beta1.BuildStrategyVolume, buildVolumes []buildv1beta1.BuildVolume) (bool, buildv1beta1.BuildReason, string) { +func BuildVolumes(strategyVolumes []buildapi.BuildStrategyVolume, buildVolumes []buildapi.BuildVolume) (bool, buildapi.BuildReason, string) { return validateVolumes(strategyVolumes, buildVolumes) } // BuildRunVolumes is used to validate volumes in the BuildRun object -func BuildRunVolumes(strategyVolumes []buildv1beta1.BuildStrategyVolume, buildVolumes []buildv1beta1.BuildVolume) (bool, string, string) { +func BuildRunVolumes(strategyVolumes []buildapi.BuildStrategyVolume, buildVolumes []buildapi.BuildVolume) (bool, string, string) { valid, reason, msg := validateVolumes(strategyVolumes, buildVolumes) return valid, string(reason), msg } @@ -24,18 +24,18 @@ func BuildRunVolumes(strategyVolumes []buildv1beta1.BuildStrategyVolume, buildVo // 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 []buildv1beta1.BuildStrategyVolume, buildVolumes []buildv1beta1.BuildVolume) (bool, buildv1beta1.BuildReason, string) { +func validateVolumes(strategyVolumes []buildapi.BuildStrategyVolume, buildVolumes []buildapi.BuildVolume) (bool, buildapi.BuildReason, string) { strategyVolumesMap := toVolumeMap(strategyVolumes) for _, buildVolume := range buildVolumes { strategyVolume, ok := strategyVolumesMap[buildVolume.Name] if !ok { - return false, buildv1beta1.UndefinedVolume, fmt.Sprintf("Volume %q is not defined in the Strategy", buildVolume.Name) + return false, buildapi.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, buildv1beta1.VolumeNotOverridable, fmt.Sprintf("Volume %q is not overridable in the Strategy", buildVolume.Name) + return false, buildapi.VolumeNotOverridable, fmt.Sprintf("Volume %q is not overridable in the Strategy", buildVolume.Name) } } @@ -43,8 +43,8 @@ func validateVolumes(strategyVolumes []buildv1beta1.BuildStrategyVolume, buildVo } // 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 []buildv1beta1.BuildStrategyVolume) map[string]buildv1beta1.BuildStrategyVolume { - res := make(map[string]buildv1beta1.BuildStrategyVolume) +func toVolumeMap(strategyVolumes []buildapi.BuildStrategyVolume) map[string]buildapi.BuildStrategyVolume { + res := make(map[string]buildapi.BuildStrategyVolume) for _, vol := range strategyVolumes { res[vol.Name] = vol } diff --git a/pkg/volumes/volumes.go b/pkg/volumes/volumes.go index 89168db1a2..4e2788da16 100644 --- a/pkg/volumes/volumes.go +++ b/pkg/volumes/volumes.go @@ -7,7 +7,7 @@ package volumes import ( "fmt" - buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "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 []buildv1beta1.BuildStrategyVolume, - buildVolumes []buildv1beta1.BuildVolume, - buildrunVolumes []buildv1beta1.BuildVolume, + strategyVolumes []buildapi.BuildStrategyVolume, + buildVolumes []buildapi.BuildVolume, + buildrunVolumes []buildapi.BuildVolume, ) ([]corev1.Volume, error) { res := []corev1.Volume{} @@ -59,7 +59,7 @@ func TaskSpecVolumes( return res, nil } -func isReadOnlyVolume(strategyVolume *buildv1beta1.BuildStrategyVolume) bool { +func isReadOnlyVolume(strategyVolume *buildapi.BuildStrategyVolume) bool { return strategyVolume.VolumeSource.ConfigMap != nil || strategyVolume.VolumeSource.Secret != nil || strategyVolume.VolumeSource.DownwardAPI != nil || @@ -69,15 +69,15 @@ func isReadOnlyVolume(strategyVolume *buildv1beta1.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 []buildv1beta1.BuildStrategyVolume, new []buildv1beta1.BuildVolume) ([]buildv1beta1.BuildStrategyVolume, error) { +func MergeBuildVolumes(into []buildapi.BuildStrategyVolume, new []buildapi.BuildVolume) ([]buildapi.BuildStrategyVolume, error) { if len(new) == 0 && len(into) == 0 { - return []buildv1beta1.BuildStrategyVolume{}, nil + return []buildapi.BuildStrategyVolume{}, nil } if len(new) == 0 { return into, nil } - mergeMap := make(map[string]buildv1beta1.BuildStrategyVolume) + mergeMap := make(map[string]buildapi.BuildStrategyVolume) var errors []error for _, vol := range into { @@ -105,7 +105,7 @@ func MergeBuildVolumes(into []buildv1beta1.BuildStrategyVolume, new []buildv1bet mergeMap[merger.Name] = original } - result := make([]buildv1beta1.BuildStrategyVolume, 0, len(mergeMap)) + result := make([]buildapi.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 a40ebb8c03..539b51fe5f 100644 --- a/pkg/volumes/volumes_test.go +++ b/pkg/volumes/volumes_test.go @@ -8,7 +8,7 @@ import ( "reflect" "testing" - buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/volumes" corev1 "k8s.io/api/core/v1" ) @@ -58,7 +58,7 @@ func createVolumeSource(vt volumeType, vsName string) *corev1.VolumeSource { return vs } -func createBuildStrategyVolume(name string, description string, vt volumeType, vsName string, overridable bool) buildv1beta1.BuildStrategyVolume { +func createBuildStrategyVolume(name string, description string, vt volumeType, vsName string, overridable bool) buildapi.BuildStrategyVolume { vs := createVolumeSource(vt, vsName) var descr *string @@ -66,7 +66,7 @@ func createBuildStrategyVolume(name string, description string, vt volumeType, v descr = &description } - bv := buildv1beta1.BuildStrategyVolume{ + bv := buildapi.BuildStrategyVolume{ Name: name, Description: descr, VolumeSource: *vs, @@ -75,7 +75,7 @@ func createBuildStrategyVolume(name string, description string, vt volumeType, v return bv } -func createBuildStrategyVolumeEmptyOverridable(name string, description string, vt volumeType, vsName string) buildv1beta1.BuildStrategyVolume { +func createBuildStrategyVolumeEmptyOverridable(name string, description string, vt volumeType, vsName string) buildapi.BuildStrategyVolume { vs := createVolumeSource(vt, vsName) var descr *string @@ -83,7 +83,7 @@ func createBuildStrategyVolumeEmptyOverridable(name string, description string, descr = &description } - bv := buildv1beta1.BuildStrategyVolume{ + bv := buildapi.BuildStrategyVolume{ Name: name, Description: descr, VolumeSource: *vs, @@ -91,10 +91,10 @@ func createBuildStrategyVolumeEmptyOverridable(name string, description string, return bv } -func createBuildVolume(name string, vt volumeType, vsName string) buildv1beta1.BuildVolume { +func createBuildVolume(name string, vt volumeType, vsName string) buildapi.BuildVolume { vs := createVolumeSource(vt, vsName) - bv := buildv1beta1.BuildVolume{ + bv := buildapi.BuildVolume{ Name: name, VolumeSource: *vs, } @@ -105,90 +105,90 @@ func TestMergeVolumes(t *testing.T) { testingData := []struct { name string - into []buildv1beta1.BuildStrategyVolume - mergers []buildv1beta1.BuildVolume - expected []buildv1beta1.BuildStrategyVolume + into []buildapi.BuildStrategyVolume + mergers []buildapi.BuildVolume + expected []buildapi.BuildStrategyVolume expectErr bool }{ { name: "both empty", - into: []buildv1beta1.BuildStrategyVolume{}, - mergers: []buildv1beta1.BuildVolume{}, - expected: []buildv1beta1.BuildStrategyVolume{}, + into: []buildapi.BuildStrategyVolume{}, + mergers: []buildapi.BuildVolume{}, + expected: []buildapi.BuildStrategyVolume{}, expectErr: false, }, { name: "mergers empty", - into: []buildv1beta1.BuildStrategyVolume{ + into: []buildapi.BuildStrategyVolume{ createBuildStrategyVolume("bvname", "bv description", "ConfigMap", "my-config", true), }, - mergers: []buildv1beta1.BuildVolume{}, - expected: []buildv1beta1.BuildStrategyVolume{ + mergers: []buildapi.BuildVolume{}, + expected: []buildapi.BuildStrategyVolume{ createBuildStrategyVolume("bvname", "bv description", "ConfigMap", "my-config", true), }, expectErr: false, }, { name: "into empty must fail", - into: []buildv1beta1.BuildStrategyVolume{}, - mergers: []buildv1beta1.BuildVolume{ + into: []buildapi.BuildStrategyVolume{}, + mergers: []buildapi.BuildVolume{ createBuildVolume("bvname", "ConfigMap", "my-config"), }, - expected: []buildv1beta1.BuildStrategyVolume{ + expected: []buildapi.BuildStrategyVolume{ createBuildStrategyVolume("bvname", "bv description", "ConfigMap", "my-config", true), }, expectErr: true, }, { name: "override one emptyDir with secret", - into: []buildv1beta1.BuildStrategyVolume{ + into: []buildapi.BuildStrategyVolume{ createBuildStrategyVolume("bvname", "bv description", "EmptyDir", "", true), }, - mergers: []buildv1beta1.BuildVolume{ + mergers: []buildapi.BuildVolume{ createBuildVolume("bvname", "ConfigMap", "my-config"), }, - expected: []buildv1beta1.BuildStrategyVolume{ + expected: []buildapi.BuildStrategyVolume{ createBuildStrategyVolume("bvname", "bv description", "ConfigMap", "my-config", true), }, expectErr: false, }, { name: "connot override - not overridable, expecting error", - into: []buildv1beta1.BuildStrategyVolume{ + into: []buildapi.BuildStrategyVolume{ createBuildStrategyVolume("bvname", "bv description", "EmptyDir", "", false), }, - mergers: []buildv1beta1.BuildVolume{ + mergers: []buildapi.BuildVolume{ createBuildVolume("bvname", "ConfigMap", "my-config"), }, - expected: []buildv1beta1.BuildStrategyVolume{ + expected: []buildapi.BuildStrategyVolume{ createBuildStrategyVolume("bvname", "bv description", "ConfigMap", "my-config", true), }, expectErr: true, }, { name: "connot override - volume does not exist, must produce err", - into: []buildv1beta1.BuildStrategyVolume{ + into: []buildapi.BuildStrategyVolume{ createBuildStrategyVolume("bvname", "bv description", "EmptyDir", "", true), }, - mergers: []buildv1beta1.BuildVolume{ + mergers: []buildapi.BuildVolume{ createBuildVolume("bvname2", "ConfigMap", "my-config"), }, - expected: []buildv1beta1.BuildStrategyVolume{ + expected: []buildapi.BuildStrategyVolume{ createBuildStrategyVolume("bvname", "bv description", "EmptyDir", "", true), }, expectErr: true, }, { name: "override second", - into: []buildv1beta1.BuildStrategyVolume{ + into: []buildapi.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: []buildv1beta1.BuildVolume{ + mergers: []buildapi.BuildVolume{ createBuildVolume("bvname2", "Secret", "secret-name"), }, - expected: []buildv1beta1.BuildStrategyVolume{ + expected: []buildapi.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), @@ -197,15 +197,15 @@ func TestMergeVolumes(t *testing.T) { }, { name: "override first", - into: []buildv1beta1.BuildStrategyVolume{ + into: []buildapi.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: []buildv1beta1.BuildVolume{ + mergers: []buildapi.BuildVolume{ createBuildVolume("bvname", "Secret", "secret-name"), }, - expected: []buildv1beta1.BuildStrategyVolume{ + expected: []buildapi.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), @@ -214,15 +214,15 @@ func TestMergeVolumes(t *testing.T) { }, { name: "override third", - into: []buildv1beta1.BuildStrategyVolume{ + into: []buildapi.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: []buildv1beta1.BuildVolume{ + mergers: []buildapi.BuildVolume{ createBuildVolume("bvname3", "EmptyDir", ""), }, - expected: []buildv1beta1.BuildStrategyVolume{ + expected: []buildapi.BuildStrategyVolume{ createBuildStrategyVolume("bvname", "bv description", "EmptyDir", "", true), createBuildStrategyVolume("bvname2", "bv description 2", "ConfigMap", "config-name", false), createBuildStrategyVolume("bvname3", "bv description 3", "EmptyDir", "", true), @@ -231,16 +231,16 @@ func TestMergeVolumes(t *testing.T) { }, { name: "override second and third", - into: []buildv1beta1.BuildStrategyVolume{ + into: []buildapi.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: []buildv1beta1.BuildVolume{ + mergers: []buildapi.BuildVolume{ createBuildVolume("bvname2", "Secret", "very-very-secret"), createBuildVolume("bvname3", "EmptyDir", ""), }, - expected: []buildv1beta1.BuildStrategyVolume{ + expected: []buildapi.BuildStrategyVolume{ createBuildStrategyVolume("bvname", "bv description", "EmptyDir", "", false), createBuildStrategyVolume("bvname2", "bv description 2", "Secret", "very-very-secret", true), createBuildStrategyVolume("bvname3", "bv description 3", "EmptyDir", "", true), @@ -249,15 +249,15 @@ func TestMergeVolumes(t *testing.T) { }, { name: "empty overridable cant be ovirriden", - into: []buildv1beta1.BuildStrategyVolume{ + into: []buildapi.BuildStrategyVolume{ createBuildStrategyVolumeEmptyOverridable("bvname", "desc", "EmptyDir", ""), createBuildStrategyVolume("bvname2", "bv description 2", "ConfigMap", "config-name", true), }, - mergers: []buildv1beta1.BuildVolume{ + mergers: []buildapi.BuildVolume{ createBuildVolume("bvname", "Secret", "very-very-secret"), createBuildVolume("bvname2", "Secret", "very-secret-2"), }, - expected: []buildv1beta1.BuildStrategyVolume{}, + expected: []buildapi.BuildStrategyVolume{}, expectErr: true, }, } @@ -302,8 +302,8 @@ func TestMergeVolumes(t *testing.T) { } } -func toVolMap(expected []buildv1beta1.BuildStrategyVolume) map[string]buildv1beta1.BuildStrategyVolume { - res := make(map[string]buildv1beta1.BuildStrategyVolume) +func toVolMap(expected []buildapi.BuildStrategyVolume) map[string]buildapi.BuildStrategyVolume { + res := make(map[string]buildapi.BuildStrategyVolume) for _, v := range expected { res[v.Name] = v diff --git a/test/e2e/v1beta1/common_cbs_test.go b/test/e2e/v1beta1/common_cbs_test.go index b287a5748b..81f0ae9280 100644 --- a/test/e2e/v1beta1/common_cbs_test.go +++ b/test/e2e/v1beta1/common_cbs_test.go @@ -12,16 +12,16 @@ import ( meta "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/wait" - buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1" ) type clusterBuildStrategyPrototype struct { - clusterBuildStrategy buildv1beta1.ClusterBuildStrategy + clusterBuildStrategy buildapi.ClusterBuildStrategy } func NewClusterBuildStrategyPrototype() *clusterBuildStrategyPrototype { return &clusterBuildStrategyPrototype{ - clusterBuildStrategy: buildv1beta1.ClusterBuildStrategy{}, + clusterBuildStrategy: buildapi.ClusterBuildStrategy{}, } } @@ -30,22 +30,22 @@ func (c *clusterBuildStrategyPrototype) Name(name string) *clusterBuildStrategyP return c } -func (c *clusterBuildStrategyPrototype) BuildStep(buildStep buildv1beta1.Step) *clusterBuildStrategyPrototype { +func (c *clusterBuildStrategyPrototype) BuildStep(buildStep buildapi.Step) *clusterBuildStrategyPrototype { c.clusterBuildStrategy.Spec.Steps = append(c.clusterBuildStrategy.Spec.Steps, buildStep) return c } -func (c *clusterBuildStrategyPrototype) Parameter(parameter buildv1beta1.Parameter) *clusterBuildStrategyPrototype { +func (c *clusterBuildStrategyPrototype) Parameter(parameter buildapi.Parameter) *clusterBuildStrategyPrototype { c.clusterBuildStrategy.Spec.Parameters = append(c.clusterBuildStrategy.Spec.Parameters, parameter) return c } -func (c *clusterBuildStrategyPrototype) Volume(volume buildv1beta1.BuildStrategyVolume) *clusterBuildStrategyPrototype { +func (c *clusterBuildStrategyPrototype) Volume(volume buildapi.BuildStrategyVolume) *clusterBuildStrategyPrototype { c.clusterBuildStrategy.Spec.Volumes = append(c.clusterBuildStrategy.Spec.Volumes, volume) return c } -func (c *clusterBuildStrategyPrototype) Create() (cbs *buildv1beta1.ClusterBuildStrategy, err error) { +func (c *clusterBuildStrategyPrototype) Create() (cbs *buildapi.ClusterBuildStrategy, err error) { ctx := context.Background() _, err = testBuild. @@ -58,7 +58,7 @@ func (c *clusterBuildStrategyPrototype) Create() (cbs *buildv1beta1.ClusterBuild return nil, err } - err = wait.PollImmediate(pollCreateInterval, pollCreateTimeout, func() (done bool, err error) { + err = wait.PollUntilContextTimeout(ctx, pollCreateInterval, pollCreateTimeout, true, func(context.Context) (done bool, err error) { cbs, err = testBuild.BuildClientSet.ShipwrightV1beta1().ClusterBuildStrategies().Get(ctx, c.clusterBuildStrategy.Name, meta.GetOptions{}) if err != nil { return false, err @@ -70,7 +70,7 @@ func (c *clusterBuildStrategyPrototype) Create() (cbs *buildv1beta1.ClusterBuild return } -func (c *clusterBuildStrategyPrototype) TestMe(f func(clusterBuildStrategy *buildv1beta1.ClusterBuildStrategy)) { +func (c *clusterBuildStrategyPrototype) TestMe(f func(clusterBuildStrategy *buildapi.ClusterBuildStrategy)) { cbs, err := c.Create() Expect(err).ToNot(HaveOccurred()) diff --git a/test/e2e/v1beta1/common_suite_test.go b/test/e2e/v1beta1/common_suite_test.go index 494a9818b5..e09df96acc 100644 --- a/test/e2e/v1beta1/common_suite_test.go +++ b/test/e2e/v1beta1/common_suite_test.go @@ -20,7 +20,7 @@ import ( "k8s.io/apimachinery/pkg/util/wait" "k8s.io/utils/pointer" - buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1" ) const ( @@ -28,12 +28,12 @@ const ( pollCreateTimeout = 10 * time.Second ) -type buildPrototype struct{ build buildv1beta1.Build } -type buildRunPrototype struct{ buildRun buildv1beta1.BuildRun } +type buildPrototype struct{ build buildapi.Build } +type buildRunPrototype struct{ buildRun buildapi.BuildRun } func NewBuildPrototype() *buildPrototype { return &buildPrototype{ - build: buildv1beta1.Build{}, + build: buildapi.Build{}, } } @@ -48,8 +48,8 @@ func (b *buildPrototype) Namespace(namespace string) *buildPrototype { } func (b *buildPrototype) BuildStrategy(name string) *buildPrototype { - var bs = buildv1beta1.NamespacedBuildStrategyKind - b.build.Spec.Strategy = buildv1beta1.Strategy{ + var bs = buildapi.NamespacedBuildStrategyKind + b.build.Spec.Strategy = buildapi.Strategy{ Kind: &bs, Name: name, } @@ -57,8 +57,8 @@ func (b *buildPrototype) BuildStrategy(name string) *buildPrototype { } func (b *buildPrototype) ClusterBuildStrategy(name string) *buildPrototype { - var cbs = buildv1beta1.ClusterBuildStrategyKind - b.build.Spec.Strategy = buildv1beta1.Strategy{ + var cbs = buildapi.ClusterBuildStrategyKind + b.build.Spec.Strategy = buildapi.Strategy{ Kind: &cbs, Name: name, } @@ -68,14 +68,14 @@ func (b *buildPrototype) ClusterBuildStrategy(name string) *buildPrototype { func (b *buildPrototype) SourceCredentials(name string) *buildPrototype { if name != "" && b.build.Spec.Source != nil { switch b.build.Spec.Source.Type { - case buildv1beta1.OCIArtifactType: + case buildapi.OCIArtifactType: if b.build.Spec.Source.OCIArtifact == nil { - b.build.Spec.Source.OCIArtifact = &buildv1beta1.OCIArtifact{} + b.build.Spec.Source.OCIArtifact = &buildapi.OCIArtifact{} } b.build.Spec.Source.OCIArtifact.PullSecret = &name - case buildv1beta1.GitType: + case buildapi.GitType: if b.build.Spec.Source.Git == nil { - b.build.Spec.Source.Git = &buildv1beta1.Git{} + b.build.Spec.Source.Git = &buildapi.Git{} } b.build.Spec.Source.Git.CloneSecret = &name } @@ -85,18 +85,18 @@ func (b *buildPrototype) SourceCredentials(name string) *buildPrototype { } func (b *buildPrototype) SourceType(sourceType string) *buildPrototype { - b.build.Spec.Source.Type = buildv1beta1.BuildSourceType(sourceType) + b.build.Spec.Source.Type = buildapi.BuildSourceType(sourceType) return b } func (b *buildPrototype) SourceGit(repository string) *buildPrototype { if b.build.Spec.Source == nil { - b.build.Spec.Source = &buildv1beta1.Source{} + b.build.Spec.Source = &buildapi.Source{} } if b.build.Spec.Source.Git == nil { - b.build.Spec.Source.Git = &buildv1beta1.Git{} + b.build.Spec.Source.Git = &buildapi.Git{} } - b.build.Spec.Source.Type = buildv1beta1.GitType + b.build.Spec.Source.Type = buildapi.GitType b.build.Spec.Source.Git.URL = repository b.build.Spec.Source.OCIArtifact = nil return b @@ -104,7 +104,7 @@ func (b *buildPrototype) SourceGit(repository string) *buildPrototype { func (b *buildPrototype) SourceGitRevision(revision string) *buildPrototype { if b.build.Spec.Source.Git == nil { - b.build.Spec.Source.Git = &buildv1beta1.Git{} + b.build.Spec.Source.Git = &buildapi.Git{} } b.build.Spec.Source.Git.Revision = &revision return b @@ -112,20 +112,20 @@ func (b *buildPrototype) SourceGitRevision(revision string) *buildPrototype { func (b *buildPrototype) SourceBundle(image string) *buildPrototype { if b.build.Spec.Source == nil { - b.build.Spec.Source = &buildv1beta1.Source{} + b.build.Spec.Source = &buildapi.Source{} } if b.build.Spec.Source.OCIArtifact == nil { - b.build.Spec.Source.OCIArtifact = &buildv1beta1.OCIArtifact{} + b.build.Spec.Source.OCIArtifact = &buildapi.OCIArtifact{} } - b.build.Spec.Source.Type = buildv1beta1.OCIArtifactType + b.build.Spec.Source.Type = buildapi.OCIArtifactType b.build.Spec.Source.OCIArtifact.Image = image b.build.Spec.Source.Git = nil return b } -func (b *buildPrototype) SourceBundlePrune(prune buildv1beta1.PruneOption) *buildPrototype { +func (b *buildPrototype) SourceBundlePrune(prune buildapi.PruneOption) *buildPrototype { if b.build.Spec.Source.OCIArtifact == nil { - b.build.Spec.Source.OCIArtifact = &buildv1beta1.OCIArtifact{} + b.build.Spec.Source.OCIArtifact = &buildapi.OCIArtifact{} } b.build.Spec.Source.OCIArtifact.Prune = &prune return b @@ -139,9 +139,9 @@ func (b *buildPrototype) SourceContextDir(contextDir string) *buildPrototype { func (b *buildPrototype) Dockerfile(dockerfile string) *buildPrototype { b.build.Spec.ParamValues = append( b.build.Spec.ParamValues, - buildv1beta1.ParamValue{ + buildapi.ParamValue{ Name: "dockerfile", - SingleValue: &buildv1beta1.SingleValue{ + SingleValue: &buildapi.SingleValue{ Value: &dockerfile, }, }, @@ -154,7 +154,7 @@ func (b *buildPrototype) OutputImage(image string) *buildPrototype { return b } -func (b *buildPrototype) OutputVulnerabilitySettings(settings buildv1beta1.VulnerabilityScanOptions) *buildPrototype { +func (b *buildPrototype) OutputVulnerabilitySettings(settings buildapi.VulnerabilityScanOptions) *buildPrototype { b.build.Spec.Output.VulnerabilityScan = &settings return b } @@ -170,7 +170,7 @@ func (b *buildPrototype) determineParameterIndex(name string) int { if index == -1 { index = len(b.build.Spec.ParamValues) - b.build.Spec.ParamValues = append(b.build.Spec.ParamValues, buildv1beta1.ParamValue{ + b.build.Spec.ParamValues = append(b.build.Spec.ParamValues, buildapi.ParamValue{ Name: name, }) } @@ -181,7 +181,7 @@ func (b *buildPrototype) determineParameterIndex(name string) int { // ArrayParamValue adds an item to an array parameter, if the parameter is not yet present, it is being added func (b *buildPrototype) ArrayParamValue(name string, value string) *buildPrototype { index := b.determineParameterIndex(name) - b.build.Spec.ParamValues[index].Values = append(b.build.Spec.ParamValues[index].Values, buildv1beta1.SingleValue{ + b.build.Spec.ParamValues[index].Values = append(b.build.Spec.ParamValues[index].Values, buildapi.SingleValue{ Value: &value, }) @@ -191,8 +191,8 @@ func (b *buildPrototype) ArrayParamValue(name string, value string) *buildProtot // ArrayParamValueFromConfigMap adds an item to an array parameter, if the parameter is not yet present, it is being added func (b *buildPrototype) ArrayParamValueFromConfigMap(name string, configMapName string, configMapKey string, format *string) *buildPrototype { index := b.determineParameterIndex(name) - b.build.Spec.ParamValues[index].Values = append(b.build.Spec.ParamValues[index].Values, buildv1beta1.SingleValue{ - ConfigMapValue: &buildv1beta1.ObjectKeyRef{ + b.build.Spec.ParamValues[index].Values = append(b.build.Spec.ParamValues[index].Values, buildapi.SingleValue{ + ConfigMapValue: &buildapi.ObjectKeyRef{ Name: configMapName, Key: configMapKey, Format: format, @@ -205,8 +205,8 @@ func (b *buildPrototype) ArrayParamValueFromConfigMap(name string, configMapName // ArrayParamValueFromSecret adds an item to an array parameter, if the parameter is not yet present, it is being added func (b *buildPrototype) ArrayParamValueFromSecret(name string, secretName string, secretKey string, format *string) *buildPrototype { index := b.determineParameterIndex(name) - b.build.Spec.ParamValues[index].Values = append(b.build.Spec.ParamValues[index].Values, buildv1beta1.SingleValue{ - SecretValue: &buildv1beta1.ObjectKeyRef{ + b.build.Spec.ParamValues[index].Values = append(b.build.Spec.ParamValues[index].Values, buildapi.SingleValue{ + SecretValue: &buildapi.ObjectKeyRef{ Name: secretName, Key: secretKey, Format: format, @@ -217,9 +217,9 @@ func (b *buildPrototype) ArrayParamValueFromSecret(name string, secretName strin } func (b *buildPrototype) StringParamValue(name string, value string) *buildPrototype { - b.build.Spec.ParamValues = append(b.build.Spec.ParamValues, buildv1beta1.ParamValue{ + b.build.Spec.ParamValues = append(b.build.Spec.ParamValues, buildapi.ParamValue{ Name: name, - SingleValue: &buildv1beta1.SingleValue{ + SingleValue: &buildapi.SingleValue{ Value: &value, }, }) @@ -228,10 +228,10 @@ func (b *buildPrototype) StringParamValue(name string, value string) *buildProto } func (b *buildPrototype) StringParamValueFromConfigMap(name string, configMapName string, configMapKey string, format *string) *buildPrototype { - b.build.Spec.ParamValues = append(b.build.Spec.ParamValues, buildv1beta1.ParamValue{ + b.build.Spec.ParamValues = append(b.build.Spec.ParamValues, buildapi.ParamValue{ Name: name, - SingleValue: &buildv1beta1.SingleValue{ - ConfigMapValue: &buildv1beta1.ObjectKeyRef{ + SingleValue: &buildapi.SingleValue{ + ConfigMapValue: &buildapi.ObjectKeyRef{ Name: configMapName, Key: configMapKey, Format: format, @@ -243,10 +243,10 @@ func (b *buildPrototype) StringParamValueFromConfigMap(name string, configMapNam } func (b *buildPrototype) StringParamValueFromSecret(name string, secretName string, secretKey string, format *string) *buildPrototype { - b.build.Spec.ParamValues = append(b.build.Spec.ParamValues, buildv1beta1.ParamValue{ + b.build.Spec.ParamValues = append(b.build.Spec.ParamValues, buildapi.ParamValue{ Name: name, - SingleValue: &buildv1beta1.SingleValue{ - SecretValue: &buildv1beta1.ObjectKeyRef{ + SingleValue: &buildapi.SingleValue{ + SecretValue: &buildapi.ObjectKeyRef{ Name: secretName, Key: secretKey, Format: format, @@ -275,7 +275,7 @@ func (b *buildPrototype) OutputTimestamp(timestampString string) *buildPrototype return b } -func (b buildPrototype) Create() (build *buildv1beta1.Build, err error) { +func (b buildPrototype) Create() (build *buildapi.Build, err error) { ctx := context.Background() _, err = testBuild. @@ -301,12 +301,12 @@ func (b buildPrototype) Create() (build *buildv1beta1.Build, err error) { } // BuildSpec returns the BuildSpec of this Build (no cluster resource is created) -func (b buildPrototype) BuildSpec() (build *buildv1beta1.BuildSpec) { +func (b buildPrototype) BuildSpec() (build *buildapi.BuildSpec) { return &b.build.Spec } func NewBuildRunPrototype() *buildRunPrototype { - return &buildRunPrototype{buildRun: buildv1beta1.BuildRun{}} + return &buildRunPrototype{buildRun: buildapi.BuildRun{}} } func (b *buildRunPrototype) Name(name string) *buildRunPrototype { @@ -319,13 +319,13 @@ func (b *buildRunPrototype) Namespace(namespace string) *buildRunPrototype { return b } -func (b *buildRunPrototype) ForBuild(build *buildv1beta1.Build) *buildRunPrototype { +func (b *buildRunPrototype) ForBuild(build *buildapi.Build) *buildRunPrototype { b.buildRun.Spec.Build.Name = &build.Name b.buildRun.ObjectMeta.Namespace = build.Namespace return b } -func (b *buildRunPrototype) WithBuildSpec(buildSpec *buildv1beta1.BuildSpec) *buildRunPrototype { +func (b *buildRunPrototype) WithBuildSpec(buildSpec *buildapi.BuildSpec) *buildRunPrototype { b.buildRun.Spec.Build.Spec = buildSpec return b } @@ -349,7 +349,7 @@ func (b *buildRunPrototype) determineParameterIndex(name string) int { if index == -1 { index = len(b.buildRun.Spec.ParamValues) - b.buildRun.Spec.ParamValues = append(b.buildRun.Spec.ParamValues, buildv1beta1.ParamValue{ + b.buildRun.Spec.ParamValues = append(b.buildRun.Spec.ParamValues, buildapi.ParamValue{ Name: name, }) } @@ -360,7 +360,7 @@ func (b *buildRunPrototype) determineParameterIndex(name string) int { // ArrayParamValue adds an item to an array parameter, if the parameter is not yet present, it is being added func (b *buildRunPrototype) ArrayParamValue(name string, value string) *buildRunPrototype { index := b.determineParameterIndex(name) - b.buildRun.Spec.ParamValues[index].Values = append(b.buildRun.Spec.ParamValues[index].Values, buildv1beta1.SingleValue{ + b.buildRun.Spec.ParamValues[index].Values = append(b.buildRun.Spec.ParamValues[index].Values, buildapi.SingleValue{ Value: &value, }) @@ -370,8 +370,8 @@ func (b *buildRunPrototype) ArrayParamValue(name string, value string) *buildRun // ArrayParamValueFromConfigMap adds an item to an array parameter, if the parameter is not yet present, it is being added func (b *buildRunPrototype) ArrayParamValueFromConfigMap(name string, configMapName string, configMapKey string, format *string) *buildRunPrototype { index := b.determineParameterIndex(name) - b.buildRun.Spec.ParamValues[index].Values = append(b.buildRun.Spec.ParamValues[index].Values, buildv1beta1.SingleValue{ - ConfigMapValue: &buildv1beta1.ObjectKeyRef{ + b.buildRun.Spec.ParamValues[index].Values = append(b.buildRun.Spec.ParamValues[index].Values, buildapi.SingleValue{ + ConfigMapValue: &buildapi.ObjectKeyRef{ Name: configMapName, Key: configMapKey, Format: format, @@ -384,8 +384,8 @@ func (b *buildRunPrototype) ArrayParamValueFromConfigMap(name string, configMapN // ArrayParamValueFromSecret adds an item to an array parameter, if the parameter is not yet present, it is being added func (b *buildRunPrototype) ArrayParamValueFromSecret(name string, secretName string, secretKey string, format *string) *buildRunPrototype { index := b.determineParameterIndex(name) - b.buildRun.Spec.ParamValues[index].Values = append(b.buildRun.Spec.ParamValues[index].Values, buildv1beta1.SingleValue{ - SecretValue: &buildv1beta1.ObjectKeyRef{ + b.buildRun.Spec.ParamValues[index].Values = append(b.buildRun.Spec.ParamValues[index].Values, buildapi.SingleValue{ + SecretValue: &buildapi.ObjectKeyRef{ Name: secretName, Key: secretKey, Format: format, @@ -396,9 +396,9 @@ func (b *buildRunPrototype) ArrayParamValueFromSecret(name string, secretName st } func (b *buildRunPrototype) StringParamValue(name string, value string) *buildRunPrototype { - b.buildRun.Spec.ParamValues = append(b.buildRun.Spec.ParamValues, buildv1beta1.ParamValue{ + b.buildRun.Spec.ParamValues = append(b.buildRun.Spec.ParamValues, buildapi.ParamValue{ Name: name, - SingleValue: &buildv1beta1.SingleValue{ + SingleValue: &buildapi.SingleValue{ Value: &value, }, }) @@ -407,10 +407,10 @@ func (b *buildRunPrototype) StringParamValue(name string, value string) *buildRu } func (b *buildRunPrototype) StringParamValueFromConfigMap(name string, configMapName string, configMapKey string, format *string) *buildRunPrototype { - b.buildRun.Spec.ParamValues = append(b.buildRun.Spec.ParamValues, buildv1beta1.ParamValue{ + b.buildRun.Spec.ParamValues = append(b.buildRun.Spec.ParamValues, buildapi.ParamValue{ Name: name, - SingleValue: &buildv1beta1.SingleValue{ - ConfigMapValue: &buildv1beta1.ObjectKeyRef{ + SingleValue: &buildapi.SingleValue{ + ConfigMapValue: &buildapi.ObjectKeyRef{ Name: configMapName, Key: configMapKey, Format: format, @@ -422,10 +422,10 @@ func (b *buildRunPrototype) StringParamValueFromConfigMap(name string, configMap } func (b *buildRunPrototype) StringParamValueFromSecret(name string, secretName string, secretKey string, format *string) *buildRunPrototype { - b.buildRun.Spec.ParamValues = append(b.buildRun.Spec.ParamValues, buildv1beta1.ParamValue{ + b.buildRun.Spec.ParamValues = append(b.buildRun.Spec.ParamValues, buildapi.ParamValue{ Name: name, - SingleValue: &buildv1beta1.SingleValue{ - SecretValue: &buildv1beta1.ObjectKeyRef{ + SingleValue: &buildapi.SingleValue{ + SecretValue: &buildapi.ObjectKeyRef{ Name: secretName, Key: secretKey, Format: format, @@ -436,7 +436,7 @@ func (b *buildRunPrototype) StringParamValueFromSecret(name string, secretName s return b } -func (b *buildRunPrototype) Create() (*buildv1beta1.BuildRun, error) { +func (b *buildRunPrototype) Create() (*buildapi.BuildRun, error) { return testBuild. BuildClientSet. ShipwrightV1beta1(). @@ -444,7 +444,7 @@ func (b *buildRunPrototype) Create() (*buildv1beta1.BuildRun, error) { Create(context.Background(), &b.buildRun, meta.CreateOptions{}) } -func (b *buildRunPrototype) MustCreate() *buildv1beta1.BuildRun { +func (b *buildRunPrototype) MustCreate() *buildapi.BuildRun { GinkgoHelper() buildrun, err := b.Create() diff --git a/test/e2e/v1beta1/common_test.go b/test/e2e/v1beta1/common_test.go index 494ec221d5..7ffffed896 100644 --- a/test/e2e/v1beta1/common_test.go +++ b/test/e2e/v1beta1/common_test.go @@ -23,7 +23,7 @@ import ( "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/rand" - buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "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" ) @@ -36,7 +36,7 @@ func removeTestIDSuffix(id string) string { return id[:len(id)-6] } -func createBuild(testBuild *utils.TestBuild, identifier string, filePath string) *buildv1beta1.Build { +func createBuild(testBuild *utils.TestBuild, identifier string, filePath string) *buildapi.Build { build, err := buildTestData(testBuild.Namespace, identifier, filePath) Expect(err).ToNot(HaveOccurred(), "Error retrieving build test data") @@ -45,7 +45,7 @@ func createBuild(testBuild *utils.TestBuild, identifier string, filePath string) // For Builds that use a namespaces build strategy, there is a race condition: we just created the // build strategy and it might be that the build controller does not yet have this in his cache // and therefore marks the build as not registered with reason BuildStrategyNotFound - Eventually(func() buildv1beta1.BuildReason { + Eventually(func() buildapi.BuildReason { // cleanup the build of the previous try if build.Status.Registered != nil && *build.Status.Registered != "" { err = testBuild.DeleteBuild(build.Name) @@ -66,13 +66,13 @@ func createBuild(testBuild *utils.TestBuild, identifier string, filePath string) Expect(err).ToNot(HaveOccurred()) return *build.Status.Reason - }, time.Duration(10*time.Second), time.Second).Should(Equal(buildv1beta1.SucceedStatus)) + }, time.Duration(10*time.Second), time.Second).Should(Equal(buildapi.SucceedStatus)) return build } // amendOutputImage amend container image URL based on informed image repository. -func amendOutputImage(b *buildv1beta1.Build, imageRepo string, insecure bool) { +func amendOutputImage(b *buildapi.Build, imageRepo string, insecure bool) { if imageRepo == "" { return } @@ -88,7 +88,7 @@ func amendOutputImage(b *buildv1beta1.Build, imageRepo string, insecure bool) { } // amendOutputCredentials amend secret-ref for output image. -func amendOutputCredentials(b *buildv1beta1.Build, secretName string) { +func amendOutputCredentials(b *buildapi.Build, secretName string) { if secretName == "" { return } @@ -97,7 +97,7 @@ func amendOutputCredentials(b *buildv1beta1.Build, secretName string) { } // amendSourceSecretName patch Build source.Git.CloneSecret with secret name. -func amendSourceSecretName(b *buildv1beta1.Build, secretName string) { +func amendSourceSecretName(b *buildapi.Build, secretName string) { if secretName == "" { return } @@ -105,7 +105,7 @@ func amendSourceSecretName(b *buildv1beta1.Build, secretName string) { } // amendSourceURL patch Build source.Git.URL with informed string. -func amendSourceURL(b *buildv1beta1.Build, sourceURL string) { +func amendSourceURL(b *buildapi.Build, sourceURL string) { if sourceURL == "" { return } @@ -113,7 +113,7 @@ func amendSourceURL(b *buildv1beta1.Build, sourceURL string) { } // amendBuild make changes on build object. -func amendBuild(identifier string, b *buildv1beta1.Build) { +func amendBuild(identifier string, b *buildapi.Build) { if strings.Contains(identifier, "github") { amendSourceSecretName(b, os.Getenv(EnvVarSourceURLSecret)) amendSourceURL(b, os.Getenv(EnvVarSourceURLGithub)) @@ -135,8 +135,8 @@ func amendBuild(identifier string, b *buildv1beta1.Build) { } // retrieveBuildAndBuildRun will retrieve the build and buildRun -func retrieveBuildAndBuildRun(testBuild *utils.TestBuild, namespace string, buildRunName string) (*buildv1beta1.Build, *buildv1beta1.BuildRun, error) { - var build *buildv1beta1.Build +func retrieveBuildAndBuildRun(testBuild *utils.TestBuild, namespace string, buildRunName string) (*buildapi.Build, *buildapi.BuildRun, error) { + var build *buildapi.Build buildrun, err := testBuild.LookupBuildRun(types.NamespacedName{Name: buildRunName, Namespace: namespace}) if err != nil { @@ -169,7 +169,7 @@ func printTestFailureDebugInfo(testBuild *utils.TestBuild, namespace string, bui } if buildRun != nil { - brCondition := buildRun.Status.GetCondition(buildv1beta1.Succeeded) + brCondition := buildRun.Status.GetCondition(buildapi.Succeeded) if brCondition != nil { Logf("The status of BuildRun %s: status=%s, reason=%s", buildRun.Name, brCondition.Status, brCondition.Reason) } @@ -206,7 +206,7 @@ func printTestFailureDebugInfo(testBuild *utils.TestBuild, namespace string, bui } else { podList, err := testBuild.Clientset.CoreV1().Pods(namespace).List(testBuild.Context, metav1.ListOptions{ LabelSelector: labels.FormatLabels(map[string]string{ - buildv1beta1.LabelBuildRun: buildRunName, + buildapi.LabelBuildRun: buildRunName, }), }) diff --git a/test/e2e/v1beta1/e2e_image_mutate_test.go b/test/e2e/v1beta1/e2e_image_mutate_test.go index 8a36253c94..a3e494913c 100644 --- a/test/e2e/v1beta1/e2e_image_mutate_test.go +++ b/test/e2e/v1beta1/e2e_image_mutate_test.go @@ -16,15 +16,15 @@ import ( "github.com/google/go-containerregistry/pkg/name" containerreg "github.com/google/go-containerregistry/pkg/v1" - buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1" ) var _ = Describe("For a Kubernetes cluster with Tekton and build installed", func() { var ( err error testID string - build *buildv1beta1.Build - buildRun *buildv1beta1.BuildRun + build *buildapi.Build + buildRun *buildapi.BuildRun ) annotationsOf := func(img containerreg.Image) map[string]string { @@ -120,7 +120,7 @@ var _ = Describe("For a Kubernetes cluster with Tekton and build installed", fun }) Context("when using BuildKit based Dockerfile build", func() { - var sampleBuildRun = func(outputTimestamp string) *buildv1beta1.BuildRun { + var sampleBuildRun = func(outputTimestamp string) *buildapi.BuildRun { return NewBuildRunPrototype(). Namespace(testBuild.Namespace). Name(testID). @@ -141,19 +141,19 @@ var _ = Describe("For a Kubernetes cluster with Tekton and build installed", fun } It("should create an image with creation timestamp set to unix epoch timestamp zero", func() { - buildRun := validateBuildRunToSucceed(testBuild, sampleBuildRun(buildv1beta1.OutputImageZeroTimestamp)) + buildRun := validateBuildRunToSucceed(testBuild, sampleBuildRun(buildapi.OutputImageZeroTimestamp)) image := testBuild.GetImage(buildRun) Expect(creationTimeOf(image)).To(BeTemporally("==", time.Unix(0, 0))) }) It("should create an image with creation timestamp set to the source timestamp", func() { - buildRun := validateBuildRunToSucceed(testBuild, sampleBuildRun(buildv1beta1.OutputImageSourceTimestamp)) + buildRun := validateBuildRunToSucceed(testBuild, sampleBuildRun(buildapi.OutputImageSourceTimestamp)) image := testBuild.GetImage(buildRun) Expect(creationTimeOf(image)).To(BeTemporally("==", time.Unix(1699261787, 0))) }) It("should create an image with creation timestamp set to the build timestamp", func() { - buildRun := validateBuildRunToSucceed(testBuild, sampleBuildRun(buildv1beta1.OutputImageBuildTimestamp)) + buildRun := validateBuildRunToSucceed(testBuild, sampleBuildRun(buildapi.OutputImageBuildTimestamp)) image := testBuild.GetImage(buildRun) Expect(creationTimeOf(image)).To(BeTemporally("==", buildRun.CreationTimestamp.Time)) }) @@ -166,7 +166,7 @@ var _ = Describe("For a Kubernetes cluster with Tekton and build installed", fun }) Context("when using Buildpacks build", func() { - var sampleBuildRun = func(outputTimestamp string) *buildv1beta1.BuildRun { + var sampleBuildRun = func(outputTimestamp string) *buildapi.BuildRun { return NewBuildRunPrototype(). Namespace(testBuild.Namespace). Name(testID). @@ -186,19 +186,19 @@ var _ = Describe("For a Kubernetes cluster with Tekton and build installed", fun } It("should create an image with creation timestamp set to unix epoch timestamp zero", func() { - buildRun := validateBuildRunToSucceed(testBuild, sampleBuildRun(buildv1beta1.OutputImageZeroTimestamp)) + buildRun := validateBuildRunToSucceed(testBuild, sampleBuildRun(buildapi.OutputImageZeroTimestamp)) image := testBuild.GetImage(buildRun) Expect(creationTimeOf(image)).To(BeTemporally("==", time.Unix(0, 0))) }) It("should create an image with creation timestamp set to the source timestamp", func() { - buildRun := validateBuildRunToSucceed(testBuild, sampleBuildRun(buildv1beta1.OutputImageSourceTimestamp)) + buildRun := validateBuildRunToSucceed(testBuild, sampleBuildRun(buildapi.OutputImageSourceTimestamp)) image := testBuild.GetImage(buildRun) Expect(creationTimeOf(image)).To(BeTemporally("==", time.Unix(1699261787, 0))) }) It("should create an image with creation timestamp set to the build timestamp", func() { - buildRun := validateBuildRunToSucceed(testBuild, sampleBuildRun(buildv1beta1.OutputImageBuildTimestamp)) + buildRun := validateBuildRunToSucceed(testBuild, sampleBuildRun(buildapi.OutputImageBuildTimestamp)) image := testBuild.GetImage(buildRun) Expect(creationTimeOf(image)).To(BeTemporally("==", buildRun.CreationTimestamp.Time)) }) @@ -222,7 +222,7 @@ var _ = Describe("For a Kubernetes cluster with Tekton and build installed", fun OutputImage(outputImage.String()). OutputImageCredentials(os.Getenv(EnvVarImageRepoSecret)). OutputImageInsecure(insecure). - OutputTimestamp(buildv1beta1.OutputImageSourceTimestamp). + OutputTimestamp(buildapi.OutputImageSourceTimestamp). BuildSpec()). MustCreate() @@ -231,7 +231,7 @@ var _ = Describe("For a Kubernetes cluster with Tekton and build installed", fun buildRun, err = testBuild.GetBRTillCompletion(buildRun.Name) Expect(err).ToNot(HaveOccurred()) - condition := buildRun.Status.GetCondition(buildv1beta1.Succeeded) + condition := buildRun.Status.GetCondition(buildapi.Succeeded) Expect(condition).ToNot(BeNil()) Expect(condition.Reason).To(ContainSubstring("TaskRunGenerationFailed")) Expect(condition.Message).To(ContainSubstring("cannot use SourceTimestamp setting")) @@ -261,7 +261,7 @@ var _ = Describe("For a Kubernetes cluster with Tekton and build installed", fun buildRun, err = testBuild.GetBRTillCompletion(buildRun.Name) Expect(err).ToNot(HaveOccurred()) - condition := buildRun.Status.GetCondition(buildv1beta1.Succeeded) + condition := buildRun.Status.GetCondition(buildapi.Succeeded) Expect(condition).ToNot(BeNil()) Expect(condition.Reason).To(ContainSubstring("Failed")) Expect(condition.Message).To(ContainSubstring("cannot parse output timestamp")) diff --git a/test/e2e/v1beta1/e2e_local_source_upload_test.go b/test/e2e/v1beta1/e2e_local_source_upload_test.go index d57177dc38..c5fe377736 100644 --- a/test/e2e/v1beta1/e2e_local_source_upload_test.go +++ b/test/e2e/v1beta1/e2e_local_source_upload_test.go @@ -12,15 +12,15 @@ import ( "k8s.io/apimachinery/pkg/types" - buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1" utils "github.com/shipwright-io/build/test/utils/v1beta1" ) var _ = Describe("For a Kubernetes cluster with Tekton and build installed", func() { var ( testID string - build *buildv1beta1.Build - buildRun *buildv1beta1.BuildRun + build *buildapi.Build + buildRun *buildapi.BuildRun ) AfterEach(func() { @@ -59,19 +59,19 @@ var _ = Describe("For a Kubernetes cluster with Tekton and build installed", fun }) }) -func getBuildRunStatusCondition(name types.NamespacedName) *buildv1beta1.Condition { +func getBuildRunStatusCondition(name types.NamespacedName) *buildapi.Condition { testBuildRun, err := testBuild.LookupBuildRun(name) Expect(err).ToNot(HaveOccurred(), "Error retrieving the BuildRun") if len(testBuildRun.Status.Conditions) == 0 { return nil } - return testBuildRun.Status.GetCondition(buildv1beta1.Succeeded) + return testBuildRun.Status.GetCondition(buildapi.Succeeded) } // validateWaiterBuildRun assert the BuildRun informed will fail, since Waiter's timeout is reached // and it causes the actual build process to fail as well. -func validateWaiterBuildRun(testBuild *utils.TestBuild, testBuildRun *buildv1beta1.BuildRun) { +func validateWaiterBuildRun(testBuild *utils.TestBuild, testBuildRun *buildapi.BuildRun) { err := testBuild.CreateBR(testBuildRun) Expect(err).ToNot(HaveOccurred(), "Failed to create BuildRun") diff --git a/test/e2e/v1beta1/e2e_ociartifact_test.go b/test/e2e/v1beta1/e2e_ociartifact_test.go index c3dd381c96..af08eb09f3 100644 --- a/test/e2e/v1beta1/e2e_ociartifact_test.go +++ b/test/e2e/v1beta1/e2e_ociartifact_test.go @@ -20,7 +20,7 @@ import ( "github.com/google/go-containerregistry/pkg/v1/remote" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1" ) var _ = Describe("Test local source code (bundle) functionality", func() { @@ -37,8 +37,8 @@ var _ = Describe("Test local source code (bundle) functionality", func() { testID string err error - build *buildv1beta1.Build - buildRun *buildv1beta1.BuildRun + build *buildapi.Build + buildRun *buildapi.BuildRun ) AfterEach(func() { @@ -245,7 +245,7 @@ var _ = Describe("Test local source code (bundle) functionality", func() { Name(testID). Namespace(testBuild.Namespace). SourceBundle(tmpImage). - SourceBundlePrune(buildv1beta1.PruneAfterPull). + SourceBundlePrune(buildapi.PruneAfterPull). SourceCredentials(secretName). SourceContextDir("docker-build"). Dockerfile("Dockerfile"). diff --git a/test/e2e/v1beta1/e2e_one_off_builds_test.go b/test/e2e/v1beta1/e2e_one_off_builds_test.go index fc85ca21c8..4539909933 100644 --- a/test/e2e/v1beta1/e2e_one_off_builds_test.go +++ b/test/e2e/v1beta1/e2e_one_off_builds_test.go @@ -13,7 +13,7 @@ import ( . "github.com/onsi/gomega" "github.com/google/go-containerregistry/pkg/name" - buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1" ) var _ = Describe("Using One-Off Builds", func() { @@ -30,7 +30,7 @@ var _ = Describe("Using One-Off Builds", func() { testID string err error - buildRun *buildv1beta1.BuildRun + buildRun *buildapi.BuildRun ) AfterEach(func() { diff --git a/test/e2e/v1beta1/e2e_params_test.go b/test/e2e/v1beta1/e2e_params_test.go index a4ed64b2d5..d544ac6734 100644 --- a/test/e2e/v1beta1/e2e_params_test.go +++ b/test/e2e/v1beta1/e2e_params_test.go @@ -8,7 +8,7 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1" test "github.com/shipwright-io/build/test/v1beta1_samples" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/types" @@ -20,9 +20,9 @@ var _ = Describe("For a Kubernetes cluster with Tekton and build installed", fun testID string err error - build *buildv1beta1.Build - buildRun *buildv1beta1.BuildRun - buildStrategy *buildv1beta1.BuildStrategy + build *buildapi.Build + buildRun *buildapi.BuildRun + buildStrategy *buildapi.BuildStrategy configMap *corev1.ConfigMap secret *corev1.Secret ) diff --git a/test/e2e/v1beta1/e2e_test.go b/test/e2e/v1beta1/e2e_test.go index 0ca8f59e26..0ea6a92598 100644 --- a/test/e2e/v1beta1/e2e_test.go +++ b/test/e2e/v1beta1/e2e_test.go @@ -13,7 +13,7 @@ import ( "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/types" - buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1" shpgit "github.com/shipwright-io/build/pkg/git" ) @@ -22,8 +22,8 @@ var _ = Describe("For a Kubernetes cluster with Tekton and build installed", fun testID string err error - build *buildv1beta1.Build - buildRun *buildv1beta1.BuildRun + build *buildapi.Build + buildRun *buildapi.BuildRun ) AfterEach(func() { @@ -139,7 +139,7 @@ var _ = Describe("For a Kubernetes cluster with Tekton and build installed", fun }) Context("when a heroku Buildpacks build is defined using a namespaced strategy", func() { - var buildStrategy *buildv1beta1.BuildStrategy + var buildStrategy *buildapi.BuildStrategy BeforeEach(func() { testID = generateTestID("buildpacks-v3-heroku-namespaced") @@ -197,7 +197,7 @@ var _ = Describe("For a Kubernetes cluster with Tekton and build installed", fun }) Context("when a Buildpacks v3 build is defined using a namespaced strategy", func() { - var buildStrategy *buildv1beta1.BuildStrategy + var buildStrategy *buildapi.BuildStrategy BeforeEach(func() { testID = generateTestID("buildpacks-v3-namespaced") diff --git a/test/e2e/v1beta1/e2e_vulnerability_scanning_test.go b/test/e2e/v1beta1/e2e_vulnerability_scanning_test.go index 14d75c7067..cbedf358ad 100644 --- a/test/e2e/v1beta1/e2e_vulnerability_scanning_test.go +++ b/test/e2e/v1beta1/e2e_vulnerability_scanning_test.go @@ -15,13 +15,13 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/utils/pointer" - buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1" ) var _ = Describe("Vulnerability Scanning", func() { var testID string var err error - var buildRun *buildv1beta1.BuildRun + var buildRun *buildapi.BuildRun var cbs *clusterBuildStrategyPrototype var insecure bool @@ -44,7 +44,7 @@ var _ = Describe("Vulnerability Scanning", func() { insecure = strings.Contains(outputImage, "cluster.local") cbs = NewClusterBuildStrategyPrototype(). Name("crane-pull-" + testID). - BuildStep(buildv1beta1.Step{ + BuildStep(buildapi.Step{ Name: "crane-pull", Image: "gcr.io/go-containerregistry/crane:latest", WorkingDir: "$(params.shp-source-root)", @@ -67,7 +67,7 @@ var _ = Describe("Vulnerability Scanning", func() { }) It("should find vulnerabilities in an image", func() { - cbs.TestMe(func(cbs *buildv1beta1.ClusterBuildStrategy) { + cbs.TestMe(func(cbs *buildapi.ClusterBuildStrategy) { unfixed := true ignoreSeverity := "LOW" buildRun, err = NewBuildRunPrototype(). @@ -80,10 +80,10 @@ var _ = Describe("Vulnerability Scanning", func() { OutputImage(outputImage). OutputImageCredentials(os.Getenv(EnvVarImageRepoSecret)). OutputImageInsecure(insecure). - OutputVulnerabilitySettings(buildv1beta1.VulnerabilityScanOptions{ + OutputVulnerabilitySettings(buildapi.VulnerabilityScanOptions{ Enabled: true, Fail: true, - Ignore: &buildv1beta1.VulnerabilityIgnoreOptions{ + Ignore: &buildapi.VulnerabilityIgnoreOptions{ Issues: []string{"CVE-2021-3807", "CVE-2022-33987"}, Severity: &ignoreSeverity, Unfixed: &unfixed, diff --git a/test/e2e/v1beta1/validators_test.go b/test/e2e/v1beta1/validators_test.go index 3e1c17c737..ccc9ce5b2b 100644 --- a/test/e2e/v1beta1/validators_test.go +++ b/test/e2e/v1beta1/validators_test.go @@ -22,7 +22,7 @@ import ( "k8s.io/kubectl/pkg/scheme" "github.com/shipwright-io/build/pkg/apis" - buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1" utils "github.com/shipwright-io/build/test/utils/v1beta1" ) @@ -111,7 +111,7 @@ func createContainerRegistrySecret(testBuild *utils.TestBuild) { } // validateBuildRunToSucceed creates the build run and watches its flow until it succeeds. -func validateBuildRunToSucceed(testBuild *utils.TestBuild, testBuildRun *buildv1beta1.BuildRun) *buildv1beta1.BuildRun { +func validateBuildRunToSucceed(testBuild *utils.TestBuild, testBuildRun *buildapi.BuildRun) *buildapi.BuildRun { trueCondition := corev1.ConditionTrue falseCondition := corev1.ConditionFalse @@ -127,11 +127,11 @@ func validateBuildRunToSucceed(testBuild *utils.TestBuild, testBuildRun *buildv1 testBuildRun, err := testBuild.LookupBuildRun(types.NamespacedName{Name: testBuildRun.Name, Namespace: testBuild.Namespace}) Expect(err).ToNot(HaveOccurred(), "Error retrieving a buildRun") - if testBuildRun.Status.GetCondition(buildv1beta1.Succeeded) == nil { + if testBuildRun.Status.GetCondition(buildapi.Succeeded) == nil { return corev1.ConditionUnknown } - Expect(testBuildRun.Status.GetCondition(buildv1beta1.Succeeded).Status).ToNot(Equal(falseCondition), "BuildRun status doesn't move to Succeeded") + Expect(testBuildRun.Status.GetCondition(buildapi.Succeeded).Status).ToNot(Equal(falseCondition), "BuildRun status doesn't move to Succeeded") now := time.Now() if now.After(nextStatusLog) { @@ -139,7 +139,7 @@ func validateBuildRunToSucceed(testBuild *utils.TestBuild, testBuildRun *buildv1 nextStatusLog = time.Now().Add(60 * time.Second) } - return testBuildRun.Status.GetCondition(buildv1beta1.Succeeded).Status + return testBuildRun.Status.GetCondition(buildapi.Succeeded).Status }, time.Duration(1100*getTimeoutMultiplier())*time.Second, 5*time.Second).Should(Equal(trueCondition), "BuildRun did not succeed") @@ -153,7 +153,7 @@ func validateBuildRunToSucceed(testBuild *utils.TestBuild, testBuildRun *buildv1 return testBuildRun } -func validateBuildRunResultsFromGitSource(testBuildRun *buildv1beta1.BuildRun) { +func validateBuildRunResultsFromGitSource(testBuildRun *buildapi.BuildRun) { testBuildRun, err := testBuild.GetBR(testBuildRun.Name) Expect(err).ToNot(HaveOccurred()) @@ -186,7 +186,7 @@ func validateBuildRunResultsFromGitSource(testBuildRun *buildv1beta1.BuildRun) { } } -func validateBuildRunResultsFromBundleSource(testBuildRun *buildv1beta1.BuildRun) { +func validateBuildRunResultsFromBundleSource(testBuildRun *buildapi.BuildRun) { testBuildRun, err := testBuild.GetBR(testBuildRun.Name) Expect(err).ToNot(HaveOccurred()) @@ -213,7 +213,7 @@ func validateBuildRunResultsFromBundleSource(testBuildRun *buildv1beta1.BuildRun } // validateBuildRunToFail creates the build run and watches its flow until it fails. -func validateBuildRunToFail(testBuild *utils.TestBuild, testBuildRun *buildv1beta1.BuildRun) { +func validateBuildRunToFail(testBuild *utils.TestBuild, testBuildRun *buildapi.BuildRun) { trueCondition := corev1.ConditionTrue falseCondition := corev1.ConditionFalse var err error @@ -230,11 +230,11 @@ func validateBuildRunToFail(testBuild *utils.TestBuild, testBuildRun *buildv1bet testBuildRun, err = testBuild.LookupBuildRun(types.NamespacedName{Name: testBuildRun.Name, Namespace: testBuild.Namespace}) Expect(err).ToNot(HaveOccurred(), "Error retrieving a buildRun") - if testBuildRun.Status.GetCondition(buildv1beta1.Succeeded) == nil { + if testBuildRun.Status.GetCondition(buildapi.Succeeded) == nil { return corev1.ConditionUnknown } - Expect(testBuildRun.Status.GetCondition(buildv1beta1.Succeeded).Status).NotTo(Equal(trueCondition), "BuildRun status moves to Succeeded") + Expect(testBuildRun.Status.GetCondition(buildapi.Succeeded).Status).NotTo(Equal(trueCondition), "BuildRun status moves to Succeeded") now := time.Now() if now.After(nextStatusLog) { @@ -242,7 +242,7 @@ func validateBuildRunToFail(testBuild *utils.TestBuild, testBuildRun *buildv1bet nextStatusLog = time.Now().Add(60 * time.Second) } - return testBuildRun.Status.GetCondition(buildv1beta1.Succeeded).Status + return testBuildRun.Status.GetCondition(buildapi.Succeeded).Status }, time.Duration(1100*getTimeoutMultiplier())*time.Second, 5*time.Second).Should(Equal(falseCondition), "BuildRun did not succeed") @@ -254,8 +254,8 @@ func validateBuildRunToFail(testBuild *utils.TestBuild, testBuildRun *buildv1bet // validateServiceAccountDeletion validates that a service account is correctly deleted after the end of // a build run and depending on the state of the build run -func validateServiceAccountDeletion(buildRun *buildv1beta1.BuildRun, namespace string) { - buildRunCondition := buildRun.Status.GetCondition(buildv1beta1.Succeeded) +func validateServiceAccountDeletion(buildRun *buildapi.BuildRun, namespace string) { + buildRunCondition := buildRun.Status.GetCondition(buildapi.Succeeded) if buildRunCondition != nil { if buildRunCondition.Status == "" || buildRunCondition.Status == corev1.ConditionUnknown { Logf("Skipping validation of service account deletion because build run did not end.") @@ -295,25 +295,25 @@ func readAndDecode(filePath string) (runtime.Object, error) { } // buildStrategyTestData gets the us the BuildStrategy test data set up -func buildStrategyTestData(ns string, buildStrategyCRPath string) (*buildv1beta1.BuildStrategy, error) { +func buildStrategyTestData(ns string, buildStrategyCRPath string) (*buildapi.BuildStrategy, error) { obj, err := readAndDecode(buildStrategyCRPath) if err != nil { return nil, err } - buildStrategy := obj.(*buildv1beta1.BuildStrategy) + buildStrategy := obj.(*buildapi.BuildStrategy) buildStrategy.SetNamespace(ns) return buildStrategy, err } -func buildTestData(namespace string, identifier string, filePath string) (*buildv1beta1.Build, error) { +func buildTestData(namespace string, identifier string, filePath string) (*buildapi.Build, error) { obj, err := readAndDecode(filePath) if err != nil { return nil, err } - build, ok := obj.(*buildv1beta1.Build) + build, ok := obj.(*buildapi.Build) if !ok { return nil, fmt.Errorf("failed to use the content of %s as a Build runtime object", filePath) } @@ -324,13 +324,13 @@ func buildTestData(namespace string, identifier string, filePath string) (*build } // buildTestData gets the us the Build test data set up -func buildRunTestData(ns string, identifier string, filePath string) (*buildv1beta1.BuildRun, error) { +func buildRunTestData(ns string, identifier string, filePath string) (*buildapi.BuildRun, error) { obj, err := readAndDecode(filePath) if err != nil { return nil, err } - buildRun, ok := obj.(*buildv1beta1.BuildRun) + buildRun, ok := obj.(*buildapi.BuildRun) if !ok { return nil, fmt.Errorf("failed to use the content of %s as a BuildRun runtime object", filePath) } @@ -350,13 +350,13 @@ func buildRunTestData(ns string, identifier string, filePath string) (*buildv1be return buildRun, nil } -func appendRegistryInsecureParamValue(build *buildv1beta1.Build, buildRun *buildv1beta1.BuildRun) { +func appendRegistryInsecureParamValue(build *buildapi.Build, buildRun *buildapi.BuildRun) { if strings.Contains(build.Spec.Output.Image, "cluster.local") { parts := strings.Split(build.Spec.Output.Image, "/") host := parts[0] - buildRun.Spec.ParamValues = append(buildRun.Spec.ParamValues, buildv1beta1.ParamValue{ + buildRun.Spec.ParamValues = append(buildRun.Spec.ParamValues, buildapi.ParamValue{ Name: "registries-insecure", - Values: []buildv1beta1.SingleValue{ + Values: []buildapi.SingleValue{ { Value: &host, }, diff --git a/test/integration/build_to_buildruns_test.go b/test/integration/build_to_buildruns_test.go index 1ffa0fd20a..cbe4ebb481 100644 --- a/test/integration/build_to_buildruns_test.go +++ b/test/integration/build_to_buildruns_test.go @@ -14,16 +14,16 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1" test "github.com/shipwright-io/build/test/v1beta1_samples" ) var _ = Describe("Integration tests Build and BuildRuns", func() { var ( - cbsObject *v1beta1.ClusterBuildStrategy - buildObject *v1beta1.Build - buildRunObject *v1beta1.BuildRun + cbsObject *buildapi.ClusterBuildStrategy + buildObject *buildapi.Build + buildRunObject *buildapi.BuildRun buildSample []byte buildRunSample []byte ) @@ -82,9 +82,9 @@ var _ = Describe("Integration tests Build and BuildRuns", func() { br, err := tb.GetBRTillCompletion(buildRunObject.Name) Expect(err).To(BeNil()) - Expect(br.Status.GetCondition(v1beta1.Succeeded).Status).To(Equal(corev1.ConditionFalse)) - Expect(br.Status.GetCondition(v1beta1.Succeeded).Reason).To(Equal("BuildRunTimeout")) - Expect(br.Status.GetCondition(v1beta1.Succeeded).Message).To(ContainSubstring("failed to finish within")) + Expect(br.Status.GetCondition(buildapi.Succeeded).Status).To(Equal(corev1.ConditionFalse)) + Expect(br.Status.GetCondition(buildapi.Succeeded).Reason).To(Equal("BuildRunTimeout")) + Expect(br.Status.GetCondition(buildapi.Succeeded).Message).To(ContainSubstring("failed to finish within")) }) }) @@ -106,9 +106,9 @@ var _ = Describe("Integration tests Build and BuildRuns", func() { br, err := tb.GetBRTillCompletion(buildRunObject.Name) Expect(err).To(BeNil()) - Expect(br.Status.GetCondition(v1beta1.Succeeded).Status).To(Equal(corev1.ConditionFalse)) - Expect(br.Status.GetCondition(v1beta1.Succeeded).Reason).To(Equal("BuildRunTimeout")) - Expect(br.Status.GetCondition(v1beta1.Succeeded).Message).To(ContainSubstring("failed to finish within")) + Expect(br.Status.GetCondition(buildapi.Succeeded).Status).To(Equal(corev1.ConditionFalse)) + Expect(br.Status.GetCondition(buildapi.Succeeded).Reason).To(Equal("BuildRunTimeout")) + Expect(br.Status.GetCondition(buildapi.Succeeded).Message).To(ContainSubstring("failed to finish within")) }) It("should be able to override the build output", func() { @@ -192,9 +192,9 @@ var _ = Describe("Integration tests Build and BuildRuns", func() { br, err := tb.GetBR(buildRunObject.Name) Expect(err).To(BeNil()) Expect(br.Status.CompletionTime).To(BeNil()) - Expect(br.Status.GetCondition(v1beta1.Succeeded).Type).To(Equal(v1beta1.Succeeded)) - Expect(br.Status.GetCondition(v1beta1.Succeeded).Status).To(Equal(corev1.ConditionUnknown)) - Expect(br.Status.GetCondition(v1beta1.Succeeded).Reason).To( + Expect(br.Status.GetCondition(buildapi.Succeeded).Type).To(Equal(buildapi.Succeeded)) + Expect(br.Status.GetCondition(buildapi.Succeeded).Status).To(Equal(corev1.ConditionUnknown)) + Expect(br.Status.GetCondition(buildapi.Succeeded).Reason).To( // BuildRun reason can be ExceededNodeResources // if the Tekton TaskRun Pod is queued due to // insufficient cluster resources. @@ -224,9 +224,9 @@ var _ = Describe("Integration tests Build and BuildRuns", func() { br, err := tb.GetBR(buildRunObject.Name) Expect(err).To(BeNil()) Expect(br.Status.StartTime).To(BeNil()) - Expect(br.Status.GetCondition(v1beta1.Succeeded).Status).To(Equal(corev1.ConditionFalse)) - Expect(br.Status.GetCondition(v1beta1.Succeeded).Reason).To(Equal("BuildNotFound")) - Expect(br.Status.GetCondition(v1beta1.Succeeded).Message).To(ContainSubstring("not found")) + Expect(br.Status.GetCondition(buildapi.Succeeded).Status).To(Equal(corev1.ConditionFalse)) + Expect(br.Status.GetCondition(buildapi.Succeeded).Reason).To(Equal("BuildNotFound")) + Expect(br.Status.GetCondition(buildapi.Succeeded).Message).To(ContainSubstring("not found")) }) }) @@ -250,9 +250,9 @@ var _ = Describe("Integration tests Build and BuildRuns", func() { br, err := tb.GetBRTillCompletion(buildRunObject.Name) Expect(err).To(BeNil()) - Expect(br.Status.GetCondition(v1beta1.Succeeded).Status).To(Equal(corev1.ConditionFalse)) - Expect(br.Status.GetCondition(v1beta1.Succeeded).Reason).To(Equal("BuildRegistrationFailed")) - Expect(br.Status.GetCondition(v1beta1.Succeeded).Message).To(ContainSubstring("Build is not registered correctly")) + Expect(br.Status.GetCondition(buildapi.Succeeded).Status).To(Equal(corev1.ConditionFalse)) + Expect(br.Status.GetCondition(buildapi.Succeeded).Reason).To(Equal("BuildRegistrationFailed")) + Expect(br.Status.GetCondition(buildapi.Succeeded).Message).To(ContainSubstring("Build is not registered correctly")) }) }) @@ -282,9 +282,9 @@ var _ = Describe("Integration tests Build and BuildRuns", func() { Expect(err).To(BeNil()) Expect(br.Status.CompletionTime).ToNot(BeNil()) Expect(br.Status.StartTime).To(BeNil()) - Expect(br.Status.GetCondition(v1beta1.Succeeded).Status).To(Equal(corev1.ConditionFalse)) - Expect(br.Status.GetCondition(v1beta1.Succeeded).Reason).To(Equal("BuildNotFound")) - Expect(br.Status.GetCondition(v1beta1.Succeeded).Message).To(ContainSubstring("not found")) + Expect(br.Status.GetCondition(buildapi.Succeeded).Status).To(Equal(corev1.ConditionFalse)) + Expect(br.Status.GetCondition(buildapi.Succeeded).Reason).To(Equal("BuildNotFound")) + Expect(br.Status.GetCondition(buildapi.Succeeded).Message).To(ContainSubstring("not found")) }) }) @@ -511,7 +511,7 @@ var _ = Describe("Integration tests Build and BuildRuns", func() { Expect(err).To(BeNil()) Expect(*buildObject.Status.Registered).To(Equal(corev1.ConditionFalse)) - Expect(*buildObject.Status.Reason).To(Equal(v1beta1.BuildNameInvalid)) + Expect(*buildObject.Status.Reason).To(Equal(buildapi.BuildNameInvalid)) Expect(*buildObject.Status.Message).To(ContainSubstring("must be no more than 63 characters")) }) }) @@ -537,8 +537,8 @@ var _ = Describe("Integration tests Build and BuildRuns", func() { Expect(err).To(BeNil()) Expect(*buildObject.Status.Registered).To(Equal(corev1.ConditionTrue)) - Expect(*buildObject.Status.Reason).To(Equal(v1beta1.SucceedStatus)) - Expect(*buildObject.Status.Message).To(Equal(v1beta1.AllValidationsSucceeded)) + Expect(*buildObject.Status.Reason).To(Equal(buildapi.SucceedStatus)) + Expect(*buildObject.Status.Message).To(Equal(buildapi.AllValidationsSucceeded)) }) }) }) diff --git a/test/integration/build_to_git_test.go b/test/integration/build_to_git_test.go index 6e781d4dce..4e3ac6f2bb 100644 --- a/test/integration/build_to_git_test.go +++ b/test/integration/build_to_git_test.go @@ -7,7 +7,7 @@ package integration_test import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1" test "github.com/shipwright-io/build/test/v1beta1_samples" corev1 "k8s.io/api/core/v1" "k8s.io/utils/pointer" @@ -16,8 +16,8 @@ import ( var _ = Describe("Integration tests Build and referenced Source url", func() { var ( - cbsObject *v1beta1.ClusterBuildStrategy - buildObject *v1beta1.Build + cbsObject *buildapi.ClusterBuildStrategy + buildObject *buildapi.Build ) // Load the ClusterBuildStrategies before each test case BeforeEach(func() { @@ -47,9 +47,9 @@ var _ = Describe("Integration tests Build and referenced Source url", func() { Expect(err).To(BeNil()) buildObject.ObjectMeta.Annotations["build.shipwright.io/verify.repository"] = "true" - buildObject.Spec.Source = &v1beta1.Source{ - Type: v1beta1.GitType, - Git: &v1beta1.Git{ + buildObject.Spec.Source = &buildapi.Source{ + Type: buildapi.GitType, + Git: &buildapi.Git{ URL: "http://github.com/shipwright-io/sample-go", }, } @@ -60,8 +60,8 @@ var _ = Describe("Integration tests Build and referenced Source url", func() { buildObject, err := tb.GetBuildTillRegistration(buildName, corev1.ConditionTrue) Expect(err).To(BeNil()) Expect(*buildObject.Status.Registered).To(Equal(corev1.ConditionTrue)) - Expect(*buildObject.Status.Reason).To(Equal(v1beta1.SucceedStatus)) - Expect(*buildObject.Status.Message).To(Equal(v1beta1.AllValidationsSucceeded)) + Expect(*buildObject.Status.Reason).To(Equal(buildapi.SucceedStatus)) + Expect(*buildObject.Status.Message).To(Equal(buildapi.AllValidationsSucceeded)) }) }) @@ -77,9 +77,9 @@ var _ = Describe("Integration tests Build and referenced Source url", func() { ) Expect(err).To(BeNil()) - buildObject.Spec.Source = &v1beta1.Source{ - Type: v1beta1.GitType, - Git: &v1beta1.Git{ + buildObject.Spec.Source = &buildapi.Source{ + Type: buildapi.GitType, + Git: &buildapi.Git{ URL: "http://github.com/shipwright-io/sample-go-fake", }, } @@ -90,8 +90,8 @@ var _ = Describe("Integration tests Build and referenced Source url", func() { Expect(err).To(BeNil()) // skip validation due to empty annotation Expect(*buildObject.Status.Registered).To(Equal(corev1.ConditionTrue)) - Expect(*buildObject.Status.Reason).To(Equal(v1beta1.SucceedStatus)) - Expect(*buildObject.Status.Message).To(Equal(v1beta1.AllValidationsSucceeded)) + Expect(*buildObject.Status.Reason).To(Equal(buildapi.SucceedStatus)) + Expect(*buildObject.Status.Message).To(Equal(buildapi.AllValidationsSucceeded)) }) }) @@ -108,9 +108,9 @@ var _ = Describe("Integration tests Build and referenced Source url", func() { Expect(err).To(BeNil()) buildObject.ObjectMeta.Annotations["build.shipwright.io/verify.repository"] = "true" - buildObject.Spec.Source = &v1beta1.Source{ - Type: v1beta1.GitType, - Git: &v1beta1.Git{ + buildObject.Spec.Source = &buildapi.Source{ + Type: buildapi.GitType, + Git: &buildapi.Git{ URL: "https://github.com/shipwright-io/sample-go", }, } @@ -121,8 +121,8 @@ var _ = Describe("Integration tests Build and referenced Source url", func() { buildObject, err := tb.GetBuildTillRegistration(buildName, corev1.ConditionTrue) Expect(err).To(BeNil()) Expect(*buildObject.Status.Registered).To(Equal(corev1.ConditionTrue)) - Expect(*buildObject.Status.Reason).To(Equal(v1beta1.SucceedStatus)) - Expect(*buildObject.Status.Message).To(Equal(v1beta1.AllValidationsSucceeded)) + Expect(*buildObject.Status.Reason).To(Equal(buildapi.SucceedStatus)) + Expect(*buildObject.Status.Message).To(Equal(buildapi.AllValidationsSucceeded)) }) }) @@ -138,9 +138,9 @@ var _ = Describe("Integration tests Build and referenced Source url", func() { ) Expect(err).To(BeNil()) - buildObject.Spec.Source = &v1beta1.Source{ - Type: v1beta1.GitType, - Git: &v1beta1.Git{ + buildObject.Spec.Source = &buildapi.Source{ + Type: buildapi.GitType, + Git: &buildapi.Git{ URL: "https://github.com/shipwright-io/sample-go-fake", }, } @@ -151,8 +151,8 @@ var _ = Describe("Integration tests Build and referenced Source url", func() { Expect(err).To(BeNil()) // skip validation due to empty annotation Expect(*buildObject.Status.Registered).To(Equal(corev1.ConditionTrue)) - Expect(*buildObject.Status.Reason).To(Equal(v1beta1.SucceedStatus)) - Expect(*buildObject.Status.Message).To(Equal(v1beta1.AllValidationsSucceeded)) + Expect(*buildObject.Status.Reason).To(Equal(buildapi.SucceedStatus)) + Expect(*buildObject.Status.Message).To(Equal(buildapi.AllValidationsSucceeded)) }) }) @@ -169,9 +169,9 @@ var _ = Describe("Integration tests Build and referenced Source url", func() { Expect(err).To(BeNil()) buildObject.ObjectMeta.Annotations["build.shipwright.io/verify.repository"] = "true" - buildObject.Spec.Source = &v1beta1.Source{ - Type: v1beta1.GitType, - Git: &v1beta1.Git{ + buildObject.Spec.Source = &buildapi.Source{ + Type: buildapi.GitType, + Git: &buildapi.Git{ URL: "foobar", }, } @@ -183,7 +183,7 @@ var _ = Describe("Integration tests Build and referenced Source url", func() { Expect(err).To(BeNil()) // this one is validating file protocol Expect(*buildObject.Status.Registered).To(Equal(corev1.ConditionFalse)) - Expect(*buildObject.Status.Reason).To(Equal(v1beta1.RemoteRepositoryUnreachable)) + Expect(*buildObject.Status.Reason).To(Equal(buildapi.RemoteRepositoryUnreachable)) Expect(*buildObject.Status.Message).To(Equal("invalid source url")) }) }) @@ -201,9 +201,9 @@ var _ = Describe("Integration tests Build and referenced Source url", func() { Expect(err).To(BeNil()) buildObject.ObjectMeta.Annotations["build.shipwright.io/verify.repository"] = "false" - buildObject.Spec.Source = &v1beta1.Source{ - Type: v1beta1.GitType, - Git: &v1beta1.Git{ + buildObject.Spec.Source = &buildapi.Source{ + Type: buildapi.GitType, + Git: &buildapi.Git{ URL: "foobar", }, } @@ -214,8 +214,8 @@ var _ = Describe("Integration tests Build and referenced Source url", func() { Expect(err).To(BeNil()) // skip validation due to false annotation Expect(*buildObject.Status.Registered).To(Equal(corev1.ConditionTrue)) - Expect(*buildObject.Status.Reason).To(Equal(v1beta1.SucceedStatus)) - Expect(*buildObject.Status.Message).To(Equal(v1beta1.AllValidationsSucceeded)) + Expect(*buildObject.Status.Reason).To(Equal(buildapi.SucceedStatus)) + Expect(*buildObject.Status.Message).To(Equal(buildapi.AllValidationsSucceeded)) }) }) @@ -232,9 +232,9 @@ var _ = Describe("Integration tests Build and referenced Source url", func() { Expect(err).To(BeNil()) buildObject.ObjectMeta.Annotations["build.shipwright.io/verify.repository"] = "true" - buildObject.Spec.Source = &v1beta1.Source{ - Type: v1beta1.GitType, - Git: &v1beta1.Git{ + buildObject.Spec.Source = &buildapi.Source{ + Type: buildapi.GitType, + Git: &buildapi.Git{ URL: "https://github.yourco.com/org/build-fake", }, } @@ -247,7 +247,7 @@ var _ = Describe("Integration tests Build and referenced Source url", func() { Expect(*buildObject.Status.Registered).To(Equal(corev1.ConditionFalse)) // Because github enterprise always require authentication, this validation will fail while // the repository could not be found. - Expect(*buildObject.Status.Reason).To(Equal(v1beta1.RemoteRepositoryUnreachable)) + Expect(*buildObject.Status.Reason).To(Equal(buildapi.RemoteRepositoryUnreachable)) Expect(*buildObject.Status.Message).To(ContainSubstring("no such host")) }) @@ -263,9 +263,9 @@ var _ = Describe("Integration tests Build and referenced Source url", func() { Expect(err).To(BeNil()) buildObject.ObjectMeta.Annotations["build.shipwright.io/verify.repository"] = "true" - buildObject.Spec.Source = &v1beta1.Source{ - Type: v1beta1.GitType, - Git: &v1beta1.Git{ + buildObject.Spec.Source = &buildapi.Source{ + Type: buildapi.GitType, + Git: &buildapi.Git{ URL: "https://github.yourco.com/org/build-fake", CloneSecret: pointer.String("foobar"), }, @@ -282,8 +282,8 @@ var _ = Describe("Integration tests Build and referenced Source url", func() { // Because this build references a source secret, Build controller will skip this validation. Expect(*buildObject.Status.Registered).To(Equal(corev1.ConditionTrue)) - Expect(*buildObject.Status.Reason).To(Equal(v1beta1.SucceedStatus)) - Expect(*buildObject.Status.Message).To(Equal(v1beta1.AllValidationsSucceeded)) + Expect(*buildObject.Status.Reason).To(Equal(buildapi.SucceedStatus)) + Expect(*buildObject.Status.Message).To(Equal(buildapi.AllValidationsSucceeded)) }) }) @@ -300,9 +300,9 @@ var _ = Describe("Integration tests Build and referenced Source url", func() { Expect(err).To(BeNil()) buildObject.ObjectMeta.Annotations["build.shipwright.io/verify.repository"] = "true" - buildObject.Spec.Source = &v1beta1.Source{ - Type: v1beta1.GitType, - Git: &v1beta1.Git{ + buildObject.Spec.Source = &buildapi.Source{ + Type: buildapi.GitType, + Git: &buildapi.Git{ URL: "git@github.com:shipwright-io/build-fake.git", }, } @@ -315,7 +315,7 @@ var _ = Describe("Integration tests Build and referenced Source url", func() { // Because sourceURL with git@ format implies that authentication is required, // this validation will be skipped and build will be successful. Expect(*buildObject.Status.Registered).To(Equal(corev1.ConditionFalse)) - Expect(*buildObject.Status.Reason).To(Equal(v1beta1.RemoteRepositoryUnreachable)) + Expect(*buildObject.Status.Reason).To(Equal(buildapi.RemoteRepositoryUnreachable)) Expect(*buildObject.Status.Message).To(Equal("the source url requires authentication")) }) }) @@ -333,9 +333,9 @@ var _ = Describe("Integration tests Build and referenced Source url", func() { Expect(err).To(BeNil()) buildObject.ObjectMeta.Annotations["build.shipwright.io/verify.repository"] = "true" - buildObject.Spec.Source = &v1beta1.Source{ - Type: v1beta1.GitType, - Git: &v1beta1.Git{ + buildObject.Spec.Source = &buildapi.Source{ + Type: buildapi.GitType, + Git: &buildapi.Git{ URL: "ssh://github.com/shipwright-io/build-fake.git", }, } @@ -348,7 +348,7 @@ var _ = Describe("Integration tests Build and referenced Source url", func() { // Because sourceURL with ssh format implies that authentication is required, // this validation will be skipped and build will be successful. Expect(*buildObject.Status.Registered).To(Equal(corev1.ConditionFalse)) - Expect(*buildObject.Status.Reason).To(Equal(v1beta1.RemoteRepositoryUnreachable)) + Expect(*buildObject.Status.Reason).To(Equal(buildapi.RemoteRepositoryUnreachable)) Expect(*buildObject.Status.Message).To(Equal("the source url requires authentication")) }) }) diff --git a/test/integration/build_to_secrets_test.go b/test/integration/build_to_secrets_test.go index 7b22646d33..4dc45e0bbe 100644 --- a/test/integration/build_to_secrets_test.go +++ b/test/integration/build_to_secrets_test.go @@ -9,7 +9,7 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1" test "github.com/shipwright-io/build/test/v1beta1_samples" corev1 "k8s.io/api/core/v1" ) @@ -17,8 +17,8 @@ import ( var _ = Describe("Integration tests Build and referenced Secrets", func() { var ( - cbsObject *v1beta1.ClusterBuildStrategy - buildObject *v1beta1.Build + cbsObject *buildapi.ClusterBuildStrategy + buildObject *buildapi.Build ) // Load the ClusterBuildStrategies before each test case BeforeEach(func() { @@ -57,7 +57,7 @@ var _ = Describe("Integration tests Build and referenced Secrets", func() { buildObject, err := tb.GetBuildTillValidation(buildName) Expect(err).To(BeNil()) Expect(*buildObject.Status.Registered).To(Equal(corev1.ConditionTrue)) - Expect(*buildObject.Status.Reason).To(Equal(v1beta1.SucceedStatus)) + Expect(*buildObject.Status.Reason).To(Equal(buildapi.SucceedStatus)) // delete a secret Expect(tb.DeleteSecret(*buildObject.Spec.Output.PushSecret)).To(BeNil()) @@ -66,7 +66,7 @@ var _ = Describe("Integration tests Build and referenced Secrets", func() { buildObject, err = tb.GetBuildTillRegistration(buildName, corev1.ConditionFalse) Expect(err).To(BeNil()) Expect(*buildObject.Status.Registered).To(Equal(corev1.ConditionFalse)) - Expect(*buildObject.Status.Reason).To(Equal(v1beta1.SpecOutputSecretRefNotFound)) + Expect(*buildObject.Status.Reason).To(Equal(buildapi.SpecOutputSecretRefNotFound)) Expect(*buildObject.Status.Message).To(Equal(fmt.Sprintf("referenced secret %s not found", *buildObject.Spec.Output.PushSecret))) }) @@ -86,7 +86,7 @@ var _ = Describe("Integration tests Build and referenced Secrets", func() { buildObject, err := tb.GetBuildTillValidation(buildName) Expect(err).To(BeNil()) Expect(*buildObject.Status.Registered).To(Equal(corev1.ConditionFalse)) - Expect(*buildObject.Status.Reason).To(Equal(v1beta1.SpecOutputSecretRefNotFound)) + Expect(*buildObject.Status.Reason).To(Equal(buildapi.SpecOutputSecretRefNotFound)) Expect(*buildObject.Status.Message).To(Equal(fmt.Sprintf("referenced secret %s not found", *buildObject.Spec.Output.PushSecret))) sampleSecret := tb.Catalog.SecretWithAnnotation(*buildObject.Spec.Output.PushSecret, buildObject.Namespace) @@ -98,7 +98,7 @@ var _ = Describe("Integration tests Build and referenced Secrets", func() { buildObject, err = tb.GetBuildTillRegistration(buildName, corev1.ConditionTrue) Expect(err).To(BeNil()) Expect(*buildObject.Status.Registered).To(Equal(corev1.ConditionTrue)) - Expect(*buildObject.Status.Reason).To(Equal(v1beta1.SucceedStatus)) + Expect(*buildObject.Status.Reason).To(Equal(buildapi.SucceedStatus)) }) }) @@ -124,7 +124,7 @@ var _ = Describe("Integration tests Build and referenced Secrets", func() { buildObject, err := tb.GetBuildTillValidation(buildName) Expect(err).To(BeNil()) Expect(*buildObject.Status.Registered).To(Equal(corev1.ConditionTrue)) - Expect(*buildObject.Status.Reason).To(Equal(v1beta1.SucceedStatus)) + Expect(*buildObject.Status.Reason).To(Equal(buildapi.SucceedStatus)) // delete a secret Expect(tb.DeleteSecret(*buildObject.Spec.Output.PushSecret)).To(BeNil()) @@ -151,7 +151,7 @@ var _ = Describe("Integration tests Build and referenced Secrets", func() { buildObject, err := tb.GetBuildTillValidation(buildName) Expect(err).To(BeNil()) Expect(*buildObject.Status.Registered).To(Equal(corev1.ConditionFalse)) - Expect(*buildObject.Status.Reason).To(Equal(v1beta1.SpecOutputSecretRefNotFound)) + Expect(*buildObject.Status.Reason).To(Equal(buildapi.SpecOutputSecretRefNotFound)) Expect(*buildObject.Status.Message).To(Equal(fmt.Sprintf("referenced secret %s not found", *buildObject.Spec.Output.PushSecret))) sampleSecret := tb.Catalog.SecretWithoutAnnotation(*buildObject.Spec.Output.PushSecret, buildObject.Namespace) @@ -163,7 +163,7 @@ var _ = Describe("Integration tests Build and referenced Secrets", func() { buildObject, err = tb.GetBuildTillRegistration(buildName, corev1.ConditionFalse) Expect(err).To(BeNil()) Expect(*buildObject.Status.Registered).To(Equal(corev1.ConditionFalse)) - Expect(*buildObject.Status.Reason).To(Equal(v1beta1.SpecOutputSecretRefNotFound)) + Expect(*buildObject.Status.Reason).To(Equal(buildapi.SpecOutputSecretRefNotFound)) Expect(*buildObject.Status.Message).To(Equal(fmt.Sprintf("referenced secret %s not found", *buildObject.Spec.Output.PushSecret))) }) @@ -183,7 +183,7 @@ var _ = Describe("Integration tests Build and referenced Secrets", func() { buildObject, err := tb.GetBuildTillValidation(buildName) Expect(err).To(BeNil()) Expect(*buildObject.Status.Registered).To(Equal(corev1.ConditionFalse)) - Expect(*buildObject.Status.Reason).To(Equal(v1beta1.SpecOutputSecretRefNotFound)) + Expect(*buildObject.Status.Reason).To(Equal(buildapi.SpecOutputSecretRefNotFound)) Expect(*buildObject.Status.Message).To(Equal(fmt.Sprintf("referenced secret %s not found", "fake-secret"))) sampleSecret := tb.Catalog.SecretWithoutAnnotation(*buildObject.Spec.Output.PushSecret, buildObject.Namespace) @@ -192,11 +192,11 @@ var _ = Describe("Integration tests Build and referenced Secrets", func() { Expect(tb.CreateSecret(sampleSecret)).To(BeNil()) // validate build status again Expect(*buildObject.Status.Registered).To(Equal(corev1.ConditionFalse)) - Expect(*buildObject.Status.Reason).To(Equal(v1beta1.SpecOutputSecretRefNotFound)) + Expect(*buildObject.Status.Reason).To(Equal(buildapi.SpecOutputSecretRefNotFound)) Expect(*buildObject.Status.Message).To(Equal(fmt.Sprintf("referenced secret %s not found", "fake-secret"))) // we modify the annotation so automatic delete does not take place - data := []byte(fmt.Sprintf(`{"metadata":{"annotations":{"%s":"true"}}}`, v1beta1.AnnotationBuildRefSecret)) + data := []byte(fmt.Sprintf(`{"metadata":{"annotations":{"%s":"true"}}}`, buildapi.AnnotationBuildRefSecret)) _, err = tb.PatchSecret(*buildObject.Spec.Output.PushSecret, data) Expect(err).To(BeNil()) @@ -205,7 +205,7 @@ var _ = Describe("Integration tests Build and referenced Secrets", func() { buildObject, err = tb.GetBuildTillRegistration(buildName, corev1.ConditionTrue) Expect(err).To(BeNil()) Expect(*buildObject.Status.Registered).To(Equal(corev1.ConditionTrue)) - Expect(*buildObject.Status.Reason).To(Equal(v1beta1.SucceedStatus)) + Expect(*buildObject.Status.Reason).To(Equal(buildapi.SucceedStatus)) Expect(*buildObject.Status.Message).To(Equal("all validations succeeded")) }) }) @@ -232,7 +232,7 @@ var _ = Describe("Integration tests Build and referenced Secrets", func() { buildObject, err := tb.GetBuildTillValidation(buildName) Expect(err).To(BeNil()) Expect(*buildObject.Status.Registered).To(Equal(corev1.ConditionTrue)) - Expect(*buildObject.Status.Reason).To(Equal(v1beta1.SucceedStatus)) + Expect(*buildObject.Status.Reason).To(Equal(buildapi.SucceedStatus)) Expect(*buildObject.Status.Message).To(Equal("all validations succeeded")) // delete a secret @@ -242,7 +242,7 @@ var _ = Describe("Integration tests Build and referenced Secrets", func() { buildObject, err = tb.GetBuildTillRegistration(buildName, corev1.ConditionFalse) Expect(err).To(BeNil()) Expect(*buildObject.Status.Registered).To(Equal(corev1.ConditionFalse)) - Expect(*buildObject.Status.Reason).To(Equal(v1beta1.SpecSourceSecretRefNotFound)) + Expect(*buildObject.Status.Reason).To(Equal(buildapi.SpecSourceSecretRefNotFound)) Expect(*buildObject.Status.Message).To(Equal(fmt.Sprintf("referenced secret %s not found", *buildObject.Spec.Source.Git.CloneSecret))) }) @@ -274,7 +274,7 @@ var _ = Describe("Integration tests Build and referenced Secrets", func() { buildObject, err = tb.GetBuildTillRegistration(buildName, corev1.ConditionTrue) Expect(err).To(BeNil()) Expect(*buildObject.Status.Registered).To(Equal(corev1.ConditionTrue)) - Expect(*buildObject.Status.Reason).To(Equal(v1beta1.SucceedStatus)) + Expect(*buildObject.Status.Reason).To(Equal(buildapi.SucceedStatus)) }) }) @@ -310,12 +310,12 @@ var _ = Describe("Integration tests Build and referenced Secrets", func() { o, err := tb.GetBuildTillValidation(firstBuildName) Expect(err).To(BeNil()) Expect(*o.Status.Registered).To(Equal(corev1.ConditionTrue)) - Expect(*o.Status.Reason).To(Equal(v1beta1.SucceedStatus)) + Expect(*o.Status.Reason).To(Equal(buildapi.SucceedStatus)) o, err = tb.GetBuildTillValidation(secondBuildName) Expect(err).To(BeNil()) Expect(*o.Status.Registered).To(Equal(corev1.ConditionTrue)) - Expect(*o.Status.Reason).To(Equal(v1beta1.SucceedStatus)) + Expect(*o.Status.Reason).To(Equal(buildapi.SucceedStatus)) // delete a secret Expect(tb.DeleteSecret(specSourceSecret.Name)).To(BeNil()) @@ -324,14 +324,14 @@ var _ = Describe("Integration tests Build and referenced Secrets", func() { o, err = tb.GetBuildTillRegistration(firstBuildName, corev1.ConditionFalse) Expect(err).To(BeNil()) Expect(*o.Status.Registered).To(Equal(corev1.ConditionFalse)) - Expect(*o.Status.Reason).To(Equal(v1beta1.SpecSourceSecretRefNotFound)) + Expect(*o.Status.Reason).To(Equal(buildapi.SpecSourceSecretRefNotFound)) Expect(*o.Status.Message).To(Equal(fmt.Sprintf("referenced secret %s not found", *firstBuildObject.Spec.Source.Git.CloneSecret))) // assert that the validation happened one more time o, err = tb.GetBuildTillRegistration(secondBuildName, corev1.ConditionFalse) Expect(err).To(BeNil()) Expect(*o.Status.Registered).To(Equal(corev1.ConditionFalse)) - Expect(*o.Status.Reason).To(Equal(v1beta1.SpecSourceSecretRefNotFound)) + Expect(*o.Status.Reason).To(Equal(buildapi.SpecSourceSecretRefNotFound)) Expect(*o.Status.Message).To(Equal(fmt.Sprintf("referenced secret %s not found", *secondBuildObject.Spec.Source.Git.CloneSecret))) }) It("should validate the Builds when a missing secret is recreated", func() { @@ -374,12 +374,12 @@ var _ = Describe("Integration tests Build and referenced Secrets", func() { o, err := tb.GetBuildTillRegistration(firstBuildName, corev1.ConditionTrue) Expect(err).To(BeNil()) Expect(*o.Status.Registered).To(Equal(corev1.ConditionTrue)) - Expect(*o.Status.Reason).To(Equal(v1beta1.SucceedStatus)) + Expect(*o.Status.Reason).To(Equal(buildapi.SucceedStatus)) o, err = tb.GetBuildTillRegistration(secondBuildName, corev1.ConditionTrue) Expect(err).To(BeNil()) Expect(*o.Status.Registered).To(Equal(corev1.ConditionTrue)) - Expect(*o.Status.Reason).To(Equal(v1beta1.SucceedStatus)) + Expect(*o.Status.Reason).To(Equal(buildapi.SucceedStatus)) }) }) }) diff --git a/test/integration/build_to_taskruns_test.go b/test/integration/build_to_taskruns_test.go index ee3b43ae93..d19c88ca4c 100644 --- a/test/integration/build_to_taskruns_test.go +++ b/test/integration/build_to_taskruns_test.go @@ -9,16 +9,16 @@ import ( . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" - "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1" utils "github.com/shipwright-io/build/test/utils/v1beta1" test "github.com/shipwright-io/build/test/v1beta1_samples" ) var _ = Describe("Integration tests Build and TaskRun", func() { var ( - cbsObject *v1beta1.ClusterBuildStrategy - buildObject *v1beta1.Build - buildRunObject *v1beta1.BuildRun + cbsObject *buildapi.ClusterBuildStrategy + buildObject *buildapi.Build + buildRunObject *buildapi.BuildRun buildSample, buildRunSample []byte ) @@ -75,8 +75,8 @@ var _ = Describe("Integration tests Build and TaskRun", func() { Expect(err).To(BeNil()) Expect(*buildObject.Status.Registered).To(Equal(corev1.ConditionTrue)) - Expect(*buildObject.Status.Reason).To(Equal(v1beta1.SucceedStatus)) - Expect(*buildObject.Status.Message).To(Equal(v1beta1.AllValidationsSucceeded)) + Expect(*buildObject.Status.Reason).To(Equal(buildapi.SucceedStatus)) + Expect(*buildObject.Status.Message).To(Equal(buildapi.AllValidationsSucceeded)) }) It("should be successful with label value as empty string", func() { @@ -90,8 +90,8 @@ var _ = Describe("Integration tests Build and TaskRun", func() { Expect(err).To(BeNil()) Expect(*buildObject.Status.Registered).To(Equal(corev1.ConditionTrue)) - Expect(*buildObject.Status.Reason).To(Equal(v1beta1.SucceedStatus)) - Expect(*buildObject.Status.Message).To(Equal(v1beta1.AllValidationsSucceeded)) + Expect(*buildObject.Status.Reason).To(Equal(buildapi.SucceedStatus)) + Expect(*buildObject.Status.Message).To(Equal(buildapi.AllValidationsSucceeded)) }) It("should be successful with annotation", func() { @@ -105,8 +105,8 @@ var _ = Describe("Integration tests Build and TaskRun", func() { Expect(err).To(BeNil()) Expect(*buildObject.Status.Registered).To(Equal(corev1.ConditionTrue)) - Expect(*buildObject.Status.Reason).To(Equal(v1beta1.SucceedStatus)) - Expect(*buildObject.Status.Message).To(Equal(v1beta1.AllValidationsSucceeded)) + Expect(*buildObject.Status.Reason).To(Equal(buildapi.SucceedStatus)) + Expect(*buildObject.Status.Message).To(Equal(buildapi.AllValidationsSucceeded)) }) It("should be successful with label", func() { @@ -120,8 +120,8 @@ var _ = Describe("Integration tests Build and TaskRun", func() { Expect(err).To(BeNil()) Expect(*buildObject.Status.Registered).To(Equal(corev1.ConditionTrue)) - Expect(*buildObject.Status.Reason).To(Equal(v1beta1.SucceedStatus)) - Expect(*buildObject.Status.Message).To(Equal(v1beta1.AllValidationsSucceeded)) + Expect(*buildObject.Status.Reason).To(Equal(buildapi.SucceedStatus)) + Expect(*buildObject.Status.Message).To(Equal(buildapi.AllValidationsSucceeded)) }) It("should be successful with both label and annotation", func() { @@ -140,8 +140,8 @@ var _ = Describe("Integration tests Build and TaskRun", func() { Expect(err).To(BeNil()) Expect(*buildObject.Status.Registered).To(Equal(corev1.ConditionTrue)) - Expect(*buildObject.Status.Reason).To(Equal(v1beta1.SucceedStatus)) - Expect(*buildObject.Status.Message).To(Equal(v1beta1.AllValidationsSucceeded)) + Expect(*buildObject.Status.Reason).To(Equal(buildapi.SucceedStatus)) + Expect(*buildObject.Status.Message).To(Equal(buildapi.AllValidationsSucceeded)) }) }) diff --git a/test/integration/buildrun_cleanup_test.go b/test/integration/buildrun_cleanup_test.go index a79d700562..68be691861 100644 --- a/test/integration/buildrun_cleanup_test.go +++ b/test/integration/buildrun_cleanup_test.go @@ -8,7 +8,7 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1" test "github.com/shipwright-io/build/test/v1beta1_samples" corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" @@ -17,9 +17,9 @@ import ( var _ = Describe("Integration tests for retention limits and ttls for succeeded buildruns.", func() { var ( - cbsObject *v1beta1.ClusterBuildStrategy - buildObject *v1beta1.Build - buildRunObject *v1beta1.BuildRun + cbsObject *buildapi.ClusterBuildStrategy + buildObject *buildapi.Build + buildRunObject *buildapi.BuildRun buildSample []byte buildRunSample []byte ) @@ -73,7 +73,7 @@ var _ = Describe("Integration tests for retention limits and ttls for succeeded br, err := tb.GetBRTillCompletion(buildRunObject.Name) Expect(err).To(BeNil()) - Expect(br.Status.GetCondition(v1beta1.Succeeded).Status).To(Equal(corev1.ConditionTrue)) + Expect(br.Status.GetCondition(buildapi.Succeeded).Status).To(Equal(corev1.ConditionTrue)) _, err = tb.GetBRTillNotFound(buildRunObject.Name, time.Second*1, time.Second*15) Expect(apierrors.IsNotFound(err)).To(BeTrue()) }) @@ -96,7 +96,7 @@ var _ = Describe("Integration tests for retention limits and ttls for succeeded Expect(tb.CreateBR(buildRunObject)).To(BeNil()) br, err := tb.GetBRTillCompletion(buildRunObject.Name) Expect(err).To(BeNil()) - Expect(br.Status.GetCondition(v1beta1.Succeeded).Status).To(Equal(corev1.ConditionTrue)) + Expect(br.Status.GetCondition(buildapi.Succeeded).Status).To(Equal(corev1.ConditionTrue)) _, err = tb.GetBRTillNotFound(buildRunObject.Name, time.Second*1, time.Second*15) Expect(apierrors.IsNotFound(err)).To(BeTrue()) }) @@ -115,7 +115,7 @@ var _ = Describe("Integration tests for retention limits and ttls for succeeded Expect(tb.CreateBR(buildRunObject)).To(BeNil()) br, err := tb.GetBRTillCompletion(buildRunObject.Name) Expect(err).To(BeNil()) - Expect(br.Status.GetCondition(v1beta1.Succeeded).Status).To(Equal(corev1.ConditionFalse)) + Expect(br.Status.GetCondition(buildapi.Succeeded).Status).To(Equal(corev1.ConditionFalse)) _, err = tb.GetBRTillNotFound(buildRunObject.Name, time.Second*1, time.Second*15) Expect(apierrors.IsNotFound(err)).To(BeTrue()) }) @@ -140,7 +140,7 @@ var _ = Describe("Integration tests for retention limits and ttls for succeeded Expect(tb.CreateBR(buildRunObject)).To(BeNil()) br, err := tb.GetBRTillCompletion(buildRunObject.Name) Expect(err).To(BeNil()) - Expect(br.Status.GetCondition(v1beta1.Succeeded).Status).To(Equal(corev1.ConditionTrue)) + Expect(br.Status.GetCondition(buildapi.Succeeded).Status).To(Equal(corev1.ConditionTrue)) // Make the TTL 5 seconds br.Spec.Retention.TTLAfterSucceeded.Duration = time.Second * 5 @@ -169,13 +169,13 @@ var _ = Describe("Integration tests for retention limits and ttls for succeeded Expect(tb.CreateBR(buildRunObject)).To(BeNil()) br1, err := tb.GetBRTillCompletion(buildRunObject.Name) Expect(err).To(BeNil()) - Expect(br1.Status.GetCondition(v1beta1.Succeeded).Status).To(Equal(corev1.ConditionTrue)) + Expect(br1.Status.GetCondition(buildapi.Succeeded).Status).To(Equal(corev1.ConditionTrue)) // Create second buildrun buildRunObject.Name = BUILDRUN + tb.Namespace + "-2" Expect(tb.CreateBR(buildRunObject)).To(BeNil()) br2, err := tb.GetBRTillCompletion(buildRunObject.Name) Expect(err).To(BeNil()) - Expect(br2.Status.GetCondition(v1beta1.Succeeded).Status).To(Equal(corev1.ConditionTrue)) + Expect(br2.Status.GetCondition(buildapi.Succeeded).Status).To(Equal(corev1.ConditionTrue)) _, err = tb.GetBRTillNotFound(BUILDRUN+tb.Namespace+"-1", time.Second*1, time.Second*5) Expect(apierrors.IsNotFound(err)).To(BeTrue()) @@ -201,7 +201,7 @@ var _ = Describe("Integration tests for retention limits and ttls for succeeded br, err := tb.GetBRTillCompletion(buildRunObject.Name) Expect(err).To(BeNil()) - Expect(br.Status.GetCondition(v1beta1.Succeeded).Status).To(Equal(corev1.ConditionTrue)) + Expect(br.Status.GetCondition(buildapi.Succeeded).Status).To(Equal(corev1.ConditionTrue)) _, err = tb.GetBRTillNotFound(buildRunObject.Name, time.Second*1, time.Second*15) Expect(apierrors.IsNotFound(err)).To(BeTrue()) @@ -234,31 +234,31 @@ var _ = Describe("Integration tests for retention limits and ttls for succeeded // Create 1 failed buildrun buildRunObject.Name = BUILDRUN + tb.Namespace + "-fail-1" str := "false" - falseParam := v1beta1.ParamValue{Name: "exit-command", SingleValue: &v1beta1.SingleValue{Value: &str}} - buildRunObject.Spec.ParamValues = []v1beta1.ParamValue{falseParam} + falseParam := buildapi.ParamValue{Name: "exit-command", SingleValue: &buildapi.SingleValue{Value: &str}} + buildRunObject.Spec.ParamValues = []buildapi.ParamValue{falseParam} err = tb.CreateBR(buildRunObject) // Wait for buildrun completion br1, err := tb.GetBRTillCompletion(BUILDRUN + tb.Namespace + "-success-1") Expect(err).To(BeNil()) - Expect(br1.Status.GetCondition(v1beta1.Succeeded).Status).To(Equal(corev1.ConditionTrue)) + Expect(br1.Status.GetCondition(buildapi.Succeeded).Status).To(Equal(corev1.ConditionTrue)) br2, err := tb.GetBRTillCompletion(BUILDRUN + tb.Namespace + "-success-2") Expect(err).To(BeNil()) - Expect(br2.Status.GetCondition(v1beta1.Succeeded).Status).To(Equal(corev1.ConditionTrue)) + Expect(br2.Status.GetCondition(buildapi.Succeeded).Status).To(Equal(corev1.ConditionTrue)) br3, err := tb.GetBRTillCompletion(BUILDRUN + tb.Namespace + "-fail-1") Expect(err).To(BeNil()) - Expect(br3.Status.GetCondition(v1beta1.Succeeded).Status).To(Equal(corev1.ConditionFalse)) + Expect(br3.Status.GetCondition(buildapi.Succeeded).Status).To(Equal(corev1.ConditionFalse)) // Create 1 failed buildrun. buildRunObject.Name = BUILDRUN + tb.Namespace + "-fail-2" - buildRunObject.Spec.ParamValues = []v1beta1.ParamValue{falseParam} + buildRunObject.Spec.ParamValues = []buildapi.ParamValue{falseParam} err = tb.CreateBR(buildRunObject) Expect(err).To(BeNil()) br4, err := tb.GetBRTillCompletion(buildRunObject.Name) Expect(err).To(BeNil()) - Expect(br4.Status.GetCondition(v1beta1.Succeeded).Status).To(Equal(corev1.ConditionFalse)) + Expect(br4.Status.GetCondition(buildapi.Succeeded).Status).To(Equal(corev1.ConditionFalse)) // Check that the older failed buildrun has been deleted while the successful buildruns exist _, err = tb.GetBRTillNotFound(BUILDRUN+tb.Namespace+"-fail-1", time.Second*1, time.Second*5) @@ -274,9 +274,9 @@ var _ = Describe("Integration tests for retention limits and ttls for succeeded var _ = Describe("Integration tests for retention limits and ttls of buildRuns that fail", func() { var ( - cbsObject *v1beta1.ClusterBuildStrategy - buildObject *v1beta1.Build - buildRunObject *v1beta1.BuildRun + cbsObject *buildapi.ClusterBuildStrategy + buildObject *buildapi.Build + buildRunObject *buildapi.BuildRun buildSample []byte buildRunSample []byte ) @@ -309,8 +309,8 @@ var _ = Describe("Integration tests for retention limits and ttls of buildRuns t buildRunObject, err = tb.Catalog.LoadBRWithNameAndRef(BUILDRUN+tb.Namespace, BUILD+tb.Namespace, buildRunSample) Expect(err).To(BeNil()) str := "false" - falseParam := v1beta1.ParamValue{Name: "exit-command", SingleValue: &v1beta1.SingleValue{Value: &str}} - buildRunObject.Spec.ParamValues = []v1beta1.ParamValue{falseParam} + falseParam := buildapi.ParamValue{Name: "exit-command", SingleValue: &buildapi.SingleValue{Value: &str}} + buildRunObject.Spec.ParamValues = []buildapi.ParamValue{falseParam} } }) @@ -332,7 +332,7 @@ var _ = Describe("Integration tests for retention limits and ttls of buildRuns t br, err := tb.GetBRTillCompletion(buildRunObject.Name) Expect(err).To(BeNil()) - Expect(br.Status.GetCondition(v1beta1.Succeeded).Status).To(Equal(corev1.ConditionFalse)) + Expect(br.Status.GetCondition(buildapi.Succeeded).Status).To(Equal(corev1.ConditionFalse)) _, err = tb.GetBRTillNotFound(buildRunObject.Name, time.Second*1, time.Second*15) Expect(apierrors.IsNotFound(err)).To(BeTrue()) }) @@ -357,7 +357,7 @@ var _ = Describe("Integration tests for retention limits and ttls of buildRuns t Expect(tb.CreateBR(buildRunObject)).To(BeNil()) br, err := tb.GetBRTillCompletion(buildRunObject.Name) Expect(err).To(BeNil()) - Expect(br.Status.GetCondition(v1beta1.Succeeded).Status).To(Equal(corev1.ConditionFalse)) + Expect(br.Status.GetCondition(buildapi.Succeeded).Status).To(Equal(corev1.ConditionFalse)) // Make the TTL 5 seconds br.Spec.Retention.TTLAfterFailed.Duration = time.Second * 5 @@ -384,7 +384,7 @@ var _ = Describe("Integration tests for retention limits and ttls of buildRuns t br, err := tb.GetBRTillCompletion(buildRunObject.Name) Expect(err).To(BeNil()) - Expect(br.Status.GetCondition(v1beta1.Succeeded).Status).To(Equal(corev1.ConditionFalse)) + Expect(br.Status.GetCondition(buildapi.Succeeded).Status).To(Equal(corev1.ConditionFalse)) _, err = tb.GetBRTillNotFound(buildRunObject.Name, time.Second*1, time.Second*15) Expect(apierrors.IsNotFound(err)).To(BeTrue()) }) @@ -406,7 +406,7 @@ var _ = Describe("Integration tests for retention limits and ttls of buildRuns t br, err := tb.GetBRTillCompletion(buildRunObject.Name) Expect(err).To(BeNil()) - Expect(br.Status.GetCondition(v1beta1.Succeeded).Status).To(Equal(corev1.ConditionFalse)) + Expect(br.Status.GetCondition(buildapi.Succeeded).Status).To(Equal(corev1.ConditionFalse)) _, err = tb.GetBRTillNotFound(buildRunObject.Name, time.Second*1, time.Second*15) Expect(apierrors.IsNotFound(err)).To(BeTrue()) @@ -431,13 +431,13 @@ var _ = Describe("Integration tests for retention limits and ttls of buildRuns t Expect(tb.CreateBR(buildRunObject)).To(BeNil()) br1, err := tb.GetBRTillCompletion(buildRunObject.Name) Expect(err).To(BeNil()) - Expect(br1.Status.GetCondition(v1beta1.Succeeded).Status).To(Equal(corev1.ConditionFalse)) + Expect(br1.Status.GetCondition(buildapi.Succeeded).Status).To(Equal(corev1.ConditionFalse)) // Create second buildrun buildRunObject.Name = BUILDRUN + tb.Namespace + "-2" Expect(tb.CreateBR(buildRunObject)).To(BeNil()) br2, err := tb.GetBRTillCompletion(buildRunObject.Name) Expect(err).To(BeNil()) - Expect(br2.Status.GetCondition(v1beta1.Succeeded).Status).To(Equal(corev1.ConditionFalse)) + Expect(br2.Status.GetCondition(buildapi.Succeeded).Status).To(Equal(corev1.ConditionFalse)) _, err = tb.GetBRTillNotFound(BUILDRUN+tb.Namespace+"-1", time.Second*1, time.Second*5) Expect(apierrors.IsNotFound(err)).To(BeTrue()) diff --git a/test/integration/buildrun_status_test.go b/test/integration/buildrun_status_test.go index 241289f16f..b15903a62a 100644 --- a/test/integration/buildrun_status_test.go +++ b/test/integration/buildrun_status_test.go @@ -11,7 +11,7 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/rand" @@ -40,21 +40,21 @@ var _ = Describe("Checking BuildRun Status fields", func() { // Use an empty strategy to only have the source step strategy := tb.Catalog.ClusterBuildStrategy(strategyName) Expect(tb.CreateClusterBuildStrategy(strategy)).To(Succeed()) - cbs := v1beta1.ClusterBuildStrategyKind + cbs := buildapi.ClusterBuildStrategyKind // Setup BuildRun with fixed revision where we know the commit details - Expect(tb.CreateBR(&v1beta1.BuildRun{ + Expect(tb.CreateBR(&buildapi.BuildRun{ ObjectMeta: metav1.ObjectMeta{Name: buildRunName}, - Spec: v1beta1.BuildRunSpec{ - Build: v1beta1.ReferencedBuild{ - Spec: &v1beta1.BuildSpec{ - Source: &v1beta1.Source{ - Type: v1beta1.GitType, - Git: &v1beta1.Git{ + Spec: buildapi.BuildRunSpec{ + Build: buildapi.ReferencedBuild{ + Spec: &buildapi.BuildSpec{ + Source: &buildapi.Source{ + Type: buildapi.GitType, + Git: &buildapi.Git{ URL: "https://github.com/shipwright-io/sample-go", Revision: pointer.String("v0.1.0"), }, }, - Strategy: v1beta1.Strategy{ + Strategy: buildapi.Strategy{ Kind: &cbs, Name: strategy.Name, }, @@ -76,21 +76,21 @@ var _ = Describe("Checking BuildRun Status fields", func() { // Use an empty strategy to only have the source step strategy := tb.Catalog.ClusterBuildStrategy(strategyName) Expect(tb.CreateClusterBuildStrategy(strategy)).To(Succeed()) - cbs := v1beta1.ClusterBuildStrategyKind + cbs := buildapi.ClusterBuildStrategyKind // Setup BuildRun with fixed image sha where we know the timestamp details - Expect(tb.CreateBR(&v1beta1.BuildRun{ + Expect(tb.CreateBR(&buildapi.BuildRun{ ObjectMeta: metav1.ObjectMeta{Name: buildRunName}, - Spec: v1beta1.BuildRunSpec{ - Build: v1beta1.ReferencedBuild{ - Spec: &v1beta1.BuildSpec{ - Strategy: v1beta1.Strategy{ + Spec: buildapi.BuildRunSpec{ + Build: buildapi.ReferencedBuild{ + Spec: &buildapi.BuildSpec{ + Strategy: buildapi.Strategy{ Kind: &cbs, Name: strategy.Name, }, - Source: &v1beta1.Source{ - Type: v1beta1.OCIArtifactType, - OCIArtifact: &v1beta1.OCIArtifact{ + Source: &buildapi.Source{ + Type: buildapi.OCIArtifactType, + OCIArtifact: &buildapi.OCIArtifact{ Image: "ghcr.io/shipwright-io/sample-go/source-bundle@sha256:9a5e264c19980387b8416e0ffa7460488272fb8a6a56127c657edaa2682daab2", }, }, diff --git a/test/integration/buildruns_to_sa_test.go b/test/integration/buildruns_to_sa_test.go index 0b6cbc909b..942769d0a1 100644 --- a/test/integration/buildruns_to_sa_test.go +++ b/test/integration/buildruns_to_sa_test.go @@ -15,16 +15,16 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/util/wait" - "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1" test "github.com/shipwright-io/build/test/v1beta1_samples" ) var _ = Describe("Integration tests BuildRuns and Service-accounts", func() { var ( - cbsObject *v1beta1.ClusterBuildStrategy - buildObject *v1beta1.Build - buildRunObject *v1beta1.BuildRun + cbsObject *buildapi.ClusterBuildStrategy + buildObject *buildapi.Build + buildRunObject *buildapi.BuildRun buildSample []byte buildRunSample []byte ) @@ -159,7 +159,7 @@ var _ = Describe("Integration tests BuildRuns and Service-accounts", func() { return false, nil } - bro.Spec.State = v1beta1.BuildRunRequestedStatePtr(v1beta1.BuildRunStateCancel) + bro.Spec.State = buildapi.BuildRunRequestedStatePtr(buildapi.BuildRunStateCancel) err = tb.UpdateBR(bro) if err != nil { GinkgoT().Logf("error on br update: %s\n", err.Error()) @@ -169,7 +169,7 @@ var _ = Describe("Integration tests BuildRuns and Service-accounts", func() { }) Expect(err).To(BeNil()) - expectedReason := v1beta1.BuildRunStateCancel + expectedReason := buildapi.BuildRunStateCancel actualReason, err := tb.GetBRTillDesiredReason(buildRunObject.Name, expectedReason) Expect(err).To(BeNil(), fmt.Sprintf("failed to get desired BuildRun reason; expected %s, got %s", expectedReason, actualReason)) @@ -247,7 +247,7 @@ var _ = Describe("Integration tests BuildRuns and Service-accounts", func() { br, _ := tb.GetBRTillCompletion(buildRunObject.Name) Expect(err).To(BeNil()) - buildRunCondition := br.Status.GetCondition(v1beta1.Succeeded) + buildRunCondition := br.Status.GetCondition(buildapi.Succeeded) Expect(buildRunCondition).ToNot(BeNil()) Expect(buildRunCondition.Status).To(Equal(corev1.ConditionFalse)) diff --git a/test/integration/buildruns_to_taskruns_test.go b/test/integration/buildruns_to_taskruns_test.go index 4633ed0bd0..4300cf9a5e 100644 --- a/test/integration/buildruns_to_taskruns_test.go +++ b/test/integration/buildruns_to_taskruns_test.go @@ -14,7 +14,7 @@ import ( . "github.com/onsi/gomega" pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" - "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "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/v1beta1_samples" @@ -27,14 +27,14 @@ import ( var _ = Describe("Integration tests BuildRuns and TaskRuns", func() { var ( - cbsObject *v1beta1.ClusterBuildStrategy - buildObject *v1beta1.Build - buildRunObject *v1beta1.BuildRun + cbsObject *buildapi.ClusterBuildStrategy + buildObject *buildapi.Build + buildRunObject *buildapi.BuildRun buildSample []byte buildRunSample []byte ) - var setupBuildAndBuildRun = func(buildDef []byte, buildRunDef []byte, strategy ...string) (watch.Interface, *v1beta1.Build, *v1beta1.BuildRun) { + var setupBuildAndBuildRun = func(buildDef []byte, buildRunDef []byte, strategy ...string) (watch.Interface, *buildapi.Build, *buildapi.BuildRun) { var strategyName = STRATEGY + tb.Namespace if len(strategy) > 0 { @@ -117,14 +117,14 @@ var _ = Describe("Integration tests BuildRuns and TaskRuns", func() { // use a fakeTime to simplify tests fakeTime := time.Date(1989, 05, 15, 00, 01, 01, 651387237, time.UTC) - var seq = []*v1beta1.Condition{} + var seq = []*buildapi.Condition{} for event := range buildRunWatcher.ResultChan() { if event.Type == watch.Error { GinkgoWriter.Write([]byte(fmt.Sprintf("Unexpected error event in watch: %v", event.Object))) continue } - condition := event.Object.(*v1beta1.BuildRun).Status.GetCondition(v1beta1.Succeeded) + condition := event.Object.(*buildapi.BuildRun).Status.GetCondition(buildapi.Succeeded) if condition != nil { condition.LastTransitionTime = metav1.Time{Time: fakeTime} seq = append(seq, condition) @@ -140,15 +140,15 @@ var _ = Describe("Integration tests BuildRuns and TaskRuns", func() { Expect(len(seq) >= 2).To(Equal(true)) // ensure the conditions move eventually from unknown into running - Expect(seq).Should(ContainElement(&v1beta1.Condition{ - Type: v1beta1.Succeeded, + Expect(seq).Should(ContainElement(&buildapi.Condition{ + Type: buildapi.Succeeded, Status: corev1.ConditionUnknown, LastTransitionTime: metav1.Time{Time: fakeTime}, Reason: "Pending", Message: "Pending", })) - Expect(seq).Should(ContainElement(&v1beta1.Condition{ - Type: v1beta1.Succeeded, + Expect(seq).Should(ContainElement(&buildapi.Condition{ + Type: buildapi.Succeeded, Status: corev1.ConditionUnknown, LastTransitionTime: metav1.Time{Time: fakeTime}, Reason: "Running", @@ -164,7 +164,7 @@ var _ = Describe("Integration tests BuildRuns and TaskRuns", func() { buildRun, err := tb.GetBRTillCompletion(buildRun.Name) Expect(err).ToNot(HaveOccurred()) - condition := buildRun.Status.GetCondition(v1beta1.Succeeded) + condition := buildRun.Status.GetCondition(buildapi.Succeeded) Expect(condition.Status).To(Equal(corev1.ConditionFalse)) Expect(condition.Reason).To(Equal("BuildRunTimeout")) Expect(condition.Message).To(Equal(fmt.Sprintf("BuildRun %s failed to finish within %v", buildRun.Name, build.Spec.Timeout.Duration))) @@ -184,7 +184,7 @@ var _ = Describe("Integration tests BuildRuns and TaskRuns", func() { Expect(buildRun.Status.FailureDetails.Location.Pod).To(Equal(taskRun.Status.PodName)) Expect(buildRun.Status.FailureDetails.Location.Container).To(Equal("step-step-build-and-push")) - condition := buildRun.Status.GetCondition(v1beta1.Succeeded) + condition := buildRun.Status.GetCondition(buildapi.Succeeded) Expect(condition.Status).To(Equal(corev1.ConditionFalse)) Expect(condition.Reason).To(Equal("Failed")) Expect(condition.Message).To(ContainSubstring("buildrun step %s failed in pod %s", "step-step-build-and-push", taskRun.Status.PodName)) @@ -200,7 +200,7 @@ var _ = Describe("Integration tests BuildRuns and TaskRuns", func() { buildRun, err := tb.GetBRTillCompletion(buildRun.Name) Expect(err).ToNot(HaveOccurred()) - condition := buildRun.Status.GetCondition(v1beta1.Succeeded) + condition := buildRun.Status.GetCondition(buildapi.Succeeded) Expect(condition.Status).To(Equal(corev1.ConditionTrue)) Expect(condition.Reason).To(Equal("Succeeded")) Expect(condition.Message).To(ContainSubstring("All Steps have completed executing")) @@ -297,7 +297,7 @@ var _ = Describe("Integration tests BuildRuns and TaskRuns", func() { b, err := tb.GetBuildTillRegistration(buildObject.Name, corev1.ConditionFalse) Expect(err).To(BeNil()) Expect(*b.Status.Registered).To(Equal(corev1.ConditionFalse)) - Expect(*b.Status.Reason).To(Equal(v1beta1.RemoteRepositoryUnreachable)) + Expect(*b.Status.Reason).To(Equal(buildapi.RemoteRepositoryUnreachable)) Expect(*b.Status.Message).To(ContainSubstring("no such host")) _, err = tb.GetBRTillCompletion(buildRunObject.Name) @@ -351,7 +351,7 @@ var _ = Describe("Integration tests BuildRuns and TaskRuns", func() { Context("when a standalone buildrun is created and the buildrun is cancelled", func() { var standAloneBuildRunSample []byte - var standaloneBuildRunObject *v1beta1.BuildRun + var standaloneBuildRunObject *buildapi.BuildRun BeforeEach(func() { standAloneBuildRunSample = []byte(test.MinimalOneOffBuildRun) @@ -369,8 +369,8 @@ var _ = Describe("Integration tests BuildRuns and TaskRuns", func() { _, err = tb.GetTaskRunFromBuildRun(br.Name) Expect(err).ToNot(HaveOccurred()) - br.Spec.State = v1beta1.BuildRunRequestedStatePtr(v1beta1.BuildRunStateCancel) - data := []byte(fmt.Sprintf(`{"spec":{"state": "%s"}}`, v1beta1.BuildRunStateCancel)) + br.Spec.State = buildapi.BuildRunRequestedStatePtr(buildapi.BuildRunStateCancel) + data := []byte(fmt.Sprintf(`{"spec":{"state": "%s"}}`, buildapi.BuildRunStateCancel)) br, err = tb.BuildClientSet.ShipwrightV1beta1(). BuildRuns(tb.Namespace). Patch(tb.Context, br.Name, types.MergePatchType, data, metav1.PatchOptions{}) @@ -379,9 +379,9 @@ var _ = Describe("Integration tests BuildRuns and TaskRuns", func() { actualReason, err := tb.GetTRTillDesiredReason(br.Name, "TaskRunCancelled") Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("failed to get desired reason; expected %s, got %s", "TaskRunCancelled", actualReason)) - actualReason, err = tb.GetBRTillDesiredReason(br.Name, v1beta1.BuildRunStateCancel) - Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("failed to get desired BuildRun reason; expected %s, got %s", v1beta1.BuildRunStateCancel, actualReason)) - Expect(actualReason).To(Equal(v1beta1.BuildRunStateCancel)) + actualReason, err = tb.GetBRTillDesiredReason(br.Name, buildapi.BuildRunStateCancel) + Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("failed to get desired BuildRun reason; expected %s, got %s", buildapi.BuildRunStateCancel, actualReason)) + Expect(actualReason).To(Equal(buildapi.BuildRunStateCancel)) }) }) @@ -408,7 +408,7 @@ var _ = Describe("Integration tests BuildRuns and TaskRuns", func() { return false, nil } - bro.Spec.State = v1beta1.BuildRunRequestedStatePtr(v1beta1.BuildRunStateCancel) + bro.Spec.State = buildapi.BuildRunRequestedStatePtr(buildapi.BuildRunStateCancel) err = tb.UpdateBR(bro) if err != nil { GinkgoT().Logf("error on br update: %s\n", err.Error()) @@ -422,7 +422,7 @@ var _ = Describe("Integration tests BuildRuns and TaskRuns", func() { actualReason, err := tb.GetTRTillDesiredReason(buildRunObject.Name, expectedReason) Expect(err).To(BeNil(), fmt.Sprintf("failed to get desired TaskRun reason; expected %s, got %s", expectedReason, actualReason)) - expectedReason = v1beta1.BuildRunStateCancel + expectedReason = buildapi.BuildRunStateCancel actualReason, err = tb.GetBRTillDesiredReason(buildRunObject.Name, expectedReason) Expect(err).To(BeNil(), fmt.Sprintf("failed to get desired BuildRun reason; expected %s, got %s", expectedReason, actualReason)) }) @@ -509,7 +509,7 @@ var _ = Describe("Integration tests BuildRuns and TaskRuns", func() { br, err := tb.GetBRTillCompletion(buildRunObject.Name) Expect(err).To(BeNil()) - condition := br.Status.GetCondition(v1beta1.Succeeded) + condition := br.Status.GetCondition(buildapi.Succeeded) Expect(condition.Status).To(Equal(corev1.ConditionFalse)) Expect(condition.Reason).To(Equal(resources.BuildRunNameInvalid)) Expect(condition.Message).To(Equal("must be no more than 63 characters")) diff --git a/test/integration/buildstrategy_to_taskruns_test.go b/test/integration/buildstrategy_to_taskruns_test.go index 0c2ebbce8e..d2d5d6d793 100644 --- a/test/integration/buildstrategy_to_taskruns_test.go +++ b/test/integration/buildstrategy_to_taskruns_test.go @@ -10,7 +10,7 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1" utils "github.com/shipwright-io/build/test/utils/v1beta1" test "github.com/shipwright-io/build/test/v1beta1_samples" pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" @@ -19,9 +19,9 @@ import ( var _ = Describe("Integration tests BuildStrategies and TaskRuns", func() { var ( - bsObject *v1beta1.BuildStrategy - buildObject *v1beta1.Build - buildRunObject *v1beta1.BuildRun + bsObject *buildapi.BuildStrategy + buildObject *buildapi.Build + buildRunObject *buildapi.BuildRun secret *corev1.Secret configMap *corev1.ConfigMap buildSample []byte @@ -144,7 +144,7 @@ var _ = Describe("Integration tests BuildStrategies and TaskRuns", func() { } } - var constructBuildObjectAndWait = func(b *v1beta1.Build) { + var constructBuildObjectAndWait = func(b *buildapi.Build) { // Create the Build object in-cluster Expect(tb.CreateBuild(b)).To(BeNil()) @@ -153,7 +153,7 @@ var _ = Describe("Integration tests BuildStrategies and TaskRuns", func() { Expect(err).To(BeNil()) } - var constructBuildRunObjectAndWait = func(br *v1beta1.BuildRun) { + var constructBuildRunObjectAndWait = func(br *buildapi.BuildRun) { // Create the BuildRun object in-cluster Expect(tb.CreateBR(br)).To(BeNil()) @@ -309,9 +309,9 @@ var _ = Describe("Integration tests BuildStrategies and TaskRuns", func() { br, err := tb.GetBRTillCompletion(buildRunObjectWithReservedParams.Name) Expect(err).To(BeNil()) - Expect(br.Status.GetCondition(v1beta1.Succeeded).GetReason()).To(Equal("RestrictedParametersInUse")) - Expect(br.Status.GetCondition(v1beta1.Succeeded).GetMessage()).To(HavePrefix("The following parameters are restricted and cannot be set")) - Expect(br.Status.GetCondition(v1beta1.Succeeded).GetMessage()).To(ContainSubstring("shp-sleep-time")) + Expect(br.Status.GetCondition(buildapi.Succeeded).GetReason()).To(Equal("RestrictedParametersInUse")) + Expect(br.Status.GetCondition(buildapi.Succeeded).GetMessage()).To(HavePrefix("The following parameters are restricted and cannot be set")) + Expect(br.Status.GetCondition(buildapi.Succeeded).GetMessage()).To(ContainSubstring("shp-sleep-time")) }) It("add params from buildRun if they are not defined in the Build", func() { @@ -356,7 +356,7 @@ var _ = Describe("Integration tests BuildStrategies and TaskRuns", func() { buildObject, err = tb.GetBuildTillValidation(buildObject.Name) Expect(err).To(BeNil()) - Expect(*buildObject.Status.Reason).To(Equal(v1beta1.RestrictedParametersInUse)) + Expect(*buildObject.Status.Reason).To(Equal(buildapi.RestrictedParametersInUse)) Expect(*buildObject.Status.Message).To(HavePrefix("The following parameters are restricted and cannot be set:")) Expect(*buildObject.Status.Message).To(ContainSubstring("shp-something")) }) @@ -377,7 +377,7 @@ var _ = Describe("Integration tests BuildStrategies and TaskRuns", func() { buildObject, err = tb.GetBuildTillValidation(buildObject.Name) Expect(err).To(BeNil()) - Expect(*buildObject.Status.Reason).To(Equal(v1beta1.UndefinedParameter)) + Expect(*buildObject.Status.Reason).To(Equal(buildapi.UndefinedParameter)) Expect(*buildObject.Status.Message).To(Equal("The following parameters are not defined in the build strategy: sleep-not")) }) @@ -483,9 +483,9 @@ var _ = Describe("Integration tests BuildStrategies and TaskRuns", func() { br, err := tb.GetBRTillCompletion(buildRunObject.Name) Expect(err).To(BeNil()) - Expect(br.Status.GetCondition(v1beta1.Succeeded).GetReason()).To(Equal("MissingParameterValues")) - Expect(br.Status.GetCondition(v1beta1.Succeeded).GetMessage()).To(HavePrefix("The following parameters are required but no value has been provided:")) - Expect(br.Status.GetCondition(v1beta1.Succeeded).GetMessage()).To(ContainSubstring("sleep-time")) + Expect(br.Status.GetCondition(buildapi.Succeeded).GetReason()).To(Equal("MissingParameterValues")) + Expect(br.Status.GetCondition(buildapi.Succeeded).GetMessage()).To(HavePrefix("The following parameters are required but no value has been provided:")) + Expect(br.Status.GetCondition(buildapi.Succeeded).GetMessage()).To(ContainSubstring("sleep-time")) }) Context("when a taskrun fails with an error result", func() { diff --git a/test/integration/clusterbuildstrategy_to_taskruns_test.go b/test/integration/clusterbuildstrategy_to_taskruns_test.go index ca0793257a..f4f436801a 100644 --- a/test/integration/clusterbuildstrategy_to_taskruns_test.go +++ b/test/integration/clusterbuildstrategy_to_taskruns_test.go @@ -8,15 +8,15 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1" test "github.com/shipwright-io/build/test/v1beta1_samples" ) var _ = Describe("Integration tests ClusterBuildStrategies and TaskRuns", func() { var ( - cbsObject *v1beta1.ClusterBuildStrategy - buildObject *v1beta1.Build - buildRunObject *v1beta1.BuildRun + cbsObject *buildapi.ClusterBuildStrategy + buildObject *buildapi.Build + buildRunObject *buildapi.BuildRun buildSample []byte buildRunSample []byte ) diff --git a/test/utils/v1beta1/buildruns.go b/test/utils/v1beta1/buildruns.go index ed6e251dda..3cd8dffe75 100644 --- a/test/utils/v1beta1/buildruns.go +++ b/test/utils/v1beta1/buildruns.go @@ -11,17 +11,16 @@ import ( "fmt" "time" + buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/wait" - - "github.com/shipwright-io/build/pkg/apis/build/v1beta1" ) // This class is intended to host all CRUD calls for testing BuildRun CRDs resources // CreateBR generates a BuildRun on the current test namespace -func (t *TestBuild) CreateBR(buildRun *v1beta1.BuildRun) error { +func (t *TestBuild) CreateBR(buildRun *buildapi.BuildRun) error { brInterface := t.BuildClientSet.ShipwrightV1beta1().BuildRuns(t.Namespace) _, err := brInterface.Create(t.Context, buildRun, metav1.CreateOptions{}) @@ -32,7 +31,7 @@ func (t *TestBuild) CreateBR(buildRun *v1beta1.BuildRun) error { } // UpdateBR updates a BuildRun on the current test namespace -func (t *TestBuild) UpdateBR(buildRun *v1beta1.BuildRun) error { +func (t *TestBuild) UpdateBR(buildRun *buildapi.BuildRun) error { brInterface := t.BuildClientSet.ShipwrightV1beta1().BuildRuns(t.Namespace) _, err := brInterface.Update(t.Context, buildRun, metav1.UpdateOptions{}) if err != nil { @@ -43,7 +42,7 @@ func (t *TestBuild) UpdateBR(buildRun *v1beta1.BuildRun) error { // GetBR retrieves a BuildRun from a desired namespace // Deprecated: Use LookupBuildRun instead. -func (t *TestBuild) GetBR(name string) (*v1beta1.BuildRun, error) { +func (t *TestBuild) GetBR(name string) (*buildapi.BuildRun, error) { brInterface := t.BuildClientSet.ShipwrightV1beta1().BuildRuns(t.Namespace) br, err := brInterface.Get(t.Context, name, metav1.GetOptions{}) @@ -70,7 +69,7 @@ func (t *TestBuild) GetBRReason(name string) (string, error) { if err != nil { return "", err } - cond := br.Status.GetCondition(v1beta1.Succeeded) + cond := br.Status.GetCondition(buildapi.Succeeded) if cond == nil { return "", errors.New("BuildRun had no Succeeded condition") } @@ -80,7 +79,7 @@ func (t *TestBuild) GetBRReason(name string) (string, error) { // GetBRTillCompletion returns a BuildRun that have a CompletionTime set. // If the timeout is reached or it fails when retrieving the BuildRun it will // stop polling and return -func (t *TestBuild) GetBRTillCompletion(name string) (*v1beta1.BuildRun, error) { +func (t *TestBuild) GetBRTillCompletion(name string) (*buildapi.BuildRun, error) { var ( pollBRTillCompletion = func(ctx context.Context) (bool, error) { @@ -110,7 +109,7 @@ func (t *TestBuild) GetBRTillCompletion(name string) (*v1beta1.BuildRun, error) } // GetBRTillNotFound waits for the buildrun to get deleted. It returns an error if BuildRun is not found -func (t *TestBuild) GetBRTillNotFound(name string, interval time.Duration, timeout time.Duration) (*v1beta1.BuildRun, error) { +func (t *TestBuild) GetBRTillNotFound(name string, interval time.Duration, timeout time.Duration) (*buildapi.BuildRun, error) { var ( GetBRTillNotFound = func(ctx context.Context) (bool, error) { @@ -137,7 +136,7 @@ func (t *TestBuild) GetBRTillNotFound(name string, interval time.Duration, timeo // GetBRTillNotOwner returns a BuildRun that has not an owner. // If the timeout is reached or it fails when retrieving the BuildRun it will // stop polling and return -func (t *TestBuild) GetBRTillNotOwner(name string, owner string) (*v1beta1.BuildRun, error) { +func (t *TestBuild) GetBRTillNotOwner(name string, owner string) (*buildapi.BuildRun, error) { brInterface := t.BuildClientSet.ShipwrightV1beta1().BuildRuns(t.Namespace) @@ -169,7 +168,7 @@ func (t *TestBuild) GetBRTillNotOwner(name string, owner string) (*v1beta1.Build // GetBRTillOwner returns a BuildRun that has an owner. // If the timeout is reached or it fails when retrieving the BuildRun it will // stop polling and return -func (t *TestBuild) GetBRTillOwner(name string, owner string) (*v1beta1.BuildRun, error) { +func (t *TestBuild) GetBRTillOwner(name string, owner string) (*buildapi.BuildRun, error) { brInterface := t.BuildClientSet.ShipwrightV1beta1().BuildRuns(t.Namespace) @@ -201,7 +200,7 @@ func (t *TestBuild) GetBRTillOwner(name string, owner string) (*v1beta1.BuildRun // GetBRTillStartTime returns a BuildRun that have a StartTime set. // If the timeout is reached or it fails when retrieving the BuildRun it will // stop polling and return -func (t *TestBuild) GetBRTillStartTime(name string) (*v1beta1.BuildRun, error) { +func (t *TestBuild) GetBRTillStartTime(name string) (*buildapi.BuildRun, error) { var ( pollBRTillCompletion = func(ctx context.Context) (bool, error) { diff --git a/test/utils/v1beta1/builds.go b/test/utils/v1beta1/builds.go index 8e1f786902..d4a16dd031 100644 --- a/test/utils/v1beta1/builds.go +++ b/test/utils/v1beta1/builds.go @@ -14,13 +14,13 @@ import ( "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/wait" - "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1" ) // This class is intended to host all CRUD calls for testing Build CRDs resources // CreateBuild generates a Build on the current test namespace -func (t *TestBuild) CreateBuild(build *v1beta1.Build) error { +func (t *TestBuild) CreateBuild(build *buildapi.Build) error { bInterface := t.BuildClientSet.ShipwrightV1beta1().Builds(t.Namespace) _, err := bInterface.Create(t.Context, build, metav1.CreateOptions{}) @@ -28,7 +28,7 @@ func (t *TestBuild) CreateBuild(build *v1beta1.Build) error { } // UpdateBR updates a BuildRun on the current test namespace -func (t *TestBuild) UpdateBuild(build *v1beta1.Build) error { +func (t *TestBuild) UpdateBuild(build *buildapi.Build) error { brInterface := t.BuildClientSet.ShipwrightV1beta1().Builds(t.Namespace) _, err := brInterface.Update(t.Context, build, metav1.UpdateOptions{}) if err != nil { @@ -48,23 +48,23 @@ func (t *TestBuild) DeleteBuild(name string) error { // GetBuild returns a Build based on name // Deprecated: Use LookupBuild instead -func (t *TestBuild) GetBuild(name string) (*v1beta1.Build, error) { +func (t *TestBuild) GetBuild(name string) (*buildapi.Build, error) { return t.BuildClientSet.ShipwrightV1beta1(). Builds(t.Namespace).Get(t.Context, name, metav1.GetOptions{}) } // ListBuilds returns existing Builds from the desired namespace -func (t *TestBuild) ListBuilds(namespace string) (*v1beta1.BuildList, error) { +func (t *TestBuild) ListBuilds(namespace string) (*buildapi.BuildList, error) { return t.BuildClientSet.ShipwrightV1beta1().Builds(namespace).List(t.Context, metav1.ListOptions{}) } // PatchBuild patches an existing Build using the merge patch type -func (t *TestBuild) PatchBuild(buildName string, data []byte) (*v1beta1.Build, error) { +func (t *TestBuild) PatchBuild(buildName string, data []byte) (*buildapi.Build, error) { return t.PatchBuildWithPatchType(buildName, data, types.MergePatchType) } // PatchBuildWithPatchType patches an existing Build and allows specifying the patch type -func (t *TestBuild) PatchBuildWithPatchType(buildName string, data []byte, pt types.PatchType) (*v1beta1.Build, error) { +func (t *TestBuild) PatchBuildWithPatchType(buildName string, data []byte, pt types.PatchType) (*buildapi.Build, error) { bInterface := t.BuildClientSet.ShipwrightV1beta1().Builds(t.Namespace) b, err := bInterface.Patch(t.Context, buildName, pt, data, metav1.PatchOptions{}) if err != nil { @@ -76,7 +76,7 @@ func (t *TestBuild) PatchBuildWithPatchType(buildName string, data []byte, pt ty // GetBuildTillValidation polls until a Build gets a validation and updates // it´s registered field. If timeout is reached or an error is found, it will // return with an error -func (t *TestBuild) GetBuildTillValidation(name string) (build *v1beta1.Build, err error) { +func (t *TestBuild) GetBuildTillValidation(name string) (build *buildapi.Build, err error) { err = wait.PollUntilContextTimeout(t.Context, t.Interval, t.TimeOut, true, func(_ context.Context) (bool, error) { build, err = t.LookupBuild(types.NamespacedName{Namespace: t.Namespace, Name: name}) if err != nil && !apierrors.IsNotFound(err) { @@ -97,7 +97,7 @@ func (t *TestBuild) GetBuildTillValidation(name string) (build *v1beta1.Build, e // GetBuildTillRegistration polls until a Build gets a desired validation and updates // it´s registered field. If timeout is reached or an error is found, it will // return with an error -func (t *TestBuild) GetBuildTillRegistration(name string, condition corev1.ConditionStatus) (*v1beta1.Build, error) { +func (t *TestBuild) GetBuildTillRegistration(name string, condition corev1.ConditionStatus) (*buildapi.Build, error) { var ( pollBuildTillRegistration = func(ctx context.Context) (bool, error) { @@ -129,7 +129,7 @@ func (t *TestBuild) GetBuildTillRegistration(name string, condition corev1.Condi // GetBuildTillMessageContainsSubstring polls until a Build message contains the desired // substring value and updates it´s registered field. If timeout is reached or an error is found, // it will return with an error -func (t *TestBuild) GetBuildTillMessageContainsSubstring(name string, partOfMessage string) (*v1beta1.Build, error) { +func (t *TestBuild) GetBuildTillMessageContainsSubstring(name string, partOfMessage string) (*buildapi.Build, error) { var ( pollBuildTillMessageContainsSubString = func(ctx context.Context) (bool, error) { diff --git a/test/utils/v1beta1/buildstrategies.go b/test/utils/v1beta1/buildstrategies.go index 151ed18ce9..24bfcc5618 100644 --- a/test/utils/v1beta1/buildstrategies.go +++ b/test/utils/v1beta1/buildstrategies.go @@ -7,13 +7,13 @@ package utils import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1" ) // This class is intended to host all CRUD calls for testing BuildStrategy CRDs resources // CreateBuildStrategy generates a BuildStrategy on the current test namespace -func (t *TestBuild) CreateBuildStrategy(bs *v1beta1.BuildStrategy) error { +func (t *TestBuild) CreateBuildStrategy(bs *buildapi.BuildStrategy) error { bsInterface := t.BuildClientSet.ShipwrightV1beta1().BuildStrategies(t.Namespace) _, err := bsInterface.Create(t.Context, bs, metav1.CreateOptions{}) diff --git a/test/utils/v1beta1/clusterbuildstrategies.go b/test/utils/v1beta1/clusterbuildstrategies.go index 0562277026..fc0ec4a2cb 100644 --- a/test/utils/v1beta1/clusterbuildstrategies.go +++ b/test/utils/v1beta1/clusterbuildstrategies.go @@ -7,13 +7,13 @@ package utils import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1" ) // This class is intended to host all CRUD calls for testing ClusterBuildStrategy CRDs resources // CreateClusterBuildStrategy generates a ClusterBuildStrategy on the current test namespace -func (t *TestBuild) CreateClusterBuildStrategy(cbs *v1beta1.ClusterBuildStrategy) error { +func (t *TestBuild) CreateClusterBuildStrategy(cbs *buildapi.ClusterBuildStrategy) error { cbsInterface := t.BuildClientSet.ShipwrightV1beta1().ClusterBuildStrategies() _, err := cbsInterface.Create(t.Context, cbs, metav1.CreateOptions{}) diff --git a/test/utils/v1beta1/image.go b/test/utils/v1beta1/image.go index cc1c9ab104..62792c2dbf 100644 --- a/test/utils/v1beta1/image.go +++ b/test/utils/v1beta1/image.go @@ -14,13 +14,13 @@ import ( "github.com/google/go-containerregistry/pkg/name" containerreg "github.com/google/go-containerregistry/pkg/v1" "github.com/google/go-containerregistry/pkg/v1/remote" - buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "k8s.io/apimachinery/pkg/types" . "github.com/onsi/gomega" ) -func getImageURL(buildRun *buildv1beta1.BuildRun) string { +func getImageURL(buildRun *buildapi.BuildRun) string { image := "" if buildRun.Spec.Output != nil && buildRun.Spec.Output.Image != "" { image = buildRun.Spec.Output.Image @@ -41,7 +41,7 @@ func getImageURL(buildRun *buildv1beta1.BuildRun) string { } // GetImage loads the image manifest for the image produced by a BuildRun -func (t *TestBuild) GetImage(buildRun *buildv1beta1.BuildRun) containerreg.Image { +func (t *TestBuild) GetImage(buildRun *buildapi.BuildRun) containerreg.Image { ref, err := name.ParseReference(getImageURL(buildRun)) Expect(err).ToNot(HaveOccurred()) @@ -52,7 +52,7 @@ func (t *TestBuild) GetImage(buildRun *buildv1beta1.BuildRun) containerreg.Image } func (t *TestBuild) getRegistryAuthentication( - buildRun *buildv1beta1.BuildRun, + buildRun *buildapi.BuildRun, ref name.Reference, ) authn.Authenticator { secretName := "" @@ -94,7 +94,7 @@ func (t *TestBuild) getRegistryAuthentication( } // ValidateImagePlatformsExist that the image produced by a BuildRun exists for a set of platforms -func (t *TestBuild) ValidateImagePlatformsExist(buildRun *buildv1beta1.BuildRun, expectedPlatforms []containerreg.Platform) { +func (t *TestBuild) ValidateImagePlatformsExist(buildRun *buildapi.BuildRun, expectedPlatforms []containerreg.Platform) { ref, err := name.ParseReference(getImageURL(buildRun)) Expect(err).ToNot(HaveOccurred()) @@ -105,7 +105,7 @@ func (t *TestBuild) ValidateImagePlatformsExist(buildRun *buildv1beta1.BuildRun, } // ValidateImageDigest ensures that an image digest is set in the BuildRun status and that this digest is pointing to an image -func (t *TestBuild) ValidateImageDigest(buildRun *buildv1beta1.BuildRun) { +func (t *TestBuild) ValidateImageDigest(buildRun *buildapi.BuildRun) { // Verify that the status contains a digest Expect(buildRun.Status.Output).NotTo(BeNil(), ".status.output is nil") Expect(buildRun.Status.Output.Digest).NotTo(Equal(""), ".status.output.digest is empty") diff --git a/test/utils/v1beta1/lookup.go b/test/utils/v1beta1/lookup.go index 067368dd3b..fe0c45275c 100644 --- a/test/utils/v1beta1/lookup.go +++ b/test/utils/v1beta1/lookup.go @@ -19,7 +19,7 @@ import ( "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/wait" - buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1" ) func (t *TestBuild) LookupSecret(entity types.NamespacedName) (*corev1.Secret, error) { @@ -44,22 +44,22 @@ func (t *TestBuild) LookupPod(entity types.NamespacedName) (*corev1.Pod, error) return result.(*corev1.Pod), err } -func (t *TestBuild) LookupBuild(entity types.NamespacedName) (*buildv1beta1.Build, error) { +func (t *TestBuild) LookupBuild(entity types.NamespacedName) (*buildapi.Build, error) { result, err := t.lookupRuntimeObject(func(ctx context.Context) (runtime.Object, error) { return t.BuildClientSet.ShipwrightV1beta1(). Builds(entity.Namespace).Get(ctx, entity.Name, metav1.GetOptions{}) }) - return result.(*buildv1beta1.Build), err + return result.(*buildapi.Build), err } -func (t *TestBuild) LookupBuildRun(entity types.NamespacedName) (*buildv1beta1.BuildRun, error) { +func (t *TestBuild) LookupBuildRun(entity types.NamespacedName) (*buildapi.BuildRun, error) { result, err := t.lookupRuntimeObject(func(ctx context.Context) (runtime.Object, error) { return t.BuildClientSet.ShipwrightV1beta1(). BuildRuns(entity.Namespace).Get(ctx, entity.Name, metav1.GetOptions{}) }) - return result.(*buildv1beta1.BuildRun), err + return result.(*buildapi.BuildRun), err } func (t *TestBuild) LookupTaskRun(entity types.NamespacedName) (*pipelineapi.TaskRun, error) { @@ -73,7 +73,7 @@ func (t *TestBuild) LookupTaskRun(entity types.NamespacedName) (*pipelineapi.Tas return result.(*pipelineapi.TaskRun), err } -func (t *TestBuild) LookupTaskRunUsingBuildRun(buildRun *buildv1beta1.BuildRun) (*pipelineapi.TaskRun, error) { +func (t *TestBuild) LookupTaskRunUsingBuildRun(buildRun *buildapi.BuildRun) (*pipelineapi.TaskRun, error) { if buildRun == nil { return nil, fmt.Errorf("no BuildRun specified to lookup TaskRun") } @@ -89,7 +89,7 @@ func (t *TestBuild) LookupTaskRunUsingBuildRun(buildRun *buildv1beta1.BuildRun) List(ctx, metav1.ListOptions{ LabelSelector: labels.SelectorFromSet( map[string]string{ - buildv1beta1.LabelBuildRun: buildRun.Name, + buildapi.LabelBuildRun: buildRun.Name, }).String(), }) }) diff --git a/test/v1beta1_samples/catalog.go b/test/v1beta1_samples/catalog.go index cfccee9b8b..e671db36e8 100644 --- a/test/v1beta1_samples/catalog.go +++ b/test/v1beta1_samples/catalog.go @@ -25,7 +25,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/yaml" - build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1" ) // Catalog allows you to access helper functions @@ -37,7 +37,7 @@ func (c *Catalog) SecretWithAnnotation(name string, ns string) *corev1.Secret { ObjectMeta: metav1.ObjectMeta{ Name: name, Namespace: ns, - Annotations: map[string]string{build.AnnotationBuildRefSecret: "true"}, + Annotations: map[string]string{buildapi.AnnotationBuildRefSecret: "true"}, }, } } @@ -89,26 +89,26 @@ func (c *Catalog) ConfigMapWithData(name string, ns string, data map[string]stri } // BuildWithClusterBuildStrategyAndFalseSourceAnnotation gives you an specific Build CRD -func (c *Catalog) BuildWithClusterBuildStrategyAndFalseSourceAnnotation(name string, ns string, strategyName string) *build.Build { - buildStrategy := build.ClusterBuildStrategyKind - return &build.Build{ +func (c *Catalog) BuildWithClusterBuildStrategyAndFalseSourceAnnotation(name string, ns string, strategyName string) *buildapi.Build { + buildStrategy := buildapi.ClusterBuildStrategyKind + return &buildapi.Build{ ObjectMeta: metav1.ObjectMeta{ Name: name, Namespace: ns, - Annotations: map[string]string{build.AnnotationBuildVerifyRepository: "false"}, + Annotations: map[string]string{buildapi.AnnotationBuildVerifyRepository: "false"}, }, - Spec: build.BuildSpec{ - Source: &build.Source{ - Git: &build.Git{ + Spec: buildapi.BuildSpec{ + Source: &buildapi.Source{ + Git: &buildapi.Git{ URL: "foobar", }, - Type: build.GitType, + Type: buildapi.GitType, }, - Strategy: build.Strategy{ + Strategy: buildapi.Strategy{ Name: strategyName, Kind: &buildStrategy, }, - Output: build.Image{ + Output: buildapi.Image{ Image: "foobar", }, }, @@ -116,25 +116,25 @@ func (c *Catalog) BuildWithClusterBuildStrategyAndFalseSourceAnnotation(name str } // BuildWithClusterBuildStrategy gives you an specific Build CRD -func (c *Catalog) BuildWithClusterBuildStrategy(name string, ns string, strategyName string, secretName string) *build.Build { - buildStrategy := build.ClusterBuildStrategyKind - return &build.Build{ +func (c *Catalog) BuildWithClusterBuildStrategy(name string, ns string, strategyName string, secretName string) *buildapi.Build { + buildStrategy := buildapi.ClusterBuildStrategyKind + return &buildapi.Build{ ObjectMeta: metav1.ObjectMeta{ Name: name, Namespace: ns, }, - Spec: build.BuildSpec{ - Source: &build.Source{ - Git: &build.Git{ + Spec: buildapi.BuildSpec{ + Source: &buildapi.Source{ + Git: &buildapi.Git{ URL: "https://github.com/shipwright-io/sample-go", }, - Type: build.GitType, + Type: buildapi.GitType, }, - Strategy: build.Strategy{ + Strategy: buildapi.Strategy{ Name: strategyName, Kind: &buildStrategy, }, - Output: build.Image{ + Output: buildapi.Image{ Image: "foobar", PushSecret: &secretName, }, @@ -143,27 +143,27 @@ func (c *Catalog) BuildWithClusterBuildStrategy(name string, ns string, strategy } // BuildWithClusterBuildStrategyAndSourceSecret gives you an specific Build CRD -func (c *Catalog) BuildWithClusterBuildStrategyAndSourceSecret(name string, ns string, strategyName string) *build.Build { - buildStrategy := build.ClusterBuildStrategyKind +func (c *Catalog) BuildWithClusterBuildStrategyAndSourceSecret(name string, ns string, strategyName string) *buildapi.Build { + buildStrategy := buildapi.ClusterBuildStrategyKind secret := "foobar" - return &build.Build{ + return &buildapi.Build{ ObjectMeta: metav1.ObjectMeta{ Name: name, Namespace: ns, }, - Spec: build.BuildSpec{ - Source: &build.Source{ - Git: &build.Git{ + Spec: buildapi.BuildSpec{ + Source: &buildapi.Source{ + Git: &buildapi.Git{ URL: "https://github.com/shipwright-io/sample-go", CloneSecret: &secret, }, - Type: build.GitType, + Type: buildapi.GitType, }, - Strategy: build.Strategy{ + Strategy: buildapi.Strategy{ Name: strategyName, Kind: &buildStrategy, }, - Output: build.Image{ + Output: buildapi.Image{ Image: "foobar", }, }, @@ -171,21 +171,21 @@ func (c *Catalog) BuildWithClusterBuildStrategyAndSourceSecret(name string, ns s } // BuildWithBuildStrategy gives you an specific Build CRD -func (c *Catalog) BuildWithBuildStrategy(name string, ns string, strategyName string) *build.Build { - buildStrategy := build.NamespacedBuildStrategyKind - return &build.Build{ +func (c *Catalog) BuildWithBuildStrategy(name string, ns string, strategyName string) *buildapi.Build { + buildStrategy := buildapi.NamespacedBuildStrategyKind + return &buildapi.Build{ ObjectMeta: metav1.ObjectMeta{ Name: name, Namespace: ns, }, - Spec: build.BuildSpec{ - Source: &build.Source{ - Git: &build.Git{ + Spec: buildapi.BuildSpec{ + Source: &buildapi.Source{ + Git: &buildapi.Git{ URL: "https://github.com/shipwright-io/sample-go", }, - Type: build.GitType, + Type: buildapi.GitType, }, - Strategy: build.Strategy{ + Strategy: buildapi.Strategy{ Name: strategyName, Kind: &buildStrategy, }, @@ -194,20 +194,20 @@ func (c *Catalog) BuildWithBuildStrategy(name string, ns string, strategyName st } // BuildWithNilBuildStrategyKind gives you an Build CRD with nil build strategy kind -func (c *Catalog) BuildWithNilBuildStrategyKind(name string, ns string, strategyName string) *build.Build { - return &build.Build{ +func (c *Catalog) BuildWithNilBuildStrategyKind(name string, ns string, strategyName string) *buildapi.Build { + return &buildapi.Build{ ObjectMeta: metav1.ObjectMeta{ Name: name, Namespace: ns, }, - Spec: build.BuildSpec{ - Source: &build.Source{ - Git: &build.Git{ + Spec: buildapi.BuildSpec{ + Source: &buildapi.Source{ + Git: &buildapi.Git{ URL: "https://github.com/shipwright-io/sample-go", }, - Type: build.GitType, + Type: buildapi.GitType, }, - Strategy: build.Strategy{ + Strategy: buildapi.Strategy{ Name: strategyName, }, }, @@ -215,20 +215,20 @@ func (c *Catalog) BuildWithNilBuildStrategyKind(name string, ns string, strategy } // BuildWithOutputSecret .... -func (c *Catalog) BuildWithOutputSecret(name string, ns string, secretName string) *build.Build { - return &build.Build{ +func (c *Catalog) BuildWithOutputSecret(name string, ns string, secretName string) *buildapi.Build { + return &buildapi.Build{ ObjectMeta: metav1.ObjectMeta{ Name: name, Namespace: ns, }, - Spec: build.BuildSpec{ - Source: &build.Source{ - Git: &build.Git{ + Spec: buildapi.BuildSpec{ + Source: &buildapi.Source{ + Git: &buildapi.Git{ URL: "https://github.com/shipwright-io/sample-go", }, - Type: build.GitType, + Type: buildapi.GitType, }, - Output: build.Image{ + Output: buildapi.Image{ PushSecret: &secretName, }, }, @@ -236,8 +236,8 @@ func (c *Catalog) BuildWithOutputSecret(name string, ns string, secretName strin } // ClusterBuildStrategy to support tests -func (c *Catalog) ClusterBuildStrategy(name string) *build.ClusterBuildStrategy { - return &build.ClusterBuildStrategy{ +func (c *Catalog) ClusterBuildStrategy(name string) *buildapi.ClusterBuildStrategy { + return &buildapi.ClusterBuildStrategy{ ObjectMeta: metav1.ObjectMeta{ Name: name, }, @@ -252,10 +252,10 @@ 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.SubResourceUpdateOption) error { +func (c *Catalog) StubFunc(status corev1.ConditionStatus, reason buildapi.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: + case *buildapi.Build: Expect(*object.Status.Registered).To(Equal(status)) Expect(*object.Status.Reason).To(Equal(reason)) Expect(*object.Status.Message).To(Equal(message)) @@ -269,7 +269,7 @@ func (c *Catalog) StubFunc(status corev1.ConditionStatus, reason build.BuildReas func (c *Catalog) StubBuildUpdateOwnerReferences(ownerKind string, ownerName string, isOwnerController *bool, blockOwnerDeletion *bool) func(context context.Context, object client.Object, _ ...client.UpdateOption) error { return func(context context.Context, object client.Object, _ ...client.UpdateOption) error { switch object := object.(type) { - case *build.BuildRun: + case *buildapi.BuildRun: Expect(object.OwnerReferences[0].Kind).To(Equal(ownerKind)) Expect(object.OwnerReferences[0].Name).To(Equal(ownerName)) Expect(object.OwnerReferences[0].Controller).To(Equal(isOwnerController)) @@ -283,11 +283,11 @@ func (c *Catalog) StubBuildUpdateOwnerReferences(ownerKind string, ownerName str // StubBuildRun is used to simulate the existence of a BuildRun // only when there is a client GET on this object type func (c *Catalog) StubBuildRun( - b *build.BuildRun, + b *buildapi.BuildRun, ) func(context context.Context, nn types.NamespacedName, object client.Object, getOptions ...client.GetOption) error { return func(context context.Context, nn types.NamespacedName, object client.Object, getOptions ...client.GetOption) error { switch object := object.(type) { - case *build.BuildRun: + case *buildapi.BuildRun: b.DeepCopyInto(object) return nil } @@ -298,12 +298,12 @@ func (c *Catalog) StubBuildRun( // StubBuildRunAndTaskRun is used to simulate the existence of a BuildRun // and a TaskRun when there is a client GET on this two objects func (c *Catalog) StubBuildRunAndTaskRun( - b *build.BuildRun, + b *buildapi.BuildRun, tr *pipelineapi.TaskRun, ) func(context context.Context, nn types.NamespacedName, object client.Object, getOptions ...client.GetOption) error { return func(context context.Context, nn types.NamespacedName, object client.Object, getOptions ...client.GetOption) error { switch object := object.(type) { - case *build.BuildRun: + case *buildapi.BuildRun: b.DeepCopyInto(object) return nil case *pipelineapi.TaskRun: @@ -317,12 +317,12 @@ func (c *Catalog) StubBuildRunAndTaskRun( // StubBuildAndTaskRun is used to simulate the existence of a Build // and a TaskRun when there is a client GET on this two objects func (c *Catalog) StubBuildAndTaskRun( - b *build.Build, + b *buildapi.Build, tr *pipelineapi.TaskRun, ) func(context context.Context, nn types.NamespacedName, object client.Object, getOptions ...client.GetOption) error { return func(context context.Context, nn types.NamespacedName, object client.Object, getOptions ...client.GetOption) error { switch object := object.(type) { - case *build.Build: + case *buildapi.Build: b.DeepCopyInto(object) return nil case *pipelineapi.TaskRun: @@ -334,10 +334,10 @@ 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.SubResourceUpdateOption) error { +func (c *Catalog) StubBuildStatusReason(reason buildapi.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: + case *buildapi.Build: if object.Status.Message != nil && *object.Status.Message != "" { Expect(*object.Status.Message).To(Equal(message)) } @@ -350,13 +350,13 @@ 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.SubResourceUpdateOption) error { +func (c *Catalog) StubBuildRunStatus(reason string, name *string, condition buildapi.Condition, status corev1.ConditionStatus, buildSpec buildapi.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: + case *buildapi.BuildRun: if !tolerateEmptyStatus { - Expect(object.Status.GetCondition(build.Succeeded).Status).To(Equal(condition.Status)) - Expect(object.Status.GetCondition(build.Succeeded).Reason).To(Equal(condition.Reason)) + Expect(object.Status.GetCondition(buildapi.Succeeded).Status).To(Equal(condition.Status)) + Expect(object.Status.GetCondition(buildapi.Succeeded).Reason).To(Equal(condition.Reason)) Expect(object.Status.TaskRunName).To(Equal(name)) } if object.Status.BuildSpec != nil { @@ -368,12 +368,12 @@ func (c *Catalog) StubBuildRunStatus(reason string, name *string, condition buil } // StubBuildRunLabel asserts Label fields on a BuildRun resource -func (c *Catalog) StubBuildRunLabel(buildSample *build.Build) func(context context.Context, object client.Object, _ ...client.UpdateOption) error { +func (c *Catalog) StubBuildRunLabel(buildSample *buildapi.Build) func(context context.Context, object client.Object, _ ...client.UpdateOption) error { return func(context context.Context, object client.Object, _ ...client.UpdateOption) error { switch object := object.(type) { - case *build.BuildRun: - Expect(object.Labels[build.LabelBuild]).To(Equal(buildSample.Name)) - Expect(object.Labels[build.LabelBuildGeneration]).To(Equal(strconv.FormatInt(buildSample.Generation, 10))) + case *buildapi.BuildRun: + Expect(object.Labels[buildapi.LabelBuild]).To(Equal(buildSample.Name)) + Expect(object.Labels[buildapi.LabelBuildGeneration]).To(Equal(strconv.FormatInt(buildSample.Generation, 10))) } return nil } @@ -382,15 +382,15 @@ func (c *Catalog) StubBuildRunLabel(buildSample *build.Build) func(context conte // StubBuildRunGetWithoutSA simulates the output of client GET calls // for the BuildRun unit tests func (c *Catalog) StubBuildRunGetWithoutSA( - b *build.Build, - br *build.BuildRun, + b *buildapi.Build, + br *buildapi.BuildRun, ) func(context context.Context, nn types.NamespacedName, object client.Object, getOptions ...client.GetOption) error { return func(context context.Context, nn types.NamespacedName, object client.Object, getOptions ...client.GetOption) error { switch object := object.(type) { - case *build.Build: + case *buildapi.Build: b.DeepCopyInto(object) return nil - case *build.BuildRun: + case *buildapi.BuildRun: br.DeepCopyInto(object) return nil } @@ -401,17 +401,17 @@ func (c *Catalog) StubBuildRunGetWithoutSA( // StubBuildRunGetWithTaskRunAndSA returns fake object for different // client calls func (c *Catalog) StubBuildRunGetWithTaskRunAndSA( - b *build.Build, - br *build.BuildRun, + b *buildapi.Build, + br *buildapi.BuildRun, tr *pipelineapi.TaskRun, sa *corev1.ServiceAccount, ) func(context context.Context, nn types.NamespacedName, object client.Object, getOptions ...client.GetOption) error { return func(context context.Context, nn types.NamespacedName, object client.Object, getOptions ...client.GetOption) error { switch object := object.(type) { - case *build.Build: + case *buildapi.Build: b.DeepCopyInto(object) return nil - case *build.BuildRun: + case *buildapi.BuildRun: br.DeepCopyInto(object) return nil case *pipelineapi.TaskRun: @@ -428,16 +428,16 @@ func (c *Catalog) StubBuildRunGetWithTaskRunAndSA( // StubBuildRunGetWithSA returns fake object for different // client calls func (c *Catalog) StubBuildRunGetWithSA( - b *build.Build, - br *build.BuildRun, + b *buildapi.Build, + br *buildapi.BuildRun, sa *corev1.ServiceAccount, ) func(context context.Context, nn types.NamespacedName, object client.Object, getOptions ...client.GetOption) error { return func(context context.Context, nn types.NamespacedName, object client.Object, getOptions ...client.GetOption) error { switch object := object.(type) { - case *build.Build: + case *buildapi.Build: b.DeepCopyInto(object) return nil - case *build.BuildRun: + case *buildapi.BuildRun: br.DeepCopyInto(object) return nil case *corev1.ServiceAccount: @@ -451,20 +451,20 @@ func (c *Catalog) StubBuildRunGetWithSA( // StubBuildRunGetWithSAandStrategies simulates the output of client GET // calls for the BuildRun unit tests func (c *Catalog) StubBuildRunGetWithSAandStrategies( - b *build.Build, - br *build.BuildRun, + b *buildapi.Build, + br *buildapi.BuildRun, sa *corev1.ServiceAccount, - cb *build.ClusterBuildStrategy, - bs *build.BuildStrategy, + cb *buildapi.ClusterBuildStrategy, + bs *buildapi.BuildStrategy, ) func(context context.Context, nn types.NamespacedName, object client.Object, getOptions ...client.GetOption) error { return func(context context.Context, nn types.NamespacedName, object client.Object, getOptions ...client.GetOption) error { switch object := object.(type) { - case *build.Build: + case *buildapi.Build: if b != nil { b.DeepCopyInto(object) return nil } - case *build.BuildRun: + case *buildapi.BuildRun: if br != nil { br.DeepCopyInto(object) return nil @@ -474,12 +474,12 @@ func (c *Catalog) StubBuildRunGetWithSAandStrategies( sa.DeepCopyInto(object) return nil } - case *build.ClusterBuildStrategy: + case *buildapi.ClusterBuildStrategy: if cb != nil { cb.DeepCopyInto(object) return nil } - case *build.BuildStrategy: + case *buildapi.BuildStrategy: if bs != nil { bs.DeepCopyInto(object) return nil @@ -490,27 +490,27 @@ func (c *Catalog) StubBuildRunGetWithSAandStrategies( } func (c *Catalog) StubBuildCRDs( - b *build.Build, - br *build.BuildRun, + b *buildapi.Build, + br *buildapi.BuildRun, sa *corev1.ServiceAccount, - cb *build.ClusterBuildStrategy, - bs *build.BuildStrategy, + cb *buildapi.ClusterBuildStrategy, + bs *buildapi.BuildStrategy, ) func(context context.Context, nn types.NamespacedName, object client.Object, getOptions ...client.GetOption) error { return func(context context.Context, nn types.NamespacedName, object client.Object, getOptions ...client.GetOption) error { switch object := object.(type) { - case *build.Build: + case *buildapi.Build: b.DeepCopyInto(object) return nil - case *build.BuildRun: + case *buildapi.BuildRun: br.DeepCopyInto(object) return nil case *corev1.ServiceAccount: sa.DeepCopyInto(object) return nil - case *build.ClusterBuildStrategy: + case *buildapi.ClusterBuildStrategy: cb.DeepCopyInto(object) return nil - case *build.BuildStrategy: + case *buildapi.BuildStrategy: bs.DeepCopyInto(object) return nil } @@ -521,29 +521,29 @@ func (c *Catalog) StubBuildCRDs( // StubBuildCRDsPodAndTaskRun stubs different objects in case a client // GET call is executed against them func (c *Catalog) StubBuildCRDsPodAndTaskRun( - b *build.Build, - br *build.BuildRun, + b *buildapi.Build, + br *buildapi.BuildRun, sa *corev1.ServiceAccount, - cb *build.ClusterBuildStrategy, - bs *build.BuildStrategy, + cb *buildapi.ClusterBuildStrategy, + bs *buildapi.BuildStrategy, tr *pipelineapi.TaskRun, pod *corev1.Pod, ) func(context context.Context, nn types.NamespacedName, object client.Object, getOptions ...client.GetOption) error { return func(context context.Context, nn types.NamespacedName, object client.Object, getOptions ...client.GetOption) error { switch object := object.(type) { - case *build.Build: + case *buildapi.Build: b.DeepCopyInto(object) return nil - case *build.BuildRun: + case *buildapi.BuildRun: br.DeepCopyInto(object) return nil case *corev1.ServiceAccount: sa.DeepCopyInto(object) return nil - case *build.ClusterBuildStrategy: + case *buildapi.ClusterBuildStrategy: cb.DeepCopyInto(object) return nil - case *build.BuildStrategy: + case *buildapi.BuildStrategy: bs.DeepCopyInto(object) return nil case *pipelineapi.TaskRun: @@ -684,117 +684,117 @@ func (c *Catalog) DefaultTaskRunWithFalseStatus(trName string, buildRunName stri } // DefaultBuild returns a minimal Build object -func (c *Catalog) DefaultBuild(buildName string, strategyName string, strategyKind build.BuildStrategyKind) *build.Build { - return &build.Build{ +func (c *Catalog) DefaultBuild(buildName string, strategyName string, strategyKind buildapi.BuildStrategyKind) *buildapi.Build { + return &buildapi.Build{ ObjectMeta: metav1.ObjectMeta{ Name: buildName, }, - Spec: build.BuildSpec{ - Strategy: build.Strategy{ + Spec: buildapi.BuildSpec{ + Strategy: buildapi.Strategy{ Name: strategyName, Kind: &strategyKind, }, }, - Status: build.BuildStatus{ - Registered: build.ConditionStatusPtr(corev1.ConditionTrue), + Status: buildapi.BuildStatus{ + Registered: buildapi.ConditionStatusPtr(corev1.ConditionTrue), }, } } // BuildWithoutStrategyKind returns a minimal Build object without an strategy kind definition -func (c *Catalog) BuildWithoutStrategyKind(buildName string, strategyName string) *build.Build { - return &build.Build{ +func (c *Catalog) BuildWithoutStrategyKind(buildName string, strategyName string) *buildapi.Build { + return &buildapi.Build{ ObjectMeta: metav1.ObjectMeta{ Name: buildName, }, - Spec: build.BuildSpec{ - Strategy: build.Strategy{ + Spec: buildapi.BuildSpec{ + Strategy: buildapi.Strategy{ Name: strategyName, }, }, - Status: build.BuildStatus{ - Registered: build.ConditionStatusPtr(corev1.ConditionTrue), + Status: buildapi.BuildStatus{ + Registered: buildapi.ConditionStatusPtr(corev1.ConditionTrue), }, } } // BuildWithBuildRunDeletions returns a minimal Build object with the // build.shipwright.io/build-run-deletion annotation set to true -func (c *Catalog) BuildWithBuildRunDeletions(buildName string, strategyName string, strategyKind build.BuildStrategyKind) *build.Build { - return &build.Build{ +func (c *Catalog) BuildWithBuildRunDeletions(buildName string, strategyName string, strategyKind buildapi.BuildStrategyKind) *buildapi.Build { + return &buildapi.Build{ ObjectMeta: metav1.ObjectMeta{ Name: buildName, }, - Spec: build.BuildSpec{ - Strategy: build.Strategy{ + Spec: buildapi.BuildSpec{ + Strategy: buildapi.Strategy{ Name: strategyName, Kind: &strategyKind, }, - Retention: &build.BuildRetention{ + Retention: &buildapi.BuildRetention{ AtBuildDeletion: pointer.Bool(true), }, }, - Status: build.BuildStatus{ - Registered: build.ConditionStatusPtr(corev1.ConditionTrue), + Status: buildapi.BuildStatus{ + Registered: buildapi.ConditionStatusPtr(corev1.ConditionTrue), }, } } // BuildWithBuildRunDeletionsAndFakeNS returns a minimal Build object with the // build.shipwright.io/build-run-deletion annotation set to true in a fake namespace -func (c *Catalog) BuildWithBuildRunDeletionsAndFakeNS(buildName string, strategyName string, strategyKind build.BuildStrategyKind) *build.Build { - return &build.Build{ +func (c *Catalog) BuildWithBuildRunDeletionsAndFakeNS(buildName string, strategyName string, strategyKind buildapi.BuildStrategyKind) *buildapi.Build { + return &buildapi.Build{ ObjectMeta: metav1.ObjectMeta{ Name: buildName, Namespace: "fakens", }, - Spec: build.BuildSpec{ - Strategy: build.Strategy{ + Spec: buildapi.BuildSpec{ + Strategy: buildapi.Strategy{ Name: strategyName, Kind: &strategyKind, }, - Retention: &build.BuildRetention{ + Retention: &buildapi.BuildRetention{ AtBuildDeletion: pointer.Bool(true), }, }, - Status: build.BuildStatus{ - Registered: build.ConditionStatusPtr(corev1.ConditionTrue), + Status: buildapi.BuildStatus{ + Registered: buildapi.ConditionStatusPtr(corev1.ConditionTrue), }, } } // DefaultBuildWithFalseRegistered returns a minimal Build object with a FALSE Registered -func (c *Catalog) DefaultBuildWithFalseRegistered(buildName string, strategyName string, strategyKind build.BuildStrategyKind) *build.Build { - return &build.Build{ +func (c *Catalog) DefaultBuildWithFalseRegistered(buildName string, strategyName string, strategyKind buildapi.BuildStrategyKind) *buildapi.Build { + return &buildapi.Build{ ObjectMeta: metav1.ObjectMeta{ Name: buildName, }, - Spec: build.BuildSpec{ - Strategy: build.Strategy{ + Spec: buildapi.BuildSpec{ + Strategy: buildapi.Strategy{ Name: strategyName, Kind: &strategyKind, }, }, - Status: build.BuildStatus{ - Registered: build.ConditionStatusPtr(corev1.ConditionFalse), - Reason: build.BuildReasonPtr("something bad happened"), + Status: buildapi.BuildStatus{ + Registered: buildapi.ConditionStatusPtr(corev1.ConditionFalse), + Reason: buildapi.BuildReasonPtr("something bad happened"), }, } } // DefaultBuildRun returns a minimal BuildRun object -func (c *Catalog) DefaultBuildRun(buildRunName string, buildName string) *build.BuildRun { - var defaultBuild = c.DefaultBuild(buildName, "foobar-strategy", build.ClusterBuildStrategyKind) - return &build.BuildRun{ +func (c *Catalog) DefaultBuildRun(buildRunName string, buildName string) *buildapi.BuildRun { + var defaultBuild = c.DefaultBuild(buildName, "foobar-strategy", buildapi.ClusterBuildStrategyKind) + return &buildapi.BuildRun{ ObjectMeta: metav1.ObjectMeta{ Name: buildRunName, }, - Spec: build.BuildRunSpec{ - Build: build.ReferencedBuild{ + Spec: buildapi.BuildRunSpec{ + Build: buildapi.ReferencedBuild{ Name: &buildName, }, }, - Status: build.BuildRunStatus{ + Status: buildapi.BuildRunStatus{ BuildSpec: &defaultBuild.Spec, }, } @@ -819,23 +819,23 @@ func (c *Catalog) PodWithInitContainerStatus(podName string, initContainerName s // BuildRunWithBuildSnapshot returns BuildRun Object with a populated // BuildSpec in the Status field -func (c *Catalog) BuildRunWithBuildSnapshot(buildRunName string, buildName string) *build.BuildRun { - return &build.BuildRun{ +func (c *Catalog) BuildRunWithBuildSnapshot(buildRunName string, buildName string) *buildapi.BuildRun { + return &buildapi.BuildRun{ ObjectMeta: metav1.ObjectMeta{ Name: buildRunName, CreationTimestamp: metav1.Time{ Time: time.Now(), }, }, - Status: build.BuildRunStatus{ - BuildSpec: &build.BuildSpec{ - Strategy: build.Strategy{ + Status: buildapi.BuildRunStatus{ + BuildSpec: &buildapi.BuildSpec{ + Strategy: buildapi.Strategy{ Name: "foobar", }, }, }, - Spec: build.BuildRunSpec{ - Build: build.ReferencedBuild{ + Spec: buildapi.BuildRunSpec{ + Build: buildapi.ReferencedBuild{ Name: &buildName, }, }, @@ -844,7 +844,7 @@ func (c *Catalog) BuildRunWithBuildSnapshot(buildRunName string, buildName strin // BuildRunWithExistingOwnerReferences returns a BuildRun object that is // already owned by some fake object -func (c *Catalog) BuildRunWithExistingOwnerReferences(buildRunName string, buildName string, ownerName string) *build.BuildRun { +func (c *Catalog) BuildRunWithExistingOwnerReferences(buildRunName string, buildName string, ownerName string) *buildapi.BuildRun { managingController := true @@ -854,13 +854,13 @@ func (c *Catalog) BuildRunWithExistingOwnerReferences(buildRunName string, build Controller: &managingController, } - return &build.BuildRun{ + return &buildapi.BuildRun{ ObjectMeta: metav1.ObjectMeta{ Name: buildRunName, OwnerReferences: []metav1.OwnerReference{fakeOwnerRef}, }, - Spec: build.BuildRunSpec{ - Build: build.ReferencedBuild{ + Spec: buildapi.BuildRunSpec{ + Build: buildapi.ReferencedBuild{ Name: &buildName, }, }, @@ -869,14 +869,14 @@ func (c *Catalog) BuildRunWithExistingOwnerReferences(buildRunName string, build // BuildRunWithFakeNamespace returns a BuildRun object with // a namespace that does not exist -func (c *Catalog) BuildRunWithFakeNamespace(buildRunName string, buildName string) *build.BuildRun { - return &build.BuildRun{ +func (c *Catalog) BuildRunWithFakeNamespace(buildRunName string, buildName string) *buildapi.BuildRun { + return &buildapi.BuildRun{ ObjectMeta: metav1.ObjectMeta{ Name: buildRunName, Namespace: "foobarns", }, - Spec: build.BuildRunSpec{ - Build: build.ReferencedBuild{ + Spec: buildapi.BuildRunSpec{ + Build: buildapi.ReferencedBuild{ Name: &buildName, }, }, @@ -919,8 +919,8 @@ func (c *Catalog) ServiceAccountWithControllerRef(name string) *corev1.ServiceAc // DefaultClusterBuildStrategy returns a minimal ClusterBuildStrategy // object with a inmutable name -func (c *Catalog) DefaultClusterBuildStrategy() *build.ClusterBuildStrategy { - return &build.ClusterBuildStrategy{ +func (c *Catalog) DefaultClusterBuildStrategy() *buildapi.ClusterBuildStrategy { + return &buildapi.ClusterBuildStrategy{ ObjectMeta: metav1.ObjectMeta{ Name: "foobar", }, @@ -929,8 +929,8 @@ func (c *Catalog) DefaultClusterBuildStrategy() *build.ClusterBuildStrategy { // DefaultNamespacedBuildStrategy returns a minimal BuildStrategy // object with a inmutable name -func (c *Catalog) DefaultNamespacedBuildStrategy() *build.BuildStrategy { - return &build.BuildStrategy{ +func (c *Catalog) DefaultNamespacedBuildStrategy() *buildapi.BuildStrategy { + return &buildapi.BuildStrategy{ ObjectMeta: metav1.ObjectMeta{ Name: "foobar", }, @@ -939,15 +939,15 @@ func (c *Catalog) DefaultNamespacedBuildStrategy() *build.BuildStrategy { // BuildRunWithSucceededCondition returns a BuildRun with a single condition // of the type Succeeded -func (c *Catalog) BuildRunWithSucceededCondition() *build.BuildRun { - return &build.BuildRun{ +func (c *Catalog) BuildRunWithSucceededCondition() *buildapi.BuildRun { + return &buildapi.BuildRun{ ObjectMeta: metav1.ObjectMeta{ Name: "foobar", }, - Status: build.BuildRunStatus{ - Conditions: build.Conditions{ - build.Condition{ - Type: build.Succeeded, + Status: buildapi.BuildRunStatus{ + Conditions: buildapi.Conditions{ + buildapi.Condition{ + Type: buildapi.Succeeded, Reason: "foobar", Message: "foo is not bar", Status: corev1.ConditionUnknown, @@ -959,29 +959,29 @@ func (c *Catalog) BuildRunWithSucceededCondition() *build.BuildRun { // BuildRunWithSA returns a customized BuildRun object that defines a // service account -func (c *Catalog) BuildRunWithSA(buildRunName string, buildName string, saName string) *build.BuildRun { - return &build.BuildRun{ +func (c *Catalog) BuildRunWithSA(buildRunName string, buildName string, saName string) *buildapi.BuildRun { + return &buildapi.BuildRun{ ObjectMeta: metav1.ObjectMeta{ Name: buildRunName, }, - Spec: build.BuildRunSpec{ - Build: build.ReferencedBuild{ + Spec: buildapi.BuildRunSpec{ + Build: buildapi.ReferencedBuild{ Name: &buildName, }, ServiceAccount: &saName, }, - Status: build.BuildRunStatus{}, + Status: buildapi.BuildRunStatus{}, } } // BuildRunWithoutSA returns a buildrun without serviceAccountName and generate serviceAccount is false -func (c *Catalog) BuildRunWithoutSA(buildRunName string, buildName string) *build.BuildRun { - return &build.BuildRun{ +func (c *Catalog) BuildRunWithoutSA(buildRunName string, buildName string) *buildapi.BuildRun { + return &buildapi.BuildRun{ ObjectMeta: metav1.ObjectMeta{ Name: buildRunName, }, - Spec: build.BuildRunSpec{ - Build: build.ReferencedBuild{ + Spec: buildapi.BuildRunSpec{ + Build: buildapi.ReferencedBuild{ Name: &buildName, }, ServiceAccount: nil, @@ -991,13 +991,13 @@ func (c *Catalog) BuildRunWithoutSA(buildRunName string, buildName string) *buil // BuildRunWithSAGenerate returns a customized BuildRun object that defines a // service account -func (c *Catalog) BuildRunWithSAGenerate(buildRunName string, buildName string) *build.BuildRun { - return &build.BuildRun{ +func (c *Catalog) BuildRunWithSAGenerate(buildRunName string, buildName string) *buildapi.BuildRun { + return &buildapi.BuildRun{ ObjectMeta: metav1.ObjectMeta{ Name: buildRunName, }, - Spec: build.BuildRunSpec{ - Build: build.ReferencedBuild{ + Spec: buildapi.BuildRunSpec{ + Build: buildapi.ReferencedBuild{ Name: &buildName, }, ServiceAccount: pointer.String(".generate"), @@ -1021,8 +1021,8 @@ func (c *Catalog) LoadCustomResources(cpu string, mem string) corev1.ResourceReq // LoadBuildYAML parses YAML bytes into JSON and from JSON // into a Build struct -func (c *Catalog) LoadBuildYAML(d []byte) (*build.Build, error) { - b := &build.Build{} +func (c *Catalog) LoadBuildYAML(d []byte) (*buildapi.Build, error) { + b := &buildapi.Build{} err := yaml.Unmarshal(d, b) if err != nil { return nil, err @@ -1031,8 +1031,8 @@ func (c *Catalog) LoadBuildYAML(d []byte) (*build.Build, error) { } // LoadBuildWithNameAndStrategy returns a populated Build with name and a referenced strategy -func (c *Catalog) LoadBuildWithNameAndStrategy(name string, strategy string, d []byte) (*build.Build, error) { - b := &build.Build{} +func (c *Catalog) LoadBuildWithNameAndStrategy(name string, strategy string, d []byte) (*buildapi.Build, error) { + b := &buildapi.Build{} err := yaml.Unmarshal(d, b) if err != nil { return nil, err @@ -1043,8 +1043,8 @@ func (c *Catalog) LoadBuildWithNameAndStrategy(name string, strategy string, d [ } // LoadBuildRunFromBytes returns a populated BuildRun -func (c *Catalog) LoadBuildRunFromBytes(d []byte) (*build.BuildRun, error) { - b := &build.BuildRun{} +func (c *Catalog) LoadBuildRunFromBytes(d []byte) (*buildapi.BuildRun, error) { + b := &buildapi.BuildRun{} err := yaml.Unmarshal(d, b) if err != nil { return nil, err @@ -1053,8 +1053,8 @@ func (c *Catalog) LoadBuildRunFromBytes(d []byte) (*build.BuildRun, error) { } // LoadBRWithNameAndRef returns a populated BuildRun with a name and a referenced Build -func (c *Catalog) LoadBRWithNameAndRef(name string, buildName string, d []byte) (*build.BuildRun, error) { - b := &build.BuildRun{} +func (c *Catalog) LoadBRWithNameAndRef(name string, buildName string, d []byte) (*buildapi.BuildRun, error) { + b := &buildapi.BuildRun{} err := yaml.Unmarshal(d, b) if err != nil { return nil, err @@ -1064,21 +1064,21 @@ func (c *Catalog) LoadBRWithNameAndRef(name string, buildName string, d []byte) return b, nil } -func (c *Catalog) LoadStandAloneBuildRunWithNameAndStrategy(name string, strategy *build.ClusterBuildStrategy, d []byte) (*build.BuildRun, error) { - b := &build.BuildRun{} +func (c *Catalog) LoadStandAloneBuildRunWithNameAndStrategy(name string, strategy *buildapi.ClusterBuildStrategy, d []byte) (*buildapi.BuildRun, error) { + b := &buildapi.BuildRun{} err := yaml.Unmarshal(d, b) if err != nil { return nil, err } b.Name = name - b.Spec.Build.Spec.Strategy = build.Strategy{Kind: (*build.BuildStrategyKind)(&strategy.Kind), Name: strategy.Name} + b.Spec.Build.Spec.Strategy = buildapi.Strategy{Kind: (*buildapi.BuildStrategyKind)(&strategy.Kind), Name: strategy.Name} return b, nil } // LoadBuildStrategyFromBytes returns a populated BuildStrategy -func (c *Catalog) LoadBuildStrategyFromBytes(d []byte) (*build.BuildStrategy, error) { - b := &build.BuildStrategy{} +func (c *Catalog) LoadBuildStrategyFromBytes(d []byte) (*buildapi.BuildStrategy, error) { + b := &buildapi.BuildStrategy{} err := yaml.Unmarshal(d, b) if err != nil { return nil, err @@ -1087,8 +1087,8 @@ func (c *Catalog) LoadBuildStrategyFromBytes(d []byte) (*build.BuildStrategy, er } // LoadCBSWithName returns a populated ClusterBuildStrategy with a name -func (c *Catalog) LoadCBSWithName(name string, d []byte) (*build.ClusterBuildStrategy, error) { - b := &build.ClusterBuildStrategy{} +func (c *Catalog) LoadCBSWithName(name string, d []byte) (*buildapi.ClusterBuildStrategy, error) { + b := &buildapi.ClusterBuildStrategy{} err := yaml.Unmarshal(d, b) if err != nil { return nil, err