Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
build: Use KinD cluster for syncing up API resources in charts
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmidyson committed Aug 8, 2022
1 parent 356ad5b commit c186056
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 69 deletions.
6 changes: 3 additions & 3 deletions charts/kubefed/templates/federatedtypeconfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: core.kubefed.io/v1beta1
kind: EnableTypeDirective
metadata:
name: ingresses.extensions
name: ingresses.networking.k8s.io
18 changes: 16 additions & 2 deletions scripts/download-binaries.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
40 changes: 5 additions & 35 deletions scripts/sync-up-helm-chart.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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

Expand All @@ -59,38 +53,17 @@ 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 <<EOF > ${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
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

Expand All @@ -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"
7 changes: 7 additions & 0 deletions scripts/util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
}
46 changes: 24 additions & 22 deletions test/common/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions test/common/fixtures/ingresses.extensions.yaml

This file was deleted.

8 changes: 8 additions & 0 deletions test/common/fixtures/ingresses.networking.k8s.io.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
kind: fixture
template:
spec:
defaultBackend:
service:
name: testsvc
port:
number: 80

0 comments on commit c186056

Please sign in to comment.