From 1ddf27abbb62b949110181a9b37cefa1c693161b Mon Sep 17 00:00:00 2001 From: Rob Scott Date: Wed, 18 Aug 2021 11:22:04 -0700 Subject: [PATCH] Versioning CRD yaml to make to simplify only installing v1alpha2 --- .gitattributes | 3 +- Makefile | 2 +- config/crd/kustomization.yaml | 20 +++---- .../networking.x-k8s.io_backendpolicies.yaml | 0 .../networking.x-k8s.io_gatewayclasses.yaml | 0 .../networking.x-k8s.io_gateways.yaml | 0 .../networking.x-k8s.io_httproutes.yaml | 0 .../networking.x-k8s.io_tcproutes.yaml | 0 .../networking.x-k8s.io_tlsroutes.yaml | 0 .../networking.x-k8s.io_udproutes.yaml | 0 ...eway.networking.k8s.io_gatewayclasses.yaml | 0 .../gateway.networking.k8s.io_gateways.yaml | 0 .../gateway.networking.k8s.io_httproutes.yaml | 0 ...y.networking.k8s.io_referencepolicies.yaml | 0 .../gateway.networking.k8s.io_tcproutes.yaml | 0 .../gateway.networking.k8s.io_tlsroutes.yaml | 0 .../gateway.networking.k8s.io_udproutes.yaml | 0 hack/update-codegen.sh | 16 ++++-- hack/verify-crds.sh | 57 ------------------- hack/verify-examples-kind.sh | 18 ++++-- 20 files changed, 33 insertions(+), 83 deletions(-) rename config/crd/{bases => v1alpha1}/networking.x-k8s.io_backendpolicies.yaml (100%) rename config/crd/{bases => v1alpha1}/networking.x-k8s.io_gatewayclasses.yaml (100%) rename config/crd/{bases => v1alpha1}/networking.x-k8s.io_gateways.yaml (100%) rename config/crd/{bases => v1alpha1}/networking.x-k8s.io_httproutes.yaml (100%) rename config/crd/{bases => v1alpha1}/networking.x-k8s.io_tcproutes.yaml (100%) rename config/crd/{bases => v1alpha1}/networking.x-k8s.io_tlsroutes.yaml (100%) rename config/crd/{bases => v1alpha1}/networking.x-k8s.io_udproutes.yaml (100%) rename config/crd/{bases => v1alpha2}/gateway.networking.k8s.io_gatewayclasses.yaml (100%) rename config/crd/{bases => v1alpha2}/gateway.networking.k8s.io_gateways.yaml (100%) rename config/crd/{bases => v1alpha2}/gateway.networking.k8s.io_httproutes.yaml (100%) rename config/crd/{bases => v1alpha2}/gateway.networking.k8s.io_referencepolicies.yaml (100%) rename config/crd/{bases => v1alpha2}/gateway.networking.k8s.io_tcproutes.yaml (100%) rename config/crd/{bases => v1alpha2}/gateway.networking.k8s.io_tlsroutes.yaml (100%) rename config/crd/{bases => v1alpha2}/gateway.networking.k8s.io_udproutes.yaml (100%) delete mode 100755 hack/verify-crds.sh diff --git a/.gitattributes b/.gitattributes index f0a5740c80..200d10edf6 100644 --- a/.gitattributes +++ b/.gitattributes @@ -8,6 +8,7 @@ apis/generated/** linguist-generated=true apis/**/generated.pb.go linguist-generated=true apis/**/generated.proto linguist-generated=true -config/crd/bases/** linguist-generated=true +config/crd/v1alpha1/** linguist-generated=true +config/crd/v1alpha2/** linguist-generated=true pkg/client/** linguist-generated=true diff --git a/Makefile b/Makefile index 2a4906af17..ddc441a38a 100644 --- a/Makefile +++ b/Makefile @@ -51,7 +51,7 @@ install: crd example # Install the CRD's to a pre-existing cluster. .PHONY: crd crd: - kubectl kustomize config/crd | kubectl apply -f - + kubectl kustomize config/crd/v1alpha2 | kubectl apply -f - # Install the example resources to a pre-existing cluster. .PHONY: example diff --git a/config/crd/kustomization.yaml b/config/crd/kustomization.yaml index 572f17d5c7..5d90b939aa 100644 --- a/config/crd/kustomization.yaml +++ b/config/crd/kustomization.yaml @@ -1,14 +1,8 @@ resources: -- bases/networking.x-k8s.io_gatewayclasses.yaml -- bases/networking.x-k8s.io_gateways.yaml -- bases/networking.x-k8s.io_httproutes.yaml -- bases/networking.x-k8s.io_tcproutes.yaml -- bases/networking.x-k8s.io_tlsroutes.yaml -- bases/networking.x-k8s.io_udproutes.yaml -- bases/networking.x-k8s.io_backendpolicies.yaml -- bases/gateway.networking.k8s.io_gatewayclasses.yaml -- bases/gateway.networking.k8s.io_gateways.yaml -- bases/gateway.networking.k8s.io_httproutes.yaml -- bases/gateway.networking.k8s.io_tcproutes.yaml -- bases/gateway.networking.k8s.io_tlsroutes.yaml -- bases/gateway.networking.k8s.io_udproutes.yaml +- v1alpha2/gateway.networking.k8s.io_gatewayclasses.yaml +- v1alpha2/gateway.networking.k8s.io_gateways.yaml +- v1alpha2/gateway.networking.k8s.io_httproutes.yaml +- v1alpha2/gateway.networking.k8s.io_referencepolicies.yaml +- v1alpha2/gateway.networking.k8s.io_tcproutes.yaml +- v1alpha2/gateway.networking.k8s.io_tlsroutes.yaml +- v1alpha2/gateway.networking.k8s.io_udproutes.yaml diff --git a/config/crd/bases/networking.x-k8s.io_backendpolicies.yaml b/config/crd/v1alpha1/networking.x-k8s.io_backendpolicies.yaml similarity index 100% rename from config/crd/bases/networking.x-k8s.io_backendpolicies.yaml rename to config/crd/v1alpha1/networking.x-k8s.io_backendpolicies.yaml diff --git a/config/crd/bases/networking.x-k8s.io_gatewayclasses.yaml b/config/crd/v1alpha1/networking.x-k8s.io_gatewayclasses.yaml similarity index 100% rename from config/crd/bases/networking.x-k8s.io_gatewayclasses.yaml rename to config/crd/v1alpha1/networking.x-k8s.io_gatewayclasses.yaml diff --git a/config/crd/bases/networking.x-k8s.io_gateways.yaml b/config/crd/v1alpha1/networking.x-k8s.io_gateways.yaml similarity index 100% rename from config/crd/bases/networking.x-k8s.io_gateways.yaml rename to config/crd/v1alpha1/networking.x-k8s.io_gateways.yaml diff --git a/config/crd/bases/networking.x-k8s.io_httproutes.yaml b/config/crd/v1alpha1/networking.x-k8s.io_httproutes.yaml similarity index 100% rename from config/crd/bases/networking.x-k8s.io_httproutes.yaml rename to config/crd/v1alpha1/networking.x-k8s.io_httproutes.yaml diff --git a/config/crd/bases/networking.x-k8s.io_tcproutes.yaml b/config/crd/v1alpha1/networking.x-k8s.io_tcproutes.yaml similarity index 100% rename from config/crd/bases/networking.x-k8s.io_tcproutes.yaml rename to config/crd/v1alpha1/networking.x-k8s.io_tcproutes.yaml diff --git a/config/crd/bases/networking.x-k8s.io_tlsroutes.yaml b/config/crd/v1alpha1/networking.x-k8s.io_tlsroutes.yaml similarity index 100% rename from config/crd/bases/networking.x-k8s.io_tlsroutes.yaml rename to config/crd/v1alpha1/networking.x-k8s.io_tlsroutes.yaml diff --git a/config/crd/bases/networking.x-k8s.io_udproutes.yaml b/config/crd/v1alpha1/networking.x-k8s.io_udproutes.yaml similarity index 100% rename from config/crd/bases/networking.x-k8s.io_udproutes.yaml rename to config/crd/v1alpha1/networking.x-k8s.io_udproutes.yaml diff --git a/config/crd/bases/gateway.networking.k8s.io_gatewayclasses.yaml b/config/crd/v1alpha2/gateway.networking.k8s.io_gatewayclasses.yaml similarity index 100% rename from config/crd/bases/gateway.networking.k8s.io_gatewayclasses.yaml rename to config/crd/v1alpha2/gateway.networking.k8s.io_gatewayclasses.yaml diff --git a/config/crd/bases/gateway.networking.k8s.io_gateways.yaml b/config/crd/v1alpha2/gateway.networking.k8s.io_gateways.yaml similarity index 100% rename from config/crd/bases/gateway.networking.k8s.io_gateways.yaml rename to config/crd/v1alpha2/gateway.networking.k8s.io_gateways.yaml diff --git a/config/crd/bases/gateway.networking.k8s.io_httproutes.yaml b/config/crd/v1alpha2/gateway.networking.k8s.io_httproutes.yaml similarity index 100% rename from config/crd/bases/gateway.networking.k8s.io_httproutes.yaml rename to config/crd/v1alpha2/gateway.networking.k8s.io_httproutes.yaml diff --git a/config/crd/bases/gateway.networking.k8s.io_referencepolicies.yaml b/config/crd/v1alpha2/gateway.networking.k8s.io_referencepolicies.yaml similarity index 100% rename from config/crd/bases/gateway.networking.k8s.io_referencepolicies.yaml rename to config/crd/v1alpha2/gateway.networking.k8s.io_referencepolicies.yaml diff --git a/config/crd/bases/gateway.networking.k8s.io_tcproutes.yaml b/config/crd/v1alpha2/gateway.networking.k8s.io_tcproutes.yaml similarity index 100% rename from config/crd/bases/gateway.networking.k8s.io_tcproutes.yaml rename to config/crd/v1alpha2/gateway.networking.k8s.io_tcproutes.yaml diff --git a/config/crd/bases/gateway.networking.k8s.io_tlsroutes.yaml b/config/crd/v1alpha2/gateway.networking.k8s.io_tlsroutes.yaml similarity index 100% rename from config/crd/bases/gateway.networking.k8s.io_tlsroutes.yaml rename to config/crd/v1alpha2/gateway.networking.k8s.io_tlsroutes.yaml diff --git a/config/crd/bases/gateway.networking.k8s.io_udproutes.yaml b/config/crd/v1alpha2/gateway.networking.k8s.io_udproutes.yaml similarity index 100% rename from config/crd/bases/gateway.networking.k8s.io_udproutes.yaml rename to config/crd/v1alpha2/gateway.networking.k8s.io_udproutes.yaml diff --git a/hack/update-codegen.sh b/hack/update-codegen.sh index 82b8d316d4..ec97a42331 100755 --- a/hack/update-codegen.sh +++ b/hack/update-codegen.sh @@ -45,16 +45,22 @@ fi readonly COMMON_FLAGS="${VERIFY_FLAG:-} --go-header-file ${SCRIPT_ROOT}/hack/boilerplate/boilerplate.generatego.txt" -echo "Generating CRDs and deepcopy" +echo "Generating v1alpha1 CRDs and deepcopy" go run sigs.k8s.io/controller-tools/cmd/controller-gen \ object:headerFile=./hack/boilerplate/boilerplate.generatego.txt \ crd:crdVersions=v1 \ - output:crd:artifacts:config=config/crd/bases \ - paths=./... + output:crd:artifacts:config=config/crd/v1alpha1 \ + paths=./apis/v1alpha1 -# TODO(robscott): Change this once v1alpha2 has received formal API approval. -sed -i -e 's/controller\-gen\.kubebuilder\.io\/version\:\ v0\.5\.0/api\-approved\.kubernetes\.io\:\ unapproved/g' config/crd/bases/gateway.networking.k8s.io* +echo "Generating v1alpha2 CRDs and deepcopy" +go run sigs.k8s.io/controller-tools/cmd/controller-gen \ + object:headerFile=./hack/boilerplate/boilerplate.generatego.txt \ + crd:crdVersions=v1 \ + output:crd:artifacts:config=config/crd/v1alpha2 \ + paths=./apis/v1alpha2 +# TODO(robscott): Change this once v1alpha2 has received formal API approval. +sed -i -e 's/controller\-gen\.kubebuilder\.io\/version\:\ v0\.5\.0/api\-approved\.kubernetes\.io\:\ unapproved/g' config/crd/v1alpha2/gateway.networking.k8s.io* for VERSION in v1alpha1 v1alpha2 do diff --git a/hack/verify-crds.sh b/hack/verify-crds.sh deleted file mode 100755 index c936fd8c0a..0000000000 --- a/hack/verify-crds.sh +++ /dev/null @@ -1,57 +0,0 @@ -#!/bin/bash - -# Copyright 2020 The Kubernetes Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -set -o errexit -set -o nounset -set -o pipefail - -SCRIPT_ROOT=$(dirname "${BASH_SOURCE}")/.. -DIFFROOT="${SCRIPT_ROOT}/config/crd/bases" -TMP_DIFFROOT="${SCRIPT_ROOT}/_tmp/config/crd/bases" -_tmp="${SCRIPT_ROOT}/_tmp" -# The controller-gen command for generating CRDs from API definitions. -CONTROLLER_GEN="go run sigs.k8s.io/controller-tools/cmd/controller-gen" -# Need v1 to support defaults in CRDs, unfortunately limiting us to k8s 1.16+ -CRD_OPTIONS="crd:crdVersions=v1" - -cd "${SCRIPT_ROOT}" - -cleanup() { - rm -rf "${_tmp}" -} -trap "cleanup" EXIT SIGINT - -cleanup - -mkdir -p "${TMP_DIFFROOT}" -cp -a "${DIFFROOT}"/* "${TMP_DIFFROOT}" - -${CONTROLLER_GEN} ${CRD_OPTIONS} rbac:roleName=manager-role webhook \ -paths="./..." output:crd:artifacts:config=${TMP_DIFFROOT} - -# TODO(robscott): Change this once v1alpha2 has received formal API approval. -sed -i -e 's/controller\-gen\.kubebuilder\.io\/version\:\ v0\.5\.0/api\-approved\.kubernetes\.io\:\ unapproved/g' ${TMP_DIFFROOT}/gateway.networking.k8s.io* - -echo "diffing ${DIFFROOT} against freshly generated codegen in ${TMP_DIFFROOT}" -ret=0 -diff -Naupr "${DIFFROOT}" "${TMP_DIFFROOT}" || ret=$? -if [[ $ret -eq 0 ]] -then - echo "${DIFFROOT} up to date." -else - echo "${DIFFROOT} is out of date. Please run 'make manifests'" - exit 1 -fi diff --git a/hack/verify-examples-kind.sh b/hack/verify-examples-kind.sh index 9a5ad0769e..7d0182800d 100755 --- a/hack/verify-examples-kind.sh +++ b/hack/verify-examples-kind.sh @@ -51,14 +51,20 @@ res=0 KIND_CREATE_ATTEMPTED=true kind create cluster --name "${CLUSTER_NAME}" --kubeconfig "${KUBECONFIG}" || res=$? -# Install CRDs -kubectl apply --kubeconfig "${KUBECONFIG}" -f config/crd/bases || res=$? +for VERSION in v1alpha1 v1alpha2 +do + # Install CRDs + kubectl apply --kubeconfig "${KUBECONFIG}" -f config/crd/"${VERSION}" || res=$? -# Temporary workaround for https://github.com/kubernetes/kubernetes/issues/104090 -sleep 8 + # Temporary workaround for https://github.com/kubernetes/kubernetes/issues/104090 + sleep 8 -# Install all example gateway-api resources. -kubectl apply --kubeconfig "${KUBECONFIG}" --recursive -f examples || res=$? + # Install all example gateway-api resources. + kubectl apply --kubeconfig "${KUBECONFIG}" --recursive -f examples/"${VERSION}" || res=$? + + # Uninstall CRDs + kubectl delete --kubeconfig "${KUBECONFIG}" -f config/crd/"${VERSION}" || res=$? +done # Clean up and exit cleanup || res=$?