Skip to content

Commit 395e047

Browse files
authored
F #25: Add Helm chart generator + update GA (#26)
1 parent 35de25d commit 395e047

File tree

16 files changed

+176
-14
lines changed

16 files changed

+176
-14
lines changed

.env.sample

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
CLUSTER_NAME=test
21
CCM_IMG=registry.dev:5005/cloud-provider-opennebula:latest
2+
CLUSTER_NAME=test
33
ONE_XMLRPC=http://10.2.11.40:2633/RPC2
44
ONE_AUTH=oneadmin:password
5-
ROUTER_TEMPLATE_NAME=capone131-vr
6-
PUBLIC_NETWORK_NAME=service
75
PRIVATE_NETWORK_NAME=private
6+
PUBLIC_NETWORK_NAME=service
7+
ROUTER_TEMPLATE_NAME=capone131-vr

.github/workflows/release.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,35 @@ jobs:
2626
- name: Build and push images
2727
run: make docker-release "CLOSEST_TAG:=$GITHUB_REF_NAME" BUILDX_NO_DEFAULT_ATTESTATIONS=1
2828

29+
- name: Generate charts
30+
run: make charts "CLOSEST_TAG:=$GITHUB_REF_NAME"
31+
32+
- name: Checkout repository (gh-pages)
33+
uses: actions/checkout@v4
34+
with:
35+
ref: gh-pages
36+
path: ./gh-pages/
37+
38+
- name: Deploy charts
39+
run: |
40+
shopt -s failglob
41+
cp -f ./_charts/$GITHUB_REF_NAME/opennebula-*-${GITHUB_REF_NAME:1}.tgz ./gh-pages/charts/
42+
43+
- name: Re-index charts
44+
working-directory: ./gh-pages/charts/
45+
run: |
46+
../../bin/helm repo index ./ --url https://opennebula.github.io/cloud-provider-opennebula/charts/
47+
48+
- name: Push gh-pages
49+
working-directory: ./gh-pages/charts/
50+
run: |
51+
shopt -s failglob
52+
git add ./index.yaml ./opennebula-*-${GITHUB_REF_NAME:1}.tgz
53+
git config user.name "$GITHUB_ACTOR"
54+
git config user.email "[email protected]"
55+
git commit -m "${GITHUB_REF_NAME:1}"
56+
git push
57+
2958
- name: Create release
3059
env: { GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" }
3160
run: gh release create "$GITHUB_REF_NAME" --generate-notes

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# If you prefer the allow list template instead of the deny list, see community template:
22
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
33

4+
_charts/
45
bin/
56
.env
67

Makefile

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ PATH := $(SELF)/bin:$(PATH)
66
SHELL = /usr/bin/env bash -o pipefail
77
.SHELLFLAGS = -ec
88

9+
CHARTS_DIR := $(SELF)/_charts
10+
911
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
1012
ifeq (,$(shell go env GOBIN))
1113
GOBIN := $(shell go env GOPATH)/bin
@@ -14,10 +16,12 @@ GOBIN := $(shell go env GOBIN)
1416
endif
1517

1618
ENVSUBST_VERSION ?= 1.4.2
19+
HELM_VERSION ?= 3.17.3
1720
KUBECTL_VERSION ?= 1.31.4
1821
KUSTOMIZE_VERSION ?= 5.6.0
1922

2023
ENVSUBST := $(SELF)/bin/envsubst
24+
HELM := $(SELF)/bin/helm
2125
KUBECTL := $(SELF)/bin/kubectl
2226
KUSTOMIZE := $(SELF)/bin/kustomize
2327

@@ -84,28 +88,67 @@ docker-release:
8488
$(CONTAINER_TOOL) buildx build --push --platform=$(_PLATFORMS) -t $(IMG_URL):$(CLOSEST_TAG) -t $(IMG_URL):latest -f Dockerfile .
8589
-$(CONTAINER_TOOL) buildx rm cloud-provider-opennebula-builder
8690

91+
# Helm
92+
93+
.PHONY: charts
94+
95+
define chart-generator-tool
96+
charts: $(CHARTS_DIR)/$(CLOSEST_TAG)/$(1)-$(subst v,,$(CLOSEST_TAG)).tgz
97+
98+
$(CHARTS_DIR)/$(CLOSEST_TAG)/$(1)-$(subst v,,$(CLOSEST_TAG)).tgz: $(CHARTS_DIR)/$(CLOSEST_TAG)/$(1) $(HELM)
99+
$(HELM) package -d $(CHARTS_DIR)/$(CLOSEST_TAG) $(CHARTS_DIR)/$(CLOSEST_TAG)/$(1)
100+
101+
$(CHARTS_DIR)/$(CLOSEST_TAG)/$(1): CCM_IMG := {{ tpl .Values.CCM_IMG . }}
102+
$(CHARTS_DIR)/$(CLOSEST_TAG)/$(1): CCM_CTL := {{ .Values.CCM_CTL }}
103+
$(CHARTS_DIR)/$(CLOSEST_TAG)/$(1): CLUSTER_NAME := {{ .Values.CLUSTER_NAME }}
104+
$(CHARTS_DIR)/$(CLOSEST_TAG)/$(1): NODE_SELECTOR := {{ (toYaml .Values.nodeSelector) | nindent 8 }}
105+
$(CHARTS_DIR)/$(CLOSEST_TAG)/$(1): ONE_AUTH := {{ .Values.ONE_AUTH }}
106+
$(CHARTS_DIR)/$(CLOSEST_TAG)/$(1): ONE_XMLRPC := {{ .Values.ONE_XMLRPC }}
107+
$(CHARTS_DIR)/$(CLOSEST_TAG)/$(1): PRIVATE_NETWORK_NAME := {{ .Values.PRIVATE_NETWORK_NAME }}
108+
$(CHARTS_DIR)/$(CLOSEST_TAG)/$(1): PUBLIC_NETWORK_NAME := {{ .Values.PUBLIC_NETWORK_NAME }}
109+
$(CHARTS_DIR)/$(CLOSEST_TAG)/$(1): ROUTER_TEMPLATE_NAME := {{ tpl .Values.ROUTER_TEMPLATE_NAME . }}
110+
111+
$(CHARTS_DIR)/$(CLOSEST_TAG)/$(1): $(KUSTOMIZE) $(ENVSUBST)
112+
install -m u=rwx,go=rx -d $(CHARTS_DIR)/$(CLOSEST_TAG)/$(1)
113+
cp -rf helm/$(1) $(CHARTS_DIR)/$(CLOSEST_TAG)/.
114+
$(KUSTOMIZE) build kustomize/$(2) | $(ENVSUBST) \
115+
| install -m u=rw,go=r -D /dev/fd/0 $(CHARTS_DIR)/$(CLOSEST_TAG)/$(1)/templates/opennebula-cpi.yaml
116+
endef
117+
118+
$(eval $(call chart-generator-tool,opennebula-cpi,base))
119+
87120
# Deployment
88121

89122
ifndef ignore-not-found
90123
ignore-not-found := false
91124
endif
92125

93-
.PHONY: deploy undeploy
126+
.PHONY: deploy-kadm undeploy-kadm deploy-rke2 undeploy-rke2
94127

95-
deploy: $(KUSTOMIZE) $(ENVSUBST) $(KUBECTL) # Deploy controller to the K8s cluster specified in ~/.kube/config.
96-
$(KUSTOMIZE) build kustomize/base/ | $(ENVSUBST) | $(KUBECTL) apply -f-
128+
# Deploy controller to the K8s cluster specified in ~/.kube/config.
129+
deploy-kadm deploy-rke2: deploy-%: $(KUSTOMIZE) $(ENVSUBST) $(KUBECTL)
130+
$(KUSTOMIZE) build kustomize/$*/ | $(ENVSUBST) | $(KUBECTL) apply -f-
97131

98-
undeploy: $(KUSTOMIZE) $(ENVSUBST) $(KUBECTL) # Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
99-
$(KUSTOMIZE) build kustomize/base/ | $(ENVSUBST) | $(KUBECTL) --ignore-not-found=$(ignore-not-found) delete -f-
132+
# Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
133+
undeploy-kadm undeploy-rke2: undeploy-%: $(KUSTOMIZE) $(ENVSUBST) $(KUBECTL)
134+
$(KUSTOMIZE) build kustomize/$*/ | $(ENVSUBST) | $(KUBECTL) --ignore-not-found=$(ignore-not-found) delete -f-
100135

101136
# Dependencies
102137

103-
.PHONY: envsubst kubectl kustomize
138+
.PHONY: envsubst helm kubectl kustomize
104139

105140
envsubst: $(ENVSUBST)
106141
$(ENVSUBST):
107142
$(call go-install-tool,$(ENVSUBST),github.com/a8m/envsubst/cmd/envsubst,v$(ENVSUBST_VERSION))
108143

144+
helm: $(HELM)
145+
$(HELM):
146+
@[ -f $@-v$(HELM_VERSION) ] || \
147+
{ curl -fsSL https://get.helm.sh/helm-v$(HELM_VERSION)-linux-amd64.tar.gz \
148+
| tar -xzO -f- linux-amd64/helm \
149+
| install -m u=rwx,go= -o $(USER) -D /dev/fd/0 $@-v$(HELM_VERSION); }
150+
@ln -sf $@-v$(HELM_VERSION) $@
151+
109152
kubectl: $(KUBECTL)
110153
$(KUBECTL):
111154
@[ -f $@-v$(KUBECTL_VERSION) ] || \

helm/opennebula-cpi/.helmignore

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
# Common backup files
9+
*.swp
10+
*.bak
11+
*.tmp
12+
*.orig
13+
*~
14+
# Various IDEs
15+
.project
16+
.idea/
17+
*.tmproj
18+
.vscode/

helm/opennebula-cpi/Chart.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
apiVersion: v2
3+
name: opennebula-cpi
4+
description: OpenNebula Cloud-Provider Interface Chart
5+
type: application
6+
# https://github.com/helm/helm/issues/9298
7+
version: 0.1.1
8+
appVersion: "v0.1.1"

helm/opennebula-cpi/templates/NOTES.txt

Whitespace-only changes.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "opennebula-cpi.name" -}}
5+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
6+
{{- end }}
7+
8+
{{/*
9+
Create a default fully qualified app name.
10+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
11+
If release name contains chart name it will be used as a full name.
12+
*/}}
13+
{{- define "opennebula-cpi.fullname" -}}
14+
{{- if .Values.fullnameOverride }}
15+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
16+
{{- else }}
17+
{{- $name := default .Chart.Name .Values.nameOverride }}
18+
{{- if contains $name .Release.Name }}
19+
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
20+
{{- else }}
21+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
22+
{{- end }}
23+
{{- end }}
24+
{{- end }}
25+
26+
{{/*
27+
Create chart name and version as used by the chart label.
28+
*/}}
29+
{{- define "opennebula-cpi.chart" -}}
30+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
31+
{{- end }}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# To be replaced..
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{- $_ := required "CLUSTER_NAME must be provided" .Values.CLUSTER_NAME -}}

0 commit comments

Comments
 (0)