Skip to content

Commit 5eb2322

Browse files
authored
Merge pull request #81 from nojnhuh/helm-push
Add Helm chart OCI push to cloudbuild
2 parents e3995a4 + f6453b0 commit 5eb2322

File tree

8 files changed

+53
-14
lines changed

8 files changed

+53
-14
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ vendor/
55
./dra-example-kubeletplugin
66

77
driver_image.tar
8+
*.tgz

Makefile

+12-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ $(DOCKER_TARGETS): docker-%: .build-image
154154
make $(*)
155155

156156
# Start an interactive shell using the development image.
157-
PHONY: .shell
157+
.PHONY: .shell
158158
.shell:
159159
$(CONTAINER_TOOL) run \
160160
--rm \
@@ -165,3 +165,14 @@ PHONY: .shell
165165
$(CONTAINER_TOOL_OPTS) \
166166
-w $(PWD) \
167167
$(BUILDIMAGE)
168+
169+
.PHONY: push-release-artifacts
170+
push-release-artifacts:
171+
if echo -n "${GIT_TAG}" | grep -q "^chart/"; then \
172+
export CHART_VERSION="$${GIT_TAG##chart/}"; \
173+
demo/scripts/push-driver-chart.sh; \
174+
else \
175+
export DRIVER_IMAGE_TAG="${GIT_TAG}"; \
176+
demo/scripts/build-driver-image.sh; \
177+
demo/scripts/push-driver-image.sh; \
178+
fi

cloudbuild.yaml

+4-6
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ options:
44
machineType: E2_HIGHCPU_32
55
steps:
66
- name: gcr.io/k8s-staging-test-infra/gcb-docker-gcloud:v20250116-2a05ea7e3d
7-
entrypoint: bash
7+
entrypoint: make
88
env:
99
- DRIVER_IMAGE_REGISTRY=us-central1-docker.pkg.dev/k8s-staging-images/dra-example-driver
10-
- DRIVER_IMAGE_TAG=$_GIT_TAG # _GIT_TAG is injected by Prow
10+
- DRIVER_CHART_REGISTRY=us-central1-docker.pkg.dev/k8s-staging-images/charts
11+
- GIT_TAG=$_GIT_TAG # _GIT_TAG is injected by the image builder running in Prow
1112
args:
12-
- -ec
13-
- |
14-
demo/scripts/build-driver-image.sh
15-
demo/scripts/push-driver-image.sh
13+
- push-release-artifacts

demo/scripts/common.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ SCRIPTS_DIR="$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)"
2626
: ${DRIVER_NAME:=dra-example-driver}
2727

2828
# The registry, image and tag for the example driver
29-
: ${DRIVER_IMAGE_REGISTRY:="registry.example.com"}
29+
: ${DRIVER_IMAGE_REGISTRY:="registry.k8s.io"}
3030
: ${DRIVER_IMAGE_NAME:="${DRIVER_NAME}"}
31-
: ${DRIVER_IMAGE_TAG:="v0.1.0"}
31+
: ${DRIVER_IMAGE_TAG:="$(helm show chart $(git rev-parse --show-toplevel)/deployments/helm/${DRIVER_NAME} | sed -n 's/^appVersion: //p')"}
3232
: ${DRIVER_IMAGE_PLATFORM:="ubuntu22.04"}
3333

3434
# The kubernetes repo to build the kind cluster from

demo/scripts/push-driver-chart.sh

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2025 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# A reference to the current directory where this script is located
18+
CURRENT_DIR="$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)"
19+
20+
set -ex
21+
set -o pipefail
22+
23+
source "${CURRENT_DIR}/common.sh"
24+
25+
# Set build variables
26+
export REGISTRY="${DRIVER_CHART_REGISTRY}"
27+
export CHART_NAME="${DRIVER_NAME}"
28+
29+
helm package --version "${CHART_VERSION}" deployments/helm/dra-example-driver
30+
helm push "${CHART_NAME}-${CHART_VERSION}.tgz" "oci://${REGISTRY}"

deployments/helm/dra-example-driver/Chart.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ type: application
1515
# This is the chart version. This version number should be incremented each time you make changes
1616
# to the chart and its templates, including the app version.
1717
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18-
version: 0.1.0
18+
version: 0.0.0-dev
1919

2020
# This is the version number of the application being deployed. This version number should be
2121
# incremented each time you make changes to the application. Versions are not expected to
2222
# follow Semantic Versioning. They should reflect the version the application is using.
2323
# It is recommended to use it with quotes.
24-
appVersion: "0.1.0"
24+
appVersion: "v0.1.0"

deployments/helm/dra-example-driver/templates/_helpers.tpl

+1-2
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ Selector labels
8080
Full image name with tag
8181
*/}}
8282
{{- define "dra-example-driver.fullimage" -}}
83-
{{- $tag := printf "v%s" .Chart.AppVersion }}
84-
{{- .Values.image.repository -}}:{{- .Values.image.tag | default $tag -}}
83+
{{- .Values.image.repository -}}:{{- .Values.image.tag | default .Chart.AppVersion -}}
8584
{{- end }}
8685

8786
{{/*

deployments/helm/dra-example-driver/values.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ allowDefaultNamespace: false
1111

1212
imagePullSecrets: []
1313
image:
14-
repository: registry.example.com/dra-example-driver
14+
repository: registry.k8s.io/dra-example-driver
1515
pullPolicy: IfNotPresent
1616
# Overrides the image tag whose default is the chart appVersion.
1717
tag: ""

0 commit comments

Comments
 (0)