Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Runtime error when using a buildRef field in v1beta1 buildrun object spec #1395

Closed
1 task done
jkhelil opened this issue Oct 4, 2023 · 1 comment
Closed
1 task done
Labels
kind/bug Categorizes issue or PR as related to a bug.

Comments

@jkhelil
Copy link
Contributor

jkhelil commented Oct 4, 2023

Is there an existing issue for this?

  • I have searched the existing issues

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

apiVersion: shipwright.io/v1alpha1
kind: Build
metadata:
  name: buildpack-java-build
spec:
  source:
    url: https://github.com/jkhelil/shipwright-example.git
    contextDir: hello-world-spring-boot
  strategy:
    name: buildpacks-v3
    kind: ClusterBuildStrategy
  output:
    image: quay.io/jkhelil/shipwright-example:latest
    credentials:
      name: push-secret
     ```
      
2- Create a BuildRun using v1beta1 and a bad buildRef field
`
apiVersion: shipwright.io/v1beta1
kind: BuildRun
metadata:
  generateName: buildpack-java-build-
spec:
  buildRef:
    name: buildpack-java-build
`

### Anything else?

_No response_
@jkhelil jkhelil added the kind/bug Categorizes issue or PR as related to a bug. label Oct 4, 2023
@SaschaSchwarze0 SaschaSchwarze0 added this to the release-v0.12.0 milestone Oct 19, 2023
@SaschaSchwarze0
Copy link
Member

SaschaSchwarze0 commented Oct 19, 2023

Fixed as part of #1403

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug.
Projects
Status: Done
Development

No branches or pull requests

2 participants