Skip to content

Commit

Permalink
Enable orb to use environment variables from context (#293)
Browse files Browse the repository at this point in the history
* Try orb env variables

* That didn't work

* progress

* Fixes

* Fix examples
  • Loading branch information
Andrew Suderman authored Mar 17, 2022
1 parent d22b387 commit 330438e
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 67 deletions.
29 changes: 29 additions & 0 deletions orb/commands/configure_env.yml
Original file line number Diff line number Diff line change
@@ -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=<<parameters.ignore-deprecations>> >> $BASH_ENV
echo PLUTO_IGNORE_REMOVALS=<<parameters.ignore-removals>> >> $BASH_ENV
echo PLUTO_TARGET_VERSIONS=<<parameters.target-versions>> >> $BASH_ENV
15 changes: 0 additions & 15 deletions orb/commands/detect.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: <<parameters.file>>
PLUTO_IGNORE_DEPRECATIONS: <<parameters.ignore-deprecations>>
PLUTO_IGNORE_REMOVALS: <<parameters.ignore-removals>>
PLUTO_TARGET_VERSIONS: <<parameters.target-versions>>
command: <<include(scripts/detect.sh)>>
15 changes: 0 additions & 15 deletions orb/commands/detect_files.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: <<parameters.directory>>
PLUTO_IGNORE_DEPRECATIONS: <<parameters.ignore-deprecations>>
PLUTO_IGNORE_REMOVALS: <<parameters.ignore-removals>>
PLUTO_TARGET_VERSIONS: <<parameters.target-versions>>
command: <<include(scripts/detect_files.sh)>>
2 changes: 1 addition & 1 deletion orb/examples/detect.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion orb/examples/detect_files.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ usage:
directory: ./K8s/Descriptors
ignore-deprecations: true
ignore-removals: false
target-versions: v1.21
target-versions: "k8s=v1.21"
15 changes: 12 additions & 3 deletions orb/jobs/detect.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -37,8 +41,13 @@ steps:
- checkout
- install:
version: <<parameters.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: <<parameters.file>>
ignore-deprecations: <<parameters.ignore-deprecations>>
ignore-removals: <<parameters.ignore-removals>>
target-versions: <<parameters.target-versions>>
15 changes: 12 additions & 3 deletions orb/jobs/detect_files.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -37,8 +41,13 @@ steps:
- checkout
- install:
version: <<parameters.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: <<parameters.directory>>
ignore-deprecations: <<parameters.ignore-deprecations>>
ignore-removals: <<parameters.ignore-removals>>
target-versions: <<parameters.target-versions>>
17 changes: 1 addition & 16 deletions orb/scripts/detect.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
14 changes: 1 addition & 13 deletions orb/scripts/detect_files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 330438e

Please sign in to comment.