Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Charts: add registry templating to support Elemental airgap scenarios #497

Merged
merged 8 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions .github/workflows/chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Build chart for release
if: startsWith(github.ref, 'refs/tags/')
run: |
REPO=quay.io/costoolkit/elemental-operator REPO_SEEDIMAGE=quay.io/costoolkit/elemental-seedimage TAG=${GITHUB_REF##*/} make chart
REGISTRY_URL=quay.io/costoolkit REPO=elemental-operator REPO_SEEDIMAGE=elemental-seedimage TAG=${GITHUB_REF##*/} make chart
- name: Publish chart to release
uses: fnkr/github-action-ghr@v1
if: startsWith(github.ref, 'refs/tags/')
Expand All @@ -45,21 +45,30 @@ jobs:
- name: Test chart values
if: ${{ !startsWith(github.ref, 'refs/tags/') }}
run: |
REGISTRY_URL=$(helm show values ${{ steps.chart.outputs.chart_name }}|yq .registry_url)
REPO=$(helm show values ${{ steps.chart.outputs.chart_name }}|yq .image.repository)
TAG=$(helm show values ${{ steps.chart.outputs.chart_name }}|yq .image.tag)
if [ "$REPO" != "quay.io/costoolkit/elemental-operator-ci" ];then
if [ "$REGISTRY_URL" != "quay.io/coostoolkit" ]; then
echo "registry_url on the built chart is not the expected value"
echo "Expected quay.io/coostoolkit but got $REGISTRY_URL"
fi
if [ "$REPO" != "elemental-operator-ci" ];then
echo "REPO on the built chart is not the expected value"
echo "Expected quay.io/costoolkit/elemental-operator but got $REPO"
echo "Expected elemental-operator-ci but got $REPO"
exit 1
fi
- name: Test release chart values
if: startsWith(github.ref, 'refs/tags/')
run: |
REGISTRY_URL=$(helm show values ${{ steps.chart.outputs.chart_name }}|yq .registry_url))
REPO=$(helm show values ${{ steps.chart.outputs.chart_name }}|yq .image.repository)
TAG=$(helm show values ${{ steps.chart.outputs.chart_name }}|yq .image.tag)
if [ "$REPO" != "quay.io/costoolkit/elemental-operator" ];then
if [ "$REGISTRY_URL" != "quay.io/coostoolkit" ]; then
echo "registry_url on the built chart is not the expected value"
echo "Expected quay.io/coostoolkit but got $REGISTRY_URL"
fi
if [ "$REPO" != "elemental-operator" ];then
echo "REPO on the built chart is not the expected value"
echo "Expected quay.io/costoolkit/elemental-operator but got $REPO"
echo "Expected elemental-operator but got $REPO"
exit 1
fi
if [ "$TAG" != "${GITHUB_REF##*/}" ];then
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ concurrency:
jobs:
push-docker:
env:
REPO: ttl.sh/elemental-operator-ci
REGISTRY_URL: ttl.sh
REPO: elemental-operator-ci
runs-on: ubuntu-latest
outputs:
chart_name: ${{ steps.chart.outputs.chart_name }}
Expand All @@ -31,7 +32,7 @@ jobs:
uses: docker/[email protected]
with:
images: |
${{ env.REPO }}
${{ env.REGISTRY_URL}}/${{ env.REPO }}
tags: |
type=sha,format=short,prefix=${{ steps.export_tag.outputs.operator_tag }}-
- name: Set up Docker Buildx
Expand All @@ -52,7 +53,7 @@ jobs:
COMMITDATE=${{ steps.export_tag.outputs.commit_date }}
COMMIT=${{ github.sha }}
- name: Make chart
run: REPO=${{ env.REPO }} make chart
run: REPO=${{ env.REPO }} REGISTRY_URL=${{ env.REGISTRY_URL }} make chart
- name: Set chart output
id: chart
run: |
Expand Down
4 changes: 0 additions & 4 deletions .obs/chartfile/crds/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ version: "%VERSION%"
appVersion: "%VERSION%"
annotations:
catalog.cattle.io/certified: rancher
catalog.cattle.io/display-name: Elemental CRDs
catalog.cattle.io/experimental: "true"
catalog.cattle.io/namespace: cattle-elemental-system
catalog.cattle.io/os: linux
catalog.cattle.io/provides-gvr: elemental.cattle.io/v1beta1
catalog.cattle.io/release-name: elemental-operator-crds
catalog.cattle.io/hidden: true # Hide specific charts. Only use on CRD charts.
7 changes: 6 additions & 1 deletion .obs/chartfile/operator/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@ icon: https://raw.githubusercontent.com/rancher/elemental/main/logo/icon-element
version: "%VERSION%"
appVersion: "%VERSION%"
annotations:
catalog.cattle.io/auto-install: elemental-crd=match
catalog.cattle.io/certified: rancher
catalog.cattle.io/display-name: Elemental
catalog.cattle.io/experimental: "true"
catalog.cattle.io/kube-version: '>= 1.23.0-0 < 1.28.0-0'
catalog.cattle.io/namespace: cattle-elemental-system
catalog.cattle.io/os: linux
catalog.cattle.io/permits-os: linux
catalog.cattle.io/provides-gvr: elemental.cattle.io/v1beta1
catalog.cattle.io/rancher-version: '>= 2.7.0-0 < 2.8.0-0'
catalog.cattle.io/release-name: elemental-operator
catalog.cattle.io/scope: management
catalog.cattle.io/type: cluster-tool
9 changes: 6 additions & 3 deletions .obs/chartfile/operator/values.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
image:
empty: rancher/pause:3.1
repository: "%%IMG_REPO%%/rancher/elemental-operator"
repository: "rancher/elemental-operator"
tag: "%VERSION%"
imagePullPolicy: IfNotPresent

seedImage:
repository: "%%IMG_REPO%%/rancher/seedimage-builder"
repository: "rancher/seedimage-builder"
tag: "%VERSION%"
imagePullPolicy: IfNotPresent

channel:
repository: "%%IMG_REPO%%/rancher/elemental-teal-channel"
repository: "rancher/elemental-teal-channel"
tag: "%VERSION%"

# number of operator replicas to deploy
Expand All @@ -26,6 +26,9 @@ global:
cattle:
systemDefaultRegistry: ""

# used only if systemDefaultRegistry is empty
registry_url: "%%IMG_REPO%%"

# enable debug output for operator
debug: false

Expand Down
38 changes: 23 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@ GIT_COMMIT?=$(shell git rev-parse HEAD)
GIT_COMMIT_SHORT?=$(shell git rev-parse --short HEAD)
GIT_TAG?=$(shell git describe --abbrev=0 --tags 2>/dev/null || echo "v0.0.0" )
TAG?=${GIT_TAG}-${GIT_COMMIT_SHORT}
REPO?=quay.io/costoolkit/elemental-operator-ci
REPO_REGISTER?=quay.io/costoolkit/elemental-register-ci
TAG_SEEDIMAGE?=${TAG}
REPO_SEEDIMAGE?=quay.io/costoolkit/seedimage-builder-ci
REPO?=elemental-operator-ci
REPO_REGISTER?=elemental-register-ci
REPO_SEEDIMAGE?=seedimage-builder-ci
REGISTRY_URL?=quay.io/coostoolkit
#REGISTRY_URL?=registry.opensuse.org/isv/rancher/elemental/dev/containers
ifneq ($(REGISTRY_URL),)
REGISTRY_HEADER := $(REGISTRY_URL)/
else
REGISTRY_HEADER := ""
endif

export ROOT_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
CHART_VERSION?=$(subst v,,$(GIT_TAG))
CHART?=$(shell find $(ROOT_DIR) -type f -name "elemental-operator-$(CHART_VERSION).tgz" -print)
Expand Down Expand Up @@ -91,7 +98,7 @@ build-docker-operator:
--build-arg "TAG=${GIT_TAG}" \
--build-arg "COMMIT=${GIT_COMMIT}" \
--build-arg "COMMITDATE=${COMMITDATE}" \
-t ${REPO}:${TAG} .
-t ${REGISTRY_HEADER}${REPO}:${TAG} .

.PHONY: build-docker-register
build-docker-register:
Expand All @@ -101,25 +108,25 @@ build-docker-register:
--build-arg "TAG=${GIT_TAG}" \
--build-arg "COMMIT=${GIT_COMMIT}" \
--build-arg "COMMITDATE=${COMMITDATE}" \
-t ${REPO_REGISTER}:${TAG} .
-t ${REGISTRY_HEADER}${REPO_REGISTER}:${TAG} .

.PHONY: build-docker-seedimage-builder
build-docker-seedimage-builder:
DOCKER_BUILDKIT=1 docker build \
-f Dockerfile.seedimage \
-t ${REPO_SEEDIMAGE}:${TAG} .
-t ${REGISTRY_HEADER}${REPO_SEEDIMAGE}:${TAG} .

.PHONY: build-docker-push-operator
build-docker-push-operator: build-docker-operator
docker push ${REPO}:${TAG}
docker push ${REGISTRY_HEADER}${REPO}:${TAG}

.PHONY: build-docker-push-register
build-docker-push-register: build-docker-register
docker push ${REPO_REGISTER}:${TAG}
docker push ${REGISTRY_HEADER}${REPO_REGISTER}:${TAG}

.PHONY: build-docker-push-seedimage-builder
build-docker-push-seedimage-builder: build-docker-seedimage-builder
docker push ${REPO_SEEDIMAGE}:${TAG}
docker push ${REGISTRY_HEADER}${REPO_SEEDIMAGE}:${TAG}

.PHONY: chart
chart:
Expand All @@ -130,8 +137,9 @@ chart:
cp -rf $(ROOT_DIR)/charts/operator $(ROOT_DIR)/build/operator
yq -i '.image.tag = "${TAG}"' $(ROOT_DIR)/build/operator/values.yaml
yq -i '.image.repository = "${REPO}"' $(ROOT_DIR)/build/operator/values.yaml
yq -i '.seedImage.tag = "${TAG_SEEDIMAGE}"' $(ROOT_DIR)/build/operator/values.yaml
yq -i '.seedImage.tag = "${TAG}"' $(ROOT_DIR)/build/operator/values.yaml
yq -i '.seedImage.repository = "${REPO_SEEDIMAGE}"' $(ROOT_DIR)/build/operator/values.yaml
yq -i '.registry_url = "${REGISTRY_URL}"' $(ROOT_DIR)/build/operator/values.yaml
helm package --version ${CHART_VERSION} --app-version ${GIT_TAG} -d $(ROOT_DIR)/build/ $(ROOT_DIR)/build/operator
rm -Rf $(ROOT_DIR)/build/operator

Expand Down Expand Up @@ -170,20 +178,20 @@ setup-full-cluster: build-docker-operator build-docker-seedimage-builder chart s
export BRIDGE_IP="172.18.0.1" && \
export CHART=$(CHART) && \
export CONFIG_PATH=$(E2E_CONF_FILE) && \
kind load docker-image --name $(CLUSTER_NAME) ${REPO}:${TAG} && \
kind load docker-image --name $(CLUSTER_NAME) ${REPO_SEEDIMAGE}:${TAG} && \
kind load docker-image --name $(CLUSTER_NAME) ${REGISTRY_HEADER}${REPO}:${TAG} && \
kind load docker-image --name $(CLUSTER_NAME) ${REGISTRY_HEADER}${REPO_SEEDIMAGE}:${TAG} && \
cd $(ROOT_DIR)/tests && $(GINKGO) -r -v --label-filter="do-nothing" ./e2e

kind-e2e-tests: build-docker-operator chart setup-kind
export CONFIG_PATH=$(E2E_CONF_FILE) && \
kind load docker-image --name $(CLUSTER_NAME) ${REPO}:${TAG}
kind load docker-image --name $(CLUSTER_NAME) ${REGISTRY_HEADER}${REPO}:${TAG}
$(MAKE) e2e-tests

# This builds the docker image, generates the chart, loads the image into the kind cluster and upgrades the chart to latest
# useful to test changes into the operator with a running system, without clearing the operator namespace
# thus losing any registration/inventories/os CRDs already created
reload-operator: build-docker-operator chart
kind load docker-image --name $(CLUSTER_NAME) ${REPO}:${TAG}
kind load docker-image --name $(CLUSTER_NAME) ${REGISTRY_HEADER}${REPO}:${TAG}
helm upgrade -n cattle-elemental-system elemental-operator $(CHART)

.PHONY: vendor
Expand Down
4 changes: 0 additions & 4 deletions charts/crds/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ version: 0.0.0
appVersion: 0.0.0
annotations:
catalog.cattle.io/certified: rancher
catalog.cattle.io/display-name: Elemental CRDs
catalog.cattle.io/experimental: "true"
catalog.cattle.io/namespace: cattle-elemental-system
catalog.cattle.io/os: linux
catalog.cattle.io/provides-gvr: elemental.cattle.io/v1beta1
catalog.cattle.io/release-name: elemental-operator-crds
catalog.cattle.io/hidden: true # Hide specific charts. Only use on CRD charts.
7 changes: 6 additions & 1 deletion charts/operator/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ icon: https://raw.githubusercontent.com/rancher/elemental/main/logo/icon-element
version: 0.0.0
appVersion: 0.0.0
annotations:
catalog.cattle.io/auto-install: elemental-crd=match
catalog.cattle.io/certified: rancher
catalog.cattle.io/display-name: Elemental
catalog.cattle.io/experimental: "true"
catalog.cattle.io/kube-version: '>= 1.23.0-0 < 1.28.0-0'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how/where did you define this range?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a mandatory annotation for the Rancher Marketplace: since these annotations are for Rancher only, seems to me that makes sense to add all the required ones.
Kubernetes 1.23 is the minimal version supported by Rancher 2.7.x and we require Rancher 2.7.x.
Kubernetes 1.28 is just an high Kube version: the value is arbitrary high and the common one used in the Rancher 2.7 marketplace.
I don't think this restriction will be put in place ever, in any case I wish that for Kube 1.28 users will install a newer chart version 😄

catalog.cattle.io/namespace: cattle-elemental-system
catalog.cattle.io/os: linux
catalog.cattle.io/permits-os: linux
catalog.cattle.io/provides-gvr: elemental.cattle.io/v1beta1
catalog.cattle.io/rancher-version: '>= 2.7.0-0 < 2.8.0-0'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, this also seem rather strict

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, this is different IMO: we don't support Rancher 2.6.x.
Moreover, we don't know if this chart will be compatible with Rancher 2.8.0: a lot could change there.
We will expand the supported versions when needed, but for sure we want the older chart versions to disappear by default from the marketplace for future Rancher versions (we want to release newer charts... or rebuild the same with updated tags is needed after proper testing).
This also is a common pattern in Rancher Marketplace charts.

catalog.cattle.io/release-name: elemental-operator
catalog.cattle.io/scope: management
catalog.cattle.io/type: cluster-tool
5 changes: 5 additions & 0 deletions charts/operator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Elemental Operator Helm Chart

This chart bootstraps an elemental-operator deployment on a [Rancher Manager](https://rancher.com/docs/rancher/) cluster using the [Helm](https://helm.sh) package manager.

Check out the [Elemental Operator Helm Chart documentation](https://elemental.docs.rancher.com/elementaloperatorchart-reference/) in the official [Elemental guide](https://elemental.docs.rancher.com/).
12 changes: 11 additions & 1 deletion charts/operator/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,14 @@
{{- else -}}
{{- "" -}}
{{- end -}}
{{- end -}}
{{- end -}}

{{- define "registry_url" -}}
{{- if .Values.global.cattle.systemDefaultRegistry -}}
{{ include "system_default_registry" . }}
{{- else if .Values.registry_url -}}
{{- printf "%s/" .Values.registry_url -}}
{{- else -}}
{{- "" -}}
{{- end -}}
{{- end -}}
2 changes: 1 addition & 1 deletion charts/operator/templates/channel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ metadata:
namespace: fleet-default
spec:
options:
image: {{ .Values.channel.repository }}:{{ .Values.channel.tag }}
image: {{ template "registry_url" . }}{{ .Values.channel.repository }}:{{ .Values.channel.tag }}
type: custom
{{ end }}
6 changes: 3 additions & 3 deletions charts/operator/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ spec:
{{- end }}
name: {{ .Release.Name }}
imagePullPolicy: "{{ .Values.image.imagePullPolicy }}"
image: {{ template "system_default_registry" . }}{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}
image: {{ template "registry_url" . }}{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}
args:
- operator
{{- if .Values.debug }}
Expand All @@ -34,9 +34,9 @@ spec:
- --namespace
- {{ .Release.Namespace }}
- --operator-image
- {{ template "system_default_registry" . }}{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}
- {{ template "registry_url" . }}{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}
- --seedimage-image
- {{ template "system_default_registry" . }}{{ .Values.seedImage.repository }}:{{ .Values.seedImage.tag | default .Chart.AppVersion }}
- {{ template "registry_url" . }}{{ .Values.seedImage.repository }}:{{ .Values.seedImage.tag | default .Chart.AppVersion }}
- --seedimage-image-pullpolicy
- {{ .Values.seedImage.imagePullPolicy}}
serviceAccountName: {{ .Release.Name }}
Expand Down
11 changes: 9 additions & 2 deletions charts/operator/values.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
image:
empty: rancher/pause:3.1
repository: "quay.io/costoolkit/elemental-operator"
repository: "rancher/elemental-operator"
tag: latest
imagePullPolicy: IfNotPresent

seedImage:
repository: "quay.io/costoolkit/seedimage-builder"
repository: "rancher/seedimage-builder"
tag: latest
imagePullPolicy: IfNotPresent

#channel:
# repository: rancher/elemental-teal-channel
# tag: latest

# number of operator replicas to deploy
replicas: 1

Expand All @@ -22,6 +26,9 @@ global:
cattle:
systemDefaultRegistry: ""

# used only if systemDefaultRegistry is empty
registry_url: ""

# enable debug output for operator
debug: false

Expand Down