From 81f089c560c9cef2d0561fa68119c14444a5fcbc Mon Sep 17 00:00:00 2001 From: Jimmi Dyson Date: Mon, 8 Aug 2022 14:11:27 +0100 Subject: [PATCH] build: Use KinD cluster for syncing up API resources in charts --- .../templates/federatedtypeconfig.yaml | 6 +-- ....yaml => ingresses.networking.k8s.io.yaml} | 2 +- scripts/download-binaries.sh | 18 ++++++++- scripts/sync-up-helm-chart.sh | 40 +++---------------- scripts/util.sh | 7 ++++ test/common/bindata.go | 38 +++++++++--------- ....yaml => ingresses.networking.k8s.io.yaml} | 0 7 files changed, 51 insertions(+), 60 deletions(-) rename config/enabletypedirectives/{ingresses.extensions.yaml => ingresses.networking.k8s.io.yaml} (66%) rename test/common/fixtures/{ingresses.extensions.yaml => ingresses.networking.k8s.io.yaml} (100%) diff --git a/charts/kubefed/templates/federatedtypeconfig.yaml b/charts/kubefed/templates/federatedtypeconfig.yaml index f85c862c53..ef30b402ea 100644 --- a/charts/kubefed/templates/federatedtypeconfig.yaml +++ b/charts/kubefed/templates/federatedtypeconfig.yaml @@ -58,7 +58,7 @@ spec: apiVersion: core.kubefed.io/v1beta1 kind: FederatedTypeConfig metadata: - name: ingresses.extensions + name: ingresses.networking.k8s.io spec: federatedType: group: types.kubefed.io @@ -68,11 +68,11 @@ spec: version: v1beta1 propagation: Enabled targetType: - group: extensions + group: networking.k8s.io kind: Ingress pluralName: ingresses scope: Namespaced - version: v1beta1 + version: v1 --- apiVersion: core.kubefed.io/v1beta1 kind: FederatedTypeConfig diff --git a/config/enabletypedirectives/ingresses.extensions.yaml b/config/enabletypedirectives/ingresses.networking.k8s.io.yaml similarity index 66% rename from config/enabletypedirectives/ingresses.extensions.yaml rename to config/enabletypedirectives/ingresses.networking.k8s.io.yaml index 4a066ebb1a..066a1c94e8 100644 --- a/config/enabletypedirectives/ingresses.extensions.yaml +++ b/config/enabletypedirectives/ingresses.networking.k8s.io.yaml @@ -1,4 +1,4 @@ apiVersion: core.kubefed.io/v1beta1 kind: EnableTypeDirective metadata: - name: ingresses.extensions + name: ingresses.networking.k8s.io diff --git a/scripts/download-binaries.sh b/scripts/download-binaries.sh index 794a381204..a571bf1195 100755 --- a/scripts/download-binaries.sh +++ b/scripts/download-binaries.sh @@ -47,14 +47,26 @@ go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest source <(setup-envtest use -p env 1.24.x) -echo "KUBEBUILDER_ASSETS is set to KUBEBUILDER_ASSETS" +echo "KUBEBUILDER_ASSETS is set to ${KUBEBUILDER_ASSETS}" -helm_version="3.6.0" +helm_version="3.9.2" helm_tgz="helm-v${helm_version}-${platform}-amd64.tar.gz" helm_url="https://get.helm.sh/$helm_tgz" curl "${curl_args}" "${helm_url}" \ | tar xzP -C "${dest_dir}" --strip-components=1 "${platform}-amd64/helm" +kubectl_version="v1.23.4" +curl -Lo "${dest_dir}/kubectl" "https://dl.k8s.io/release/${kubectl_version}/bin/${platform}/amd64/kubectl" +(cd "${dest_dir}" && \ + echo "$(curl -L "https://dl.k8s.io/release/${kubectl_version}/bin/${platform}/amd64/kubectl.sha256") kubectl" | \ + sha256sum --check +) +chmod +x "${dest_dir}/kubectl" + +kubebuilder_version="2.3.2" +curl -L https://github.com/kubernetes-sigs/kubebuilder/releases/download/v${kubebuilder_version}/kubebuilder_${kubebuilder_version}_${platform}_amd64.tar.gz | \ + tar xzP -C "${dest_dir}" --strip-components=2 -- "kubebuilder_${kubebuilder_version}_${platform}_amd64/bin/kubebuilder" + golint_version="1.40.1" golint_dir="golangci-lint-${golint_version}-${platform}-amd64" golint_tgz="${golint_dir}.tar.gz" @@ -75,3 +87,5 @@ echo -n "# kubebuilder: "; "${dest_dir}/kubebuilder" version echo -n "# helm: "; "${dest_dir}/helm" version --client --short echo -n "# golangci-lint: "; "${dest_dir}/golangci-lint" --version echo -n "# go-bindata: "; "${dest_dir}/go-bindata" -version + +"${root_dir}/scripts/download-e2e-binaries.sh" diff --git a/scripts/sync-up-helm-chart.sh b/scripts/sync-up-helm-chart.sh index 4c00f45a0a..5ac3501b4e 100755 --- a/scripts/sync-up-helm-chart.sh +++ b/scripts/sync-up-helm-chart.sh @@ -22,6 +22,7 @@ source "$(dirname "${BASH_SOURCE}")/util.sh" ROOT_DIR="$(cd "$(dirname "$0")/.." ; pwd)" WORKDIR=$(mktemp -d) +trap-add 'rm -rf "${WORKDIR}"' EXIT NS="${KUBEFED_NAMESPACE:-kube-federation-system}" CHART_FEDERATED_PROPAGATION_DIR="${CHART_FEDERATED_PROPAGATION_DIR:-charts/kubefed}" TEMP_CRDS_YAML="/tmp/kubefed-crds.yaml" @@ -36,13 +37,6 @@ if [ "${OS}" == "Darwin" ];then SED=gsed fi -# Check for existence of kube-apiserver and etcd binaries in bin directory -if [[ ! -f ${ROOT_DIR}/bin/etcd || ! -f ${ROOT_DIR}/bin/kube-apiserver ]]; -then - echo "Missing 'etcd' and/or 'kube-apiserver' binaries in bin directory. Call './scripts/download-binaries.sh' to download them first" - exit 1 -fi - # Remove existing generated crds to ensure that stale content doesn't linger. rm -f ./config/crds/*.yaml @@ -59,30 +53,9 @@ done mv ${TEMP_CRDS_YAML} ./charts/kubefed/charts/controllermanager/crds/crds.yaml -# Generate kubeconfig to access kube-apiserver. It is cleaned when script is done. -cat < ${WORKDIR}/kubeconfig -apiVersion: v1 -clusters: -- cluster: - server: 127.0.0.1:8080 - name: development -contexts: -- context: - cluster: development - user: "" - name: kubefed -current-context: "" -kind: Config -preferences: {} -users: [] -EOF - -# Start kube-apiserver to generate CRDs -${ROOT_DIR}/bin/etcd --data-dir ${WORKDIR} --log-output stdout > ${WORKDIR}/etcd.log 2>&1 & -util::wait-for-condition 'etcd' "curl http://127.0.0.1:2379/version &> /dev/null" 30 - -${ROOT_DIR}/bin/kube-apiserver --etcd-servers=http://127.0.0.1:2379 --service-cluster-ip-range=10.0.0.0/16 --cert-dir=${WORKDIR} 2> ${WORKDIR}/kube-apiserver.log & -util::wait-for-condition 'kube-apiserver' "kubectl --kubeconfig ${WORKDIR}/kubeconfig --context kubefed get --raw=/healthz &> /dev/null" 60 +declare -rx KUBECONFIG="${WORKDIR}/kubeconfig" +kind create cluster --name=kubefed-dev +trap-add 'kind delete cluster --name=kubefed-dev' EXIT # Generate YAML templates to enable resource propagation for helm chart. echo -n > ${CHART_FEDERATED_PROPAGATION_DIR}/templates/federatedtypeconfig.yaml @@ -90,7 +63,7 @@ echo -n > ${CHART_FEDERATED_PROPAGATION_DIR}/crds/crds.yaml for filename in ./config/enabletypedirectives/*.yaml; do full_name=${CHART_FEDERATED_PROPAGATION_DIR}/templates/$(basename $filename) - ./bin/kubefedctl --kubeconfig ${WORKDIR}/kubeconfig enable -f "${filename}" --kubefed-namespace="${NS}" --host-cluster-context kubefed -o yaml > ${full_name} + ./bin/kubefedctl --kubeconfig ${WORKDIR}/kubeconfig enable -f "${filename}" --kubefed-namespace="${NS}" -o yaml > ${full_name} $SED -n '/^---/,/^---/p' ${full_name} >> ${CHART_FEDERATED_PROPAGATION_DIR}/templates/federatedtypeconfig.yaml $SED -i '$d' ${CHART_FEDERATED_PROPAGATION_DIR}/templates/federatedtypeconfig.yaml @@ -101,7 +74,4 @@ for filename in ./config/enabletypedirectives/*.yaml; do done # Clean kube-apiserver daemons and temporary files -kill %1 # etcd -kill %2 # kube-apiserver -rm -fr ${WORKDIR} echo "Helm chart synced successfully" diff --git a/scripts/util.sh b/scripts/util.sh index 3787fb3bfb..d82b3f9b7f 100644 --- a/scripts/util.sh +++ b/scripts/util.sh @@ -119,3 +119,10 @@ function check-command-installed() { exit 1 } } + +trap-add() { + local sig="${2:?Signal required}" + hdls="$(trap -p "${sig}" | cut -f2 -d \')" + # shellcheck disable=SC2064 # Quotes are required here to properly expand when adding the new trap. + trap "${hdls}${hdls:+;}${1:?Handler required}" "${sig}" +} diff --git a/test/common/bindata.go b/test/common/bindata.go index 6c4defded0..1d68508b7a 100644 --- a/test/common/bindata.go +++ b/test/common/bindata.go @@ -20,7 +20,7 @@ limitations under the License. // test/common/fixtures/clusterroles.rbac.authorization.k8s.io.yaml // test/common/fixtures/configmaps.yaml // test/common/fixtures/deployments.apps.yaml -// test/common/fixtures/ingresses.extensions.yaml +// test/common/fixtures/ingresses.networking.k8s.io.yaml // test/common/fixtures/jobs.batch.yaml // test/common/fixtures/namespaces.yaml // test/common/fixtures/replicasets.apps.yaml @@ -31,7 +31,7 @@ limitations under the License. // config/enabletypedirectives/clusterroles.rbac.authorization.k8s.io.yaml // config/enabletypedirectives/configmaps.yaml // config/enabletypedirectives/deployments.apps.yaml -// config/enabletypedirectives/ingresses.extensions.yaml +// config/enabletypedirectives/ingresses.networking.k8s.io.yaml // config/enabletypedirectives/jobs.batch.yaml // config/enabletypedirectives/namespaces.yaml // config/enabletypedirectives/replicasets.apps.yaml @@ -182,7 +182,7 @@ func testCommonFixturesDeploymentsAppsYaml() (*asset, error) { return a, nil } -var _testCommonFixturesIngressesExtensionsYaml = []byte(`kind: fixture +var _testCommonFixturesIngressesNetworkingK8sIoYaml = []byte(`kind: fixture template: spec: backend: @@ -190,17 +190,17 @@ template: servicePort: 80 `) -func testCommonFixturesIngressesExtensionsYamlBytes() ([]byte, error) { - return _testCommonFixturesIngressesExtensionsYaml, nil +func testCommonFixturesIngressesNetworkingK8sIoYamlBytes() ([]byte, error) { + return _testCommonFixturesIngressesNetworkingK8sIoYaml, nil } -func testCommonFixturesIngressesExtensionsYaml() (*asset, error) { - bytes, err := testCommonFixturesIngressesExtensionsYamlBytes() +func testCommonFixturesIngressesNetworkingK8sIoYaml() (*asset, error) { + bytes, err := testCommonFixturesIngressesNetworkingK8sIoYamlBytes() if err != nil { return nil, err } - info := bindataFileInfo{name: "test/common/fixtures/ingresses.extensions.yaml", size: 0, mode: os.FileMode(0), modTime: time.Unix(0, 0)} + info := bindataFileInfo{name: "test/common/fixtures/ingresses.networking.k8s.io.yaml", size: 0, mode: os.FileMode(0), modTime: time.Unix(0, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -485,23 +485,23 @@ func configEnabletypedirectivesDeploymentsAppsYaml() (*asset, error) { return a, nil } -var _configEnabletypedirectivesIngressesExtensionsYaml = []byte(`apiVersion: core.kubefed.io/v1beta1 +var _configEnabletypedirectivesIngressesNetworkingK8sIoYaml = []byte(`apiVersion: core.kubefed.io/v1beta1 kind: EnableTypeDirective metadata: - name: ingresses.extensions + name: ingresses.networking.k8s.io `) -func configEnabletypedirectivesIngressesExtensionsYamlBytes() ([]byte, error) { - return _configEnabletypedirectivesIngressesExtensionsYaml, nil +func configEnabletypedirectivesIngressesNetworkingK8sIoYamlBytes() ([]byte, error) { + return _configEnabletypedirectivesIngressesNetworkingK8sIoYaml, nil } -func configEnabletypedirectivesIngressesExtensionsYaml() (*asset, error) { - bytes, err := configEnabletypedirectivesIngressesExtensionsYamlBytes() +func configEnabletypedirectivesIngressesNetworkingK8sIoYaml() (*asset, error) { + bytes, err := configEnabletypedirectivesIngressesNetworkingK8sIoYamlBytes() if err != nil { return nil, err } - info := bindataFileInfo{name: "config/enabletypedirectives/ingresses.extensions.yaml", size: 0, mode: os.FileMode(0), modTime: time.Unix(0, 0)} + info := bindataFileInfo{name: "config/enabletypedirectives/ingresses.networking.k8s.io.yaml", size: 0, mode: os.FileMode(0), modTime: time.Unix(0, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -687,7 +687,7 @@ var _bindata = map[string]func() (*asset, error){ "test/common/fixtures/clusterroles.rbac.authorization.k8s.io.yaml": testCommonFixturesClusterrolesRbacAuthorizationK8sIoYaml, "test/common/fixtures/configmaps.yaml": testCommonFixturesConfigmapsYaml, "test/common/fixtures/deployments.apps.yaml": testCommonFixturesDeploymentsAppsYaml, - "test/common/fixtures/ingresses.extensions.yaml": testCommonFixturesIngressesExtensionsYaml, + "test/common/fixtures/ingresses.networking.k8s.io.yaml": testCommonFixturesIngressesNetworkingK8sIoYaml, "test/common/fixtures/jobs.batch.yaml": testCommonFixturesJobsBatchYaml, "test/common/fixtures/namespaces.yaml": testCommonFixturesNamespacesYaml, "test/common/fixtures/replicasets.apps.yaml": testCommonFixturesReplicasetsAppsYaml, @@ -698,7 +698,7 @@ var _bindata = map[string]func() (*asset, error){ "config/enabletypedirectives/clusterroles.rbac.authorization.k8s.io.yaml": configEnabletypedirectivesClusterrolesRbacAuthorizationK8sIoYaml, "config/enabletypedirectives/configmaps.yaml": configEnabletypedirectivesConfigmapsYaml, "config/enabletypedirectives/deployments.apps.yaml": configEnabletypedirectivesDeploymentsAppsYaml, - "config/enabletypedirectives/ingresses.extensions.yaml": configEnabletypedirectivesIngressesExtensionsYaml, + "config/enabletypedirectives/ingresses.networking.k8s.io.yaml": configEnabletypedirectivesIngressesNetworkingK8sIoYaml, "config/enabletypedirectives/jobs.batch.yaml": configEnabletypedirectivesJobsBatchYaml, "config/enabletypedirectives/namespaces.yaml": configEnabletypedirectivesNamespacesYaml, "config/enabletypedirectives/replicasets.apps.yaml": configEnabletypedirectivesReplicasetsAppsYaml, @@ -753,7 +753,7 @@ var _bintree = &bintree{nil, map[string]*bintree{ "clusterroles.rbac.authorization.k8s.io.yaml": &bintree{configEnabletypedirectivesClusterrolesRbacAuthorizationK8sIoYaml, map[string]*bintree{}}, "configmaps.yaml": &bintree{configEnabletypedirectivesConfigmapsYaml, map[string]*bintree{}}, "deployments.apps.yaml": &bintree{configEnabletypedirectivesDeploymentsAppsYaml, map[string]*bintree{}}, - "ingresses.extensions.yaml": &bintree{configEnabletypedirectivesIngressesExtensionsYaml, map[string]*bintree{}}, + "ingresses.networking.k8s.io.yaml": &bintree{configEnabletypedirectivesIngressesNetworkingK8sIoYaml, map[string]*bintree{}}, "jobs.batch.yaml": &bintree{configEnabletypedirectivesJobsBatchYaml, map[string]*bintree{}}, "namespaces.yaml": &bintree{configEnabletypedirectivesNamespacesYaml, map[string]*bintree{}}, "replicasets.apps.yaml": &bintree{configEnabletypedirectivesReplicasetsAppsYaml, map[string]*bintree{}}, @@ -769,7 +769,7 @@ var _bintree = &bintree{nil, map[string]*bintree{ "clusterroles.rbac.authorization.k8s.io.yaml": &bintree{testCommonFixturesClusterrolesRbacAuthorizationK8sIoYaml, map[string]*bintree{}}, "configmaps.yaml": &bintree{testCommonFixturesConfigmapsYaml, map[string]*bintree{}}, "deployments.apps.yaml": &bintree{testCommonFixturesDeploymentsAppsYaml, map[string]*bintree{}}, - "ingresses.extensions.yaml": &bintree{testCommonFixturesIngressesExtensionsYaml, map[string]*bintree{}}, + "ingresses.networking.k8s.io.yaml": &bintree{testCommonFixturesIngressesNetworkingK8sIoYaml, map[string]*bintree{}}, "jobs.batch.yaml": &bintree{testCommonFixturesJobsBatchYaml, map[string]*bintree{}}, "namespaces.yaml": &bintree{testCommonFixturesNamespacesYaml, map[string]*bintree{}}, "replicasets.apps.yaml": &bintree{testCommonFixturesReplicasetsAppsYaml, map[string]*bintree{}}, diff --git a/test/common/fixtures/ingresses.extensions.yaml b/test/common/fixtures/ingresses.networking.k8s.io.yaml similarity index 100% rename from test/common/fixtures/ingresses.extensions.yaml rename to test/common/fixtures/ingresses.networking.k8s.io.yaml