| # Licensed to the Apache Software Foundation (ASF) under one |
| # or more contributor license agreements. See the NOTICE file |
| # distributed with this work for additional information |
| # regarding copyright ownership. The ASF licenses this file |
| # to you 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. |
| |
| version: '3' |
| |
| vars: |
| RETRY: 100 |
| SLEEP: 20 |
| TIMEOUT: 60 |
| |
| env: |
| KUBECONFIG: |
| sh: |- |
| if test -e $OPS_TMP/kubeconfig |
| then echo $OPS_TMP/kubeconfig |
| else echo ~/.kube/config |
| fi |
| |
| tasks: |
| |
| waitfor: |
| desc: wait for an object matching a condition |
| silent: true |
| cmds: |
| - test -n "{{.OBJ}}" || die "use OBJ=<pod/pod-name>" |
| - test -n "{{.FOR}}" || die "use FOR=<kubernetes-for-condition>" |
| - | |
| N=0 |
| RES=false |
| while [[ $N -lt {{.RETRY}} ]] |
| do |
| if kubectl -n nuvolaris wait --for="{{.FOR}}" "{{.OBJ}}" --timeout="{{.TIMEOUT}}s" |
| then RES=true; break |
| else echo "$((N++)) Waiting {{.OBJ}} for {{.FOR}}" |
| sleep "{{.SLEEP}}s" |
| fi |
| done |
| $RES |
| |
| wait: |
| desc: wait for a value matching the given jsonpath on the specific resources under the namespace nuvolaris |
| silent: true |
| cmds: |
| - test -n "{{.OBJECT}}" || die "use OBJECT=<pod/pod-name>" |
| - test -n "{{.JSONPATH}}" || die "use JSONPATH=<cm/config-jsonpath-lookup>" |
| - | |
| N=0 |
| RES=false |
| while [[ $N -lt {{.RETRY}} ]] |
| do |
| MATCHING_VALUE="$(kubectl -n nuvolaris get {{.OBJECT}} -o jsonpath='{{.JSONPATH}}')" |
| if [[ -z "$MATCHING_VALUE" ]] |
| then |
| echo "$((N++)) Waiting for {{.JSONPATH}} to be non empty value" |
| sleep 5 |
| else |
| RES=true; break |
| fi |
| done |
| $RES |
| |
| export: |
| desc: exporting NAMEd kubeconfig to specified FILE |
| requires: {vars: [FILE, NAME]} |
| cmds: |
| - test -e "$OPS_TMP/{{.NAME}}.kubeconfig" || die "no {{.NAME}} kubeconfig" |
| - | |
| FILE="$(realpath {{.FILE}})" |
| cp "$OPS_TMP/kubeconfig" "$FILE" |
| |
| import: |
| desc: importing FILE to the NAMEd kubeconfig |
| requires: {vars: [FILE, NAME]} |
| cmds: |
| - | |
| FILE="$(realpath {{.FILE}})" |
| if test -e "$FILE" |
| then cp "$FILE" "$OPS_TMP/{{.NAME}}.kubeconfig" |
| else echo "$FILE" not found |
| fi |