Skip to content

Commit

Permalink
Helm Chart release automation
Browse files Browse the repository at this point in the history
- Add workflow to update helm chart and push to ghcr.io oc registry
- add chart update script to edit chart values for a specific release
- add makefile target to install pre-req and invoke update script above

Signed-off-by: adrianc <[email protected]>
  • Loading branch information
adrianchiris committed Jun 4, 2024
1 parent 8d32f42 commit 421009f
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 0 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/chart-push-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: "Push helm chart on release"

env:
IMAGE_NAME: ghcr.io/${{ github.repository }}

on:
push:
tags:
- v*
jobs:
package-and-push-helm-chart:
runs-on: ubuntu-22.04
steps:
- name: Check out the repo
uses: actions/checkout@v4

- name: update chart
run: GITHUB_TAG=${GITHUB_REF_NAME} GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} make update-chart

- name: push chart
uses: bsord/[email protected]
with:
useOCIRegistry: true
registry-url: oci://ghcr.io/${{ github.repository }}
username: ${{ github.repository_owner }}
access-token: ${{ secrets.GITHUB_TOKEN }}
force: true
chart-folder: deployment/sriov-network-operator
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,14 @@ $(GOLANGCI_LINT): ; $(info installing golangci-lint...)
.PHONY: lint
lint: | $(GOLANGCI_LINT) ; $(info running golangci-lint...) @ ## Run golangci-lint
$(GOLANGCI_LINT) run --timeout=10m

YQ=$(BIN_DIR)/yq
YQ_VERSION=v4.44.1
$(YQ): ; $(info installing yq)
wget https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64 -O $(YQ) &&\
chmod +x $(YQ)

.PHONY: prep-chart-release
prep-chart-release: | $(YQ) ; ## prepare chart for release
@ TAG=$(TAG) GITHUB_TOKEN=$(GITHUB_TOKEN) hack/release/chart-update.sh

57 changes: 57 additions & 0 deletions hack/release/chart-update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash
set -e

BASE=${PWD}
# path to yq tool
YQ="${BASE}/bin/yq"
# path to helm values
HELM_VALUES=${BASE}/deployment/sriov-network-operator/values.yaml
HELM_CHART=${BASE}/deployment/sriov-network-operator/Chart.yaml
# github tag e.g v1.2.3
GITHUB_TAG=${GITHUB_TAG:-}
# github api token (needed only for read access)
GITHUB_TOKEN=${GITHUB_TOKEN:-}

if [ -z "$GITHUB_TAG" ]; then
echo "ERROR: GITHUB_TAG must be provided as env var"
exit 1
fi

if [ -z "$GITHUB_TOKEN" ]; then
echo "ERROR: GITHUB_TOKEN must be provided as env var"
exit 1
fi

get_latest_github_tag() {
local owner="$1"
local repo="$2"
local latest_tag

# Fetch the latest tags using GitHub API and extract the latest tag name
latest_tag=$(curl -s "https://api.github.com/repos/$owner/$repo/tags" --header "Authorization: Bearer ${GITHUB_TOKEN}" | jq -r '.[0].name')

echo "$latest_tag"
}
# check strings not empty

# tag providedf via env var
OPERATOR_TAG=${GITHUB_TAG}
IB_SRIOV_CNI_TAG=$(get_latest_github_tag k8snetworkplumbingwg ib-sriov-cni)
SRIOV_CNI_TAG=$(get_latest_github_tag k8snetworkplumbingwg sriov-cni)
OVS_CNI_TAG=$(get_latest_github_tag k8snetworkplumbingwg ovs-cni)
NETWORK_RESOURCE_INJECTOR_TAG=$(get_latest_github_tag k8snetworkplumbingwg network-resources-injector)
SRIOV_DEVICE_PLUGIN_TAG=$(get_latest_github_tag k8snetworkplumbingwg sriov-network-device-plugin)

# patch values.yaml in-place
$YQ -i ".images.operator = \"ghcr.io/k8snetworkplumbingwg/sriov-network-operator:${OPERATOR_TAG}\"" ${HELM_VALUES}
$YQ -i ".images.sriovConfigDaemon = \"ghcr.io/k8snetworkplumbingwg/sriov-network-operator-config-daemon:${OPERATOR_TAG}\"" ${HELM_VALUES}
$YQ -i ".images.sriovCni = \"ghcr.io/k8snetworkplumbingwg/sriov-cni:${SRIOV_CNI_TAG}\"" ${HELM_VALUES}
$YQ -i ".images.ibSriovCni = \"ghcr.io/k8snetworkplumbingwg/ib-sriov-cni:${IB_SRIOV_CNI_TAG}\"" ${HELM_VALUES}
$YQ -i ".images.ovsCni = \"ghcr.io/k8snetworkplumbingwg/ovs-cni:${OVS_CNI_TAG}\"" ${HELM_VALUES}
$YQ -i ".images.sriovDevicePlugin = \"ghcr.io/k8snetworkplumbingwg/sriov-network-device-plugin:${SRIOV_DEVICE_PLUGIN_TAG}\"" ${HELM_VALUES}
$YQ -i ".images.resourcesInjector = \"ghcr.io/k8snetworkplumbingwg/network-resources-injector:${NETWORK_RESOURCE_INJECTOR_TAG}\"" ${HELM_VALUES}
$YQ -i ".images.webhook = \"ghcr.io/k8snetworkplumbingwg/sriov-network-operator-webhook:${OPERATOR_TAG}\"" ${HELM_VALUES}

# patch Chart.yaml in-place
$YQ -i ".version = \"${OPERATOR_TAG#"v"}\"" ${HELM_CHART}
$YQ -i ".appVersion = \"${OPERATOR_TAG}\"" ${HELM_CHART}

0 comments on commit 421009f

Please sign in to comment.