Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 15 additions & 17 deletions bin/airgap-include.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# Copyright © 2023-2024, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0

# shellcheck disable=SC2148
# This script is not intended to be run directly

# This file is not marked as executable as it is intended to be sourced
# Current directory must be the root directory of the repo


if [ "$AIRGAP_SOURCED" == "" ]; then
## Check for AIRGAP_REGISTRY, if null/empty, error out. Otherwise set and create HELM_URL_BASE.
if [ -z $AIRGAP_REGISTRY ]; then
if [ -z "$AIRGAP_REGISTRY" ]; then
log_error "AIRGAP_REGISTRY has not been set"
log_error "Please provide the URL for the private image registry and try again"
exit 1
Expand All @@ -16,31 +18,27 @@ if [ "$AIRGAP_SOURCED" == "" ]; then
AIRGAP_IMAGE_PULL_SECRET_NAME=${AIRGAP_IMAGE_PULL_SECRET_NAME:-"v4m-image-pull-secret"}

# Check for the image pull secret for the air gap environment
if [ -z "$(kubectl get secret -n $V4M_NS $AIRGAP_IMAGE_PULL_SECRET_NAME -o name --ignore-not-found)" ]; then
log_error "The image pull secret, [$AIRGAP_IMAGE_PULL_SECRET_NAME], was not detected"
log_error "Please add the image pull secret to the [$V4M_NS] namespace and run the deployment script again"
exit 1
if [ -z "$(kubectl get secret -n "$V4M_NS" "$AIRGAP_IMAGE_PULL_SECRET_NAME" -o name --ignore-not-found)" ]; then
log_error "The image pull secret, [$AIRGAP_IMAGE_PULL_SECRET_NAME], was not detected"
log_error "Please add the image pull secret to the [$V4M_NS] namespace and run the deployment script again"
exit 1
fi

AIRGAP_HELM_REPO=${AIRGAP_HELM_REPO:-"$AIRGAP_REGISTRY"}
AIRGAP_HELM_FORMAT=${AIRGAP_HELM_FORMAT:-"oci"}

if [ "$AIRGAP_HELM_FORMAT" == "tgz" ]; then
if [ ! -d "$AIRGAP_HELM_REPO" ]; then
log_error "When AIRGAP_HELM_FORMAT is 'tgz', AIRGAP_HELM_REPO is expected to be a directory."
log_error "The specified AIRGAP_HELM_REPO directory [$AIRGAP_HELM_REPO] does NOT exist."
exit 1
else
log_debug "Confirmed AIRGAP_HELM_REPO [$AIRGAP_HELM_REPO] exists"
fi
if [ ! -d "$AIRGAP_HELM_REPO" ]; then
log_error "When AIRGAP_HELM_FORMAT is 'tgz', AIRGAP_HELM_REPO is expected to be a directory."
log_error "The specified AIRGAP_HELM_REPO directory [$AIRGAP_HELM_REPO] does NOT exist."
exit 1
else
log_debug "Confirmed AIRGAP_HELM_REPO [$AIRGAP_HELM_REPO] exists"
fi
fi
fi

log_info "Deploying into an 'air-gapped' cluster from private registry [$AIRGAP_REGISTRY]"

airgapDir="$TMP_DIR/airgap"
mkdir -p $airgapDir

export AIRGAP_SOURCED=true
fi

56 changes: 27 additions & 29 deletions bin/autogenerate-include.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Copyright © 2025, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0

# shellcheck disable=SC2148
# This script is not intended to be run directly

# This file is not marked as executable as it is intended to be sourced
# Current directory must be the root directory of the repo


