Skip to content

Commit c82e9a6

Browse files
Merge pull request #52 from GitGuardian/ctourriere/fix_vault_k8s_and_lint_examples
Ctourriere/fix vault k8s and lint examples
2 parents a0303dd + ae4e94b commit c82e9a6

File tree

4 files changed

+101
-5
lines changed

4 files changed

+101
-5
lines changed

.github/workflows/validate-helm-examples.yml

Lines changed: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,101 @@ on:
1212
workflow_dispatch:
1313

1414
jobs:
15+
find-examples:
16+
runs-on: ubuntu-latest
17+
outputs:
18+
examples: ${{ steps.set-matrix.outputs.examples }}
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
23+
- name: Find all examples and create matrix
24+
id: set-matrix
25+
run: |
26+
# Find all example directories
27+
ALL_EXAMPLES=$(find charts/ggscout/examples -maxdepth 1 -mindepth 1 -type d -exec basename {} \;)
28+
29+
# Create JSON array for GitHub Actions matrix
30+
echo "examples=$(echo "$ALL_EXAMPLES" | jq -R -s -c 'split("\n") | map(select(length > 0))')" >> $GITHUB_OUTPUT
31+
32+
echo "Found examples: $ALL_EXAMPLES"
33+
34+
lint-examples:
35+
needs: find-examples
36+
runs-on: ubuntu-latest
37+
strategy:
38+
# Run all examples in parallel
39+
fail-fast: false
40+
matrix:
41+
example: ${{ fromJson(needs.find-examples.outputs.examples) }}
42+
43+
steps:
44+
- name: Checkout code
45+
uses: actions/checkout@v4
46+
47+
- name: Set up Helm
48+
uses: azure/setup-helm@v3
49+
with:
50+
version: 'latest'
51+
52+
- name: Install yq
53+
run: |
54+
sudo wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/bin/yq
55+
sudo chmod +x /usr/bin/yq
56+
57+
- name: Lint chart example - ${{ matrix.example }}
58+
run: |
59+
echo "🔍 Linting example: ${{ matrix.example }}"
60+
61+
# Create values-ci.yaml for linting
62+
echo "Creating values-ci.yaml for ${{ matrix.example }}"
63+
cp "charts/ggscout/examples/${{ matrix.example }}/values.yaml" "charts/ggscout/examples/${{ matrix.example }}/values-ci.yaml"
64+
65+
# Check if secret.yaml exists and apply values to values-ci.yaml
66+
if [ -f "charts/ggscout/examples/${{ matrix.example }}/secret.yaml" ]; then
67+
echo "Found secret.yaml, using it for values replacement"
68+
69+
# Create a temporary file to store environment variables
70+
ENV_FILE="charts/ggscout/examples/${{ matrix.example }}/.env.tmp"
71+
touch $ENV_FILE
72+
73+
# Extract keys and values from secret.yaml and write to env file
74+
yq '.stringData | to_entries | .[] | .key + "=" + .value' "charts/ggscout/examples/${{ matrix.example }}/secret.yaml" > $ENV_FILE
75+
76+
# Process values-ci.yaml and replace ${VAR} patterns with actual values from secret.yaml
77+
# Read env file line by line
78+
while IFS= read -r line; do
79+
# Extract key and value
80+
KEY=$(echo $line | cut -d= -f1)
81+
VALUE=$(echo $line | cut -d= -f2-)
82+
# Remove quotes if present
83+
VALUE="${VALUE%\"}"
84+
VALUE="${VALUE#\"}"
85+
VALUE="${VALUE%\'}"
86+
VALUE="${VALUE#\'}"
87+
88+
# Replace ${KEY} with VALUE in values-ci.yaml
89+
sed -i.bak "s|\${$KEY}|$VALUE|g" "charts/ggscout/examples/${{ matrix.example }}/values-ci.yaml"
90+
rm "charts/ggscout/examples/${{ matrix.example }}/values-ci.yaml.bak"
91+
done < $ENV_FILE
92+
93+
# Remove temporary env file
94+
rm $ENV_FILE
95+
fi
96+
97+
# Run helm lint
98+
if ! helm lint charts/ggscout -f "charts/ggscout/examples/${{ matrix.example }}/values-ci.yaml"; then
99+
echo "❌ Helm lint failed for ${{ matrix.example }}"
100+
exit 1
101+
else
102+
echo "✅ Helm lint passed for ${{ matrix.example }}"
103+
fi
104+
105+
# Clean up the temporary values-ci.yaml file
106+
rm "charts/ggscout/examples/${{ matrix.example }}/values-ci.yaml"
107+
15108
validate-examples:
109+
needs: lint-examples
16110
runs-on: ubuntu-latest
17111

18112
strategy:
@@ -350,4 +444,4 @@ jobs:
350444
351445
for example in $DIRS; do
352446
echo "|$example|✅ Passed with job completion|" >> $GITHUB_STEP_SUMMARY
353-
done
447+
done

charts/ggscout/examples/custom_certificates/values.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@ inventory:
2424
type: gitlabci
2525
token: gitlab-token # Replace with the GitLab CI token
2626
url: https://gitlab.com # GitLab URL
27+
gitguardian:
28+
endpoint: "https://my-gg-instance/v1"
29+
api_token: "my_api_token"

charts/ggscout/examples/gcpsecretmanager-workload/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ inventory:
1010
auth:
1111
auth_mode: k8s
1212
project_id: my-project-id # GCP Project ID where the service account is located
13-
project_number: 1234567890 # GCP Project Number
13+
project_number: "1234567890" # GCP Project Number
1414
pool_id: my-pool-id # GCP Workload Identity Pool ID
1515
provider_id: my-provider-id # Workload Identity Provider ID
1616
gcp_service_account_name: my-service-account-name # GCP Service Account Name

charts/ggscout/examples/hashicorpvault-k8s/values.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ inventory:
99
vault_address: "https://your-vault-address-here.com"
1010
auth:
1111
auth_mode: "k8s"
12-
k8s:
13-
role: "${VAULT_K8S_ROLE}"
14-
mount: "kubernetes" # This is the default; if the authentication path has changed, this must be updated
12+
role: "${VAULT_K8S_ROLE}"
13+
mount: "kubernetes" # This is the default; if the authentication path has changed, this must be updated
1514
fetch_all_versions: true # Fetch all versions of secrets or not
1615
path: "secret/dev" # Vault path or unspecified
1716
mode: "read/write" # Can be `read`, `write` or `read/write` depending on wether fetch and/or sync are enabled

0 commit comments

Comments
 (0)