Skip to content

Commit

Permalink
🐛 Patch generated yaml for restore CRD as a hacky workaround (vmware-…
Browse files Browse the repository at this point in the history
…tanzu#2814)

* 🐛 Patch generated yaml for restore CRD as a hacky workaround

Signed-off-by: Ashish Amarnath <ashisham@vmware.com>

* changelog

Signed-off-by: Ashish Amarnath <ashisham@vmware.com>
  • Loading branch information
ashish-amarnath authored and georgettica committed Jan 26, 2021
1 parent 4402aac commit 0b53b06
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/2814-ashish-amarnath
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
🐛 Manually patch the generated yaml for restore CRD as a hacky workaround
3 changes: 1 addition & 2 deletions config/crd/bases/velero.io_restores.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@

---
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
Expand Down Expand Up @@ -857,6 +855,7 @@ spec:
type: string
required:
- containerPort
- protocol
type: object
type: array
x-kubernetes-list-map-keys:
Expand Down
2 changes: 1 addition & 1 deletion config/crd/crds/crds.go

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions hack/build-image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,8 @@ RUN wget --quiet https://github.com/goreleaser/goreleaser/releases/download/v0.1

# get golangci-lint
RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.27.0

# install kubectl
RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
RUN chmod +x ./kubectl
RUN mv ./kubectl /usr/local/bin
3 changes: 3 additions & 0 deletions hack/restore-crd-patch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
{ "op": "replace", "path": "/spec/validation/openAPIV3Schema/properties/spec/properties/hooks/properties/resources/items/properties/postHooks/items/properties/init/properties/initContainers/items/properties/ports/items/required", "value": [ "containerPort", "protocol"] }
]
9 changes: 9 additions & 0 deletions hack/update-generated-crd-code.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,13 @@ controller-gen \
paths=./pkg/controller/... \
output:crd:artifacts:config=config/crd/bases

# this is a super hacky workaround for https://github.com/kubernetes/kubernetes/issues/91395
# which a result of fixing the validation on CRD objects. The validation ensures the fields that are list map keys, are either marked
# as required or have default values to ensure merging of list map items work as expected.
# With "containerPort" and "protocol" being considered as x-kubernetes-list-map-keys in the container ports, and "protocol" was not
# a required field, the CRD would fail validation with errors similar to the one reported in https://github.com/kubernetes/kubernetes/issues/91395.
# once controller-gen (above) is able to generate CRDs with `protocol` as a required field, this hack can be removed.
kubectl patch -f config/crd/bases/velero.io_restores.yaml -p "$(cat hack/restore-crd-patch.json)" --type=json --local=true -o yaml > /tmp/velero.io_restores-yaml.patched
mv /tmp/velero.io_restores-yaml.patched config/crd/bases/velero.io_restores.yaml

go generate ./config/crd/crds

0 comments on commit 0b53b06

Please sign in to comment.