From 2cb77e81a57d4f95d41699781ed40604cbf32c7b Mon Sep 17 00:00:00 2001 From: Sascha Schwarze Date: Sat, 2 Dec 2023 21:07:49 +0100 Subject: [PATCH] Make Build.spec.source.git.url required --- deploy/crds/shipwright.io_buildruns.yaml | 4 ++++ deploy/crds/shipwright.io_builds.yaml | 2 ++ pkg/apis/build/v1beta1/build_conversion.go | 6 +++--- pkg/apis/build/v1beta1/source.go | 4 +--- .../build/v1beta1/zz_generated.deepcopy.go | 5 ----- pkg/webhook/conversion/converter_test.go | 2 +- test/e2e/v1beta1/common_suite_test.go | 2 +- test/e2e/v1beta1/common_test.go | 2 +- test/v1beta1_samples/catalog.go | 18 ++++++++++++------ 9 files changed, 25 insertions(+), 20 deletions(-) diff --git a/deploy/crds/shipwright.io_buildruns.yaml b/deploy/crds/shipwright.io_buildruns.yaml index 51cb70047c..d3cb6e5b2e 100644 --- a/deploy/crds/shipwright.io_buildruns.yaml +++ b/deploy/crds/shipwright.io_buildruns.yaml @@ -6703,6 +6703,8 @@ spec: url: description: URL describes the URL of the Git repository. type: string + required: + - url type: object local: description: LocalSource @@ -10695,6 +10697,8 @@ spec: url: description: URL describes the URL of the Git repository. type: string + required: + - url type: object local: description: LocalSource diff --git a/deploy/crds/shipwright.io_builds.yaml b/deploy/crds/shipwright.io_builds.yaml index a086012783..a76781a66f 100644 --- a/deploy/crds/shipwright.io_builds.yaml +++ b/deploy/crds/shipwright.io_builds.yaml @@ -2478,6 +2478,8 @@ spec: url: description: URL describes the URL of the Git repository. type: string + required: + - url type: object local: description: LocalSource diff --git a/pkg/apis/build/v1beta1/build_conversion.go b/pkg/apis/build/v1beta1/build_conversion.go index c246cd5284..c0199aae74 100644 --- a/pkg/apis/build/v1beta1/build_conversion.go +++ b/pkg/apis/build/v1beta1/build_conversion.go @@ -126,10 +126,10 @@ func (dest *BuildSpec) ConvertFrom(orig *v1alpha1.BuildSpec) error { if orig.Source.Credentials != nil { specSource.OCIArtifact.PullSecret = &orig.Source.Credentials.Name } - } else { + } else if orig.Source.URL != nil { specSource.Type = GitType specSource.GitSource = &Git{ - URL: orig.Source.URL, + URL: *orig.Source.URL, Revision: orig.Source.Revision, } if orig.Source.Credentials != nil { @@ -434,7 +434,7 @@ func getAlphaBuildSource(src BuildSpec) v1alpha1.Source { } } if src.Source.GitSource != nil { - source.URL = src.Source.GitSource.URL + source.URL = &src.Source.GitSource.URL revision = src.Source.GitSource.Revision } diff --git a/pkg/apis/build/v1beta1/source.go b/pkg/apis/build/v1beta1/source.go index dad731678f..9413c57486 100644 --- a/pkg/apis/build/v1beta1/source.go +++ b/pkg/apis/build/v1beta1/source.go @@ -44,9 +44,7 @@ type Local struct { // Git describes the git repository to pull type Git struct { // URL describes the URL of the Git repository. - // - // +optional - URL *string `json:"url,omitempty"` + URL string `json:"url"` // Revision describes the Git revision (e.g., branch, tag, commit SHA, // etc.) to fetch. diff --git a/pkg/apis/build/v1beta1/zz_generated.deepcopy.go b/pkg/apis/build/v1beta1/zz_generated.deepcopy.go index 4c3dc1dfeb..4000f8342c 100644 --- a/pkg/apis/build/v1beta1/zz_generated.deepcopy.go +++ b/pkg/apis/build/v1beta1/zz_generated.deepcopy.go @@ -738,11 +738,6 @@ func (in *FailureDetails) DeepCopy() *FailureDetails { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Git) DeepCopyInto(out *Git) { *out = *in - if in.URL != nil { - in, out := &in.URL, &out.URL - *out = new(string) - **out = **in - } if in.Revision != nil { in, out := &in.Revision, &out.Revision *out = new(string) diff --git a/pkg/webhook/conversion/converter_test.go b/pkg/webhook/conversion/converter_test.go index 6907e17ffc..db05141278 100644 --- a/pkg/webhook/conversion/converter_test.go +++ b/pkg/webhook/conversion/converter_test.go @@ -732,7 +732,7 @@ request: Type: v1beta1.GitType, ContextDir: &ctxDir, GitSource: &v1beta1.Git{ - URL: &url, + URL: url, Revision: &revision, CloneSecret: &secretName, }, diff --git a/test/e2e/v1beta1/common_suite_test.go b/test/e2e/v1beta1/common_suite_test.go index a898b3edee..ac71a8c8b9 100644 --- a/test/e2e/v1beta1/common_suite_test.go +++ b/test/e2e/v1beta1/common_suite_test.go @@ -79,7 +79,7 @@ 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.GitSource.URL = pointer.String(repository) + 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 4ba907bb44..165119e559 100644 --- a/test/e2e/v1beta1/common_test.go +++ b/test/e2e/v1beta1/common_test.go @@ -111,7 +111,7 @@ func amendSourceURL(b *buildv1beta1.Build, sourceURL string) { if sourceURL == "" { return } - b.Spec.Source.GitSource.URL = &sourceURL + b.Spec.Source.GitSource.URL = sourceURL } // amendBuild make changes on build object. diff --git a/test/v1beta1_samples/catalog.go b/test/v1beta1_samples/catalog.go index 338c8cf71f..7834b10a43 100644 --- a/test/v1beta1_samples/catalog.go +++ b/test/v1beta1_samples/catalog.go @@ -100,8 +100,9 @@ func (c *Catalog) BuildWithClusterBuildStrategyAndFalseSourceAnnotation(name str Spec: build.BuildSpec{ Source: build.Source{ GitSource: &build.Git{ - URL: pointer.String("foobar"), + URL: "foobar", }, + Type: build.GitType, }, Strategy: build.Strategy{ Name: strategyName, @@ -125,8 +126,9 @@ func (c *Catalog) BuildWithClusterBuildStrategy(name string, ns string, strategy Spec: build.BuildSpec{ Source: build.Source{ GitSource: &build.Git{ - URL: pointer.String("https://github.com/shipwright-io/sample-go"), + URL: "https://github.com/shipwright-io/sample-go", }, + Type: build.GitType, }, Strategy: build.Strategy{ Name: strategyName, @@ -152,9 +154,10 @@ func (c *Catalog) BuildWithClusterBuildStrategyAndSourceSecret(name string, ns s Spec: build.BuildSpec{ Source: build.Source{ GitSource: &build.Git{ - URL: pointer.String("https://github.com/shipwright-io/sample-go"), + URL: "https://github.com/shipwright-io/sample-go", CloneSecret: &secret, }, + Type: build.GitType, }, Strategy: build.Strategy{ Name: strategyName, @@ -178,8 +181,9 @@ func (c *Catalog) BuildWithBuildStrategy(name string, ns string, strategyName st Spec: build.BuildSpec{ Source: build.Source{ GitSource: &build.Git{ - URL: pointer.String("https://github.com/shipwright-io/sample-go"), + URL: "https://github.com/shipwright-io/sample-go", }, + Type: build.GitType, }, Strategy: build.Strategy{ Name: strategyName, @@ -199,8 +203,9 @@ func (c *Catalog) BuildWithNilBuildStrategyKind(name string, ns string, strategy Spec: build.BuildSpec{ Source: build.Source{ GitSource: &build.Git{ - URL: pointer.String("https://github.com/shipwright-io/sample-go"), + URL: "https://github.com/shipwright-io/sample-go", }, + Type: build.GitType, }, Strategy: build.Strategy{ Name: strategyName, @@ -219,8 +224,9 @@ func (c *Catalog) BuildWithOutputSecret(name string, ns string, secretName strin Spec: build.BuildSpec{ Source: build.Source{ GitSource: &build.Git{ - URL: pointer.String("https://github.com/shipwright-io/sample-go"), + URL: "https://github.com/shipwright-io/sample-go", }, + Type: build.GitType, }, Output: build.Image{ PushSecret: &secretName,