Skip to content

Commit

Permalink
Make the buildrun.spec.build a mandatory field
Browse files Browse the repository at this point in the history
Due to seeing panics reported in issues, when this field
for v1beta1 CR's was not set by human error.
  • Loading branch information
qu1queee committed Oct 18, 2023
1 parent e22ca65 commit 9ef8506
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
6 changes: 3 additions & 3 deletions pkg/apis/build/v1beta1/buildrun_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ func (src *BuildRun) ConvertTo(ctx context.Context, obj *unstructured.Unstructur
return err
}
alphaBuildRun.Spec.BuildSpec = &newBuildSpec
} else {
} else if src.Spec.Build.Name != nil {
alphaBuildRun.Spec.BuildRef = &v1alpha1.BuildRef{
Name: src.Spec.Build.Name,
Name: *src.Spec.Build.Name,
}
}

Expand Down Expand Up @@ -200,7 +200,7 @@ func (dest *BuildRunSpec) ConvertFrom(orig *v1alpha1.BuildRunSpec) error {
}
}
if orig.BuildRef != nil {
dest.Build.Name = orig.BuildRef.Name
dest.Build.Name = &orig.BuildRef.Name
}

// only interested on spec.sources as long as an item of the list
Expand Down
8 changes: 4 additions & 4 deletions pkg/apis/build/v1beta1/buildrun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ type ReferencedBuild struct {
// Name of the referent; More info: http://kubernetes.io/docs/user-guide/identifiers#names
//
// +optional
Name string `json:"name,omitempty"`
Name *string `json:"name,omitempty"`
}

// BuildRunSpec defines the desired state of BuildRun
type BuildRunSpec struct {
// Build refers to an embedded build specification
// This field is mandatory
//
// +optional
Build *ReferencedBuild `json:"build,omitempty"`
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 @@ -380,7 +380,7 @@ func (brs *BuildRunStatus) SetCondition(condition *Condition) {
// build resource or an embedded build specification
func (buildrunSpec *BuildRunSpec) BuildName() string {
if buildrunSpec.Build != nil {
return buildrunSpec.Build.Name
return *buildrunSpec.Build.Name
}

// Only BuildRuns with a ReferencedBuild can actually return a proper Build name
Expand Down
4 changes: 2 additions & 2 deletions pkg/webhook/conversion/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,7 @@ request:
},
Spec: v1beta1.BuildRunSpec{
Build: &v1beta1.ReferencedBuild{
Name: "a_build",
Name: pointer.String("a_build"),
},
Source: &v1beta1.BuildRunSource{
Type: v1beta1.LocalType,
Expand Down Expand Up @@ -1162,7 +1162,7 @@ request:
},
Spec: v1beta1.BuildRunSpec{
Build: &v1beta1.ReferencedBuild{
Name: "a_build",
Name: pointer.String("a_build"),
},
ServiceAccount: &sa,
Timeout: &v1.Duration{
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/v1beta1/common_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ func (b *buildRunPrototype) ForBuild(build *buildv1beta1.Build) *buildRunPrototy
if b.buildRun.Spec.Build == nil {
b.buildRun.Spec.Build = &buildv1beta1.ReferencedBuild{}
}
b.buildRun.Spec.Build.Name = build.Name
b.buildRun.Spec.Build.Name = &build.Name
b.buildRun.ObjectMeta.Namespace = build.Namespace
return b
}
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/v1beta1/validators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ func buildRunTestData(ns string, identifier string, filePath string) (*buildv1be

buildRun.SetNamespace(ns)
buildRun.SetName(identifier)
buildRun.Spec.Build.Name = identifier
buildRun.Spec.Build.Name = &identifier

serviceAccountName := os.Getenv(EnvVarServiceAccountName)
if serviceAccountName == "generated" {
Expand Down
16 changes: 8 additions & 8 deletions test/v1beta1_samples/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ func (c *Catalog) DefaultBuildRun(buildRunName string, buildName string) *build.
},
Spec: build.BuildRunSpec{
Build: &build.ReferencedBuild{
Name: buildName,
Name: &buildName,
},
},
Status: build.BuildRunStatus{
Expand Down Expand Up @@ -830,7 +830,7 @@ func (c *Catalog) BuildRunWithBuildSnapshot(buildRunName string, buildName strin
},
Spec: build.BuildRunSpec{
Build: &build.ReferencedBuild{
Name: buildName,
Name: &buildName,
},
},
}
Expand All @@ -855,7 +855,7 @@ func (c *Catalog) BuildRunWithExistingOwnerReferences(buildRunName string, build
},
Spec: build.BuildRunSpec{
Build: &build.ReferencedBuild{
Name: buildName,
Name: &buildName,
},
},
}
Expand All @@ -871,7 +871,7 @@ func (c *Catalog) BuildRunWithFakeNamespace(buildRunName string, buildName strin
},
Spec: build.BuildRunSpec{
Build: &build.ReferencedBuild{
Name: buildName,
Name: &buildName,
},
},
}
Expand Down Expand Up @@ -960,7 +960,7 @@ func (c *Catalog) BuildRunWithSA(buildRunName string, buildName string, saName s
},
Spec: build.BuildRunSpec{
Build: &build.ReferencedBuild{
Name: buildName,
Name: &buildName,
},
ServiceAccount: &saName,
},
Expand All @@ -976,7 +976,7 @@ func (c *Catalog) BuildRunWithoutSA(buildRunName string, buildName string) *buil
},
Spec: build.BuildRunSpec{
Build: &build.ReferencedBuild{
Name: buildName,
Name: &buildName,
},
ServiceAccount: nil,
},
Expand All @@ -992,7 +992,7 @@ func (c *Catalog) BuildRunWithSAGenerate(buildRunName string, buildName string)
},
Spec: build.BuildRunSpec{
Build: &build.ReferencedBuild{
Name: buildName,
Name: &buildName,
},
ServiceAccount: pointer.String(".generate"),
},
Expand Down Expand Up @@ -1054,7 +1054,7 @@ func (c *Catalog) LoadBRWithNameAndRef(name string, buildName string, d []byte)
return nil, err
}
b.Name = name
b.Spec.Build.Name = buildName
b.Spec.Build.Name = &buildName
return b, nil
}

Expand Down

0 comments on commit 9ef8506

Please sign in to comment.