From eb6ccf02013ef16e9ce69c39cfe2e0663fdbe2db Mon Sep 17 00:00:00 2001 From: Vladislav Kuzmin Date: Mon, 5 Apr 2021 02:36:48 +0400 Subject: [PATCH] Move kubectl calls to KRM toolbox pt.1 Move kubectl calls to phases. These phases call KRM toolbox with prepared shell scripts. Change-Id: Iddf64c7df94c9d796b101bbb4fafb22a7b7621b7 --- .../get_pods/kubectl_get_pods.sh | 15 ++++++++ .../phase-helpers/get_pods/kustomization.yaml | 6 ++++ .../function/phase-helpers/kustomization.yaml | 4 ++- .../wait_tigera/kubectl_wait_tigera.sh | 34 +++++++++++++++++++ .../wait_tigera/kustomization.yaml | 6 ++++ manifests/phases/executors.yaml | 30 ++++++++++++++++ manifests/phases/phases.yaml | 23 ++++++++++++- tools/deployment/25_deploy_ephemeral_node.sh | 15 ++++---- .../26_deploy_capi_ephemeral_node.sh | 25 +++----------- 9 files changed, 129 insertions(+), 29 deletions(-) create mode 100644 manifests/function/phase-helpers/get_pods/kubectl_get_pods.sh create mode 100644 manifests/function/phase-helpers/get_pods/kustomization.yaml create mode 100644 manifests/function/phase-helpers/wait_tigera/kubectl_wait_tigera.sh create mode 100644 manifests/function/phase-helpers/wait_tigera/kustomization.yaml diff --git a/manifests/function/phase-helpers/get_pods/kubectl_get_pods.sh b/manifests/function/phase-helpers/get_pods/kubectl_get_pods.sh new file mode 100644 index 000000000..d5defa041 --- /dev/null +++ b/manifests/function/phase-helpers/get_pods/kubectl_get_pods.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +# 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. + +kubectl --kubeconfig $KUBECONFIG --context $KCTL_CONTEXT get pods --all-namespaces 1>&2 diff --git a/manifests/function/phase-helpers/get_pods/kustomization.yaml b/manifests/function/phase-helpers/get_pods/kustomization.yaml new file mode 100644 index 000000000..2300b7b67 --- /dev/null +++ b/manifests/function/phase-helpers/get_pods/kustomization.yaml @@ -0,0 +1,6 @@ +configMapGenerator: +- name: kubectl-get-pods + options: + disableNameSuffixHash: true + files: + - script=kubectl_get_pods.sh diff --git a/manifests/function/phase-helpers/kustomization.yaml b/manifests/function/phase-helpers/kustomization.yaml index c27d68b66..9adcb2e75 100644 --- a/manifests/function/phase-helpers/kustomization.yaml +++ b/manifests/function/phase-helpers/kustomization.yaml @@ -1,2 +1,4 @@ resources: -- wait_node \ No newline at end of file +- wait_node +- get_pods +- wait_tigera diff --git a/manifests/function/phase-helpers/wait_tigera/kubectl_wait_tigera.sh b/manifests/function/phase-helpers/wait_tigera/kubectl_wait_tigera.sh new file mode 100644 index 000000000..414cb0d89 --- /dev/null +++ b/manifests/function/phase-helpers/wait_tigera/kubectl_wait_tigera.sh @@ -0,0 +1,34 @@ +#!/bin/sh + +# 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. + +echo "Wait for Calico to be deployed using tigera" 1>&2 +kubectl --kubeconfig $KUBECONFIG --context $KCTL_CONTEXT wait --all-namespaces --for=condition=Ready pods --all --timeout=1000s 1>&2 + +echo "Wait for Established condition of tigerastatus(CRD) to be true for tigerastatus(CR) to show up" 1>&2 +kubectl --kubeconfig $KUBECONFIG --context $KCTL_CONTEXT wait --for=condition=Established crd/tigerastatuses.operator.tigera.io --timeout=300s 1>&2 + +# Wait till CR(tigerastatus) shows up to query +count=0 +max_retry_attempts=150 +until [ "$(kubectl --kubeconfig $KUBECONFIG --context $KCTL_CONTEXT get tigerastatus 2>/dev/null)" ]; do + count=$((count + 1)) + if [[ ${count} -eq "${max_retry_attempts}" ]]; then + echo 'Timed out waiting for tigerastatus' 1>&2 + exit 1 + fi + sleep 2 +done + +# Wait till condition is available for tigerastatus +kubectl --kubeconfig $KUBECONFIG --context $KCTL_CONTEXT wait --for=condition=Available tigerastatus --all --timeout=1000s 1>&2 diff --git a/manifests/function/phase-helpers/wait_tigera/kustomization.yaml b/manifests/function/phase-helpers/wait_tigera/kustomization.yaml new file mode 100644 index 000000000..364dfd4b8 --- /dev/null +++ b/manifests/function/phase-helpers/wait_tigera/kustomization.yaml @@ -0,0 +1,6 @@ +configMapGenerator: +- name: kubectl-wait-tigera + options: + disableNameSuffixHash: true + files: + - script=kubectl_wait_tigera.sh diff --git a/manifests/phases/executors.yaml b/manifests/phases/executors.yaml index 9c9927ae4..0607d3968 100644 --- a/manifests/phases/executors.yaml +++ b/manifests/phases/executors.yaml @@ -288,3 +288,33 @@ configRef: kind: ConfigMap name: kubectl-get-node apiVersion: v1 +--- +apiVersion: airshipit.org/v1alpha1 +kind: GenericContainer +metadata: + name: kubectl-get-pods + labels: + airshipit.org/deploy-k8s: "false" +spec: + type: krm + image: quay.io/airshipit/toolbox:latest + hostNetwork: true +configRef: + kind: ConfigMap + name: kubectl-get-pods + apiVersion: v1 +--- +apiVersion: airshipit.org/v1alpha1 +kind: GenericContainer +metadata: + name: kubectl-wait-tigera + labels: + airshipit.org/deploy-k8s: "false" +spec: + type: krm + image: quay.io/airshipit/toolbox:latest + hostNetwork: true +configRef: + kind: ConfigMap + name: kubectl-wait-tigera + apiVersion: v1 diff --git a/manifests/phases/phases.yaml b/manifests/phases/phases.yaml index 9e8ca7f64..41c3d446a 100644 --- a/manifests/phases/phases.yaml +++ b/manifests/phases/phases.yaml @@ -289,4 +289,25 @@ config: apiVersion: airshipit.org/v1alpha1 kind: GenericContainer name: kubectl-get-node - documentEntryPoint: ephemeral/initinfra-networking +--- +apiVersion: airshipit.org/v1alpha1 +kind: Phase +metadata: + name: kubectl-get-pods-ephemeral + clusterName: ephemeral-cluster +config: + executorRef: + apiVersion: airshipit.org/v1alpha1 + kind: GenericContainer + name: kubectl-get-pods +--- +apiVersion: airshipit.org/v1alpha1 +kind: Phase +metadata: + name: kubectl-wait-tigera-ephemeral + clusterName: ephemeral-cluster +config: + executorRef: + apiVersion: airshipit.org/v1alpha1 + kind: GenericContainer + name: kubectl-wait-tigera diff --git a/tools/deployment/25_deploy_ephemeral_node.sh b/tools/deployment/25_deploy_ephemeral_node.sh index 133eb3174..39f1bf371 100755 --- a/tools/deployment/25_deploy_ephemeral_node.sh +++ b/tools/deployment/25_deploy_ephemeral_node.sh @@ -14,16 +14,17 @@ set -xe -#Default wait timeout is 3600 seconds -export TIMEOUT=${TIMEOUT:-3600} -export KUBECONFIG=${KUBECONFIG:-"$HOME/.airship/kubeconfig"} -export KUBECONFIG_EPHEMERAL_CONTEXT=${KUBECONFIG_EPHEMERAL_CONTEXT:-"ephemeral-cluster"} - echo "Deploy ephemeral node using redfish with iso" airshipctl phase run remotedirect-ephemeral --debug echo "Wait for apiserver to become available" -airshipctl phase run kubectl-wait-node-ephemeral +# Scripts for this phase placed in manifests/function/phase-helpers/wait_node/ +# To get ConfigMap for this phase, execute `airshipctl phase render --source config -k ConfigMap` +# and find ConfigMap with name kubectl-get-node +airshipctl phase run kubectl-wait-node-ephemeral --debug echo "List all pods" -kubectl --kubeconfig $KUBECONFIG --context $KUBECONFIG_EPHEMERAL_CONTEXT get pods --all-namespaces +# Scripts for this phase placed in manifests/function/phase-helpers/get_pods/ +# To get ConfigMap for this phase, execute `airshipctl phase render --source config -k ConfigMap` +# and find ConfigMap with name kubectl-get-pods +airshipctl phase run kubectl-get-pods-ephemeral --debug diff --git a/tools/deployment/26_deploy_capi_ephemeral_node.sh b/tools/deployment/26_deploy_capi_ephemeral_node.sh index 5db08047d..514d04ce6 100755 --- a/tools/deployment/26_deploy_capi_ephemeral_node.sh +++ b/tools/deployment/26_deploy_capi_ephemeral_node.sh @@ -23,26 +23,11 @@ if [ "$PROVIDER" = "metal3" ]; then echo "Deploy calico using tigera operator" airshipctl phase run initinfra-networking-ephemeral --debug - echo "Wait for Calico to be deployed using tigera" - kubectl --kubeconfig $KUBECONFIG --context $KUBECONFIG_EPHEMERAL_CONTEXT wait --all-namespaces --for=condition=Ready pods --all --timeout=1000s - - echo "Wait for Established condition of tigerastatus(CRD) to be true for tigerastatus(CR) to show up" - kubectl --kubeconfig $KUBECONFIG --context $KUBECONFIG_EPHEMERAL_CONTEXT wait --for=condition=Established crd/tigerastatuses.operator.tigera.io --timeout=300s - - # Wait till CR(tigerastatus) shows up to query - count=0 - max_retry_attempts=150 - until [[ $(kubectl --kubeconfig $KUBECONFIG --context $KUBECONFIG_EPHEMERAL_CONTEXT get tigerastatus 2>/dev/null) ]]; do - count=$((count + 1)) - if [[ ${count} -eq "${max_retry_attempts}" ]]; then - echo ' Timed out waiting for tigerastatus' - exit 1 - fi - sleep 2 - done - - # Wait till condition is available for tigerastatus - kubectl --kubeconfig $KUBECONFIG --context $KUBECONFIG_EPHEMERAL_CONTEXT wait --for=condition=Available tigerastatus --all --timeout=1000s + # "Wait for Calico to be deployed using tigera" + # Scripts for this phase placed in manifests/function/phase-helpers/wait_tigera/ + # To get ConfigMap for this phase, execute `airshipctl phase render --source config -k ConfigMap` + # and find ConfigMap with name kubectl-wait_tigera + airshipctl phase run kubectl-wait-tigera-ephemeral --debug echo "Deploy metal3.io components to ephemeral node" airshipctl phase run initinfra-ephemeral --debug