Skip to content

Commit

Permalink
Now with exit codes
Browse files Browse the repository at this point in the history
  • Loading branch information
gsmith-sas committed Dec 14, 2023
1 parent 80fa02b commit cf0f786
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 30 deletions.
41 changes: 23 additions & 18 deletions bin/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -254,20 +254,20 @@ export -f errexit_msg
export -f disable_sa_token_automount
export -f enable_pod_token_automount


function parseFullImage {
fullImage="$1"
unset REGISTRY REPOS IMAGE VERSION

if [[ "$1" =~ (.*)\/(.*)\/(.*)\:(.*) ]]; then
echo "DEBUG: ${BASH_REMATCH[0]}"

REGISTRY="${BASH_REMATCH[1]}"
REPOS="${BASH_REMATCH[2]}"
IMAGE="${BASH_REMATCH[3]}"
VERSION="${BASH_REMATCH[4]}"
return 0
else
echo "no match"
log_warn "Invalid value for full container image; does not fit expected pattern [$1]."
return 1
fi
}

Expand All @@ -285,35 +285,40 @@ function doitall {

#arg1 Full container image
#arg2 name of template file
#arg3 prefix to insert in placeholders
#arg3 prefix to insert in placeholders (optional)

if ! parseFullImage "$1"; then
log_error "Unable to parse full image [$1]"
return 1
fi

parseFullImage "$1"
prefix=${3:-""}

tempfile="/tmp/container_image.yaml"
imageKeysFile="$TMP_DIR/imageKeysFile.yaml"
template_file=$2

if [ "$template_file" != "TEMPFILE" ]; then
rm -f $tempfile
cp $template_file $tempfile
rm -f $imageKeysFile
cp $template_file $imageKeysFile
else
echo "DEBUG: modifying existing file"
log_debug "Modifying an existing imageKeysFile"
fi

if [ "$AIRGAP_DEPLOYMENT" == "true" ]; then
REGISTRY="$AIRGAP_REGISTRY"
fi
v4m_replace "__${prefix}IMAGE_REGISTRY__" "$REGISTRY" "$tempfile"
v4m_replace "__${prefix}GLOBAL_REGISTRY__" "$REGISTRY" "$tempfile"
v4m_replace "__${prefix}IMAGE_REPO__" "$REGISTRY\/$REPOS\/$IMAGE" "$tempfile"
v4m_replace "__${prefix}IMAGE__" "$IMAGE" "$tempfile"
v4m_replace "__${prefix}IMAGE_TAG__" "$VERSION" "$tempfile"
v4m_replace "__${prefix}IMAGE_PULL_POLICY__" "Always" "$tempfile"
v4m_replace "__${prefix}IMAGE_PULL_SECRET__" "null" "$tempfile" #Handle Single Image Pull Secret
v4m_replace "__${prefix}IMAGE_PULL_SECRETS__" "[]" "$tempfile" #Handle Multiple Image Pull Secrets

}
v4m_replace "__${prefix}IMAGE_REGISTRY__" "$REGISTRY" "$imageKeysFile"
v4m_replace "__${prefix}GLOBAL_REGISTRY__" "$REGISTRY" "$imageKeysFile"
v4m_replace "__${prefix}IMAGE_REPO__" "$REGISTRY\/$REPOS\/$IMAGE" "$imageKeysFile"
v4m_replace "__${prefix}IMAGE__" "$IMAGE" "$imageKeysFile"
v4m_replace "__${prefix}IMAGE_TAG__" "$VERSION" "$imageKeysFile"
v4m_replace "__${prefix}IMAGE_PULL_POLICY__" "Always" "$imageKeysFile"
v4m_replace "__${prefix}IMAGE_PULL_SECRET__" "null" "$imageKeysFile" #Handle Single Image Pull Secret
v4m_replace "__${prefix}IMAGE_PULL_SECRETS__" "[]" "$imageKeysFile" #Handle Multiple Image Pull Secrets

return 0
}


