From 330438ef6deb89725f178abed9e10c9457c39279 Mon Sep 17 00:00:00 2001 From: Andrew Suderman Date: Thu, 17 Mar 2022 15:10:53 -0600 Subject: [PATCH] Enable orb to use environment variables from context (#293) * Try orb env variables * That didn't work * progress * Fixes * Fix examples --- orb/commands/configure_env.yml | 29 +++++++++++++++++++++++++++++ orb/commands/detect.yml | 15 --------------- orb/commands/detect_files.yml | 15 --------------- orb/examples/detect.yml | 2 +- orb/examples/detect_files.yml | 2 +- orb/jobs/detect.yml | 15 ++++++++++++--- orb/jobs/detect_files.yml | 15 ++++++++++++--- orb/scripts/detect.sh | 17 +---------------- orb/scripts/detect_files.sh | 14 +------------- 9 files changed, 57 insertions(+), 67 deletions(-) create mode 100644 orb/commands/configure_env.yml diff --git a/orb/commands/configure_env.yml b/orb/commands/configure_env.yml new file mode 100644 index 00000000..df121e5f --- /dev/null +++ b/orb/commands/configure_env.yml @@ -0,0 +1,29 @@ +description: Configures pluto environment variables. +parameters: + executor: + description: The name of custom executor to use. Only recommended for development. + type: executor + default: default + ignore-deprecations: + type: boolean + default: false + description: Exit Code 3 is ignored, useful if you do not want the job to fail if deprecated APIs are detected. + ignore-removals: + type: boolean + default: false + description: Exit Code 3 is ignored, useful if you do not want the job to fail if removed APIs are detected. + target-versions: + description: You can target the Kubernetes version you are concerned with. If blank defaults to latest. + type: string + default: "" +steps: + - run: + name: configure Pluto env vars + command: | + #!/bin/bash + + set -e + + echo PLUTO_IGNORE_DEPRECATIONS=<> >> $BASH_ENV + echo PLUTO_IGNORE_REMOVALS=<> >> $BASH_ENV + echo PLUTO_TARGET_VERSIONS=<> >> $BASH_ENV diff --git a/orb/commands/detect.yml b/orb/commands/detect.yml index 129843e0..95b9a245 100644 --- a/orb/commands/detect.yml +++ b/orb/commands/detect.yml @@ -8,24 +8,9 @@ parameters: description: The name of custom executor to use. Only recommended for development. type: executor default: default - ignore-deprecations: - type: boolean - default: false - description: Exit Code 3 is ignored, useful if you do not want the job to fail if deprecated APIs are detected. - ignore-removals: - type: boolean - default: false - description: Exit Code 3 is ignored, useful if you do not want the job to fail if removed APIs are detected. - target-versions: - description: You can target the Kubernetes version you are concerned with. If blank defaults to latest. - type: string - default: "" steps: - run: name: Pluto detect environment: PLUTO_FILE: <> - PLUTO_IGNORE_DEPRECATIONS: <> - PLUTO_IGNORE_REMOVALS: <> - PLUTO_TARGET_VERSIONS: <> command: <> diff --git a/orb/commands/detect_files.yml b/orb/commands/detect_files.yml index 5c8efd1f..55f189e3 100644 --- a/orb/commands/detect_files.yml +++ b/orb/commands/detect_files.yml @@ -8,24 +8,9 @@ parameters: description: The name of custom executor to use. Only recommended for development. type: executor default: default - ignore-deprecations: - type: boolean - default: false - description: Exit Code 3 is ignored, useful if you do not want the job to fail if deprecated APIs are detected. - ignore-removals: - type: boolean - default: false - description: Exit Code 3 is ignored, useful if you do not want the job to fail if removed APIs are detected. - target-versions: - description: You can target the Kubernetes version you are concerned with. If blank defaults to latest. - type: string - default: "" steps: - run: name: Pluto detect-files environment: PLUTO_DIRECTORY: <> - PLUTO_IGNORE_DEPRECATIONS: <> - PLUTO_IGNORE_REMOVALS: <> - PLUTO_TARGET_VERSIONS: <> command: <> diff --git a/orb/examples/detect.yml b/orb/examples/detect.yml index cd985ab6..5f0e39b7 100644 --- a/orb/examples/detect.yml +++ b/orb/examples/detect.yml @@ -11,4 +11,4 @@ usage: file: ./K8s/Descriptors/ingress.yml ignore-deprecations: true ignore-removals: false - target-versions: v1.21 + target-versions: "k8s=v1.21" diff --git a/orb/examples/detect_files.yml b/orb/examples/detect_files.yml index 170c8ea4..29974b52 100644 --- a/orb/examples/detect_files.yml +++ b/orb/examples/detect_files.yml @@ -11,4 +11,4 @@ usage: directory: ./K8s/Descriptors ignore-deprecations: true ignore-removals: false - target-versions: v1.21 + target-versions: "k8s=v1.21" diff --git a/orb/jobs/detect.yml b/orb/jobs/detect.yml index 83382677..5c112c94 100644 --- a/orb/jobs/detect.yml +++ b/orb/jobs/detect.yml @@ -13,6 +13,10 @@ parameters: description: The file to scan. Required. type: string default: "" + use-external-context: + type: boolean + default: false + description: If this is true, then the configure_env step will be skipped. ignore-deprecations: type: boolean default: false @@ -37,8 +41,13 @@ steps: - checkout - install: version: <> + - when: + condition: + not: << parameters.use-external-context >> + steps: + - configure_env: + ignore-deprecations: << parameters.ignore-deprecations >> + ignore-removals: << parameters.ignore-removals >> + target-versions: << parameters.target-versions >> - detect: file: <> - ignore-deprecations: <> - ignore-removals: <> - target-versions: <> diff --git a/orb/jobs/detect_files.yml b/orb/jobs/detect_files.yml index 04cbf761..1f851f85 100644 --- a/orb/jobs/detect_files.yml +++ b/orb/jobs/detect_files.yml @@ -13,6 +13,10 @@ parameters: description: The name of custom executor to use. Only recommended for development. type: executor default: default + use-external-context: + type: boolean + default: false + description: If this is true, then the configure_env step will be skipped. ignore-deprecations: type: boolean default: false @@ -37,8 +41,13 @@ steps: - checkout - install: version: <> + - when: + condition: + not: << parameters.use-external-context >> + steps: + - configure_env: + ignore-deprecations: << parameters.ignore-deprecations >> + ignore-removals: << parameters.ignore-removals >> + target-versions: << parameters.target-versions >> - detect_files: directory: <> - ignore-deprecations: <> - ignore-removals: <> - target-versions: <> diff --git a/orb/scripts/detect.sh b/orb/scripts/detect.sh index 9c613694..8d77bc0a 100644 --- a/orb/scripts/detect.sh +++ b/orb/scripts/detect.sh @@ -6,19 +6,4 @@ if [[ -z "${PLUTO_FILE}" ]]; then exit 1 fi -if [[ "${PLUTO_IGNORE_DEPRECATIONS}" = true ]]; then - PLUTO_ARGS="$PLUTO_ARGS --ignore-deprecations" -fi - -if [[ "${PLUTO_IGNORE_REMOVALS}" = true ]]; then - PLUTO_ARGS="$PLUTO_ARGS --ignore-removals" -fi - -if [[ -n "${PLUTO_TARGET_VERSIONS}" ]]; then - PLUTO_ARGS="$PLUTO_ARGS --target-versions k8s=${PLUTO_TARGET_VERSIONS}" -fi - -export PLUTO_ARGS -export PLUTO_FILE_PATH - -pluto detect $PLUTO_FILE $PLUTO_ARGS +pluto detect "$PLUTO_FILE" diff --git a/orb/scripts/detect_files.sh b/orb/scripts/detect_files.sh index 64763791..8a95d7ae 100755 --- a/orb/scripts/detect_files.sh +++ b/orb/scripts/detect_files.sh @@ -5,18 +5,6 @@ if [[ -n "${PLUTO_DIRECTORY}" ]]; then PLUTO_ARGS="$PLUTO_ARGS --directory ${PLUTO_DIRECTORY}" fi -if [[ "${PLUTO_IGNORE_DEPRECATIONS}" = true ]]; then - PLUTO_ARGS="$PLUTO_ARGS --ignore-deprecations" -fi - -if [[ "${PLUTO_IGNORE_REMOVALS}" = true ]]; then - PLUTO_ARGS="$PLUTO_ARGS --ignore-removals" -fi - -if [[ -n "${PLUTO_TARGET_VERSIONS}" ]]; then - PLUTO_ARGS="$PLUTO_ARGS --target-versions k8s=${PLUTO_TARGET_VERSIONS}" -fi - export PLUTO_ARGS -pluto detect-files $PLUTO_ARGS +pluto detect-files "$PLUTO_ARGS"