diff --git a/.github/gitops-action/action.yml b/.github/gitops-action/action.yml index 6914748..17f26da 100644 --- a/.github/gitops-action/action.yml +++ b/.github/gitops-action/action.yml @@ -8,6 +8,9 @@ inputs: dry-run-only: description: 'Whether to only run the fleetctl gitops commands in dry-run mode.' default: 'false' + delete-other-teams: + description: 'Whether to delete other teams in Fleet which are not part of the gitops config.' + default: 'true' runs: using: "composite" @@ -27,4 +30,5 @@ runs: working-directory: ${{ inputs.working-directory }} env: FLEET_DRY_RUN_ONLY: ${{ inputs.dry-run-only }} + FLEET_DELETE_OTHER_TEAMS: ${{ inputs.delete-other-teams }} run: ./gitops.sh diff --git a/gitops.sh b/gitops.sh index d3bb58e..da13393 100755 --- a/gitops.sh +++ b/gitops.sh @@ -6,10 +6,11 @@ # -o pipefail: Exit if any command in a pipeline fails. set -exuo pipefail -FLEET_GITOPS_DIR="${FLEET_GITOPS_DIR:-./}" +FLEET_GITOPS_DIR="${FLEET_GITOPS_DIR:-.}" FLEET_GLOBAL_FILE="${FLEET_GLOBAL_FILE:-$FLEET_GITOPS_DIR/default.yml}" FLEETCTL="${FLEETCTL:-fleetctl}" FLEET_DRY_RUN_ONLY="${FLEET_DRY_RUN_ONLY:-false}" +FLEET_DELETE_OTHER_TEAMS="${FLEET_DELETE_OTHER_TEAMS:-true}" # Validate that global file contains org_settings grep -Exq "^org_settings:.*" "$FLEET_GLOBAL_FILE" @@ -20,21 +21,19 @@ if compgen -G "$FLEET_GITOPS_DIR"/teams/*.yml > /dev/null; then ! perl -nle 'print $1 if /^name:\s*(.+)$/' "$FLEET_GITOPS_DIR"/teams/*.yml | sort | uniq -d | grep . -cq fi -# Dry run -$FLEETCTL gitops -f "$FLEET_GLOBAL_FILE" --dry-run +args=(-f "$FLEET_GLOBAL_FILE") for team_file in "$FLEET_GITOPS_DIR"/teams/*.yml; do - if [ -f "$team_file" ]; then - $FLEETCTL gitops -f "$team_file" --dry-run - fi + args+=(-f "$team_file") done +if [ "$FLEET_DELETE_OTHER_TEAMS" = true ]; then + args+=(--delete-other-teams) +fi + +# Dry run +$FLEETCTL gitops "${args[@]}" --dry-run if [ "$FLEET_DRY_RUN_ONLY" = true ]; then exit 0 fi # Real run -$FLEETCTL gitops -f "$FLEET_GLOBAL_FILE" -for team_file in "$FLEET_GITOPS_DIR"/teams/*.yml; do - if [ -f "$team_file" ]; then - $FLEETCTL gitops -f "$team_file" - fi -done +$FLEETCTL gitops "${args[@]}"