This commit is contained in:
@@ -55,6 +55,12 @@ add_teleport_labels() {
|
||||
|
||||
echo "Adding Teleport labels from TELEPORT_LABELS environment variable..."
|
||||
|
||||
# Check if ssh_service section exists
|
||||
if ! grep -q "ssh_service:" "$CONFIG_FILE"; then
|
||||
echo "Error: ssh_service section not found in teleport.yaml"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Extract existing labels from the config file
|
||||
declare -A EXISTING_LABELS
|
||||
IN_LABELS_SECTION=0
|
||||
@@ -92,6 +98,33 @@ add_teleport_labels() {
|
||||
fi
|
||||
done < "$CONFIG_FILE"
|
||||
|
||||
# Check if all labels from TELEPORT_LABELS are already present
|
||||
IFS=',' read -ra LABELS <<< "$TELEPORT_LABELS"
|
||||
ALL_LABELS_EXIST=true
|
||||
for label in "${LABELS[@]}"; do
|
||||
# Trim whitespace
|
||||
label=$(echo "$label" | xargs)
|
||||
|
||||
# Check if label contains colon
|
||||
if [[ "$label" == *":"* ]]; then
|
||||
key=$(echo "$label" | cut -d':' -f1 | xargs)
|
||||
|
||||
if [ -n "$key" ]; then
|
||||
# Check if this label key doesn't exist
|
||||
if [ -z "${EXISTING_LABELS[$key]}" ]; then
|
||||
ALL_LABELS_EXIST=false
|
||||
break
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
# If all labels already exist, skip file modification
|
||||
if [ "$ALL_LABELS_EXIST" = true ]; then
|
||||
echo "All Teleport labels from TELEPORT_LABELS are already present, skipping update"
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Build the new ssh_service section with existing and new labels
|
||||
NEW_SSH_SECTION="ssh_service:"
|
||||
NEW_SSH_SECTION="$NEW_SSH_SECTION"$'\n'" labels:"
|
||||
|
||||
Reference in New Issue
Block a user