Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating fleet-gitops to delete other teams not specified in the configs #37

Merged
merged 1 commit into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/gitops-action/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
23 changes: 11 additions & 12 deletions gitops.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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[@]}"
Loading