@@ -35,20 +35,22 @@ if uname -s | grep -q "Darwin"; then
3535 fi
3636fi
3737
38- CONFIG_DIR=~ /.kind-d8-operator-helm
38+ PARENT_DIR=$( cd -- " $( dirname -- " ${BASH_SOURCE[0]} " ) /.." & > /dev/null && pwd)
39+
40+ KIND_CLUSTER_NAME=${KIND_CLUSTER_NAME:- d8-operator-helm}
41+ KIND_CONFIG_DIR=${KIND_CONFIG_DIR:- $PARENT_DIR / kind} /$KIND_CLUSTER_NAME
3942KIND_IMAGE=kindest/node:v1.31.6@sha256:28b7cbb993dfe093c76641a0c95807637213c9109b761f1d422c2400e22b8e87
4043D8_RELEASE_CHANNEL_TAG=stable
4144D8_RELEASE_CHANNEL_NAME=Stable
4245D8_REGISTRY_ADDRESS=registry.deckhouse.io
4346D8_REGISTRY_PATH=${D8_REGISTRY_ADDRESS} /deckhouse/ce
4447D8_LICENSE_KEY=
4548
46- KIND_INSTALL_DIRECTORY=$CONFIG_DIR
49+ KIND_INSTALL_DIRECTORY=$PARENT_DIR /kind/bin
4750KIND_PATH=kind
48- KIND_CLUSTER_NAME=d8-operator-helm
4951KIND_VERSION=v0.27.0
5052
51- KUBECTL_INSTALL_DIRECTORY=$CONFIG_DIR
53+ KUBECTL_INSTALL_DIRECTORY=$PARENT_DIR /kind/bin
5254KUBECTL_PATH=kubectl
5355KUBECTL_VERSION=v1.31.6
5456
@@ -235,33 +237,10 @@ kubectl_check() {
235237 KUBECTL_PATH=${KUBECTL_INSTALL_DIRECTORY} /kubectl
236238 else
237239 echo " kubectl is not installed."
238- while [[ " $should_install_kubectl " != " y" ]]; do
239- read -rp " Install kubectl? y/[n]: " should_install_kubectl
240-
241- if [[ (" $should_install_kubectl " == " n" ) || (-z " $should_install_kubectl " ) ]]; then
242- printf "
243- Please install kubectl.
244-
245- You can find the installation instruction here: https://kubernetes.io/docs/tasks/tools/#kubectl
246- "
247- exit 1
248- fi
249-
250- if [[ " $should_install_kubectl " != " y" ]]; then
251- echo " Please type 'y' to continue or 'n' to abort the installation."
252- fi
253-
254- done
255-
256- read -rp " kubectl installation directory [$KUBECTL_INSTALL_DIRECTORY ]: " kubectl_install_directory_answer
257- if [[ -n " $kubectl_install_directory_answer " ]]; then
258- KUBECTL_INSTALL_DIRECTORY=$kubectl_install_directory_answer
259- fi
260-
261240 echo " Installing the latest stable kubectl version to ${KUBECTL_INSTALL_DIRECTORY} /kubectl ..."
262241
263242 mkdir -p $KUBECTL_INSTALL_DIRECTORY
264- curl -LO " https://dl.k8s.io/release/${KUBECTL_VERSION} /bin/${OS_NAME/ mac/ darwin} /${MACHINE_ARCH/ x86_64/ amd64} /kubectl"
243+ curl -sLO " https://dl.k8s.io/release/${KUBECTL_VERSION} /bin/${OS_NAME/ mac/ darwin} /${MACHINE_ARCH/ x86_64/ amd64} /kubectl"
265244
266245 if [ " $? " -ne " 0" ]; then
267246 echo " Unable to download kubectl."
@@ -294,18 +273,18 @@ kind_check() {
294273
295274 mkdir -p ${KIND_INSTALL_DIRECTORY}
296275
297- curl -Lo ./kind " https://kind.sigs.k8s.io/dl/${KIND_VERSION} /kind-${OS_NAME/ mac/ darwin} -${MACHINE_ARCH/ x86_64/ amd64} "
276+ curl -sLo ./kind-binary " https://kind.sigs.k8s.io/dl/${KIND_VERSION} /kind-${OS_NAME/ mac/ darwin} -${MACHINE_ARCH/ x86_64/ amd64} "
298277
299278 if [ " $? " -ne " 0" ]; then
300279 echo " Unable to download kind."
301280 exit 1
302281 fi
303282
304- install -m 0755 kind " ${KIND_INSTALL_DIRECTORY} " /kind
283+ install -m 0755 kind-binary " ${KIND_INSTALL_DIRECTORY} " /kind
305284
306285 if [ " $? " -ne " 0" ]; then
307286 echo " Insufficient permissions to install kind. Trying again with sudo..."
308- sudo install -m 0755 kind " ${KIND_INSTALL_DIRECTORY} " /kind
287+ sudo install -m 0755 kind-binary " ${KIND_INSTALL_DIRECTORY} " /kind
309288 if [ " $? " -ne " 0" ]; then
310289 echo " Unable to install kind. Check installation path and permissions."
311290 exit 1
@@ -338,10 +317,10 @@ preinstall_checks() {
338317}
339318
340319configs_create () {
341- mkdir -p ${CONFIG_DIR }
320+ mkdir -p ${KIND_CONFIG_DIR }
342321
343- echo " Creating kind config file (${CONFIG_DIR } /kind.cfg)..."
344- cat << EOF >${CONFIG_DIR } /kind.cfg
322+ echo " Creating kind config file (${KIND_CONFIG_DIR } /kind.cfg)..."
323+ cat << EOF >${KIND_CONFIG_DIR } /kind.cfg
345324apiVersion: kind.x-k8s.io/v1alpha4
346325kind: Cluster
347326featureGates:
@@ -361,8 +340,8 @@ nodes:
361340 protocol: TCP
362341EOF
363342
364- echo " Creating Deckhouse Kubernetes Platform installation config file (${CONFIG_DIR } /config.yml)..."
365- cat << EOF >${CONFIG_DIR } /config.yml
343+ echo " Creating Deckhouse Kubernetes Platform installation config file (${KIND_CONFIG_DIR } /config.yml)..."
344+ cat << EOF >${KIND_CONFIG_DIR } /config.yml
366345apiVersion: deckhouse.io/v1alpha1
367346kind: ModuleConfig
368347metadata:
457436
458437 if [[ -n " $D8_LICENSE_KEY " ]]; then
459438 generate_ee_access_string " $D8_LICENSE_KEY "
460- cat << EOF >>${CONFIG_DIR } /config.yml
439+ cat << EOF >>${KIND_CONFIG_DIR } /config.yml
461440---
462441apiVersion: deckhouse.io/v1
463442kind: InitConfiguration
@@ -467,8 +446,8 @@ deckhouse:
467446EOF
468447 fi
469448
470- echo " Creating Deckhouse Kubernetes Platform resource file (${CONFIG_DIR } /resources.yml)..."
471- cat << EOF >${CONFIG_DIR } /resources.yml
449+ echo " Creating Deckhouse Kubernetes Platform resource file (${KIND_CONFIG_DIR } /resources.yml)..."
450+ cat << EOF >${KIND_CONFIG_DIR } /resources.yml
472451apiVersion: deckhouse.io/v1
473452kind: IngressNginxController
474453metadata:
@@ -494,7 +473,7 @@ To delete created cluster use the following command:
494473
495474cluster_create () {
496475
497- ${KIND_PATH} create cluster --name " ${KIND_CLUSTER_NAME} " --image " ${KIND_IMAGE} " --config " ${CONFIG_DIR } /kind.cfg"
476+ ${KIND_PATH} create cluster --name " ${KIND_CLUSTER_NAME} " --image " ${KIND_IMAGE} " --config " ${KIND_CONFIG_DIR } /kind.cfg"
498477
499478 if [ " $? " -ne " 0" ]; then
500479 printf "
@@ -508,7 +487,7 @@ E.g., you can find programs that use these ports using the following command:
508487 exit 1
509488 fi
510489
511- ${KIND_PATH} get kubeconfig --internal --name " ${KIND_CLUSTER_NAME} " > ${CONFIG_DIR } /kubeconfig
490+ ${KIND_PATH} get kubeconfig --internal --name " ${KIND_CLUSTER_NAME} " > ${KIND_CONFIG_DIR } /kubeconfig
512491
513492}
514493
@@ -517,9 +496,9 @@ deckhouse_install() {
517496
518497 # Use the --debug flag to see exactly why it's failing
519498 docker run --pull=always --rm --network kind \
520- -v " ${CONFIG_DIR } /config.yml:/config.yml" \
521- -v " ${CONFIG_DIR } /resources.yml:/resources.yml" \
522- -v " ${CONFIG_DIR } /kubeconfig:/kubeconfig" \
499+ -v " ${KIND_CONFIG_DIR } /config.yml:/config.yml" \
500+ -v " ${KIND_CONFIG_DIR } /resources.yml:/resources.yml" \
501+ -v " ${KIND_CONFIG_DIR } /kubeconfig:/kubeconfig" \
523502 ${D8_REGISTRY_PATH} /install:${D8_RELEASE_CHANNEL_TAG} \
524503 bash -c " dhctl bootstrap-phase install-deckhouse --kubeconfig=/kubeconfig --kubeconfig-context=kind-${KIND_CLUSTER_NAME} --config=/config.yml"
525504
@@ -528,7 +507,7 @@ deckhouse_install() {
528507 echo " First phase might have timed out. Waiting 30s for CRDs to settle..."
529508 sleep 30
530509 # Try the resource creation phase separately
531- docker run --rm --network kind -v " ${CONFIG_DIR } /resources.yml:/resources.yml" -v " ${CONFIG_DIR } /kubeconfig:/kubeconfig" \
510+ docker run --rm --network kind -v " ${KIND_CONFIG_DIR } /resources.yml:/resources.yml" -v " ${KIND_CONFIG_DIR } /kubeconfig:/kubeconfig" \
532511 ${D8_REGISTRY_PATH} /install:${D8_RELEASE_CHANNEL_TAG} \
533512 dhctl bootstrap-phase create-resources --kubeconfig=/kubeconfig --kubeconfig-context=kind-${KIND_CLUSTER_NAME} --resources=/resources.yml
534513 fi
@@ -596,30 +575,6 @@ generate_ee_access_string() {
596575 fi
597576}
598577
599- install_show_credentials () {
600-
601- local prometheus_password
602- prometheus_password=$( ${KUBECTL_PATH} --context " kind-${KIND_CLUSTER_NAME} " -n d8-system exec deploy/deckhouse -c deckhouse -- sh -c " deckhouse-controller module values prometheus -o json | jq -r '.internal.auth.password'" )
603- if [ " $? " -ne " 0" ] || [ -z " $prometheus_password " ]; then
604- printf "
605- Error getting Prometheus password.
606-
607- Try to run the following command to get Prometheus password:
608-
609- %s --context %s -n d8-system exec deploy/deckhouse -c deckhouse -- sh -c " deckhouse-controller module values prometheus -o json | jq -r ' .internal.auth.password' "
610-
611- " " ${KUBECTL_PATH} " " kind-${KIND_CLUSTER_NAME} "
612- else
613- printf "
614- Provide following credentials to access Grafana at http://grafana.127.0.0.1.sslip.io/ :
615-
616- Username: admin
617- Password: %s
618-
619- " " ${prometheus_password} "
620- fi
621- }
622-
623578setup_operator_helm () {
624579 echo " Enabling operator-helm module..."
625580
@@ -655,6 +610,10 @@ spec:
655610EOF
656611}
657612
613+ extract_kubectl_context () {
614+ ${KUBECTL_PATH} config view --context " kind-${KIND_CLUSTER_NAME} " --minify --flatten > " ${KIND_CONFIG_DIR} /kubeconfig-external"
615+ }
616+
658617main () {
659618 parse_args " $@ "
660619
@@ -665,6 +624,7 @@ main() {
665624 deckhouse_install
666625 macos_force_qemu
667626 setup_operator_helm
627+ extract_kubectl_context
668628}
669629
670630main " $@ "
0 commit comments