Skip to content

Commit 62e4673

Browse files
Merge pull request #1486 from SaschaSchwarze0/sascha-fix-conversion-generated-serviceaccount
Fix the BuildRun conversion from alpha to beta when .spec.serviceAccount.generate=true
2 parents caa0662 + fec5af0 commit 62e4673

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

pkg/apis/build/v1beta1/buildrun_conversion.go

+3
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,9 @@ func (dest *BuildRunSpec) ConvertFrom(orig *v1alpha1.BuildRunSpec) error {
212212

213213
if orig.ServiceAccount != nil {
214214
dest.ServiceAccount = orig.ServiceAccount.Name
215+
if orig.ServiceAccount.Generate != nil && *orig.ServiceAccount.Generate {
216+
dest.ServiceAccount = pointer.String(".generate")
217+
}
215218
}
216219

217220
dest.Timeout = orig.Timeout

pkg/webhook/conversion/converter_test.go

+58
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,63 @@ request:
10961096
Expect(buildRun).To(BeComparableTo(desiredBuildRun))
10971097
})
10981098

1099+
It("converts for spec a generated serviceAccount", func() {
1100+
// Create the yaml in v1alpha1
1101+
buildRunTemplate := `kind: ConversionReview
1102+
apiVersion: %s
1103+
request:
1104+
uid: 0000-0000-0000-0000
1105+
desiredAPIVersion: %s
1106+
objects:
1107+
- apiVersion: shipwright.io/v1alpha1
1108+
kind: BuildRun
1109+
metadata:
1110+
name: buildkit-run
1111+
spec:
1112+
buildRef:
1113+
name: a_build
1114+
serviceAccount:
1115+
generate: true
1116+
output:
1117+
image: foobar
1118+
`
1119+
o := fmt.Sprintf(buildRunTemplate, apiVersion, desiredAPIVersion)
1120+
1121+
// Invoke the /convert webhook endpoint
1122+
conversionReview, err := getConversionReview(o)
1123+
Expect(err).To(BeNil())
1124+
Expect(conversionReview.Response.Result.Status).To(Equal(v1.StatusSuccess))
1125+
1126+
convertedObj, err := ToUnstructured(conversionReview)
1127+
Expect(err).To(BeNil())
1128+
1129+
buildRun, err := toV1Beta1BuildRunObject(convertedObj)
1130+
Expect(err).To(BeNil())
1131+
1132+
// Prepare our desired v1beta1 BuildRun
1133+
desiredBuildRun := v1beta1.BuildRun{
1134+
ObjectMeta: v1.ObjectMeta{
1135+
Name: "buildkit-run",
1136+
},
1137+
TypeMeta: v1.TypeMeta{
1138+
APIVersion: "shipwright.io/v1beta1",
1139+
Kind: "BuildRun",
1140+
},
1141+
Spec: v1beta1.BuildRunSpec{
1142+
Build: v1beta1.ReferencedBuild{
1143+
Name: pointer.String("a_build"),
1144+
},
1145+
ServiceAccount: pointer.String(".generate"),
1146+
Output: &v1beta1.Image{
1147+
Image: "foobar",
1148+
},
1149+
},
1150+
}
1151+
1152+
// Use ComparableTo and assert the whole object
1153+
Expect(buildRun).To(BeComparableTo(desiredBuildRun))
1154+
})
1155+
10991156
It("converts for spec Build buildref", func() {
11001157
// Create the yaml in v1alpha1
11011158
buildTemplate := `kind: ConversionReview
@@ -1215,6 +1272,7 @@ request:
12151272
Expect(buildRun).To(BeComparableTo(desiredBuildRun))
12161273
})
12171274
})
1275+
12181276
Context("for a BuildStrategy spec from v1beta1 to v1alpha1", func() {
12191277
var desiredAPIVersion = "shipwright.io/v1alpha1"
12201278
It("converts the strategy", func() {

0 commit comments

Comments
 (0)