Skip to content

Commit 3410da2

Browse files
authored
Feat: updated helm shared workflow for kubediagram (#208)
1 parent a87942a commit 3410da2

File tree

2 files changed

+75
-21
lines changed

2 files changed

+75
-21
lines changed

.github/workflows/helm.yml

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,17 @@ on:
7878
type: number
7979
default: 900
8080
description: 'The assumed role duration in seconds, if assuming a role. Defaults to 1 hour.'
81+
diagram-file-name:
82+
required: false
83+
type: string
84+
default: diagram.png
85+
description: 'Optional output diagram file name for kube-diagrams'
86+
generate-diagram:
87+
required: false
88+
type: boolean
89+
default: false
90+
description: 'Set to true to generate KubeDiagram from Helm templates'
91+
8192
secrets:
8293
AWS_ACCESS_KEY_ID:
8394
description: 'AWS Access Key ID'
@@ -157,6 +168,26 @@ jobs:
157168
run: |
158169
helm template ${{ inputs.helm-chart-directory }} -f ${{ inputs.values-file-path }}
159170
171+
- name: Install Graphviz & KubeDiagrams
172+
if: ${{ inputs.generate-diagram == true }}
173+
run: |
174+
sudo apt-get update
175+
sudo apt-get install -y graphviz
176+
pip install git+https://github.com/philippemerle/KubeDiagrams.git
177+
178+
- name: Generate Helm template and KubeDiagram
179+
if: ${{ inputs.generate-diagram == true }}
180+
run: |
181+
helm template ${{ inputs.helm-chart-directory }} --namespace ${{ inputs.namespace }} -f ${{ inputs.values-file-path }} \
182+
| kube-diagrams -o "${{ inputs.diagram-file-name }}" -
183+
184+
- name: Upload Diagram Artifact
185+
if: ${{ inputs.generate-diagram == true }}
186+
uses: actions/upload-artifact@v4
187+
with:
188+
name: helm-diagram
189+
path: ${{ inputs.diagram-file-name }}
190+
160191
- name: helm install and upgrade
161192
if: ${{ inputs.rollback != true && inputs.uninstall != true }}
162193
run: |
@@ -168,11 +199,26 @@ jobs:
168199
--history-max ${{ inputs.history-max }} --atomic --wait --debug --timeout ${{ inputs.timeout }}
169200
fi
170201
171-
- name: Rollback Helm Release
202+
- name: Helm Rollback
172203
if: ${{ inputs.rollback == true && inputs.uninstall != true }}
173204
run: |
174-
export HISTORY_COUNT=$(helm history ${{ inputs.release-name }} -n ${{ inputs.namespace }} | head -2 | tail -1 | awk '{print $1}')
175-
helm rollback ${{ inputs.release-name }} -n ${{ inputs.namespace }} ${{ inputs.revision }} --debug || ( echo "Valid revision values can be greater than or equal to $HISTORY_COUNT" && exit 1 )
205+
echo "⏪ Attempting rollback of release: ${{ inputs.release-name }} to revision ${{ inputs.revision }}"
206+
207+
REVISION=${{ inputs.revision }}
208+
REV_STATUS=$(helm history ${{ inputs.release-name }} -n ${{ inputs.namespace }} | awk -v rev="$REVISION" '$1 == rev {print $4}')
209+
210+
if [ -z "$REV_STATUS" ]; then
211+
echo "❌ Revision $REVISION does not exist."
212+
exit 1
213+
fi
214+
215+
if [ "$REV_STATUS" = "failed" ] || [ "$REV_STATUS" = "pending" ]; then
216+
echo "⚠️ Revision $REVISION exists but has status '$REV_STATUS'. Cannot roll back to it."
217+
exit 1
218+
fi
219+
220+
helm rollback ${{ inputs.release-name }} -n ${{ inputs.namespace }} $REVISION --debug
221+
176222
177223
- name: Uninstall Helm Release
178224
if: ${{ inputs.uninstall == true }}

docs/helm.md

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ To use the helm Workflow, add the following workflow definition to your `.github
1010

1111
```yaml
1212
name: Helm Workflow AWS
13+
1314
on:
1415
workflow_dispatch:
1516
inputs:
@@ -18,29 +19,36 @@ on:
1819
type: choice
1920
description: Select Environment name
2021
options:
21-
- # This option is blank beacause we did not given name to helm deploy or you can give this name eg. deploy
22-
- rollback # GitHub manual workflow trigger with environment selection for rollback
22+
- # Leave blank to trigger deploy
23+
- rollback # Select to trigger rollback
24+
2325
jobs:
2426
aws:
2527
uses: clouddrove/github-shared-workflows/.github/workflows/helm.yml@master
2628
secrets:
27-
BUILD_ROLE: # AWS OIDC role for aws authentication
29+
BUILD_ROLE: # AWS OIDC role for authentication
30+
AWS_ACCESS_KEY_ID: # AWS access key
31+
AWS_SECRET_ACCESS_KEY: # AWS secret key
32+
AWS_SESSION_TOKEN: # AWS session token (optional)
33+
set-parameters: # Optional Helm overrides, e.g., --set image.tag=latest
34+
2835
with:
29-
provider: # aws
30-
aws-region: # AWS region
31-
eks-cluster-name: # EKS cluster name
32-
release-name: # Helm chart realease name
33-
helm-chart-directory: # Helm chart directory from repo
34-
# Set parameter is optionals below format support set parameter
35-
set-parameters:
36-
# --set image.tag=latest
37-
# --set replicaCount=3
38-
# --set service.type=LoadBalancer
39-
timeout: # Timeout in seconds default values is 120s
40-
values-file-path: #Values file path
41-
history-max: # Revision history deafault values is 7
42-
namespace: # Namespace
43-
rollback: ${{ github.event.inputs.environment }} # Mandetory input do not change this
36+
provider: aws # Cloud provider: 'aws'
37+
eks-cluster-name: <EKS cluster name> # Name of the Amazon EKS cluster
38+
aws-region: <AWS region> # AWS region, e.g., 'us-east-1'
39+
helm-chart-directory: <chart path> # Directory where your Helm chart is located
40+
release-name: <release name> # Unique name for Helm release
41+
timeout: <timeout in seconds> # Max wait time for Helm operations, e.g., '600s'
42+
values-file-path: <values file path> # Path to Helm values.yaml file
43+
history-max: <revision count> # Number of revisions to retain in history
44+
namespace: <namespace> # Kubernetes namespace to deploy into
45+
dependencies: <true|false> # Install chart dependencies (true/false)
46+
uninstall: <true|false> # Set to true to uninstall the release
47+
rollback: <true|false> # <true|false> Trigger rollback to previous revision (true/false)
48+
revision: <revision number> # Specific revision to roll back to
49+
diagram-file-name: <output file name> # Optional: output file name for KubeDiagram PNG
50+
generate-diagram : <true|false> # <true|false> Set to true to generate a visual KubeDiagram from Helm templates
51+
4452
```
4553

4654
#### Example for Azure cloud provider

0 commit comments

Comments
 (0)