Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Extract hnc installation in script
Browse files Browse the repository at this point in the history
  • Loading branch information
mnitchev authored and gcapizzi committed Oct 11, 2021
1 parent 06156af commit 3f19b8c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 23 deletions.
24 changes: 1 addition & 23 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -75,30 +75,8 @@ GINKGO = $(shell pwd)/bin/ginkgo
ginkgo:
$(call go-get-tool,$(GINKGO),github.com/onsi/ginkgo/ginkgo@latest)

HNC_VERSION ?= v0.8.0
HNC_PLATFORM=$(shell go env GOHOSTOS)_$(shell go env GOHOSTARCH)
HNC_BIN=$(shell pwd)/bin
export PATH := $(HNC_BIN):$(PATH)
hnc-install:
mkdir -p "$(HNC_BIN)"
curl -L https://github.com/kubernetes-sigs/multi-tenancy/releases/download/hnc-$(HNC_VERSION)/kubectl-hns_$(HNC_PLATFORM) -o "$(HNC_BIN)/kubectl-hns"
chmod +x "$(HNC_BIN)/kubectl-hns"

kubectl label ns kube-system hnc.x-k8s.io/excluded-namespace=true --overwrite
kubectl label ns kube-public hnc.x-k8s.io/excluded-namespace=true --overwrite
kubectl label ns kube-node-lease hnc.x-k8s.io/excluded-namespace=true --overwrite
kubectl apply -f https://github.com/kubernetes-sigs/multi-tenancy/releases/download/hnc-$(HNC_VERSION)/hnc-manager.yaml
kubectl rollout status deployment/hnc-controller-manager -w -n hnc-system
# Hierarchical namespace controller is quite asynchronous. There is no
# guarantee that the operations below would succeed on first invocation,
# so retry until they do.
echo -n waiting for hns controller to be ready and servicing validating webhooks
until kubectl create namespace ping-hnc; do echo -n .; sleep 0.5; done
until kubectl hns create -n ping-hnc ping-hnc-child; do echo -n .; sleep 0.5; done
until kubectl get namespace ping-hnc-child; do echo -n .; sleep 0.5; done
until kubectl hns set --allowCascadingDeletion ping-hnc; do echo -n .; sleep 0.5; done
until kubectl delete namespace ping-hnc --wait=false; do echo -n .; sleep 0.5; done
echo
./scripts/install-hnc.sh

# go-get-tool will 'go get' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
Expand Down
44 changes: 44 additions & 0 deletions scripts/install-hnc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash

set -euxo pipefail

readonly HNC_VERSION="v0.8.0"
readonly HNC_PLATFORM="$(go env GOHOSTOS)_$(go env GOHOSTARCH)"
readonly HNC_BIN="$PWD/bin"
export PATH="$HNC_BIN:$PATH"

mkdir -p "$HNC_BIN"
curl -L "https://github.com/kubernetes-sigs/multi-tenancy/releases/download/hnc-${HNC_VERSION}/kubectl-hns_${HNC_PLATFORM}" -o "${HNC_BIN}/kubectl-hns"
chmod +x "${HNC_BIN}/kubectl-hns"

kubectl label ns kube-system hnc.x-k8s.io/excluded-namespace=true --overwrite
kubectl label ns kube-public hnc.x-k8s.io/excluded-namespace=true --overwrite
kubectl label ns kube-node-lease hnc.x-k8s.io/excluded-namespace=true --overwrite
kubectl apply -f "https://github.com/kubernetes-sigs/multi-tenancy/releases/download/hnc-${HNC_VERSION}/hnc-manager.yaml"
kubectl rollout status deployment/hnc-controller-manager -w -n hnc-system

# Hierarchical namespace controller is quite asynchronous. There is no
# guarantee that the operations below would succeed on first invocation,
# so retry until they do.
echo -n waiting for hns controller to be ready and servicing validating webhooks
until kubectl create namespace ping-hnc; do
echo -n .
sleep 0.5
done
until kubectl hns create -n ping-hnc ping-hnc-child; do
echo -n .
sleep 0.5
done
until kubectl get namespace ping-hnc-child; do
echo -n .
sleep 0.5
done
until kubectl hns set --allowCascadingDeletion ping-hnc; do
echo -n .
sleep 0.5
done
until kubectl delete namespace ping-hnc --wait=false; do
echo -n .
sleep 0.5
done
echo

0 comments on commit 3f19b8c

Please sign in to comment.