Skip to content

Commit b5b91df

Browse files
authored
Merge pull request #82 from alexander-demicev/helm
✨ Publish helm charts on each operator release
2 parents e4131a1 + 259a35b commit b5b91df

20 files changed

+1268
-8
lines changed

.github/workflows/release.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
7+
8+
permissions:
9+
contents: write # Allow to create a release.
10+
11+
jobs:
12+
release:
13+
name: Create draft release
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Set env
17+
run: echo "RELEASE_TAG=${GITHUB_REF:10}" >> $GITHUB_ENV
18+
- name: checkout code
19+
uses: actions/checkout@v3
20+
with:
21+
fetch-depth: 0
22+
- name: Set up Go
23+
uses: actions/setup-go@v3
24+
with:
25+
go-version: '1.19'
26+
- name: Generate release artifacts
27+
run: |
28+
make release
29+
- name: Create draft GH release
30+
uses: softprops/action-gh-release@1
31+
with:
32+
draft: true
33+
files: |
34+
out/operator-components.yaml
35+
out/package/*
36+
body: "TODO: Add release notes here."

Makefile

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ export GO111MODULE=on
3636
# This option is for running docker manifest command
3737
export DOCKER_CLI_EXPERIMENTAL := enabled
3838

39+
CURL_RETRIES=3
40+
3941
# Directories
4042
TOOLS_DIR := $(ROOT)/hack/tools
4143
TOOLS_BIN_DIR := $(TOOLS_DIR)/bin
@@ -82,7 +84,11 @@ ENVSUBST := $(TOOLS_BIN_DIR)/$(ENVSUBST_BIN)-$(ENVSUBST_VER)
8284

8385
GO_APIDIFF_VER := v0.5.0
8486
GO_APIDIFF_BIN := go-apidiff
85-
GO_APIDIFF := $(TOOLS_BIN_DIR)/$(GO_APIDIFF_BIN)
87+
GO_APIDIFF := $(TOOLS_BIN_DIR)/$(GO_APIDIFF_BIN)-$(GO_APIDIFF_VER)
88+
89+
HELM_VER := v3.8.1
90+
HELM_BIN := helm
91+
HELM := $(TOOLS_BIN_DIR)/$(HELM_BIN)-$(HELM_VER)
8692

8793
# It is set by Prow GIT_TAG, a git-based tag of the form vYYYYMMDD-hash, e.g., v20210120-v0.3.10-308-gc61521971
8894
TAG ?= dev
@@ -115,8 +121,11 @@ SKIP_CREATE_MGMT_CLUSTER ?= false
115121

116122
# Relase
117123
RELEASE_TAG := $(shell git describe --abbrev=0 2>/dev/null)
124+
HELM_CHART_TAG := $(shell echo $(RELEASE_TAG) | cut -c 2-)
118125
RELEASE_ALIAS_TAG ?= $(PULL_BASE_REF)
119126
RELEASE_DIR := out
127+
CHART_DIR := $(RELEASE_DIR)/charts/cluster-api-operator
128+
CHART_PACKAGE_DIR := $(RELEASE_DIR)/package
120129

121130
all: generate test operator
122131

@@ -135,6 +144,7 @@ controller-gen: $(CONTROLLER_GEN) ## Build a local copy of controller-gen.
135144
setup-envtest: $(SETUP_ENVTEST) ## Build a local copy of setup-envtest.
136145
golangci-lint: $(GOLANGCI_LINT) ## Build a local copy of golang ci-lint.
137146
gotestsum: $(GOTESTSUM) ## Build a local copy of gotestsum.
147+
helm: $(HELM) ## Build a local copy of helm.
138148

139149
$(KUSTOMIZE): ## Build kustomize from tools folder.
140150
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) sigs.k8s.io/kustomize/kustomize/v4 $(KUSTOMIZE_BIN) $(KUSTOMIZE_VER)
@@ -160,6 +170,15 @@ $(GOTESTSUM): # Build gotestsum from tools folder.
160170
$(GOLANGCI_LINT): ## Build golangci-lint from tools folder.
161171
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) github.com/golangci/golangci-lint/cmd/golangci-lint $(GOLANGCI_LINT_BIN) $(GOLANGCI_LINT_VER)
162172

173+
$(HELM): ## Put helm into tools folder.
174+
mkdir -p $(TOOLS_BIN_DIR)
175+
rm -f "$(TOOLS_BIN_DIR)/$(HELM_BIN)*"
176+
curl --retry $(CURL_RETRIES) -fsSL -o $(TOOLS_BIN_DIR)/get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
177+
chmod 700 $(TOOLS_BIN_DIR)/get_helm.sh
178+
USE_SUDO=false HELM_INSTALL_DIR=$(TOOLS_BIN_DIR) DESIRED_VERSION=$(HELM_VER) BINARY_NAME=$(HELM_BIN)-$(HELM_VER) $(TOOLS_BIN_DIR)/get_helm.sh
179+
ln -sf $(HELM) $(TOOLS_BIN_DIR)/$(HELM_BIN)
180+
rm -f $(TOOLS_BIN_DIR)/get_helm.sh
181+
163182
.PHONY: cert-mananger
164183
cert-manager: # Install cert-manager on the cluster. This is used for development purposes only.
165184
$(ROOT)/hack/cert-manager.sh
@@ -330,14 +349,22 @@ set-manifest-image:
330349
$(RELEASE_DIR):
331350
mkdir -p $(RELEASE_DIR)/
332351

352+
$(CHART_DIR):
353+
mkdir -p $(CHART_DIR)/templates
354+
355+
$(CHART_PACKAGE_DIR):
356+
mkdir -p $(CHART_PACKAGE_DIR)
357+
333358
.PHONY: release
334359
release: clean-release $(RELEASE_DIR) ## Builds and push container images using the latest git tag for the commit.
335360
@if [ -z "${RELEASE_TAG}" ]; then echo "RELEASE_TAG is not set"; exit 1; fi
336361
@if ! [ -z "$$(git status --porcelain)" ]; then echo "Your local git repository contains uncommitted changes, use git clean before proceeding."; exit 1; fi
337362
git checkout "${RELEASE_TAG}"
338363
# Set the manifest image to the production bucket.
339364
$(MAKE) manifest-modification REGISTRY=$(PROD_REGISTRY)
365+
$(MAKE) chart-manifest-modification REGISTRY=$(PROD_REGISTRY)
340366
$(MAKE) release-manifests
367+
$(MAKE) release-chart
341368

342369
.PHONY: manifest-modification
343370
manifest-modification: # Set the manifest images to the staging/production bucket.
@@ -346,10 +373,22 @@ manifest-modification: # Set the manifest images to the staging/production bucke
346373
TARGET_RESOURCE="./config/default/manager_image_patch.yaml"
347374
$(MAKE) set-manifest-pull-policy PULL_POLICY=IfNotPresent TARGET_RESOURCE="./config/default/manager_pull_policy.yaml"
348375

376+
.PHONY: chart-manifest-modification
377+
chart-manifest-modification: # Set the manifest images to the staging/production bucket.
378+
$(MAKE) set-manifest-image \
379+
MANIFEST_IMG=$(REGISTRY)/$(IMAGE_NAME) MANIFEST_TAG=$(RELEASE_TAG) \
380+
TARGET_RESOURCE="./config/chart/manager_image_patch.yaml"
381+
$(MAKE) set-manifest-pull-policy PULL_POLICY=IfNotPresent TARGET_RESOURCE="./config/chart/manager_pull_policy.yaml"
382+
349383
.PHONY: release-manifests
350384
release-manifests: $(KUSTOMIZE) $(RELEASE_DIR) ## Builds the manifests to publish with a release
351385
$(KUSTOMIZE) build ./config/default > $(RELEASE_DIR)/operator-components.yaml
352386

387+
release-chart: $(HELM) $(KUSTOMIZE) $(RELEASE_DIR) $(CHART_DIR) $(CHART_PACKAGE_DIR) ## Builds the chart to publish with a release
388+
$(KUSTOMIZE) build ./config/chart > $(CHART_DIR)/templates/operator-components.yaml
389+
cp -rf $(ROOT)/hack/chart/. $(CHART_DIR)
390+
$(HELM) package $(CHART_DIR) --app-version=$(HELM_CHART_TAG) --version=$(HELM_CHART_TAG) --destination=$(CHART_PACKAGE_DIR)
391+
353392
.PHONY: release-staging
354393
release-staging: ## Builds and push container images and manifests to the staging bucket.
355394
$(MAKE) docker-build-all
@@ -366,6 +405,10 @@ release-alias-tag: # Adds the tag to the last build tag.
366405
upload-staging-artifacts: ## Upload release artifacts to the staging bucket
367406
gsutil cp $(RELEASE_DIR)/* gs://$(STAGING_BUCKET)/components/$(RELEASE_ALIAS_TAG)/
368407

408+
.PHONY: update-helm-repo
409+
update-helm-repo:
410+
./hack/update-helm-repo.sh $(RELEASE_TAG)
411+
369412
## --------------------------------------
370413
## Cleanup / Verification
371414
## --------------------------------------

config/chart/kustomization.yaml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Adds namespace to all resources.
2+
namespace: "{{ .Release.Namespace }}"
3+
4+
# Value of this field is prepended to the
5+
# names of all resources, e.g. a deployment named
6+
# "wordpress" becomes "alices-wordpress".
7+
# Note that it should also match with the prefix (text before '-') of the namespace
8+
# field above.
9+
namePrefix: capi-operator-
10+
11+
# Labels to add to all resources and selectors.
12+
commonLabels:
13+
clusterctl.cluster.x-k8s.io/core: "capi-operator"
14+
15+
bases:
16+
- ../crd
17+
- ../rbac
18+
- ../manager
19+
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
20+
# crd/kustomization.yaml
21+
- ../webhook
22+
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'. 'WEBHOOK' components are required.
23+
- ../certmanager
24+
# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
25+
#- ../prometheus
26+
27+
patchesStrategicMerge:
28+
# Protect the /metrics endpoint by putting it behind auth.
29+
# If you want your controller-manager to expose the /metrics
30+
# endpoint w/o any authn/z, please comment the following line.
31+
- manager_auth_proxy_patch.yaml
32+
# Provide customizable hook for make targets.
33+
- manager_pull_policy.yaml
34+
- manager_image_patch.yaml
35+
36+
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
37+
# crd/kustomization.yaml
38+
- manager_webhook_patch.yaml
39+
40+
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'.
41+
# Uncomment 'CERTMANAGER' sections in crd/kustomization.yaml to enable the CA injection in the admission webhooks.
42+
# 'CERTMANAGER' needs to be enabled to use ca injection
43+
- webhookcainjection_patch.yaml
44+
45+
configurations:
46+
- kustomizeconfig.yaml
47+
vars:
48+
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER' prefix.
49+
- name: CERTIFICATE_NAMESPACE # namespace of the certificate CR
50+
objref:
51+
kind: Certificate
52+
group: cert-manager.io
53+
version: v1
54+
name: serving-cert # this name should match the one in certificate.yaml
55+
fieldref:
56+
fieldpath: metadata.namespace
57+
- name: CERTIFICATE_NAME
58+
objref:
59+
kind: Certificate
60+
group: cert-manager.io
61+
version: v1
62+
name: serving-cert # this name should match the one in certificate.yaml
63+
- name: SERVICE_NAMESPACE # namespace of the service
64+
objref:
65+
kind: Service
66+
version: v1
67+
name: webhook-service
68+
fieldref:
69+
fieldpath: metadata.namespace
70+
- name: SERVICE_NAME
71+
objref:
72+
kind: Service
73+
version: v1
74+
name: webhook-service

config/chart/kustomizeconfig.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# This configuration is for teaching kustomize how to update name ref and var substitution
2+
varReference:
3+
- kind: Deployment
4+
path: spec/template/spec/volumes/secret/secretName
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# This patch inject a sidecar container which is a HTTP proxy for the
2+
# controller manager, it performs RBAC authorization against the Kubernetes API using SubjectAccessReviews.
3+
apiVersion: apps/v1
4+
kind: Deployment
5+
metadata:
6+
name: controller-manager
7+
namespace: system
8+
spec:
9+
template:
10+
spec:
11+
containers:
12+
- name: kube-rbac-proxy
13+
image: gcr.io/kubebuilder/kube-rbac-proxy:v0.5.0
14+
args:
15+
- "--secure-listen-address=0.0.0.0:8443"
16+
- "--upstream=http://127.0.0.1:8080/"
17+
- "--logtostderr=true"
18+
- "--v=10"
19+
ports:
20+
- containerPort: 8443
21+
name: https
22+
- name: manager
23+
args:
24+
- "--metrics-bind-addr=127.0.0.1:8080"
25+
- "--leader-elect"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: controller-manager
5+
namespace: system
6+
spec:
7+
template:
8+
spec:
9+
containers:
10+
- image: gcr.io/k8s-staging-capi-operator/cluster-api-operator:dev
11+
name: manager
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: controller-manager
5+
namespace: system
6+
spec:
7+
template:
8+
spec:
9+
containers:
10+
- name: manager
11+
imagePullPolicy: IfNotPresent
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: controller-manager
5+
namespace: system
6+
spec:
7+
template:
8+
spec:
9+
containers:
10+
- name: manager
11+
ports:
12+
- containerPort: 9443
13+
name: webhook-server
14+
protocol: TCP
15+
volumeMounts:
16+
- mountPath: /tmp/k8s-webhook-server/serving-certs
17+
name: cert
18+
readOnly: true
19+
volumes:
20+
- name: cert
21+
secret:
22+
defaultMode: 420
23+
secretName: $(SERVICE_NAME)-cert
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# This patch add annotation to admission webhook config and
2+
# the variables $(CERTIFICATE_NAMESPACE) and $(CERTIFICATE_NAME) will be substituted by kustomize.
3+
apiVersion: admissionregistration.k8s.io/v1
4+
kind: ValidatingWebhookConfiguration
5+
metadata:
6+
name: validating-webhook-configuration
7+
annotations:
8+
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)

config/default/kustomization.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ bases:
2323
- ../certmanager
2424
# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
2525
#- ../prometheus
26+
- ../namespace
2627

2728
patchesStrategicMerge:
2829
# Protect the /metrics endpoint by putting it behind auth.

0 commit comments

Comments
 (0)