[BUG] Runtime error when using a buildRef field in v1beta1 buildrun object spec #1395
Closed
1 task done
Labels
kind/bug
Categorizes issue or PR as related to a bug.
Milestone
Is there an existing issue for this?
Kubernetes Version
Kubernetes Version: v1.26.6+6bf3f75
Shipwright Version
Commit: fa7bea6
Current Behavior
When I create a BuildRun object that uses v1beta1 api but still reference some field from v1alpha1 api (here in the example buildRef), we have a runtime error
apiVersion: shipwright.io/v1beta1 kind: BuildRun metadata: generateName: buildpack-java-build- spec: buildRef: name: buildpack-java-build
demo git:(master) ✗ oc create -f buildpacks-buildrun-java.yaml Warning: unknown field "spec.buildRef" Error from server: error when creating "buildpacks-buildrun-java.yaml": conversion webhook for shipwright.io/v1beta1, Kind=BuildRun failed: Post "https://openshift-builds-webhook.shipwright-build.svc:443/convert?timeout=30s": EOF
We can see this error int the conversion webhook logs
`{"level":"info","ts":1695715728.6255689,"logger":"shp-build-webhook","msg":"handling request"}
{"level":"info","ts":1695715728.626294,"logger":"shp-build-webhook","msg":"converting custom resource"}
{"level":"debug","ts":1695715728.6266005,"logger":"shp-build-webhook","msg":"Converting Build from alpha to beta","namespace":"default","name":"buildpack-java-build"}
{"level":"info","ts":1695715728.6269345,"logger":"shp-build-webhook","msg":"sending response: &ConversionResponse{UID:ff0af2fd-d610-488c-9708-ade742ab27c7,ConvertedObjects:[]RawExtension{{[] 0xc000308050},},Result:{{ } { } Success nil 0},}"}
{"level":"info","ts":1695715746.8473518,"logger":"shp-build-webhook","msg":"handling request"}
{"level":"info","ts":1695715746.8475904,"logger":"shp-build-webhook","msg":"converting custom resource"}
{"level":"debug","ts":1695715746.8499992,"logger":"shp-build-webhook","msg":"Converting BuildRun from beta to alpha","namespace":"default","name":"buildpack-java-build-2s92p"}
2023/09/26 08:09:06 http: panic serving 10.128.0.1:47740: runtime error: invalid memory address or nil pointer dereference
goroutine 258 [running]:
net/http.(*conn).serve.func1()
/usr/lib/golang/src/net/http/server.go:1850 +0xbf
panic({0xc14f00, 0x1318d00})
/usr/lib/golang/src/runtime/panic.go:890 +0x262
github.com/shipwright-io/build/pkg/apis/build/v1beta1.(*BuildRun).ConvertTo(0xc0001b01e0, {0xe1eae0, 0xc00019b560}, 0xc0003080b8)
/remote-source/app/pkg/apis/build/v1beta1/buildrun_conversion.go:32 +0x21c
github.com/shipwright-io/build/pkg/webhook/conversion.convertSHPCR({0xe1eae0, 0xc00019b560}, 0xc000308098, {0xc000314318, 0x16})
/remote-source/app/pkg/webhook/conversion/converter.go:63 +0xadb
github.com/shipwright-io/build/pkg/webhook/conversion.doConversion({0xe1eae0, 0xc00019b560}, 0xc0004e4d80, 0xd59e90)
/remote-source/app/pkg/webhook/conversion/conversion.go:177 +0x2ca
github.com/shipwright-io/build/pkg/webhook/conversion.serve({0xe1eae0, 0xc00019b560}, {0xe1e320?, 0xc0002d40e0?}, 0xc0001b4700, 0x4f0e49?)
/remote-source/app/pkg/webhook/conversion/conversion.go:107 +0x43e
github.com/shipwright-io/build/pkg/webhook/conversion.CRDConvert(...)
/remote-source/app/pkg/webhook/conversion/conversion.go:64
github.com/shipwright-io/build/pkg/webhook/conversion.CRDConvertHandler.func1({0xe1e320?, 0xc0002d40e0?}, 0xc13cc2442566e865?)
/remote-source/app/pkg/webhook/conversion/conversion.go:58 +0x45
net/http.HandlerFunc.ServeHTTP(0x17f?, {0xe1e320?, 0xc0002d40e0?}, 0x7fdc0248b7a8?)
/usr/lib/golang/src/net/http/server.go:2109 +0x2f
net/http.(*ServeMux).ServeHTTP(0xc00004069e?, {0xe1e320, 0xc0002d40e0}, 0xc0001b4700)
/usr/lib/golang/src/net/http/server.go:2487 +0x149
net/http.serverHandler.ServeHTTP({0xe190e0?}, {0xe1e320, 0xc0002d40e0}, 0xc0001b4700)
/usr/lib/golang/src/net/http/server.go:2947 +0x30c
net/http.(*conn).serve(0xc000168000, {0xe1eae0, 0xc00027a390})
/usr/lib/golang/src/net/http/server.go:1991 +0x607
created by net/http.(*Server).Serve
/usr/lib/golang/src/net/http/server.go:3102 +0x4db
`
Expected Behavior
We expect the object been validated through the api schema and an explicit gentleman error message returned to the user
Steps To Reproduce
1- Create a Build
The text was updated successfully, but these errors were encountered: