Skip to content

Commit

Permalink
script-updates
Browse files Browse the repository at this point in the history
  • Loading branch information
codekow committed Oct 13, 2023
1 parent dc6a546 commit 50fd14c
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 51 deletions.
25 changes: 19 additions & 6 deletions scripts/automate_operators.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -295,7 +308,7 @@ create_operator_readme(){

GIT_REPO=https://github.com/redhat-cop/gitops-catalog

cat <<YAML > "${BASE_DIR}/README.md"
cat <<HTML > "${BASE_DIR}/README.md"
# ${DISPLAY_NAME}
Install ${DISPLAY_NAME}.
Expand Down Expand Up @@ -332,7 +345,7 @@ kind: Kustomization
resources:
- ${GIT_REPO}/${BASE_DIR}/operator/overlays/<channel>?ref=main
\`\`\`
YAML
HTML

}

Expand Down
93 changes: 48 additions & 45 deletions scripts/validate_manifests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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!"
init "${@}"
process_kustomization

0 comments on commit 50fd14c

Please sign in to comment.