Skip to content

Commit

Permalink
Fixes for Beta API and conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
SaschaSchwarze0 authored and qu1queee committed Oct 18, 2023
1 parent f5b8ed4 commit ac9c985
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 46 deletions.
17 changes: 7 additions & 10 deletions pkg/apis/build/v1beta1/build_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (dest *BuildSpec) ConvertFrom(orig *v1alpha1.BuildSpec) error {
// only interested on spec.sources as long as an item of the list
// is of the type LocalCopy. Otherwise, we move into bundle or git types.
index, isLocal := v1alpha1.IsLocalCopyType(orig.Sources)
if len(orig.Sources) > 0 && isLocal {
if isLocal {
specSource.Type = LocalType
specSource.LocalSource = &Local{
Name: orig.Sources[index].Name,
Expand Down Expand Up @@ -226,15 +226,12 @@ func (dest *BuildSpec) ConvertFrom(orig *v1alpha1.BuildSpec) error {

func (dest *BuildSpec) ConvertTo(bs *v1alpha1.BuildSpec) error {
// Handle BuildSpec Sources or Source
if dest.Source.Type == LocalType {
bs.Sources = []v1alpha1.BuildSource{}
if dest.Source.LocalSource != nil {
bs.Sources = append(bs.Sources, v1alpha1.BuildSource{
Name: dest.Source.LocalSource.Name,
Type: v1alpha1.LocalCopy,
Timeout: dest.Source.LocalSource.Timeout,
})
}
if dest.Source.Type == LocalType && dest.Source.LocalSource != nil {
bs.Sources = append(bs.Sources, v1alpha1.BuildSource{
Name: dest.Source.LocalSource.Name,
Type: v1alpha1.LocalCopy,
Timeout: dest.Source.LocalSource.Timeout,
})
} else {
bs.Source = getAlphaBuildSource(*dest)
}
Expand Down
23 changes: 9 additions & 14 deletions pkg/apis/build/v1beta1/buildrun_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,12 @@ func (src *BuildRun) ConvertTo(ctx context.Context, obj *unstructured.Unstructur
}

// BuildRunSpec Sources
if src.Spec.Source != nil {
alphaBuildRun.Spec.Sources = []v1alpha1.BuildSource{}
if src.Spec.Source.Type == LocalType {
alphaBuildRun.Spec.Sources = append(alphaBuildRun.Spec.Sources, v1alpha1.BuildSource{
Name: src.Spec.Source.LocalSource.Name,
Type: v1alpha1.LocalCopy,
Timeout: src.Spec.Source.LocalSource.Timeout,
})
}
if src.Spec.Source != nil && src.Spec.Source.Type == LocalType && src.Spec.Source.LocalSource != nil {
alphaBuildRun.Spec.Sources = append(alphaBuildRun.Spec.Sources, v1alpha1.BuildSource{
Name: src.Spec.Source.LocalSource.Name,
Type: v1alpha1.LocalCopy,
Timeout: src.Spec.Source.LocalSource.Timeout,
})
}

// BuildRunSpec ServiceAccount
Expand Down Expand Up @@ -193,11 +190,9 @@ func (src *BuildRun) ConvertFrom(ctx context.Context, obj *unstructured.Unstruct
func (dest *BuildRunSpec) ConvertFrom(orig *v1alpha1.BuildRunSpec) error {

// BuildRunSpec BuildSpec
dest.Build = &ReferencedBuild{}
if orig.BuildSpec != nil {
if dest.Build.Build != nil {
dest.Build.Build.ConvertFrom(orig.BuildSpec)
}
dest.Build.Build = &BuildSpec{}
dest.Build.Build.ConvertFrom(orig.BuildSpec)
}
if orig.BuildRef != nil {
dest.Build.Name = &orig.BuildRef.Name
Expand All @@ -206,7 +201,7 @@ func (dest *BuildRunSpec) ConvertFrom(orig *v1alpha1.BuildRunSpec) error {
// only interested on spec.sources as long as an item of the list
// is of the type LocalCopy. Otherwise, we move into bundle or git types.
index, isLocal := v1alpha1.IsLocalCopyType(orig.Sources)
if len(orig.Sources) > 0 && isLocal {
if isLocal {
dest.Source = &BuildRunSource{
Type: LocalType,
LocalSource: &Local{
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/build/v1beta1/buildrun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type BuildRunSpec struct {
// Build refers to an embedded build specification
// This field is mandatory
//
Build *ReferencedBuild `json:"build"`
Build ReferencedBuild `json:"build"`

// Source refers to the location where the source code is,
// this could only be a local source
Expand Down Expand Up @@ -379,7 +379,7 @@ func (brs *BuildRunStatus) SetCondition(condition *Condition) {
// BuildName returns the name of the associated build, which can be a referenced
// build resource or an embedded build specification
func (buildrunSpec *BuildRunSpec) BuildName() string {
if buildrunSpec.Build != nil {
if buildrunSpec.Build.Name != nil {
return *buildrunSpec.Build.Name
}

Expand Down
6 changes: 1 addition & 5 deletions pkg/apis/build/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pkg/webhook/conversion/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,7 @@ request:
Kind: "BuildRun",
},
Spec: v1beta1.BuildRunSpec{
Build: &v1beta1.ReferencedBuild{
Build: v1beta1.ReferencedBuild{
Name: pointer.String("a_build"),
},
Source: &v1beta1.BuildRunSource{
Expand Down Expand Up @@ -1161,7 +1161,7 @@ request:
Kind: "BuildRun",
},
Spec: v1beta1.BuildRunSpec{
Build: &v1beta1.ReferencedBuild{
Build: v1beta1.ReferencedBuild{
Name: pointer.String("a_build"),
},
ServiceAccount: &sa,
Expand Down
6 changes: 0 additions & 6 deletions test/e2e/v1beta1/common_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,18 +280,12 @@ func (b *buildRunPrototype) Namespace(namespace string) *buildRunPrototype {
}

func (b *buildRunPrototype) ForBuild(build *buildv1beta1.Build) *buildRunPrototype {
if b.buildRun.Spec.Build == nil {
b.buildRun.Spec.Build = &buildv1beta1.ReferencedBuild{}
}
b.buildRun.Spec.Build.Name = &build.Name
b.buildRun.ObjectMeta.Namespace = build.Namespace
return b
}

func (b *buildRunPrototype) WithBuildSpec(buildSpec *buildv1beta1.BuildSpec) *buildRunPrototype {
if b.buildRun.Spec.Build == nil {
b.buildRun.Spec.Build = &buildv1beta1.ReferencedBuild{}
}
b.buildRun.Spec.Build.Build = buildSpec
return b
}
Expand Down
14 changes: 7 additions & 7 deletions test/v1beta1_samples/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ func (c *Catalog) DefaultBuildRun(buildRunName string, buildName string) *build.
Name: buildRunName,
},
Spec: build.BuildRunSpec{
Build: &build.ReferencedBuild{
Build: build.ReferencedBuild{
Name: &buildName,
},
},
Expand Down Expand Up @@ -829,7 +829,7 @@ func (c *Catalog) BuildRunWithBuildSnapshot(buildRunName string, buildName strin
},
},
Spec: build.BuildRunSpec{
Build: &build.ReferencedBuild{
Build: build.ReferencedBuild{
Name: &buildName,
},
},
Expand All @@ -854,7 +854,7 @@ func (c *Catalog) BuildRunWithExistingOwnerReferences(buildRunName string, build
OwnerReferences: []metav1.OwnerReference{fakeOwnerRef},
},
Spec: build.BuildRunSpec{
Build: &build.ReferencedBuild{
Build: build.ReferencedBuild{
Name: &buildName,
},
},
Expand All @@ -870,7 +870,7 @@ func (c *Catalog) BuildRunWithFakeNamespace(buildRunName string, buildName strin
Namespace: "foobarns",
},
Spec: build.BuildRunSpec{
Build: &build.ReferencedBuild{
Build: build.ReferencedBuild{
Name: &buildName,
},
},
Expand Down Expand Up @@ -959,7 +959,7 @@ func (c *Catalog) BuildRunWithSA(buildRunName string, buildName string, saName s
Name: buildRunName,
},
Spec: build.BuildRunSpec{
Build: &build.ReferencedBuild{
Build: build.ReferencedBuild{
Name: &buildName,
},
ServiceAccount: &saName,
Expand All @@ -975,7 +975,7 @@ func (c *Catalog) BuildRunWithoutSA(buildRunName string, buildName string) *buil
Name: buildRunName,
},
Spec: build.BuildRunSpec{
Build: &build.ReferencedBuild{
Build: build.ReferencedBuild{
Name: &buildName,
},
ServiceAccount: nil,
Expand All @@ -991,7 +991,7 @@ func (c *Catalog) BuildRunWithSAGenerate(buildRunName string, buildName string)
Name: buildRunName,
},
Spec: build.BuildRunSpec{
Build: &build.ReferencedBuild{
Build: build.ReferencedBuild{
Name: &buildName,
},
ServiceAccount: pointer.String(".generate"),
Expand Down

0 comments on commit ac9c985

Please sign in to comment.