export -f parseFullImage
Expand Down
33 changes: 25 additions & 8 deletions bin/test-fb-image2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ function parseFullImage {
unset REGISTRY REPOS IMAGE VERSION

if [[ "$1" =~ (.*)\/(.*)\/(.*)\:(.*) ]]; then
echo "DEBUG: ${BASH_REMATCH[0]}"
###echo "DEBUG: ${BASH_REMATCH[0]}"

REGISTRY="${BASH_REMATCH[1]}"
REPOS="${BASH_REMATCH[2]}"
IMAGE="${BASH_REMATCH[3]}"
VERSION="${BASH_REMATCH[4]}"
return 0
else
echo "no match"
###echo "no match"
return 1
fi
}

Expand All @@ -35,7 +37,11 @@ function doitall {
#arg2 name of template file
#arg3 prefix to insert in placeholders

parseFullImage "$1"
if ! parseFullImage "$1"; then
echo "ERROR: unable to parse full image [$1]"
return 1
fi

prefix=${3:-""}

tempfile="/tmp/container_image.yaml"
Expand All @@ -51,6 +57,7 @@ function doitall {
if [ "$AIRGAP_DEPLOYMENT" == "true" ]; then
REGISTRY="$AIRGAP_REGISTRY"
fi

v4m_replace "__${prefix}IMAGE_REGISTRY__" "$REGISTRY" "$tempfile"
v4m_replace "__${prefix}GLOBAL_REGISTRY__" "$REGISTRY" "$tempfile"
v4m_replace "__${prefix}IMAGE_REPO__" "$REGISTRY\/$REPOS\/$IMAGE" "$tempfile"
Expand All @@ -60,6 +67,7 @@ function doitall {
v4m_replace "__${prefix}IMAGE_PULL_SECRET__" "null" "$tempfile" #Handle Single Image Pull Secret
v4m_replace "__${prefix}IMAGE_PULL_SECRETS__" "[]" "$tempfile" #Handle Multiple Image Pull Secrets

return 0
}


Expand All @@ -80,14 +88,23 @@ echo "*****************"
TEMPFILE="/tmp/container_image.yaml"

###FB_FULL_IMAGE="cr.fluentbit.io/fluent/fluent-bit:2.1.10"
doitall "$FB_FULL_IMAGE" "logging/fb/container_image.template"
cat $TEMPFILE
if doitall "$FB_FULL_IMAGE" "logging/fb/container_image.template"; then
cat $TEMPFILE
else
echo "ERROR"
fi

###OS_FULL_IMAGE="docker.io/opensearchproject/opensearch:2.10.0"
###OS_SYSCTL_FULL_IMAGE="docker.io/library/busybox:latest"
doitall "$OS_FULL_IMAGE" "logging/opensearch/os_container_image.template"
doitall "$OS_SYSCTL_FULL_IMAGE" "TEMPFILE" "OS_SYSCTL_"
cat $TEMPFILE
if doitall "$OS_FULL_IMAGE" "logging/opensearch/os_container_image.template"; then
if doitall "$OS_SYSCTL_FULL_IMAGE" "TEMPFILE" "OS_SYSCTL_"; then
cat $TEMPFILE
else echo "ERROR: Failed on [OS_SYSCT]"
fi
else
echo "ERROR: Failed on [OS]"
fi
exit

###OSD_FULL_IMAGE="docker.io/opensearchproject/opensearch-dashboards:2.10.0"
doitall "$OSD_FULL_IMAGE" "logging/opensearch/osd_container_image.template"
Expand Down
7 changes: 3 additions & 4 deletions logging/bin/deploy_esexporter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,10 @@ if [ "$AIRGAP_DEPLOYMENT" == "true" ]; then
fi

########
echo "DDDDDDD"
echo "DDDDDDD" #DEBUGGING-REMOVE
doitall "$ES_EXPORTER_FULL_IMAGE" "logging/esexporter/es-exporter_container_image.template"
imageKeysFile="/tmp/container_image.yaml"
cat "$imageKeysFile"
echo "DDDDDDD"
cat "$imageKeysFile" #DEBUGGING-REMOVE
echo "DDDDDDD" #DEBUGGING-REMOVE



Expand Down

0 comments on commit cf0f786

Please sign in to comment.