diff --git a/scripts/automate_operators.sh b/scripts/automate_operators.sh index 4761d28f..6b688bcd 100755 --- a/scripts/automate_operators.sh +++ b/scripts/automate_operators.sh @@ -1,17 +1,28 @@ #!/bin/bash # set -x +check_shell(){ + [[ "${0}" =~ "bash" ]] && return + echo "Please verify you are running in bash shell" +} + +check_shell + + usage(){ echo " -This script is ALPHA and there is probably a better way to do this, but it should help you create -the basic file structure you need to setup an operator. +This script is ALPHA! -examples: +There is probably a better way to do this, but it should help create +the basic file structure needed for an operator. + +functions: get_all_pkg_manifests get_all_pkg_manifests_details save_all_pkg_manifests_details + # ex: rhods-operator get_pkg_manifest_info rhods-operator get_pkg_manifest_channels rhods-operator get_pkg_manifest_description rhods-operator @@ -39,6 +50,8 @@ check_oc(){ sleep 4 } +# main script functions + MANIFEST_INFO="NAME:.status.packageName" MANIFEST_INFO="${MANIFEST_INFO},NAMESPACE:.status.channels[0].currentCSVDesc.annotations.operatorframework\.io/suggested-namespace" MANIFEST_INFO="${MANIFEST_INFO},CATALOG_SOURCE:.status.catalogSource" @@ -240,7 +253,7 @@ metadata: namespace: ${NAMESPACE} YAML -if [ "${NS_OWN}" == "true" ] && [ "${NS_MULTI}" != "true" ] ; then +if [ "${NS_OWN}" == "true" ]; then echo -n "spec: targetNamespaces: - ${NAMESPACE} @@ -295,7 +308,7 @@ create_operator_readme(){ GIT_REPO=https://github.com/redhat-cop/gitops-catalog -cat < "${BASE_DIR}/README.md" +cat < "${BASE_DIR}/README.md" # ${DISPLAY_NAME} Install ${DISPLAY_NAME}. @@ -332,7 +345,7 @@ kind: Kustomization resources: - ${GIT_REPO}/${BASE_DIR}/operator/overlays/?ref=main \`\`\` -YAML +HTML } diff --git a/scripts/validate_manifests.sh b/scripts/validate_manifests.sh index 7ae4cedb..bde71310 100755 --- a/scripts/validate_manifests.sh +++ b/scripts/validate_manifests.sh @@ -4,8 +4,8 @@ # DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" DIR="$(pwd)" -function display_help { - echo "./$(basename "$0") [ -d | --directory DIRECTORY ] [ -q | --quiet ] [ -h | --help | --vpc-keypair | --lab | --teardown | --redeploy | --clear-logs ] [ OPTIONAL ANSIBLE OPTIONS ] +display_help(){ + echo "./$(basename "$0") [ -d | --directory DIRECTORY ] [ -e | --enforce-all-schemas ] [ -h | --help ] [ -sl | --schema-location ] Script to validate the manifests generated by Kustomize Where: -d | --directory DIRECTORY Base directory containing Kustomize overlays @@ -14,60 +14,63 @@ Where: -sl | --schema-location Location containing schemas" } -which kustomize && KUSTOMIZE_CMD="kustomize build" +which kustomize && KUSTOMIZE="kustomize build" KUSTOMIZE_CMD="${KUSTOMIZE_CMD:-oc kustomize}" IGNORE_MISSING_SCHEMAS="--ignore-missing-schemas" SCHEMA_LOCATION="${DIR}/openshift-json-schema" KUSTOMIZE_DIRS="${DIR}" -for i in "$@" -do - case $i in - -d=* | --directory=* ) - KUSTOMIZE_DIRS="${i#*=}" - shift - ;; - -e | --enforce-all-schemas ) - shift - IGNORE_MISSING_SCHEMAS="" - shift - ;; - -sl=* | --schema-location=* ) - SCHEMA_LOCATION="${i#*=}" - shift - ;; - -h | --help ) - display_help - exit 0 - ;; - esac -done +init(){ + for i in "${@}" + do + case $i in + -d | --directory ) + shift + KUSTOMIZE_DIRS="${1}" + shift + ;; + -e | --enforce-all-schemas ) + IGNORE_MISSING_SCHEMAS="" + shift + ;; + -sl | --schema-location ) + shift + SCHEMA_LOCATION="${1}" + shift + ;; + -h | --help ) + display_help + exit 0 + ;; + -*) echo >&2 "Invalid option: " "${@}" + exit 1 + ;; + esac + done +} -for i in $(find "${KUSTOMIZE_DIRS}" -name "kustomization.yaml" -exec dirname {} \;) -do - echo - echo "Validating $i" - echo +process_kustomization(){ - KUSTOMIZE_BUILD_OUTPUT=$(${KUSTOMIZE_CMD} "$i") + echo "Validating..." - build_response=$? + for BUILD in $(find "${KUSTOMIZE_DIRS}" -name "kustomization.yaml" -exec dirname {} \;) + do + echo "${BUILD}" - if [ $build_response -ne 0 ]; then - echo "Error building $i" - exit 1 - fi + # echo "$KUSTOMIZE_BUILD_OUTPUT" | kubeval ${IGNORE_MISSING_SCHEMAS} --schema-location="file://${SCHEMA_LOCATION}" --force-color + KUSTOMIZE_BUILD_OUTPUT=$(${KUSTOMIZE_CMD} "${BUILD}") -# echo "$KUSTOMIZE_BUILD_OUTPUT" | kubeval ${IGNORE_MISSING_SCHEMAS} --schema-location="file://${SCHEMA_LOCATION}" --force-color + build_response=$? -# validation_response=$? + if [ $build_response -ne 0 ]; then + echo "[ERROR]" + exit 1 + fi -# if [ $validation_response -ne 0 ]; then -# echo "Error validating $i" -# exit 1 -# fi -done + echo "[OK]" + done +} -echo -echo "Manifests successfully validated!" \ No newline at end of file +init "${@}" +process_kustomization