Skip to content

Commit

Permalink
Helm chart auto update (#8331) (#8618)
Browse files Browse the repository at this point in the history
backport of #8331

Signed-off-by: Vladyslav Diachenko <[email protected]>
  • Loading branch information
vlad-diachenko authored Feb 24, 2023
1 parent 5f428c5 commit aad37d1
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 3 deletions.
58 changes: 57 additions & 1 deletion .drone/drone.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ local archs = ['amd64', 'arm64', 'arm'];

local build_image_version = std.extVar('__build-image-version');

local drone_updater_plugin_image = 'us.gcr.io/kubernetes-dev/drone/plugins/updater@sha256:cbcb09c74f96a34c528f52bf9b4815a036b11fed65f685be216e0c8b8e84285b';

local onPRs = {
event: ['pull_request'],
};
Expand All @@ -11,6 +13,10 @@ local onTagOrMain = {
event: ['push', 'tag'],
};

local onTag = {
event: ['tag'],
};

local onPath(path) = {
paths+: [path],
};
Expand Down Expand Up @@ -44,6 +50,7 @@ local gpg_private_key = secret('gpg_private_key', 'infra/data/ci/packages-publis

// Injected in a secret because this is a public repository and having the config here would leak our environment names
local updater_config_template = secret('updater_config_template', 'secret/data/common/loki_ci_autodeploy', 'updater-config-template.json');
local helm_chart_auto_update_config_template = secret('helm-chart-update-config-template', 'secret/data/common/loki-helm-chart-auto-update', 'on-loki-release-config.json');

local run(name, commands, env={}) = {
name: name,
Expand Down Expand Up @@ -647,7 +654,7 @@ local manifest_ecr(apps, archs) = pipeline('manifest-ecr') {
},
{
name: 'trigger',
image: 'us.gcr.io/kubernetes-dev/drone/plugins/updater',
image: drone_updater_plugin_image,
settings: {
github_token: { from_secret: github_secret.name },
config_file: configFileName,
Expand All @@ -656,6 +663,54 @@ local manifest_ecr(apps, archs) = pipeline('manifest-ecr') {
},
],
},
pipeline('update-loki-helm-chart-on-loki-release') {
local configFileName = 'updater-config.json',
depends_on: ['manifest'],
image_pull_secrets: [pull_secret.name],
trigger: {
// wee need to run it only on Loki tags that starts with `v`.
ref: ['refs/tags/v*'],
},
steps: [
{
name: 'check-version-is-latest',
image: 'alpine',
when: onTag,
commands: [
'apk add --no-cache bash git',
'git fetch --tags',
"latest_version=$(git tag -l 'v[0-9]*.[0-9]*.[0-9]*' | sort -V | tail -n 1 | sed 's/v//g')",
'RELEASE_TAG=$(./tools/image-tag)',
'if [ "$RELEASE_TAG" != "$latest_version" ]; then echo "Current version $RELEASE_TAG is not the latest version of Loki. The latest version is $latest_version" && exit 78; fi',
],
},
{
name: 'prepare-helm-chart-update-config',
image: 'alpine',
depends_on: ['check-version-is-latest'],
commands: [
'RELEASE_TAG=$(./tools/image-tag)',
'echo $PLUGIN_CONFIG_TEMPLATE > %s' % configFileName,
// replace placeholders with RELEASE TAG
'sed -i -E "s/\\{\\{release\\}\\}/$RELEASE_TAG/g" %s' % configFileName,
],
settings: {
config_template: { from_secret: helm_chart_auto_update_config_template.name },
},
},
{
name: 'trigger-helm-chart-update',
image: drone_updater_plugin_image,
settings: {
github_token: {
from_secret: github_secret.name,
},
config_file: configFileName,
},
depends_on: ['prepare-helm-chart-update-config'],
},
],
},
promtail_win(),
logql_analyzer(),
pipeline('release') {
Expand Down Expand Up @@ -767,6 +822,7 @@ local manifest_ecr(apps, archs) = pipeline('manifest-ecr') {
ecr_key,
ecr_secret_key,
updater_config_template,
helm_chart_auto_update_config_template,
gpg_passphrase,
gpg_private_key,
]
54 changes: 52 additions & 2 deletions .drone/drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1211,7 +1211,7 @@ steps:
from_secret: updater_config_template
- depends_on:
- prepare-updater-config
image: us.gcr.io/kubernetes-dev/drone/plugins/updater
image: us.gcr.io/kubernetes-dev/drone/plugins/updater@sha256:cbcb09c74f96a34c528f52bf9b4815a036b11fed65f685be216e0c8b8e84285b
name: trigger
settings:
config_file: updater-config.json
Expand All @@ -1227,6 +1227,50 @@ trigger:
- refs/tags/v*
- refs/pull/*/head
---
depends_on:
- manifest
image_pull_secrets:
- dockerconfigjson
kind: pipeline
name: update-loki-helm-chart-on-loki-release
steps:
- commands:
- apk add --no-cache bash git
- git fetch --tags
- latest_version=$(git tag -l 'v[0-9]*.[0-9]*.[0-9]*' | sort -V | tail -n 1 | sed
's/v//g')
- RELEASE_TAG=$(./tools/image-tag)
- if [ "$RELEASE_TAG" != "$latest_version" ]; then echo "Current version $RELEASE_TAG
is not the latest version of Loki. The latest version is $latest_version" && exit
78; fi
image: alpine
name: check-version-is-latest
when:
event:
- tag
- commands:
- RELEASE_TAG=$(./tools/image-tag)
- echo $PLUGIN_CONFIG_TEMPLATE > updater-config.json
- sed -i -E "s/\{\{release\}\}/$RELEASE_TAG/g" updater-config.json
depends_on:
- check-version-is-latest
image: alpine
name: prepare-helm-chart-update-config
settings:
config_template:
from_secret: helm-chart-update-config-template
- depends_on:
- prepare-helm-chart-update-config
image: us.gcr.io/kubernetes-dev/drone/plugins/updater@sha256:cbcb09c74f96a34c528f52bf9b4815a036b11fed65f685be216e0c8b8e84285b
name: trigger-helm-chart-update
settings:
config_file: updater-config.json
github_token:
from_secret: github_token
trigger:
ref:
- refs/tags/v*
---
kind: pipeline
name: promtail-windows
platform:
Expand Down Expand Up @@ -1585,6 +1629,12 @@ get:
kind: secret
name: updater_config_template
---
get:
name: on-loki-release-config.json
path: secret/data/common/loki-helm-chart-auto-update
kind: secret
name: helm-chart-update-config-template
---
get:
name: passphrase
path: infra/data/ci/packages-publish/gpg
Expand All @@ -1598,6 +1648,6 @@ kind: secret
name: gpg_private_key
---
kind: signature
hmac: 005e039eade09df9d73ab4e65d06e173a12cfb3ebb591da0913543e7110459b2
hmac: 9137902edcbe4b5cd0ada685ea9783902627be3762677e0b9d3b9b6d3c592d30

...

0 comments on commit aad37d1

Please sign in to comment.