Skip to content

Commit 4bc658c

Browse files
authored
Now deleting other teams by default. (#37)
1 parent c039381 commit 4bc658c

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

.github/gitops-action/action.yml

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ inputs:
88
dry-run-only:
99
description: 'Whether to only run the fleetctl gitops commands in dry-run mode.'
1010
default: 'false'
11+
delete-other-teams:
12+
description: 'Whether to delete other teams in Fleet which are not part of the gitops config.'
13+
default: 'true'
1114

1215
runs:
1316
using: "composite"
@@ -27,4 +30,5 @@ runs:
2730
working-directory: ${{ inputs.working-directory }}
2831
env:
2932
FLEET_DRY_RUN_ONLY: ${{ inputs.dry-run-only }}
33+
FLEET_DELETE_OTHER_TEAMS: ${{ inputs.delete-other-teams }}
3034
run: ./gitops.sh

gitops.sh

+11-12
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
# -o pipefail: Exit if any command in a pipeline fails.
77
set -exuo pipefail
88

9-
FLEET_GITOPS_DIR="${FLEET_GITOPS_DIR:-./}"
9+
FLEET_GITOPS_DIR="${FLEET_GITOPS_DIR:-.}"
1010
FLEET_GLOBAL_FILE="${FLEET_GLOBAL_FILE:-$FLEET_GITOPS_DIR/default.yml}"
1111
FLEETCTL="${FLEETCTL:-fleetctl}"
1212
FLEET_DRY_RUN_ONLY="${FLEET_DRY_RUN_ONLY:-false}"
13+
FLEET_DELETE_OTHER_TEAMS="${FLEET_DELETE_OTHER_TEAMS:-true}"
1314

1415
# Validate that global file contains org_settings
1516
grep -Exq "^org_settings:.*" "$FLEET_GLOBAL_FILE"
@@ -20,21 +21,19 @@ if compgen -G "$FLEET_GITOPS_DIR"/teams/*.yml > /dev/null; then
2021
! perl -nle 'print $1 if /^name:\s*(.+)$/' "$FLEET_GITOPS_DIR"/teams/*.yml | sort | uniq -d | grep . -cq
2122
fi
2223

23-
# Dry run
24-
$FLEETCTL gitops -f "$FLEET_GLOBAL_FILE" --dry-run
24+
args=(-f "$FLEET_GLOBAL_FILE")
2525
for team_file in "$FLEET_GITOPS_DIR"/teams/*.yml; do
26-
if [ -f "$team_file" ]; then
27-
$FLEETCTL gitops -f "$team_file" --dry-run
28-
fi
26+
args+=(-f "$team_file")
2927
done
28+
if [ "$FLEET_DELETE_OTHER_TEAMS" = true ]; then
29+
args+=(--delete-other-teams)
30+
fi
31+
32+
# Dry run
33+
$FLEETCTL gitops "${args[@]}" --dry-run
3034
if [ "$FLEET_DRY_RUN_ONLY" = true ]; then
3135
exit 0
3236
fi
3337

3438
# Real run
35-
$FLEETCTL gitops -f "$FLEET_GLOBAL_FILE"
36-
for team_file in "$FLEET_GITOPS_DIR"/teams/*.yml; do
37-
if [ -f "$team_file" ]; then
38-
$FLEETCTL gitops -f "$team_file"
39-
fi
40-
done
39+
$FLEETCTL gitops "${args[@]}"

0 commit comments

Comments
 (0)