|
| 1 | + |
| 2 | +function sonobuoy() { |
| 3 | + sonobuoy_binary |
| 4 | + |
| 5 | + sonobuoy_airgap_maybe_tag_image "k8s.gcr.io/conformance:v${KUBERNETES_VERSION}" "registry.k8s.io/conformance:v${KUBERNETES_VERSION}" |
| 6 | + sonobuoy_airgap_maybe_tag_image "registry.k8s.io/conformance:v${KUBERNETES_VERSION}" "k8s.gcr.io/conformance:v${KUBERNETES_VERSION}" |
| 7 | +} |
| 8 | + |
| 9 | +function sonobuoy_already_applied() { |
| 10 | + sonobuoy_airgap_maybe_tag_image "k8s.gcr.io/conformance:v${KUBERNETES_VERSION}" "registry.k8s.io/conformance:v${KUBERNETES_VERSION}" |
| 11 | + sonobuoy_airgap_maybe_tag_image "registry.k8s.io/conformance:v${KUBERNETES_VERSION}" "k8s.gcr.io/conformance:v${KUBERNETES_VERSION}" |
| 12 | +} |
| 13 | + |
| 14 | +function sonobuoy_join() { |
| 15 | + sonobuoy_binary |
| 16 | + |
| 17 | + sonobuoy_airgap_maybe_tag_image "k8s.gcr.io/conformance:v${KUBERNETES_VERSION}" "registry.k8s.io/conformance:v${KUBERNETES_VERSION}" |
| 18 | + sonobuoy_airgap_maybe_tag_image "registry.k8s.io/conformance:v${KUBERNETES_VERSION}" "k8s.gcr.io/conformance:v${KUBERNETES_VERSION}" |
| 19 | +} |
| 20 | + |
| 21 | +function sonobuoy_binary() { |
| 22 | + local src="${DIR}/addons/sonobuoy/${SONOBUOY_VERSION}" |
| 23 | + |
| 24 | + if ! kubernetes_is_master; then |
| 25 | + return 0 |
| 26 | + fi |
| 27 | + |
| 28 | + if [ "${AIRGAP}" != "1" ]; then |
| 29 | + mkdir -p "${src}/assets" |
| 30 | + curl -L -o "${src}/assets/sonobuoy.tar.gz" "https://github.com/vmware-tanzu/sonobuoy/releases/download/v${SONOBUOY_VERSION}/sonobuoy_${SONOBUOY_VERSION}_linux_amd64.tar.gz" |
| 31 | + fi |
| 32 | + |
| 33 | + tar xzf "${src}/assets/sonobuoy.tar.gz" -C /usr/local/bin |
| 34 | +} |
| 35 | + |
| 36 | +function sonobuoy_airgap_maybe_tag_image() { |
| 37 | + if [ "$AIRGAP" != "1" ]; then |
| 38 | + return |
| 39 | + fi |
| 40 | + if [ -n "$DOCKER_VERSION" ]; then |
| 41 | + sonobuoy_docker_maybe_tag_image "$@" |
| 42 | + else |
| 43 | + sonobuoy_ctr_maybe_tag_image "$@" |
| 44 | + fi |
| 45 | +} |
| 46 | + |
| 47 | +function sonobuoy_docker_maybe_tag_image() { |
| 48 | + local src="$1" |
| 49 | + local dst="$2" |
| 50 | + if ! docker image inspect "$src" >/dev/null 2>&1 ; then |
| 51 | + # source image does not exist, will not tag |
| 52 | + return |
| 53 | + fi |
| 54 | + if docker image inspect "$dst" >/dev/null 2>&1 ; then |
| 55 | + # destination image exists, will not tag |
| 56 | + return |
| 57 | + fi |
| 58 | + docker image tag "$src" "$dst" |
| 59 | +} |
| 60 | + |
| 61 | +function sonobuoy_ctr_maybe_tag_image() { |
| 62 | + local src="$1" |
| 63 | + local dst="$2" |
| 64 | + if [ "$(ctr -n=k8s.io images list -q name=="$src" 2>/dev/null | wc -l)" = "0" ] ; then |
| 65 | + # source image does not exist, will not tag |
| 66 | + return |
| 67 | + fi |
| 68 | + if [ "$(ctr -n=k8s.io images list -q name=="$dst" 2>/dev/null | wc -l)" = "1" ] ; then |
| 69 | + # destination image exists, will not tag |
| 70 | + return |
| 71 | + fi |
| 72 | + ctr -n=k8s.io images tag "$src" "$dst" |
| 73 | +} |
0 commit comments