From ca44420ffb552acb3ba05ccac2a6ac8140121aed Mon Sep 17 00:00:00 2001 From: Jason Hall Date: Thu, 18 Mar 2021 16:55:03 -0400 Subject: [PATCH] Unify Go struct field names with YAML/JSON field names Signed-off-by: Jason Hall --- deploy/crds/shipwright.io_buildruns.yaml | 69 +++++++-------- deploy/crds/shipwright.io_builds.yaml | 50 ++++++----- pkg/apis/build/v1alpha1/build_types.go | 38 +++++---- pkg/apis/build/v1alpha1/buildrun_types.go | 1 - pkg/apis/build/v1alpha1/buildstrategy.go | 4 +- pkg/apis/build/v1alpha1/gitsource.go | 27 ------ pkg/apis/build/v1alpha1/source.go | 34 ++++++++ .../build/v1alpha1/zz_generated.deepcopy.go | 84 +++++++++---------- .../build/v1alpha1/zz_generated.openapi.go | 31 ------- pkg/reconciler/build/build.go | 2 +- pkg/reconciler/build/build_test.go | 30 +++---- pkg/reconciler/build/controller.go | 22 ++--- pkg/reconciler/buildrun/buildrun.go | 21 +++-- .../buildrun/resources/credentials.go | 10 +-- .../buildrun/resources/credentials_test.go | 24 +++--- .../buildrun/resources/runtime_image.go | 22 ++--- .../buildrun/resources/runtime_image_test.go | 8 +- .../buildrun/resources/strategies.go | 4 +- pkg/reconciler/buildrun/resources/taskrun.go | 28 +++---- .../buildrun/resources/taskrun_test.go | 8 +- pkg/validate/secrets.go | 22 ++--- pkg/validate/sourceurl.go | 2 +- pkg/validate/strategies.go | 28 +++---- pkg/validate/validate.go | 4 +- test/catalog.go | 48 +++++------ test/e2e/common_test.go | 20 ++--- test/integration/build_to_git_test.go | 4 +- test/integration/build_to_secrets_test.go | 65 +++++++------- test/integration/buildruns_to_sa_test.go | 4 +- 29 files changed, 345 insertions(+), 369 deletions(-) delete mode 100644 pkg/apis/build/v1alpha1/gitsource.go create mode 100644 pkg/apis/build/v1alpha1/source.go delete mode 100644 pkg/apis/build/v1alpha1/zz_generated.openapi.go diff --git a/deploy/crds/shipwright.io_buildruns.yaml b/deploy/crds/shipwright.io_buildruns.yaml index 01be3be48e..92d83ca40e 100644 --- a/deploy/crds/shipwright.io_buildruns.yaml +++ b/deploy/crds/shipwright.io_buildruns.yaml @@ -74,8 +74,8 @@ spec: spec properties: credentials: - description: SecretRef is a reference to the Secret containing - the credentials to push the image to the registry + description: Credentials references a Secret that contains credentials + to access the image registry. properties: name: description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names @@ -83,8 +83,7 @@ spec: type: string type: object image: - description: ImageURL is the URL where the image will be pushed - to. + description: Image is the reference of the image. type: string required: - image @@ -115,12 +114,12 @@ spec: description: BuildSpec is the Build Spec of this BuildRun. properties: builder: - description: BuilderImage refers to the image containing the build + description: Builder refers to the image containing the build tools inside which the source code would be built. properties: credentials: - description: SecretRef is a reference to the Secret containing - the credentials to push the image to the registry + description: Credentials references a Secret that contains + credentials to access the image registry. properties: name: description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names @@ -128,8 +127,7 @@ spec: type: string type: object image: - description: ImageURL is the URL where the image will be pushed - to. + description: Image is the reference of the image. type: string required: - image @@ -140,12 +138,12 @@ spec: an image. type: string output: - description: Output refers to the location where the generated - image would be pushed to. + description: Output refers to the location where the built image + would be pushed. properties: credentials: - description: SecretRef is a reference to the Secret containing - the credentials to push the image to the registry + description: Credentials references a Secret that contains + credentials to access the image registry. properties: name: description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names @@ -153,8 +151,7 @@ spec: type: string type: object image: - description: ImageURL is the URL where the image will be pushed - to. + description: Image is the reference of the image. type: string required: - image @@ -177,14 +174,14 @@ spec: type: object type: array runtime: - description: Runtime represents the runtime-image + description: Runtime represents the runtime-image. properties: base: description: Base runtime base image. properties: credentials: - description: SecretRef is a reference to the Secret containing - the credentials to push the image to the registry + description: Credentials references a Secret that contains + credentials to access the image registry. properties: name: description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names @@ -193,8 +190,7 @@ spec: type: string type: object image: - description: ImageURL is the URL where the image will - be pushed to. + description: Image is the reference of the image. type: string required: - image @@ -253,8 +249,8 @@ spec: Optional. type: string credentials: - description: SecretRef refers to the secret that contains - credentials to access the git repo. Optional. + description: Credentials references a Secret that contains + credentials to access the repository. properties: name: description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names @@ -262,19 +258,19 @@ spec: type: string type: object revision: - description: Ref is a git reference. Optional. If not defined, - it will fallback to the git repository default branch. + description: "Revision describes the Git revision (e.g., branch, + tag, commit SHA, etc.) to fetch. \n If not defined, it will + fallback to the repository's default branch." type: string url: - description: URL of the git repo + description: URL describes the URL of the Git repository. type: string required: - url type: object strategy: - description: StrategyRef refers to the BuildStrategy to be used - to build the container image. There are namespaced scope and - cluster scope BuildStrategy + description: Strategy references the BuildStrategy to use to build + the container image. properties: apiVersion: description: API version of the referent @@ -290,7 +286,8 @@ spec: - name type: object timeout: - description: Timeout defines the maximum run time of a build run. + description: Timeout defines the maximum amount of time the Build + should take to execute. format: duration type: string required: @@ -303,7 +300,8 @@ spec: format: date-time type: string conditions: - description: Conditions + description: Conditions holds the latest available observations of + a resource's current state. items: description: Condition defines the required fields for populating Build controllers Conditions @@ -340,18 +338,21 @@ spec: type: string type: object latestTaskRunRef: - description: PodName is the name of the pod responsible for executing - this task's steps. + description: "LatestTaskRunRef is the name of the TaskRun responsible + for executing this BuildRun. \n TODO: This should be called something + like \"TaskRunName\"" type: string reason: - description: The Succeeded reason of the TaskRun + description: "The Succeeded reason of the TaskRun \n Deprecated: Use + Conditions instead. This will be removed in a future release." type: string startTime: description: StartTime is the time the build is actually started. format: date-time type: string succeeded: - description: The Succeeded status of the TaskRun + description: "The Succeeded status of the TaskRun \n Deprecated: Use + Conditions instead. This will be removed in a future release." type: string type: object type: object diff --git a/deploy/crds/shipwright.io_builds.yaml b/deploy/crds/shipwright.io_builds.yaml index c1df11ddd3..b2bbd6b25f 100644 --- a/deploy/crds/shipwright.io_builds.yaml +++ b/deploy/crds/shipwright.io_builds.yaml @@ -59,12 +59,12 @@ spec: description: BuildSpec defines the desired state of Build properties: builder: - description: BuilderImage refers to the image containing the build - tools inside which the source code would be built. + description: Builder refers to the image containing the build tools + inside which the source code would be built. properties: credentials: - description: SecretRef is a reference to the Secret containing - the credentials to push the image to the registry + description: Credentials references a Secret that contains credentials + to access the image registry. properties: name: description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names @@ -72,8 +72,7 @@ spec: type: string type: object image: - description: ImageURL is the URL where the image will be pushed - to. + description: Image is the reference of the image. type: string required: - image @@ -83,12 +82,12 @@ spec: build strategies which bank on the Dockerfile for building an image. type: string output: - description: Output refers to the location where the generated image - would be pushed to. + description: Output refers to the location where the built image would + be pushed. properties: credentials: - description: SecretRef is a reference to the Secret containing - the credentials to push the image to the registry + description: Credentials references a Secret that contains credentials + to access the image registry. properties: name: description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names @@ -96,8 +95,7 @@ spec: type: string type: object image: - description: ImageURL is the URL where the image will be pushed - to. + description: Image is the reference of the image. type: string required: - image @@ -120,14 +118,14 @@ spec: type: object type: array runtime: - description: Runtime represents the runtime-image + description: Runtime represents the runtime-image. properties: base: description: Base runtime base image. properties: credentials: - description: SecretRef is a reference to the Secret containing - the credentials to push the image to the registry + description: Credentials references a Secret that contains + credentials to access the image registry. properties: name: description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names @@ -135,8 +133,7 @@ spec: type: string type: object image: - description: ImageURL is the URL where the image will be pushed - to. + description: Image is the reference of the image. type: string required: - image @@ -194,8 +191,8 @@ spec: description: ContextDir is a path to subfolder in the repo. Optional. type: string credentials: - description: SecretRef refers to the secret that contains credentials - to access the git repo. Optional. + description: Credentials references a Secret that contains credentials + to access the repository. properties: name: description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names @@ -203,19 +200,19 @@ spec: type: string type: object revision: - description: Ref is a git reference. Optional. If not defined, - it will fallback to the git repository default branch. + description: "Revision describes the Git revision (e.g., branch, + tag, commit SHA, etc.) to fetch. \n If not defined, it will + fallback to the repository's default branch." type: string url: - description: URL of the git repo + description: URL describes the URL of the Git repository. type: string required: - url type: object strategy: - description: StrategyRef refers to the BuildStrategy to be used to - build the container image. There are namespaced scope and cluster - scope BuildStrategy + description: Strategy references the BuildStrategy to use to build + the container image. properties: apiVersion: description: API version of the referent @@ -231,7 +228,8 @@ spec: - name type: object timeout: - description: Timeout defines the maximum run time of a build run. + description: Timeout defines the maximum amount of time the Build + should take to execute. format: duration type: string required: diff --git a/pkg/apis/build/v1alpha1/build_types.go b/pkg/apis/build/v1alpha1/build_types.go index 64f77e8cf2..a6b3192a3c 100644 --- a/pkg/apis/build/v1alpha1/build_types.go +++ b/pkg/apis/build/v1alpha1/build_types.go @@ -65,38 +65,41 @@ const ( type BuildSpec struct { // Source refers to the Git repository containing the // source code to be built. - Source GitSource `json:"source"` + Source Source `json:"source"` - // StrategyRef refers to the BuildStrategy to be used to - // build the container image. - // There are namespaced scope and cluster scope BuildStrategy - StrategyRef *StrategyRef `json:"strategy"` + // Strategy references the BuildStrategy to use to build the container + // image. + Strategy *Strategy `json:"strategy"` - // BuilderImage refers to the image containing the build tools - // inside which the source code would be built. + // Builder refers to the image containing the build tools inside which + // the source code would be built. + // // +optional - BuilderImage *Image `json:"builder,omitempty"` + Builder *Image `json:"builder,omitempty"` // Dockerfile is the path to the Dockerfile to be used for // build strategies which bank on the Dockerfile for building // an image. + // // +optional Dockerfile *string `json:"dockerfile,omitempty"` // Parameters contains name-value that could be used to loosely // type parameters in the BuildStrategy. + // // +optional Parameters *[]Parameter `json:"parameters,omitempty"` - // Runtime represents the runtime-image + // Runtime represents the runtime-image. + // // +optional Runtime *Runtime `json:"runtime,omitempty"` - // Output refers to the location where the generated - // image would be pushed to. + // Output refers to the location where the built image would be pushed. Output Image `json:"output"` - // Timeout defines the maximum run time of a build run. + // Timeout defines the maximum amount of time the Build should take to execute. + // // +optional // +kubebuilder:validation:Format=duration Timeout *metav1.Duration `json:"timeout,omitempty"` @@ -104,13 +107,14 @@ type BuildSpec struct { // Image refers to an container image with credentials type Image struct { - // ImageURL is the URL where the image will be pushed to. - ImageURL string `json:"image"` + // Image is the reference of the image. + Image string `json:"image"` - // SecretRef is a reference to the Secret containing the - // credentials to push the image to the registry + // Credentials references a Secret that contains credentials to access + // the image registry. + // // +optional - SecretRef *corev1.LocalObjectReference `json:"credentials,omitempty"` + Credentials *corev1.LocalObjectReference `json:"credentials,omitempty"` } // Runtime represents the runtime-image, created using parts of builder-image, and a different diff --git a/pkg/apis/build/v1alpha1/buildrun_types.go b/pkg/apis/build/v1alpha1/buildrun_types.go index 276df5d05e..2728420769 100644 --- a/pkg/apis/build/v1alpha1/buildrun_types.go +++ b/pkg/apis/build/v1alpha1/buildrun_types.go @@ -22,7 +22,6 @@ const ( // BuildRunSpec defines the desired state of BuildRun type BuildRunSpec struct { - // BuildRef refers to the Build BuildRef *BuildRef `json:"buildRef"` diff --git a/pkg/apis/build/v1alpha1/buildstrategy.go b/pkg/apis/build/v1alpha1/buildstrategy.go index 13d31766a3..70af296067 100644 --- a/pkg/apis/build/v1alpha1/buildstrategy.go +++ b/pkg/apis/build/v1alpha1/buildstrategy.go @@ -34,9 +34,9 @@ type BuildStrategyStatus struct { // BuildStrategyKind defines the type of BuildStrategy used by the build. type BuildStrategyKind string -// StrategyRef can be used to refer to a specific instance of a buildstrategy. +// Strategy can be used to refer to a specific instance of a buildstrategy. // Copied from CrossVersionObjectReference: https://github.com/kubernetes/kubernetes/blob/169df7434155cbbc22f1532cba8e0a9588e29ad8/pkg/apis/autoscaling/types.go#L64 -type StrategyRef struct { +type Strategy struct { // Name of the referent; More info: http://kubernetes.io/docs/user-guide/identifiers#names Name string `json:"name"` diff --git a/pkg/apis/build/v1alpha1/gitsource.go b/pkg/apis/build/v1alpha1/gitsource.go deleted file mode 100644 index 56b251066f..0000000000 --- a/pkg/apis/build/v1alpha1/gitsource.go +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright The Shipwright Contributors -// -// SPDX-License-Identifier: Apache-2.0 - -package v1alpha1 - -import ( - corev1 "k8s.io/api/core/v1" -) - -// GitSource contains the versioned source code metadata -// This is similar to OpenShift BuildConfig Git Source API -type GitSource struct { - - // URL of the git repo - URL string `json:"url"` - - // Ref is a git reference. Optional. If not defined, it will fallback to the git repository default branch. - Revision *string `json:"revision,omitempty"` - - // ContextDir is a path to subfolder in the repo. Optional. - // +optional - ContextDir *string `json:"contextDir,omitempty"` - - // SecretRef refers to the secret that contains credentials to access the git repo. Optional. - SecretRef *corev1.LocalObjectReference `json:"credentials,omitempty"` -} diff --git a/pkg/apis/build/v1alpha1/source.go b/pkg/apis/build/v1alpha1/source.go new file mode 100644 index 0000000000..36ecf27396 --- /dev/null +++ b/pkg/apis/build/v1alpha1/source.go @@ -0,0 +1,34 @@ +// Copyright The Shipwright Contributors +// +// SPDX-License-Identifier: Apache-2.0 + +package v1alpha1 + +import ( + corev1 "k8s.io/api/core/v1" +) + +// Source describes the Git source repository to fetch. +type Source struct { + // URL describes the URL of the Git repository. + URL string `json:"url"` + + // Revision describes the Git revision (e.g., branch, tag, commit SHA, + // etc.) to fetch. + // + // If not defined, it will fallback to the repository's default branch. + // + // +optional + Revision *string `json:"revision,omitempty"` + + // ContextDir is a path to subfolder in the repo. Optional. + // + // +optional + ContextDir *string `json:"contextDir,omitempty"` + + // Credentials references a Secret that contains credentials to access + // the repository. + // + // +optional + Credentials *corev1.LocalObjectReference `json:"credentials,omitempty"` +} diff --git a/pkg/apis/build/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/build/v1alpha1/zz_generated.deepcopy.go index 38365987ec..bb949e540f 100644 --- a/pkg/apis/build/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/build/v1alpha1/zz_generated.deepcopy.go @@ -238,13 +238,13 @@ func (in *BuildRunStatus) DeepCopy() *BuildRunStatus { func (in *BuildSpec) DeepCopyInto(out *BuildSpec) { *out = *in in.Source.DeepCopyInto(&out.Source) - if in.StrategyRef != nil { - in, out := &in.StrategyRef, &out.StrategyRef - *out = new(StrategyRef) + if in.Strategy != nil { + in, out := &in.Strategy, &out.Strategy + *out = new(Strategy) (*in).DeepCopyInto(*out) } - if in.BuilderImage != nil { - in, out := &in.BuilderImage, &out.BuilderImage + if in.Builder != nil { + in, out := &in.Builder, &out.Builder *out = new(Image) (*in).DeepCopyInto(*out) } @@ -535,42 +535,11 @@ func (in *FailedAt) DeepCopy() *FailedAt { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *GitSource) DeepCopyInto(out *GitSource) { - *out = *in - if in.Revision != nil { - in, out := &in.Revision, &out.Revision - *out = new(string) - **out = **in - } - if in.ContextDir != nil { - in, out := &in.ContextDir, &out.ContextDir - *out = new(string) - **out = **in - } - if in.SecretRef != nil { - in, out := &in.SecretRef, &out.SecretRef - *out = new(corev1.LocalObjectReference) - **out = **in - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GitSource. -func (in *GitSource) DeepCopy() *GitSource { - if in == nil { - return nil - } - out := new(GitSource) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Image) DeepCopyInto(out *Image) { *out = *in - if in.SecretRef != nil { - in, out := &in.SecretRef, &out.SecretRef + if in.Credentials != nil { + in, out := &in.Credentials, &out.Credentials *out = new(corev1.LocalObjectReference) **out = **in } @@ -676,7 +645,38 @@ func (in *ServiceAccount) DeepCopy() *ServiceAccount { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *StrategyRef) DeepCopyInto(out *StrategyRef) { +func (in *Source) DeepCopyInto(out *Source) { + *out = *in + if in.Revision != nil { + in, out := &in.Revision, &out.Revision + *out = new(string) + **out = **in + } + if in.ContextDir != nil { + in, out := &in.ContextDir, &out.ContextDir + *out = new(string) + **out = **in + } + if in.Credentials != nil { + in, out := &in.Credentials, &out.Credentials + *out = new(corev1.LocalObjectReference) + **out = **in + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Source. +func (in *Source) DeepCopy() *Source { + if in == nil { + return nil + } + out := new(Source) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Strategy) DeepCopyInto(out *Strategy) { *out = *in if in.Kind != nil { in, out := &in.Kind, &out.Kind @@ -686,12 +686,12 @@ func (in *StrategyRef) DeepCopyInto(out *StrategyRef) { return } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new StrategyRef. -func (in *StrategyRef) DeepCopy() *StrategyRef { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Strategy. +func (in *Strategy) DeepCopy() *Strategy { if in == nil { return nil } - out := new(StrategyRef) + out := new(Strategy) in.DeepCopyInto(out) return out } diff --git a/pkg/apis/build/v1alpha1/zz_generated.openapi.go b/pkg/apis/build/v1alpha1/zz_generated.openapi.go deleted file mode 100644 index 9408ae9595..0000000000 --- a/pkg/apis/build/v1alpha1/zz_generated.openapi.go +++ /dev/null @@ -1,31 +0,0 @@ -// +build !ignore_autogenerated - -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by openapi-gen. DO NOT EDIT. - -// This file was autogenerated by openapi-gen. Do not edit it manually! - -package v1alpha1 - -import ( - common "k8s.io/kube-openapi/pkg/common" -) - -func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenAPIDefinition { - return map[string]common.OpenAPIDefinition{} -} diff --git a/pkg/reconciler/build/build.go b/pkg/reconciler/build/build.go index a6851156cf..7bc3d4aa9e 100644 --- a/pkg/reconciler/build/build.go +++ b/pkg/reconciler/build/build.go @@ -108,7 +108,7 @@ func (r *ReconcileBuild) Reconcile(request reconcile.Request) (reconcile.Result, } // Increase Build count in metrics - buildmetrics.BuildCountInc(b.Spec.StrategyRef.Name, b.Namespace, b.Name) + buildmetrics.BuildCountInc(b.Spec.Strategy.Name, b.Namespace, b.Name) ctxlog.Debug(ctx, "finishing reconciling Build", namespace, request.Namespace, name, request.Name) return reconcile.Result{}, nil diff --git a/pkg/reconciler/build/build_test.go b/pkg/reconciler/build/build_test.go index 2ea9880d0b..27a0af9968 100644 --- a/pkg/reconciler/build/build_test.go +++ b/pkg/reconciler/build/build_test.go @@ -84,10 +84,10 @@ 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.SecretRef = &corev1.LocalObjectReference{ + buildSample.Spec.Source.Credentials = &corev1.LocalObjectReference{ Name: "non-existing", } - buildSample.Spec.Output.SecretRef = nil + buildSample.Spec.Output.Credentials = nil statusCall := ctl.StubFunc(corev1.ConditionFalse, build.SpecSourceSecretRefNotFound, "referenced secret non-existing not found") statusWriter.UpdateCalls(statusCall) @@ -98,10 +98,10 @@ var _ = Describe("Reconcile Build", func() { }) It("succeeds when the secret exists foobar", func() { - buildSample.Spec.Source.SecretRef = &corev1.LocalObjectReference{ + buildSample.Spec.Source.Credentials = &corev1.LocalObjectReference{ Name: "existing", } - buildSample.Spec.Output.SecretRef = nil + buildSample.Spec.Output.Credentials = nil // Fake some client Get calls and ensure we populate all // different resources we could get during reconciliation @@ -130,13 +130,13 @@ var _ = Describe("Reconcile Build", func() { Context("when builder image secret is specified", func() { It("fails when the secret does not exist", func() { - buildSample.Spec.BuilderImage = &build.Image{ - ImageURL: "busybox", - SecretRef: &corev1.LocalObjectReference{ + buildSample.Spec.Builder = &build.Image{ + Image: "busybox", + Credentials: &corev1.LocalObjectReference{ Name: "non-existing", }, } - buildSample.Spec.Output.SecretRef = nil + buildSample.Spec.Output.Credentials = nil statusCall := ctl.StubFunc(corev1.ConditionFalse, build.SpecBuilderSecretRefNotFound, "referenced secret non-existing not found") statusWriter.UpdateCalls(statusCall) @@ -147,13 +147,13 @@ var _ = Describe("Reconcile Build", func() { }) It("succeeds when the secret exists", func() { - buildSample.Spec.BuilderImage = &build.Image{ - ImageURL: "busybox", - SecretRef: &corev1.LocalObjectReference{ + buildSample.Spec.Builder = &build.Image{ + Image: "busybox", + Credentials: &corev1.LocalObjectReference{ Name: "existing", }, } - buildSample.Spec.Output.SecretRef = nil + buildSample.Spec.Output.Credentials = nil // Fake some client Get calls and ensure we populate all // different resources we could get during reconciliation @@ -218,10 +218,10 @@ 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.SecretRef = &corev1.LocalObjectReference{ + buildSample.Spec.Source.Credentials = &corev1.LocalObjectReference{ Name: "non-existing-source", } - buildSample.Spec.Output.SecretRef = &corev1.LocalObjectReference{ + buildSample.Spec.Output.Credentials = &corev1.LocalObjectReference{ Name: "non-existing-output", } @@ -453,7 +453,7 @@ var _ = Describe("Reconcile Build", func() { 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 = "https://github.yourco.com/org/build-fake" - buildSample.Spec.Source.SecretRef.Name = registrySecret + buildSample.Spec.Source.Credentials.Name = registrySecret // 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 671f8d5ee2..cd588fb2c4 100644 --- a/pkg/reconciler/build/controller.go +++ b/pkg/reconciler/build/controller.go @@ -96,7 +96,7 @@ func add(ctx context.Context, mgr manager.Manager, r reconcile.Reconciler, maxCo // Only filter events where the secret have the Build specific annotation CreateFunc: func(e event.CreateEvent) bool { objectAnnotations := e.Meta.GetAnnotations() - if _, ok := buildSecretRefAnnotationExist(objectAnnotations); ok { + if _, ok := buildCredentialsAnnotationExist(objectAnnotations); ok { return true } return false @@ -108,8 +108,8 @@ func add(ctx context.Context, mgr manager.Manager, r reconcile.Reconciler, maxCo oldAnnotations := e.MetaOld.GetAnnotations() newAnnotations := e.MetaNew.GetAnnotations() - if _, oldBuildKey := buildSecretRefAnnotationExist(oldAnnotations); !oldBuildKey { - if _, newBuildKey := buildSecretRefAnnotationExist(newAnnotations); newBuildKey { + if _, oldBuildKey := buildCredentialsAnnotationExist(oldAnnotations); !oldBuildKey { + if _, newBuildKey := buildCredentialsAnnotationExist(newAnnotations); newBuildKey { return true } } @@ -119,7 +119,7 @@ func add(ctx context.Context, mgr manager.Manager, r reconcile.Reconciler, maxCo // Only filter events where the secret have the Build specific annotation DeleteFunc: func(e event.DeleteEvent) bool { objectAnnotations := e.Meta.GetAnnotations() - if _, ok := buildSecretRefAnnotationExist(objectAnnotations); ok { + if _, ok := buildCredentialsAnnotationExist(objectAnnotations); ok { return true } return false @@ -152,18 +152,18 @@ func add(ctx context.Context, mgr manager.Manager, r reconcile.Reconciler, maxCo flagReconcile := false for _, build := range buildList.Items { - if build.Spec.Source.SecretRef != nil { - if build.Spec.Source.SecretRef.Name == secret.Name { + if build.Spec.Source.Credentials != nil { + if build.Spec.Source.Credentials.Name == secret.Name { flagReconcile = true } } - if build.Spec.Output.SecretRef != nil { - if build.Spec.Output.SecretRef.Name == secret.Name { + if build.Spec.Output.Credentials != nil { + if build.Spec.Output.Credentials.Name == secret.Name { flagReconcile = true } } - if build.Spec.BuilderImage != nil && build.Spec.BuilderImage.SecretRef != nil { - if build.Spec.BuilderImage.SecretRef.Name == secret.Name { + if build.Spec.Builder != nil && build.Spec.Builder.Credentials != nil { + if build.Spec.Builder.Credentials.Name == secret.Name { flagReconcile = true } } @@ -181,7 +181,7 @@ func add(ctx context.Context, mgr manager.Manager, r reconcile.Reconciler, maxCo }, preSecret) } -func buildSecretRefAnnotationExist(annotation map[string]string) (string, bool) { +func buildCredentialsAnnotationExist(annotation map[string]string) (string, bool) { if val, ok := annotation[build.AnnotationBuildRefSecret]; ok { return val, true } diff --git a/pkg/reconciler/buildrun/buildrun.go b/pkg/reconciler/buildrun/buildrun.go index ecc60aec8a..189cc9890a 100644 --- a/pkg/reconciler/buildrun/buildrun.go +++ b/pkg/reconciler/buildrun/buildrun.go @@ -204,11 +204,11 @@ func (r *ReconcileBuildRun) Reconcile(request reconcile.Request) (reconcile.Resu } // Increase BuildRun count in metrics - buildmetrics.BuildRunCountInc(buildRun.Status.BuildSpec.StrategyRef.Name, buildRun.Namespace, buildRun.Spec.BuildRef.Name, buildRun.Name) + buildmetrics.BuildRunCountInc(buildRun.Status.BuildSpec.Strategy.Name, buildRun.Namespace, buildRun.Spec.BuildRef.Name, buildRun.Name) // Report buildrun ramp-up duration (time between buildrun creation and taskrun creation) buildmetrics.BuildRunRampUpDurationObserve( - buildRun.Status.BuildSpec.StrategyRef.Name, + buildRun.Status.BuildSpec.Strategy.Name, buildRun.Namespace, buildRun.Spec.BuildRef.Name, buildRun.Name, @@ -274,7 +274,7 @@ func (r *ReconcileBuildRun) Reconcile(request reconcile.Request) (reconcile.Resu // Report the buildrun established duration (time between the creation of the buildrun and the start of the buildrun) buildmetrics.BuildRunEstablishObserve( - buildRun.Status.BuildSpec.StrategyRef.Name, + buildRun.Status.BuildSpec.Strategy.Name, buildRun.Namespace, buildRun.Spec.BuildRef.Name, buildRun.Name, @@ -285,10 +285,10 @@ func (r *ReconcileBuildRun) Reconcile(request reconcile.Request) (reconcile.Resu if lastTaskRun.Status.CompletionTime != nil && buildRun.Status.CompletionTime == nil { buildRun.Status.CompletionTime = lastTaskRun.Status.CompletionTime - if buildRun.Status.BuildSpec.StrategyRef != nil { + if buildRun.Status.BuildSpec.Strategy != nil { // buildrun completion duration (total time between the creation of the buildrun and the buildrun completion) buildmetrics.BuildRunCompletionObserve( - buildRun.Status.BuildSpec.StrategyRef.Name, + buildRun.Status.BuildSpec.Strategy.Name, buildRun.Namespace, buildRun.Spec.BuildRef.Name, buildRun.Name, @@ -306,7 +306,7 @@ func (r *ReconcileBuildRun) Reconcile(request reconcile.Request) (reconcile.Resu if lastInitPod.State.Terminated != nil { // taskrun pod ramp-up (time between pod creation and last init container completion) buildmetrics.TaskRunPodRampUpDurationObserve( - buildRun.Status.BuildSpec.StrategyRef.Name, + buildRun.Status.BuildSpec.Strategy.Name, buildRun.Namespace, buildRun.Spec.BuildRef.Name, buildRun.Name, @@ -317,7 +317,7 @@ func (r *ReconcileBuildRun) Reconcile(request reconcile.Request) (reconcile.Resu // taskrun ramp-up duration (time between taskrun creation and taskrun pod creation) buildmetrics.TaskRunRampUpDurationObserve( - buildRun.Status.BuildSpec.StrategyRef.Name, + buildRun.Status.BuildSpec.Strategy.Name, buildRun.Namespace, buildRun.Spec.BuildRef.Name, buildRun.Name, @@ -372,8 +372,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) { - - if build.Spec.StrategyRef.Kind == nil { + 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) strategy, err = resources.RetrieveBuildStrategy(ctx, r.client, build) @@ -387,7 +386,7 @@ func (r *ReconcileBuildRun) getReferencedStrategy(ctx context.Context, build *bu return strategy, err } - switch *build.Spec.StrategyRef.Kind { + switch *build.Spec.Strategy.Kind { case buildv1alpha1.NamespacedBuildStrategyKind: strategy, err = resources.RetrieveBuildStrategy(ctx, r.client, build) if err != nil { @@ -407,7 +406,7 @@ func (r *ReconcileBuildRun) getReferencedStrategy(ctx context.Context, build *bu } } default: - err = fmt.Errorf("unknown strategy %s", string(*build.Spec.StrategyRef.Kind)) + err = fmt.Errorf("unknown strategy %s", string(*build.Spec.Strategy.Kind)) if updateErr := resources.UpdateConditionWithFalseStatus(ctx, r.client, buildRun, err.Error(), resources.ConditionUnknownStrategyKind); updateErr != nil { return nil, resources.HandleError("failed to get referenced strategy", err, updateErr) } diff --git a/pkg/reconciler/buildrun/resources/credentials.go b/pkg/reconciler/buildrun/resources/credentials.go index 3939cd5c2d..1a7845cf58 100644 --- a/pkg/reconciler/buildrun/resources/credentials.go +++ b/pkg/reconciler/buildrun/resources/credentials.go @@ -20,19 +20,19 @@ func ApplyCredentials(ctx context.Context, build *buildv1alpha1.Build, serviceAc modified := false // credentials of the source/git repo - sourceSecret := build.Spec.Source.SecretRef + sourceSecret := build.Spec.Source.Credentials if sourceSecret != nil { modified = updateServiceAccountIfSecretNotLinked(ctx, sourceSecret, serviceAccount) || modified } // credentials of the 'Builder' image registry - builderImage := build.Spec.BuilderImage - if builderImage != nil && builderImage.SecretRef != nil { - modified = updateServiceAccountIfSecretNotLinked(ctx, builderImage.SecretRef, serviceAccount) || modified + builderImage := build.Spec.Builder + if builderImage != nil && builderImage.Credentials != nil { + modified = updateServiceAccountIfSecretNotLinked(ctx, builderImage.Credentials, serviceAccount) || modified } // credentials of the 'output' image registry - sourceSecret = build.Spec.Output.SecretRef + sourceSecret = build.Spec.Output.Credentials if sourceSecret != nil { modified = updateServiceAccountIfSecretNotLinked(ctx, sourceSecret, serviceAccount) || modified } diff --git a/pkg/reconciler/buildrun/resources/credentials_test.go b/pkg/reconciler/buildrun/resources/credentials_test.go index 36e046636f..60dff6774d 100644 --- a/pkg/reconciler/buildrun/resources/credentials_test.go +++ b/pkg/reconciler/buildrun/resources/credentials_test.go @@ -37,21 +37,21 @@ var _ = Describe("Credentials", func() { BeforeEach(func() { build = &buildv1alpha1.Build{ Spec: buildv1alpha1.BuildSpec{ - Source: buildv1alpha1.GitSource{ + Source: buildv1alpha1.Source{ URL: "a/b/c", - SecretRef: &corev1.LocalObjectReference{ + Credentials: &corev1.LocalObjectReference{ Name: "secret_a", }, }, - BuilderImage: &buildv1alpha1.Image{ - ImageURL: "quay.io/namespace/image", - SecretRef: &corev1.LocalObjectReference{ + Builder: &buildv1alpha1.Image{ + Image: "quay.io/namespace/image", + Credentials: &corev1.LocalObjectReference{ Name: "secret_docker.io", }, }, Output: buildv1alpha1.Image{ - ImageURL: "quay.io/namespace/image", - SecretRef: &corev1.LocalObjectReference{ + Image: "quay.io/namespace/image", + Credentials: &corev1.LocalObjectReference{ Name: "secret_quay.io", }, }, @@ -79,9 +79,9 @@ var _ = Describe("Credentials", func() { BeforeEach(func() { build = &buildv1alpha1.Build{ Spec: buildv1alpha1.BuildSpec{ - Source: buildv1alpha1.GitSource{ + Source: buildv1alpha1.Source{ URL: "a/b/c", - SecretRef: &corev1.LocalObjectReference{ + Credentials: &corev1.LocalObjectReference{ Name: "secret_b", }, }, @@ -105,9 +105,9 @@ var _ = Describe("Credentials", func() { BeforeEach(func() { build = &buildv1alpha1.Build{ Spec: buildv1alpha1.BuildSpec{ - Source: buildv1alpha1.GitSource{ - URL: "a/b/c", - SecretRef: nil, + Source: buildv1alpha1.Source{ + URL: "a/b/c", + Credentials: nil, }, }, } diff --git a/pkg/reconciler/buildrun/resources/runtime_image.go b/pkg/reconciler/buildrun/resources/runtime_image.go index db2f245cf3..3bfdf71c71 100644 --- a/pkg/reconciler/buildrun/resources/runtime_image.go +++ b/pkg/reconciler/buildrun/resources/runtime_image.go @@ -23,9 +23,9 @@ import ( const ( // runtimeDockerfileTmpl Dockerfile template to be used with runtime-image, it uses Build // attributes directly as template input. - runtimeDockerfileTmpl = `FROM {{ .Spec.Output.ImageURL }} as builder + runtimeDockerfileTmpl = `FROM {{ .Spec.Output.Image }} as builder -FROM {{ .Spec.Runtime.Base.ImageURL }} +FROM {{ .Spec.Runtime.Base.Image }} {{- range $k, $v := .Spec.Runtime.Env }} ENV {{ $k }}="{{ $v }}" @@ -164,8 +164,8 @@ func runtimeDockerfileStep(b *buildv1alpha1.Build) (*v1beta1.Step, error) { // using builder-image when defined, or falling back to a default imageURL := defultShellImage - if isBuilderImageDefined(b) { - imageURL = b.Spec.BuilderImage.ImageURL + if isBuilderDefined(b) { + imageURL = b.Spec.Builder.Image } container := v1.Container{ @@ -216,7 +216,7 @@ func runtimeBuildAndPushStep(b *buildv1alpha1.Build, kanikoImage string) *v1beta "--skip-tls-verify=true", fmt.Sprintf("--dockerfile=%s", runtimeDockerfile), fmt.Sprintf("--context=%x", path.Join(workspaceDir, contextDir)), - fmt.Sprintf("--destination=%s", b.Spec.Output.ImageURL), + fmt.Sprintf("--destination=%s", b.Spec.Output.Image), "--snapshotMode=redo", "--oci-layout-path=/workspace/output/image", }, @@ -242,24 +242,24 @@ func AmendTaskSpecWithRuntimeImage( return nil } -// isBuilderImageDefined inspect if build contains `.spec.BuilderImage` defined. -func isBuilderImageDefined(b *buildv1alpha1.Build) bool { - if b.Spec.BuilderImage == nil { +// isBuilderDefined inspect if build contains `.spec.Builder` defined. +func isBuilderDefined(b *buildv1alpha1.Build) bool { + if b.Spec.Builder == nil { return false } - if b.Spec.BuilderImage.ImageURL == "" { + if b.Spec.Builder.Image == "" { return false } return true } // IsRuntimeDefined inspect if build has `.spec.runtime` defined, checking intermediary attributes -// and making sure ImageURL is informed. +// and making sure Image is informed. func IsRuntimeDefined(b *buildv1alpha1.Build) bool { if b.Spec.Runtime == nil { return false } - if b.Spec.Runtime.Base.ImageURL == "" { + if b.Spec.Runtime.Base.Image == "" { return false } return true diff --git a/pkg/reconciler/buildrun/resources/runtime_image_test.go b/pkg/reconciler/buildrun/resources/runtime_image_test.go index 6094eee302..dfc9255d0a 100644 --- a/pkg/reconciler/buildrun/resources/runtime_image_test.go +++ b/pkg/reconciler/buildrun/resources/runtime_image_test.go @@ -18,15 +18,15 @@ import ( var _ = Describe("runtime-image", func() { b := &buildv1alpha1.Build{ Spec: buildv1alpha1.BuildSpec{ - BuilderImage: &buildv1alpha1.Image{ - ImageURL: "test/builder-image:latest", + Builder: &buildv1alpha1.Image{ + Image: "test/builder-image:latest", }, Output: buildv1alpha1.Image{ - ImageURL: "test/output-image:latest", + Image: "test/output-image:latest", }, Runtime: &buildv1alpha1.Runtime{ Base: buildv1alpha1.Image{ - ImageURL: "test/base-image:latest", + Image: "test/base-image:latest", }, Env: map[string]string{ "ENVIRONMENT_VARIABLE": "VALUE", diff --git a/pkg/reconciler/buildrun/resources/strategies.go b/pkg/reconciler/buildrun/resources/strategies.go index f613d8454d..536b031467 100644 --- a/pkg/reconciler/buildrun/resources/strategies.go +++ b/pkg/reconciler/buildrun/resources/strategies.go @@ -21,7 +21,7 @@ func RetrieveBuildStrategy(ctx context.Context, client client.Client, build *bui ctxlog.Debug(ctx, "retrieving BuildStrategy", namespace, build.Namespace, name, build.Name) // Note: When returning the client.Get call, the buildStrategyInstance gets populated and properly returned as the first argument - return buildStrategyInstance, client.Get(ctx, types.NamespacedName{Name: build.Spec.StrategyRef.Name, Namespace: build.Namespace}, buildStrategyInstance) + return buildStrategyInstance, client.Get(ctx, types.NamespacedName{Name: build.Spec.Strategy.Name, Namespace: build.Namespace}, buildStrategyInstance) } // RetrieveClusterBuildStrategy returns a cluster scoped strategy @@ -31,5 +31,5 @@ func RetrieveClusterBuildStrategy(ctx context.Context, client client.Client, bui ctxlog.Debug(ctx, "retrieving ClusterBuildStrategy", namespace, build.Namespace, name, build.Name) // Note: When returning the client.Get call, the clusterBuildStrategyInstance gets populated and properly returned as the first argument - return clusterBuildStrategyInstance, client.Get(ctx, types.NamespacedName{Name: build.Spec.StrategyRef.Name}, clusterBuildStrategyInstance) + return clusterBuildStrategyInstance, client.Get(ctx, types.NamespacedName{Name: build.Spec.Strategy.Name}, clusterBuildStrategyInstance) } diff --git a/pkg/reconciler/buildrun/resources/taskrun.go b/pkg/reconciler/buildrun/resources/taskrun.go index 0cac734612..c49568f26d 100644 --- a/pkg/reconciler/buildrun/resources/taskrun.go +++ b/pkg/reconciler/buildrun/resources/taskrun.go @@ -23,7 +23,7 @@ const ( inputSourceResourceName = "source" inputGitSourceURL = "url" inputGitSourceRevision = "revision" - inputParamBuilderImage = "BUILDER_IMAGE" + inputParamBuilder = "BUILDER_IMAGE" inputParamDockerfile = "DOCKERFILE" inputParamContextDir = "CONTEXT_DIR" outputImageResourceName = "image" @@ -36,7 +36,7 @@ func getStringTransformations(fullText string) string { stringTransformations := map[string]string{ "$(build.output.image)": "$(outputs.resources.image.url)", - "$(build.builder.image)": fmt.Sprintf("$(inputs.params.%s)", inputParamBuilderImage), + "$(build.builder.image)": fmt.Sprintf("$(inputs.params.%s)", inputParamBuilder), "$(build.dockerfile)": fmt.Sprintf("$(inputs.params.%s)", inputParamDockerfile), "$(build.source.contextDir)": fmt.Sprintf("$(inputs.params.%s)", inputParamContextDir), } @@ -98,16 +98,16 @@ func GenerateTaskSpec( Steps: []v1beta1.Step{}, } - if build.Spec.BuilderImage != nil { - InputBuilderImage := v1beta1.ParamSpec{ + if build.Spec.Builder != nil { + InputBuilder := v1beta1.ParamSpec{ Description: "Image containing the build tools/logic", - Name: inputParamBuilderImage, + Name: inputParamBuilder, Default: &v1beta1.ArrayOrString{ Type: v1beta1.ParamTypeString, - StringVal: build.Spec.BuilderImage.ImageURL, + StringVal: build.Spec.Builder.Image, }, } - generatedTaskSpec.Params = append(generatedTaskSpec.Params, InputBuilderImage) + generatedTaskSpec.Params = append(generatedTaskSpec.Params, InputBuilder) } var vols []corev1.Volume @@ -189,11 +189,11 @@ func GenerateTaskRun( } // retrieve expected imageURL form build or buildRun - var ImageURL string + var Image string if buildRun.Spec.Output != nil { - ImageURL = buildRun.Spec.Output.ImageURL + Image = buildRun.Spec.Output.Image } else { - ImageURL = build.Spec.Output.ImageURL + Image = build.Spec.Output.Image } taskSpec, err := GenerateTaskSpec(cfg, build, buildRun, strategy.GetBuildSteps()) @@ -245,7 +245,7 @@ func GenerateTaskRun( Params: []taskv1.ResourceParam{ { Name: outputImageResourceURL, - Value: ImageURL, + Value: Image, }, }, }, @@ -274,12 +274,12 @@ func GenerateTaskRun( expectedTaskRun.Spec.Timeout = effectiveTimeout(build, buildRun) var inputParams []v1beta1.Param - if build.Spec.BuilderImage != nil { + if build.Spec.Builder != nil { inputParams = append(inputParams, v1beta1.Param{ - Name: inputParamBuilderImage, + Name: inputParamBuilder, Value: v1beta1.ArrayOrString{ Type: v1beta1.ParamTypeString, - StringVal: build.Spec.BuilderImage.ImageURL, + StringVal: build.Spec.Builder.Image, }, }) } diff --git a/pkg/reconciler/buildrun/resources/taskrun_test.go b/pkg/reconciler/buildrun/resources/taskrun_test.go index 0b2b5f1ae7..4f3fe0f540 100644 --- a/pkg/reconciler/buildrun/resources/taskrun_test.go +++ b/pkg/reconciler/buildrun/resources/taskrun_test.go @@ -48,7 +48,7 @@ var _ = Describe("GenerateTaskrun", func() { ) BeforeEach(func() { builderImage = &buildv1alpha1.Image{ - ImageURL: "quay.io/builder/image", + Image: "quay.io/builder/image", } }) @@ -123,7 +123,7 @@ var _ = Describe("GenerateTaskrun", func() { contextDir = "docker-build" revision = "" builderImage = &buildv1alpha1.Image{ - ImageURL: "heroku/buildpacks:18", + Image: "heroku/buildpacks:18", } outputPath = "image-registry.openshift-image-registry.svc:5000/example/buildpacks-app" outputPathBuildRun = "image-registry.openshift-image-registry.svc:5000/example/buildpacks-app-v2" @@ -154,7 +154,7 @@ var _ = Describe("GenerateTaskrun", func() { 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.StrategyRef.Name)) + Expect(got.Labels[buildv1alpha1.LabelBuildStrategyName]).To(Equal(build.Spec.Strategy.Name)) Expect(got.Labels[buildv1alpha1.LabelBuildStrategyGeneration]).To(Equal("0")) }) @@ -239,7 +239,7 @@ var _ = Describe("GenerateTaskrun", func() { params := got.Spec.Params for _, param := range params { if param.Name == "BUILDER_IMAGE" { - Expect(param.Value.StringVal).To(Equal(builderImage.ImageURL)) + Expect(param.Value.StringVal).To(Equal(builderImage.Image)) } if param.Name == "DOCKERFILE" { Expect(param.Value.StringVal).To(Equal(dockerfile)) diff --git a/pkg/validate/secrets.go b/pkg/validate/secrets.go index 780e4ca0b8..c16c3e27ba 100644 --- a/pkg/validate/secrets.go +++ b/pkg/validate/secrets.go @@ -17,20 +17,20 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" ) -// SecretRef contains all required fields +// Credentials contains all required fields // to validate a Build spec secrets definitions -type SecretRef struct { +type Credentials struct { Build *build.Build Client client.Client } // ValidatePath implements BuildPath interface and validates // that all referenced secrets under spec exists -func (s SecretRef) ValidatePath(ctx context.Context) error { +func (s Credentials) ValidatePath(ctx context.Context) error { var missingSecrets []string secret := &corev1.Secret{} - secretNames := s.buildSecretReferences() + secretNames := s.buildCredentialserences() for refSecret, secretType := range secretNames { if err := s.Client.Get(ctx, types.NamespacedName{Name: refSecret, Namespace: s.Build.Namespace}, secret); err != nil && !apierrors.IsNotFound(err) { @@ -52,17 +52,17 @@ func (s SecretRef) ValidatePath(ctx context.Context) error { return nil } -func (s SecretRef) buildSecretReferences() map[string]build.BuildReason { +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.SecretRef != nil && s.Build.Spec.Output.SecretRef.Name != "" { - secretRefMap[s.Build.Spec.Output.SecretRef.Name] = build.SpecOutputSecretRefNotFound + 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.Source.SecretRef != nil && s.Build.Spec.Source.SecretRef.Name != "" { - secretRefMap[s.Build.Spec.Source.SecretRef.Name] = build.SpecSourceSecretRefNotFound + 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.BuilderImage != nil && s.Build.Spec.BuilderImage.SecretRef != nil && s.Build.Spec.BuilderImage.SecretRef.Name != "" { - secretRefMap[s.Build.Spec.BuilderImage.SecretRef.Name] = build.SpecBuilderSecretRefNotFound + 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 } return secretRefMap } diff --git a/pkg/validate/sourceurl.go b/pkg/validate/sourceurl.go index 2335f7051d..8732680793 100644 --- a/pkg/validate/sourceurl.go +++ b/pkg/validate/sourceurl.go @@ -25,7 +25,7 @@ type SourceURLRef struct { // 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.SecretRef == nil { + if s.Build.Spec.Source.Credentials == nil { switch s.Build.GetAnnotations()[build.AnnotationBuildVerifyRepository] { case "true": err := git.ValidateGitURLExists(s.Build.Spec.Source.URL) diff --git a/pkg/validate/strategies.go b/pkg/validate/strategies.go index 6d16e98c15..eaf99fe5bd 100644 --- a/pkg/validate/strategies.go +++ b/pkg/validate/strategies.go @@ -15,9 +15,9 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" ) -// StrategyRef contains all required fields +// Strategy contains all required fields // to validate a Build spec strategy definition -type StrategyRef struct { +type Strategy struct { Build *build.Build Client client.Client } @@ -25,24 +25,24 @@ type StrategyRef struct { // ValidatePath implements BuildPath interface and validates // that the referenced strategy exists. This applies to both // namespaced or cluster scoped strategies -func (s StrategyRef) ValidatePath(ctx context.Context) error { - if s.Build.Spec.StrategyRef != nil { - if s.Build.Spec.StrategyRef.Kind != nil { - switch *s.Build.Spec.StrategyRef.Kind { +func (s Strategy) ValidatePath(ctx context.Context) error { + if s.Build.Spec.Strategy != nil { + if s.Build.Spec.Strategy.Kind != nil { + switch *s.Build.Spec.Strategy.Kind { case build.NamespacedBuildStrategyKind: - if err := s.validateBuildStrategy(ctx, s.Build.Spec.StrategyRef.Name, s.Build); err != nil { + if err := s.validateBuildStrategy(ctx, s.Build.Spec.Strategy.Name, s.Build); err != nil { return err } case build.ClusterBuildStrategyKind: - if err := s.validateClusterBuildStrategy(ctx, s.Build.Spec.StrategyRef.Name, s.Build); err != nil { + if err := s.validateClusterBuildStrategy(ctx, s.Build.Spec.Strategy.Name, s.Build); err != nil { return err } default: - return fmt.Errorf("unknown strategy kind: %v", *s.Build.Spec.StrategyRef.Kind) + return fmt.Errorf("unknown strategy kind: %v", *s.Build.Spec.Strategy.Kind) } } else { ctxlog.Info(ctx, "buildStrategy kind is nil, use default NamespacedBuildStrategyKind") - if err := s.validateBuildStrategy(ctx, s.Build.Spec.StrategyRef.Name, s.Build); err != nil { + if err := s.validateBuildStrategy(ctx, s.Build.Spec.Strategy.Name, s.Build); err != nil { return err } } @@ -50,25 +50,25 @@ func (s StrategyRef) ValidatePath(ctx context.Context) error { return nil } -func (s StrategyRef) validateBuildStrategy(ctx context.Context, strategyName string, b *build.Build) error { +func (s Strategy) validateBuildStrategy(ctx context.Context, strategyName string, b *build.Build) error { buildStrategy := &build.BuildStrategy{} if err := s.Client.Get(ctx, types.NamespacedName{Name: strategyName, Namespace: b.Namespace}, buildStrategy); err != nil && !apierrors.IsNotFound(err) { return err } else if apierrors.IsNotFound(err) { b.Status.Reason = build.BuildStrategyNotFound - b.Status.Message = fmt.Sprintf("buildStrategy %s does not exist in namespace %s", b.Spec.StrategyRef.Name, b.Namespace) + b.Status.Message = fmt.Sprintf("buildStrategy %s does not exist in namespace %s", b.Spec.Strategy.Name, b.Namespace) } return nil } -func (s StrategyRef) validateClusterBuildStrategy(ctx context.Context, strategyName string, b *build.Build) error { +func (s Strategy) validateClusterBuildStrategy(ctx context.Context, strategyName string, b *build.Build) error { clusterBuildStrategy := &build.ClusterBuildStrategy{} if err := s.Client.Get(ctx, types.NamespacedName{Name: strategyName}, clusterBuildStrategy); err != nil && !apierrors.IsNotFound(err) { return err } else if apierrors.IsNotFound(err) { b.Status.Reason = build.ClusterBuildStrategyNotFound - b.Status.Message = fmt.Sprintf("clusterBuildStrategy %s does not exist", b.Spec.StrategyRef.Name) + b.Status.Message = fmt.Sprintf("clusterBuildStrategy %s does not exist", b.Spec.Strategy.Name) } return nil } diff --git a/pkg/validate/validate.go b/pkg/validate/validate.go index 98979057c4..b5dd6b17fc 100644 --- a/pkg/validate/validate.go +++ b/pkg/validate/validate.go @@ -43,11 +43,11 @@ func NewValidation( client client.Client, scheme *runtime.Scheme, ) (BuildPath, error) { - secretRef := SecretRef{ + secretRef := Credentials{ Build: build, Client: client, } - strategyRef := StrategyRef{ + strategyRef := Strategy{ Build: build, Client: client, } diff --git a/test/catalog.go b/test/catalog.go index 1766380c98..4b30057f69 100644 --- a/test/catalog.go +++ b/test/catalog.go @@ -61,15 +61,15 @@ func (c *Catalog) BuildWithClusterBuildStrategyAndFalseSourceAnnotation(name str Annotations: map[string]string{build.AnnotationBuildVerifyRepository: "false"}, }, Spec: build.BuildSpec{ - Source: build.GitSource{ + Source: build.Source{ URL: "foobar", }, - StrategyRef: &build.StrategyRef{ + Strategy: &build.Strategy{ Name: strategyName, Kind: &buildStrategy, }, Output: build.Image{ - ImageURL: "foobar", + Image: "foobar", }, }, } @@ -84,16 +84,16 @@ func (c *Catalog) BuildWithClusterBuildStrategy(name string, ns string, strategy Namespace: ns, }, Spec: build.BuildSpec{ - Source: build.GitSource{ + Source: build.Source{ URL: "https://github.com/shipwright-io/sample-go", }, - StrategyRef: &build.StrategyRef{ + Strategy: &build.Strategy{ Name: strategyName, Kind: &buildStrategy, }, Output: build.Image{ - ImageURL: "foobar", - SecretRef: &corev1.LocalObjectReference{ + Image: "foobar", + Credentials: &corev1.LocalObjectReference{ Name: secretName, }, }, @@ -110,18 +110,18 @@ func (c *Catalog) BuildWithClusterBuildStrategyAndSourceSecret(name string, ns s Namespace: ns, }, Spec: build.BuildSpec{ - Source: build.GitSource{ + Source: build.Source{ URL: "https://github.com/shipwright-io/sample-go", - SecretRef: &corev1.LocalObjectReference{ + Credentials: &corev1.LocalObjectReference{ Name: "foobar", }, }, - StrategyRef: &build.StrategyRef{ + Strategy: &build.Strategy{ Name: strategyName, Kind: &buildStrategy, }, Output: build.Image{ - ImageURL: "foobar", + Image: "foobar", }, }, } @@ -136,10 +136,10 @@ func (c *Catalog) BuildWithBuildStrategy(name string, ns string, strategyName st Namespace: ns, }, Spec: build.BuildSpec{ - Source: build.GitSource{ + Source: build.Source{ URL: "https://github.com/shipwright-io/sample-go", }, - StrategyRef: &build.StrategyRef{ + Strategy: &build.Strategy{ Name: strategyName, Kind: &buildStrategy, }, @@ -155,10 +155,10 @@ func (c *Catalog) BuildWithNilBuildStrategyKind(name string, ns string, strategy Namespace: ns, }, Spec: build.BuildSpec{ - Source: build.GitSource{ + Source: build.Source{ URL: "https://github.com/shipwright-io/sample-go", }, - StrategyRef: &build.StrategyRef{ + Strategy: &build.Strategy{ Name: strategyName, }, }, @@ -173,11 +173,11 @@ func (c *Catalog) BuildWithOutputSecret(name string, ns string, secretName strin Namespace: ns, }, Spec: build.BuildSpec{ - Source: build.GitSource{ + Source: build.Source{ URL: "https://github.com/shipwright-io/sample-go", }, Output: build.Image{ - SecretRef: &corev1.LocalObjectReference{ + Credentials: &corev1.LocalObjectReference{ Name: secretName, }, }, @@ -613,7 +613,7 @@ func (c *Catalog) DefaultBuild(buildName string, strategyName string, strategyKi Name: buildName, }, Spec: build.BuildSpec{ - StrategyRef: &build.StrategyRef{ + Strategy: &build.Strategy{ Name: strategyName, Kind: &strategyKind, }, @@ -631,7 +631,7 @@ func (c *Catalog) BuildWithoutStrategyKind(buildName string, strategyName string Name: buildName, }, Spec: build.BuildSpec{ - StrategyRef: &build.StrategyRef{ + Strategy: &build.Strategy{ Name: strategyName, }, }, @@ -650,7 +650,7 @@ func (c *Catalog) BuildWithBuildRunDeletions(buildName string, strategyName stri Annotations: map[string]string{build.AnnotationBuildRunDeletion: "true"}, }, Spec: build.BuildSpec{ - StrategyRef: &build.StrategyRef{ + Strategy: &build.Strategy{ Name: strategyName, Kind: &strategyKind, }, @@ -671,7 +671,7 @@ func (c *Catalog) BuildWithBuildRunDeletionsAndFakeNS(buildName string, strategy Annotations: map[string]string{build.AnnotationBuildRunDeletion: "true"}, }, Spec: build.BuildSpec{ - StrategyRef: &build.StrategyRef{ + Strategy: &build.Strategy{ Name: strategyName, Kind: &strategyKind, }, @@ -689,7 +689,7 @@ func (c *Catalog) DefaultBuildWithFalseRegistered(buildName string, strategyName Name: buildName, }, Spec: build.BuildSpec{ - StrategyRef: &build.StrategyRef{ + Strategy: &build.Strategy{ Name: strategyName, Kind: &strategyKind, }, @@ -748,7 +748,7 @@ func (c *Catalog) BuildRunWithBuildSnapshot(buildRunName string, buildName strin }, Status: build.BuildRunStatus{ BuildSpec: &build.BuildSpec{ - StrategyRef: &build.StrategyRef{ + Strategy: &build.Strategy{ Name: "foobar", }, }, @@ -964,7 +964,7 @@ func (c *Catalog) LoadBuildWithNameAndStrategy(name string, strategy string, d [ return nil, err } b.Name = name - b.Spec.StrategyRef.Name = strategy + b.Spec.Strategy.Name = strategy return b, nil } diff --git a/test/e2e/common_test.go b/test/e2e/common_test.go index ff69a80178..3ee7f65b42 100644 --- a/test/e2e/common_test.go +++ b/test/e2e/common_test.go @@ -50,8 +50,8 @@ func createBuild(testBuild *utils.TestBuild, identifier string, filePath string) return build } -// amendOutputImageURL amend container image URL based on informed image repository. -func amendOutputImageURL(b *buildv1alpha1.Build, imageRepo string) { +// amendOutputImage amend container image URL based on informed image repository. +func amendOutputImage(b *buildv1alpha1.Build, imageRepo string) { if imageRepo == "" { return } @@ -60,25 +60,25 @@ func amendOutputImageURL(b *buildv1alpha1.Build, imageRepo string) { imageTag := removeTestIDSuffix(b.Name) imageURL := fmt.Sprintf("%s:%s", imageRepo, imageTag) - b.Spec.Output.ImageURL = imageURL + b.Spec.Output.Image = imageURL Logf("Amended object: name='%s', image-url='%s'", b.Name, imageURL) } -// amendOutputSecretRef amend secret-ref for output image. -func amendOutputSecretRef(b *buildv1alpha1.Build, secretName string) { +// amendOutputCredentials amend secret-ref for output image. +func amendOutputCredentials(b *buildv1alpha1.Build, secretName string) { if secretName == "" { return } - b.Spec.Output.SecretRef = &corev1.LocalObjectReference{Name: secretName} + b.Spec.Output.Credentials = &corev1.LocalObjectReference{Name: secretName} Logf("Amended object: name='%s', secret-ref='%s'", b.Name, secretName) } -// amendSourceSecretName patch Build source.SecretRef with secret name. +// amendSourceSecretName patch Build source.Credentials with secret name. func amendSourceSecretName(b *buildv1alpha1.Build, secretName string) { if secretName == "" { return } - b.Spec.Source.SecretRef = &corev1.LocalObjectReference{Name: secretName} + b.Spec.Source.Credentials = &corev1.LocalObjectReference{Name: secretName} } // amendSourceURL patch Build source.URL with informed string. @@ -98,8 +98,8 @@ func amendBuild(identifier string, b *buildv1alpha1.Build) { amendSourceURL(b, os.Getenv(EnvVarSourceURLGitlab)) } - amendOutputImageURL(b, os.Getenv(EnvVarImageRepo)) - amendOutputSecretRef(b, os.Getenv(EnvVarImageRepoSecret)) + amendOutputImage(b, os.Getenv(EnvVarImageRepo)) + amendOutputCredentials(b, os.Getenv(EnvVarImageRepoSecret)) } // retrieveBuildAndBuildRun will retrieve the build and buildRun diff --git a/test/integration/build_to_git_test.go b/test/integration/build_to_git_test.go index fca57f5822..1d1061cdda 100644 --- a/test/integration/build_to_git_test.go +++ b/test/integration/build_to_git_test.go @@ -228,9 +228,9 @@ var _ = Describe("Integration tests Build and referenced Source url", func() { buildObject.ObjectMeta.Annotations["build.shipwright.io/verify.repository"] = "true" buildObject.Spec.Source.URL = "https://github.yourco.com/org/build-fake" - buildObject.Spec.Source.SecretRef = &corev1.LocalObjectReference{Name: "foobar"} + buildObject.Spec.Source.Credentials = &corev1.LocalObjectReference{Name: "foobar"} - sampleSecret := tb.Catalog.SecretWithAnnotation(buildObject.Spec.Source.SecretRef.Name, buildObject.Namespace) + sampleSecret := tb.Catalog.SecretWithAnnotation(buildObject.Spec.Source.Credentials.Name, buildObject.Namespace) Expect(tb.CreateSecret(sampleSecret)).To(BeNil()) Expect(tb.CreateBuild(buildObject)).To(BeNil()) diff --git a/test/integration/build_to_secrets_test.go b/test/integration/build_to_secrets_test.go index 396fc52422..70461dd3a6 100644 --- a/test/integration/build_to_secrets_test.go +++ b/test/integration/build_to_secrets_test.go @@ -47,7 +47,7 @@ var _ = Describe("Integration tests Build and referenced Secrets", func() { ) Expect(err).To(BeNil()) - sampleSecret := tb.Catalog.SecretWithAnnotation(buildObject.Spec.Output.SecretRef.Name, buildObject.Namespace) + sampleSecret := tb.Catalog.SecretWithAnnotation(buildObject.Spec.Output.Credentials.Name, buildObject.Namespace) Expect(tb.CreateSecret(sampleSecret)).To(BeNil()) @@ -60,14 +60,14 @@ var _ = Describe("Integration tests Build and referenced Secrets", func() { Expect(buildObject.Status.Reason).To(Equal(v1alpha1.SucceedStatus)) // delete a secret - Expect(tb.DeleteSecret(buildObject.Spec.Output.SecretRef.Name)).To(BeNil()) + Expect(tb.DeleteSecret(buildObject.Spec.Output.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.SpecOutputSecretRefNotFound)) - Expect(buildObject.Status.Message).To(Equal(fmt.Sprintf("referenced secret %s not found", buildObject.Spec.Output.SecretRef.Name))) + Expect(buildObject.Status.Message).To(Equal(fmt.Sprintf("referenced secret %s not found", buildObject.Spec.Output.Credentials.Name))) }) It("should validate when a missing secret is recreated", func() { @@ -87,9 +87,9 @@ var _ = Describe("Integration tests Build and referenced Secrets", func() { 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.SecretRef.Name))) + Expect(buildObject.Status.Message).To(Equal(fmt.Sprintf("referenced secret %s not found", buildObject.Spec.Output.Credentials.Name))) - sampleSecret := tb.Catalog.SecretWithAnnotation(buildObject.Spec.Output.SecretRef.Name, buildObject.Namespace) + sampleSecret := tb.Catalog.SecretWithAnnotation(buildObject.Spec.Output.Credentials.Name, buildObject.Namespace) // generate resources Expect(tb.CreateSecret(sampleSecret)).To(BeNil()) @@ -114,7 +114,7 @@ var _ = Describe("Integration tests Build and referenced Secrets", func() { ) Expect(err).To(BeNil()) - sampleSecret := tb.Catalog.SecretWithoutAnnotation(buildObject.Spec.Output.SecretRef.Name, buildObject.Namespace) + sampleSecret := tb.Catalog.SecretWithoutAnnotation(buildObject.Spec.Output.Credentials.Name, buildObject.Namespace) // generate resources Expect(tb.CreateSecret(sampleSecret)).To(BeNil()) @@ -127,7 +127,7 @@ var _ = Describe("Integration tests Build and referenced Secrets", func() { Expect(buildObject.Status.Reason).To(Equal(v1alpha1.SucceedStatus)) // delete a secret - Expect(tb.DeleteSecret(buildObject.Spec.Output.SecretRef.Name)).To(BeNil()) + Expect(tb.DeleteSecret(buildObject.Spec.Output.Credentials.Name)).To(BeNil()) // assert that the validation happened one more time buildObject, err = tb.GetBuild(buildName) @@ -152,9 +152,9 @@ var _ = Describe("Integration tests Build and referenced Secrets", func() { 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.SecretRef.Name))) + Expect(buildObject.Status.Message).To(Equal(fmt.Sprintf("referenced secret %s not found", buildObject.Spec.Output.Credentials.Name))) - sampleSecret := tb.Catalog.SecretWithoutAnnotation(buildObject.Spec.Output.SecretRef.Name, buildObject.Namespace) + sampleSecret := tb.Catalog.SecretWithoutAnnotation(buildObject.Spec.Output.Credentials.Name, buildObject.Namespace) // generate resources Expect(tb.CreateSecret(sampleSecret)).To(BeNil()) @@ -164,7 +164,7 @@ var _ = Describe("Integration tests Build and referenced Secrets", func() { 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.SecretRef.Name))) + Expect(buildObject.Status.Message).To(Equal(fmt.Sprintf("referenced secret %s not found", buildObject.Spec.Output.Credentials.Name))) }) It("should validate when a missing secret is recreated with annotation", func() { @@ -186,7 +186,7 @@ var _ = Describe("Integration tests Build and referenced Secrets", func() { Expect(buildObject.Status.Reason).To(Equal(v1alpha1.SpecOutputSecretRefNotFound)) Expect(buildObject.Status.Message).To(Equal(fmt.Sprintf("referenced secret %s not found", "fake-secret"))) - sampleSecret := tb.Catalog.SecretWithoutAnnotation(buildObject.Spec.Output.SecretRef.Name, buildObject.Namespace) + sampleSecret := tb.Catalog.SecretWithoutAnnotation(buildObject.Spec.Output.Credentials.Name, buildObject.Namespace) // generate resources Expect(tb.CreateSecret(sampleSecret)).To(BeNil()) @@ -198,7 +198,7 @@ var _ = Describe("Integration tests Build and referenced Secrets", func() { // we modify the annotation so automatic delete does not take place data := []byte(fmt.Sprintf(`{"metadata":{"annotations":{"%s":"true"}}}`, v1alpha1.AnnotationBuildRefSecret)) - _, err = tb.PatchSecret(buildObject.Spec.Output.SecretRef.Name, data) + _, err = tb.PatchSecret(buildObject.Spec.Output.Credentials.Name, data) Expect(err).To(BeNil()) // // assert that the validation happened one more time @@ -222,7 +222,7 @@ var _ = Describe("Integration tests Build and referenced Secrets", func() { ) Expect(err).To(BeNil()) - sampleSecret := tb.Catalog.SecretWithAnnotation(buildObject.Spec.Source.SecretRef.Name, buildObject.Namespace) + sampleSecret := tb.Catalog.SecretWithAnnotation(buildObject.Spec.Source.Credentials.Name, buildObject.Namespace) Expect(tb.CreateSecret(sampleSecret)).To(BeNil()) @@ -236,14 +236,14 @@ var _ = Describe("Integration tests Build and referenced Secrets", func() { Expect(buildObject.Status.Message).To(Equal("all validations succeeded")) // delete a secret - Expect(tb.DeleteSecret(buildObject.Spec.Source.SecretRef.Name)).To(BeNil()) + Expect(tb.DeleteSecret(buildObject.Spec.Source.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.SpecSourceSecretRefNotFound)) - Expect(buildObject.Status.Message).To(Equal(fmt.Sprintf("referenced secret %s not found", buildObject.Spec.Source.SecretRef.Name))) + Expect(buildObject.Status.Message).To(Equal(fmt.Sprintf("referenced secret %s not found", buildObject.Spec.Source.Credentials.Name))) }) It("should validate when a missing secret is recreated", func() { @@ -263,9 +263,9 @@ var _ = Describe("Integration tests Build and referenced Secrets", func() { Expect(err).To(BeNil()) Expect(buildObject.Status.Registered).To(Equal(corev1.ConditionFalse)) // 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.SecretRef.Name))) + // 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.SecretRef.Name, buildObject.Namespace) + sampleSecret := tb.Catalog.SecretWithAnnotation(buildObject.Spec.Source.Credentials.Name, buildObject.Namespace) // generate resources Expect(tb.CreateSecret(sampleSecret)).To(BeNil()) @@ -290,7 +290,7 @@ var _ = Describe("Integration tests Build and referenced Secrets", func() { ) Expect(err).To(BeNil()) - sampleSecret := tb.Catalog.SecretWithAnnotation(buildObject.Spec.BuilderImage.SecretRef.Name, buildObject.Namespace) + sampleSecret := tb.Catalog.SecretWithAnnotation(buildObject.Spec.Builder.Credentials.Name, buildObject.Namespace) Expect(tb.CreateSecret(sampleSecret)).To(BeNil()) @@ -303,15 +303,14 @@ var _ = Describe("Integration tests Build and referenced Secrets", func() { Expect(buildObject.Status.Reason).To(Equal(v1alpha1.SucceedStatus)) // delete a secret - Expect(tb.DeleteSecret(buildObject.Spec.BuilderImage.SecretRef.Name)).To(BeNil()) + 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.BuilderImage.SecretRef.Name))) - + 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() { @@ -331,9 +330,9 @@ var _ = Describe("Integration tests Build and referenced Secrets", func() { 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.BuilderImage.SecretRef.Name))) + Expect(buildObject.Status.Message).To(Equal(fmt.Sprintf("referenced secret %s not found", buildObject.Spec.Builder.Credentials.Name))) - sampleSecret := tb.Catalog.SecretWithAnnotation(buildObject.Spec.BuilderImage.SecretRef.Name, buildObject.Namespace) + sampleSecret := tb.Catalog.SecretWithAnnotation(buildObject.Spec.Builder.Credentials.Name, buildObject.Namespace) // generate resources Expect(tb.CreateSecret(sampleSecret)).To(BeNil()) @@ -358,8 +357,8 @@ var _ = Describe("Integration tests Build and referenced Secrets", func() { ) Expect(err).To(BeNil()) - specSourceSecret := tb.Catalog.SecretWithAnnotation(buildObject.Spec.Source.SecretRef.Name, buildObject.Namespace) - specBuilderSecret := tb.Catalog.SecretWithAnnotation(buildObject.Spec.BuilderImage.SecretRef.Name, buildObject.Namespace) + 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()) @@ -403,11 +402,11 @@ var _ = Describe("Integration tests Build and referenced Secrets", func() { 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.SecretRef.Name)) - Expect(buildObject.Status.Message).To(ContainSubstring(buildObject.Spec.BuilderImage.SecretRef.Name)) + 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.SecretRef.Name, buildObject.Namespace) - specBuilderSecret := tb.Catalog.SecretWithAnnotation(buildObject.Spec.BuilderImage.SecretRef.Name, buildObject.Namespace) + 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()) @@ -441,7 +440,7 @@ var _ = Describe("Integration tests Build and referenced Secrets", func() { ) Expect(err).To(BeNil()) - specSourceSecret := tb.Catalog.SecretWithAnnotation(firstBuildObject.Spec.Source.SecretRef.Name, firstBuildObject.Namespace) + specSourceSecret := tb.Catalog.SecretWithAnnotation(firstBuildObject.Spec.Source.Credentials.Name, firstBuildObject.Namespace) Expect(tb.CreateSecret(specSourceSecret)).To(BeNil()) @@ -467,14 +466,14 @@ var _ = Describe("Integration tests Build and referenced Secrets", func() { 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.SecretRef.Name))) + Expect(o.Status.Message).To(Equal(fmt.Sprintf("referenced secret %s not found", firstBuildObject.Spec.Source.Credentials.Name))) // 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.SecretRef.Name))) + Expect(o.Status.Message).To(Equal(fmt.Sprintf("referenced secret %s not found", secondBuildObject.Spec.Source.Credentials.Name))) }) It("should validate the Builds when a missing secret is recreated", func() { // populate Build related vars @@ -507,7 +506,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.SecretRef.Name, firstBuildObject.Namespace) + specSourceSecret := tb.Catalog.SecretWithAnnotation(firstBuildObject.Spec.Source.Credentials.Name, firstBuildObject.Namespace) // generate resources Expect(tb.CreateSecret(specSourceSecret)).To(BeNil()) diff --git a/test/integration/buildruns_to_sa_test.go b/test/integration/buildruns_to_sa_test.go index 0c04f133f8..2e3d1aaf2d 100644 --- a/test/integration/buildruns_to_sa_test.go +++ b/test/integration/buildruns_to_sa_test.go @@ -79,7 +79,7 @@ var _ = Describe("Integration tests BuildRuns and Service-accounts", func() { return false } - sampleSecret := tb.Catalog.SecretWithAnnotation(buildObject.Spec.Output.SecretRef.Name, buildObject.Namespace) + sampleSecret := tb.Catalog.SecretWithAnnotation(buildObject.Spec.Output.Credentials.Name, buildObject.Namespace) Expect(tb.CreateSecret(sampleSecret)).To(BeNil()) @@ -97,7 +97,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.SecretRef.Name)).To(BeTrue()) + Expect(contains(sa.Secrets, buildObject.Spec.Output.Credentials.Name)).To(BeTrue()) _, err = tb.GetBRTillCompletion(buildRunObject.Name) Expect(err).To(BeNil())