Skip to content

Commit

Permalink
Merge pull request #10 from mzeevi/ci/addHelm
Browse files Browse the repository at this point in the history
ci: add helm chart to repo with release workflow
  • Loading branch information
dvirgilad authored Aug 19, 2024
2 parents ba39079 + 850906d commit ab38e83
Show file tree
Hide file tree
Showing 20 changed files with 888 additions and 47 deletions.
37 changes: 0 additions & 37 deletions .github/workflows/post-release.yaml

This file was deleted.

95 changes: 95 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: release
on:
release:
types: [published]
env:
REGISTRY: ghcr.io
REPOSITORY_NAME: ${{ github.repository }}
DANA_ORG: dana-team

jobs:
build-and-push-image:
name: Build and push image
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push image
run: make docker-build docker-push IMG=${{ env.REGISTRY }}/${{ env.REPOSITORY_NAME }}:${GITHUB_REF##*/}

- name: Create install.yaml file
run: make build-installer IMG=${{ env.REGISTRY }}/${{ env.REPOSITORY_NAME }}:${GITHUB_REF##*/}

- name: Upload install.yaml file
uses: softprops/action-gh-release@v2
with:
files: dist/install.yaml

build-and-push-helm-chart:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write

steps:
- name: Checkout repository
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9

- name: Set up Helm
uses: azure/setup-helm@5119fcb9089d432beecbf79bb2c7915207344b78
with:
version: v3.12.0

- name: Set chart name
id: chart-name
run: echo "value=${{ github.event.repository.name }}" >> "$GITHUB_OUTPUT"

- name: Set OCI registry name
id: oci-registry-name
run: echo "value=ghcr.io/${{ github.repository_owner }}/helm-charts" >> "$GITHUB_OUTPUT"

- name: Set OCI chart name
id: oci-chart-name
run: echo "value=${{ steps.oci-registry-name.outputs.value }}/${{ steps.chart-name.outputs.value }}" >> "$GITHUB_OUTPUT"

- name: Helm lint
run: helm lint charts/${{ steps.chart-name.outputs.value }}

- name: Trim prefix from version
id: version
run: echo "value=$(echo ${{ github.ref_name }} | sed 's/release-//')" >> "$GITHUB_OUTPUT"

- name: Helm package
id: build
run: |
helm package charts/${{ steps.chart-name.outputs.value }} --version ${{ steps.version.outputs.value }} --app-version ${{ steps.version.outputs.value }}
echo "package=${{ steps.chart-name.outputs.value }}-${{ steps.version.outputs.value }}.tgz" >> "$GITHUB_OUTPUT"
- name: Upload chart as artifact
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32
with:
name: "[${{ github.job }}] Helm chart"
path: ${{ steps.build.outputs.package }}

- name: Log in to the Container registry
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Helm push
run: helm push ${{ steps.build.outputs.package }} oci://${{ steps.oci-registry-name.outputs.value }}
env:
HELM_REGISTRY_CONFIG: ~/.docker/config.json
43 changes: 33 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,9 @@ deploy-addons: deploy-score-addon deploy-status-addon
.PHONY: undeploy-addons
undeploy-addons: undeploy-score-addon undeploy-status-addon

.PHONY: build/install.yaml
build/install.yaml: kustomize
mkdir -p $(dir $@) && \
rm -rf build/kustomize && \
mkdir -p build/kustomize && \
cd build/kustomize && \
$(KUSTOMIZE) create --resources ../../score/deploy/resources/default,../../status/deploy/resources/default && \
$(KUSTOMIZE) edit set image controller=${IMG} && \
cd ${CURDIR} && \
$(KUSTOMIZE) build build/kustomize > $@
.PHONY: doc-chart
doc-chart: helm-docs helm helm-plugins
$(HELM_DOCS) charts/

##@ Dependencies

Expand All @@ -169,12 +162,16 @@ KUSTOMIZE ?= $(LOCALBIN)/kustomize-$(KUSTOMIZE_VERSION)
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen-$(CONTROLLER_TOOLS_VERSION)
ENVTEST ?= $(LOCALBIN)/setup-envtest-$(ENVTEST_VERSION)
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint-$(GOLANGCI_LINT_VERSION)
HELM_DOCS ?= $(LOCALBIN)/helm-docs-$(HELM_DOCS_VERSION)

HELM_URL ?= https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3

## Tool Versions
KUSTOMIZE_VERSION ?= v5.3.0
CONTROLLER_TOOLS_VERSION ?= v0.14.0
ENVTEST_VERSION ?= release-0.17
GOLANGCI_LINT_VERSION ?= v1.54.2
HELM_DOCS_VERSION ?= v1.14.2

.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
Expand All @@ -196,6 +193,32 @@ golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
$(GOLANGCI_LINT): $(LOCALBIN)
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,${GOLANGCI_LINT_VERSION})

.PHONY: helm
helm: ## Install helm on the local machine
wget -O $(LOCALBIN)/get-helm.sh $(HELM_URL)
chmod 700 $(LOCALBIN)/get-helm.sh
$(LOCALBIN)/get-helm.sh

.PHONY: helm-plugins
helm-plugins: ## Install helm plugins on the local machine
@if ! helm plugin list | grep -q 'diff'; then \
helm plugin install https://github.com/databus23/helm-diff; \
fi
@if ! helm plugin list | grep -q 'git'; then \
helm plugin install https://github.com/aslafy-z/helm-git; \
fi
@if ! helm plugin list | grep -q 's3'; then \
helm plugin install https://github.com/hypnoglow/helm-s3; \
fi
@if ! helm plugin list | grep -q 'secrets'; then \
helm plugin install https://github.com/jkroepke/helm-secrets; \
fi

.PHONY: helm-docs
helm-docs: $(HELM_DOCS)
$(HELM_DOCS): $(LOCALBIN)
$(call go-install-tool,$(HELM_DOCS),github.com/norwoodj/helm-docs/cmd/helm-docs,$(HELM_DOCS_VERSION))

# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
# $1 - target path with name of binary (ideally with version)
# $2 - package url which can be installed
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ Based on the [resource-usage-collect-addon](https://github.com/open-cluster-mana

Check the guide on the `rcs-ocm-deployer` [repo](https://github.com/mzeevi/rcs-ocm-deployer/tree/main?tab=readme-ov-file#deploy-the-add-ons) for information about deploying the `AddOns` on an `OCM` cluster.

Deploy using the Helm chart located at `charts/rcs-ocm-addons`:

```bash
$ helm upgrade --install rcs-ocm-addons --namespace open-cluster-management --create-namespace oci://ghcr.io/dana-team/helm-charts/rcs-ocm-addons --version <release>
```

### Build your own image

```bash
Expand Down
23 changes: 23 additions & 0 deletions charts/rcs-ocm-addons/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
24 changes: 24 additions & 0 deletions charts/rcs-ocm-addons/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: rcs-ocm-addons
description: A Helm chart for the rcs-score-addon

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.0.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "latest"
44 changes: 44 additions & 0 deletions charts/rcs-ocm-addons/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# rcs-ocm-addons

![Version: 0.0.0](https://img.shields.io/badge/Version-0.0.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: latest](https://img.shields.io/badge/AppVersion-latest-informational?style=flat-square)

A Helm chart for the rcs-score-addon

## Values

| Key | Type | Default | Description |
|-----|------|---------|-------------|
| affinity | object | `{}` | Node affinity rules for scheduling pods. Allows you to specify advanced node selection constraints. |
| deploymentConfig | object | `{"agentInstallNamespace":"open-cluster-management-agent-addon","customizedVariables":[{"name":"MAX_CPU_COUNT","value":"1"},{"name":"MIN_CPU_COUNT","value":"0"},{"name":"MAX_MEMORY_BYTES","value":"104857"},{"name":"MIN_MEMORY_BYTES","value":"0"}],"name":"rcs-score-deploy-config","namespace":"open-cluster-management-hub"}` | Configurations for the AddonDeploymentConfig object |
| deploymentConfig.agentInstallNamespace | string | `"open-cluster-management-agent-addon"` | Namespace where the agent addon is installed |
| deploymentConfig.customizedVariables | list | `[{"name":"MAX_CPU_COUNT","value":"1"},{"name":"MIN_CPU_COUNT","value":"0"},{"name":"MAX_MEMORY_BYTES","value":"104857"},{"name":"MIN_MEMORY_BYTES","value":"0"}]` | Customzied variables for the addon |
| deploymentConfig.name | string | `"rcs-score-deploy-config"` | Name of the AddonDeploymentConfig |
| deploymentConfig.namespace | string | `"open-cluster-management-hub"` | Namespace of the AddonDeploymentConfig |
| fullnameOverride | string | `""` | |
| image.pullPolicy | string | `"IfNotPresent"` | The pull policy for the image. |
| image.repository | string | `"ghcr.io/dana-team/rcs-ocm-addons"` | The repository of the manager container image. |
| image.tag | string | `""` | The tag of the manager container image. |
| installStrategy.score.placements[0].configs[0].group | string | `"addon.open-cluster-management.io"` | |
| installStrategy.score.placements[0].configs[0].name | string | `"rcs-score-deploy-config"` | |
| installStrategy.score.placements[0].configs[0].namespace | string | `"open-cluster-management-hu"` | |
| installStrategy.score.placements[0].configs[0].resource | string | `"addondeploymentconfigs"` | |
| installStrategy.score.placements[0].name | string | `"all-clusters"` | |
| installStrategy.score.placements[0].namespace | string | `"test"` | |
| installStrategy.score.placements[0].rolloutStrategy.type | string | `"All"` | |
| installStrategy.score.type | string | `"Placements"` | |
| installStrategy.status.placements[0].name | string | `"all-clusters"` | |
| installStrategy.status.placements[0].namespace | string | `"test"` | |
| installStrategy.status.placements[0].rolloutStrategy.type | string | `"All"` | |
| installStrategy.status.type | string | `"Placements"` | |
| manager | object | `{"resources":{"limits":{"cpu":"500m","memory":"128Mi"},"requests":{"cpu":"10m","memory":"64Mi"}},"score":{"args":["manager"],"command":["/score-addon"]},"securityContext":{"allowPrivilegeEscalation":false,"capabilities":{"drop":["ALL"]}},"status":{"args":["manager"],"command":["/status-addon"]}}` | Configuration for the manager container. |
| manager.resources | object | `{"limits":{"cpu":"500m","memory":"128Mi"},"requests":{"cpu":"10m","memory":"64Mi"}}` | Resource requests and limits for the manager container. |
| manager.score.args | list | `["manager"]` | Command-line arguments passed to the score-addon manager container. |
| manager.score.command | list | `["/score-addon"]` | Command-line commands passed to the score-addon manager container. |
| manager.securityContext | object | `{"allowPrivilegeEscalation":false,"capabilities":{"drop":["ALL"]}}` | Security settings for the manager container. |
| manager.status.args | list | `["manager"]` | Command-line arguments passed to the status-adon manager container. |
| manager.status.command | list | `["/status-addon"]` | Command-line commands passed to the status-addon manager container. |
| nameOverride | string | `""` | |
| nodeSelector | object | `{}` | Node selector for scheduling pods. Allows you to specify node labels for pod assignment. |
| replicaCount | int | `1` | The number of replicas for the deployment. |
| tolerations | list | `[]` | Node tolerations for scheduling pods. Allows the pods to be scheduled on nodes with matching taints. |

62 changes: 62 additions & 0 deletions charts/rcs-ocm-addons/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "rcs-ocm-addons.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "rcs-ocm-addons.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "rcs-ocm-addons.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "rcs-ocm-addons.labels" -}}
helm.sh/chart: {{ include "rcs-ocm-addons.chart" . }}
{{ include "rcs-ocm-addons.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "rcs-ocm-addons.selectorLabels" -}}
app.kubernetes.io/name: {{ include "rcs-ocm-addons.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "rcs-ocm-addons.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "rcs-ocm-addons.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
Loading

0 comments on commit ab38e83

Please sign in to comment.