diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fc32ee1502..736a580b42 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -215,11 +215,24 @@ jobs: if [ "${POD_NAME}" != "" ]; then RESTART_COUNT=$(echo "${PODS}" | jq -r ".items[] | select(.metadata.name == \"${POD_NAME}\") | .status.containerStatuses[0].restartCount") if [ "${RESTART_COUNT}" != "0" ]; then - echo "# Previous logs:" + echo "# Build Controller Previous logs:" kubectl -n shipwright-build logs "${POD_NAME}" --previous || true fi - echo "# Logs:" + echo "# Build Controller Logs:" kubectl -n shipwright-build logs "${POD_NAME}" else echo "# Pod is missing, there are no logs to retrieve, bailing out..." fi + + WEBHOOK_POD_NAME=$(echo "${PODS}" | jq -r '.items[] | select(.metadata.name | startswith("shipwright-build-webhook-")) | .metadata.name') + if [ "${WEBHOOK_POD_NAME}" != "" ]; then + RESTART_COUNT=$(echo "${PODS}" | jq -r ".items[] | select(.metadata.name == \"${WEBHOOK_POD_NAME}\") | .status.containerStatuses[0].restartCount") + if [ "${RESTART_COUNT}" != "0" ]; then + echo "# Build Webhook Previous logs:" + kubectl -n shipwright-build logs "${WEBHOOK_POD_NAME}" --previous || true + fi + echo "# Build Webhook Logs:" + kubectl -n shipwright-build logs "${WEBHOOK_POD_NAME}" + else + echo "# Pod is missing, there are no logs to retrieve, bailing out..." + fi \ No newline at end of file diff --git a/deploy/crds/shipwright.io_buildruns.yaml b/deploy/crds/shipwright.io_buildruns.yaml index e0b710e8e8..f0cfdf9fd4 100644 --- a/deploy/crds/shipwright.io_buildruns.yaml +++ b/deploy/crds/shipwright.io_buildruns.yaml @@ -6354,7 +6354,7 @@ spec: - spec type: object served: true - storage: true + storage: false subresources: status: {} - additionalPrinterColumns: @@ -12580,7 +12580,7 @@ spec: - spec type: object served: true - storage: false + storage: true subresources: status: {} diff --git a/deploy/crds/shipwright.io_builds.yaml b/deploy/crds/shipwright.io_builds.yaml index a76781a66f..82bbd07b67 100644 --- a/deploy/crds/shipwright.io_builds.yaml +++ b/deploy/crds/shipwright.io_builds.yaml @@ -2143,7 +2143,7 @@ spec: - spec type: object served: true - storage: true + storage: false subresources: status: {} - additionalPrinterColumns: @@ -4197,7 +4197,7 @@ spec: - spec type: object served: true - storage: false + storage: true subresources: status: {} diff --git a/deploy/crds/shipwright.io_buildstrategies.yaml b/deploy/crds/shipwright.io_buildstrategies.yaml index 2887d73696..0c2c0779bb 100644 --- a/deploy/crds/shipwright.io_buildstrategies.yaml +++ b/deploy/crds/shipwright.io_buildstrategies.yaml @@ -2930,7 +2930,7 @@ spec: type: object type: object served: true - storage: true + storage: false subresources: status: {} - name: v1beta1 @@ -5026,7 +5026,7 @@ spec: type: object type: object served: true - storage: false + storage: true subresources: status: {} diff --git a/deploy/crds/shipwright.io_clusterbuildstrategies.yaml b/deploy/crds/shipwright.io_clusterbuildstrategies.yaml index c7f5467c6c..1ed12dee0e 100644 --- a/deploy/crds/shipwright.io_clusterbuildstrategies.yaml +++ b/deploy/crds/shipwright.io_clusterbuildstrategies.yaml @@ -2930,7 +2930,7 @@ spec: type: object type: object served: true - storage: true + storage: false subresources: status: {} - name: v1beta1 @@ -5026,7 +5026,7 @@ spec: type: object type: object served: true - storage: false + storage: true subresources: status: {} diff --git a/pkg/apis/build/v1alpha1/build_conversion.go b/pkg/apis/build/v1alpha1/build_conversion.go deleted file mode 100644 index c6638dd704..0000000000 --- a/pkg/apis/build/v1alpha1/build_conversion.go +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright The Shipwright Contributors -// -// SPDX-License-Identifier: Apache-2.0 - -package v1alpha1 - -import ( - "context" - "fmt" - - "github.com/shipwright-io/build/pkg/webhook" - "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" -) - -// ensure v1alpha1 implements the Conversion interface -var _ webhook.Conversion = (*Build)(nil) - -func (src *Build) ConvertTo(_ context.Context, _ *unstructured.Unstructured) error { - return fmt.Errorf("v1alpha1 is the current storage version, nothing to convert to") -} - -func (src *Build) ConvertFrom(_ context.Context, _ *unstructured.Unstructured) error { - return fmt.Errorf("v1alpha1 is the current storage version, nothing to convert from") -} diff --git a/pkg/apis/build/v1alpha1/build_types.go b/pkg/apis/build/v1alpha1/build_types.go index e9f3789079..8023c71f32 100644 --- a/pkg/apis/build/v1alpha1/build_types.go +++ b/pkg/apis/build/v1alpha1/build_types.go @@ -257,7 +257,6 @@ type BuildStatus struct { // Build is the Schema representing a Build definition // +kubebuilder:subresource:status -// +kubebuilder:storageversion // +kubebuilder:resource:path=builds,scope=Namespaced // +kubebuilder:printcolumn:name="Registered",type="string",JSONPath=".status.registered",description="The register status of the Build" // +kubebuilder:printcolumn:name="Reason",type="string",JSONPath=".status.reason",description="The reason of the registered Build, either an error or succeed message" diff --git a/pkg/apis/build/v1alpha1/buildrun_conversion.go b/pkg/apis/build/v1alpha1/buildrun_conversion.go deleted file mode 100644 index 5e07c04b46..0000000000 --- a/pkg/apis/build/v1alpha1/buildrun_conversion.go +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright The Shipwright Contributors -// -// SPDX-License-Identifier: Apache-2.0 - -package v1alpha1 - -import ( - "context" - "fmt" - - "github.com/shipwright-io/build/pkg/webhook" - "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" -) - -// ensure v1alpha1 implements the Conversion interface -var _ webhook.Conversion = (*BuildRun)(nil) - -func (src *BuildRun) ConvertTo(_ context.Context, _ *unstructured.Unstructured) error { - return fmt.Errorf("v1alpha1 is the current storage version, nothing to convert to") -} - -func (src *BuildRun) ConvertFrom(_ context.Context, _ *unstructured.Unstructured) error { - return fmt.Errorf("v1alpha1 is the current storage version, nothing to convert from") -} diff --git a/pkg/apis/build/v1alpha1/buildrun_types.go b/pkg/apis/build/v1alpha1/buildrun_types.go index 2d8cc09a24..571552665b 100644 --- a/pkg/apis/build/v1alpha1/buildrun_types.go +++ b/pkg/apis/build/v1alpha1/buildrun_types.go @@ -238,7 +238,6 @@ type ServiceAccount struct { // BuildRun is the Schema representing an instance of build execution // +kubebuilder:subresource:status -// +kubebuilder:storageversion // +kubebuilder:resource:path=buildruns,scope=Namespaced,shortName=br;brs // +kubebuilder:printcolumn:name="Succeeded",type="string",JSONPath=".status.conditions[?(@.type==\"Succeeded\")].status",description="The Succeeded status of the BuildRun" // +kubebuilder:printcolumn:name="Reason",type="string",JSONPath=".status.conditions[?(@.type==\"Succeeded\")].reason",description="The Succeeded reason of the BuildRun" diff --git a/pkg/apis/build/v1alpha1/buildstrategy_conversion.go b/pkg/apis/build/v1alpha1/buildstrategy_conversion.go deleted file mode 100644 index fd0de79cf4..0000000000 --- a/pkg/apis/build/v1alpha1/buildstrategy_conversion.go +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright The Shipwright Contributors -// -// SPDX-License-Identifier: Apache-2.0 - -package v1alpha1 - -import ( - "context" - "fmt" - - "github.com/shipwright-io/build/pkg/webhook" - "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" -) - -// ensure v1alpha1 implements the Conversion interface -var _ webhook.Conversion = (*BuildStrategy)(nil) - -func (src *BuildStrategy) ConvertTo(_ context.Context, _ *unstructured.Unstructured) error { - return fmt.Errorf("v1alpha1 is the current storage version, nothing to convert to") -} - -func (src *BuildStrategy) ConvertFrom(_ context.Context, _ *unstructured.Unstructured) error { - return fmt.Errorf("v1alpha1 is the current storage version, nothing to convert from") -} diff --git a/pkg/apis/build/v1alpha1/buildstrategy_types.go b/pkg/apis/build/v1alpha1/buildstrategy_types.go index 395e459f81..3bb7373927 100644 --- a/pkg/apis/build/v1alpha1/buildstrategy_types.go +++ b/pkg/apis/build/v1alpha1/buildstrategy_types.go @@ -26,7 +26,6 @@ const ( // BuildStrategy is the Schema representing a strategy in the namespace scope to build images from source code. // +kubebuilder:subresource:status -// +kubebuilder:storageversion // +kubebuilder:resource:path=buildstrategies,scope=Namespaced,shortName=bs;bss type BuildStrategy struct { metav1.TypeMeta `json:",inline"` diff --git a/pkg/apis/build/v1alpha1/clusterbuildstrategy_conversion.go b/pkg/apis/build/v1alpha1/clusterbuildstrategy_conversion.go deleted file mode 100644 index 21b1856290..0000000000 --- a/pkg/apis/build/v1alpha1/clusterbuildstrategy_conversion.go +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright The Shipwright Contributors -// -// SPDX-License-Identifier: Apache-2.0 - -package v1alpha1 - -import ( - "context" - "fmt" - - "github.com/shipwright-io/build/pkg/webhook" - "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" -) - -// ensure v1alpha1 implements the Conversion interface -var _ webhook.Conversion = (*ClusterBuildStrategy)(nil) - -func (src *ClusterBuildStrategy) ConvertTo(_ context.Context, _ *unstructured.Unstructured) error { - return fmt.Errorf("v1alpha1 is the current storage version, nothing to convert to") -} - -func (src *ClusterBuildStrategy) ConvertFrom(_ context.Context, _ *unstructured.Unstructured) error { - return fmt.Errorf("v1alpha1 is the current storage version, nothing to convert from") -} diff --git a/pkg/apis/build/v1alpha1/clusterbuildstrategy_types.go b/pkg/apis/build/v1alpha1/clusterbuildstrategy_types.go index b247167bf1..ae41c2a85d 100644 --- a/pkg/apis/build/v1alpha1/clusterbuildstrategy_types.go +++ b/pkg/apis/build/v1alpha1/clusterbuildstrategy_types.go @@ -27,7 +27,6 @@ const ( // ClusterBuildStrategy is the Schema representing a strategy in the cluster scope to build images from source code. // +kubebuilder:subresource:status -// +kubebuilder:storageversion // +kubebuilder:resource:path=clusterbuildstrategies,scope=Cluster,shortName=cbs;cbss type ClusterBuildStrategy struct { metav1.TypeMeta `json:",inline"` diff --git a/pkg/apis/build/v1beta1/build_types.go b/pkg/apis/build/v1beta1/build_types.go index 738fa05e14..a0e51f298b 100644 --- a/pkg/apis/build/v1beta1/build_types.go +++ b/pkg/apis/build/v1beta1/build_types.go @@ -220,6 +220,7 @@ type BuildStatus struct { // Build is the Schema representing a Build definition // +kubebuilder:subresource:status +// +kubebuilder:storageversion // +kubebuilder:resource:path=builds,scope=Namespaced // +kubebuilder:printcolumn:name="Registered",type="string",JSONPath=".status.registered",description="The register status of the Build" // +kubebuilder:printcolumn:name="Reason",type="string",JSONPath=".status.reason",description="The reason of the registered Build, either an error or succeed message" @@ -274,3 +275,18 @@ type BuildRetention struct { func init() { SchemeBuilder.Register(&Build{}, &BuildList{}) } + +// GetSourceCredentials returns the secret name for a Build Source +func (b Build) GetSourceCredentials() *string { + switch b.Spec.Source.Type { + case OCIArtifactType: + if b.Spec.Source.OCIArtifact != nil && b.Spec.Source.OCIArtifact.PullSecret != nil { + return b.Spec.Source.OCIArtifact.PullSecret + } + default: + if b.Spec.Source.GitSource != nil && b.Spec.Source.GitSource.CloneSecret != nil { + return b.Spec.Source.GitSource.CloneSecret + } + } + return nil +} diff --git a/pkg/apis/build/v1beta1/buildrun_types.go b/pkg/apis/build/v1beta1/buildrun_types.go index 8703976ff1..381a69f460 100644 --- a/pkg/apis/build/v1beta1/buildrun_types.go +++ b/pkg/apis/build/v1beta1/buildrun_types.go @@ -221,6 +221,7 @@ type FailureDetails struct { // BuildRun is the Schema representing an instance of build execution // +kubebuilder:subresource:status +// +kubebuilder:storageversion // +kubebuilder:resource:path=buildruns,scope=Namespaced,shortName=br;brs // +kubebuilder:printcolumn:name="Succeeded",type="string",JSONPath=".status.conditions[?(@.type==\"Succeeded\")].status",description="The Succeeded status of the BuildRun" // +kubebuilder:printcolumn:name="Reason",type="string",JSONPath=".status.conditions[?(@.type==\"Succeeded\")].reason",description="The Succeeded reason of the BuildRun" diff --git a/pkg/apis/build/v1beta1/buildstrategy_types.go b/pkg/apis/build/v1beta1/buildstrategy_types.go index 2d1ece058f..1613164c7d 100644 --- a/pkg/apis/build/v1beta1/buildstrategy_types.go +++ b/pkg/apis/build/v1beta1/buildstrategy_types.go @@ -26,6 +26,7 @@ const ( // BuildStrategy is the Schema representing a strategy in the namespace scope to build images from source code. // +kubebuilder:subresource:status +// +kubebuilder:storageversion // +kubebuilder:resource:path=buildstrategies,scope=Namespaced,shortName=bs;bss type BuildStrategy struct { metav1.TypeMeta `json:",inline"` diff --git a/pkg/apis/build/v1beta1/clusterbuildstrategy_types.go b/pkg/apis/build/v1beta1/clusterbuildstrategy_types.go index 42df58465f..c6c612c391 100644 --- a/pkg/apis/build/v1beta1/clusterbuildstrategy_types.go +++ b/pkg/apis/build/v1beta1/clusterbuildstrategy_types.go @@ -27,6 +27,7 @@ const ( // ClusterBuildStrategy is the Schema representing a strategy in the cluster scope to build images from source code. // +kubebuilder:subresource:status +// +kubebuilder:storageversion // +kubebuilder:resource:path=clusterbuildstrategies,scope=Cluster,shortName=cbs;cbss type ClusterBuildStrategy struct { metav1.TypeMeta `json:",inline"` diff --git a/pkg/image/delete_test.go b/pkg/image/delete_test.go index 74193d1923..a71b20da48 100644 --- a/pkg/image/delete_test.go +++ b/pkg/image/delete_test.go @@ -17,7 +17,7 @@ import ( "github.com/google/go-containerregistry/pkg/v1/random" "github.com/google/go-containerregistry/pkg/v1/remote" "github.com/shipwright-io/build/pkg/image" - utils "github.com/shipwright-io/build/test/utils/v1alpha1" + utils "github.com/shipwright-io/build/test/utils/v1beta1" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" diff --git a/pkg/reconciler/build/build.go b/pkg/reconciler/build/build.go index ba9b2a9d2c..ea4d246ea9 100644 --- a/pkg/reconciler/build/build.go +++ b/pkg/reconciler/build/build.go @@ -15,7 +15,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/manager" "sigs.k8s.io/controller-runtime/pkg/reconcile" - build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/config" "github.com/shipwright-io/build/pkg/ctxlog" buildmetrics "github.com/shipwright-io/build/pkg/metrics" @@ -28,7 +28,7 @@ var validationTypes = [...]string{ validate.SourceURL, validate.Secrets, validate.Strategies, - validate.Sources, + validate.Source, validate.BuildName, validate.Envs, validate.Triggers, diff --git a/pkg/reconciler/build/build_test.go b/pkg/reconciler/build/build_test.go index c399ee49e7..aecd01c8d2 100644 --- a/pkg/reconciler/build/build_test.go +++ b/pkg/reconciler/build/build_test.go @@ -20,11 +20,11 @@ import ( "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" "sigs.k8s.io/controller-runtime/pkg/reconcile" - build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/config" "github.com/shipwright-io/build/pkg/controller/fakes" buildController "github.com/shipwright-io/build/pkg/reconciler/build" - test "github.com/shipwright-io/build/test/v1alpha1_samples" + test "github.com/shipwright-io/build/test/v1beta1_samples" ) var _ = Describe("Reconcile Build", func() { @@ -83,10 +83,9 @@ var _ = Describe("Reconcile Build", func() { Describe("Reconcile", func() { Context("when source secret is specified", func() { It("fails when the secret does not exist", func() { - buildSample.Spec.Source.Credentials = &corev1.LocalObjectReference{ - Name: "non-existing", - } - buildSample.Spec.Output.Credentials = nil + buildSample.Spec.Source.GitSource.CloneSecret = pointer.String("non-existing") + + buildSample.Spec.Output.PushSecret = nil statusCall := ctl.StubFunc(corev1.ConditionFalse, build.SpecSourceSecretRefNotFound, "referenced secret non-existing not found") statusWriter.UpdateCalls(statusCall) @@ -97,62 +96,8 @@ var _ = Describe("Reconcile Build", func() { }) It("succeeds when the secret exists foobar", func() { - buildSample.Spec.Source.Credentials = &corev1.LocalObjectReference{ - Name: "existing", - } - buildSample.Spec.Output.Credentials = nil - - // Fake some client Get calls and ensure we populate all - // different resources we could get during reconciliation - client.GetCalls(func(_ context.Context, nn types.NamespacedName, object crc.Object, getOptions ...crc.GetOption) error { - switch object := object.(type) { - case *build.Build: - buildSample.DeepCopyInto(object) - case *build.ClusterBuildStrategy: - clusterBuildStrategySample.DeepCopyInto(object) - case *corev1.Secret: - secretSample = ctl.SecretWithoutAnnotation("existing", namespace) - secretSample.DeepCopyInto(object) - } - return nil - }) - - statusCall := ctl.StubFunc(corev1.ConditionTrue, build.SucceedStatus, "all validations succeeded") - statusWriter.UpdateCalls(statusCall) - - result, err := reconciler.Reconcile(context.TODO(), request) - Expect(err).ToNot(HaveOccurred()) - Expect(statusWriter.UpdateCallCount()).To(Equal(1)) - Expect(reconcile.Result{}).To(Equal(result)) - }) - }) - - Context("when builder image secret is specified", func() { - It("fails when the secret does not exist", func() { - buildSample.Spec.Builder = &build.Image{ - Image: "busybox", - Credentials: &corev1.LocalObjectReference{ - Name: "non-existing", - }, - } - buildSample.Spec.Output.Credentials = nil - - statusCall := ctl.StubFunc(corev1.ConditionFalse, build.SpecBuilderSecretRefNotFound, "referenced secret non-existing not found") - statusWriter.UpdateCalls(statusCall) - - _, err := reconciler.Reconcile(context.TODO(), request) - Expect(err).To(BeNil()) - Expect(statusWriter.UpdateCallCount()).To(Equal(1)) - }) - - It("succeeds when the secret exists", func() { - buildSample.Spec.Builder = &build.Image{ - Image: "busybox", - Credentials: &corev1.LocalObjectReference{ - Name: "existing", - }, - } - buildSample.Spec.Output.Credentials = nil + buildSample.Spec.Source.GitSource.CloneSecret = pointer.String("existing") + buildSample.Spec.Output.PushSecret = nil // Fake some client Get calls and ensure we populate all // different resources we could get during reconciliation @@ -217,12 +162,8 @@ var _ = Describe("Reconcile Build", func() { Context("when source secret and output secret are specified", func() { It("fails when both secrets do not exist", func() { - buildSample.Spec.Source.Credentials = &corev1.LocalObjectReference{ - Name: "non-existing-source", - } - buildSample.Spec.Output.Credentials = &corev1.LocalObjectReference{ - Name: "non-existing-output", - } + buildSample.Spec.Source.GitSource.CloneSecret = pointer.String("non-existing-source") + buildSample.Spec.Output.PushSecret = pointer.String("non-existing-output") statusCall := ctl.StubFunc(corev1.ConditionFalse, build.MultipleSecretRefNotFound, "missing secrets are non-existing-output,non-existing-source") statusWriter.UpdateCalls(statusCall) @@ -371,7 +312,7 @@ var _ = Describe("Reconcile Build", func() { Context("when source URL is specified", func() { // validate file protocol It("fails when source URL is invalid", func() { - buildSample.Spec.Source.URL = pointer.String("foobar") + buildSample.Spec.Source.GitSource.URL = "foobar" buildSample.SetAnnotations(map[string]string{ build.AnnotationBuildVerifyRepository: "true", }) @@ -385,7 +326,7 @@ var _ = Describe("Reconcile Build", func() { // validate https protocol It("fails when public source URL is unreachable", func() { - buildSample.Spec.Source.URL = pointer.String("https://github.com/shipwright-io/sample-go-fake") + buildSample.Spec.Source.GitSource.URL = "https://github.com/shipwright-io/sample-go-fake" buildSample.SetAnnotations(map[string]string{ build.AnnotationBuildVerifyRepository: "true", }) @@ -400,7 +341,7 @@ var _ = Describe("Reconcile Build", func() { // skip validation because of empty sourceURL annotation It("succeed when source URL is invalid because source annotation is empty", func() { - buildSample.Spec.Source.URL = pointer.String("foobar") + buildSample.Spec.Source.GitSource.URL = "foobar" // Fake some client Get calls and ensure we populate all // different resources we could get during reconciliation @@ -451,8 +392,8 @@ var _ = Describe("Reconcile Build", func() { // skip validation because build references a sourceURL secret It("succeed when source URL is fake private URL because build reference a sourceURL secret", func() { buildSample := ctl.BuildWithClusterBuildStrategyAndSourceSecret(buildName, namespace, buildStrategyName) - buildSample.Spec.Source.URL = pointer.String("https://github.yourco.com/org/build-fake") - buildSample.Spec.Source.Credentials.Name = registrySecret + buildSample.Spec.Source.GitSource.URL = "https://github.yourco.com/org/build-fake" + buildSample.Spec.Source.GitSource.CloneSecret = pointer.String(registrySecret) // Fake some client Get calls and ensure we populate all // different resources we could get during reconciliation @@ -479,10 +420,8 @@ var _ = Describe("Reconcile Build", func() { Context("when environment variables are specified", func() { JustBeforeEach(func() { - buildSample.Spec.Source.Credentials = &corev1.LocalObjectReference{ - Name: "existing", - } - buildSample.Spec.Output.Credentials = nil + buildSample.Spec.Source.GitSource.CloneSecret = pointer.String("existing") + buildSample.Spec.Output.PushSecret = nil // Fake some client Get calls and ensure we populate all // different resources we could get during reconciliation diff --git a/pkg/reconciler/build/controller.go b/pkg/reconciler/build/controller.go index ec46c7500b..64c7aa11b7 100644 --- a/pkg/reconciler/build/controller.go +++ b/pkg/reconciler/build/controller.go @@ -12,6 +12,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" + "k8s.io/utils/pointer" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" @@ -22,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/v1alpha1" + build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/config" "github.com/shipwright-io/build/pkg/ctxlog" ) @@ -62,27 +63,54 @@ func add(ctx context.Context, mgr manager.Manager, r reconcile.Reconciler, maxCo o := e.ObjectOld.(*build.Build) n := e.ObjectNew.(*build.Build) - buildRunDeletionAnnotation := false - // Check if the AnnotationBuildRunDeletion annotation is updated - oldAnnot := o.GetAnnotations() - newAnnot := n.GetAnnotations() - if !reflect.DeepEqual(oldAnnot, newAnnot) { - if oldAnnot[build.AnnotationBuildRunDeletion] != newAnnot[build.AnnotationBuildRunDeletion] { - ctxlog.Debug( - ctx, - "updating predicated passed, the annotation was modified.", - namespace, - n.GetNamespace(), - name, - n.GetName(), - ) - buildRunDeletionAnnotation = true + buildAtBuildDeletion := false + + // Check if the Build retention AtBuildDeletion is updated + oldBuildRetention := o.Spec.Retention + newBuildRetention := n.Spec.Retention + + logAndEnableDeletion := func() { + ctxlog.Debug( + ctx, + "updating predicated passed, the build retention AtBuildDeletion was modified.", + namespace, + n.GetNamespace(), + name, + n.GetName(), + ) + buildAtBuildDeletion = true + } + + xorBuildRetentions := func(oldDeletion, newDeletion *bool) bool { + if oldDeletion == nil { + oldDeletion = pointer.Bool(false) + } + if newDeletion == nil { + newDeletion = pointer.Bool(false) + } + return (*oldDeletion || *newDeletion) && !(*oldDeletion && *newDeletion) + } + + if !reflect.DeepEqual(oldBuildRetention, newBuildRetention) { + switch { + case o.Spec.Retention == nil && n.Spec.Retention != nil: + if n.Spec.Retention.AtBuildDeletion != nil && *n.Spec.Retention.AtBuildDeletion { + logAndEnableDeletion() + } + case o.Spec.Retention != nil && n.Spec.Retention == nil: + if o.Spec.Retention.AtBuildDeletion != nil && *o.Spec.Retention.AtBuildDeletion { + logAndEnableDeletion() + } + case o.Spec.Retention != nil && n.Spec.Retention != nil: + if xorBuildRetentions(o.Spec.Retention.AtBuildDeletion, n.Spec.Retention.AtBuildDeletion) { + logAndEnableDeletion() + } } } // Ignore updates to CR status in which case metadata.Generation does not change // or BuildRunDeletion annotation does not change - return o.GetGeneration() != n.GetGeneration() || buildRunDeletionAnnotation + return o.GetGeneration() != n.GetGeneration() || buildAtBuildDeletion }, DeleteFunc: func(_ event.DeleteEvent) bool { // Never reconcile on deletion, there is nothing we have to do @@ -153,21 +181,16 @@ func add(ctx context.Context, mgr manager.Manager, r reconcile.Reconciler, maxCo flagReconcile := false for _, build := range buildList.Items { - if build.Spec.Source.Credentials != nil { - if build.Spec.Source.Credentials.Name == secret.Name { - flagReconcile = true - } - } - if build.Spec.Output.Credentials != nil { - if build.Spec.Output.Credentials.Name == secret.Name { - flagReconcile = true - } + if build.GetSourceCredentials() != nil && *build.GetSourceCredentials() == secret.Name { + flagReconcile = true } - if build.Spec.Builder != nil && build.Spec.Builder.Credentials != nil { - if build.Spec.Builder.Credentials.Name == secret.Name { + + if build.Spec.Output.PushSecret != nil { + if *build.Spec.Output.PushSecret == secret.Name { flagReconcile = true } } + if flagReconcile { reconcileList = append(reconcileList, reconcile.Request{ NamespacedName: types.NamespacedName{ diff --git a/pkg/reconciler/buildlimitcleanup/build_limit_cleanup.go b/pkg/reconciler/buildlimitcleanup/build_limit_cleanup.go index 69bca8008a..1d36c57189 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/v1alpha1" + build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/config" "github.com/shipwright-io/build/pkg/ctxlog" corev1 "k8s.io/api/core/v1" diff --git a/pkg/reconciler/buildlimitcleanup/controller.go b/pkg/reconciler/buildlimitcleanup/controller.go index 15bd8240e4..270696099c 100644 --- a/pkg/reconciler/buildlimitcleanup/controller.go +++ b/pkg/reconciler/buildlimitcleanup/controller.go @@ -7,7 +7,7 @@ package buildlimitcleanup import ( "context" - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/config" 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.(*buildv1alpha1.Build) + o := e.Object.(*buildv1beta1.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.(*buildv1alpha1.Build) - o := e.ObjectOld.(*buildv1alpha1.Build) + n := e.ObjectNew.(*buildv1beta1.Build) + o := e.ObjectOld.(*buildv1beta1.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.(*buildv1alpha1.BuildRun) + n := e.ObjectNew.(*buildv1beta1.BuildRun) // check if Buildrun is related to a build - if n.Spec.BuildRef == nil { + if n.Spec.Build.Name == nil { return false } - o := e.ObjectOld.(*buildv1alpha1.BuildRun) - oldCondition := o.Status.GetCondition(buildv1alpha1.Succeeded) - newCondition := n.Status.GetCondition(buildv1alpha1.Succeeded) + o := e.ObjectOld.(*buildv1beta1.BuildRun) + oldCondition := o.Status.GetCondition(buildv1beta1.Succeeded) + newCondition := n.Status.GetCondition(buildv1beta1.Succeeded) if newCondition != nil { if (oldCondition == nil || oldCondition.Status == corev1.ConditionUnknown) && (newCondition.Status == corev1.ConditionFalse || newCondition.Status == corev1.ConditionTrue) { @@ -113,18 +113,18 @@ func add(mgr manager.Manager, r reconcile.Reconciler, maxConcurrentReconciles in } // Watch for changes to primary resource Build - if err = c.Watch(&source.Kind{Type: &buildv1alpha1.Build{}}, &handler.EnqueueRequestForObject{}, pred); err != nil { + if err = c.Watch(&source.Kind{Type: &buildv1beta1.Build{}}, &handler.EnqueueRequestForObject{}, pred); err != nil { return err } // Watch for changes to resource BuildRun - return c.Watch(&source.Kind{Type: &buildv1alpha1.BuildRun{}}, handler.EnqueueRequestsFromMapFunc(func(o client.Object) []reconcile.Request { - buildRun := o.(*buildv1alpha1.BuildRun) + return c.Watch(&source.Kind{Type: &buildv1beta1.BuildRun{}}, handler.EnqueueRequestsFromMapFunc(func(o client.Object) []reconcile.Request { + buildRun := o.(*buildv1beta1.BuildRun) return []reconcile.Request{ { NamespacedName: types.NamespacedName{ - Name: buildRun.Spec.BuildRef.Name, + Name: *buildRun.Spec.Build.Name, Namespace: buildRun.Namespace, }, }, diff --git a/pkg/reconciler/buildrun/buildrun.go b/pkg/reconciler/buildrun/buildrun.go index eb7ab6ba7f..de8a675e48 100644 --- a/pkg/reconciler/buildrun/buildrun.go +++ b/pkg/reconciler/buildrun/buildrun.go @@ -26,7 +26,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/manager" "sigs.k8s.io/controller-runtime/pkg/reconcile" - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/config" "github.com/shipwright-io/build/pkg/ctxlog" buildmetrics "github.com/shipwright-io/build/pkg/metrics" @@ -66,8 +66,8 @@ func NewReconciler(c *config.Config, mgr manager.Manager, ownerRef setOwnerRefer // Reconcile reads that state of the cluster for a Build object and makes changes based on the state read // and what is in the Build.Spec func (r *ReconcileBuildRun) Reconcile(ctx context.Context, request reconcile.Request) (reconcile.Result, error) { - var buildRun *buildv1alpha1.BuildRun - var build *buildv1alpha1.Build + var buildRun *buildv1beta1.BuildRun + var build *buildv1beta1.Build updateBuildRunRequired := false @@ -79,7 +79,7 @@ func (r *ReconcileBuildRun) Reconcile(ctx context.Context, request reconcile.Req // with build run cancel, it is now possible for a build run update to stem from something other than a task run update, // so we can no longer assume that a build run event will not come in after the build run has a task run ref in its status - buildRun = &buildv1alpha1.BuildRun{} + buildRun = &buildv1beta1.BuildRun{} getBuildRunErr := r.GetBuildRunObject(ctx, request.Name, request.Namespace, buildRun) lastTaskRun := &pipelineapi.TaskRun{} getTaskRunErr := r.client.Get(ctx, types.NamespacedName{Name: request.Name, Namespace: request.Namespace}, lastTaskRun) @@ -124,16 +124,16 @@ func (r *ReconcileBuildRun) Reconcile(ctx context.Context, request reconcile.Req } // if this is a build run event after we've set the task run ref, get the task run using the task run name stored in the build run - if getBuildRunErr == nil && apierrors.IsNotFound(getTaskRunErr) && buildRun.Status.LatestTaskRunRef != nil { - getTaskRunErr = r.client.Get(ctx, types.NamespacedName{Name: *buildRun.Status.LatestTaskRunRef, Namespace: request.Namespace}, lastTaskRun) + if getBuildRunErr == nil && apierrors.IsNotFound(getTaskRunErr) && buildRun.Status.TaskRunName != nil { + getTaskRunErr = r.client.Get(ctx, types.NamespacedName{Name: *buildRun.Status.TaskRunName, Namespace: request.Namespace}, lastTaskRun) } // for existing TaskRuns update the BuildRun Status, if there is no TaskRun, then create one if getTaskRunErr != nil { if apierrors.IsNotFound(getTaskRunErr) { - build = &buildv1alpha1.Build{} + build = &buildv1beta1.Build{} if err := resources.GetBuildObject(ctx, r.client, buildRun, build); err != nil { - if !resources.IsClientStatusUpdateError(err) && buildRun.Status.IsFailed(buildv1alpha1.Succeeded) { + if !resources.IsClientStatusUpdateError(err) && buildRun.Status.IsFailed(buildv1beta1.Succeeded) { return reconcile.Result{}, nil } // system call failure, reconcile again @@ -147,17 +147,17 @@ func (r *ReconcileBuildRun) Reconcile(ctx context.Context, request reconcile.Req // an actual resource in the cluster and _should_ have been // validated and registered by now ... // reconcile again until it gets a registration value - case buildRun.Spec.BuildRef != nil: + case buildRun.Spec.Build.Name != nil: return reconcile.Result{}, fmt.Errorf("the Build is not yet validated, build: %s", build.Name) // When the build(spec) is embedded in the buildrun, the now // transient/volatile build resource needs to be validated first - case buildRun.Spec.BuildSpec != nil: + case buildRun.Spec.Build.Build != nil: err := validate.All(ctx, validate.NewSourceURL(r.client, build), validate.NewCredentials(r.client, build), validate.NewStrategies(r.client, build), - validate.NewSourcesRef(build), + validate.NewSourceRef(build), validate.NewBuildName(build), validate.NewEnv(build), ) @@ -178,18 +178,17 @@ func (r *ReconcileBuildRun) Reconcile(ctx context.Context, request reconcile.Req resources.ConditionBuildRegistrationFailed, ) } - // mark transient build as "registered" and validated - build.Status.Registered = buildv1alpha1.ConditionStatusPtr(corev1.ConditionTrue) - build.Status.Reason = buildv1alpha1.BuildReasonPtr(buildv1alpha1.SucceedStatus) - build.Status.Message = pointer.String(buildv1alpha1.AllValidationsSucceeded) + build.Status.Registered = buildv1beta1.ConditionStatusPtr(corev1.ConditionTrue) + build.Status.Reason = buildv1beta1.BuildReasonPtr(buildv1beta1.SucceedStatus) + build.Status.Message = pointer.String(buildv1beta1.AllValidationsSucceeded) } } if *build.Status.Registered != corev1.ConditionTrue { // stop reconciling and mark the BuildRun as Failed // we only reconcile again if the status.Update call fails - var reason buildv1alpha1.BuildReason + var reason buildv1beta1.BuildReason if build.Status.Reason != nil { reason = *build.Status.Reason @@ -210,31 +209,33 @@ func (r *ReconcileBuildRun) Reconcile(ctx context.Context, request reconcile.Req // make sure the BuildRun has not already been cancelled if buildRun.IsCanceled() { - if updateErr := resources.UpdateConditionWithFalseStatus(ctx, r.client, buildRun, "the BuildRun is marked canceled.", buildv1alpha1.BuildRunStateCancel); updateErr != nil { + if updateErr := resources.UpdateConditionWithFalseStatus(ctx, r.client, buildRun, "the BuildRun is marked canceled.", buildv1beta1.BuildRunStateCancel); updateErr != nil { return reconcile.Result{}, updateErr } return reconcile.Result{}, nil } - // Set OwnerReference for Build and BuildRun only when build.shipwright.io/build-run-deletion is set "true" - if build.GetAnnotations()[buildv1alpha1.AnnotationBuildRunDeletion] == "true" && !resources.IsOwnedByBuild(build, buildRun.OwnerReferences) { - if err := r.setOwnerReferenceFunc(build, buildRun, r.scheme); err != nil { - build.Status.Reason = buildv1alpha1.BuildReasonPtr(buildv1alpha1.SetOwnerReferenceFailed) - build.Status.Message = pointer.String(fmt.Sprintf("unexpected error when trying to set the ownerreference: %v", err)) - if err := r.client.Status().Update(ctx, build); err != nil { - return reconcile.Result{}, err + // Set OwnerReference for Build and BuildRun only when build retention AtBuildDeletion is set to "true" + if build.Spec.Retention != nil && build.Spec.Retention.AtBuildDeletion != nil { + if *build.Spec.Retention.AtBuildDeletion && !resources.IsOwnedByBuild(build, buildRun.OwnerReferences) { + if err := r.setOwnerReferenceFunc(build, buildRun, r.scheme); err != nil { + build.Status.Reason = buildv1beta1.BuildReasonPtr(buildv1beta1.SetOwnerReferenceFailed) + build.Status.Message = pointer.String(fmt.Sprintf("unexpected error when trying to set the ownerreference: %v", err)) + if err := r.client.Status().Update(ctx, build); err != nil { + return reconcile.Result{}, err + } } + ctxlog.Info(ctx, fmt.Sprintf("updating BuildRun %s OwnerReferences, owner is Build %s", buildRun.Name, build.Name), namespace, request.Namespace, name, request.Name) + updateBuildRunRequired = true } - ctxlog.Info(ctx, fmt.Sprintf("updating BuildRun %s OwnerReferences, owner is Build %s", buildRun.Name, build.Name), namespace, request.Namespace, name, request.Name) - updateBuildRunRequired = true } // Add missing build name and generation labels to BuildRun (unless it is an embedded build) if build.Name != "" && build.Generation != 0 { buildGeneration := strconv.FormatInt(build.Generation, 10) - if buildRun.GetLabels()[buildv1alpha1.LabelBuild] != build.Name || buildRun.GetLabels()[buildv1alpha1.LabelBuildGeneration] != buildGeneration { - buildRun.Labels[buildv1alpha1.LabelBuild] = build.Name - buildRun.Labels[buildv1alpha1.LabelBuildGeneration] = buildGeneration + if buildRun.GetLabels()[buildv1beta1.LabelBuild] != build.Name || buildRun.GetLabels()[buildv1beta1.LabelBuildGeneration] != buildGeneration { + buildRun.Labels[buildv1beta1.LabelBuild] = build.Name + buildRun.Labels[buildv1beta1.LabelBuildGeneration] = buildGeneration ctxlog.Info(ctx, "updating BuildRun labels", namespace, request.Namespace, name, request.Name) updateBuildRunRequired = true } @@ -253,11 +254,10 @@ func (r *ReconcileBuildRun) Reconcile(ctx context.Context, request reconcile.Req if err := r.client.Status().Update(ctx, buildRun); err != nil { return reconcile.Result{}, err } - // Choose a service account to use svcAccount, err := resources.RetrieveServiceAccount(ctx, r.client, build, buildRun) if err != nil { - if !resources.IsClientStatusUpdateError(err) && buildRun.Status.IsFailed(buildv1alpha1.Succeeded) { + if !resources.IsClientStatusUpdateError(err) && buildRun.Status.IsFailed(buildv1beta1.Succeeded) { return reconcile.Result{}, nil } // system call failure, reconcile again @@ -266,7 +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(buildv1alpha1.Succeeded) { + if !resources.IsClientStatusUpdateError(err) && buildRun.Status.IsFailed(buildv1beta1.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(buildv1alpha1.Succeeded) { + if !resources.IsClientStatusUpdateError(err) && buildRun.Status.IsFailed(buildv1beta1.Succeeded) { ctxlog.Info(ctx, "taskRun generation failed", namespace, request.Namespace, name, request.Name) return reconcile.Result{}, nil } @@ -305,7 +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(buildv1alpha1.VolumeDoesNotExist)); err != nil { + if err := resources.UpdateConditionWithFalseStatus(ctx, r.client, buildRun, err.Error(), string(buildv1beta1.VolumeDoesNotExist)); err != nil { return reconcile.Result{}, err } @@ -324,7 +324,7 @@ func (r *ReconcileBuildRun) Reconcile(ctx context.Context, request reconcile.Req } // Set the LastTaskRunRef in the BuildRun status - buildRun.Status.LatestTaskRunRef = &generatedTaskRun.Name + buildRun.Status.TaskRunName = &generatedTaskRun.Name ctxlog.Info(ctx, "updating BuildRun status with TaskRun name", namespace, request.Namespace, name, request.Name, "TaskRun", generatedTaskRun.Name) if err = r.client.Status().Update(ctx, buildRun); err != nil { // we ignore the error here to prevent another reconciliation that would create another TaskRun, @@ -359,7 +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[buildv1alpha1.LabelBuildRun], request.Namespace, buildRun) + err := r.GetBuildRunObject(ctx, lastTaskRun.Labels[buildv1beta1.LabelBuildRun], request.Namespace, buildRun) if err != nil && !apierrors.IsNotFound(err) { return reconcile.Result{}, err } @@ -408,7 +408,7 @@ func (r *ReconcileBuildRun) Reconcile(ctx context.Context, request reconcile.Req } } - buildRun.Status.LatestTaskRunRef = &lastTaskRun.Name + buildRun.Status.TaskRunName = &lastTaskRun.Name if buildRun.Status.StartTime == nil && lastTaskRun.Status.StartTime != nil { buildRun.Status.StartTime = lastTaskRun.Status.StartTime @@ -479,13 +479,13 @@ func (r *ReconcileBuildRun) Reconcile(ctx context.Context, request reconcile.Req } // GetBuildRunObject retrieves an existing BuildRun based on a name and namespace -func (r *ReconcileBuildRun) GetBuildRunObject(ctx context.Context, objectName string, objectNS string, buildRun *buildv1alpha1.BuildRun) error { +func (r *ReconcileBuildRun) GetBuildRunObject(ctx context.Context, objectName string, objectNS string, buildRun *buildv1beta1.BuildRun) error { return r.client.Get(ctx, types.NamespacedName{Name: objectName, Namespace: objectNS}, buildRun) } // VerifyRequestName parse a Reconcile request name and looks for an associated BuildRun name // If the BuildRun object exists and is not yet completed, it will update it with an error. -func (r *ReconcileBuildRun) VerifyRequestName(ctx context.Context, request reconcile.Request, buildRun *buildv1alpha1.BuildRun) { +func (r *ReconcileBuildRun) VerifyRequestName(ctx context.Context, request reconcile.Request, buildRun *buildv1beta1.BuildRun) { regxBuildRun, _ := regexp.Compile(generatedNameRegex) @@ -506,7 +506,7 @@ func (r *ReconcileBuildRun) VerifyRequestName(ctx context.Context, request recon } } -func (r *ReconcileBuildRun) getReferencedStrategy(ctx context.Context, build *buildv1alpha1.Build, buildRun *buildv1alpha1.BuildRun) (strategy buildv1alpha1.BuilderStrategy, err error) { +func (r *ReconcileBuildRun) getReferencedStrategy(ctx context.Context, build *buildv1beta1.Build, buildRun *buildv1beta1.BuildRun) (strategy buildv1beta1.BuilderStrategy, err error) { if build.Spec.Strategy.Kind == nil { // If the strategy Kind is not specified, we default to a namespaced-scope strategy ctxlog.Info(ctx, "missing strategy Kind, defaulting to a namespaced-scope one", buildRun.Name, build.Name, namespace) @@ -522,7 +522,7 @@ func (r *ReconcileBuildRun) getReferencedStrategy(ctx context.Context, build *bu } switch *build.Spec.Strategy.Kind { - case buildv1alpha1.NamespacedBuildStrategyKind: + case buildv1beta1.NamespacedBuildStrategyKind: strategy, err = resources.RetrieveBuildStrategy(ctx, r.client, build) if err != nil { if apierrors.IsNotFound(err) { @@ -531,7 +531,7 @@ func (r *ReconcileBuildRun) getReferencedStrategy(ctx context.Context, build *bu } } } - case buildv1alpha1.ClusterBuildStrategyKind: + case buildv1beta1.ClusterBuildStrategyKind: strategy, err = resources.RetrieveClusterBuildStrategy(ctx, r.client, build) if err != nil { if apierrors.IsNotFound(err) { @@ -550,7 +550,7 @@ func (r *ReconcileBuildRun) getReferencedStrategy(ctx context.Context, build *bu return strategy, err } -func (r *ReconcileBuildRun) createTaskRun(ctx context.Context, serviceAccount *corev1.ServiceAccount, strategy buildv1alpha1.BuilderStrategy, build *buildv1alpha1.Build, buildRun *buildv1alpha1.BuildRun) (*pipelineapi.TaskRun, error) { +func (r *ReconcileBuildRun) createTaskRun(ctx context.Context, serviceAccount *corev1.ServiceAccount, strategy buildv1beta1.BuilderStrategy, build *buildv1beta1.Build, buildRun *buildv1beta1.BuildRun) (*pipelineapi.TaskRun, error) { var ( generatedTaskRun *pipelineapi.TaskRun ) diff --git a/pkg/reconciler/buildrun/buildrun_test.go b/pkg/reconciler/buildrun/buildrun_test.go index 1f95f07649..f05e76db6f 100644 --- a/pkg/reconciler/buildrun/buildrun_test.go +++ b/pkg/reconciler/buildrun/buildrun_test.go @@ -29,12 +29,12 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" "github.com/shipwright-io/build/pkg/apis" - build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/config" "github.com/shipwright-io/build/pkg/controller/fakes" buildrunctl "github.com/shipwright-io/build/pkg/reconciler/buildrun" "github.com/shipwright-io/build/pkg/reconciler/buildrun/resources" - test "github.com/shipwright-io/build/test/v1alpha1_samples" + test "github.com/shipwright-io/build/test/v1beta1_samples" ) var _ = Describe("Reconcile BuildRun", func() { @@ -1173,7 +1173,7 @@ var _ = Describe("Reconcile BuildRun", func() { ) // Ensure the BuildRun gets an ownershipReference when - // the buildv1alpha1.AnnotationBuildRunDeletion is set to true + // the spec.Retention.AtBuildDeletion is set to true // in the build clientUpdateCalls := ctl.StubBuildUpdateOwnerReferences("Build", buildName, @@ -1323,14 +1323,16 @@ var _ = Describe("Reconcile BuildRun", func() { }) }) - It("should mark BuildRun as invalid if BuildRef and BuildSpec are used", func() { + It("should mark BuildRun as invalid if Build name and BuildSpec are used", func() { buildRunSample = &build.BuildRun{ ObjectMeta: metav1.ObjectMeta{ Name: buildRunName, }, Spec: build.BuildRunSpec{ - BuildRef: &build.BuildRef{}, - BuildSpec: &build.BuildSpec{}, + Build: build.ReferencedBuild{ + Build: &build.BuildSpec{}, + Name: pointer.String("foobar"), + }, }, } @@ -1346,8 +1348,10 @@ var _ = Describe("Reconcile BuildRun", func() { Name: buildRunName, }, Spec: build.BuildRunSpec{ - Output: &build.Image{Image: "foo:bar"}, - BuildSpec: &build.BuildSpec{}, + Output: &build.Image{Image: "foo:bar"}, + Build: build.ReferencedBuild{ + Build: &build.BuildSpec{}, + }, }, } @@ -1367,7 +1371,9 @@ var _ = Describe("Reconcile BuildRun", func() { Name: "foo", SingleValue: &build.SingleValue{Value: pointer.String("bar")}, }}, - BuildSpec: &build.BuildSpec{}, + Build: build.ReferencedBuild{ + Build: &build.BuildSpec{}, + }, }, } @@ -1383,8 +1389,10 @@ var _ = Describe("Reconcile BuildRun", func() { Name: buildRunName, }, Spec: build.BuildRunSpec{ - Env: []corev1.EnvVar{{Name: "foo", Value: "bar"}}, - BuildSpec: &build.BuildSpec{}, + Env: []corev1.EnvVar{{Name: "foo", Value: "bar"}}, + Build: build.ReferencedBuild{ + Build: &build.BuildSpec{}, + }, }, } @@ -1400,8 +1408,10 @@ var _ = Describe("Reconcile BuildRun", func() { Name: buildRunName, }, Spec: build.BuildRunSpec{ - Timeout: &metav1.Duration{Duration: time.Second}, - BuildSpec: &build.BuildSpec{}, + Timeout: &metav1.Duration{Duration: time.Second}, + Build: build.ReferencedBuild{ + Build: &build.BuildSpec{}, + }, }, } @@ -1419,22 +1429,25 @@ var _ = Describe("Reconcile BuildRun", func() { Name: buildRunName, }, Spec: build.BuildRunSpec{ - BuildSpec: &build.BuildSpec{ - Source: build.Source{ - URL: pointer.String("https://github.com/shipwright-io/sample-go.git"), - ContextDir: pointer.String("source-build"), + Build: build.ReferencedBuild{ + Build: &build.BuildSpec{ + Source: build.Source{ + Type: build.GitType, + GitSource: &build.Git{ + URL: "https://github.com/shipwright-io/sample-go.git", + }, + ContextDir: pointer.String("source-build"), + }, + Strategy: build.Strategy{ + Kind: &clusterBuildStrategy, + Name: strategyName, + }, + Output: build.Image{ + Image: "foo/bar:latest", + }, }, - Strategy: build.Strategy{ - Kind: &clusterBuildStrategy, - Name: strategyName, - }, - Output: build.Image{ - Image: "foo/bar:latest", - }, - }, - ServiceAccount: &build.ServiceAccount{ - Generate: pointer.Bool(true), }, + ServiceAccount: pointer.String(".generate"), }, } @@ -1443,7 +1456,6 @@ var _ = Describe("Reconcile BuildRun", func() { case *build.BuildRun: buildRunSample.DeepCopyInto(object) return nil - case *build.ClusterBuildStrategy: ctl.ClusterBuildStrategy(strategyName).DeepCopyInto(object) return nil @@ -1468,7 +1480,6 @@ var _ = Describe("Reconcile BuildRun", func() { switch taskRun := o.(type) { case *pipelineapi.TaskRun: taskRunCreates++ - Expect(taskRun.Labels).ToNot(HaveKey(build.LabelBuild), "no build name label is suppose to be set") Expect(taskRun.Labels).ToNot(HaveKey(build.LabelBuildGeneration), "no build generation label is suppose to be set") } diff --git a/pkg/reconciler/buildrun/controller.go b/pkg/reconciler/buildrun/controller.go index d241ada9a4..112c5afa41 100644 --- a/pkg/reconciler/buildrun/controller.go +++ b/pkg/reconciler/buildrun/controller.go @@ -23,7 +23,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" "sigs.k8s.io/controller-runtime/pkg/source" - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/config" ) @@ -53,16 +53,16 @@ func add(mgr manager.Manager, r reconcile.Reconciler, maxConcurrentReconciles in predBuildRun := predicate.Funcs{ CreateFunc: func(e event.CreateEvent) bool { - o := e.Object.(*buildv1alpha1.BuildRun) + o := e.Object.(*buildv1beta1.BuildRun) // The CreateFunc is also called when the controller is started and iterates over all objects. For those BuildRuns that have a TaskRun referenced already, // we do not need to do a further reconciliation. BuildRun updates then only happen from the TaskRun. - return o.Status.LatestTaskRunRef == nil && o.Status.CompletionTime == nil + return o.Status.TaskRunName == nil && o.Status.CompletionTime == nil }, UpdateFunc: func(e event.UpdateEvent) bool { // Ignore updates to CR status in which case metadata.Generation does not change - o := e.ObjectOld.(*buildv1alpha1.BuildRun) - n := e.ObjectNew.(*buildv1alpha1.BuildRun) + o := e.ObjectOld.(*buildv1beta1.BuildRun) + n := e.ObjectNew.(*buildv1beta1.BuildRun) // Only reconcile a BuildRun update when // - it is set to canceled @@ -107,7 +107,7 @@ func add(mgr manager.Manager, r reconcile.Reconciler, maxConcurrentReconciles in } // Watch for changes to primary resource BuildRun - if err = c.Watch(&source.Kind{Type: &buildv1alpha1.BuildRun{}}, &handler.EnqueueRequestForObject{}, predBuildRun); err != nil { + if err = c.Watch(&source.Kind{Type: &buildv1beta1.BuildRun{}}, &handler.EnqueueRequestForObject{}, predBuildRun); err != nil { return err } @@ -117,7 +117,7 @@ func add(mgr manager.Manager, r reconcile.Reconciler, maxConcurrentReconciles in taskRun := o.(*pipelineapi.TaskRun) // check if TaskRun is related to BuildRun - if taskRun.GetLabels() == nil || taskRun.GetLabels()[buildv1alpha1.LabelBuildRun] == "" { + if taskRun.GetLabels() == nil || taskRun.GetLabels()[buildv1beta1.LabelBuildRun] == "" { return []reconcile.Request{} } diff --git a/pkg/reconciler/buildrun/resources/build.go b/pkg/reconciler/buildrun/resources/build.go index 72e8e419d1..b58d8d6430 100644 --- a/pkg/reconciler/buildrun/resources/build.go +++ b/pkg/reconciler/buildrun/resources/build.go @@ -13,19 +13,19 @@ import ( "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" ) // GetBuildObject retrieves an existing Build based on a name and namespace -func GetBuildObject(ctx context.Context, client client.Client, buildRun *buildv1alpha1.BuildRun, build *buildv1alpha1.Build) error { +func GetBuildObject(ctx context.Context, client client.Client, buildRun *buildv1beta1.BuildRun, build *buildv1beta1.Build) error { // Option #1: BuildRef is specified // An actual Build resource is specified by name and needs to be looked up in the cluster. - if buildRun.Spec.BuildRef != nil { + if buildRun.Spec.Build.Name != nil { err := client.Get(ctx, types.NamespacedName{Name: buildRun.Spec.BuildName(), Namespace: buildRun.Namespace}, build) if apierrors.IsNotFound(err) { // stop reconciling and mark the BuildRun as Failed // we only reconcile again if the status.Update call fails - if updateErr := UpdateConditionWithFalseStatus(ctx, client, buildRun, fmt.Sprintf("build.shipwright.io %q not found", buildRun.Spec.BuildRef.Name), ConditionBuildNotFound); updateErr != nil { + if updateErr := UpdateConditionWithFalseStatus(ctx, client, buildRun, fmt.Sprintf("build.shipwright.io %q not found", *buildRun.Spec.Build.Name), ConditionBuildNotFound); updateErr != nil { return HandleError("build object not found", err, updateErr) } } @@ -35,11 +35,11 @@ func GetBuildObject(ctx context.Context, client client.Client, buildRun *buildv1 // Option #2: BuildSpec is specified // The build specification is embedded in the BuildRun itself, create a transient Build resource. - if buildRun.Spec.BuildSpec != nil { + if buildRun.Spec.Build.Build != nil { build.Name = "" build.Namespace = buildRun.Namespace - build.Status = buildv1alpha1.BuildStatus{} - buildRun.Spec.BuildSpec.DeepCopyInto(&build.Spec) + build.Status = buildv1beta1.BuildStatus{} + buildRun.Spec.Build.Build.DeepCopyInto(&build.Spec) return nil } @@ -48,7 +48,7 @@ func GetBuildObject(ctx context.Context, client client.Client, buildRun *buildv1 } // IsOwnedByBuild checks if the controllerReferences contains a well known owner Kind -func IsOwnedByBuild(build *buildv1alpha1.Build, controlledReferences []metav1.OwnerReference) bool { +func IsOwnedByBuild(build *buildv1beta1.Build, controlledReferences []metav1.OwnerReference) bool { for _, ref := range controlledReferences { if ref.Kind == build.Kind && ref.Name == build.Name { return true diff --git a/pkg/reconciler/buildrun/resources/build_test.go b/pkg/reconciler/buildrun/resources/build_test.go index c559f1447f..9814c77dc0 100644 --- a/pkg/reconciler/buildrun/resources/build_test.go +++ b/pkg/reconciler/buildrun/resources/build_test.go @@ -17,10 +17,10 @@ import ( "k8s.io/apimachinery/pkg/types" crc "sigs.k8s.io/controller-runtime/pkg/client" - build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/controller/fakes" "github.com/shipwright-io/build/pkg/reconciler/buildrun/resources" - test "github.com/shipwright-io/build/test/v1alpha1_samples" + test "github.com/shipwright-io/build/test/v1beta1_samples" ) var _ = Describe("Build Resource", func() { @@ -39,8 +39,8 @@ var _ = Describe("Build Resource", func() { Namespace: "bar", }, Spec: build.BuildRunSpec{ - BuildRef: &build.BuildRef{ - Name: buildName, + Build: build.ReferencedBuild{ + Name: &buildName, }, }, } @@ -136,8 +136,10 @@ var _ = Describe("Build Resource", func() { Namespace: "bar", }, Spec: build.BuildRunSpec{ - BuildSpec: &build.BuildSpec{ - Env: []v1.EnvVar{{Name: "foo", Value: "bar"}}, + Build: build.ReferencedBuild{ + Build: &build.BuildSpec{ + Env: []v1.EnvVar{{Name: "foo", Value: "bar"}}, + }, }, }, } diff --git a/pkg/reconciler/buildrun/resources/conditions.go b/pkg/reconciler/buildrun/resources/conditions.go index 3478096212..0d3ef8380a 100644 --- a/pkg/reconciler/buildrun/resources/conditions.go +++ b/pkg/reconciler/buildrun/resources/conditions.go @@ -16,7 +16,7 @@ import ( apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/ctxlog" ) @@ -47,7 +47,7 @@ const ( ) // UpdateBuildRunUsingTaskRunCondition updates the BuildRun Succeeded Condition -func UpdateBuildRunUsingTaskRunCondition(ctx context.Context, client client.Client, buildRun *buildv1alpha1.BuildRun, taskRun *pipelineapi.TaskRun, trCondition *apis.Condition) error { +func UpdateBuildRunUsingTaskRunCondition(ctx context.Context, client client.Client, buildRun *buildv1beta1.BuildRun, taskRun *pipelineapi.TaskRun, trCondition *apis.Condition) error { var reason, message string = trCondition.Reason, trCondition.Message status := trCondition.Status @@ -57,13 +57,13 @@ func UpdateBuildRunUsingTaskRunCondition(ctx context.Context, client client.Clie case pipelineapi.TaskRunReasonRunning: if buildRun.IsCanceled() { status = corev1.ConditionUnknown // in practice the taskrun status is already unknown in this case, but we are making sure here - reason = buildv1alpha1.BuildRunStateCancel + reason = buildv1beta1.BuildRunStateCancel message = "The user requested the BuildRun to be canceled. This BuildRun controller has requested the TaskRun be canceled. That request has not been process by Tekton's TaskRun controller yet." } case pipelineapi.TaskRunReasonCancelled: if buildRun.IsCanceled() { status = corev1.ConditionFalse // in practice the taskrun status is already false in this case, bue we are making sure here - reason = buildv1alpha1.BuildRunStateCancel + reason = buildv1beta1.BuildRunStateCancel message = "The BuildRun and underlying TaskRun were canceled successfully." } @@ -95,18 +95,22 @@ func UpdateBuildRunUsingTaskRunCondition(ctx context.Context, client client.Clie } //nolint:staticcheck // SA1019 we want to give users some time to adopt to failureDetails - buildRun.Status.FailedAt = &buildv1alpha1.FailedAt{Pod: pod.Name} + buildRun.Status.FailureDetails = &buildv1beta1.FailureDetails{ + Location: &buildv1beta1.Location{ + Pod: pod.Name, + }, + } if pod.Status.Reason == "Evicted" { message = pod.Status.Message - reason = buildv1alpha1.BuildRunStatePodEvicted + reason = buildv1beta1.BuildRunStatePodEvicted if failedContainer != nil { //nolint:staticcheck // SA1019 we want to give users some time to adopt to failureDetails - buildRun.Status.FailedAt.Container = failedContainer.Name + buildRun.Status.FailureDetails.Location.Container = failedContainer.Name } } else if failedContainer != nil { //nolint:staticcheck // SA1019 we want to give users some time to adopt to failureDetails - buildRun.Status.FailedAt.Container = failedContainer.Name + buildRun.Status.FailureDetails.Location.Container = failedContainer.Name message = fmt.Sprintf("buildrun step %s failed in pod %s, for detailed information: kubectl --namespace %s logs %s --container=%s", failedContainer.Name, pod.Name, @@ -124,9 +128,9 @@ func UpdateBuildRunUsingTaskRunCondition(ctx context.Context, client client.Clie } } - buildRun.Status.SetCondition(&buildv1alpha1.Condition{ + buildRun.Status.SetCondition(&buildv1beta1.Condition{ LastTransitionTime: metav1.Now(), - Type: buildv1alpha1.Succeeded, + Type: buildv1beta1.Succeeded, Status: status, Reason: reason, Message: message, @@ -138,12 +142,12 @@ func UpdateBuildRunUsingTaskRunCondition(ctx context.Context, client client.Clie // UpdateConditionWithFalseStatus sets the Succeeded condition fields and mark // the condition as Status False. It also updates the object in the cluster by // calling client Status Update -func UpdateConditionWithFalseStatus(ctx context.Context, client client.Client, buildRun *buildv1alpha1.BuildRun, errorMessage string, reason string) error { +func UpdateConditionWithFalseStatus(ctx context.Context, client client.Client, buildRun *buildv1beta1.BuildRun, errorMessage string, reason string) error { now := metav1.Now() buildRun.Status.CompletionTime = &now - buildRun.Status.SetCondition(&buildv1alpha1.Condition{ + buildRun.Status.SetCondition(&buildv1beta1.Condition{ LastTransitionTime: now, - Type: buildv1alpha1.Succeeded, + Type: buildv1beta1.Succeeded, Status: corev1.ConditionFalse, Reason: reason, Message: errorMessage, diff --git a/pkg/reconciler/buildrun/resources/conditions_test.go b/pkg/reconciler/buildrun/resources/conditions_test.go index 84661792ad..06dbe2fbcc 100644 --- a/pkg/reconciler/buildrun/resources/conditions_test.go +++ b/pkg/reconciler/buildrun/resources/conditions_test.go @@ -9,10 +9,10 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/controller/fakes" "github.com/shipwright-io/build/pkg/reconciler/buildrun/resources" - test "github.com/shipwright-io/build/test/v1alpha1_samples" + test "github.com/shipwright-io/build/test/v1beta1_samples" pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" corev1 "k8s.io/api/core/v1" k8serrors "k8s.io/apimachinery/pkg/api/errors" diff --git a/pkg/reconciler/buildrun/resources/credentials.go b/pkg/reconciler/buildrun/resources/credentials.go index 2836acbf79..495154b410 100644 --- a/pkg/reconciler/buildrun/resources/credentials.go +++ b/pkg/reconciler/buildrun/resources/credentials.go @@ -9,51 +9,44 @@ import ( corev1 "k8s.io/api/core/v1" - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/ctxlog" ) // ApplyCredentials adds all credentials that are referenced by the build and adds them to the service account. // The function returns true if the service account was modified. -func ApplyCredentials(ctx context.Context, build *buildv1alpha1.Build, buildRun *buildv1alpha1.BuildRun, serviceAccount *corev1.ServiceAccount) bool { +func ApplyCredentials(ctx context.Context, build *buildv1beta1.Build, buildRun *buildv1beta1.BuildRun, serviceAccount *corev1.ServiceAccount) bool { modified := false - // credentials of the 'Builder' image registry - builderImage := build.Spec.Builder - if builderImage != nil && builderImage.Credentials != nil { - modified = updateServiceAccountIfSecretNotLinked(ctx, builderImage.Credentials, serviceAccount) || modified - } - // if output is overridden by buildrun, and if this override has credentials, // it should be added to the sa - if buildRun.Spec.Output != nil && buildRun.Spec.Output.Credentials != nil { - modified = updateServiceAccountIfSecretNotLinked(ctx, buildRun.Spec.Output.Credentials, serviceAccount) || modified + if buildRun.Spec.Output != nil && buildRun.Spec.Output.PushSecret != nil { + modified = updateServiceAccountIfSecretNotLinked(ctx, *buildRun.Spec.Output.PushSecret, serviceAccount) || modified } else { // otherwise, if buildrun does not override the output credentials, // we should use the ones provided by the build - outputSecret := build.Spec.Output.Credentials - if outputSecret != nil { - modified = updateServiceAccountIfSecretNotLinked(ctx, outputSecret, serviceAccount) || modified + if build.Spec.Output.PushSecret != nil { + modified = updateServiceAccountIfSecretNotLinked(ctx, *build.Spec.Output.PushSecret, serviceAccount) || modified } } return modified } -func updateServiceAccountIfSecretNotLinked(ctx context.Context, sourceSecret *corev1.LocalObjectReference, serviceAccount *corev1.ServiceAccount) bool { +func updateServiceAccountIfSecretNotLinked(ctx context.Context, sourceSecret string, serviceAccount *corev1.ServiceAccount) bool { isSecretPresent := false for _, credentialSecret := range serviceAccount.Secrets { - if credentialSecret.Name == sourceSecret.Name { + if credentialSecret.Name == sourceSecret { isSecretPresent = true break } } if !isSecretPresent { - ctxlog.Debug(ctx, "adding secret to serviceAccount", "secret", sourceSecret.Name, "serviceAccount", serviceAccount.Name) + ctxlog.Debug(ctx, "adding secret to serviceAccount", "secret", sourceSecret, "serviceAccount", serviceAccount.Name) serviceAccount.Secrets = append(serviceAccount.Secrets, corev1.ObjectReference{ - Name: sourceSecret.Name, + Name: sourceSecret, }) return true } diff --git a/pkg/reconciler/buildrun/resources/credentials_test.go b/pkg/reconciler/buildrun/resources/credentials_test.go index 95d02aafa9..91d29006ff 100644 --- a/pkg/reconciler/buildrun/resources/credentials_test.go +++ b/pkg/reconciler/buildrun/resources/credentials_test.go @@ -13,14 +13,14 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/utils/pointer" - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/reconciler/buildrun/resources" ) var _ = Describe("Credentials", func() { var ( - build *buildv1alpha1.Build - buildRun *buildv1alpha1.BuildRun + build *buildv1beta1.Build + buildRun *buildv1beta1.BuildRun beforeServiceAccount *corev1.ServiceAccount expectedAfterServiceAccount *corev1.ServiceAccount ) @@ -35,36 +35,27 @@ var _ = Describe("Credentials", func() { Context("when secrets were not present in the service account", func() { BeforeEach(func() { - build = &buildv1alpha1.Build{ - Spec: buildv1alpha1.BuildSpec{ - Source: buildv1alpha1.Source{ - URL: pointer.String("a/b/c"), - Credentials: &corev1.LocalObjectReference{ - Name: "secret_a", + build = &buildv1beta1.Build{ + Spec: buildv1beta1.BuildSpec{ + Source: buildv1beta1.Source{ + Type: buildv1beta1.GitType, + GitSource: &buildv1beta1.Git{ + URL: "a/b/c", + CloneSecret: pointer.String("secret_a"), }, }, - Builder: &buildv1alpha1.Image{ - Image: "quay.io/namespace/image", - Credentials: &corev1.LocalObjectReference{ - Name: "secret_docker.io", - }, - }, - Output: buildv1alpha1.Image{ - Image: "quay.io/namespace/image", - Credentials: &corev1.LocalObjectReference{ - Name: "secret_quay.io", - }, + Output: buildv1beta1.Image{ + Image: "quay.io/namespace/image", + PushSecret: pointer.String("secret_quay.io"), }, }, } - buildRun = &buildv1alpha1.BuildRun{ - Spec: buildv1alpha1.BuildRunSpec{ - Output: &buildv1alpha1.Image{ - Image: "quay.io/namespace/brImage", - Credentials: &corev1.LocalObjectReference{ - Name: "secret_buildrun.io", - }, + buildRun = &buildv1beta1.BuildRun{ + Spec: buildv1beta1.BuildRunSpec{ + Output: &buildv1beta1.Image{ + Image: "quay.io/namespace/brImage", + PushSecret: pointer.String("secret_buildrun.io"), }, }, } @@ -74,7 +65,6 @@ var _ = Describe("Credentials", func() { Secrets: []corev1.ObjectReference{ {Name: "secret_b"}, {Name: "secret_c"}, - {Name: "secret_docker.io"}, {Name: "secret_buildrun.io"}, }, } @@ -91,24 +81,25 @@ var _ = Describe("Credentials", func() { Context("when secrets were already in the service account", func() { BeforeEach(func() { - build = &buildv1alpha1.Build{ - Spec: buildv1alpha1.BuildSpec{ - Source: buildv1alpha1.Source{ - URL: pointer.String("a/b/c"), - }, - Output: buildv1alpha1.Image{ - Credentials: &corev1.LocalObjectReference{ - Name: "secret_b", + build = &buildv1beta1.Build{ + Spec: buildv1beta1.BuildSpec{ + Source: buildv1beta1.Source{ + Type: buildv1beta1.GitType, + GitSource: &buildv1beta1.Git{ + URL: "a/b/c", }, }, + Output: buildv1beta1.Image{ + PushSecret: pointer.String("secret_b"), + }, }, } // This is just a placeholder BuildRun with no // SecretRef added to the ones from the Build - buildRun = &buildv1alpha1.BuildRun{ - Spec: buildv1alpha1.BuildRunSpec{ - Output: &buildv1alpha1.Image{ + buildRun = &buildv1beta1.BuildRun{ + Spec: buildv1beta1.BuildRunSpec{ + Output: &buildv1beta1.Image{ Image: "https://image.url/", }, }, @@ -128,20 +119,23 @@ var _ = Describe("Credentials", func() { Context("when build does not reference any secret", func() { BeforeEach(func() { - build = &buildv1alpha1.Build{ - Spec: buildv1alpha1.BuildSpec{ - Source: buildv1alpha1.Source{ - URL: pointer.String("a/b/c"), - Credentials: nil, + build = &buildv1beta1.Build{ + Spec: buildv1beta1.BuildSpec{ + Source: buildv1beta1.Source{ + Type: buildv1beta1.GitType, + GitSource: &buildv1beta1.Git{ + URL: "a/b/c", + CloneSecret: nil, + }, }, }, } // This is just a placeholder BuildRun with no // SecretRef added to the ones from the Build - buildRun = &buildv1alpha1.BuildRun{ - Spec: buildv1alpha1.BuildRunSpec{ - Output: &buildv1alpha1.Image{ + buildRun = &buildv1beta1.BuildRun{ + Spec: buildv1beta1.BuildRunSpec{ + Output: &buildv1beta1.Image{ Image: "https://image.url/", }, }, diff --git a/pkg/reconciler/buildrun/resources/failure_details.go b/pkg/reconciler/buildrun/resources/failure_details.go index b96451abaf..3be2dc272e 100644 --- a/pkg/reconciler/buildrun/resources/failure_details.go +++ b/pkg/reconciler/buildrun/resources/failure_details.go @@ -13,7 +13,7 @@ import ( "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/ctxlog" pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" "github.com/tektoncd/pipeline/pkg/result" @@ -28,7 +28,7 @@ const ( ) // UpdateBuildRunUsingTaskFailures is extracting failures from taskRun steps and adding them to buildRun (mutates) -func UpdateBuildRunUsingTaskFailures(ctx context.Context, client client.Client, buildRun *buildv1alpha1.BuildRun, taskRun *pipelineapi.TaskRun) { +func UpdateBuildRunUsingTaskFailures(ctx context.Context, client client.Client, buildRun *buildv1beta1.BuildRun, taskRun *pipelineapi.TaskRun) { trCondition := taskRun.Status.GetCondition(apis.ConditionSucceeded) // only extract failures when failing condition is present @@ -91,12 +91,12 @@ func extractFailedPodAndContainer(ctx context.Context, client client.Client, tas return &pod, failedContainer, nil } -func extractFailureDetails(ctx context.Context, client client.Client, taskRun *pipelineapi.TaskRun) (failure *buildv1alpha1.FailureDetails) { - failure = &buildv1alpha1.FailureDetails{} +func extractFailureDetails(ctx context.Context, client client.Client, taskRun *pipelineapi.TaskRun) (failure *buildv1beta1.FailureDetails) { + failure = &buildv1beta1.FailureDetails{} failure.Reason, failure.Message = extractFailureReasonAndMessage(taskRun) - failure.Location = &buildv1alpha1.FailedAt{Pod: taskRun.Status.PodName} + failure.Location = &buildv1beta1.Location{Pod: taskRun.Status.PodName} pod, container, _ := extractFailedPodAndContainer(ctx, client, taskRun) if pod != nil && container != nil { diff --git a/pkg/reconciler/buildrun/resources/failure_details_test.go b/pkg/reconciler/buildrun/resources/failure_details_test.go index dbae3cc308..225e3dc0dc 100644 --- a/pkg/reconciler/buildrun/resources/failure_details_test.go +++ b/pkg/reconciler/buildrun/resources/failure_details_test.go @@ -16,7 +16,7 @@ import ( corev1 "k8s.io/api/core/v1" "knative.dev/pkg/apis" - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" buildfakes "github.com/shipwright-io/build/pkg/controller/fakes" ) @@ -46,7 +46,7 @@ var _ = Describe("Surfacing errors", func() { followUpStep := pipelineapi.StepState{} redTaskRun.Status.Steps = append(redTaskRun.Status.Steps, failedStep, followUpStep) - redBuild := buildv1alpha1.BuildRun{} + redBuild := buildv1beta1.BuildRun{} UpdateBuildRunUsingTaskFailures(ctx, client, &redBuild, &redTaskRun) @@ -67,7 +67,7 @@ var _ = Describe("Surfacing errors", func() { failedStep.Terminated = &corev1.ContainerStateTerminated{Message: string(message)} redTaskRun.Status.Steps = append(redTaskRun.Status.Steps, failedStep) - redBuild := buildv1alpha1.BuildRun{} + redBuild := buildv1beta1.BuildRun{} UpdateBuildRunUsingTaskFailures(ctx, client, &redBuild, &redTaskRun) @@ -93,7 +93,7 @@ var _ = Describe("Surfacing errors", func() { failedStep.Terminated = &corev1.ContainerStateTerminated{Message: string(message)} greenTaskRun.Status.Steps = append(greenTaskRun.Status.Steps, failedStep) - greenBuildRun := buildv1alpha1.BuildRun{} + greenBuildRun := buildv1beta1.BuildRun{} UpdateBuildRunUsingTaskFailures(ctx, client, &greenBuildRun, &greenTaskRun) @@ -103,7 +103,7 @@ var _ = Describe("Surfacing errors", func() { It("should not surface errors for a successful TaskRun", func() { greenTaskRun := pipelineapi.TaskRun{} greenTaskRun.Status.Conditions = append(greenTaskRun.Status.Conditions, apis.Condition{Type: apis.ConditionSucceeded}) - greenBuildRun := buildv1alpha1.BuildRun{} + greenBuildRun := buildv1beta1.BuildRun{} UpdateBuildRunUsingTaskFailures(ctx, client, &greenBuildRun, &greenTaskRun) @@ -113,7 +113,7 @@ var _ = Describe("Surfacing errors", func() { It("should not surface errors if the TaskRun does not have a Succeeded condition", func() { unfinishedTaskRun := pipelineapi.TaskRun{} unfinishedTaskRun.Status.Conditions = append(unfinishedTaskRun.Status.Conditions, apis.Condition{Type: apis.ConditionReady}) - unfinishedBuildRun := buildv1alpha1.BuildRun{} + unfinishedBuildRun := buildv1beta1.BuildRun{} UpdateBuildRunUsingTaskFailures(ctx, client, &unfinishedBuildRun, &unfinishedTaskRun) Expect(unfinishedBuildRun.Status.FailureDetails).To(BeNil()) @@ -122,7 +122,7 @@ var _ = Describe("Surfacing errors", func() { It("should not surface errors if the TaskRun is in progress", func() { unknownTaskRun := pipelineapi.TaskRun{} unknownTaskRun.Status.Conditions = append(unknownTaskRun.Status.Conditions, apis.Condition{Type: apis.ConditionSucceeded, Reason: "random"}) - unknownBuildRun := buildv1alpha1.BuildRun{} + unknownBuildRun := buildv1beta1.BuildRun{} UpdateBuildRunUsingTaskFailures(ctx, client, &unknownBuildRun, &unknownTaskRun) Expect(unknownBuildRun.Status.FailureDetails).To(BeNil()) diff --git a/pkg/reconciler/buildrun/resources/image_processing.go b/pkg/reconciler/buildrun/resources/image_processing.go index 349ed6af63..6ad80852e2 100644 --- a/pkg/reconciler/buildrun/resources/image_processing.go +++ b/pkg/reconciler/buildrun/resources/image_processing.go @@ -7,7 +7,7 @@ package resources import ( "fmt" - build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/config" "github.com/shipwright-io/build/pkg/reconciler/buildrun/resources/sources" pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" @@ -117,14 +117,14 @@ func SetupImageProcessing(taskRun *pipelineapi.TaskRun, cfg *config.Config, buil }) } - if buildOutput.Credentials != nil { - sources.AppendSecretVolume(taskRun.Spec.TaskSpec, buildOutput.Credentials.Name) + if buildOutput.PushSecret != nil { + sources.AppendSecretVolume(taskRun.Spec.TaskSpec, *buildOutput.PushSecret) secretMountPath := fmt.Sprintf("/workspace/%s-push-secret", prefixParamsResultsVolumes) // define the volume mount on the container imageProcessingStep.VolumeMounts = append(imageProcessingStep.VolumeMounts, core.VolumeMount{ - Name: sources.SanitizeVolumeNameForSecretName(buildOutput.Credentials.Name), + Name: sources.SanitizeVolumeNameForSecretName(*buildOutput.PushSecret), MountPath: secretMountPath, ReadOnly: true, }) diff --git a/pkg/reconciler/buildrun/resources/image_processing_test.go b/pkg/reconciler/buildrun/resources/image_processing_test.go index 0e7853a854..a96d9ac208 100644 --- a/pkg/reconciler/buildrun/resources/image_processing_test.go +++ b/pkg/reconciler/buildrun/resources/image_processing_test.go @@ -8,12 +8,10 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - corev1 "k8s.io/api/core/v1" - - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/config" "github.com/shipwright-io/build/pkg/reconciler/buildrun/resources" - utils "github.com/shipwright-io/build/test/utils/v1alpha1" + utils "github.com/shipwright-io/build/test/utils/v1beta1" pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" ) @@ -38,9 +36,9 @@ var _ = Describe("Image Processing overrides", func() { Context("for a build without labels and annotation in the output", func() { BeforeEach(func() { processedTaskRun = taskRun.DeepCopy() - resources.SetupImageProcessing(processedTaskRun, config, buildv1alpha1.Image{ + resources.SetupImageProcessing(processedTaskRun, config, buildv1beta1.Image{ Image: "some-registry/some-namespace/some-image", - }, buildv1alpha1.Image{}) + }, buildv1beta1.Image{}) }) It("does not add the image-processing step", func() { @@ -52,12 +50,12 @@ var _ = Describe("Image Processing overrides", func() { Context("for a build with a label in the output", func() { BeforeEach(func() { processedTaskRun = taskRun.DeepCopy() - resources.SetupImageProcessing(processedTaskRun, config, buildv1alpha1.Image{ + resources.SetupImageProcessing(processedTaskRun, config, buildv1beta1.Image{ Image: "some-registry/some-namespace/some-image", Labels: map[string]string{ "aKey": "aLabel", }, - }, buildv1alpha1.Image{}) + }, buildv1beta1.Image{}) }) It("adds the image-processing step", func() { @@ -103,12 +101,12 @@ var _ = Describe("Image Processing overrides", func() { Context("for a build with label and annotation in the output", func() { BeforeEach(func() { processedTaskRun = taskRun.DeepCopy() - resources.SetupImageProcessing(processedTaskRun, config, buildv1alpha1.Image{ + resources.SetupImageProcessing(processedTaskRun, config, buildv1beta1.Image{ Image: "some-registry/some-namespace/some-image", Labels: map[string]string{ "a-label": "a-value", }, - }, buildv1alpha1.Image{ + }, buildv1beta1.Image{ Annotations: map[string]string{ "an-annotation": "some-value", }, @@ -151,9 +149,9 @@ var _ = Describe("Image Processing overrides", func() { Context("for a build without labels and annotation in the output", func() { BeforeEach(func() { processedTaskRun = taskRun.DeepCopy() - resources.SetupImageProcessing(processedTaskRun, config, buildv1alpha1.Image{ + resources.SetupImageProcessing(processedTaskRun, config, buildv1beta1.Image{ Image: "some-registry/some-namespace/some-image", - }, buildv1alpha1.Image{}) + }, buildv1beta1.Image{}) }) It("adds the output-directory parameter", func() { @@ -189,12 +187,11 @@ var _ = Describe("Image Processing overrides", func() { Context("for a build with an output with a secret", func() { BeforeEach(func() { processedTaskRun = taskRun.DeepCopy() - resources.SetupImageProcessing(processedTaskRun, config, buildv1alpha1.Image{ - Image: "some-registry/some-namespace/some-image", - Credentials: &corev1.LocalObjectReference{ - Name: "some-secret", - }, - }, buildv1alpha1.Image{}) + someSecret := "some-secret" + resources.SetupImageProcessing(processedTaskRun, config, buildv1beta1.Image{ + Image: "some-registry/some-namespace/some-image", + PushSecret: &someSecret, + }, buildv1beta1.Image{}) }) It("adds the output-directory parameter", func() { diff --git a/pkg/reconciler/buildrun/resources/params.go b/pkg/reconciler/buildrun/resources/params.go index 3e5b9f8205..16c79c2dbf 100644 --- a/pkg/reconciler/buildrun/resources/params.go +++ b/pkg/reconciler/buildrun/resources/params.go @@ -12,7 +12,7 @@ import ( corev1 "k8s.io/api/core/v1" - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" ) @@ -31,7 +31,7 @@ var ( // OverrideParams allows to override an existing list of parameters with a second list, // as long as their entry names matches -func OverrideParams(originalParams []buildv1alpha1.ParamValue, overrideParams []buildv1alpha1.ParamValue) []buildv1alpha1.ParamValue { +func OverrideParams(originalParams []buildv1beta1.ParamValue, overrideParams []buildv1beta1.ParamValue) []buildv1beta1.ParamValue { if len(overrideParams) == 0 { return originalParams } @@ -41,7 +41,7 @@ func OverrideParams(originalParams []buildv1alpha1.ParamValue, overrideParams [] } // Build a map from originalParams - originalMap := make(map[string]buildv1alpha1.ParamValue) + originalMap := make(map[string]buildv1beta1.ParamValue) for _, p := range originalParams { originalMap[p.Name] = p } @@ -53,7 +53,7 @@ func OverrideParams(originalParams []buildv1alpha1.ParamValue, overrideParams [] } // drop results on a slice and return - paramsList := []buildv1alpha1.ParamValue{} + paramsList := []buildv1beta1.ParamValue{} for k := range originalMap { paramsList = append(paramsList, originalMap[k]) @@ -68,7 +68,7 @@ func IsSystemReservedParameter(param string) bool { } // FindParameterByName returns the first entry in a Parameter array with a specified name, or nil -func FindParameterByName(parameters []buildv1alpha1.Parameter, name string) *buildv1alpha1.Parameter { +func FindParameterByName(parameters []buildv1beta1.Parameter, name string) *buildv1beta1.Parameter { for _, candidate := range parameters { if candidate.Name == name { return &candidate @@ -79,7 +79,7 @@ func FindParameterByName(parameters []buildv1alpha1.Parameter, name string) *bui } // FindParamValueByName returns the first entry in a ParamValue array with a specified name, or nil -func FindParamValueByName(paramValues []buildv1alpha1.ParamValue, name string) *buildv1alpha1.ParamValue { +func FindParamValueByName(paramValues []buildv1beta1.ParamValue, name string) *buildv1beta1.ParamValue { for _, candidate := range paramValues { if candidate.Name == name { return &candidate @@ -90,7 +90,7 @@ func FindParamValueByName(paramValues []buildv1alpha1.ParamValue, name string) * } // HandleTaskRunParam makes the necessary changes to a TaskRun for a parameter -func HandleTaskRunParam(taskRun *pipelineapi.TaskRun, parameterDefinition *buildv1alpha1.Parameter, paramValue buildv1alpha1.ParamValue) error { +func HandleTaskRunParam(taskRun *pipelineapi.TaskRun, parameterDefinition *buildv1beta1.Parameter, paramValue buildv1beta1.ParamValue) error { taskRunParam := pipelineapi.Param{ Name: paramValue.Name, Value: pipelineapi.ParamValue{}, @@ -99,7 +99,7 @@ func HandleTaskRunParam(taskRun *pipelineapi.TaskRun, parameterDefinition *build switch parameterDefinition.Type { case "": // string is default fallthrough - case buildv1alpha1.ParameterTypeString: + case buildv1beta1.ParameterTypeString: taskRunParam.Value.Type = pipelineapi.ParamTypeString switch { @@ -145,7 +145,7 @@ func HandleTaskRunParam(taskRun *pipelineapi.TaskRun, parameterDefinition *build } - case buildv1alpha1.ParameterTypeArray: + case buildv1beta1.ParameterTypeArray: taskRunParam.Value.Type = pipelineapi.ParamTypeArray switch { diff --git a/pkg/reconciler/buildrun/resources/params_test.go b/pkg/reconciler/buildrun/resources/params_test.go index b42bc50606..3e95fb9d65 100644 --- a/pkg/reconciler/buildrun/resources/params_test.go +++ b/pkg/reconciler/buildrun/resources/params_test.go @@ -14,59 +14,59 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/utils/pointer" - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" ) var _ = Describe("Params overrides", func() { DescribeTable("original params can be overridden", - func(buildParams []buildv1alpha1.ParamValue, buildRunParams []buildv1alpha1.ParamValue, expected types.GomegaMatcher) { + func(buildParams []buildv1beta1.ParamValue, buildRunParams []buildv1beta1.ParamValue, expected types.GomegaMatcher) { Expect(OverrideParams(buildParams, buildRunParams)).To(expected) }, Entry("override a single parameter", - []buildv1alpha1.ParamValue{ - {Name: "a", SingleValue: &buildv1alpha1.SingleValue{ + []buildv1beta1.ParamValue{ + {Name: "a", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("2"), }}, - }, []buildv1alpha1.ParamValue{ - {Name: "a", SingleValue: &buildv1alpha1.SingleValue{ + }, []buildv1beta1.ParamValue{ + {Name: "a", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("3"), }}, - }, ContainElements([]buildv1alpha1.ParamValue{ - {Name: "a", SingleValue: &buildv1alpha1.SingleValue{ + }, ContainElements([]buildv1beta1.ParamValue{ + {Name: "a", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("3"), }}, })), Entry("override two parameters", - []buildv1alpha1.ParamValue{ - {Name: "a", SingleValue: &buildv1alpha1.SingleValue{ + []buildv1beta1.ParamValue{ + {Name: "a", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("2"), }}, - {Name: "b", SingleValue: &buildv1alpha1.SingleValue{ - SecretValue: &buildv1alpha1.ObjectKeyRef{ + {Name: "b", SingleValue: &buildv1beta1.SingleValue{ + SecretValue: &buildv1beta1.ObjectKeyRef{ Name: "a-secret", Key: "a-key", }, }}, - }, []buildv1alpha1.ParamValue{ - {Name: "a", SingleValue: &buildv1alpha1.SingleValue{ + }, []buildv1beta1.ParamValue{ + {Name: "a", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("3"), }}, - {Name: "b", SingleValue: &buildv1alpha1.SingleValue{ - ConfigMapValue: &buildv1alpha1.ObjectKeyRef{ + {Name: "b", SingleValue: &buildv1beta1.SingleValue{ + ConfigMapValue: &buildv1beta1.ObjectKeyRef{ Name: "a-config-map", Key: "a-cm-key", }, }}, - }, ContainElements([]buildv1alpha1.ParamValue{ - {Name: "a", SingleValue: &buildv1alpha1.SingleValue{ + }, ContainElements([]buildv1beta1.ParamValue{ + {Name: "a", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("3"), }}, - {Name: "b", SingleValue: &buildv1alpha1.SingleValue{ - ConfigMapValue: &buildv1alpha1.ObjectKeyRef{ + {Name: "b", SingleValue: &buildv1beta1.SingleValue{ + ConfigMapValue: &buildv1beta1.ObjectKeyRef{ Name: "a-config-map", Key: "a-cm-key", }, @@ -74,116 +74,116 @@ var _ = Describe("Params overrides", func() { })), Entry("override multiple parameters", - []buildv1alpha1.ParamValue{ - {Name: "a", SingleValue: &buildv1alpha1.SingleValue{ + []buildv1beta1.ParamValue{ + {Name: "a", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("2"), }}, - {Name: "b", SingleValue: &buildv1alpha1.SingleValue{ + {Name: "b", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("2"), }}, - {Name: "c", SingleValue: &buildv1alpha1.SingleValue{ + {Name: "c", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("2"), }}, - }, []buildv1alpha1.ParamValue{ - {Name: "a", SingleValue: &buildv1alpha1.SingleValue{ + }, []buildv1beta1.ParamValue{ + {Name: "a", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("6"), }}, - {Name: "c", SingleValue: &buildv1alpha1.SingleValue{ + {Name: "c", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("6"), }}, - }, ContainElements([]buildv1alpha1.ParamValue{ - {Name: "a", SingleValue: &buildv1alpha1.SingleValue{ + }, ContainElements([]buildv1beta1.ParamValue{ + {Name: "a", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("6"), }}, - {Name: "b", SingleValue: &buildv1alpha1.SingleValue{ + {Name: "b", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("2"), }}, - {Name: "c", SingleValue: &buildv1alpha1.SingleValue{ + {Name: "c", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("6"), }}, })), Entry("dont override when second list is empty", - []buildv1alpha1.ParamValue{ - {Name: "t", SingleValue: &buildv1alpha1.SingleValue{ + []buildv1beta1.ParamValue{ + {Name: "t", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("2"), }}, - {Name: "z", SingleValue: &buildv1alpha1.SingleValue{ + {Name: "z", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("2"), }}, - {Name: "g", SingleValue: &buildv1alpha1.SingleValue{ + {Name: "g", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("2"), }}, }, - []buildv1alpha1.ParamValue{ + []buildv1beta1.ParamValue{ // no overrides }, - ContainElements([]buildv1alpha1.ParamValue{ - {Name: "t", SingleValue: &buildv1alpha1.SingleValue{ + ContainElements([]buildv1beta1.ParamValue{ + {Name: "t", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("2"), }}, - {Name: "z", SingleValue: &buildv1alpha1.SingleValue{ + {Name: "z", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("2"), }}, - {Name: "g", SingleValue: &buildv1alpha1.SingleValue{ + {Name: "g", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("2"), }}, })), Entry("override when first list is empty but not the second list", - []buildv1alpha1.ParamValue{ + []buildv1beta1.ParamValue{ // no original values - }, []buildv1alpha1.ParamValue{ - {Name: "a", SingleValue: &buildv1alpha1.SingleValue{ + }, []buildv1beta1.ParamValue{ + {Name: "a", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("6"), }}, - {Name: "c", SingleValue: &buildv1alpha1.SingleValue{ + {Name: "c", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("6"), }}, - }, ContainElements([]buildv1alpha1.ParamValue{ - {Name: "a", SingleValue: &buildv1alpha1.SingleValue{ + }, ContainElements([]buildv1beta1.ParamValue{ + {Name: "a", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("6"), }}, - {Name: "c", SingleValue: &buildv1alpha1.SingleValue{ + {Name: "c", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("6"), }}, })), Entry("override multiple parameters if the match and add them if not present in first list", - []buildv1alpha1.ParamValue{ - {Name: "a", SingleValue: &buildv1alpha1.SingleValue{ + []buildv1beta1.ParamValue{ + {Name: "a", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("2"), }}, - }, []buildv1alpha1.ParamValue{ - {Name: "a", SingleValue: &buildv1alpha1.SingleValue{ + }, []buildv1beta1.ParamValue{ + {Name: "a", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("22"), }}, - {Name: "b", SingleValue: &buildv1alpha1.SingleValue{ + {Name: "b", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("20"), }}, - {Name: "c", SingleValue: &buildv1alpha1.SingleValue{ + {Name: "c", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("10"), }}, - {Name: "d", SingleValue: &buildv1alpha1.SingleValue{ + {Name: "d", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("8"), }}, - {Name: "e", SingleValue: &buildv1alpha1.SingleValue{ + {Name: "e", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("4"), }}, - }, ContainElements([]buildv1alpha1.ParamValue{ - {Name: "a", SingleValue: &buildv1alpha1.SingleValue{ + }, ContainElements([]buildv1beta1.ParamValue{ + {Name: "a", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("22"), }}, - {Name: "b", SingleValue: &buildv1alpha1.SingleValue{ + {Name: "b", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("20"), }}, - {Name: "c", SingleValue: &buildv1alpha1.SingleValue{ + {Name: "c", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("10"), }}, - {Name: "d", SingleValue: &buildv1alpha1.SingleValue{ + {Name: "d", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("8"), }}, - {Name: "e", SingleValue: &buildv1alpha1.SingleValue{ + {Name: "e", SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("4"), }}, })), @@ -211,7 +211,7 @@ var _ = Describe("FindParameterByName", func() { Context("For a list of three parameters", func() { - parameters := []buildv1alpha1.Parameter{{ + parameters := []buildv1beta1.Parameter{{ Name: "some-parameter", Type: "string", }, { @@ -229,7 +229,7 @@ var _ = Describe("FindParameterByName", func() { It("returns the correct parameter with a matching name", func() { parameter := FindParameterByName(parameters, "another-parameter") Expect(parameter).ToNot(BeNil()) - Expect(parameter).To(BeEquivalentTo(&buildv1alpha1.Parameter{ + Expect(parameter).To(BeEquivalentTo(&buildv1beta1.Parameter{ Name: "another-parameter", Type: "array", })) @@ -241,19 +241,19 @@ var _ = Describe("FindParamValueByName", func() { Context("For a list of three parameter values", func() { - paramValues := []buildv1alpha1.ParamValue{{ + paramValues := []buildv1beta1.ParamValue{{ Name: "some-parameter", - SingleValue: &buildv1alpha1.SingleValue{ + SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("some-value"), }, }, { Name: "another-parameter", - Values: []buildv1alpha1.SingleValue{ + Values: []buildv1beta1.SingleValue{ { Value: pointer.String("item"), }, { - ConfigMapValue: &buildv1alpha1.ObjectKeyRef{ + ConfigMapValue: &buildv1beta1.ObjectKeyRef{ Name: "a-configmap", Key: "a-key", }, @@ -261,7 +261,7 @@ var _ = Describe("FindParamValueByName", func() { }, }, { Name: "last-parameter", - SingleValue: &buildv1alpha1.SingleValue{ + SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("last-value"), }, }} @@ -273,14 +273,14 @@ var _ = Describe("FindParamValueByName", func() { It("returns the correct parameter with a matching name", func() { parameter := FindParamValueByName(paramValues, "another-parameter") Expect(parameter).ToNot(BeNil()) - Expect(parameter).To(BeEquivalentTo(&buildv1alpha1.ParamValue{ + Expect(parameter).To(BeEquivalentTo(&buildv1beta1.ParamValue{ Name: "another-parameter", - Values: []buildv1alpha1.SingleValue{ + Values: []buildv1beta1.SingleValue{ { Value: pointer.String("item"), }, { - ConfigMapValue: &buildv1alpha1.ObjectKeyRef{ + ConfigMapValue: &buildv1beta1.ObjectKeyRef{ Name: "a-configmap", Key: "a-key", }, @@ -374,15 +374,15 @@ var _ = Describe("HandleTaskRunParam", func() { Context("for a string parameter", func() { - parameterDefinition := &buildv1alpha1.Parameter{ + parameterDefinition := &buildv1beta1.Parameter{ Name: "string-parameter", - Type: buildv1alpha1.ParameterTypeString, + Type: buildv1beta1.ParameterTypeString, } It("adds a simple value", func() { - err := HandleTaskRunParam(taskRun, parameterDefinition, buildv1alpha1.ParamValue{ + err := HandleTaskRunParam(taskRun, parameterDefinition, buildv1beta1.ParamValue{ Name: "string-parameter", - SingleValue: &buildv1alpha1.SingleValue{ + SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("My value"), }, }) @@ -400,10 +400,10 @@ var _ = Describe("HandleTaskRunParam", func() { }) It("adds a configmap value without a format", func() { - err := HandleTaskRunParam(taskRun, parameterDefinition, buildv1alpha1.ParamValue{ + err := HandleTaskRunParam(taskRun, parameterDefinition, buildv1beta1.ParamValue{ Name: "string-parameter", - SingleValue: &buildv1alpha1.SingleValue{ - ConfigMapValue: &buildv1alpha1.ObjectKeyRef{ + SingleValue: &buildv1beta1.SingleValue{ + ConfigMapValue: &buildv1beta1.ObjectKeyRef{ Name: "config-map-name", Key: "my-key", }, @@ -443,10 +443,10 @@ var _ = Describe("HandleTaskRunParam", func() { }) It("adds a configmap value with a format", func() { - err := HandleTaskRunParam(taskRun, parameterDefinition, buildv1alpha1.ParamValue{ + err := HandleTaskRunParam(taskRun, parameterDefinition, buildv1beta1.ParamValue{ Name: "string-parameter", - SingleValue: &buildv1alpha1.SingleValue{ - ConfigMapValue: &buildv1alpha1.ObjectKeyRef{ + SingleValue: &buildv1beta1.SingleValue{ + ConfigMapValue: &buildv1beta1.ObjectKeyRef{ Name: "config-map-name", Key: "my-key", Format: pointer.String("The value from the config map is '${CONFIGMAP_VALUE}'."), @@ -487,10 +487,10 @@ var _ = Describe("HandleTaskRunParam", func() { }) It("adds a secret value without a format", func() { - err := HandleTaskRunParam(taskRun, parameterDefinition, buildv1alpha1.ParamValue{ + err := HandleTaskRunParam(taskRun, parameterDefinition, buildv1beta1.ParamValue{ Name: "string-parameter", - SingleValue: &buildv1alpha1.SingleValue{ - SecretValue: &buildv1alpha1.ObjectKeyRef{ + SingleValue: &buildv1beta1.SingleValue{ + SecretValue: &buildv1beta1.ObjectKeyRef{ Name: "secret-name", Key: "secret-key", }, @@ -530,10 +530,10 @@ var _ = Describe("HandleTaskRunParam", func() { }) It("adds a secret value with a format", func() { - err := HandleTaskRunParam(taskRun, parameterDefinition, buildv1alpha1.ParamValue{ + err := HandleTaskRunParam(taskRun, parameterDefinition, buildv1beta1.ParamValue{ Name: "string-parameter", - SingleValue: &buildv1alpha1.SingleValue{ - SecretValue: &buildv1alpha1.ObjectKeyRef{ + SingleValue: &buildv1beta1.SingleValue{ + SecretValue: &buildv1beta1.ObjectKeyRef{ Name: "secret-name", Key: "secret-key", Format: pointer.String("secret-value: ${SECRET_VALUE}"), @@ -576,15 +576,15 @@ var _ = Describe("HandleTaskRunParam", func() { Context("for an array parameter", func() { - parameterDefinition := &buildv1alpha1.Parameter{ + parameterDefinition := &buildv1beta1.Parameter{ Name: "array-parameter", - Type: buildv1alpha1.ParameterTypeArray, + Type: buildv1beta1.ParameterTypeArray, } It("adds simple values correctly", func() { - err := HandleTaskRunParam(taskRun, parameterDefinition, buildv1alpha1.ParamValue{ + err := HandleTaskRunParam(taskRun, parameterDefinition, buildv1beta1.ParamValue{ Name: "array-parameter", - Values: []buildv1alpha1.SingleValue{ + Values: []buildv1beta1.SingleValue{ { Value: pointer.String("first entry"), }, @@ -617,20 +617,20 @@ var _ = Describe("HandleTaskRunParam", func() { }) It("adds values from different sources correctly", func() { - err := HandleTaskRunParam(taskRun, parameterDefinition, buildv1alpha1.ParamValue{ + err := HandleTaskRunParam(taskRun, parameterDefinition, buildv1beta1.ParamValue{ Name: "array-parameter", - Values: []buildv1alpha1.SingleValue{ + Values: []buildv1beta1.SingleValue{ { Value: pointer.String("first entry"), }, { - SecretValue: &buildv1alpha1.ObjectKeyRef{ + SecretValue: &buildv1beta1.ObjectKeyRef{ Name: "secret-name", Key: "secret-key", }, }, { - SecretValue: &buildv1alpha1.ObjectKeyRef{ + SecretValue: &buildv1beta1.ObjectKeyRef{ Name: "secret-name", Key: "secret-key", Format: pointer.String("The secret value is ${SECRET_VALUE}"), diff --git a/pkg/reconciler/buildrun/resources/results.go b/pkg/reconciler/buildrun/resources/results.go index 61b31a9d3c..d6d60dae91 100644 --- a/pkg/reconciler/buildrun/resources/results.go +++ b/pkg/reconciler/buildrun/resources/results.go @@ -9,7 +9,7 @@ import ( "fmt" "strconv" - build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/ctxlog" pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" @@ -32,14 +32,15 @@ func UpdateBuildRunUsingTaskResults( // Set source results updateBuildRunStatusWithSourceResult(buildRun, taskRunResult) - // Initializing output result - buildRun.Status.Output = &build.Output{} - // Set output results updateBuildRunStatusWithOutputResult(ctx, buildRun, taskRunResult, request) } func updateBuildRunStatusWithOutputResult(ctx context.Context, buildRun *build.BuildRun, taskRunResult []pipelineapi.TaskRunResult, request reconcile.Request) { + if buildRun.Status.Output == nil { + buildRun.Status.Output = &build.Output{} + } + for _, result := range taskRunResult { switch result.Name { case generateOutputResultName(imageDigestResult): diff --git a/pkg/reconciler/buildrun/resources/results_test.go b/pkg/reconciler/buildrun/resources/results_test.go index 5196d8da4b..26bebae104 100644 --- a/pkg/reconciler/buildrun/resources/results_test.go +++ b/pkg/reconciler/buildrun/resources/results_test.go @@ -10,13 +10,12 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/reconciler/buildrun/resources" - test "github.com/shipwright-io/build/test/v1alpha1_samples" + test "github.com/shipwright-io/build/test/v1beta1_samples" pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" "k8s.io/apimachinery/pkg/types" - "k8s.io/utils/pointer" "sigs.k8s.io/controller-runtime/pkg/reconcile" ) @@ -50,8 +49,14 @@ var _ = Describe("TaskRun results to BuildRun", func() { It("should surface the TaskRun results emitting from default(git) source step", func() { commitSha := "0e0583421a5e4bf562ffe33f3651e16ba0c78591" - br.Status.BuildSpec.Source.URL = pointer.String("https://github.com/shipwright-io/sample-go") - + br.Status.BuildSpec = &build.BuildSpec{ + Source: build.Source{ + Type: build.GitType, + GitSource: &build.Git{ + URL: "https://github.com/shipwright-io/sample-go", + }, + }, + } tr.Status.Results = append(tr.Status.Results, pipelineapi.TaskRunResult{ Name: "shp-source-default-commit-sha", @@ -70,15 +75,20 @@ var _ = Describe("TaskRun results to BuildRun", func() { resources.UpdateBuildRunUsingTaskResults(ctx, br, tr.Status.Results, taskRunRequest) - Expect(len(br.Status.Sources)).To(Equal(1)) - Expect(br.Status.Sources[0].Git.CommitSha).To(Equal(commitSha)) - Expect(br.Status.Sources[0].Git.CommitAuthor).To(Equal("foo bar")) + Expect(br.Status.Source).ToNot(BeNil()) + Expect(br.Status.Source.Git.CommitSha).To(Equal(commitSha)) + Expect(br.Status.Source.Git.CommitAuthor).To(Equal("foo bar")) }) It("should surface the TaskRun results emitting from default(bundle) source step", func() { bundleImageDigest := "sha256:fe1b73cd25ac3f11dec752755e2" - br.Status.BuildSpec.Source.BundleContainer = &build.BundleContainer{ - Image: "ghcr.io/shipwright-io/sample-go/source-bundle:latest", + br.Status.BuildSpec = &build.BuildSpec{ + Source: build.Source{ + Type: build.OCIArtifactType, + OCIArtifact: &build.OCIArtifact{ + Image: "ghcr.io/shipwright-io/sample-go/source-bundle:latest", + }, + }, } tr.Status.Results = append(tr.Status.Results, @@ -92,8 +102,8 @@ var _ = Describe("TaskRun results to BuildRun", func() { resources.UpdateBuildRunUsingTaskResults(ctx, br, tr.Status.Results, taskRunRequest) - Expect(len(br.Status.Sources)).To(Equal(1)) - Expect(br.Status.Sources[0].Bundle.Digest).To(Equal(bundleImageDigest)) + Expect(br.Status.Source).ToNot(BeNil()) + Expect(br.Status.Source.OciArtifact.Digest).To(Equal(bundleImageDigest)) }) It("should surface the TaskRun results emitting from output step", func() { @@ -124,7 +134,14 @@ var _ = Describe("TaskRun results to BuildRun", func() { It("should surface the TaskRun results emitting from source and output step", func() { commitSha := "0e0583421a5e4bf562ffe33f3651e16ba0c78591" imageDigest := "sha256:fe1b73cd25ac3f11dec752755e2" - br.Status.BuildSpec.Source.URL = pointer.String("https://github.com/shipwright-io/sample-go") + br.Status.BuildSpec = &build.BuildSpec{ + Source: build.Source{ + Type: build.GitType, + GitSource: &build.Git{ + URL: "https://github.com/shipwright-io/sample-go", + }, + }, + } tr.Status.Results = append(tr.Status.Results, pipelineapi.TaskRunResult{ @@ -158,9 +175,10 @@ var _ = Describe("TaskRun results to BuildRun", func() { resources.UpdateBuildRunUsingTaskResults(ctx, br, tr.Status.Results, taskRunRequest) - Expect(len(br.Status.Sources)).To(Equal(1)) - Expect(br.Status.Sources[0].Git.CommitSha).To(Equal(commitSha)) - Expect(br.Status.Sources[0].Git.CommitAuthor).To(Equal("foo bar")) + Expect(br.Status.Source).ToNot(BeNil()) + Expect(br.Status.Source.Git).ToNot(BeNil()) + Expect(br.Status.Source.Git.CommitSha).To(Equal(commitSha)) + Expect(br.Status.Source.Git.CommitAuthor).To(Equal("foo bar")) Expect(br.Status.Output.Digest).To(Equal(imageDigest)) Expect(br.Status.Output.Size).To(Equal(int64(230))) }) diff --git a/pkg/reconciler/buildrun/resources/service_accounts.go b/pkg/reconciler/buildrun/resources/service_accounts.go index 38cd815f3d..d49f308258 100644 --- a/pkg/reconciler/buildrun/resources/service_accounts.go +++ b/pkg/reconciler/buildrun/resources/service_accounts.go @@ -8,7 +8,7 @@ import ( "context" "fmt" - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/ctxlog" corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" @@ -30,17 +30,17 @@ const ( ) // GetGeneratedServiceAccountName returns the name of the generated service account for a build run -func GetGeneratedServiceAccountName(buildRun *buildv1alpha1.BuildRun) string { +func GetGeneratedServiceAccountName(buildRun *buildv1beta1.BuildRun) string { return buildRun.Name } // IsGeneratedServiceAccountUsed checks if a build run uses a generated service account -func IsGeneratedServiceAccountUsed(buildRun *buildv1alpha1.BuildRun) bool { - return buildRun.Spec.ServiceAccount != nil && buildRun.Spec.ServiceAccount.Generate != nil && *buildRun.Spec.ServiceAccount.Generate +func IsGeneratedServiceAccountUsed(buildRun *buildv1beta1.BuildRun) bool { + return buildRun.Spec.ServiceAccount != nil && *buildRun.Spec.ServiceAccount == ".generate" } // GenerateSA generates a new service account on the fly -func GenerateSA(ctx context.Context, client client.Client, build *buildv1alpha1.Build, buildRun *buildv1alpha1.BuildRun) (serviceAccount *corev1.ServiceAccount, err error) { +func GenerateSA(ctx context.Context, client client.Client, build *buildv1beta1.Build, buildRun *buildv1beta1.BuildRun) (serviceAccount *corev1.ServiceAccount, err error) { serviceAccount = &corev1.ServiceAccount{} err = client.Get( ctx, @@ -60,9 +60,9 @@ func GenerateSA(ctx context.Context, client client.Client, build *buildv1alpha1. ObjectMeta: metav1.ObjectMeta{ Name: GetGeneratedServiceAccountName(buildRun), Namespace: buildRun.Namespace, - Labels: map[string]string{buildv1alpha1.LabelBuildRun: buildRun.Name}, + Labels: map[string]string{buildv1beta1.LabelBuildRun: buildRun.Name}, OwnerReferences: []metav1.OwnerReference{ - *metav1.NewControllerRef(buildRun, buildv1alpha1.SchemeGroupVersion.WithKind("BuildRun")), + *metav1.NewControllerRef(buildRun, buildv1beta1.SchemeGroupVersion.WithKind("BuildRun")), }, }, AutomountServiceAccountToken: pointer.Bool(false), @@ -87,11 +87,10 @@ func GenerateSA(ctx context.Context, client client.Client, build *buildv1alpha1. // DeleteServiceAccount deletes the service account of a completed BuildRun if the service account // was generated -func DeleteServiceAccount(ctx context.Context, client client.Client, completedBuildRun *buildv1alpha1.BuildRun) error { +func DeleteServiceAccount(ctx context.Context, client client.Client, completedBuildRun *buildv1beta1.BuildRun) error { if !IsGeneratedServiceAccountUsed(completedBuildRun) { return nil } - serviceAccount := &corev1.ServiceAccount{} serviceAccount.Name = GetGeneratedServiceAccountName(completedBuildRun) serviceAccount.Namespace = completedBuildRun.Namespace @@ -106,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 *buildv1alpha1.BuildRun) (*corev1.ServiceAccount, error) { +func getDefaultNamespaceSA(ctx context.Context, client client.Client, buildRun *buildv1beta1.BuildRun) (*corev1.ServiceAccount, error) { // Note: If the default SA is not in the namespace, the controller will be always reconciling until if finds it or until the // BuildRun gets deleted serviceAccount := &corev1.ServiceAccount{} @@ -127,14 +126,13 @@ func getDefaultNamespaceSA(ctx context.Context, client client.Client, buildRun * // RetrieveServiceAccount provides either a default sa with a referenced secret or it will generate a new sa on the fly. // When not using the generate feature, it will modify and return the default sa from a k8s namespace, which is "default" // or the default sa inside an openshift namespace, which is "pipeline". -func RetrieveServiceAccount(ctx context.Context, client client.Client, build *buildv1alpha1.Build, buildRun *buildv1alpha1.BuildRun) (serviceAccount *corev1.ServiceAccount, err error) { +func RetrieveServiceAccount(ctx context.Context, client client.Client, build *buildv1beta1.Build, buildRun *buildv1beta1.BuildRun) (serviceAccount *corev1.ServiceAccount, err error) { // generate or retrieve an existing autogenerated sa if IsGeneratedServiceAccountUsed(buildRun) { return GenerateSA(ctx, client, build, buildRun) } - - if buildRun.Spec.ServiceAccount != nil && buildRun.Spec.ServiceAccount.Name != nil { - serviceAccountName := *buildRun.Spec.ServiceAccount.Name + if buildRun.Spec.ServiceAccount != nil { + serviceAccountName := *buildRun.Spec.ServiceAccount // here we might need to update Status Conditions and Fail the BR serviceAccount = &corev1.ServiceAccount{} @@ -144,7 +142,6 @@ func RetrieveServiceAccount(ctx context.Context, client client.Client, build *bu return nil, HandleError("failed to retrieve service account", err, updateErr) } } - return nil, err } diff --git a/pkg/reconciler/buildrun/resources/service_accounts_test.go b/pkg/reconciler/buildrun/resources/service_accounts_test.go index 2e36bdfefb..eb271f9e3c 100644 --- a/pkg/reconciler/buildrun/resources/service_accounts_test.go +++ b/pkg/reconciler/buildrun/resources/service_accounts_test.go @@ -10,10 +10,10 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/controller/fakes" "github.com/shipwright-io/build/pkg/reconciler/buildrun/resources" - test "github.com/shipwright-io/build/test/v1alpha1_samples" + test "github.com/shipwright-io/build/test/v1beta1_samples" corev1 "k8s.io/api/core/v1" k8serrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime/schema" @@ -26,7 +26,7 @@ var _ = Describe("Operating service accounts", func() { client *fakes.FakeClient ctl test.Catalog buildName, buildRunName string - buildRunSample *buildv1alpha1.BuildRun + buildRunSample *buildv1beta1.BuildRun ) BeforeEach(func() { @@ -113,7 +113,7 @@ var _ = Describe("Operating service accounts", func() { statusWriter := &fakes.FakeStatusWriter{} statusWriter.UpdateCalls(func(_ context.Context, object crc.Object, _ ...crc.SubResourceUpdateOption) error { switch object.(type) { - case *buildv1alpha1.BuildRun: + case *buildv1beta1.BuildRun: return fmt.Errorf("failed") } return nil @@ -128,7 +128,7 @@ var _ = Describe("Operating service accounts", func() { }) }) - Context("Retrieving autogenerated service accounts when the spec.serviceAccount.generate key is used", func() { + Context("Retrieving autogenerated service accounts when the spec.serviceAccount .generate value is used", func() { It("should provide a generated sa name", func() { Expect(resources.GetGeneratedServiceAccountName(buildRunSample)).To(Equal(buildRunSample.Name)) @@ -147,7 +147,7 @@ var _ = Describe("Operating service accounts", func() { case *corev1.ServiceAccount: Expect(len(object.Secrets)).To(Equal(1)) Expect(len(object.OwnerReferences)).To(Equal(1)) - Expect(object.Labels[buildv1alpha1.LabelBuildRun]).To(Equal(buildRunName)) + Expect(object.Labels[buildv1beta1.LabelBuildRun]).To(Equal(buildRunName)) Expect(object.Secrets[0].Name).To(Equal("foosecret")) Expect(object.AutomountServiceAccountToken).To(Equal(&mountTokenVal)) } diff --git a/pkg/reconciler/buildrun/resources/sources.go b/pkg/reconciler/buildrun/resources/sources.go index 5e7b8b7fee..415cbb593e 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" - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/config" "github.com/shipwright-io/build/pkg/reconciler/buildrun/resources/sources" @@ -25,19 +25,20 @@ 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 *buildv1alpha1.Build, - buildRun *buildv1alpha1.BuildRun, -) *buildv1alpha1.BuildSource { - sources := []buildv1alpha1.BuildSource{} - - sources = append(sources, build.Spec.Sources...) - sources = append(sources, buildRun.Spec.Sources...) + build *buildv1beta1.Build, + buildRun *buildv1beta1.BuildRun, +) *buildv1beta1.Local { + + // Note: In v1alpha1 we will append all sources across builds and buildruns, and then return + // the first source of type Local. + if build.Spec.Source.Type == buildv1beta1.LocalType { + return build.Spec.Source.LocalSource + } - for _, source := range sources { - if source.Type == buildv1alpha1.LocalCopy { - return &source - } + if buildRun.Spec.Source != nil && buildRun.Spec.Source.Type == buildv1beta1.LocalType { + return buildRun.Spec.Source.LocalSource } + return nil } @@ -55,50 +56,45 @@ func appendSourceTimestampResult(taskSpec *pipelineapi.TaskSpec) { func AmendTaskSpecWithSources( cfg *config.Config, taskSpec *pipelineapi.TaskSpec, - build *buildv1alpha1.Build, - buildRun *buildv1alpha1.BuildRun, + build *buildv1beta1.Build, + buildRun *buildv1beta1.BuildRun, ) { if localCopy := isLocalCopyBuildSource(build, buildRun); localCopy != nil { sources.AppendLocalCopyStep(cfg, taskSpec, localCopy.Timeout) } else { - // create the step for spec.source, either Git or Bundle - switch { - case build.Spec.Source.BundleContainer != nil: - appendSourceTimestampResult(taskSpec) - sources.AppendBundleStep(cfg, taskSpec, build.Spec.Source, defaultSourceName) - case build.Spec.Source.URL != nil: - appendSourceTimestampResult(taskSpec) - sources.AppendGitStep(cfg, taskSpec, build.Spec.Source, defaultSourceName) - } - } - // inspecting .spec.sources looking for "http" typed sources to generate the TaskSpec items - // in order to handle remote artifacts - for _, source := range build.Spec.Sources { - if source.Type == buildv1alpha1.HTTP { - sources.AppendHTTPStep(cfg, taskSpec, source) + // create the step for spec.source, either Git or Bundle + switch build.Spec.Source.Type { + case buildv1beta1.OCIArtifactType: + if build.Spec.Source.OCIArtifact != nil { + appendSourceTimestampResult(taskSpec) + sources.AppendBundleStep(cfg, taskSpec, build.Spec.Source.OCIArtifact, defaultSourceName) + } + case buildv1beta1.GitType: + if build.Spec.Source.GitSource != nil { + appendSourceTimestampResult(taskSpec) + sources.AppendGitStep(cfg, taskSpec, *build.Spec.Source.GitSource, defaultSourceName) + } } } } -func updateBuildRunStatusWithSourceResult(buildrun *buildv1alpha1.BuildRun, results []pipelineapi.TaskRunResult) { +func updateBuildRunStatusWithSourceResult(buildrun *buildv1beta1.BuildRun, results []pipelineapi.TaskRunResult) { buildSpec := buildrun.Status.BuildSpec // no results for HTTP sources yet switch { - case buildSpec.Source.BundleContainer != nil: + case buildSpec.Source.Type == buildv1beta1.OCIArtifactType && buildSpec.Source.OCIArtifact != nil: sources.AppendBundleResult(buildrun, defaultSourceName, results) - case buildSpec.Source.URL != nil: + case buildSpec.Source.Type == buildv1beta1.GitType && buildSpec.Source.GitSource != nil: sources.AppendGitResult(buildrun, defaultSourceName, results) } if sourceTimestamp := sources.FindResultValue(results, defaultSourceName, sourceTimestampName); strings.TrimSpace(sourceTimestamp) != "" { if sec, err := strconv.ParseInt(sourceTimestamp, 10, 64); err == nil { - for i := range buildrun.Status.Sources { - if buildrun.Status.Sources[i].Name == defaultSourceName { - buildrun.Status.Sources[i].Timestamp = &metav1.Time{Time: time.Unix(sec, 0)} - } + if buildrun.Status.Source != nil { + buildrun.Status.Source.Timestamp = &metav1.Time{Time: time.Unix(sec, 0)} } } } diff --git a/pkg/reconciler/buildrun/resources/sources/bundle.go b/pkg/reconciler/buildrun/resources/sources/bundle.go index 1d4d52a9bd..ec39f1ab69 100644 --- a/pkg/reconciler/buildrun/resources/sources/bundle.go +++ b/pkg/reconciler/buildrun/resources/sources/bundle.go @@ -8,21 +8,15 @@ import ( "fmt" "strings" - corev1 "k8s.io/api/core/v1" - - build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/config" + corev1 "k8s.io/api/core/v1" pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" ) // AppendBundleStep appends the bundle step to the TaskSpec -func AppendBundleStep( - cfg *config.Config, - taskSpec *pipelineapi.TaskSpec, - source build.Source, - name string, -) { +func AppendBundleStep(cfg *config.Config, taskSpec *pipelineapi.TaskSpec, oci *build.OCIArtifact, name string) { // append the result taskSpec.Results = append(taskSpec.Results, pipelineapi.TaskResult{ @@ -38,7 +32,7 @@ func AppendBundleStep( ImagePullPolicy: cfg.BundleContainerTemplate.ImagePullPolicy, Command: cfg.BundleContainerTemplate.Command, Args: []string{ - "--image", source.BundleContainer.Image, + "--image", oci.Image, "--target", fmt.Sprintf("$(params.%s-%s)", PrefixParamsResultsVolumes, paramSourceRoot), "--result-file-image-digest", fmt.Sprintf("$(results.%s-source-%s-image-digest.path)", PrefixParamsResultsVolumes, name), "--result-file-source-timestamp", fmt.Sprintf("$(results.%s-source-%s-source-timestamp.path)", PrefixParamsResultsVolumes, name), @@ -50,14 +44,14 @@ func AppendBundleStep( } // add credentials mount, if provided - if source.Credentials != nil { - AppendSecretVolume(taskSpec, source.Credentials.Name) + if oci.PullSecret != nil { + AppendSecretVolume(taskSpec, *oci.PullSecret) secretMountPath := fmt.Sprintf("/workspace/%s-pull-secret", PrefixParamsResultsVolumes) // define the volume mount on the container bundleStep.VolumeMounts = append(bundleStep.VolumeMounts, corev1.VolumeMount{ - Name: SanitizeVolumeNameForSecretName(source.Credentials.Name), + Name: SanitizeVolumeNameForSecretName(*oci.PullSecret), MountPath: secretMountPath, ReadOnly: true, }) @@ -69,7 +63,7 @@ func AppendBundleStep( } // add prune flag in when prune after pull is configured - if source.BundleContainer.Prune != nil && *source.BundleContainer.Prune == build.PruneAfterPull { + if oci.Prune != nil && *oci.Prune == build.PruneAfterPull { bundleStep.Args = append(bundleStep.Args, "--prune") } @@ -81,11 +75,11 @@ func AppendBundleResult(buildRun *build.BuildRun, name string, results []pipelin imageDigest := FindResultValue(results, name, "image-digest") if strings.TrimSpace(imageDigest) != "" { - buildRun.Status.Sources = append(buildRun.Status.Sources, build.SourceResult{ - Name: name, - Bundle: &build.BundleSourceResult{ - Digest: imageDigest, - }, - }) + if buildRun.Status.Source == nil { + buildRun.Status.Source = &build.SourceResult{} + } + buildRun.Status.Source.OciArtifact = &build.OciArtifactSourceResult{ + Digest: imageDigest, + } } } diff --git a/pkg/reconciler/buildrun/resources/sources/git.go b/pkg/reconciler/buildrun/resources/sources/git.go index 8f310f258f..67c91b7ccc 100644 --- a/pkg/reconciler/buildrun/resources/sources/git.go +++ b/pkg/reconciler/buildrun/resources/sources/git.go @@ -10,7 +10,9 @@ import ( corev1 "k8s.io/api/core/v1" - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + "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" "github.com/shipwright-io/build/pkg/config" pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" @@ -26,7 +28,7 @@ const ( func AppendGitStep( cfg *config.Config, taskSpec *pipelineapi.TaskSpec, - source buildv1alpha1.Source, + source buildv1beta1.Git, name string, ) { // append the result @@ -52,7 +54,7 @@ func AppendGitStep( ImagePullPolicy: cfg.GitContainerTemplate.ImagePullPolicy, Command: cfg.GitContainerTemplate.Command, Args: []string{ - "--url", *source.URL, + "--url", source.URL, "--target", fmt.Sprintf("$(params.%s-%s)", PrefixParamsResultsVolumes, paramSourceRoot), "--result-file-commit-sha", fmt.Sprintf("$(results.%s-source-%s-%s.path)", PrefixParamsResultsVolumes, name, commitSHAResult), "--result-file-commit-author", fmt.Sprintf("$(results.%s-source-%s-%s.path)", PrefixParamsResultsVolumes, name, commitAuthorResult), @@ -82,15 +84,15 @@ func AppendGitStep( gitStep.Args = append(gitStep.Args, "--git-url-rewrite") } - if source.Credentials != nil { + if source.CloneSecret != nil { // ensure the value is there - AppendSecretVolume(taskSpec, source.Credentials.Name) + AppendSecretVolume(taskSpec, *source.CloneSecret) secretMountPath := fmt.Sprintf("/workspace/%s-source-secret", PrefixParamsResultsVolumes) // define the volume mount on the container gitStep.VolumeMounts = append(gitStep.VolumeMounts, corev1.VolumeMount{ - Name: SanitizeVolumeNameForSecretName(source.Credentials.Name), + Name: SanitizeVolumeNameForSecretName(*source.CloneSecret), MountPath: secretMountPath, ReadOnly: true, }) @@ -108,19 +110,19 @@ func AppendGitStep( } // AppendGitResult append git source result to build run -func AppendGitResult(buildRun *buildv1alpha1.BuildRun, name string, results []pipelineapi.TaskRunResult) { +func AppendGitResult(buildRun *buildv1beta1.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) != "" { - buildRun.Status.Sources = append(buildRun.Status.Sources, buildv1alpha1.SourceResult{ - Name: name, - Git: &buildv1alpha1.GitSourceResult{ - CommitAuthor: commitAuthor, - CommitSha: commitSha, - BranchName: branchName, - }, - }) + if buildRun.Status.Source == nil { + buildRun.Status.Source = &build.SourceResult{} + } + buildRun.Status.Source.Git = &v1beta1.GitSourceResult{ + CommitAuthor: commitAuthor, + CommitSha: commitSha, + BranchName: branchName, + } } } diff --git a/pkg/reconciler/buildrun/resources/sources/git_test.go b/pkg/reconciler/buildrun/resources/sources/git_test.go index b3fa413578..361b01c3bb 100644 --- a/pkg/reconciler/buildrun/resources/sources/git_test.go +++ b/pkg/reconciler/buildrun/resources/sources/git_test.go @@ -8,12 +8,11 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/config" "github.com/shipwright-io/build/pkg/reconciler/buildrun/resources/sources" pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" - corev1 "k8s.io/api/core/v1" "k8s.io/utils/pointer" ) @@ -30,8 +29,8 @@ var _ = Describe("Git", func() { }) JustBeforeEach(func() { - sources.AppendGitStep(cfg, taskSpec, buildv1alpha1.Source{ - URL: pointer.String("https://github.com/shipwright-io/build"), + sources.AppendGitStep(cfg, taskSpec, buildv1beta1.Git{ + URL: "https://github.com/shipwright-io/build", }, "default") }) @@ -68,11 +67,9 @@ var _ = Describe("Git", func() { }) JustBeforeEach(func() { - sources.AppendGitStep(cfg, taskSpec, buildv1alpha1.Source{ - URL: pointer.String("git@github.com:shipwright-io/build.git"), - Credentials: &corev1.LocalObjectReference{ - Name: "a.secret", - }, + sources.AppendGitStep(cfg, taskSpec, buildv1beta1.Git{ + URL: "git@github.com:shipwright-io/build.git", + CloneSecret: pointer.String("a.secret"), }, "default") }) diff --git a/pkg/reconciler/buildrun/resources/sources/http.go b/pkg/reconciler/buildrun/resources/sources/http.go deleted file mode 100644 index fbc55f8d1f..0000000000 --- a/pkg/reconciler/buildrun/resources/sources/http.go +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright The Shipwright Contributors -// -// SPDX-License-Identifier: Apache-2.0 - -package sources - -import ( - "fmt" - - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" - "github.com/shipwright-io/build/pkg/config" - pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" -) - -// RemoteArtifactsContainerName name for the container dealing with remote artifacts download. -const RemoteArtifactsContainerName = "sources-http" - -// AppendHTTPStep appends the step for a HTTP source to the TaskSpec -func AppendHTTPStep( - cfg *config.Config, - taskSpec *pipelineapi.TaskSpec, - source buildv1alpha1.BuildSource, -) { - // HTTP is done currently all in a single step, see if there is already one - httpStep := findExistingHTTPSourcesStep(taskSpec) - if httpStep != nil { - httpStep.Args[3] = fmt.Sprintf("%s ; wget %q", httpStep.Args[3], source.URL) - } else { - httpStep := pipelineapi.Step{ - Name: RemoteArtifactsContainerName, - Image: cfg.RemoteArtifactsContainerImage, - WorkingDir: fmt.Sprintf("$(params.%s-%s)", PrefixParamsResultsVolumes, paramSourceRoot), - Command: []string{ - "/bin/sh", - }, - Args: []string{ - "-e", - "-x", - "-c", - fmt.Sprintf("wget %q", source.URL), - }, - } - - // append the git step - taskSpec.Steps = append(taskSpec.Steps, httpStep) - } -} - -func findExistingHTTPSourcesStep(taskSpec *pipelineapi.TaskSpec) *pipelineapi.Step { - for _, candidateStep := range taskSpec.Steps { - if candidateStep.Name == RemoteArtifactsContainerName { - return &candidateStep - } - } - return nil -} diff --git a/pkg/reconciler/buildrun/resources/sources/http_test.go b/pkg/reconciler/buildrun/resources/sources/http_test.go deleted file mode 100644 index b2f8083be9..0000000000 --- a/pkg/reconciler/buildrun/resources/sources/http_test.go +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright The Shipwright Contributors -// -// SPDX-License-Identifier: Apache-2.0 - -package sources_test - -import ( - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" - "github.com/shipwright-io/build/pkg/config" - "github.com/shipwright-io/build/pkg/reconciler/buildrun/resources/sources" - - pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" -) - -var _ = Describe("HTTP", func() { - - cfg := config.NewDefaultConfig() - - Context("when a TaskSpec does not contain an step", func() { - var taskSpec *pipelineapi.TaskSpec - - BeforeEach(func() { - taskSpec = &pipelineapi.TaskSpec{} - }) - - It("adds the first step", func() { - sources.AppendHTTPStep(cfg, taskSpec, buildv1alpha1.BuildSource{ - Name: "logo", - URL: "https://shipwright.io/icons/logo.svg", - }) - - Expect(len(taskSpec.Steps)).To(Equal(1)) - Expect(taskSpec.Steps[0].Name).To(Equal(sources.RemoteArtifactsContainerName)) - Expect(taskSpec.Steps[0].Image).To(Equal(cfg.RemoteArtifactsContainerImage)) - Expect(taskSpec.Steps[0].WorkingDir).To(Equal("$(params.shp-source-root)")) - Expect(taskSpec.Steps[0].Args[3]).To(Equal("wget \"https://shipwright.io/icons/logo.svg\"")) - }) - }) - - Context("when a TaskSpec already contains the http step", func() { - var taskSpec *pipelineapi.TaskSpec - - BeforeEach(func() { - taskSpec = &pipelineapi.TaskSpec{ - Steps: []pipelineapi.Step{ - { - Name: sources.RemoteArtifactsContainerName, - Image: cfg.RemoteArtifactsContainerImage, - WorkingDir: "$(params.shp-source-root)", - Command: []string{ - "/bin/sh", - }, - Args: []string{ - "-e", - "-x", - "-c", - "wget \"https://tekton.dev/images/tekton-horizontal-color.png\"", - }, - }, - }, - } - }) - - It("updates the existing step", func() { - sources.AppendHTTPStep(cfg, taskSpec, buildv1alpha1.BuildSource{ - Name: "logo", - URL: "https://shipwright.io/icons/logo.svg", - }) - - Expect(len(taskSpec.Steps)).To(Equal(1)) - Expect(taskSpec.Steps[0].Name).To(Equal(sources.RemoteArtifactsContainerName)) - Expect(taskSpec.Steps[0].Image).To(Equal(cfg.RemoteArtifactsContainerImage)) - Expect(taskSpec.Steps[0].WorkingDir).To(Equal("$(params.shp-source-root)")) - Expect(taskSpec.Steps[0].Args[3]).To(Equal("wget \"https://tekton.dev/images/tekton-horizontal-color.png\" ; wget \"https://shipwright.io/icons/logo.svg\"")) - }) - }) - - Context("when a TaskSpec already another source step step", func() { - var taskSpec *pipelineapi.TaskSpec - - BeforeEach(func() { - taskSpec = &pipelineapi.TaskSpec{ - Steps: []pipelineapi.Step{ - { - Name: "source-something", - }, - }, - } - }) - - It("appends the http step", func() { - sources.AppendHTTPStep(cfg, taskSpec, buildv1alpha1.BuildSource{ - Name: "logo", - URL: "https://shipwright.io/icons/logo.svg", - }) - - Expect(len(taskSpec.Steps)).To(Equal(2)) - Expect(taskSpec.Steps[1].Name).To(Equal(sources.RemoteArtifactsContainerName)) - Expect(taskSpec.Steps[1].Image).To(Equal(cfg.RemoteArtifactsContainerImage)) - Expect(taskSpec.Steps[1].WorkingDir).To(Equal("$(params.shp-source-root)")) - Expect(taskSpec.Steps[1].Args[3]).To(Equal("wget \"https://shipwright.io/icons/logo.svg\"")) - }) - }) -}) diff --git a/pkg/reconciler/buildrun/resources/steps/security_context.go b/pkg/reconciler/buildrun/resources/steps/security_context.go index 4cc0af4302..20b5eab3cb 100644 --- a/pkg/reconciler/buildrun/resources/steps/security_context.go +++ b/pkg/reconciler/buildrun/resources/steps/security_context.go @@ -7,7 +7,7 @@ package steps import ( "fmt" - buildapi "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1" pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" corev1 "k8s.io/api/core/v1" "k8s.io/utils/pointer" @@ -28,7 +28,7 @@ const ( // UpdateSecurityContext updates the security context of a step based on the build strategy steps. If all build strategy steps run as the same user and group, // then the step is configured to also run as this user and group. This ensures that the supporting steps run as the same user as the build strategy and file // permissions created by source steps match the user that runs the build strategy steps. -func UpdateSecurityContext(taskSpec *pipelineapi.TaskSpec, taskRunAnnotations map[string]string, buildStrategySteps []buildapi.BuildStep, buildStrategySecurityContext *buildapi.BuildStrategySecurityContext) { +func UpdateSecurityContext(taskSpec *pipelineapi.TaskSpec, taskRunAnnotations map[string]string, buildStrategySteps []buildapi.Step, buildStrategySecurityContext *buildapi.BuildStrategySecurityContext) { if buildStrategySecurityContext == nil { return } diff --git a/pkg/reconciler/buildrun/resources/steps/security_context_test.go b/pkg/reconciler/buildrun/resources/steps/security_context_test.go index a3de510633..e8a0f48ca9 100644 --- a/pkg/reconciler/buildrun/resources/steps/security_context_test.go +++ b/pkg/reconciler/buildrun/resources/steps/security_context_test.go @@ -9,7 +9,7 @@ import ( "github.com/shipwright-io/build/pkg/reconciler/buildrun/resources/steps" - buildapi "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + buildapi "github.com/shipwright-io/build/pkg/apis/build/v1beta1" pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" corev1 "k8s.io/api/core/v1" "k8s.io/utils/pointer" @@ -21,30 +21,24 @@ import ( var _ = Describe("UpdateSecurityContext", func() { var buildStrategySecurityContext *buildapi.BuildStrategySecurityContext - var buildStrategySteps []buildapi.BuildStep + var buildStrategySteps []buildapi.Step var taskRunSpec *pipelineapi.TaskSpec var taskRunAnnotations map[string]string BeforeEach(func() { - buildStrategySteps = []buildapi.BuildStep{{ - Container: corev1.Container{ - Name: "first-step", - SecurityContext: &corev1.SecurityContext{ - RunAsUser: pointer.Int64(891), - RunAsGroup: pointer.Int64(1210), - }, + buildStrategySteps = []buildapi.Step{{ + Name: "first-step", + SecurityContext: &corev1.SecurityContext{ + RunAsUser: pointer.Int64(891), + RunAsGroup: pointer.Int64(1210), }, }, { - Container: corev1.Container{ - Name: "second-step", - SecurityContext: &corev1.SecurityContext{ - RunAsUser: pointer.Int64(891), - }, + Name: "second-step", + SecurityContext: &corev1.SecurityContext{ + RunAsUser: pointer.Int64(891), }, }, { - Container: corev1.Container{ - Name: "third-step", - }, + Name: "third-step", }} taskRunSpec = &pipelineapi.TaskSpec{ diff --git a/pkg/reconciler/buildrun/resources/strategies.go b/pkg/reconciler/buildrun/resources/strategies.go index 536b031467..8d1ae1fbdc 100644 --- a/pkg/reconciler/buildrun/resources/strategies.go +++ b/pkg/reconciler/buildrun/resources/strategies.go @@ -7,7 +7,7 @@ package resources import ( "context" - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "sigs.k8s.io/controller-runtime/pkg/client" "github.com/shipwright-io/build/pkg/ctxlog" @@ -15,8 +15,8 @@ import ( ) // RetrieveBuildStrategy returns a namespace scoped strategy -func RetrieveBuildStrategy(ctx context.Context, client client.Client, build *buildv1alpha1.Build) (*buildv1alpha1.BuildStrategy, error) { - buildStrategyInstance := &buildv1alpha1.BuildStrategy{} +func RetrieveBuildStrategy(ctx context.Context, client client.Client, build *buildv1beta1.Build) (*buildv1beta1.BuildStrategy, error) { + buildStrategyInstance := &buildv1beta1.BuildStrategy{} ctxlog.Debug(ctx, "retrieving BuildStrategy", namespace, build.Namespace, name, build.Name) @@ -25,8 +25,8 @@ func RetrieveBuildStrategy(ctx context.Context, client client.Client, build *bui } // RetrieveClusterBuildStrategy returns a cluster scoped strategy -func RetrieveClusterBuildStrategy(ctx context.Context, client client.Client, build *buildv1alpha1.Build) (*buildv1alpha1.ClusterBuildStrategy, error) { - clusterBuildStrategyInstance := &buildv1alpha1.ClusterBuildStrategy{} +func RetrieveClusterBuildStrategy(ctx context.Context, client client.Client, build *buildv1beta1.Build) (*buildv1beta1.ClusterBuildStrategy, error) { + clusterBuildStrategyInstance := &buildv1beta1.ClusterBuildStrategy{} ctxlog.Debug(ctx, "retrieving ClusterBuildStrategy", namespace, build.Namespace, name, build.Name) diff --git a/pkg/reconciler/buildrun/resources/strategies_test.go b/pkg/reconciler/buildrun/resources/strategies_test.go index 8e6a5f5f25..14d64132bc 100644 --- a/pkg/reconciler/buildrun/resources/strategies_test.go +++ b/pkg/reconciler/buildrun/resources/strategies_test.go @@ -9,10 +9,10 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/controller/fakes" "github.com/shipwright-io/build/pkg/reconciler/buildrun/resources" - test "github.com/shipwright-io/build/test/v1alpha1_samples" + test "github.com/shipwright-io/build/test/v1beta1_samples" k8serrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/types" @@ -33,7 +33,7 @@ var _ = Describe("Operating Build strategies", func() { // stub a GET API call with a cluster strategy getClientStub := func(_ context.Context, nn types.NamespacedName, object crc.Object, _ ...crc.GetOption) error { switch object := object.(type) { - case *buildv1alpha1.ClusterBuildStrategy: + case *buildv1beta1.ClusterBuildStrategy: ctl.DefaultClusterBuildStrategy().DeepCopyInto(object) return nil } @@ -51,7 +51,7 @@ var _ = Describe("Operating Build strategies", func() { // stub a GET API call with a namespace strategy getClientStub := func(_ context.Context, nn types.NamespacedName, object crc.Object, _ ...crc.GetOption) error { switch object := object.(type) { - case *buildv1alpha1.BuildStrategy: + case *buildv1beta1.BuildStrategy: ctl.DefaultNamespacedBuildStrategy().DeepCopyInto(object) return nil } diff --git a/pkg/reconciler/buildrun/resources/taskrun.go b/pkg/reconciler/buildrun/resources/taskrun.go index cf91c0a606..0fd3d69a78 100644 --- a/pkg/reconciler/buildrun/resources/taskrun.go +++ b/pkg/reconciler/buildrun/resources/taskrun.go @@ -13,7 +13,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/config" "github.com/shipwright-io/build/pkg/env" "github.com/shipwright-io/build/pkg/reconciler/buildrun/resources/steps" @@ -31,8 +31,6 @@ const ( workspaceSource = "source" - inputParamBuilder = "BUILDER_IMAGE" - inputParamDockerfile = "DOCKERFILE" inputParamContextDir = "CONTEXT_DIR" ) @@ -44,9 +42,6 @@ func getStringTransformations(fullText string) string { // this will be removed, build strategy author should use $(params.shp-output-image) directly "$(build.output.image)": fmt.Sprintf("$(params.%s-%s)", prefixParamsResultsVolumes, paramOutputImage), - "$(build.builder.image)": fmt.Sprintf("$(inputs.params.%s)", inputParamBuilder), - "$(build.dockerfile)": fmt.Sprintf("$(inputs.params.%s)", inputParamDockerfile), - // this will be removed, build strategy author should use $(params.shp-source-context); it is still needed by the ko build // strategy that mis-uses this setting to store the path to the main package; requires strategy parameter support to get rid "$(build.source.contextDir)": fmt.Sprintf("$(inputs.params.%s)", inputParamContextDir), @@ -62,22 +57,14 @@ func getStringTransformations(fullText string) string { // GenerateTaskSpec creates Tekton TaskRun spec to be used for a build run func GenerateTaskSpec( cfg *config.Config, - build *buildv1alpha1.Build, - buildRun *buildv1alpha1.BuildRun, - buildSteps []buildv1alpha1.BuildStep, - parameterDefinitions []buildv1alpha1.Parameter, - buildStrategyVolumes []buildv1alpha1.BuildStrategyVolume, + build *buildv1beta1.Build, + buildRun *buildv1beta1.BuildRun, + buildSteps []buildv1beta1.Step, + parameterDefinitions []buildv1beta1.Parameter, + buildStrategyVolumes []buildv1beta1.BuildStrategyVolume, ) (*pipelineapi.TaskSpec, error) { generatedTaskSpec := pipelineapi.TaskSpec{ Params: []pipelineapi.ParamSpec{ - { - Description: "Path to the Dockerfile", - Name: inputParamDockerfile, - Default: &pipelineapi.ParamValue{ - Type: pipelineapi.ParamTypeString, - StringVal: "Dockerfile", - }, - }, { // CONTEXT_DIR comes from the git source specification // in the Build object @@ -119,18 +106,6 @@ func GenerateTaskSpec( generatedTaskSpec.Results = append(getTaskSpecResults(), getFailureDetailsTaskSpecResults()...) - if build.Spec.Builder != nil { - InputBuilder := pipelineapi.ParamSpec{ - Description: "Image containing the build tools/logic", - Name: inputParamBuilder, - Default: &pipelineapi.ParamValue{ - Type: pipelineapi.ParamTypeString, - StringVal: build.Spec.Builder.Image, - }, - } - generatedTaskSpec.Params = append(generatedTaskSpec.Params, InputBuilder) - } - // define the results, steps and volumes for sources, or alternatively, wait for user upload AmendTaskSpecWithSources(cfg, &generatedTaskSpec, build, buildRun) @@ -145,7 +120,7 @@ func GenerateTaskSpec( switch parameterDefinition.Type { case "": // string is default fallthrough - case buildv1alpha1.ParameterTypeString: + case buildv1beta1.ParameterTypeString: param.Type = pipelineapi.ParamTypeString if parameterDefinition.Default != nil { param.Default = &pipelineapi.ParamValue{ @@ -154,7 +129,7 @@ func GenerateTaskSpec( } } - case buildv1alpha1.ParameterTypeArray: + case buildv1beta1.ParameterTypeArray: param.Type = pipelineapi.ParamTypeArray if parameterDefinition.Defaults != nil { param.Default = &pipelineapi.ParamValue{ @@ -239,10 +214,10 @@ func GenerateTaskSpec( // GenerateTaskRun creates a Tekton TaskRun to be used for a build run func GenerateTaskRun( cfg *config.Config, - build *buildv1alpha1.Build, - buildRun *buildv1alpha1.BuildRun, + build *buildv1beta1.Build, + buildRun *buildv1beta1.BuildRun, serviceAccountName string, - strategy buildv1alpha1.BuilderStrategy, + strategy buildv1beta1.BuilderStrategy, ) (*pipelineapi.TaskRun, error) { // retrieve expected imageURL form build or buildRun @@ -274,14 +249,14 @@ func GenerateTaskRun( // Add BuildRun name reference to the TaskRun labels taskRunLabels := map[string]string{ - buildv1alpha1.LabelBuildRun: buildRun.Name, - buildv1alpha1.LabelBuildRunGeneration: strconv.FormatInt(buildRun.Generation, 10), + buildv1beta1.LabelBuildRun: buildRun.Name, + buildv1beta1.LabelBuildRunGeneration: strconv.FormatInt(buildRun.Generation, 10), } // Add Build name reference unless it is an embedded Build (empty build name) if build.Name != "" { - taskRunLabels[buildv1alpha1.LabelBuild] = build.Name - taskRunLabels[buildv1alpha1.LabelBuildGeneration] = strconv.FormatInt(build.Generation, 10) + taskRunLabels[buildv1beta1.LabelBuild] = build.Name + taskRunLabels[buildv1beta1.LabelBuildGeneration] = strconv.FormatInt(build.Generation, 10) } expectedTaskRun := &pipelineapi.TaskRun{ @@ -349,24 +324,7 @@ func GenerateTaskRun( }, }, } - if build.Spec.Builder != nil { - params = append(params, pipelineapi.Param{ - Name: inputParamBuilder, - Value: pipelineapi.ParamValue{ - Type: pipelineapi.ParamTypeString, - StringVal: build.Spec.Builder.Image, - }, - }) - } - if build.Spec.Dockerfile != nil && *build.Spec.Dockerfile != "" { - params = append(params, pipelineapi.Param{ - Name: inputParamDockerfile, - Value: pipelineapi.ParamValue{ - Type: pipelineapi.ParamTypeString, - StringVal: *build.Spec.Dockerfile, - }, - }) - } + if build.Spec.Source.ContextDir != nil { params = append(params, pipelineapi.Param{ Name: inputParamContextDir, @@ -415,14 +373,14 @@ func GenerateTaskRun( // and if the strategy is pushing the image by not using $(params.shp-output-directory) buildRunOutput := buildRun.Spec.Output if buildRunOutput == nil { - buildRunOutput = &buildv1alpha1.Image{} + buildRunOutput = &buildv1beta1.Image{} } SetupImageProcessing(expectedTaskRun, cfg, build.Spec.Output, *buildRunOutput) return expectedTaskRun, nil } -func effectiveTimeout(build *buildv1alpha1.Build, buildRun *buildv1alpha1.BuildRun) *metav1.Duration { +func effectiveTimeout(build *buildv1beta1.Build, buildRun *buildv1beta1.BuildRun) *metav1.Duration { if buildRun.Spec.Timeout != nil { return buildRun.Spec.Timeout @@ -437,13 +395,13 @@ func effectiveTimeout(build *buildv1alpha1.Build, buildRun *buildv1alpha1.BuildR // also, annotations using our own custom resource domains are filtered out because we have no annotations with a semantic for both TaskRun and Pod func isPropagatableAnnotation(key string) bool { return key != "kubectl.kubernetes.io/last-applied-configuration" && - !strings.HasPrefix(key, buildv1alpha1.ClusterBuildStrategyDomain+"/") && - !strings.HasPrefix(key, buildv1alpha1.BuildStrategyDomain+"/") && - !strings.HasPrefix(key, buildv1alpha1.BuildDomain+"/") && - !strings.HasPrefix(key, buildv1alpha1.BuildRunDomain+"/") + !strings.HasPrefix(key, buildv1beta1.ClusterBuildStrategyDomain+"/") && + !strings.HasPrefix(key, buildv1beta1.BuildStrategyDomain+"/") && + !strings.HasPrefix(key, buildv1beta1.BuildDomain+"/") && + !strings.HasPrefix(key, buildv1beta1.BuildRunDomain+"/") } -func toVolumeMap(strategyVolumes []buildv1alpha1.BuildStrategyVolume) map[string]bool { +func toVolumeMap(strategyVolumes []buildv1beta1.BuildStrategyVolume) map[string]bool { res := make(map[string]bool) for _, v := range strategyVolumes { res[v.Name] = true diff --git a/pkg/reconciler/buildrun/resources/taskrun_test.go b/pkg/reconciler/buildrun/resources/taskrun_test.go index cd118952e5..5c3a02d976 100644 --- a/pkg/reconciler/buildrun/resources/taskrun_test.go +++ b/pkg/reconciler/buildrun/resources/taskrun_test.go @@ -18,31 +18,29 @@ import ( "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/config" "github.com/shipwright-io/build/pkg/env" "github.com/shipwright-io/build/pkg/reconciler/buildrun/resources" - utils "github.com/shipwright-io/build/test/utils/v1alpha1" - test "github.com/shipwright-io/build/test/v1alpha1_samples" + utils "github.com/shipwright-io/build/test/utils/v1beta1" + test "github.com/shipwright-io/build/test/v1beta1_samples" ) var _ = Describe("GenerateTaskrun", func() { var ( - build *buildv1alpha1.Build - buildWithEnvs *buildv1alpha1.Build - buildRun *buildv1alpha1.BuildRun - buildRunWithEnvs *buildv1alpha1.BuildRun - buildStrategy *buildv1alpha1.BuildStrategy + build *buildv1beta1.Build + buildWithEnvs *buildv1beta1.Build + buildRun *buildv1beta1.BuildRun + buildRunWithEnvs *buildv1beta1.BuildRun + buildStrategy *buildv1beta1.BuildStrategy buildStrategyStepNames map[string]struct{} - buildStrategyWithEnvs *buildv1alpha1.BuildStrategy - builderImage *buildv1alpha1.Image - dockerfile, buildpacks string + buildStrategyWithEnvs *buildv1beta1.BuildStrategy + buildpacks string ctl test.Catalog ) BeforeEach(func() { buildpacks = "buildpacks-v3" - dockerfile = "Dockerfile" }) Describe("Generate the TaskSpec", func() { @@ -51,11 +49,6 @@ var _ = Describe("GenerateTaskrun", func() { got *pipelineapi.TaskSpec err error ) - BeforeEach(func() { - builderImage = &buildv1alpha1.Image{ - Image: "quay.io/builder/image", - } - }) Context("when the task spec is generated", func() { BeforeEach(func() { @@ -67,10 +60,10 @@ var _ = Describe("GenerateTaskrun", func() { buildStrategy, err = ctl.LoadBuildStrategyFromBytes([]byte(test.MinimalBuildahBuildStrategy)) Expect(err).To(BeNil()) - buildStrategy.Spec.BuildSteps[0].ImagePullPolicy = "Always" + buildStrategy.Spec.Steps[0].ImagePullPolicy = "Always" expectedCommandOrArg = []string{ - "bud", "--tag=$(params.shp-output-image)", fmt.Sprintf("--file=$(inputs.params.%s)", "DOCKERFILE"), "$(params.shp-source-context)", + "bud", "--tag=$(params.shp-output-image)", "--file=$(params.dockerfile)", "$(params.shp-source-context)", } }) @@ -84,7 +77,7 @@ var _ = Describe("GenerateTaskrun", func() { Expect(got.Steps[0].Name).To(Equal("source-default")) Expect(got.Steps[0].Command[0]).To(Equal("/ko-app/git")) Expect(got.Steps[0].Args).To(Equal([]string{ - "--url", *build.Spec.Source.URL, + "--url", build.Spec.Source.GitSource.URL, "--target", "$(params.shp-source-root)", "--result-file-commit-sha", "$(results.shp-source-default-commit-sha.path)", "--result-file-commit-author", "$(results.shp-source-default-commit-author.path)", @@ -141,7 +134,6 @@ var _ = Describe("GenerateTaskrun", func() { // legacy params Expect(got.Params).ToNot(utils.ContainNamedElement("BUILDER_IMAGE")) // test build has no builder image Expect(got.Params).To(utils.ContainNamedElement("CONTEXT_DIR")) - Expect(got.Params).To(utils.ContainNamedElement("DOCKERFILE")) Expect(len(got.Params)).To(Equal(6)) }) @@ -234,9 +226,9 @@ var _ = Describe("GenerateTaskrun", func() { buildStrategy, err = ctl.LoadBuildStrategyFromBytes([]byte(test.MinimalBuildahBuildStrategy)) Expect(err).To(BeNil()) - buildStrategy.Spec.BuildSteps[0].ImagePullPolicy = "Always" + buildStrategy.Spec.Steps[0].ImagePullPolicy = "Always" buildStrategyStepNames = make(map[string]struct{}) - for _, step := range buildStrategy.Spec.BuildSteps { + for _, step := range buildStrategy.Spec.Steps { buildStrategyStepNames[step.Name] = struct{}{} } @@ -249,7 +241,7 @@ var _ = Describe("GenerateTaskrun", func() { }) It("should contain env vars specified in Build in every BuildStrategy step", func() { - got, err = resources.GenerateTaskSpec(config.NewDefaultConfig(), buildWithEnvs, buildRun, buildStrategy.Spec.BuildSteps, []buildv1alpha1.Parameter{}, buildStrategy.GetVolumes()) + got, err = resources.GenerateTaskSpec(config.NewDefaultConfig(), buildWithEnvs, buildRun, buildStrategy.Spec.Steps, []buildv1beta1.Parameter{}, buildStrategy.GetVolumes()) Expect(err).To(BeNil()) combinedEnvs, err := env.MergeEnvVars(buildRun.Spec.Env, buildWithEnvs.Spec.Env, true) @@ -266,7 +258,7 @@ var _ = Describe("GenerateTaskrun", func() { }) It("should contain env vars specified in BuildRun in every step", func() { - got, err = resources.GenerateTaskSpec(config.NewDefaultConfig(), build, buildRunWithEnvs, buildStrategy.Spec.BuildSteps, []buildv1alpha1.Parameter{}, buildStrategy.GetVolumes()) + got, err = resources.GenerateTaskSpec(config.NewDefaultConfig(), build, buildRunWithEnvs, buildStrategy.Spec.Steps, []buildv1beta1.Parameter{}, buildStrategy.GetVolumes()) Expect(err).To(BeNil()) combinedEnvs, err := env.MergeEnvVars(buildRunWithEnvs.Spec.Env, build.Spec.Env, true) @@ -283,7 +275,7 @@ var _ = Describe("GenerateTaskrun", func() { }) It("should override Build env vars with BuildRun env vars in every step", func() { - got, err = resources.GenerateTaskSpec(config.NewDefaultConfig(), buildWithEnvs, buildRunWithEnvs, buildStrategy.Spec.BuildSteps, []buildv1alpha1.Parameter{}, buildStrategy.GetVolumes()) + got, err = resources.GenerateTaskSpec(config.NewDefaultConfig(), buildWithEnvs, buildRunWithEnvs, buildStrategy.Spec.Steps, []buildv1beta1.Parameter{}, buildStrategy.GetVolumes()) Expect(err).To(BeNil()) combinedEnvs, err := env.MergeEnvVars(buildRunWithEnvs.Spec.Env, buildWithEnvs.Spec.Env, true) @@ -301,7 +293,7 @@ var _ = Describe("GenerateTaskrun", func() { }) It("should fail attempting to override an env var in a BuildStrategy", func() { - got, err = resources.GenerateTaskSpec(config.NewDefaultConfig(), buildWithEnvs, buildRunWithEnvs, buildStrategyWithEnvs.Spec.BuildSteps, []buildv1alpha1.Parameter{}, buildStrategy.GetVolumes()) + got, err = resources.GenerateTaskSpec(config.NewDefaultConfig(), buildWithEnvs, buildRunWithEnvs, buildStrategyWithEnvs.Spec.Steps, []buildv1beta1.Parameter{}, buildStrategy.GetVolumes()) Expect(err).NotTo(BeNil()) Expect(err.Error()).To(Equal("error(s) occurred merging environment variables into BuildStrategy \"buildah\" steps: [environment variable \"MY_VAR_1\" already exists, environment variable \"MY_VAR_2\" already exists]")) }) @@ -317,14 +309,14 @@ var _ = Describe("GenerateTaskrun", func() { buildStrategy, err = ctl.LoadBuildStrategyFromBytes([]byte(test.MinimalBuildahBuildStrategy)) Expect(err).To(BeNil()) - buildStrategy.Spec.BuildSteps[0].ImagePullPolicy = "Always" + buildStrategy.Spec.Steps[0].ImagePullPolicy = "Always" expectedCommandOrArg = []string{ "bud", "--tag=$(params.shp-output-image)", fmt.Sprintf("--file=$(inputs.params.%s)", "DOCKERFILE"), "$(params.shp-source-context)", } JustBeforeEach(func() { - got, err = resources.GenerateTaskSpec(config.NewDefaultConfig(), build, buildRun, buildStrategy.Spec.BuildSteps, []buildv1alpha1.Parameter{}, buildStrategy.GetVolumes()) + got, err = resources.GenerateTaskSpec(config.NewDefaultConfig(), build, buildRun, buildStrategy.Spec.Steps, []buildv1beta1.Parameter{}, buildStrategy.GetVolumes()) Expect(err).To(BeNil()) }) @@ -358,14 +350,14 @@ var _ = Describe("GenerateTaskrun", func() { buildStrategy, err = ctl.LoadBuildStrategyFromBytes([]byte(test.MinimalBuildahBuildStrategy)) Expect(err).To(BeNil()) - buildStrategy.Spec.BuildSteps[0].ImagePullPolicy = "Always" + buildStrategy.Spec.Steps[0].ImagePullPolicy = "Always" expectedCommandOrArg = []string{ "bud", "--tag=$(params.shp-output-image)", fmt.Sprintf("--file=$(inputs.params.%s)", "DOCKERFILE"), "$(params.shp-source-context)", } JustBeforeEach(func() { - got, err = resources.GenerateTaskSpec(config.NewDefaultConfig(), build, buildRun, buildStrategy.Spec.BuildSteps, []buildv1alpha1.Parameter{}, buildStrategy.GetVolumes()) + got, err = resources.GenerateTaskSpec(config.NewDefaultConfig(), build, buildRun, buildStrategy.Spec.Steps, []buildv1beta1.Parameter{}, buildStrategy.GetVolumes()) Expect(err).To(BeNil()) }) @@ -414,9 +406,6 @@ var _ = Describe("GenerateTaskrun", func() { namespace = "build-test" contextDir = "docker-build" - builderImage = &buildv1alpha1.Image{ - Image: "heroku/builder:22", - } outputPath = "image-registry.openshift-image-registry.svc:5000/example/buildpacks-app" outputPathBuildRun = "image-registry.openshift-image-registry.svc:5000/example/buildpacks-app-v2" serviceAccountName = buildpacks + "-serviceaccount" @@ -444,10 +433,10 @@ var _ = Describe("GenerateTaskrun", func() { Expect(strings.Contains(got.GenerateName, buildRun.Name+"-")).To(Equal(true)) Expect(got.Namespace).To(Equal(namespace)) Expect(got.Spec.ServiceAccountName).To(Equal(buildpacks + "-serviceaccount")) - Expect(got.Labels[buildv1alpha1.LabelBuild]).To(Equal(build.Name)) - Expect(got.Labels[buildv1alpha1.LabelBuildRun]).To(Equal(buildRun.Name)) - Expect(got.Labels[buildv1alpha1.LabelBuildStrategyName]).To(Equal(build.Spec.Strategy.Name)) - Expect(got.Labels[buildv1alpha1.LabelBuildStrategyGeneration]).To(Equal("0")) + Expect(got.Labels[buildv1beta1.LabelBuild]).To(Equal(build.Name)) + Expect(got.Labels[buildv1beta1.LabelBuildRun]).To(Equal(buildRun.Name)) + Expect(got.Labels[buildv1beta1.LabelBuildStrategyName]).To(Equal(build.Spec.Strategy.Name)) + Expect(got.Labels[buildv1beta1.LabelBuildStrategyGeneration]).To(Equal("0")) }) It("should filter out certain annotations when propagating them to the TaskRun", func() { @@ -496,8 +485,8 @@ var _ = Describe("GenerateTaskrun", func() { Expect(strings.Contains(got.GenerateName, buildRun.Name+"-")).To(Equal(true)) Expect(got.Namespace).To(Equal(namespace)) Expect(got.Spec.ServiceAccountName).To(Equal(buildpacks + "-serviceaccount")) - Expect(got.Labels[buildv1alpha1.LabelBuild]).To(Equal(build.Name)) - Expect(got.Labels[buildv1alpha1.LabelBuildRun]).To(Equal(buildRun.Name)) + Expect(got.Labels[buildv1beta1.LabelBuild]).To(Equal(build.Name)) + Expect(got.Labels[buildv1beta1.LabelBuildRun]).To(Equal(buildRun.Name)) }) It("should ensure generated TaskRun's spec special input params are correct", func() { @@ -509,8 +498,6 @@ var _ = Describe("GenerateTaskrun", func() { paramOutputInsecureFound := false // legacy params - paramBuilderImageFound := false - paramDockerfileFound := false paramContextDirFound := false for _, param := range params { @@ -531,14 +518,6 @@ var _ = Describe("GenerateTaskrun", func() { paramOutputInsecureFound = true Expect(param.Value.StringVal).To(Equal("false")) - case "BUILDER_IMAGE": - paramBuilderImageFound = true - Expect(param.Value.StringVal).To(Equal(builderImage.Image)) - - case "DOCKERFILE": - paramDockerfileFound = true - Expect(param.Value.StringVal).To(Equal(dockerfile)) - case "CONTEXT_DIR": paramContextDirFound = true Expect(param.Value.StringVal).To(Equal(contextDir)) @@ -552,9 +531,6 @@ var _ = Describe("GenerateTaskrun", func() { Expect(paramSourceContextFound).To(BeTrue()) Expect(paramOutputImageFound).To(BeTrue()) Expect(paramOutputInsecureFound).To(BeTrue()) - - Expect(paramBuilderImageFound).To(BeTrue()) - Expect(paramDockerfileFound).To(BeTrue()) Expect(paramContextDirFound).To(BeTrue()) }) diff --git a/pkg/reconciler/buildrunttlcleanup/buildrun_ttl_cleanup.go b/pkg/reconciler/buildrunttlcleanup/buildrun_ttl_cleanup.go index b1f581e7fd..abe645b8a6 100644 --- a/pkg/reconciler/buildrunttlcleanup/buildrun_ttl_cleanup.go +++ b/pkg/reconciler/buildrunttlcleanup/buildrun_ttl_cleanup.go @@ -8,7 +8,7 @@ import ( "context" "time" - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/config" "github.com/shipwright-io/build/pkg/ctxlog" 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 := &buildv1alpha1.BuildRun{} + br := &buildv1beta1.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(buildv1alpha1.Succeeded) + condition := br.Status.GetCondition(buildv1beta1.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 fe893363bc..4cef1bc7d9 100644 --- a/pkg/reconciler/buildrunttlcleanup/controller.go +++ b/pkg/reconciler/buildrunttlcleanup/controller.go @@ -7,7 +7,7 @@ package buildrunttlcleanup import ( "context" - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/config" 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 *buildv1alpha1.Condition, o *buildv1alpha1.BuildRun) bool { +func reconcileCompletedBuildRun(condition *buildv1beta1.Condition, o *buildv1beta1.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 *buildv1alpha1.Condition, o *buildv1al // 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 *buildv1alpha1.Condition, n *buildv1alpha1.BuildRun, o *buildv1alpha1.BuildRun) bool { +func reconcileAlreadyCompletedBuildRun(newCondition *buildv1beta1.Condition, n *buildv1beta1.BuildRun, o *buildv1beta1.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.(*buildv1alpha1.BuildRun) + o := e.Object.(*buildv1beta1.BuildRun) // ignore a running BuildRun - condition := o.Status.GetCondition(buildv1alpha1.Succeeded) + condition := o.Status.GetCondition(buildv1beta1.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.(*buildv1alpha1.BuildRun) - newCondition := n.Status.GetCondition(buildv1alpha1.Succeeded) + n := e.ObjectNew.(*buildv1beta1.BuildRun) + newCondition := n.Status.GetCondition(buildv1beta1.Succeeded) if newCondition == nil || newCondition.Status == corev1.ConditionUnknown { return false } - o := e.ObjectOld.(*buildv1alpha1.BuildRun) - oldCondition := o.Status.GetCondition(buildv1alpha1.Succeeded) + o := e.ObjectOld.(*buildv1beta1.BuildRun) + oldCondition := o.Status.GetCondition(buildv1beta1.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{Type: &buildv1alpha1.BuildRun{}}, &handler.EnqueueRequestForObject{}, predBuildRun) + return c.Watch(&source.Kind{Type: &buildv1beta1.BuildRun{}}, &handler.EnqueueRequestForObject{}, predBuildRun) } diff --git a/pkg/reconciler/buildstrategy/controller.go b/pkg/reconciler/buildstrategy/controller.go index 775272a598..bc21822861 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" - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/config" ) @@ -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{Type: &buildv1alpha1.BuildStrategy{}}, &handler.EnqueueRequestForObject{}) + return c.Watch(&source.Kind{Type: &buildv1beta1.BuildStrategy{}}, &handler.EnqueueRequestForObject{}) } diff --git a/pkg/reconciler/clusterbuildstrategy/controller.go b/pkg/reconciler/clusterbuildstrategy/controller.go index 22ec740b93..51fead9dd0 100644 --- a/pkg/reconciler/clusterbuildstrategy/controller.go +++ b/pkg/reconciler/clusterbuildstrategy/controller.go @@ -13,7 +13,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" "sigs.k8s.io/controller-runtime/pkg/source" - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/config" ) @@ -40,5 +40,5 @@ func add(mgr manager.Manager, r reconcile.Reconciler, maxConcurrentReconciles in } // Watch for changes to primary resource ClusterBuildStrategy - return c.Watch(&source.Kind{Type: &buildv1alpha1.ClusterBuildStrategy{}}, &handler.EnqueueRequestForObject{}) + return c.Watch(&source.Kind{Type: &buildv1beta1.ClusterBuildStrategy{}}, &handler.EnqueueRequestForObject{}) } diff --git a/pkg/validate/buildname.go b/pkg/validate/buildname.go index 1eaa83c1f5..8f810d2dcf 100644 --- a/pkg/validate/buildname.go +++ b/pkg/validate/buildname.go @@ -11,7 +11,7 @@ import ( "k8s.io/apimachinery/pkg/util/validation" "k8s.io/utils/pointer" - build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" ) // BuildNameRef contains all required fields diff --git a/pkg/validate/envvars.go b/pkg/validate/envvars.go index 6d116b78ad..aacea4a8a9 100644 --- a/pkg/validate/envvars.go +++ b/pkg/validate/envvars.go @@ -12,7 +12,7 @@ import ( kerrors "k8s.io/apimachinery/pkg/util/errors" "k8s.io/utils/pointer" - build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" ) // Env implements the Env interface to add validations for the `build.spec.env` slice. diff --git a/pkg/validate/envvars_test.go b/pkg/validate/envvars_test.go index 293de3e5ac..9dc921ff99 100644 --- a/pkg/validate/envvars_test.go +++ b/pkg/validate/envvars_test.go @@ -13,7 +13,7 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/utils/pointer" - build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/validate" ) diff --git a/pkg/validate/ownerreferences.go b/pkg/validate/ownerreferences.go index 2a39c8fe83..27d38f2954 100644 --- a/pkg/validate/ownerreferences.go +++ b/pkg/validate/ownerreferences.go @@ -15,7 +15,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" - build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/ctxlog" ) @@ -35,8 +35,7 @@ func (o OwnerRef) ValidatePath(ctx context.Context) error { return err } - switch o.Build.GetAnnotations()[build.AnnotationBuildRunDeletion] { - case "true": + if o.Build.Spec.Retention != nil && o.Build.Spec.Retention.AtBuildDeletion != nil && *o.Build.Spec.Retention.AtBuildDeletion { // if the buildRun does not have an ownerreference to the Build, lets add it. for i := range buildRunList.Items { buildRun := buildRunList.Items[i] @@ -52,7 +51,7 @@ func (o OwnerRef) ValidatePath(ctx context.Context) error { ctxlog.Info(ctx, fmt.Sprintf("successfully updated BuildRun %s", buildRun.Name), namespace, buildRun.Namespace, name, buildRun.Name) } } - case "", "false": + } else { // if the buildRun have an ownerreference to the Build, lets remove it for i := range buildRunList.Items { buildRun := buildRunList.Items[i] @@ -65,12 +64,7 @@ func (o OwnerRef) ValidatePath(ctx context.Context) error { ctxlog.Info(ctx, fmt.Sprintf("successfully updated BuildRun %s", buildRun.Name), namespace, buildRun.Namespace, name, buildRun.Name) } } - - default: - ctxlog.Info(ctx, fmt.Sprintf("the annotation %s was not properly defined, supported values are true or false", build.AnnotationBuildRunDeletion), namespace, o.Build.Namespace, name, o.Build.Name) - return fmt.Errorf("the annotation %s was not properly defined, supported values are true or false", build.AnnotationBuildRunDeletion) } - return nil } diff --git a/pkg/validate/params.go b/pkg/validate/params.go index 17fb4a8be9..34a4e4d29c 100644 --- a/pkg/validate/params.go +++ b/pkg/validate/params.go @@ -8,23 +8,23 @@ import ( "fmt" "strings" - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/reconciler/buildrun/resources" ) // BuildParameters validates that the parameter values specified in Build are suitable for what is defined in the BuildStrategy -func BuildParameters(parameterDefinitions []buildv1alpha1.Parameter, buildParamValues []buildv1alpha1.ParamValue) (bool, buildv1alpha1.BuildReason, string) { +func BuildParameters(parameterDefinitions []buildv1beta1.Parameter, buildParamValues []buildv1beta1.ParamValue) (bool, buildv1beta1.BuildReason, string) { valid, reason, message := validateParameters(parameterDefinitions, buildParamValues, true) - return valid, buildv1alpha1.BuildReason(reason), message + return valid, buildv1beta1.BuildReason(reason), message } // BuildRunParameters validates that the parameter values specified in Build and BuildRun are suitable for what is defined in the BuildStrategy -func BuildRunParameters(parameterDefinitions []buildv1alpha1.Parameter, buildParamValues []buildv1alpha1.ParamValue, buildRunParamValues []buildv1alpha1.ParamValue) (bool, string, string) { +func BuildRunParameters(parameterDefinitions []buildv1beta1.Parameter, buildParamValues []buildv1beta1.ParamValue, buildRunParamValues []buildv1beta1.ParamValue) (bool, string, string) { paramValues := resources.OverrideParams(buildParamValues, buildRunParamValues) return validateParameters(parameterDefinitions, paramValues, false) } -func validateParameters(parameterDefinitions []buildv1alpha1.Parameter, paramValues []buildv1alpha1.ParamValue, ignoreMissingParameters bool) (bool, string, string) { +func validateParameters(parameterDefinitions []buildv1beta1.Parameter, paramValues []buildv1beta1.ParamValue, ignoreMissingParameters bool) (bool, string, string) { // list of params that collide with reserved system strategy parameters undesiredParams := []string{} @@ -76,7 +76,7 @@ func validateParameters(parameterDefinitions []buildv1alpha1.Parameter, paramVal switch parameterDefinition.Type { case "": // string is default fallthrough - case buildv1alpha1.ParameterTypeString: + case buildv1beta1.ParameterTypeString: if paramValue != nil { // check if a string value contains array values if paramValue.Values != nil { @@ -107,7 +107,7 @@ func validateParameters(parameterDefinitions []buildv1alpha1.Parameter, paramVal continue } - case buildv1alpha1.ParameterTypeArray: + case buildv1beta1.ParameterTypeArray: if paramValue != nil { // check if an array value contains a single value if paramValue.SingleValue != nil { @@ -180,7 +180,7 @@ func validateParameters(parameterDefinitions []buildv1alpha1.Parameter, paramVal } // hasMoreThanOneValue checks if a SingleValue has more than one value set (plain text, secret, and config map key reference) -func hasMoreThanOneValue(singleValue buildv1alpha1.SingleValue) bool { +func hasMoreThanOneValue(singleValue buildv1beta1.SingleValue) bool { if singleValue.Value != nil && (singleValue.ConfigMapValue != nil || singleValue.SecretValue != nil) { return true } @@ -195,7 +195,7 @@ func hasMoreThanOneValue(singleValue buildv1alpha1.SingleValue) bool { } // hasNoValue checks if a SingleValue has no value set (plain text, secret, and config map key reference) -func hasNoValue(singleValue buildv1alpha1.SingleValue) bool { +func hasNoValue(singleValue buildv1beta1.SingleValue) bool { if singleValue.ConfigMapValue == nil && singleValue.SecretValue == nil && singleValue.Value == nil { return true } @@ -204,7 +204,7 @@ func hasNoValue(singleValue buildv1alpha1.SingleValue) bool { } // hasIncompleteConfigMapValue checks if a SingleValue has a ConfigMap value with an empty name or key -func hasIncompleteConfigMapValue(singleValue buildv1alpha1.SingleValue) bool { +func hasIncompleteConfigMapValue(singleValue buildv1beta1.SingleValue) bool { if singleValue.ConfigMapValue != nil && (singleValue.ConfigMapValue.Name == "" || singleValue.ConfigMapValue.Key == "") { return true } @@ -213,7 +213,7 @@ func hasIncompleteConfigMapValue(singleValue buildv1alpha1.SingleValue) bool { } // hasIncompleteSecretValue checks if a SingleValue has a Secret value with an empty name or key -func hasIncompleteSecretValue(singleValue buildv1alpha1.SingleValue) bool { +func hasIncompleteSecretValue(singleValue buildv1beta1.SingleValue) bool { if singleValue.SecretValue != nil && (singleValue.SecretValue.Name == "" || singleValue.SecretValue.Key == "") { return true } diff --git a/pkg/validate/params_test.go b/pkg/validate/params_test.go index 9b97130e6e..494badf7c9 100644 --- a/pkg/validate/params_test.go +++ b/pkg/validate/params_test.go @@ -9,46 +9,46 @@ import ( . "github.com/onsi/gomega" "k8s.io/utils/pointer" - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/validate" ) var _ = Describe("ValidateBuildRunParameters", func() { Context("for a set of parameter definitions", func() { - parameterDefinitions := []buildv1alpha1.Parameter{ + parameterDefinitions := []buildv1beta1.Parameter{ { Name: "string-param-no-default", }, { Name: "string-param-with-default", - Type: buildv1alpha1.ParameterTypeString, + Type: buildv1beta1.ParameterTypeString, Default: pointer.String("default value"), }, { Name: "array-param-no-defaults", - Type: buildv1alpha1.ParameterTypeArray, + Type: buildv1beta1.ParameterTypeArray, }, { Name: "array-param-with-defaults", - Type: buildv1alpha1.ParameterTypeArray, + Type: buildv1beta1.ParameterTypeArray, Defaults: &[]string{}, }, } Context("for parameters just for the required fields", func() { - buildParamValues := []buildv1alpha1.ParamValue{ + buildParamValues := []buildv1beta1.ParamValue{ { Name: "string-param-no-default", - SingleValue: &buildv1alpha1.SingleValue{ + SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("a value"), }, }, } - buildRunParamValues := []buildv1alpha1.ParamValue{ + buildRunParamValues := []buildv1beta1.ParamValue{ { Name: "array-param-no-defaults", - Values: []buildv1alpha1.SingleValue{}, + Values: []buildv1beta1.SingleValue{}, }, } @@ -59,11 +59,11 @@ var _ = Describe("ValidateBuildRunParameters", func() { }) Context("for parameter values from different sources", func() { - buildParamValues := []buildv1alpha1.ParamValue{ + buildParamValues := []buildv1beta1.ParamValue{ { Name: "string-param-no-default", - SingleValue: &buildv1alpha1.SingleValue{ - ConfigMapValue: &buildv1alpha1.ObjectKeyRef{ + SingleValue: &buildv1beta1.SingleValue{ + ConfigMapValue: &buildv1beta1.ObjectKeyRef{ Name: "a-config-map", Key: "some-key", }, @@ -72,16 +72,16 @@ var _ = Describe("ValidateBuildRunParameters", func() { { Name: "string-param-with-default", // This is invalid but will be corrected in the BuildRun - Values: []buildv1alpha1.SingleValue{}, + Values: []buildv1beta1.SingleValue{}, }, } - buildRunParamValues := []buildv1alpha1.ParamValue{ + buildRunParamValues := []buildv1beta1.ParamValue{ { Name: "array-param-no-defaults", - Values: []buildv1alpha1.SingleValue{ + Values: []buildv1beta1.SingleValue{ { - SecretValue: &buildv1alpha1.ObjectKeyRef{ + SecretValue: &buildv1beta1.ObjectKeyRef{ Name: "a-secret", Key: "my-credential-key", }, @@ -90,7 +90,7 @@ var _ = Describe("ValidateBuildRunParameters", func() { }, { Name: "string-param-with-default", - SingleValue: &buildv1alpha1.SingleValue{ + SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String(""), }, }, @@ -105,7 +105,7 @@ var _ = Describe("ValidateBuildRunParameters", func() { Context("for parameter values that are missing", func() { It("validates with the correct validation error", func() { - valid, reason, message := validate.BuildRunParameters(parameterDefinitions, []buildv1alpha1.ParamValue{}, []buildv1alpha1.ParamValue{}) + valid, reason, message := validate.BuildRunParameters(parameterDefinitions, []buildv1beta1.ParamValue{}, []buildv1beta1.ParamValue{}) Expect(valid).To(BeFalse()) Expect(reason).To(Equal("MissingParameterValues")) Expect(message).To(HavePrefix("The following parameters are required but no value has been provided:")) @@ -115,17 +115,17 @@ var _ = Describe("ValidateBuildRunParameters", func() { }) Context("for a parameter value that is defined but contains no value", func() { - buildParamValues := []buildv1alpha1.ParamValue{ + buildParamValues := []buildv1beta1.ParamValue{ { Name: "string-param-no-default", - SingleValue: &buildv1alpha1.SingleValue{}, + SingleValue: &buildv1beta1.SingleValue{}, }, } - buildRunParamValues := []buildv1alpha1.ParamValue{ + buildRunParamValues := []buildv1beta1.ParamValue{ { Name: "array-param-no-defaults", - Values: []buildv1alpha1.SingleValue{}, + Values: []buildv1beta1.SingleValue{}, }, } @@ -138,23 +138,23 @@ var _ = Describe("ValidateBuildRunParameters", func() { }) Context("for parameter values that contain a value for a system parameter", func() { - buildParamValues := []buildv1alpha1.ParamValue{ + buildParamValues := []buildv1beta1.ParamValue{ { Name: "string-param-no-default", - SingleValue: &buildv1alpha1.SingleValue{ + SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("a value"), }, }, { Name: "array-param-no-defaults", - Values: []buildv1alpha1.SingleValue{}, + Values: []buildv1beta1.SingleValue{}, }, } - buildRunParamValues := []buildv1alpha1.ParamValue{ + buildRunParamValues := []buildv1beta1.ParamValue{ { Name: "shp-source-context", - SingleValue: &buildv1alpha1.SingleValue{ + SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("/my-source"), }, }, @@ -169,27 +169,27 @@ var _ = Describe("ValidateBuildRunParameters", func() { }) Context("for parameter values that are not defined in the build strategy", func() { - buildParamValues := []buildv1alpha1.ParamValue{ + buildParamValues := []buildv1beta1.ParamValue{ { Name: "string-param-no-default", - SingleValue: &buildv1alpha1.SingleValue{ + SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("a value"), }, }, { Name: "array-param-no-defaults", - Values: []buildv1alpha1.SingleValue{}, + Values: []buildv1beta1.SingleValue{}, }, { Name: "non-existing-parameter-on-build", - Values: []buildv1alpha1.SingleValue{}, + Values: []buildv1beta1.SingleValue{}, }, } - buildRunParamValues := []buildv1alpha1.ParamValue{ + buildRunParamValues := []buildv1beta1.ParamValue{ { Name: "non-existing-parameter", - SingleValue: &buildv1alpha1.SingleValue{ + SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("my value"), }, }, @@ -206,12 +206,12 @@ var _ = Describe("ValidateBuildRunParameters", func() { }) Context("for parameter values that contain more than one value", func() { - buildParamValues := []buildv1alpha1.ParamValue{ + buildParamValues := []buildv1beta1.ParamValue{ { Name: "string-param-no-default", - SingleValue: &buildv1alpha1.SingleValue{ + SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("a value"), - ConfigMapValue: &buildv1alpha1.ObjectKeyRef{ + ConfigMapValue: &buildv1beta1.ObjectKeyRef{ Name: "a-config-map", Key: "a-key", }, @@ -219,19 +219,19 @@ var _ = Describe("ValidateBuildRunParameters", func() { }, } - buildRunParamValues := []buildv1alpha1.ParamValue{ + buildRunParamValues := []buildv1beta1.ParamValue{ { Name: "array-param-no-defaults", - Values: []buildv1alpha1.SingleValue{ + Values: []buildv1beta1.SingleValue{ { Value: pointer.String("a good item"), }, { - ConfigMapValue: &buildv1alpha1.ObjectKeyRef{ + ConfigMapValue: &buildv1beta1.ObjectKeyRef{ Name: "a-config-map", Key: "a-key", }, - SecretValue: &buildv1alpha1.ObjectKeyRef{ + SecretValue: &buildv1beta1.ObjectKeyRef{ Name: "a-secret", Key: "a-key", }, @@ -251,15 +251,15 @@ var _ = Describe("ValidateBuildRunParameters", func() { }) Context("for parameter values that use the wrong type", func() { - buildParamValues := []buildv1alpha1.ParamValue{ + buildParamValues := []buildv1beta1.ParamValue{ { Name: "string-param-no-default", - Values: []buildv1alpha1.SingleValue{ + Values: []buildv1beta1.SingleValue{ { Value: pointer.String("an item"), }, { - ConfigMapValue: &buildv1alpha1.ObjectKeyRef{ + ConfigMapValue: &buildv1beta1.ObjectKeyRef{ Name: "a-config-map", Key: "a-key", }, @@ -268,10 +268,10 @@ var _ = Describe("ValidateBuildRunParameters", func() { }, } - buildRunParamValues := []buildv1alpha1.ParamValue{ + buildRunParamValues := []buildv1beta1.ParamValue{ { Name: "array-param-no-defaults", - SingleValue: &buildv1alpha1.SingleValue{ + SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String("a value"), }, }, @@ -288,16 +288,16 @@ var _ = Describe("ValidateBuildRunParameters", func() { }) Context("for array parameter values that contain empty items", func() { - buildParamValues := []buildv1alpha1.ParamValue{ + buildParamValues := []buildv1beta1.ParamValue{ { Name: "string-param-no-default", - SingleValue: &buildv1alpha1.SingleValue{ + SingleValue: &buildv1beta1.SingleValue{ Value: pointer.String(" some value"), }, }, { Name: "array-param-with-defaults", - Values: []buildv1alpha1.SingleValue{ + Values: []buildv1beta1.SingleValue{ { // the bad item without any value }, @@ -305,10 +305,10 @@ var _ = Describe("ValidateBuildRunParameters", func() { }, } - buildRunParamValues := []buildv1alpha1.ParamValue{ + buildRunParamValues := []buildv1beta1.ParamValue{ { Name: "array-param-no-defaults", - Values: []buildv1alpha1.SingleValue{ + Values: []buildv1beta1.SingleValue{ { Value: pointer.String("a good item"), }, @@ -316,7 +316,7 @@ var _ = Describe("ValidateBuildRunParameters", func() { // the bad item without any value }, { - ConfigMapValue: &buildv1alpha1.ObjectKeyRef{ + ConfigMapValue: &buildv1beta1.ObjectKeyRef{ Name: "a-configmap", Key: "a-key", }, @@ -336,26 +336,26 @@ var _ = Describe("ValidateBuildRunParameters", func() { }) Context("for parameter values that contain incomplete configMapValues", func() { - buildParamValues := []buildv1alpha1.ParamValue{ + buildParamValues := []buildv1beta1.ParamValue{ { Name: "string-param-no-default", - SingleValue: &buildv1alpha1.SingleValue{ - ConfigMapValue: &buildv1alpha1.ObjectKeyRef{ + SingleValue: &buildv1beta1.SingleValue{ + ConfigMapValue: &buildv1beta1.ObjectKeyRef{ Name: "a-config-map", }, }, }, } - buildRunParamValues := []buildv1alpha1.ParamValue{ + buildRunParamValues := []buildv1beta1.ParamValue{ { Name: "array-param-no-defaults", - Values: []buildv1alpha1.SingleValue{ + Values: []buildv1beta1.SingleValue{ { Value: pointer.String("an item"), }, { - ConfigMapValue: &buildv1alpha1.ObjectKeyRef{ + ConfigMapValue: &buildv1beta1.ObjectKeyRef{ Key: "a-key", }, }, @@ -374,26 +374,26 @@ var _ = Describe("ValidateBuildRunParameters", func() { }) Context("for parameter values that contain incomplete secretValues", func() { - buildParamValues := []buildv1alpha1.ParamValue{ + buildParamValues := []buildv1beta1.ParamValue{ { Name: "string-param-no-default", - SingleValue: &buildv1alpha1.SingleValue{ - SecretValue: &buildv1alpha1.ObjectKeyRef{ + SingleValue: &buildv1beta1.SingleValue{ + SecretValue: &buildv1beta1.ObjectKeyRef{ Name: "a-secret", }, }, }, } - buildRunParamValues := []buildv1alpha1.ParamValue{ + buildRunParamValues := []buildv1beta1.ParamValue{ { Name: "array-param-no-defaults", - Values: []buildv1alpha1.SingleValue{ + Values: []buildv1beta1.SingleValue{ { Value: pointer.String("an item"), }, { - SecretValue: &buildv1alpha1.ObjectKeyRef{ + SecretValue: &buildv1beta1.ObjectKeyRef{ Key: "a-key", }, }, diff --git a/pkg/validate/secrets.go b/pkg/validate/secrets.go index 5e3692e0c6..0043049663 100644 --- a/pkg/validate/secrets.go +++ b/pkg/validate/secrets.go @@ -16,7 +16,7 @@ import ( "k8s.io/utils/pointer" "sigs.k8s.io/controller-runtime/pkg/client" - build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" ) // Credentials contains all required fields @@ -61,14 +61,12 @@ func (s Credentials) ValidatePath(ctx context.Context) error { func (s Credentials) buildCredentialserences() map[string]build.BuildReason { // Validate if the referenced secrets exist in the namespace secretRefMap := map[string]build.BuildReason{} - if s.Build.Spec.Output.Credentials != nil && s.Build.Spec.Output.Credentials.Name != "" { - secretRefMap[s.Build.Spec.Output.Credentials.Name] = build.SpecOutputSecretRefNotFound + if s.Build.Spec.Output.PushSecret != nil { + secretRefMap[*s.Build.Spec.Output.PushSecret] = build.SpecOutputSecretRefNotFound } - if s.Build.Spec.Source.Credentials != nil && s.Build.Spec.Source.Credentials.Name != "" { - secretRefMap[s.Build.Spec.Source.Credentials.Name] = build.SpecSourceSecretRefNotFound - } - if s.Build.Spec.Builder != nil && s.Build.Spec.Builder.Credentials != nil && s.Build.Spec.Builder.Credentials.Name != "" { - secretRefMap[s.Build.Spec.Builder.Credentials.Name] = build.SpecBuilderSecretRefNotFound + + if s.Build.GetSourceCredentials() != nil { + secretRefMap[*s.Build.GetSourceCredentials()] = build.SpecSourceSecretRefNotFound } return secretRefMap } diff --git a/pkg/validate/sources.go b/pkg/validate/sources.go index 8e8d37055e..3b7161249c 100644 --- a/pkg/validate/sources.go +++ b/pkg/validate/sources.go @@ -7,42 +7,54 @@ package validate import ( "context" "fmt" - "net/url" - build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" ) -// SourcesRef implements RuntimeRef interface to add validations for `build.spec.sources` slice. -type SourcesRef struct { +// SourcesRef implements RuntimeRef interface to add validations for `build.spec.source`. +type SourceRef struct { Build *build.Build // build instance for analysis } -// ValidatePath executes the validation routine, inspecting the `build.spec.sources` path, which -// contains a slice of BuildSource. -func (s *SourcesRef) ValidatePath(_ context.Context) error { - for _, source := range s.Build.Spec.Sources { - if err := s.validateSourceEntry(source); err != nil { - return err - } +// ValidatePath executes the validation routine, inspecting the `build.spec.source` path +func (s *SourceRef) ValidatePath(_ context.Context) error { + + if err := s.validateSourceEntry(s.Build.Spec.Source); err != nil { + return err } + return nil } // validateSourceEntry inspect informed entry, probes all required attributes. -func (s *SourcesRef) validateSourceEntry(source build.BuildSource) error { - if source.Name == "" { - return fmt.Errorf("name must be informed") - } - if source.URL == "" { - return fmt.Errorf("URL must be informed") +func (s *SourceRef) validateSourceEntry(source build.Source) error { + + // dont bail out if the Source object is empty, we preserve the old behaviour as in v1alpha1 + if source.Type == "" && source.GitSource == nil && + source.OCIArtifact == nil && source.LocalSource == nil { + return nil } - if _, err := url.ParseRequestURI(source.URL); err != nil { - return err + + switch source.Type { + case "Git": + if source.GitSource == nil || source.OCIArtifact != nil || source.LocalSource != nil { + return fmt.Errorf("type does not match the source") + } + case "OCI": + if source.OCIArtifact == nil || source.GitSource != nil || source.LocalSource != nil { + return fmt.Errorf("type does not match the source") + } + case "Local": + if source.LocalSource == nil || source.OCIArtifact != nil || source.GitSource != nil { + return fmt.Errorf("type does not match the source") + } + case "": + return fmt.Errorf("type definition is missing") } return nil } // NewSourcesRef instantiate a new SourcesRef passing the build object pointer along. -func NewSourcesRef(b *build.Build) *SourcesRef { - return &SourcesRef{Build: b} +func NewSourceRef(b *build.Build) *SourceRef { + return &SourceRef{Build: b} } diff --git a/pkg/validate/sources_test.go b/pkg/validate/sources_test.go index ab68bb3efb..d2914eb8d3 100644 --- a/pkg/validate/sources_test.go +++ b/pkg/validate/sources_test.go @@ -10,23 +10,24 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/validate" ) var _ = Describe("SourcesRef", func() { Context("ValidatePath", func() { - It("should successfully validate an empty sources slice", func() { - srcRef := validate.NewSourcesRef(&build.Build{}) + It("should successfully validate an empty source", func() { + srcRef := validate.NewSourceRef(&build.Build{}) Expect(srcRef.ValidatePath(context.TODO())).To(BeNil()) }) - It("should successfully validate a build with a valid URL", func() { - srcRef := validate.NewSourcesRef(&build.Build{ + It("should successfully validate a build with source", func() { + srcRef := validate.NewSourceRef(&build.Build{ Spec: build.BuildSpec{ - Sources: []build.BuildSource{ - {Name: "name", URL: "https://github.com/shipwright-io/build"}, + Source: build.Source{ + Type: "Git", + GitSource: &build.Git{}, }, }, }) @@ -34,11 +35,11 @@ var _ = Describe("SourcesRef", func() { Expect(srcRef.ValidatePath(context.TODO())).To(BeNil()) }) - It("should fail to validate if the name is not informed", func() { - srcRef := validate.NewSourcesRef(&build.Build{ + It("should fail to validate if the type is not defined", func() { + srcRef := validate.NewSourceRef(&build.Build{ Spec: build.BuildSpec{ - Sources: []build.BuildSource{ - {Name: ""}, + Source: build.Source{ + GitSource: &build.Git{}, }, }, }) @@ -46,23 +47,12 @@ var _ = Describe("SourcesRef", func() { Expect(srcRef.ValidatePath(context.TODO())).To(HaveOccurred()) }) - It("should fail to validate if the URL is not informed", func() { - srcRef := validate.NewSourcesRef(&build.Build{ + It("should fail to validate if the type does not match the source git", func() { + srcRef := validate.NewSourceRef(&build.Build{ Spec: build.BuildSpec{ - Sources: []build.BuildSource{ - {Name: "name", URL: ""}, - }, - }, - }) - - Expect(srcRef.ValidatePath(context.TODO())).To(HaveOccurred()) - }) - - It("should fail to validate a build with an invalid URL", func() { - srcRef := validate.NewSourcesRef(&build.Build{ - Spec: build.BuildSpec{ - Sources: []build.BuildSource{ - {Name: "name", URL: "invalid URL"}, + Source: build.Source{ + Type: "OCI", + GitSource: &build.Git{}, }, }, }) diff --git a/pkg/validate/sourceurl.go b/pkg/validate/sourceurl.go index c724d423b7..888f889f1a 100644 --- a/pkg/validate/sourceurl.go +++ b/pkg/validate/sourceurl.go @@ -11,7 +11,7 @@ import ( "k8s.io/utils/pointer" "sigs.k8s.io/controller-runtime/pkg/client" - build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/ctxlog" "github.com/shipwright-io/build/pkg/git" ) @@ -31,22 +31,24 @@ func NewSourceURL(client client.Client, build *build.Build) *SourceURLRef { // that the spec.source.url exists. This validation only applies // to endpoints that do not require authentication. func (s SourceURLRef) ValidatePath(ctx context.Context) error { - if s.Build.Spec.Source.Credentials == nil && s.Build.Spec.Source.URL != nil { - switch s.Build.GetAnnotations()[build.AnnotationBuildVerifyRepository] { - case "true": - if err := git.ValidateGitURLExists(ctx, *s.Build.Spec.Source.URL); err != nil { - s.MarkBuildStatus(s.Build, build.RemoteRepositoryUnreachable, err.Error()) - return err + if s.Build.Spec.Source.Type == build.GitType { + gitSource := s.Build.Spec.Source.GitSource + if gitSource.CloneSecret == nil { + switch s.Build.GetAnnotations()[build.AnnotationBuildVerifyRepository] { + case "true": + if err := git.ValidateGitURLExists(ctx, gitSource.URL); err != nil { + s.MarkBuildStatus(s.Build, build.RemoteRepositoryUnreachable, err.Error()) + return err + } + case "", "false": + ctxlog.Info(ctx, fmt.Sprintf("the annotation %s is set to %s, nothing to do", build.AnnotationBuildVerifyRepository, s.Build.GetAnnotations()[build.AnnotationBuildVerifyRepository]), namespace, s.Build.Namespace, name, s.Build.Name) + + default: + var annoErr = fmt.Errorf("the annotation %s was not properly defined, supported values are true or false", build.AnnotationBuildVerifyRepository) + ctxlog.Error(ctx, annoErr, namespace, s.Build.Namespace, name, s.Build.Name) + s.MarkBuildStatus(s.Build, build.RemoteRepositoryUnreachable, annoErr.Error()) + return annoErr } - - case "", "false": - ctxlog.Info(ctx, fmt.Sprintf("the annotation %s is set to %s, nothing to do", build.AnnotationBuildVerifyRepository, s.Build.GetAnnotations()[build.AnnotationBuildVerifyRepository]), namespace, s.Build.Namespace, name, s.Build.Name) - - default: - var annoErr = fmt.Errorf("the annotation %s was not properly defined, supported values are true or false", build.AnnotationBuildVerifyRepository) - ctxlog.Error(ctx, annoErr, namespace, s.Build.Namespace, name, s.Build.Name) - s.MarkBuildStatus(s.Build, build.RemoteRepositoryUnreachable, annoErr.Error()) - return annoErr } } diff --git a/pkg/validate/strategies.go b/pkg/validate/strategies.go index 56a24d253a..3ecbcc2706 100644 --- a/pkg/validate/strategies.go +++ b/pkg/validate/strategies.go @@ -13,7 +13,7 @@ import ( "k8s.io/utils/pointer" "sigs.k8s.io/controller-runtime/pkg/client" - build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/ctxlog" ) diff --git a/pkg/validate/trigger.go b/pkg/validate/trigger.go index 562aafea1f..d25d39d863 100644 --- a/pkg/validate/trigger.go +++ b/pkg/validate/trigger.go @@ -7,7 +7,7 @@ import ( "context" "fmt" - build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" kerrors "k8s.io/apimachinery/pkg/util/errors" "k8s.io/utils/pointer" ) diff --git a/pkg/validate/trigger_test.go b/pkg/validate/trigger_test.go index 728e8e35d8..7d99745fbe 100644 --- a/pkg/validate/trigger_test.go +++ b/pkg/validate/trigger_test.go @@ -8,7 +8,7 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/validate" ) diff --git a/pkg/validate/validate.go b/pkg/validate/validate.go index 408fee1042..3e854c8f6c 100644 --- a/pkg/validate/validate.go +++ b/pkg/validate/validate.go @@ -11,7 +11,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" "sigs.k8s.io/controller-runtime/pkg/client" - build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + build "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/reconciler/buildrun/resources" ) @@ -23,7 +23,7 @@ const ( // SourceURL for validating the source URL in Build objects SourceURL = "sourceurl" // Sources for validating `spec.sources` entries - Sources = "sources" + Source = "source" // BuildName for validating `metadata.name` entry BuildName = "buildname" // Envs for validating `spec.env` entries @@ -63,8 +63,8 @@ func NewValidation( return &SourceURLRef{Build: build, Client: client}, nil case OwnerReferences: return &OwnerRef{Build: build, Client: client, Scheme: scheme}, nil - case Sources: - return &SourcesRef{Build: build}, nil + case Source: + return &SourceRef{Build: build}, nil case BuildName: return &BuildNameRef{Build: build}, nil case Envs: @@ -90,13 +90,13 @@ func All(ctx context.Context, validations ...BuildPath) error { // BuildRunFields runs field validations against a BuildRun to detect // disallowed field combinations func BuildRunFields(buildRun *build.BuildRun) (string, string) { - if buildRun.Spec.BuildSpec == nil && buildRun.Spec.BuildRef == nil { + if buildRun.Spec.Build.Build == nil && buildRun.Spec.Build.Name == nil { return resources.BuildRunNoRefOrSpec, "no build referenced or specified, either 'buildRef' or 'buildSpec' has to be set" } - if buildRun.Spec.BuildSpec != nil { - if buildRun.Spec.BuildRef != nil { + if buildRun.Spec.Build.Build != nil { + if buildRun.Spec.Build.Name != nil { return resources.BuildRunAmbiguousBuild, "fields 'buildRef' and 'buildSpec' are mutually exclusive" } @@ -121,7 +121,7 @@ func BuildRunFields(buildRun *build.BuildRun) (string, string) { "cannot use 'timeout' override and 'buildSpec' simultaneously" } - if buildRun.Spec.BuildSpec.Trigger != nil { + if buildRun.Spec.Build.Build.Trigger != nil { return resources.BuildRunBuildFieldOverrideForbidden, "cannot use 'triggers' override in the 'BuildRun', only allowed in the 'Build'" } diff --git a/pkg/validate/volumes.go b/pkg/validate/volumes.go index f71aaa55db..8b152cc9fc 100644 --- a/pkg/validate/volumes.go +++ b/pkg/validate/volumes.go @@ -7,16 +7,16 @@ package validate import ( "fmt" - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" ) // BuildVolumes is used to validate volumes in the Build object -func BuildVolumes(strategyVolumes []buildv1alpha1.BuildStrategyVolume, buildVolumes []buildv1alpha1.BuildVolume) (bool, buildv1alpha1.BuildReason, string) { +func BuildVolumes(strategyVolumes []buildv1beta1.BuildStrategyVolume, buildVolumes []buildv1beta1.BuildVolume) (bool, buildv1beta1.BuildReason, string) { return validateVolumes(strategyVolumes, buildVolumes) } // BuildRunVolumes is used to validate volumes in the BuildRun object -func BuildRunVolumes(strategyVolumes []buildv1alpha1.BuildStrategyVolume, buildVolumes []buildv1alpha1.BuildVolume) (bool, string, string) { +func BuildRunVolumes(strategyVolumes []buildv1beta1.BuildStrategyVolume, buildVolumes []buildv1beta1.BuildVolume) (bool, string, string) { valid, reason, msg := validateVolumes(strategyVolumes, buildVolumes) return valid, string(reason), msg } @@ -24,18 +24,18 @@ func BuildRunVolumes(strategyVolumes []buildv1alpha1.BuildStrategyVolume, buildV // validateBuildVolumes validates build overriding the build strategy volumes. in case it tries // to override the non-overridable volume, or volume that does not exist in the strategy, it is // good to fail early -func validateVolumes(strategyVolumes []buildv1alpha1.BuildStrategyVolume, buildVolumes []buildv1alpha1.BuildVolume) (bool, buildv1alpha1.BuildReason, string) { +func validateVolumes(strategyVolumes []buildv1beta1.BuildStrategyVolume, buildVolumes []buildv1beta1.BuildVolume) (bool, buildv1beta1.BuildReason, string) { strategyVolumesMap := toVolumeMap(strategyVolumes) for _, buildVolume := range buildVolumes { strategyVolume, ok := strategyVolumesMap[buildVolume.Name] if !ok { - return false, buildv1alpha1.UndefinedVolume, fmt.Sprintf("Volume %q is not defined in the Strategy", buildVolume.Name) + return false, buildv1beta1.UndefinedVolume, fmt.Sprintf("Volume %q is not defined in the Strategy", buildVolume.Name) } // nil for overridable is equal to false if strategyVolume.Overridable == nil || !*strategyVolume.Overridable { - return false, buildv1alpha1.VolumeNotOverridable, fmt.Sprintf("Volume %q is not overridable in the Strategy", buildVolume.Name) + return false, buildv1beta1.VolumeNotOverridable, fmt.Sprintf("Volume %q is not overridable in the Strategy", buildVolume.Name) } } @@ -43,8 +43,8 @@ func validateVolumes(strategyVolumes []buildv1alpha1.BuildStrategyVolume, buildV } // toVolumeMap coverts slice of build strategy volumes to map of build strategy volumes, in order to later search them quickly by name -func toVolumeMap(strategyVolumes []buildv1alpha1.BuildStrategyVolume) map[string]buildv1alpha1.BuildStrategyVolume { - res := make(map[string]buildv1alpha1.BuildStrategyVolume) +func toVolumeMap(strategyVolumes []buildv1beta1.BuildStrategyVolume) map[string]buildv1beta1.BuildStrategyVolume { + res := make(map[string]buildv1beta1.BuildStrategyVolume) for _, vol := range strategyVolumes { res[vol.Name] = vol } diff --git a/pkg/volumes/volumes.go b/pkg/volumes/volumes.go index 691fda794f..89168db1a2 100644 --- a/pkg/volumes/volumes.go +++ b/pkg/volumes/volumes.go @@ -7,7 +7,7 @@ package volumes import ( "fmt" - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" corev1 "k8s.io/api/core/v1" kerrors "k8s.io/apimachinery/pkg/util/errors" ) @@ -16,9 +16,9 @@ import ( // checks for some erroneous situations around volumes and volume mounts func TaskSpecVolumes( existingVolumeMounts map[string]bool, - strategyVolumes []buildv1alpha1.BuildStrategyVolume, - buildVolumes []buildv1alpha1.BuildVolume, - buildrunVolumes []buildv1alpha1.BuildVolume, + strategyVolumes []buildv1beta1.BuildStrategyVolume, + buildVolumes []buildv1beta1.BuildVolume, + buildrunVolumes []buildv1beta1.BuildVolume, ) ([]corev1.Volume, error) { res := []corev1.Volume{} @@ -59,7 +59,7 @@ func TaskSpecVolumes( return res, nil } -func isReadOnlyVolume(strategyVolume *buildv1alpha1.BuildStrategyVolume) bool { +func isReadOnlyVolume(strategyVolume *buildv1beta1.BuildStrategyVolume) bool { return strategyVolume.VolumeSource.ConfigMap != nil || strategyVolume.VolumeSource.Secret != nil || strategyVolume.VolumeSource.DownwardAPI != nil || @@ -69,15 +69,15 @@ func isReadOnlyVolume(strategyVolume *buildv1alpha1.BuildStrategyVolume) bool { // MergeBuildVolumes merges Build Volumes from one list into the other. It only allows to merge those that have property // Overridable set to true. In case it is empty or false, it is not allowed to be overridden, so Volume cannot be merged // Merging in this context means copying the VolumeSource from one object to the other. -func MergeBuildVolumes(into []buildv1alpha1.BuildStrategyVolume, new []buildv1alpha1.BuildVolume) ([]buildv1alpha1.BuildStrategyVolume, error) { +func MergeBuildVolumes(into []buildv1beta1.BuildStrategyVolume, new []buildv1beta1.BuildVolume) ([]buildv1beta1.BuildStrategyVolume, error) { if len(new) == 0 && len(into) == 0 { - return []buildv1alpha1.BuildStrategyVolume{}, nil + return []buildv1beta1.BuildStrategyVolume{}, nil } if len(new) == 0 { return into, nil } - mergeMap := make(map[string]buildv1alpha1.BuildStrategyVolume) + mergeMap := make(map[string]buildv1beta1.BuildStrategyVolume) var errors []error for _, vol := range into { @@ -105,7 +105,7 @@ func MergeBuildVolumes(into []buildv1alpha1.BuildStrategyVolume, new []buildv1al mergeMap[merger.Name] = original } - result := make([]buildv1alpha1.BuildStrategyVolume, 0, len(mergeMap)) + result := make([]buildv1beta1.BuildStrategyVolume, 0, len(mergeMap)) for _, v := range mergeMap { result = append(result, v) } diff --git a/pkg/volumes/volumes_test.go b/pkg/volumes/volumes_test.go index 8daafca3b5..a40ebb8c03 100644 --- a/pkg/volumes/volumes_test.go +++ b/pkg/volumes/volumes_test.go @@ -8,7 +8,7 @@ import ( "reflect" "testing" - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/volumes" corev1 "k8s.io/api/core/v1" ) @@ -55,11 +55,10 @@ func createVolumeSource(vt volumeType, vsName string) *corev1.VolumeSource { case emptyDirVT: vs = createEmptyDirVolumeSource() } - return vs } -func createBuildStrategyVolume(name string, description string, vt volumeType, vsName string, overridable bool) buildv1alpha1.BuildStrategyVolume { +func createBuildStrategyVolume(name string, description string, vt volumeType, vsName string, overridable bool) buildv1beta1.BuildStrategyVolume { vs := createVolumeSource(vt, vsName) var descr *string @@ -67,7 +66,7 @@ func createBuildStrategyVolume(name string, description string, vt volumeType, v descr = &description } - bv := buildv1alpha1.BuildStrategyVolume{ + bv := buildv1beta1.BuildStrategyVolume{ Name: name, Description: descr, VolumeSource: *vs, @@ -76,7 +75,7 @@ func createBuildStrategyVolume(name string, description string, vt volumeType, v return bv } -func createBuildStrategyVolumeEmptyOverridable(name string, description string, vt volumeType, vsName string) buildv1alpha1.BuildStrategyVolume { +func createBuildStrategyVolumeEmptyOverridable(name string, description string, vt volumeType, vsName string) buildv1beta1.BuildStrategyVolume { vs := createVolumeSource(vt, vsName) var descr *string @@ -84,7 +83,7 @@ func createBuildStrategyVolumeEmptyOverridable(name string, description string, descr = &description } - bv := buildv1alpha1.BuildStrategyVolume{ + bv := buildv1beta1.BuildStrategyVolume{ Name: name, Description: descr, VolumeSource: *vs, @@ -92,17 +91,11 @@ func createBuildStrategyVolumeEmptyOverridable(name string, description string, return bv } -func createBuildVolume(name string, description string, vt volumeType, vsName string) buildv1alpha1.BuildVolume { +func createBuildVolume(name string, vt volumeType, vsName string) buildv1beta1.BuildVolume { vs := createVolumeSource(vt, vsName) - var descr *string - if len(description) > 0 { - descr = &description - } - - bv := buildv1alpha1.BuildVolume{ + bv := buildv1beta1.BuildVolume{ Name: name, - Description: descr, VolumeSource: *vs, } return bv @@ -112,90 +105,90 @@ func TestMergeVolumes(t *testing.T) { testingData := []struct { name string - into []buildv1alpha1.BuildStrategyVolume - mergers []buildv1alpha1.BuildVolume - expected []buildv1alpha1.BuildStrategyVolume + into []buildv1beta1.BuildStrategyVolume + mergers []buildv1beta1.BuildVolume + expected []buildv1beta1.BuildStrategyVolume expectErr bool }{ { name: "both empty", - into: []buildv1alpha1.BuildStrategyVolume{}, - mergers: []buildv1alpha1.BuildVolume{}, - expected: []buildv1alpha1.BuildStrategyVolume{}, + into: []buildv1beta1.BuildStrategyVolume{}, + mergers: []buildv1beta1.BuildVolume{}, + expected: []buildv1beta1.BuildStrategyVolume{}, expectErr: false, }, { name: "mergers empty", - into: []buildv1alpha1.BuildStrategyVolume{ + into: []buildv1beta1.BuildStrategyVolume{ createBuildStrategyVolume("bvname", "bv description", "ConfigMap", "my-config", true), }, - mergers: []buildv1alpha1.BuildVolume{}, - expected: []buildv1alpha1.BuildStrategyVolume{ + mergers: []buildv1beta1.BuildVolume{}, + expected: []buildv1beta1.BuildStrategyVolume{ createBuildStrategyVolume("bvname", "bv description", "ConfigMap", "my-config", true), }, expectErr: false, }, { name: "into empty must fail", - into: []buildv1alpha1.BuildStrategyVolume{}, - mergers: []buildv1alpha1.BuildVolume{ - createBuildVolume("bvname", "bv description", "ConfigMap", "my-config"), + into: []buildv1beta1.BuildStrategyVolume{}, + mergers: []buildv1beta1.BuildVolume{ + createBuildVolume("bvname", "ConfigMap", "my-config"), }, - expected: []buildv1alpha1.BuildStrategyVolume{ + expected: []buildv1beta1.BuildStrategyVolume{ createBuildStrategyVolume("bvname", "bv description", "ConfigMap", "my-config", true), }, expectErr: true, }, { name: "override one emptyDir with secret", - into: []buildv1alpha1.BuildStrategyVolume{ + into: []buildv1beta1.BuildStrategyVolume{ createBuildStrategyVolume("bvname", "bv description", "EmptyDir", "", true), }, - mergers: []buildv1alpha1.BuildVolume{ - createBuildVolume("bvname", "bv description 2", "ConfigMap", "my-config"), + mergers: []buildv1beta1.BuildVolume{ + createBuildVolume("bvname", "ConfigMap", "my-config"), }, - expected: []buildv1alpha1.BuildStrategyVolume{ + expected: []buildv1beta1.BuildStrategyVolume{ createBuildStrategyVolume("bvname", "bv description", "ConfigMap", "my-config", true), }, expectErr: false, }, { name: "connot override - not overridable, expecting error", - into: []buildv1alpha1.BuildStrategyVolume{ + into: []buildv1beta1.BuildStrategyVolume{ createBuildStrategyVolume("bvname", "bv description", "EmptyDir", "", false), }, - mergers: []buildv1alpha1.BuildVolume{ - createBuildVolume("bvname", "bv description 2", "ConfigMap", "my-config"), + mergers: []buildv1beta1.BuildVolume{ + createBuildVolume("bvname", "ConfigMap", "my-config"), }, - expected: []buildv1alpha1.BuildStrategyVolume{ + expected: []buildv1beta1.BuildStrategyVolume{ createBuildStrategyVolume("bvname", "bv description", "ConfigMap", "my-config", true), }, expectErr: true, }, { name: "connot override - volume does not exist, must produce err", - into: []buildv1alpha1.BuildStrategyVolume{ + into: []buildv1beta1.BuildStrategyVolume{ createBuildStrategyVolume("bvname", "bv description", "EmptyDir", "", true), }, - mergers: []buildv1alpha1.BuildVolume{ - createBuildVolume("bvname2", "bv description 2", "ConfigMap", "my-config"), + mergers: []buildv1beta1.BuildVolume{ + createBuildVolume("bvname2", "ConfigMap", "my-config"), }, - expected: []buildv1alpha1.BuildStrategyVolume{ + expected: []buildv1beta1.BuildStrategyVolume{ createBuildStrategyVolume("bvname", "bv description", "EmptyDir", "", true), }, expectErr: true, }, { name: "override second", - into: []buildv1alpha1.BuildStrategyVolume{ + into: []buildv1beta1.BuildStrategyVolume{ createBuildStrategyVolume("bvname", "bv description", "EmptyDir", "", false), createBuildStrategyVolume("bvname2", "bv description 2", "ConfigMap", "config-name", true), createBuildStrategyVolume("bvname3", "bv description 3", "Secret", "very-secret-name", true), }, - mergers: []buildv1alpha1.BuildVolume{ - createBuildVolume("bvname2", "bv description 4", "Secret", "secret-name"), + mergers: []buildv1beta1.BuildVolume{ + createBuildVolume("bvname2", "Secret", "secret-name"), }, - expected: []buildv1alpha1.BuildStrategyVolume{ + expected: []buildv1beta1.BuildStrategyVolume{ createBuildStrategyVolume("bvname", "bv description", "EmptyDir", "", false), createBuildStrategyVolume("bvname2", "bv description 2", "Secret", "secret-name", true), createBuildStrategyVolume("bvname3", "bv description 3", "Secret", "very-secret-name", true), @@ -204,15 +197,15 @@ func TestMergeVolumes(t *testing.T) { }, { name: "override first", - into: []buildv1alpha1.BuildStrategyVolume{ + into: []buildv1beta1.BuildStrategyVolume{ createBuildStrategyVolume("bvname", "bv description", "EmptyDir", "", true), createBuildStrategyVolume("bvname2", "bv description 2", "ConfigMap", "config-name", false), createBuildStrategyVolume("bvname3", "bv description 3", "Secret", "very-secret-name", false), }, - mergers: []buildv1alpha1.BuildVolume{ - createBuildVolume("bvname", "bv description 4", "Secret", "secret-name"), + mergers: []buildv1beta1.BuildVolume{ + createBuildVolume("bvname", "Secret", "secret-name"), }, - expected: []buildv1alpha1.BuildStrategyVolume{ + expected: []buildv1beta1.BuildStrategyVolume{ createBuildStrategyVolume("bvname", "bv description", "Secret", "secret-name", true), createBuildStrategyVolume("bvname2", "bv description 2", "ConfigMap", "config-name", false), createBuildStrategyVolume("bvname3", "bv description 3", "Secret", "very-secret-name", false), @@ -221,15 +214,15 @@ func TestMergeVolumes(t *testing.T) { }, { name: "override third", - into: []buildv1alpha1.BuildStrategyVolume{ + into: []buildv1beta1.BuildStrategyVolume{ createBuildStrategyVolume("bvname", "bv description", "EmptyDir", "", true), createBuildStrategyVolume("bvname2", "bv description 2", "ConfigMap", "config-name", false), createBuildStrategyVolume("bvname3", "bv description 3", "Secret", "very-secret-name", true), }, - mergers: []buildv1alpha1.BuildVolume{ - createBuildVolume("bvname3", "bv description 4", "EmptyDir", ""), + mergers: []buildv1beta1.BuildVolume{ + createBuildVolume("bvname3", "EmptyDir", ""), }, - expected: []buildv1alpha1.BuildStrategyVolume{ + expected: []buildv1beta1.BuildStrategyVolume{ createBuildStrategyVolume("bvname", "bv description", "EmptyDir", "", true), createBuildStrategyVolume("bvname2", "bv description 2", "ConfigMap", "config-name", false), createBuildStrategyVolume("bvname3", "bv description 3", "EmptyDir", "", true), @@ -238,16 +231,16 @@ func TestMergeVolumes(t *testing.T) { }, { name: "override second and third", - into: []buildv1alpha1.BuildStrategyVolume{ + into: []buildv1beta1.BuildStrategyVolume{ createBuildStrategyVolume("bvname", "bv description", "EmptyDir", "", false), createBuildStrategyVolume("bvname2", "bv description 2", "ConfigMap", "config-name", true), createBuildStrategyVolume("bvname3", "bv description 3", "Secret", "very-secret-name", true), }, - mergers: []buildv1alpha1.BuildVolume{ - createBuildVolume("bvname2", "bv description 655", "Secret", "very-very-secret"), - createBuildVolume("bvname3", "bv description 4", "EmptyDir", ""), + mergers: []buildv1beta1.BuildVolume{ + createBuildVolume("bvname2", "Secret", "very-very-secret"), + createBuildVolume("bvname3", "EmptyDir", ""), }, - expected: []buildv1alpha1.BuildStrategyVolume{ + expected: []buildv1beta1.BuildStrategyVolume{ createBuildStrategyVolume("bvname", "bv description", "EmptyDir", "", false), createBuildStrategyVolume("bvname2", "bv description 2", "Secret", "very-very-secret", true), createBuildStrategyVolume("bvname3", "bv description 3", "EmptyDir", "", true), @@ -256,15 +249,15 @@ func TestMergeVolumes(t *testing.T) { }, { name: "empty overridable cant be ovirriden", - into: []buildv1alpha1.BuildStrategyVolume{ + into: []buildv1beta1.BuildStrategyVolume{ createBuildStrategyVolumeEmptyOverridable("bvname", "desc", "EmptyDir", ""), createBuildStrategyVolume("bvname2", "bv description 2", "ConfigMap", "config-name", true), }, - mergers: []buildv1alpha1.BuildVolume{ - createBuildVolume("bvname", "bv description 111", "Secret", "very-very-secret"), - createBuildVolume("bvname2", "bv description 4", "Secret", "very-secret-2"), + mergers: []buildv1beta1.BuildVolume{ + createBuildVolume("bvname", "Secret", "very-very-secret"), + createBuildVolume("bvname2", "Secret", "very-secret-2"), }, - expected: []buildv1alpha1.BuildStrategyVolume{}, + expected: []buildv1beta1.BuildStrategyVolume{}, expectErr: true, }, } @@ -309,8 +302,8 @@ func TestMergeVolumes(t *testing.T) { } } -func toVolMap(expected []buildv1alpha1.BuildStrategyVolume) map[string]buildv1alpha1.BuildStrategyVolume { - res := make(map[string]buildv1alpha1.BuildStrategyVolume) +func toVolMap(expected []buildv1beta1.BuildStrategyVolume) map[string]buildv1beta1.BuildStrategyVolume { + res := make(map[string]buildv1beta1.BuildStrategyVolume) for _, v := range expected { res[v.Name] = v diff --git a/test/data/v1beta1/build_buildah_cr_custom_context+dockerfile.yaml b/test/data/v1beta1/build_buildah_cr_custom_context+dockerfile.yaml index 84dce74654..350fea2fb9 100644 --- a/test/data/v1beta1/build_buildah_cr_custom_context+dockerfile.yaml +++ b/test/data/v1beta1/build_buildah_cr_custom_context+dockerfile.yaml @@ -5,6 +5,7 @@ metadata: name: buildah-custom-context-dockerfile spec: source: + type: Git git: url: https://github.com/shipwright-io/sample-nodejs contextDir: docker-build-renamed diff --git a/test/data/v1beta1/build_buildah_cr_local_source_upload.yaml b/test/data/v1beta1/build_buildah_cr_local_source_upload.yaml index 4a0e5f160a..d01cd89ddc 100644 --- a/test/data/v1beta1/build_buildah_cr_local_source_upload.yaml +++ b/test/data/v1beta1/build_buildah_cr_local_source_upload.yaml @@ -5,6 +5,7 @@ metadata: name: buildah-golang-build-local-source-upload spec: source: + type: Git git: url: https://github.com/shipwright-io/sample-go contextDir: docker-build diff --git a/test/data/v1beta1/build_buildah_cr_mutate.yaml b/test/data/v1beta1/build_buildah_cr_mutate.yaml index ae7cb9b5c2..6d6f8959d6 100644 --- a/test/data/v1beta1/build_buildah_cr_mutate.yaml +++ b/test/data/v1beta1/build_buildah_cr_mutate.yaml @@ -5,6 +5,7 @@ metadata: name: buildah-golang-build-mutate spec: source: + type: Git git: url: https://github.com/shipwright-io/sample-go contextDir: docker-build diff --git a/test/data/v1beta1/build_buildah_cr_private_github.yaml b/test/data/v1beta1/build_buildah_cr_private_github.yaml index 81ef768b7c..161b963e1a 100644 --- a/test/data/v1beta1/build_buildah_cr_private_github.yaml +++ b/test/data/v1beta1/build_buildah_cr_private_github.yaml @@ -5,6 +5,7 @@ metadata: name: buildah-golang-build spec: source: + type: Git git: url: git@github.com:qu1queee/newtaxi.git cloneSecret: github-ssh-all diff --git a/test/data/v1beta1/build_buildah_cr_private_gitlab.yaml b/test/data/v1beta1/build_buildah_cr_private_gitlab.yaml index 13b19a0693..ee5f5031db 100644 --- a/test/data/v1beta1/build_buildah_cr_private_gitlab.yaml +++ b/test/data/v1beta1/build_buildah_cr_private_gitlab.yaml @@ -5,6 +5,7 @@ metadata: name: buildah-golang-build spec: source: + type: Git git: url: git@gitlab.com:eduardooli/newtaxi.git strategy: diff --git a/test/data/v1beta1/build_buildkit_cr_insecure_registry.yaml b/test/data/v1beta1/build_buildkit_cr_insecure_registry.yaml index a870298db1..3634c0cfc5 100644 --- a/test/data/v1beta1/build_buildkit_cr_insecure_registry.yaml +++ b/test/data/v1beta1/build_buildkit_cr_insecure_registry.yaml @@ -5,6 +5,7 @@ metadata: name: buildkit-build spec: source: + type: Git git: url: https://github.com/shipwright-io/sample-go contextDir: docker-build diff --git a/test/data/v1beta1/build_buildpacks-v3_golang_cr.yaml b/test/data/v1beta1/build_buildpacks-v3_golang_cr.yaml index f097c9aba4..c99a500bd0 100644 --- a/test/data/v1beta1/build_buildpacks-v3_golang_cr.yaml +++ b/test/data/v1beta1/build_buildpacks-v3_golang_cr.yaml @@ -5,6 +5,7 @@ metadata: name: buildpack-golang-build spec: source: + type: Git git: url: https://github.com/shipwright-io/sample-go contextDir: source-build diff --git a/test/data/v1beta1/build_buildpacks-v3_golang_cr_env.yaml b/test/data/v1beta1/build_buildpacks-v3_golang_cr_env.yaml index 9806e5114a..739d1b6c93 100644 --- a/test/data/v1beta1/build_buildpacks-v3_golang_cr_env.yaml +++ b/test/data/v1beta1/build_buildpacks-v3_golang_cr_env.yaml @@ -5,6 +5,7 @@ metadata: name: buildpack-golang-build spec: source: + type: Git git: url: https://github.com/shipwright-io/sample-go contextDir: source-build-with-package diff --git a/test/data/v1beta1/build_buildpacks-v3_golang_delete_cr.yaml b/test/data/v1beta1/build_buildpacks-v3_golang_delete_cr.yaml index 4826426153..8a6f08b5ca 100644 --- a/test/data/v1beta1/build_buildpacks-v3_golang_delete_cr.yaml +++ b/test/data/v1beta1/build_buildpacks-v3_golang_delete_cr.yaml @@ -5,6 +5,7 @@ metadata: name: buildpack-golang-build spec: source: + type: Git git: url: https://github.com/shipwright-io/sample-go contextDir: source-build diff --git a/test/data/v1beta1/build_buildpacks-v3_java_cr.yaml b/test/data/v1beta1/build_buildpacks-v3_java_cr.yaml index 8628426e2b..d918548168 100644 --- a/test/data/v1beta1/build_buildpacks-v3_java_cr.yaml +++ b/test/data/v1beta1/build_buildpacks-v3_java_cr.yaml @@ -5,6 +5,7 @@ metadata: name: buildpack-java-build spec: source: + type: Git git: url: https://github.com/shipwright-io/sample-java contextDir: source-build diff --git a/test/data/v1beta1/build_buildpacks-v3_php_cr.yaml b/test/data/v1beta1/build_buildpacks-v3_php_cr.yaml index 4966f5b6a8..adff8c0f65 100644 --- a/test/data/v1beta1/build_buildpacks-v3_php_cr.yaml +++ b/test/data/v1beta1/build_buildpacks-v3_php_cr.yaml @@ -5,6 +5,7 @@ metadata: name: buildpack-php-build spec: source: + type: Git git: url: https://github.com/shipwright-io/sample-php contextDir: source-build diff --git a/test/data/v1beta1/build_buildpacks-v3_ruby_cr.yaml b/test/data/v1beta1/build_buildpacks-v3_ruby_cr.yaml index 440dc37c96..7a5276ab81 100644 --- a/test/data/v1beta1/build_buildpacks-v3_ruby_cr.yaml +++ b/test/data/v1beta1/build_buildpacks-v3_ruby_cr.yaml @@ -5,6 +5,7 @@ metadata: name: buildpack-ruby-build spec: source: + type: Git git: url: https://github.com/shipwright-io/sample-ruby contextDir: source-build diff --git a/test/data/v1beta1/build_kaniko_cr_advanced_dockerfile.yaml b/test/data/v1beta1/build_kaniko_cr_advanced_dockerfile.yaml index 46818a38c2..130c4c3cb7 100644 --- a/test/data/v1beta1/build_kaniko_cr_advanced_dockerfile.yaml +++ b/test/data/v1beta1/build_kaniko_cr_advanced_dockerfile.yaml @@ -5,6 +5,7 @@ metadata: name: kaniko-advanced-dockerfile spec: source: + type: Git git: url: https://github.com/shipwright-io/sample-java contextDir: docker-build diff --git a/test/data/v1beta1/build_kaniko_cr_custom_context+dockerfile.yaml b/test/data/v1beta1/build_kaniko_cr_custom_context+dockerfile.yaml index 2d6ccc5966..79d59f05f5 100644 --- a/test/data/v1beta1/build_kaniko_cr_custom_context+dockerfile.yaml +++ b/test/data/v1beta1/build_kaniko_cr_custom_context+dockerfile.yaml @@ -5,6 +5,7 @@ metadata: name: kaniko-custom-context-dockerfile spec: source: + type: Git git: url: https://github.com/shipwright-io/sample-nodejs contextDir: docker-build diff --git a/test/data/v1beta1/build_kaniko_cr_private_github.yaml b/test/data/v1beta1/build_kaniko_cr_private_github.yaml index 26fdfd6e3f..224fc53ff9 100644 --- a/test/data/v1beta1/build_kaniko_cr_private_github.yaml +++ b/test/data/v1beta1/build_kaniko_cr_private_github.yaml @@ -5,6 +5,7 @@ metadata: name: kaniko-golang-build spec: source: + type: Git git: url: git@github.com:qu1queee/newtaxi.git strategy: diff --git a/test/data/v1beta1/build_kaniko_cr_private_gitlab.yaml b/test/data/v1beta1/build_kaniko_cr_private_gitlab.yaml index a0a4c87505..77cbf1cacc 100644 --- a/test/data/v1beta1/build_kaniko_cr_private_gitlab.yaml +++ b/test/data/v1beta1/build_kaniko_cr_private_gitlab.yaml @@ -5,6 +5,7 @@ metadata: name: kaniko-golang-build spec: source: + type: Git git: url: git@gitlab.com:eduardooli/newtaxi.git strategy: diff --git a/test/data/v1beta1/build_non_existing_repo.yaml b/test/data/v1beta1/build_non_existing_repo.yaml index 6c8869fd6a..1b619e2061 100644 --- a/test/data/v1beta1/build_non_existing_repo.yaml +++ b/test/data/v1beta1/build_non_existing_repo.yaml @@ -5,6 +5,7 @@ metadata: name: build-non-existing-repo spec: source: + type: Git git: url: https://github.com/shipwright-io/sample-nodejs-no-exists strategy: diff --git a/test/data/v1beta1/build_source-to-image_cr_private_github.yaml b/test/data/v1beta1/build_source-to-image_cr_private_github.yaml index 747de724b0..9d75193c47 100644 --- a/test/data/v1beta1/build_source-to-image_cr_private_github.yaml +++ b/test/data/v1beta1/build_source-to-image_cr_private_github.yaml @@ -5,6 +5,7 @@ metadata: name: s2i-nodejs-build spec: source: + type: Git git: url: git@github.com:shipwright-io/sample-nodejs-private.git strategy: diff --git a/test/e2e/v1alpha1/common_test.go b/test/e2e/v1alpha1/common_test.go index 4c3c9ba7ce..43111cecee 100644 --- a/test/e2e/v1alpha1/common_test.go +++ b/test/e2e/v1alpha1/common_test.go @@ -6,6 +6,7 @@ package e2e_test import ( "bytes" + "context" "encoding/json" "fmt" "io" @@ -16,15 +17,18 @@ import ( . "github.com/onsi/gomega" knativeapis "knative.dev/pkg/apis" + "sigs.k8s.io/controller-runtime/pkg/client" corev1 "k8s.io/api/core/v1" + apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/rand" buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" - "github.com/shipwright-io/build/pkg/reconciler/buildrun/resources" + "github.com/shipwright-io/build/pkg/ctxlog" + resources "github.com/shipwright-io/build/pkg/reconciler/buildrun/resources" utils "github.com/shipwright-io/build/test/utils/v1alpha1" ) @@ -143,7 +147,7 @@ func retrieveBuildAndBuildRun(testBuild *utils.TestBuild, namespace string, buil } var build buildv1alpha1.Build - if err := resources.GetBuildObject(testBuild.Context, testBuild.ControllerRuntimeClient, buildRun, &build); err != nil { + if err := GetBuildObject(testBuild.Context, testBuild.ControllerRuntimeClient, buildRun, &build); err != nil { Logf("Failed to get Build from BuildRun %s: %s", buildRunName, err) return nil, buildRun, err } @@ -246,3 +250,51 @@ func printTestFailureDebugInfo(testBuild *utils.TestBuild, namespace string, bui } } } + +// GetBuildObject retrieves an existing Build based on a name and namespace +func GetBuildObject(ctx context.Context, client client.Client, buildRun *buildv1alpha1.BuildRun, build *buildv1alpha1.Build) error { + // Option #1: BuildRef is specified + // An actual Build resource is specified by name and needs to be looked up in the cluster. + if buildRun.Spec.BuildRef.Name != "" { + err := client.Get(ctx, types.NamespacedName{Name: buildRun.Spec.BuildName(), Namespace: buildRun.Namespace}, build) + if apierrors.IsNotFound(err) { + // stop reconciling and mark the BuildRun as Failed + // we only reconcile again if the status.Update call fails + if updateErr := UpdateConditionWithFalseStatus(ctx, client, buildRun, fmt.Sprintf("build.shipwright.io %q not found", buildRun.Spec.BuildName()), resources.ConditionBuildNotFound); updateErr != nil { + return resources.HandleError("build object not found", err, updateErr) + } + } + + return err + } + + // Option #2: BuildSpec is specified + // The build specification is embedded in the BuildRun itself, create a transient Build resource. + if buildRun.Spec.BuildSpec != nil { + build.Name = "" + build.Namespace = buildRun.Namespace + build.Status = buildv1alpha1.BuildStatus{} + buildRun.Spec.BuildSpec.DeepCopyInto(&build.Spec) + return nil + } + + // Bail out hard in case of an invalid state + return fmt.Errorf("invalid BuildRun resource that neither has a BuildRef nor an embedded BuildSpec") +} + +func UpdateConditionWithFalseStatus(ctx context.Context, client client.Client, buildRun *buildv1alpha1.BuildRun, errorMessage string, reason string) error { + now := metav1.Now() + buildRun.Status.CompletionTime = &now + buildRun.Status.SetCondition(&buildv1alpha1.Condition{ + LastTransitionTime: now, + Type: buildv1alpha1.Succeeded, + Status: corev1.ConditionFalse, + Reason: reason, + Message: errorMessage, + }) + ctxlog.Debug(ctx, "updating buildRun status", "namespace", buildRun.Namespace, "name", buildRun.Name, "reason", reason) + if err := client.Status().Update(ctx, buildRun); err != nil { + return err + } + return nil +} diff --git a/test/e2e/v1beta1/common_suite_test.go b/test/e2e/v1beta1/common_suite_test.go index ac71a8c8b9..036ddbe746 100644 --- a/test/e2e/v1beta1/common_suite_test.go +++ b/test/e2e/v1beta1/common_suite_test.go @@ -75,10 +75,16 @@ func (b *buildPrototype) SourceCredentials(name string) *buildPrototype { return b } +func (b *buildPrototype) SourceType(sourceType string) *buildPrototype { + b.build.Spec.Source.Type = buildv1beta1.BuildSourceType(sourceType) + return b +} + func (b *buildPrototype) SourceGit(repository string) *buildPrototype { if b.build.Spec.Source.GitSource == nil { b.build.Spec.Source.GitSource = &buildv1beta1.Git{} } + b.build.Spec.Source.Type = buildv1beta1.GitType b.build.Spec.Source.GitSource.URL = repository b.build.Spec.Source.OCIArtifact = nil return b diff --git a/test/e2e/v1beta1/common_test.go b/test/e2e/v1beta1/common_test.go index 165119e559..fd317de76b 100644 --- a/test/e2e/v1beta1/common_test.go +++ b/test/e2e/v1beta1/common_test.go @@ -19,12 +19,10 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/rand" - buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/reconciler/buildrun/resources" utils "github.com/shipwright-io/build/test/utils/v1beta1" @@ -138,38 +136,20 @@ 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) { - buildRun, err := testBuild.LookupBuildRun(types.NamespacedName{Name: buildRunName, Namespace: namespace}) + var build *buildv1beta1.Build + + buildrun, err := testBuild.LookupBuildRun(types.NamespacedName{Name: buildRunName, Namespace: namespace}) if err != nil { Logf("Failed to get BuildRun %q: %s", buildRunName, err) return nil, nil, err } - var alphaBuild buildv1alpha1.Build - var obj unstructured.Unstructured - - buildRun.ConvertTo(testBuild.Context, &obj) - jsonData, err := json.Marshal(obj.Object) - if err != nil { - Logf("Failed to convert the buildRun to v1alpha1: %s", err) - } - - var alphaBuildRun buildv1alpha1.BuildRun - json.Unmarshal(jsonData, &alphaBuildRun) - - if err := resources.GetBuildObject(testBuild.Context, testBuild.ControllerRuntimeClient, &alphaBuildRun, &alphaBuild); err != nil { + if err := resources.GetBuildObject(testBuild.Context, testBuild.ControllerRuntimeClient, buildrun, build); err != nil { Logf("Failed to get Build from BuildRun %s: %s", buildRunName, err) - return nil, buildRun, err - } - - alphaBuild.ConvertTo(testBuild.Context, &obj) - jsonData, err = json.Marshal(obj.Object) - if err != nil { - Logf("Failed to convert the build to v1beta1: %s", err) + return nil, buildrun, err } - var betaBuild buildv1beta1.Build - json.Unmarshal(jsonData, &betaBuild) - return &betaBuild, buildRun, nil + return build, buildrun, nil } // printTestFailureDebugInfo will output the status of Build, BuildRun, TaskRun and Pod, also print logs of Pod diff --git a/test/integration/build_to_buildruns_test.go b/test/integration/build_to_buildruns_test.go index 104441f8f8..1ffa0fd20a 100644 --- a/test/integration/build_to_buildruns_test.go +++ b/test/integration/build_to_buildruns_test.go @@ -5,7 +5,6 @@ package integration_test import ( - "fmt" "strings" corev1 "k8s.io/api/core/v1" @@ -14,18 +13,17 @@ import ( . "github.com/onsi/gomega" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" - "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" - test "github.com/shipwright-io/build/test/v1alpha1_samples" + "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 *v1alpha1.ClusterBuildStrategy - buildObject *v1alpha1.Build - buildRunObject *v1alpha1.BuildRun + cbsObject *v1beta1.ClusterBuildStrategy + buildObject *v1beta1.Build + buildRunObject *v1beta1.BuildRun buildSample []byte buildRunSample []byte ) @@ -84,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(v1alpha1.Succeeded).Status).To(Equal(corev1.ConditionFalse)) - Expect(br.Status.GetCondition(v1alpha1.Succeeded).Reason).To(Equal("BuildRunTimeout")) - Expect(br.Status.GetCondition(v1alpha1.Succeeded).Message).To(ContainSubstring("failed to finish within")) + 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")) }) }) @@ -108,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(v1alpha1.Succeeded).Status).To(Equal(corev1.ConditionFalse)) - Expect(br.Status.GetCondition(v1alpha1.Succeeded).Reason).To(Equal("BuildRunTimeout")) - Expect(br.Status.GetCondition(v1alpha1.Succeeded).Message).To(ContainSubstring("failed to finish within")) + 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")) }) It("should be able to override the build output", func() { @@ -194,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(v1alpha1.Succeeded).Type).To(Equal(v1alpha1.Succeeded)) - Expect(br.Status.GetCondition(v1alpha1.Succeeded).Status).To(Equal(corev1.ConditionUnknown)) - Expect(br.Status.GetCondition(v1alpha1.Succeeded).Reason).To( + 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( // BuildRun reason can be ExceededNodeResources // if the Tekton TaskRun Pod is queued due to // insufficient cluster resources. @@ -226,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(v1alpha1.Succeeded).Status).To(Equal(corev1.ConditionFalse)) - Expect(br.Status.GetCondition(v1alpha1.Succeeded).Reason).To(Equal("BuildNotFound")) - Expect(br.Status.GetCondition(v1alpha1.Succeeded).Message).To(ContainSubstring("not found")) + 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")) }) }) @@ -252,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(v1alpha1.Succeeded).Status).To(Equal(corev1.ConditionFalse)) - Expect(br.Status.GetCondition(v1alpha1.Succeeded).Reason).To(Equal("BuildRegistrationFailed")) - Expect(br.Status.GetCondition(v1alpha1.Succeeded).Message).To(ContainSubstring("Build is not registered correctly")) + 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")) }) }) @@ -284,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(v1alpha1.Succeeded).Status).To(Equal(corev1.ConditionFalse)) - Expect(br.Status.GetCondition(v1alpha1.Succeeded).Reason).To(Equal("BuildNotFound")) - Expect(br.Status.GetCondition(v1alpha1.Succeeded).Message).To(ContainSubstring("not found")) + 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")) }) }) @@ -382,8 +380,7 @@ var _ = Describe("Integration tests Build and BuildRuns", func() { }) - It("does not deletes the buildrun if the annotation is changed", func() { - + It("does not deletes the buildrun if retention atBuildDeletion is changed", func() { Expect(tb.CreateBuild(buildObject)).To(BeNil()) buildObject, err = tb.GetBuildTillValidation(buildObject.Name) @@ -402,7 +399,7 @@ var _ = Describe("Integration tests Build and BuildRuns", func() { Expect(err).To(BeNil()) // we modify the annotation so automatic delete does not take place - data := []byte(fmt.Sprintf(`{"metadata":{"annotations":{"%s":"false"}}}`, v1alpha1.AnnotationBuildRunDeletion)) + data := []byte(`{"spec":{"retention":{"atBuildDeletion":false}}}`) _, err = tb.PatchBuild(BUILD+tb.Namespace, data) Expect(err).To(BeNil()) @@ -414,7 +411,8 @@ var _ = Describe("Integration tests Build and BuildRuns", func() { Expect(ownerReferenceNames(br.OwnerReferences)).ShouldNot(ContainElement(buildObject.Name)) }) - It("does not deletes the buildrun if the annotation is removed", func() { + + It("does not deletes the buildrun if retention atBuildDeletion is removed", func() { Expect(tb.CreateBuild(buildObject)).To(BeNil()) @@ -433,9 +431,11 @@ var _ = Describe("Integration tests Build and BuildRuns", func() { _, err = tb.GetBRTillStartTime(autoDeleteBuildRun.Name) Expect(err).To(BeNil()) - // we remove the annotation so automatic delete does not take place, "/" is escaped by "~1" in a JSON pointer - data := []byte(fmt.Sprintf(`[{"op":"remove","path":"/metadata/annotations/%s"}]`, strings.ReplaceAll(v1alpha1.AnnotationBuildRunDeletion, "/", "~1"))) - _, err = tb.PatchBuildWithPatchType(BUILD+tb.Namespace, data, types.JSONPatchType) + buildObject.Spec.Retention = nil + err = tb.UpdateBuild(buildObject) + Expect(err).To(BeNil()) + + buildObject, err = tb.GetBuildTillValidation(buildObject.Name) Expect(err).To(BeNil()) err = tb.DeleteBuild(BUILD + tb.Namespace) @@ -446,6 +446,7 @@ var _ = Describe("Integration tests Build and BuildRuns", func() { Expect(ownerReferenceNames(br.OwnerReferences)).ShouldNot(ContainElement(buildObject.Name)) }) + It("does delete the buildrun after several modifications of the annotation", func() { Expect(tb.CreateBuild(buildObject)).To(BeNil()) @@ -463,25 +464,25 @@ var _ = Describe("Integration tests Build and BuildRuns", func() { Expect(tb.CreateBR(autoDeleteBuildRun)).To(BeNil()) // we modify the annotation for the automatic deletion to not take place - data := []byte(fmt.Sprintf(`{"metadata":{"annotations":{"%s":"false"}}}`, v1alpha1.AnnotationBuildRunDeletion)) + data := []byte(`{"spec":{"retention":{"atBuildDeletion":false}}}`) _, err = tb.PatchBuild(BUILD+tb.Namespace, data) Expect(err).To(BeNil()) patchedBuild, err := tb.GetBuild(BUILD + tb.Namespace) Expect(err).To(BeNil()) - Expect(patchedBuild.Annotations[v1alpha1.AnnotationBuildRunDeletion]).To(Equal("false")) + Expect(*patchedBuild.Spec.Retention.AtBuildDeletion).To(Equal(false)) _, err = tb.GetBRTillStartTime(autoDeleteBuildRun.Name) Expect(err).To(BeNil()) // we modify the annotation one more time, to validate that the build should be deleted this time - data = []byte(fmt.Sprintf(`{"metadata":{"annotations":{"%s":"true"}}}`, v1alpha1.AnnotationBuildRunDeletion)) + data = []byte(`{"spec":{"retention":{"atBuildDeletion":true}}}`) _, err = tb.PatchBuild(BUILD+tb.Namespace, data) Expect(err).To(BeNil()) patchedBuild, err = tb.GetBuild(BUILD + tb.Namespace) Expect(err).To(BeNil()) - Expect(patchedBuild.Annotations[v1alpha1.AnnotationBuildRunDeletion]).To(Equal("true")) + Expect(*patchedBuild.Spec.Retention.AtBuildDeletion).To(Equal(true)) br, err := tb.GetBRTillOwner(BUILDRUN+tb.Namespace, buildObject.Name) Expect(err).To(BeNil()) @@ -510,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(v1alpha1.BuildNameInvalid)) + Expect(*buildObject.Status.Reason).To(Equal(v1beta1.BuildNameInvalid)) Expect(*buildObject.Status.Message).To(ContainSubstring("must be no more than 63 characters")) }) }) @@ -536,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(v1alpha1.SucceedStatus)) - Expect(*buildObject.Status.Message).To(Equal(v1alpha1.AllValidationsSucceeded)) + Expect(*buildObject.Status.Reason).To(Equal(v1beta1.SucceedStatus)) + Expect(*buildObject.Status.Message).To(Equal(v1beta1.AllValidationsSucceeded)) }) }) }) diff --git a/test/integration/build_to_git_test.go b/test/integration/build_to_git_test.go index 71add4753b..5fb1f74a12 100644 --- a/test/integration/build_to_git_test.go +++ b/test/integration/build_to_git_test.go @@ -7,19 +7,17 @@ package integration_test import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - + "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" - - "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" - test "github.com/shipwright-io/build/test/v1alpha1_samples" ) var _ = Describe("Integration tests Build and referenced Source url", func() { var ( - cbsObject *v1alpha1.ClusterBuildStrategy - buildObject *v1alpha1.Build + cbsObject *v1beta1.ClusterBuildStrategy + buildObject *v1beta1.Build ) // Load the ClusterBuildStrategies before each test case BeforeEach(func() { @@ -49,7 +47,12 @@ 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.URL = pointer.String("http://github.com/shipwright-io/sample-go") + buildObject.Spec.Source = v1beta1.Source{ + Type: v1beta1.GitType, + GitSource: &v1beta1.Git{ + URL: "http://github.com/shipwright-io/sample-go", + }, + } Expect(tb.CreateBuild(buildObject)).To(BeNil()) @@ -57,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(v1alpha1.SucceedStatus)) - Expect(*buildObject.Status.Message).To(Equal(v1alpha1.AllValidationsSucceeded)) + Expect(*buildObject.Status.Reason).To(Equal(v1beta1.SucceedStatus)) + Expect(*buildObject.Status.Message).To(Equal(v1beta1.AllValidationsSucceeded)) }) }) @@ -74,7 +77,12 @@ var _ = Describe("Integration tests Build and referenced Source url", func() { ) Expect(err).To(BeNil()) - buildObject.Spec.Source.URL = pointer.String("http://github.com/shipwright-io/sample-go-fake") + buildObject.Spec.Source = v1beta1.Source{ + Type: v1beta1.GitType, + GitSource: &v1beta1.Git{ + URL: "http://github.com/shipwright-io/sample-go-fake", + }, + } Expect(tb.CreateBuild(buildObject)).To(BeNil()) // wait until the Build finish the validation @@ -82,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(v1alpha1.SucceedStatus)) - Expect(*buildObject.Status.Message).To(Equal(v1alpha1.AllValidationsSucceeded)) + Expect(*buildObject.Status.Reason).To(Equal(v1beta1.SucceedStatus)) + Expect(*buildObject.Status.Message).To(Equal(v1beta1.AllValidationsSucceeded)) }) }) @@ -100,7 +108,12 @@ 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.URL = pointer.String("https://github.com/shipwright-io/sample-go") + buildObject.Spec.Source = v1beta1.Source{ + Type: v1beta1.GitType, + GitSource: &v1beta1.Git{ + URL: "https://github.com/shipwright-io/sample-go", + }, + } Expect(tb.CreateBuild(buildObject)).To(BeNil()) @@ -108,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(v1alpha1.SucceedStatus)) - Expect(*buildObject.Status.Message).To(Equal(v1alpha1.AllValidationsSucceeded)) + Expect(*buildObject.Status.Reason).To(Equal(v1beta1.SucceedStatus)) + Expect(*buildObject.Status.Message).To(Equal(v1beta1.AllValidationsSucceeded)) }) }) @@ -125,7 +138,12 @@ var _ = Describe("Integration tests Build and referenced Source url", func() { ) Expect(err).To(BeNil()) - buildObject.Spec.Source.URL = pointer.String("https://github.com/shipwright-io/sample-go-fake") + buildObject.Spec.Source = v1beta1.Source{ + Type: v1beta1.GitType, + GitSource: &v1beta1.Git{ + URL: "https://github.com/shipwright-io/sample-go-fake", + }, + } Expect(tb.CreateBuild(buildObject)).To(BeNil()) // wait until the Build finish the validation @@ -133,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(v1alpha1.SucceedStatus)) - Expect(*buildObject.Status.Message).To(Equal(v1alpha1.AllValidationsSucceeded)) + Expect(*buildObject.Status.Reason).To(Equal(v1beta1.SucceedStatus)) + Expect(*buildObject.Status.Message).To(Equal(v1beta1.AllValidationsSucceeded)) }) }) @@ -151,7 +169,12 @@ 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.URL = pointer.String("foobar") + buildObject.Spec.Source = v1beta1.Source{ + Type: v1beta1.GitType, + GitSource: &v1beta1.Git{ + URL: "foobar", + }, + } Expect(tb.CreateBuild(buildObject)).To(BeNil()) @@ -160,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(v1alpha1.RemoteRepositoryUnreachable)) + Expect(*buildObject.Status.Reason).To(Equal(v1beta1.RemoteRepositoryUnreachable)) Expect(*buildObject.Status.Message).To(Equal("invalid source url")) }) }) @@ -178,7 +201,12 @@ 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.URL = pointer.String("foobar") + buildObject.Spec.Source = v1beta1.Source{ + Type: v1beta1.GitType, + GitSource: &v1beta1.Git{ + URL: "foobar", + }, + } Expect(tb.CreateBuild(buildObject)).To(BeNil()) // wait until the Build finish the validation @@ -186,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(v1alpha1.SucceedStatus)) - Expect(*buildObject.Status.Message).To(Equal(v1alpha1.AllValidationsSucceeded)) + Expect(*buildObject.Status.Reason).To(Equal(v1beta1.SucceedStatus)) + Expect(*buildObject.Status.Message).To(Equal(v1beta1.AllValidationsSucceeded)) }) }) @@ -204,7 +232,12 @@ 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.URL = pointer.String("https://github.yourco.com/org/build-fake") + buildObject.Spec.Source = v1beta1.Source{ + Type: v1beta1.GitType, + GitSource: &v1beta1.Git{ + URL: "https://github.yourco.com/org/build-fake", + }, + } Expect(tb.CreateBuild(buildObject)).To(BeNil()) @@ -214,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(v1alpha1.RemoteRepositoryUnreachable)) + Expect(*buildObject.Status.Reason).To(Equal(v1beta1.RemoteRepositoryUnreachable)) Expect(*buildObject.Status.Message).To(ContainSubstring("no such host")) }) @@ -230,10 +263,15 @@ 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.URL = pointer.String("https://github.yourco.com/org/build-fake") - buildObject.Spec.Source.Credentials = &corev1.LocalObjectReference{Name: "foobar"} - - sampleSecret := tb.Catalog.SecretWithAnnotation(buildObject.Spec.Source.Credentials.Name, buildObject.Namespace) + buildObject.Spec.Source = v1beta1.Source{ + Type: v1beta1.GitType, + GitSource: &v1beta1.Git{ + URL: "https://github.yourco.com/org/build-fake", + CloneSecret: pointer.String("foobar"), + }, + } + + sampleSecret := tb.Catalog.SecretWithAnnotation(*buildObject.Spec.Source.GitSource.CloneSecret, buildObject.Namespace) Expect(tb.CreateSecret(sampleSecret)).To(BeNil()) Expect(tb.CreateBuild(buildObject)).To(BeNil()) @@ -244,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(v1alpha1.SucceedStatus)) - Expect(*buildObject.Status.Message).To(Equal(v1alpha1.AllValidationsSucceeded)) + Expect(*buildObject.Status.Reason).To(Equal(v1beta1.SucceedStatus)) + Expect(*buildObject.Status.Message).To(Equal(v1beta1.AllValidationsSucceeded)) }) }) @@ -262,7 +300,12 @@ 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.URL = pointer.String("git@github.com:shipwright-io/build-fake.git") + buildObject.Spec.Source = v1beta1.Source{ + Type: v1beta1.GitType, + GitSource: &v1beta1.Git{ + URL: "git@github.com:shipwright-io/build-fake.git", + }, + } Expect(tb.CreateBuild(buildObject)).To(BeNil()) @@ -272,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(v1alpha1.RemoteRepositoryUnreachable)) + Expect(*buildObject.Status.Reason).To(Equal(v1beta1.RemoteRepositoryUnreachable)) Expect(*buildObject.Status.Message).To(Equal("the source url requires authentication")) }) }) @@ -290,7 +333,12 @@ 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.URL = pointer.String("ssh://github.com/shipwright-io/build-fake.git") + buildObject.Spec.Source = v1beta1.Source{ + Type: v1beta1.GitType, + GitSource: &v1beta1.Git{ + URL: "ssh://github.com/shipwright-io/build-fake.git", + }, + } Expect(tb.CreateBuild(buildObject)).To(BeNil()) @@ -300,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(v1alpha1.RemoteRepositoryUnreachable)) + Expect(*buildObject.Status.Reason).To(Equal(v1beta1.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 dcb476ecaf..4cb0efb714 100644 --- a/test/integration/build_to_secrets_test.go +++ b/test/integration/build_to_secrets_test.go @@ -9,16 +9,16 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" - test "github.com/shipwright-io/build/test/v1alpha1_samples" + "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + test "github.com/shipwright-io/build/test/v1beta1_samples" corev1 "k8s.io/api/core/v1" ) var _ = Describe("Integration tests Build and referenced Secrets", func() { var ( - cbsObject *v1alpha1.ClusterBuildStrategy - buildObject *v1alpha1.Build + cbsObject *v1beta1.ClusterBuildStrategy + buildObject *v1beta1.Build ) // Load the ClusterBuildStrategies before each test case BeforeEach(func() { @@ -47,7 +47,7 @@ var _ = Describe("Integration tests Build and referenced Secrets", func() { ) Expect(err).To(BeNil()) - sampleSecret := tb.Catalog.SecretWithAnnotation(buildObject.Spec.Output.Credentials.Name, buildObject.Namespace) + sampleSecret := tb.Catalog.SecretWithAnnotation(*buildObject.Spec.Output.PushSecret, buildObject.Namespace) Expect(tb.CreateSecret(sampleSecret)).To(BeNil()) @@ -57,17 +57,17 @@ 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(v1alpha1.SucceedStatus)) + Expect(*buildObject.Status.Reason).To(Equal(v1beta1.SucceedStatus)) // delete a secret - Expect(tb.DeleteSecret(buildObject.Spec.Output.Credentials.Name)).To(BeNil()) + Expect(tb.DeleteSecret(*buildObject.Spec.Output.PushSecret)).To(BeNil()) // assert that the validation happened one more time 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(v1alpha1.SpecOutputSecretRefNotFound)) - Expect(*buildObject.Status.Message).To(Equal(fmt.Sprintf("referenced secret %s not found", buildObject.Spec.Output.Credentials.Name))) + Expect(*buildObject.Status.Reason).To(Equal(v1beta1.SpecOutputSecretRefNotFound)) + Expect(*buildObject.Status.Message).To(Equal(fmt.Sprintf("referenced secret %s not found", *buildObject.Spec.Output.PushSecret))) }) It("should validate when a missing secret is recreated", func() { @@ -86,10 +86,10 @@ 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(v1alpha1.SpecOutputSecretRefNotFound)) - Expect(*buildObject.Status.Message).To(Equal(fmt.Sprintf("referenced secret %s not found", buildObject.Spec.Output.Credentials.Name))) + Expect(*buildObject.Status.Reason).To(Equal(v1beta1.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.Credentials.Name, buildObject.Namespace) + sampleSecret := tb.Catalog.SecretWithAnnotation(*buildObject.Spec.Output.PushSecret, buildObject.Namespace) // generate resources Expect(tb.CreateSecret(sampleSecret)).To(BeNil()) @@ -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(v1alpha1.SucceedStatus)) + Expect(*buildObject.Status.Reason).To(Equal(v1beta1.SucceedStatus)) }) }) @@ -114,7 +114,7 @@ var _ = Describe("Integration tests Build and referenced Secrets", func() { ) Expect(err).To(BeNil()) - sampleSecret := tb.Catalog.SecretWithoutAnnotation(buildObject.Spec.Output.Credentials.Name, buildObject.Namespace) + sampleSecret := tb.Catalog.SecretWithoutAnnotation(*buildObject.Spec.Output.PushSecret, buildObject.Namespace) // generate resources Expect(tb.CreateSecret(sampleSecret)).To(BeNil()) @@ -124,10 +124,10 @@ 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(v1alpha1.SucceedStatus)) + Expect(*buildObject.Status.Reason).To(Equal(v1beta1.SucceedStatus)) // delete a secret - Expect(tb.DeleteSecret(buildObject.Spec.Output.Credentials.Name)).To(BeNil()) + Expect(tb.DeleteSecret(*buildObject.Spec.Output.PushSecret)).To(BeNil()) // assert that the validation happened one more time buildObject, err = tb.GetBuild(buildName) @@ -151,10 +151,10 @@ 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(v1alpha1.SpecOutputSecretRefNotFound)) - Expect(*buildObject.Status.Message).To(Equal(fmt.Sprintf("referenced secret %s not found", buildObject.Spec.Output.Credentials.Name))) + Expect(*buildObject.Status.Reason).To(Equal(v1beta1.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.Credentials.Name, buildObject.Namespace) + sampleSecret := tb.Catalog.SecretWithoutAnnotation(*buildObject.Spec.Output.PushSecret, buildObject.Namespace) // generate resources Expect(tb.CreateSecret(sampleSecret)).To(BeNil()) @@ -163,8 +163,8 @@ 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(v1alpha1.SpecOutputSecretRefNotFound)) - Expect(*buildObject.Status.Message).To(Equal(fmt.Sprintf("referenced secret %s not found", buildObject.Spec.Output.Credentials.Name))) + Expect(*buildObject.Status.Reason).To(Equal(v1beta1.SpecOutputSecretRefNotFound)) + Expect(*buildObject.Status.Message).To(Equal(fmt.Sprintf("referenced secret %s not found", *buildObject.Spec.Output.PushSecret))) }) It("should validate when a missing secret is recreated with annotation", func() { @@ -183,29 +183,29 @@ 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(v1alpha1.SpecOutputSecretRefNotFound)) + Expect(*buildObject.Status.Reason).To(Equal(v1beta1.SpecOutputSecretRefNotFound)) Expect(*buildObject.Status.Message).To(Equal(fmt.Sprintf("referenced secret %s not found", "fake-secret"))) - sampleSecret := tb.Catalog.SecretWithoutAnnotation(buildObject.Spec.Output.Credentials.Name, buildObject.Namespace) + sampleSecret := tb.Catalog.SecretWithoutAnnotation(*buildObject.Spec.Output.PushSecret, buildObject.Namespace) // generate resources Expect(tb.CreateSecret(sampleSecret)).To(BeNil()) // validate build status again Expect(*buildObject.Status.Registered).To(Equal(corev1.ConditionFalse)) - Expect(*buildObject.Status.Reason).To(Equal(v1alpha1.SpecOutputSecretRefNotFound)) + Expect(*buildObject.Status.Reason).To(Equal(v1beta1.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"}}}`, v1alpha1.AnnotationBuildRefSecret)) + data := []byte(fmt.Sprintf(`{"metadata":{"annotations":{"%s":"true"}}}`, v1beta1.AnnotationBuildRefSecret)) - _, err = tb.PatchSecret(buildObject.Spec.Output.Credentials.Name, data) + _, err = tb.PatchSecret(*buildObject.Spec.Output.PushSecret, data) Expect(err).To(BeNil()) // // assert that the validation happened one more time 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(v1alpha1.SucceedStatus)) + Expect(*buildObject.Status.Reason).To(Equal(v1beta1.SucceedStatus)) Expect(*buildObject.Status.Message).To(Equal("all validations succeeded")) }) }) @@ -222,7 +222,7 @@ var _ = Describe("Integration tests Build and referenced Secrets", func() { ) Expect(err).To(BeNil()) - sampleSecret := tb.Catalog.SecretWithAnnotation(buildObject.Spec.Source.Credentials.Name, buildObject.Namespace) + sampleSecret := tb.Catalog.SecretWithAnnotation(*buildObject.Spec.Source.GitSource.CloneSecret, buildObject.Namespace) Expect(tb.CreateSecret(sampleSecret)).To(BeNil()) @@ -232,18 +232,18 @@ 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(v1alpha1.SucceedStatus)) + Expect(*buildObject.Status.Reason).To(Equal(v1beta1.SucceedStatus)) Expect(*buildObject.Status.Message).To(Equal("all validations succeeded")) // delete a secret - Expect(tb.DeleteSecret(buildObject.Spec.Source.Credentials.Name)).To(BeNil()) + Expect(tb.DeleteSecret(*buildObject.Spec.Source.GitSource.CloneSecret)).To(BeNil()) // assert that the validation happened one more time 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(v1alpha1.SpecSourceSecretRefNotFound)) - Expect(*buildObject.Status.Message).To(Equal(fmt.Sprintf("referenced secret %s not found", buildObject.Spec.Source.Credentials.Name))) + Expect(*buildObject.Status.Reason).To(Equal(v1beta1.SpecSourceSecretRefNotFound)) + Expect(*buildObject.Status.Message).To(Equal(fmt.Sprintf("referenced secret %s not found", *buildObject.Spec.Source.GitSource.CloneSecret))) }) It("should validate when a missing secret is recreated", func() { @@ -265,7 +265,7 @@ var _ = Describe("Integration tests Build and referenced Secrets", func() { // Status reason sometimes returns message "there are no secrets in namespace..." // Expect(buildObject.Status.Reason).To(Equal(fmt.Sprintf("secret %s does not exist", buildObject.Spec.Source.Credentials.Name))) - sampleSecret := tb.Catalog.SecretWithAnnotation(buildObject.Spec.Source.Credentials.Name, buildObject.Namespace) + sampleSecret := tb.Catalog.SecretWithAnnotation(*buildObject.Spec.Source.GitSource.CloneSecret, buildObject.Namespace) // generate resources Expect(tb.CreateSecret(sampleSecret)).To(BeNil()) @@ -274,151 +274,10 @@ 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(v1alpha1.SucceedStatus)) + Expect(*buildObject.Status.Reason).To(Equal(v1beta1.SucceedStatus)) }) }) - Context("when a build reference a secret with annotations for the spec builder", func() { - It("should validate the Build after secret deletion", func() { - - // populate Build related vars - buildName := BUILD + tb.Namespace - buildObject, err = tb.Catalog.LoadBuildWithNameAndStrategy( - buildName, - STRATEGY+tb.Namespace, - []byte(test.BuildWithBuilderRefSecret), - ) - Expect(err).To(BeNil()) - - sampleSecret := tb.Catalog.SecretWithAnnotation(buildObject.Spec.Builder.Credentials.Name, buildObject.Namespace) - - Expect(tb.CreateSecret(sampleSecret)).To(BeNil()) - - Expect(tb.CreateBuild(buildObject)).To(BeNil()) - - // wait until the Build finish the validation - buildObject, err := tb.GetBuildTillValidation(buildName) - Expect(err).To(BeNil()) - Expect(*buildObject.Status.Registered).To(Equal(corev1.ConditionTrue)) - Expect(*buildObject.Status.Reason).To(Equal(v1alpha1.SucceedStatus)) - - // delete a secret - Expect(tb.DeleteSecret(buildObject.Spec.Builder.Credentials.Name)).To(BeNil()) - - // assert that the validation happened one more time - 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(v1alpha1.SpecBuilderSecretRefNotFound)) - Expect(*buildObject.Status.Message).To(Equal(fmt.Sprintf("referenced secret %s not found", buildObject.Spec.Builder.Credentials.Name))) - }) - - It("should validate when a missing secret is recreated", func() { - // populate Build related vars - buildName := BUILD + tb.Namespace - buildObject, err = tb.Catalog.LoadBuildWithNameAndStrategy( - buildName, - STRATEGY+tb.Namespace, - []byte(test.BuildWithBuilderRefSecret), - ) - Expect(err).To(BeNil()) - - Expect(tb.CreateBuild(buildObject)).To(BeNil()) - - // wait until the Build finish the validation - buildObject, err := tb.GetBuildTillValidation(buildName) - Expect(err).To(BeNil()) - Expect(*buildObject.Status.Registered).To(Equal(corev1.ConditionFalse)) - Expect(*buildObject.Status.Reason).To(Equal(v1alpha1.SpecBuilderSecretRefNotFound)) - Expect(*buildObject.Status.Message).To(Equal(fmt.Sprintf("referenced secret %s not found", buildObject.Spec.Builder.Credentials.Name))) - - sampleSecret := tb.Catalog.SecretWithAnnotation(buildObject.Spec.Builder.Credentials.Name, buildObject.Namespace) - - // generate resources - Expect(tb.CreateSecret(sampleSecret)).To(BeNil()) - - // assert that the validation happened one more time - 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(v1alpha1.SucceedStatus)) - }) - }) - - Context("when a build reference multiple secrets with annotations for a build instance", func() { - It("should validate the Build after secret deletion", func() { - - // populate Build related vars - buildName := BUILD + tb.Namespace - buildObject, err = tb.Catalog.LoadBuildWithNameAndStrategy( - buildName, - STRATEGY+tb.Namespace, - []byte(test.BuildWithMultipleRefSecrets), - ) - Expect(err).To(BeNil()) - - specSourceSecret := tb.Catalog.SecretWithAnnotation(buildObject.Spec.Source.Credentials.Name, buildObject.Namespace) - specBuilderSecret := tb.Catalog.SecretWithAnnotation(buildObject.Spec.Builder.Credentials.Name, buildObject.Namespace) - - Expect(tb.CreateSecret(specSourceSecret)).To(BeNil()) - Expect(tb.CreateSecret(specBuilderSecret)).To(BeNil()) - - Expect(tb.CreateBuild(buildObject)).To(BeNil()) - - // wait until the Build finish the validation - buildObject, err := tb.GetBuildTillValidation(buildName) - Expect(err).To(BeNil()) - Expect(*buildObject.Status.Registered).To(Equal(corev1.ConditionTrue)) - Expect(*buildObject.Status.Reason).To(Equal(v1alpha1.SucceedStatus)) - - // delete a secret - Expect(tb.DeleteSecret(specSourceSecret.Name)).To(BeNil()) - Expect(tb.DeleteSecret(specBuilderSecret.Name)).To(BeNil()) - - buildObject, err = tb.GetBuildTillMessageContainsSubstring(buildName, "missing secrets are") - Expect(err).To(BeNil()) - Expect(*buildObject.Status.Registered).To(Equal(corev1.ConditionFalse)) - Expect(*buildObject.Status.Reason).To(Equal(v1alpha1.MultipleSecretRefNotFound)) - Expect(*buildObject.Status.Message).To(ContainSubstring(specSourceSecret.Name)) - Expect(*buildObject.Status.Message).To(ContainSubstring(specBuilderSecret.Name)) - - }) - - It("should validate when a missing secret is recreated", func() { - // populate Build related vars - buildName := BUILD + tb.Namespace - buildObject, err = tb.Catalog.LoadBuildWithNameAndStrategy( - buildName, - STRATEGY+tb.Namespace, - []byte(test.BuildWithMultipleRefSecrets), - ) - Expect(err).To(BeNil()) - - Expect(tb.CreateBuild(buildObject)).To(BeNil()) - - // wait until the Build finish the validation - buildObject, err := tb.GetBuildTillValidation(buildName) - Expect(err).To(BeNil()) - Expect(*buildObject.Status.Registered).To(Equal(corev1.ConditionFalse)) - Expect(*buildObject.Status.Reason).To(Equal(v1alpha1.MultipleSecretRefNotFound)) - Expect(*buildObject.Status.Message).To(ContainSubstring("missing secrets are")) - Expect(*buildObject.Status.Message).To(ContainSubstring(buildObject.Spec.Source.Credentials.Name)) - Expect(*buildObject.Status.Message).To(ContainSubstring(buildObject.Spec.Builder.Credentials.Name)) - - specSourceSecret := tb.Catalog.SecretWithAnnotation(buildObject.Spec.Source.Credentials.Name, buildObject.Namespace) - specBuilderSecret := tb.Catalog.SecretWithAnnotation(buildObject.Spec.Builder.Credentials.Name, buildObject.Namespace) - - // generate resources - Expect(tb.CreateSecret(specSourceSecret)).To(BeNil()) - Expect(tb.CreateSecret(specBuilderSecret)).To(BeNil()) - - // assert that the validation happened one more time - 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(v1alpha1.SucceedStatus)) - }) - }) Context("when multiple builds reference a secret with annotations for the spec.source", func() { It("should validate the Builds after secret deletion", func() { @@ -440,7 +299,7 @@ var _ = Describe("Integration tests Build and referenced Secrets", func() { ) Expect(err).To(BeNil()) - specSourceSecret := tb.Catalog.SecretWithAnnotation(firstBuildObject.Spec.Source.Credentials.Name, firstBuildObject.Namespace) + specSourceSecret := tb.Catalog.SecretWithAnnotation(*firstBuildObject.Spec.Source.GitSource.CloneSecret, firstBuildObject.Namespace) Expect(tb.CreateSecret(specSourceSecret)).To(BeNil()) @@ -451,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(v1alpha1.SucceedStatus)) + Expect(*o.Status.Reason).To(Equal(v1beta1.SucceedStatus)) o, err = tb.GetBuildTillValidation(secondBuildName) Expect(err).To(BeNil()) Expect(*o.Status.Registered).To(Equal(corev1.ConditionTrue)) - Expect(*o.Status.Reason).To(Equal(v1alpha1.SucceedStatus)) + Expect(*o.Status.Reason).To(Equal(v1beta1.SucceedStatus)) // delete a secret Expect(tb.DeleteSecret(specSourceSecret.Name)).To(BeNil()) @@ -465,15 +324,15 @@ 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(v1alpha1.SpecSourceSecretRefNotFound)) - Expect(*o.Status.Message).To(Equal(fmt.Sprintf("referenced secret %s not found", firstBuildObject.Spec.Source.Credentials.Name))) + Expect(*o.Status.Reason).To(Equal(v1beta1.SpecSourceSecretRefNotFound)) + Expect(*o.Status.Message).To(Equal(fmt.Sprintf("referenced secret %s not found", *firstBuildObject.Spec.Source.GitSource.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(v1alpha1.SpecSourceSecretRefNotFound)) - Expect(*o.Status.Message).To(Equal(fmt.Sprintf("referenced secret %s not found", secondBuildObject.Spec.Source.Credentials.Name))) + Expect(*o.Status.Reason).To(Equal(v1beta1.SpecSourceSecretRefNotFound)) + Expect(*o.Status.Message).To(Equal(fmt.Sprintf("referenced secret %s not found", *secondBuildObject.Spec.Source.GitSource.CloneSecret))) }) It("should validate the Builds when a missing secret is recreated", func() { // populate Build related vars @@ -506,7 +365,7 @@ var _ = Describe("Integration tests Build and referenced Secrets", func() { Expect(err).To(BeNil()) Expect(*buildObject.Status.Registered).To(Equal(corev1.ConditionFalse)) - specSourceSecret := tb.Catalog.SecretWithAnnotation(firstBuildObject.Spec.Source.Credentials.Name, firstBuildObject.Namespace) + specSourceSecret := tb.Catalog.SecretWithAnnotation(*firstBuildObject.Spec.Source.GitSource.CloneSecret, firstBuildObject.Namespace) // generate resources Expect(tb.CreateSecret(specSourceSecret)).To(BeNil()) @@ -515,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(v1alpha1.SucceedStatus)) + Expect(*o.Status.Reason).To(Equal(v1beta1.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(v1alpha1.SucceedStatus)) + Expect(*o.Status.Reason).To(Equal(v1beta1.SucceedStatus)) }) }) }) diff --git a/test/integration/build_to_taskruns_test.go b/test/integration/build_to_taskruns_test.go index 2279500594..579ef65cdf 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/v1alpha1" - utils "github.com/shipwright-io/build/test/utils/v1alpha1" - test "github.com/shipwright-io/build/test/v1alpha1_samples" + "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 *v1alpha1.ClusterBuildStrategy - buildObject *v1alpha1.Build - buildRunObject *v1alpha1.BuildRun + cbsObject *v1beta1.ClusterBuildStrategy + buildObject *v1beta1.Build + buildRunObject *v1beta1.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(v1alpha1.SucceedStatus)) - Expect(*buildObject.Status.Message).To(Equal(v1alpha1.AllValidationsSucceeded)) + Expect(*buildObject.Status.Reason).To(Equal(v1beta1.SucceedStatus)) + Expect(*buildObject.Status.Message).To(Equal(v1beta1.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(v1alpha1.SucceedStatus)) - Expect(*buildObject.Status.Message).To(Equal(v1alpha1.AllValidationsSucceeded)) + Expect(*buildObject.Status.Reason).To(Equal(v1beta1.SucceedStatus)) + Expect(*buildObject.Status.Message).To(Equal(v1beta1.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(v1alpha1.SucceedStatus)) - Expect(*buildObject.Status.Message).To(Equal(v1alpha1.AllValidationsSucceeded)) + Expect(*buildObject.Status.Reason).To(Equal(v1beta1.SucceedStatus)) + Expect(*buildObject.Status.Message).To(Equal(v1beta1.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(v1alpha1.SucceedStatus)) - Expect(*buildObject.Status.Message).To(Equal(v1alpha1.AllValidationsSucceeded)) + Expect(*buildObject.Status.Reason).To(Equal(v1beta1.SucceedStatus)) + Expect(*buildObject.Status.Message).To(Equal(v1beta1.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(v1alpha1.SucceedStatus)) - Expect(*buildObject.Status.Message).To(Equal(v1alpha1.AllValidationsSucceeded)) + Expect(*buildObject.Status.Reason).To(Equal(v1beta1.SucceedStatus)) + Expect(*buildObject.Status.Message).To(Equal(v1beta1.AllValidationsSucceeded)) }) }) diff --git a/test/integration/buildrun_cleanup_test.go b/test/integration/buildrun_cleanup_test.go index f5ba42d993..a79d700562 100644 --- a/test/integration/buildrun_cleanup_test.go +++ b/test/integration/buildrun_cleanup_test.go @@ -8,17 +8,18 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" - test "github.com/shipwright-io/build/test/v1alpha1_samples" + "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" + "k8s.io/utils/pointer" ) var _ = Describe("Integration tests for retention limits and ttls for succeeded buildruns.", func() { var ( - cbsObject *v1alpha1.ClusterBuildStrategy - buildObject *v1alpha1.Build - buildRunObject *v1alpha1.BuildRun + cbsObject *v1beta1.ClusterBuildStrategy + buildObject *v1beta1.Build + buildRunObject *v1beta1.BuildRun buildSample []byte buildRunSample []byte ) @@ -72,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(v1alpha1.Succeeded).Status).To(Equal(corev1.ConditionTrue)) + Expect(br.Status.GetCondition(v1beta1.Succeeded).Status).To(Equal(corev1.ConditionTrue)) _, err = tb.GetBRTillNotFound(buildRunObject.Name, time.Second*1, time.Second*15) Expect(apierrors.IsNotFound(err)).To(BeTrue()) }) @@ -95,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(v1alpha1.Succeeded).Status).To(Equal(corev1.ConditionTrue)) + Expect(br.Status.GetCondition(v1beta1.Succeeded).Status).To(Equal(corev1.ConditionTrue)) _, err = tb.GetBRTillNotFound(buildRunObject.Name, time.Second*1, time.Second*15) Expect(apierrors.IsNotFound(err)).To(BeTrue()) }) @@ -110,11 +111,11 @@ var _ = Describe("Integration tests for retention limits and ttls for succeeded It("Should not find the buildrun few seconds after it fails", func() { - buildRunObject.Spec.BuildRef.Name = "non-existent-buildref" + buildRunObject.Spec.Build.Name = pointer.String("non-existent-buildref") Expect(tb.CreateBR(buildRunObject)).To(BeNil()) br, err := tb.GetBRTillCompletion(buildRunObject.Name) Expect(err).To(BeNil()) - Expect(br.Status.GetCondition(v1alpha1.Succeeded).Status).To(Equal(corev1.ConditionFalse)) + Expect(br.Status.GetCondition(v1beta1.Succeeded).Status).To(Equal(corev1.ConditionFalse)) _, err = tb.GetBRTillNotFound(buildRunObject.Name, time.Second*1, time.Second*15) Expect(apierrors.IsNotFound(err)).To(BeTrue()) }) @@ -139,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(v1alpha1.Succeeded).Status).To(Equal(corev1.ConditionTrue)) + Expect(br.Status.GetCondition(v1beta1.Succeeded).Status).To(Equal(corev1.ConditionTrue)) // Make the TTL 5 seconds br.Spec.Retention.TTLAfterSucceeded.Duration = time.Second * 5 @@ -168,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(v1alpha1.Succeeded).Status).To(Equal(corev1.ConditionTrue)) + Expect(br1.Status.GetCondition(v1beta1.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(v1alpha1.Succeeded).Status).To(Equal(corev1.ConditionTrue)) + Expect(br2.Status.GetCondition(v1beta1.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()) @@ -200,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(v1alpha1.Succeeded).Status).To(Equal(corev1.ConditionTrue)) + Expect(br.Status.GetCondition(v1beta1.Succeeded).Status).To(Equal(corev1.ConditionTrue)) _, err = tb.GetBRTillNotFound(buildRunObject.Name, time.Second*1, time.Second*15) Expect(apierrors.IsNotFound(err)).To(BeTrue()) @@ -233,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 := v1alpha1.ParamValue{Name: "exit-command", SingleValue: &v1alpha1.SingleValue{Value: &str}} - buildRunObject.Spec.ParamValues = []v1alpha1.ParamValue{falseParam} + falseParam := v1beta1.ParamValue{Name: "exit-command", SingleValue: &v1beta1.SingleValue{Value: &str}} + buildRunObject.Spec.ParamValues = []v1beta1.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(v1alpha1.Succeeded).Status).To(Equal(corev1.ConditionTrue)) + Expect(br1.Status.GetCondition(v1beta1.Succeeded).Status).To(Equal(corev1.ConditionTrue)) br2, err := tb.GetBRTillCompletion(BUILDRUN + tb.Namespace + "-success-2") Expect(err).To(BeNil()) - Expect(br2.Status.GetCondition(v1alpha1.Succeeded).Status).To(Equal(corev1.ConditionTrue)) + Expect(br2.Status.GetCondition(v1beta1.Succeeded).Status).To(Equal(corev1.ConditionTrue)) br3, err := tb.GetBRTillCompletion(BUILDRUN + tb.Namespace + "-fail-1") Expect(err).To(BeNil()) - Expect(br3.Status.GetCondition(v1alpha1.Succeeded).Status).To(Equal(corev1.ConditionFalse)) + Expect(br3.Status.GetCondition(v1beta1.Succeeded).Status).To(Equal(corev1.ConditionFalse)) // Create 1 failed buildrun. buildRunObject.Name = BUILDRUN + tb.Namespace + "-fail-2" - buildRunObject.Spec.ParamValues = []v1alpha1.ParamValue{falseParam} + buildRunObject.Spec.ParamValues = []v1beta1.ParamValue{falseParam} err = tb.CreateBR(buildRunObject) Expect(err).To(BeNil()) br4, err := tb.GetBRTillCompletion(buildRunObject.Name) Expect(err).To(BeNil()) - Expect(br4.Status.GetCondition(v1alpha1.Succeeded).Status).To(Equal(corev1.ConditionFalse)) + Expect(br4.Status.GetCondition(v1beta1.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) @@ -273,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 *v1alpha1.ClusterBuildStrategy - buildObject *v1alpha1.Build - buildRunObject *v1alpha1.BuildRun + cbsObject *v1beta1.ClusterBuildStrategy + buildObject *v1beta1.Build + buildRunObject *v1beta1.BuildRun buildSample []byte buildRunSample []byte ) @@ -308,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 := v1alpha1.ParamValue{Name: "exit-command", SingleValue: &v1alpha1.SingleValue{Value: &str}} - buildRunObject.Spec.ParamValues = []v1alpha1.ParamValue{falseParam} + falseParam := v1beta1.ParamValue{Name: "exit-command", SingleValue: &v1beta1.SingleValue{Value: &str}} + buildRunObject.Spec.ParamValues = []v1beta1.ParamValue{falseParam} } }) @@ -331,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(v1alpha1.Succeeded).Status).To(Equal(corev1.ConditionFalse)) + Expect(br.Status.GetCondition(v1beta1.Succeeded).Status).To(Equal(corev1.ConditionFalse)) _, err = tb.GetBRTillNotFound(buildRunObject.Name, time.Second*1, time.Second*15) Expect(apierrors.IsNotFound(err)).To(BeTrue()) }) @@ -356,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(v1alpha1.Succeeded).Status).To(Equal(corev1.ConditionFalse)) + Expect(br.Status.GetCondition(v1beta1.Succeeded).Status).To(Equal(corev1.ConditionFalse)) // Make the TTL 5 seconds br.Spec.Retention.TTLAfterFailed.Duration = time.Second * 5 @@ -383,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(v1alpha1.Succeeded).Status).To(Equal(corev1.ConditionFalse)) + Expect(br.Status.GetCondition(v1beta1.Succeeded).Status).To(Equal(corev1.ConditionFalse)) _, err = tb.GetBRTillNotFound(buildRunObject.Name, time.Second*1, time.Second*15) Expect(apierrors.IsNotFound(err)).To(BeTrue()) }) @@ -405,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(v1alpha1.Succeeded).Status).To(Equal(corev1.ConditionFalse)) + Expect(br.Status.GetCondition(v1beta1.Succeeded).Status).To(Equal(corev1.ConditionFalse)) _, err = tb.GetBRTillNotFound(buildRunObject.Name, time.Second*1, time.Second*15) Expect(apierrors.IsNotFound(err)).To(BeTrue()) @@ -430,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(v1alpha1.Succeeded).Status).To(Equal(corev1.ConditionFalse)) + Expect(br1.Status.GetCondition(v1beta1.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(v1alpha1.Succeeded).Status).To(Equal(corev1.ConditionFalse)) + Expect(br2.Status.GetCondition(v1beta1.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 597da17f00..810619d5f1 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/v1alpha1" + "github.com/shipwright-io/build/pkg/apis/build/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/rand" @@ -40,16 +40,24 @@ 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 // Setup BuildRun with fixed revision where we know the commit details - Expect(tb.CreateBR(&v1alpha1.BuildRun{ + Expect(tb.CreateBR(&v1beta1.BuildRun{ ObjectMeta: metav1.ObjectMeta{Name: buildRunName}, - Spec: v1alpha1.BuildRunSpec{ - BuildSpec: &v1alpha1.BuildSpec{ - Strategy: v1alpha1.Strategy{Kind: (*v1alpha1.BuildStrategyKind)(&strategy.Kind), Name: strategy.Name}, - Source: v1alpha1.Source{ - URL: pointer.String("https://github.com/shipwright-io/sample-go"), - Revision: pointer.String("v0.1.0"), + Spec: v1beta1.BuildRunSpec{ + Build: v1beta1.ReferencedBuild{ + Build: &v1beta1.BuildSpec{ + Source: v1beta1.Source{ + Type: v1beta1.GitType, + GitSource: &v1beta1.Git{ + URL: "https://github.com/shipwright-io/sample-go", + Revision: pointer.String("v0.1.0"), + }, + }, + Strategy: v1beta1.Strategy{ + Kind: &cbs, + Name: strategy.Name, + }, }, }, }, @@ -59,25 +67,32 @@ var _ = Describe("Checking BuildRun Status fields", func() { Expect(err).ToNot(HaveOccurred()) Expect(buildRun).ToNot(BeNil()) - Expect(buildRun.Status.Sources).ToNot(BeEmpty()) - Expect(buildRun.Status.Sources[0].Timestamp).ToNot(BeNil()) - Expect(buildRun.Status.Sources[0].Timestamp.Time).To(BeTemporally("==", time.Unix(1619426578, 0))) + Expect(buildRun.Status.Source).ToNot(BeNil()) + Expect(buildRun.Status.Source.Timestamp).ToNot(BeNil()) + Expect(buildRun.Status.Source.Timestamp.Time).To(BeTemporally("==", time.Unix(1619426578, 0))) }) It("should have the correct source timestamp for Bundle sources", 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 // Setup BuildRun with fixed image sha where we know the timestamp details - Expect(tb.CreateBR(&v1alpha1.BuildRun{ + Expect(tb.CreateBR(&v1beta1.BuildRun{ + ObjectMeta: metav1.ObjectMeta{Name: buildRunName}, - Spec: v1alpha1.BuildRunSpec{ - BuildSpec: &v1alpha1.BuildSpec{ - Strategy: v1alpha1.Strategy{Kind: (*v1alpha1.BuildStrategyKind)(&strategy.Kind), Name: strategy.Name}, - Source: v1alpha1.Source{ - BundleContainer: &v1alpha1.BundleContainer{ - Image: "ghcr.io/shipwright-io/sample-go/source-bundle@sha256:9a5e264c19980387b8416e0ffa7460488272fb8a6a56127c657edaa2682daab2", + Spec: v1beta1.BuildRunSpec{ + Build: v1beta1.ReferencedBuild{ + Build: &v1beta1.BuildSpec{ + Strategy: v1beta1.Strategy{ + Kind: &cbs, + Name: strategy.Name, + }, + Source: v1beta1.Source{ + Type: v1beta1.OCIArtifactType, + OCIArtifact: &v1beta1.OCIArtifact{ + Image: "ghcr.io/shipwright-io/sample-go/source-bundle@sha256:9a5e264c19980387b8416e0ffa7460488272fb8a6a56127c657edaa2682daab2", + }, }, }, }, @@ -88,9 +103,9 @@ var _ = Describe("Checking BuildRun Status fields", func() { Expect(err).ToNot(HaveOccurred()) Expect(buildRun).ToNot(BeNil()) - Expect(buildRun.Status.Sources).ToNot(BeEmpty()) - Expect(buildRun.Status.Sources[0].Timestamp).ToNot(BeNil()) - Expect(buildRun.Status.Sources[0].Timestamp.Time).To(BeTemporally("==", time.Unix(1691650396, 0))) + Expect(buildRun.Status.Source).ToNot(BeNil()) + Expect(buildRun.Status.Source.Timestamp).ToNot(BeNil()) + Expect(buildRun.Status.Source.Timestamp.Time).To(BeTemporally("==", time.Unix(1691650396, 0))) }) }) }) diff --git a/test/integration/buildruns_to_sa_test.go b/test/integration/buildruns_to_sa_test.go index 85e998bb03..4f3c1749b6 100644 --- a/test/integration/buildruns_to_sa_test.go +++ b/test/integration/buildruns_to_sa_test.go @@ -14,16 +14,16 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/util/wait" - "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" - test "github.com/shipwright-io/build/test/v1alpha1_samples" + "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 *v1alpha1.ClusterBuildStrategy - buildObject *v1alpha1.Build - buildRunObject *v1alpha1.BuildRun + cbsObject *v1beta1.ClusterBuildStrategy + buildObject *v1beta1.Build + buildRunObject *v1beta1.BuildRun buildSample []byte buildRunSample []byte ) @@ -82,7 +82,7 @@ var _ = Describe("Integration tests BuildRuns and Service-accounts", func() { return false } - sampleSecret := tb.Catalog.SecretWithAnnotation(buildObject.Spec.Output.Credentials.Name, buildObject.Namespace) + sampleSecret := tb.Catalog.SecretWithAnnotation(*buildObject.Spec.Output.PushSecret, buildObject.Namespace) Expect(tb.CreateSecret(sampleSecret)).To(BeNil()) @@ -100,7 +100,7 @@ var _ = Describe("Integration tests BuildRuns and Service-accounts", func() { Expect(err).To(BeNil()) // Verify that the sa have our Build specified secret - Expect(contains(sa.Secrets, buildObject.Spec.Output.Credentials.Name)).To(BeTrue()) + Expect(contains(sa.Secrets, *buildObject.Spec.Output.PushSecret)).To(BeTrue()) _, err = tb.GetBRTillCompletion(buildRunObject.Name) Expect(err).To(BeNil()) @@ -130,7 +130,7 @@ var _ = Describe("Integration tests BuildRuns and Service-accounts", func() { return false } - sampleSecret := tb.Catalog.SecretWithAnnotation(buildObject.Spec.Output.Credentials.Name, buildObject.Namespace) + sampleSecret := tb.Catalog.SecretWithAnnotation(*buildObject.Spec.Output.PushSecret, buildObject.Namespace) Expect(tb.CreateSecret(sampleSecret)).To(BeNil()) @@ -148,7 +148,7 @@ var _ = Describe("Integration tests BuildRuns and Service-accounts", func() { Expect(err).To(BeNil()) // Verify that the sa have our Build specified secret - Expect(contains(sa.Secrets, buildObject.Spec.Output.Credentials.Name)).To(BeTrue()) + Expect(contains(sa.Secrets, *buildObject.Spec.Output.PushSecret)).To(BeTrue()) // cancel the br err = wait.PollImmediate(1*time.Second, 4*time.Second, func() (done bool, err error) { @@ -158,7 +158,7 @@ var _ = Describe("Integration tests BuildRuns and Service-accounts", func() { return false, nil } - bro.Spec.State = v1alpha1.BuildRunRequestedStatePtr(v1alpha1.BuildRunStateCancel) + bro.Spec.State = v1beta1.BuildRunRequestedStatePtr(v1beta1.BuildRunStateCancel) err = tb.UpdateBR(bro) if err != nil { GinkgoT().Logf("error on br update: %s\n", err.Error()) @@ -168,7 +168,7 @@ var _ = Describe("Integration tests BuildRuns and Service-accounts", func() { }) Expect(err).To(BeNil()) - expectedReason := v1alpha1.BuildRunStateCancel + expectedReason := v1beta1.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)) @@ -246,7 +246,7 @@ var _ = Describe("Integration tests BuildRuns and Service-accounts", func() { br, _ := tb.GetBRTillCompletion(buildRunObject.Name) Expect(err).To(BeNil()) - buildRunCondition := br.Status.GetCondition(v1alpha1.Succeeded) + buildRunCondition := br.Status.GetCondition(v1beta1.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 8d75f6ec49..33362d15f8 100644 --- a/test/integration/buildruns_to_taskruns_test.go +++ b/test/integration/buildruns_to_taskruns_test.go @@ -14,9 +14,9 @@ import ( . "github.com/onsi/gomega" pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" - "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + "github.com/shipwright-io/build/pkg/apis/build/v1beta1" "github.com/shipwright-io/build/pkg/reconciler/buildrun/resources" - test "github.com/shipwright-io/build/test/v1alpha1_samples" + test "github.com/shipwright-io/build/test/v1beta1_samples" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -27,14 +27,14 @@ import ( var _ = Describe("Integration tests BuildRuns and TaskRuns", func() { var ( - cbsObject *v1alpha1.ClusterBuildStrategy - buildObject *v1alpha1.Build - buildRunObject *v1alpha1.BuildRun + cbsObject *v1beta1.ClusterBuildStrategy + buildObject *v1beta1.Build + buildRunObject *v1beta1.BuildRun buildSample []byte buildRunSample []byte ) - var setupBuildAndBuildRun = func(buildDef []byte, buildRunDef []byte, strategy ...string) (watch.Interface, *v1alpha1.Build, *v1alpha1.BuildRun) { + var setupBuildAndBuildRun = func(buildDef []byte, buildRunDef []byte, strategy ...string) (watch.Interface, *v1beta1.Build, *v1beta1.BuildRun) { var strategyName = STRATEGY + tb.Namespace if len(strategy) > 0 { @@ -42,7 +42,7 @@ var _ = Describe("Integration tests BuildRuns and TaskRuns", func() { } timeout := int64(tb.TimeOut.Seconds()) - buildRunWatcher, err := tb.BuildClientSet.ShipwrightV1alpha1().BuildRuns(tb.Namespace).Watch(context.TODO(), metav1.ListOptions{TimeoutSeconds: &timeout}) + buildRunWatcher, err := tb.BuildClientSet.ShipwrightV1beta1().BuildRuns(tb.Namespace).Watch(context.TODO(), metav1.ListOptions{TimeoutSeconds: &timeout}) Expect(err).To(BeNil()) buildObject, err = tb.Catalog.LoadBuildWithNameAndStrategy(BUILD+tb.Namespace, strategyName, buildDef) @@ -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 = []*v1alpha1.Condition{} + var seq = []*v1beta1.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.(*v1alpha1.BuildRun).Status.GetCondition(v1alpha1.Succeeded) + condition := event.Object.(*v1beta1.BuildRun).Status.GetCondition(v1beta1.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(&v1alpha1.Condition{ - Type: v1alpha1.Succeeded, + Expect(seq).Should(ContainElement(&v1beta1.Condition{ + Type: v1beta1.Succeeded, Status: corev1.ConditionUnknown, LastTransitionTime: metav1.Time{Time: fakeTime}, Reason: "Pending", Message: "Pending", })) - Expect(seq).Should(ContainElement(&v1alpha1.Condition{ - Type: v1alpha1.Succeeded, + Expect(seq).Should(ContainElement(&v1beta1.Condition{ + Type: v1beta1.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(v1alpha1.Succeeded) + condition := buildRun.Status.GetCondition(v1beta1.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(v1alpha1.Succeeded) + condition := buildRun.Status.GetCondition(v1beta1.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(v1alpha1.Succeeded) + condition := buildRun.Status.GetCondition(v1beta1.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(v1alpha1.RemoteRepositoryUnreachable)) + Expect(*b.Status.Reason).To(Equal(v1beta1.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 *v1alpha1.BuildRun + var standaloneBuildRunObject *v1beta1.BuildRun BeforeEach(func() { standAloneBuildRunSample = []byte(test.MinimalOneOffBuildRun) @@ -369,9 +369,9 @@ var _ = Describe("Integration tests BuildRuns and TaskRuns", func() { _, err = tb.GetTaskRunFromBuildRun(br.Name) Expect(err).ToNot(HaveOccurred()) - br.Spec.State = v1alpha1.BuildRunRequestedStatePtr(v1alpha1.BuildRunStateCancel) - data := []byte(fmt.Sprintf(`{"spec":{"state": "%s"}}`, v1alpha1.BuildRunStateCancel)) - br, err = tb.BuildClientSet.ShipwrightV1alpha1(). + br.Spec.State = v1beta1.BuildRunRequestedStatePtr(v1beta1.BuildRunStateCancel) + data := []byte(fmt.Sprintf(`{"spec":{"state": "%s"}}`, v1beta1.BuildRunStateCancel)) + br, err = tb.BuildClientSet.ShipwrightV1beta1(). BuildRuns(tb.Namespace). Patch(tb.Context, br.Name, types.MergePatchType, data, metav1.PatchOptions{}) Expect(err).ToNot(HaveOccurred()) @@ -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, v1alpha1.BuildRunStateCancel) - Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("failed to get desired BuildRun reason; expected %s, got %s", v1alpha1.BuildRunStateCancel, actualReason)) - Expect(actualReason).To(Equal(v1alpha1.BuildRunStateCancel)) + 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)) }) }) @@ -408,7 +408,7 @@ var _ = Describe("Integration tests BuildRuns and TaskRuns", func() { return false, nil } - bro.Spec.State = v1alpha1.BuildRunRequestedStatePtr(v1alpha1.BuildRunStateCancel) + bro.Spec.State = v1beta1.BuildRunRequestedStatePtr(v1beta1.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 = v1alpha1.BuildRunStateCancel + expectedReason = v1beta1.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(v1alpha1.Succeeded) + condition := br.Status.GetCondition(v1beta1.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 adc6064812..aefffa02b0 100644 --- a/test/integration/buildstrategy_to_taskruns_test.go +++ b/test/integration/buildstrategy_to_taskruns_test.go @@ -10,18 +10,18 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" - utils "github.com/shipwright-io/build/test/utils/v1alpha1" - test "github.com/shipwright-io/build/test/v1alpha1_samples" + "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" corev1 "k8s.io/api/core/v1" ) var _ = Describe("Integration tests BuildStrategies and TaskRuns", func() { var ( - bsObject *v1alpha1.BuildStrategy - buildObject *v1alpha1.Build - buildRunObject *v1alpha1.BuildRun + bsObject *v1beta1.BuildStrategy + buildObject *v1beta1.Build + buildRunObject *v1beta1.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 *v1alpha1.Build) { + var constructBuildObjectAndWait = func(b *v1beta1.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 *v1alpha1.BuildRun) { + var constructBuildRunObjectAndWait = func(br *v1beta1.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(v1alpha1.Succeeded).GetReason()).To(Equal("RestrictedParametersInUse")) - Expect(br.Status.GetCondition(v1alpha1.Succeeded).GetMessage()).To(HavePrefix("The following parameters are restricted and cannot be set")) - Expect(br.Status.GetCondition(v1alpha1.Succeeded).GetMessage()).To(ContainSubstring("shp-sleep-time")) + 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")) }) 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(v1alpha1.RestrictedParametersInUse)) + Expect(*buildObject.Status.Reason).To(Equal(v1beta1.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(v1alpha1.UndefinedParameter)) + Expect(*buildObject.Status.Reason).To(Equal(v1beta1.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(v1alpha1.Succeeded).GetReason()).To(Equal("MissingParameterValues")) - Expect(br.Status.GetCondition(v1alpha1.Succeeded).GetMessage()).To(HavePrefix("The following parameters are required but no value has been provided:")) - Expect(br.Status.GetCondition(v1alpha1.Succeeded).GetMessage()).To(ContainSubstring("sleep-time")) + 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")) }) Context("when a taskrun fails with an error result", func() { @@ -601,9 +601,7 @@ var _ = Describe("Integration tests BuildStrategies and TaskRuns", func() { }) It("creates a TaskRun with Shipwright managed push", func() { - buildObject.Spec.Output.Credentials = &corev1.LocalObjectReference{ - Name: secret.Name, - } + buildObject.Spec.Output.PushSecret = &secret.Name Expect(tb.CreateBuild(buildObject)).ToNot(HaveOccurred()) buildObject, err = tb.GetBuildTillValidation(buildObject.Name) diff --git a/test/integration/clusterbuildstrategy_to_taskruns_test.go b/test/integration/clusterbuildstrategy_to_taskruns_test.go index 1fce846285..ca0793257a 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/v1alpha1" - test "github.com/shipwright-io/build/test/v1alpha1_samples" + "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 *v1alpha1.ClusterBuildStrategy - buildObject *v1alpha1.Build - buildRunObject *v1alpha1.BuildRun + cbsObject *v1beta1.ClusterBuildStrategy + buildObject *v1beta1.Build + buildRunObject *v1beta1.BuildRun buildSample []byte buildRunSample []byte ) diff --git a/test/integration/integration_suite_test.go b/test/integration/integration_suite_test.go index 75ae2bc70f..916fde550b 100644 --- a/test/integration/integration_suite_test.go +++ b/test/integration/integration_suite_test.go @@ -12,8 +12,7 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - // utils "github.com/shipwright-io/build/test/utils" - utils "github.com/shipwright-io/build/test/utils/v1alpha1" + utils "github.com/shipwright-io/build/test/utils/v1beta1" ) const ( diff --git a/test/utils/v1beta1/builds.go b/test/utils/v1beta1/builds.go index e6e5704b4c..a3809b6c6d 100644 --- a/test/utils/v1beta1/builds.go +++ b/test/utils/v1beta1/builds.go @@ -27,6 +27,16 @@ func (t *TestBuild) CreateBuild(build *v1beta1.Build) error { return err } +// UpdateBR updates a BuildRun on the current test namespace +func (t *TestBuild) UpdateBuild(build *v1beta1.Build) error { + brInterface := t.BuildClientSet.ShipwrightV1beta1().Builds(t.Namespace) + _, err := brInterface.Update(context.TODO(), build, metav1.UpdateOptions{}) + if err != nil { + return err + } + return nil +} + // DeleteBuild deletes a Build on the desired namespace func (t *TestBuild) DeleteBuild(name string) error { bInterface := t.BuildClientSet.ShipwrightV1beta1().Builds(t.Namespace) diff --git a/test/v1beta1_samples/build_samples.go b/test/v1beta1_samples/build_samples.go index 154ec55abd..271f157c1f 100644 --- a/test/v1beta1_samples/build_samples.go +++ b/test/v1beta1_samples/build_samples.go @@ -144,11 +144,6 @@ spec: strategy: name: buildpacks-v3 kind: ClusterBuildStrategy - paramValues: - - name: dockerfile - value: Dockerfile - - name: builder-image - value: heroku/builder:22 output: image: image-registry.openshift-image-registry.svc:5000/example/buildpacks-app timeout: 30s diff --git a/test/v1beta1_samples/buildrun_samples.go b/test/v1beta1_samples/buildrun_samples.go index 0d8676400c..cb88c40e09 100644 --- a/test/v1beta1_samples/buildrun_samples.go +++ b/test/v1beta1_samples/buildrun_samples.go @@ -134,6 +134,7 @@ spec: build: spec: source: + type: Git git: url: "https://github.com/shipwright-io/sample-go" contextDir: docker-build diff --git a/test/v1beta1_samples/buildstrategy_samples.go b/test/v1beta1_samples/buildstrategy_samples.go index 9fd61f7f87..2e11b54652 100644 --- a/test/v1beta1_samples/buildstrategy_samples.go +++ b/test/v1beta1_samples/buildstrategy_samples.go @@ -27,7 +27,7 @@ spec: args: - bud - --tag=$(params.shp-output-image) - - --file=$(build.dockerfile) + - --file=$(params.dockerfile) - $(params.shp-source-context) resources: limits: @@ -59,6 +59,11 @@ spec: volumeMounts: - name: buildah-images mountPath: /var/lib/containers/storage + parameters: + - name: dockerfile + description: The path to the Dockerfile to be used for building the image. + type: string + default: "Dockerfile" ` // MinimalBuildahBuildStrategyWithEnvs defines a @@ -153,7 +158,7 @@ spec: - --tls-verify=false - --layers - -f - - $(build.dockerfile) + - $(params.dockerfile) - -t - $(params.shp-output-image) - $(params.shp-source-context) @@ -167,6 +172,11 @@ spec: volumeMounts: - name: varlibcontainers mountPath: /var/lib/containers + parameters: + - name: dockerfile + description: The path to the Dockerfile to be used for building the image. + type: string + default: "Dockerfile" ` // BuildpacksBuildStrategySingleStep defines a @@ -183,7 +193,7 @@ spec: emptyDir: {} steps: - name: build - image: "$(build.builder.image)" + image: "$(params.builder-image)" workingDir: $(params.shp-source-root) command: - /cnb/lifecycle/builder diff --git a/test/v1beta1_samples/catalog.go b/test/v1beta1_samples/catalog.go index 7834b10a43..62b4994801 100644 --- a/test/v1beta1_samples/catalog.go +++ b/test/v1beta1_samples/catalog.go @@ -252,8 +252,8 @@ func (c *Catalog) FakeClusterBuildStrategyNotFound(name string) error { // StubFunc is used to simulate the status of the Build // after a .Status().Update() call in the controller. This // receives a parameter to return an specific status state -func (c *Catalog) StubFunc(status corev1.ConditionStatus, reason build.BuildReason, message string) func(context context.Context, object client.Object, _ ...client.UpdateOption) error { - return func(context context.Context, object client.Object, _ ...client.UpdateOption) error { +func (c *Catalog) StubFunc(status corev1.ConditionStatus, reason build.BuildReason, message string) func(context context.Context, object client.Object, _ ...client.SubResourceUpdateOption) error { + return func(context context.Context, object client.Object, _ ...client.SubResourceUpdateOption) error { switch object := object.(type) { case *build.Build: Expect(*object.Status.Registered).To(Equal(status)) @@ -334,8 +334,8 @@ func (c *Catalog) StubBuildAndTaskRun( } // StubBuildStatusReason asserts Status fields on a Build resource -func (c *Catalog) StubBuildStatusReason(reason build.BuildReason, message string) func(context context.Context, object client.Object, _ ...client.UpdateOption) error { - return func(context context.Context, object client.Object, _ ...client.UpdateOption) error { +func (c *Catalog) StubBuildStatusReason(reason build.BuildReason, message string) func(context context.Context, object client.Object, _ ...client.SubResourceUpdateOption) error { + return func(context context.Context, object client.Object, _ ...client.SubResourceUpdateOption) error { switch object := object.(type) { case *build.Build: if object.Status.Message != nil && *object.Status.Message != "" { @@ -350,8 +350,8 @@ func (c *Catalog) StubBuildStatusReason(reason build.BuildReason, message string } // StubBuildRunStatus asserts Status fields on a BuildRun resource -func (c *Catalog) StubBuildRunStatus(reason string, name *string, condition build.Condition, status corev1.ConditionStatus, buildSpec build.BuildSpec, tolerateEmptyStatus bool) func(context context.Context, object client.Object, _ ...client.UpdateOption) error { - return func(context context.Context, object client.Object, _ ...client.UpdateOption) error { +func (c *Catalog) StubBuildRunStatus(reason string, name *string, condition build.Condition, status corev1.ConditionStatus, buildSpec build.BuildSpec, tolerateEmptyStatus bool) func(context context.Context, object client.Object, _ ...client.SubResourceUpdateOption) error { + return func(context context.Context, object client.Object, _ ...client.SubResourceUpdateOption) error { switch object := object.(type) { case *build.BuildRun: if !tolerateEmptyStatus { diff --git a/test/v1beta1_samples/clusterbuildstrategy_samples.go b/test/v1beta1_samples/clusterbuildstrategy_samples.go index 4d6a775bd4..c0877f23a3 100644 --- a/test/v1beta1_samples/clusterbuildstrategy_samples.go +++ b/test/v1beta1_samples/clusterbuildstrategy_samples.go @@ -17,7 +17,7 @@ spec: - name: buildah-images volumeSource: emptyDir: {} - buildSteps: + steps: - name: buildah-bud image: quay.io/containers/buildah:v1.34.0 workingDir: $(params.shp-source-root) @@ -75,7 +75,7 @@ spec: - name: buildah-images volumeSource: emptyDir: {} - buildSteps: + steps: - name: buildah-bud image: quay.io/containers/buildah:v1.34.0 workingDir: $(params.shp-source-root) @@ -129,7 +129,7 @@ kind: ClusterBuildStrategy metadata: name: kaniko spec: - buildSteps: + steps: - name: step-build-and-push image: gcr.io/kaniko-project/executor:v1.20.1 workingDir: $(params.shp-source-root) @@ -178,7 +178,7 @@ kind: ClusterBuildStrategy metadata: name: kaniko spec: - buildSteps: + steps: - name: step-build-and-push image: gcr.io/kaniko-project/executor:v1.20.1 workingDir: $(params.shp-source-root) @@ -229,7 +229,7 @@ spec: - name: exit-command description: "Exit command for the pod" default: "true" - buildSteps: + steps: - name: step-no-and-op image: alpine:latest workingDir: $(params.shp-source-root) @@ -269,7 +269,7 @@ kind: ClusterBuildStrategy metadata: name: noop spec: - buildSteps: + steps: - name: sleep30 image: alpine:latest command: @@ -296,7 +296,7 @@ metadata: kubectl.kubernetes.io/last-applied-configuration: anotherValue name: kaniko spec: - buildSteps: + steps: - name: step-build-and-push image: gcr.io/kaniko-project/executor:v1.20.1 workingDir: $(params.shp-source-root) @@ -348,7 +348,7 @@ spec: - name: sleep-time description: "time in seconds for sleeping" default: "1" - buildSteps: + steps: - name: sleep30 image: alpine:latest command: