Skip to content

Commit

Permalink
Merge pull request aws-ia#2 from aws-samples/feature/helm-monitoring
Browse files Browse the repository at this point in the history
Added mechanism to regularly check for helm chart updates
  • Loading branch information
niallthomson authored May 2, 2022
2 parents 15bb3b8 + d3e01a3 commit 5c5336b
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 4 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/helm-update.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Helm Chart Update

on:
workflow_dispatch:

permissions:
pull-requests: write
contents: write

jobs:
check:
name: check
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Run check
working-directory: helm
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
python check_helm_charts.py
cat ../terraform/modules/cluster/helm_versions.tf.json
- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: Update helm charts
title: 'chore: Update helm charts'
body: |
Auto-generated pull request to update Helm charts in `helm/charts.yaml`
branch: update-helm-charts
labels: |
dependencies
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ vendor
builds

public
resources
resources

env
11 changes: 11 additions & 0 deletions helm/charts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
charts:
- name: aws-load-balancer-controller
repository: https://aws.github.io/eks-charts
chart: aws-load-balancer-controller
constraint: '>=1.4.0 <1.5.0'
- name: karpenter
repository: https://charts.karpenter.sh
chart: karpenter
- name: aws-efs-csi-driver
repository: https://kubernetes-sigs.github.io/aws-efs-csi-driver
chart: aws-efs-csi-driver
64 changes: 64 additions & 0 deletions helm/check_helm_charts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import yaml
import requests
import semantic_version
import json

def load_chart_requirements():
stream = open("charts.yaml", "r")

charts = yaml.safe_load(stream)

stream.close()

return charts

def load_terraform_variables():
f = open('../terraform/modules/cluster/helm_versions.tf.json')

data = json.load(f)

f.close()

return data

def save_terraform_variables(vars):
with open('../terraform/modules/cluster/helm_versions.tf.json', 'w') as outfile:
outfile.write('')
json.dump(vars, outfile, indent=2, sort_keys=True)

charts = load_chart_requirements()
vars = {
'//': "This file is auto-generated, do not modify manually",
'variable': {
'helm_chart_versions': {
'default': {}
}
}
}

for chart in charts['charts']:
url = '{}/index.yaml'.format(chart['repository'])
resp = requests.get(url=url)
data = yaml.safe_load(resp.content)

entry = data['entries'][chart['chart']]

selected_version = ''

for version in entry:
if 'constraint' in chart:
if semantic_version.Version(version['version']) in semantic_version.NpmSpec(chart['constraint']):
selected_version = version['version']
break
else:
selected_version = version['version']
break

if selected_version == '':
print('Valid version not found')
else:
print("Selected version {}:{}".format(chart['name'], version['version']))

vars['variable']['helm_chart_versions']['default'][chart['name']] = selected_version

save_terraform_variables(vars)
7 changes: 7 additions & 0 deletions helm/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
certifi==2021.10.8
charset-normalizer==2.0.12
idna==3.3
PyYAML==6.0
requests==2.27.1
semantic-version==2.9.0
urllib3==1.26.9
2 changes: 1 addition & 1 deletion terraform/modules/cluster/addons.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ module "eks-blueprints-kubernetes-addons" {

enable_aws_load_balancer_controller = true
aws_load_balancer_controller_helm_config = {
version = var.aws_load_balancer_controller_version
version = var.helm_chart_versions["aws-load-balancer-controller"]
}
}
9 changes: 7 additions & 2 deletions terraform/modules/cluster/helm_versions.tf.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
{
"//": "This file is auto-generated, do not modify manually",
"variable": {
"aws_load_balancer_controller_version": {
"default": "1.4.1"
"helm_chart_versions": {
"default": {
"aws-efs-csi-driver": "2.2.6",
"aws-load-balancer-controller": "1.4.1",
"karpenter": "0.9.0"
}
}
}
}

0 comments on commit 5c5336b

Please sign in to comment.