quay / quay-bridge-operator

Utilization of Red Hat Quay as the default image registry for an OpenShift Container Platform environment
Apache License 2.0
20 stars 23 forks source link

Issue with BuildConfig being mutated incorrectly #39

Closed clarku closed 2 years ago

clarku commented 2 years ago

Issue

Creating a BuildConfig with spec.output.to.kind: ImageStreamTag, and a value for spec.output.to.namespace gives an error:

Example build config:

spec: 
  output:
    to:
      kind: ImageStreamTag
      namespace: example
      name: example.com/test/test:latest

Error Message:

The Build {build-name} is invalid: spec.output.to.namespace: Invalid value: "example": namespace is not valid when used with a 'DockerImage'

Replication Steps

  1. Create a build config using the above spec

  2. Start build with oc start-build {build-name}

Cause:

Normally this error would come up with a build config like this:

spec: 
  output:
    to:
      kind: DockerImage
      namespace: example
      name: example.com/test/test:latest

where there is a kind: DockerImage with a namespace value. This is invalid as the namespace value should only be used with kind: ImageStreamTag.

However in this case there is an issue with the operator where it is changing the spec incorrectly:

In lines 145-149 of quay-bridge-operator/pkg/webhook/webhook.go we have this code in the mutating webhook which changes the spec.output.to value to DockerImage.

// Update the Kind
 patch = append(patch, patchOperation{
  Op:    "replace",
  Path:  "/spec/output/to/kind",
  Value: "DockerImage",
})

However there is no code which checks for the existence of the spec.output.to.namespace value and deletes it, thus causing the error.

BillDett commented 2 years ago

Thanks for the PR!- I've added a JIRA to track this as part of the overall Quay delivery- https://issues.redhat.com/browse/PROJQUAY-2898 - we'll continue updates there.