function checkYqVersion {
# confirm yq installed and correct version
local goodver yq_version
Expand Down Expand Up @@ -35,8 +37,8 @@ function create_ingress_certs {
if [ -f "$certFile" ] && [ -f "$keyFile" ]; then
kubectl delete secret "$secretName" --namespace "$namespace" --ignore-not-found
kubectl create secret tls "$secretName" --namespace "$namespace" --key="$keyFile" --cert="$certFile"
kubectl -n $namespace label secret $secretName managed-by="v4m-es-script"
elif [ ! -z "$certFile$keyFile" ]; then
kubectl -n "$namespace" label secret "$secretName" managed-by="v4m-es-script"
elif [ -n "$certFile$keyFile" ]; then
log_warn "Missing Ingress certificate file; specified Ingress cert [$certFile] and/or key [$keyFile] file is missing."
log_warn "Create the missing Kubernetes secrets after deployment; use command: kubectl -create secret tls $secretName --namespace $namespace --key=cert_key_file --cert=cert_file"
fi
Expand Down Expand Up @@ -70,8 +72,12 @@ if [ -z "$AUTOGENERATE_SOURCED" ]; then
exit 1
fi

#validate required inputs
BASE_DOMAIN="${BASE_DOMAIN}"
#validate required inputs:
# BASE_DOMAIN
# ROUTING
# INGRESS_CERT
# INGRESS_KEY

if [ -z "$BASE_DOMAIN" ]; then
log_error "Required parameter [BASE_DOMAIN] not provided"
exit 1
Expand All @@ -87,8 +93,6 @@ if [ -z "$AUTOGENERATE_SOURCED" ]; then
exit 1
fi

INGRESS_CERT="${INGRESS_CERT}"
INGRESS_KEY="${INGRESS_KEY}"
if [ "$INGRESS_CERT/$INGRESS_KEY" != "/" ]; then
if [ ! -f "$INGRESS_CERT" ] || [ ! -f "$INGRESS_KEY" ]; then
# Only WARN b/c missing cert doesn't prevent deployment and it can be created afterwards
Expand All @@ -112,21 +116,15 @@ if [ -z "$AUTOGENERATE_SOURCED" ]; then

if [ "$AUTOGENERATE_SMTP" == "true" ]; then

#required
# shellcheck disable=SC2269
SMTP_HOST="${SMTP_HOST}"
# shellcheck disable=SC2269
SMTP_PORT="${SMTP_PORT}"
# shellcheck disable=SC2269
SMTP_FROM_ADDRESS="${SMTP_FROM_ADDRESS}"
# shellcheck disable=SC2269
SMTP_FROM_NAME="${SMTP_FROM_NAME}"

#optional
# shellcheck disable=SC2269
SMTP_USER="${SMTP_USER}"
# shellcheck disable=SC2269
SMTP_PASSWORD="${SMTP_PASSWORD}"
#required settings
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious what this change is here? Do we not actually need these lines?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We originally had lines assigning these variables the values already assigned to them (e.g. SMTP_HOST="${SMTP_HOST}"). Why? Mostly they were artifacts of the early implementation work, as we sorted out what parameters were needed..but the lines also clarified what inputs this functionality required or used. When shellck flagged them, I thought the latter reason was still valid and added the shellcheck disable comments. But, later when looking over things one more time, I decided that keeping the line AND adding the disabling quotes was silly and the documentation objective could be achieved more cleanly with comments. Which is what we ended up with. I don't like the idea of code responding to apparently random environment variables. Documenting which environment variables are intended to influence behavior seems "better".

# SMTP_HOST - no default
# SMTP_PORT - no default
# SMTP_FROM_ADDRESS - no default
# SMTP_FROM_NAME - no default

#optional settings
# SMTP_USER - no default
# SMTP_PASSWORD - no default
SMTP_USER_SECRET="${SMTP_USER_SECRET:-grafana-smtp-user}"
SMTP_SKIP_VERIFY="${SMTP_SKIP_VERIFY:-false}"
SMTP_TLS_CERT_FILE="${SMTP_TLS_CERT_FILE:-/cert/tls.crt}"
Expand Down Expand Up @@ -159,7 +157,7 @@ if [ -z "$AUTOGENERATE_SOURCED" ]; then
log_debug "Secret [$SMTP_USER_SECRET] exists; will use it for SMTP user credentials"
elif [ -z "$SMTP_USER" ] && [ -z "$SMTP_PASSWORD" ]; then
log_debug "Neither SMTP_USER nor SMTP_PASSWORD are set; skipping creation of secret [$SMTP_USER_SECRET]"
elif [ -z "$SMTP_USER" ] || [ -z "$SMTP_PASSWORD" ]; then
elif [ -z "$SMTP_USER" ] || [ -z "$SMTP_PASSWORD" ]; then
log_error "Complete SMTP Credentials NOT provided; MUST provide BOTH [SMTP_USER] and [SMTP_PASSWORD]"
log_info "SMTP_USER is set to [$SMTP_USER] and SMTP_PASSWORD is set to [$SMTP_PASSWORD]"
exit 1
Expand All @@ -173,13 +171,12 @@ if [ -z "$AUTOGENERATE_SOURCED" ]; then

export AUTOGENERATE_SOURCED="true"

elif [ "$AUTOGENERATE_SOURCED" == "NotNeeded" ]; then
log_debug "autogenerate-include.sh not needed"
else
log_debug "autogenerate-include.sh was already sourced [$AUTOGENERATE_SOURCED]"
elif [ "$AUTOGENERATE_SOURCED" == "NotNeeded" ]; then
log_debug "autogenerate-include.sh not needed"
else
log_debug "autogenerate-include.sh was already sourced [$AUTOGENERATE_SOURCED]"
fi


function checkStorageClass {
# input parms: $1 *Name of env var* identifying storageClass
# input parms: $2 storageClass
Expand All @@ -193,7 +190,8 @@ function checkStorageClass {
log_error "Required parameter not provided. Either [$storageClassEnvVar] or [STORAGECLASS] MUST be provided."
exit 1
else
if $(kubectl get storageClass "$storageClass" -o name &>/dev/null); then
# shellcheck disable=SC2091
if $(kubectl get storageClass "$storageClass" -o name &> /dev/null); then
log_debug "The specified StorageClass [$storageClass] exists"
else
log_error "The specified StorageClass [$storageClass] does NOT exist"
Expand Down
35 changes: 19 additions & 16 deletions bin/colors-include.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Copyright © 2020, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0

# shellcheck disable=SC2148
# This script is not intended to be run directly

# Added background colors and functions

# Colors
Expand Down Expand Up @@ -34,67 +37,67 @@ lightbluebg="\033[46m"

# Foregrounds
function black {
echo -e "${black}${1}${end}" >&3
echo -e "${black}${1}${end}" >&3
}

function blackb {
echo -e "${blackb}${1}${end}" >&3
echo -e "${blackb}${1}${end}" >&3
}

function white {
echo -e "${white}${1}${end}" >&3
echo -e "${white}${1}${end}" >&3
}

function whiteb {
echo -e "${whiteb}${1}${end}" >&3
echo -e "${whiteb}${1}${end}" >&3
}

function red {
echo -e "${red}${1}${end}" >&3
echo -e "${red}${1}${end}" >&3
}

function redb {
echo -e "${redb}${1}${end}" >&3
echo -e "${redb}${1}${end}" >&3
}

function green {
echo -e "${green}${1}${end}" >&3
echo -e "${green}${1}${end}" >&3
}

function greenb {
echo -e "${greenb}${1}${end}" >&3
echo -e "${greenb}${1}${end}" >&3
}

function yellow {
echo -e "${yellow}${1}${end}" >&3
echo -e "${yellow}${1}${end}" >&3
}

function yellowb {
echo -e "${yellowb}${1}${end}" >&3
echo -e "${yellowb}${1}${end}" >&3
}

function blue {
echo -e "${blue}${1}${end}" >&3
echo -e "${blue}${1}${end}" >&3
}

function blueb {
echo -e "${blueb}${1}${end}" >&3
echo -e "${blueb}${1}${end}" >&3
}

function purple {
echo -e "${purple}${1}${end}" >&3
echo -e "${purple}${1}${end}" >&3
}

function purpleb {
echo -e "${purpleb}${1}${end}" >&3
echo -e "${purpleb}${1}${end}" >&3
}

function lightblue {
echo -e "${lightblue}${1}${end}" >&3
echo -e "${lightblue}${1}${end}" >&3
}

function lightblueb {
echo -e "${lightblueb}${1}${end}" >&3
echo -e "${lightblueb}${1}${end}" >&3
}

# Export all the things
Expand Down
Loading