Skip to content

Commit c4db5ba

Browse files
committed
feat: add helm unit tests
Signed-off-by: Sathvik <Sathvik.S@ibm.com>
1 parent ba30fa7 commit c4db5ba

31 files changed

Lines changed: 5379 additions & 0 deletions

Makefile

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,3 +305,74 @@ endef
305305
define gomodver
306306
$(shell go list -m -f '{{if .Replace}}{{.Replace.Version}}{{else}}{{.Version}}{{end}}' $(1) 2>/dev/null)
307307
endef
308+
309+
##@ Helm Deployment
310+
311+
## Helm binary to use for deploying the chart
312+
HELM ?= helm
313+
## Namespace to deploy the Helm release
314+
HELM_NAMESPACE ?= mcp-lifecycle-operator-system
315+
## Name of the Helm release
316+
HELM_RELEASE ?= mcp-lifecycle-operator
317+
## Path to the Helm chart directory
318+
HELM_CHART_DIR ?= dist/chart
319+
## Additional arguments to pass to helm commands
320+
HELM_EXTRA_ARGS ?=
321+
322+
.PHONY: install-helm
323+
install-helm: ## Install the latest version of Helm.
324+
@command -v $(HELM) >/dev/null 2>&1 || { \
325+
echo "Installing Helm..." && \
326+
curl -fsSL https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-4 | bash; \
327+
}
328+
329+
.PHONY: helm-deploy
330+
helm-deploy: install-helm ## Deploy manager to the K8s cluster via Helm. Specify an image with IMG.
331+
$(HELM) upgrade --install $(HELM_RELEASE) $(HELM_CHART_DIR) \
332+
--namespace $(HELM_NAMESPACE) \
333+
--create-namespace \
334+
--set manager.image.repository=$${IMG%:*} \
335+
--set manager.image.tag=$${IMG##*:} \
336+
--wait \
337+
--timeout 5m \
338+
$(HELM_EXTRA_ARGS)
339+
340+
.PHONY: helm-uninstall
341+
helm-uninstall: ## Uninstall the Helm release from the K8s cluster.
342+
$(HELM) uninstall $(HELM_RELEASE) --namespace $(HELM_NAMESPACE)
343+
344+
.PHONY: helm-status
345+
helm-status: ## Show Helm release status.
346+
$(HELM) status $(HELM_RELEASE) --namespace $(HELM_NAMESPACE)
347+
348+
.PHONY: helm-history
349+
helm-history: ## Show Helm release history.
350+
$(HELM) history $(HELM_RELEASE) --namespace $(HELM_NAMESPACE)
351+
352+
.PHONY: helm-rollback
353+
helm-rollback: ## Rollback to previous Helm release.
354+
355+
##@ Helm Testing
356+
357+
## Helm unittest plugin version
358+
HELM_UNITTEST_VERSION ?= 0.6.2
359+
360+
.PHONY: install-helm-unittest
361+
install-helm-unittest: install-helm ## Install helm-unittest plugin if not already installed.
362+
@$(HELM) plugin list | grep -q unittest || { \
363+
echo "Installing helm-unittest plugin..." && \
364+
$(HELM) plugin install https://github.com/helm-unittest/helm-unittest.git --version $(HELM_UNITTEST_VERSION) --verify=false; \
365+
}
366+
367+
.PHONY: helm-test
368+
helm-test: install-helm-unittest ## Run helm-unittest tests for the Helm chart.
369+
$(HELM) unittest $(HELM_CHART_DIR)
370+
371+
.PHONY: helm-test-verbose
372+
helm-test-verbose: install-helm-unittest ## Run helm-unittest tests with verbose output.
373+
$(HELM) unittest $(HELM_CHART_DIR) -d
374+
375+
.PHONY: helm-test-debug
376+
helm-test-debug: install-helm-unittest ## Run helm-unittest tests with debug output and rendered templates.
377+
$(HELM) unittest $(HELM_CHART_DIR) -d --debug
378+
$(HELM) rollback $(HELM_RELEASE) --namespace $(HELM_NAMESPACE)

PROJECT

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ cliVersion: 4.11.1
66
domain: x-k8s.io
77
layout:
88
- go.kubebuilder.io/v4
9+
plugins:
10+
helm.kubebuilder.io/v2-alpha:
11+
manifests: dist/install.yaml
12+
output: dist
913
projectName: mcp-lifecycle-operator
1014
repo: github.com/kubernetes-sigs/mcp-lifecycle-operator
1115
resources:

dist/chart/.helmignore

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Patterns to ignore when building Helm packages.
2+
# Operating system files
3+
.DS_Store
4+
5+
# Version control directories
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.hg/
10+
.hgignore
11+
.svn/
12+
13+
# Backup and temporary files
14+
*.swp
15+
*.tmp
16+
*.bak
17+
*.orig
18+
*~
19+
20+
# IDE and editor-related files
21+
.idea/
22+
.vscode/
23+
24+
# Helm chart artifacts
25+
dist/chart/*.tgz

dist/chart/Chart.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: v2
2+
name: mcp-lifecycle-operator
3+
description: A Helm chart to distribute mcp-lifecycle-operator
4+
type: application
5+
6+
version: 0.1.0
7+
appVersion: "0.1.0"
8+
9+
keywords:
10+
- kubernetes
11+
- operator
12+
13+
annotations:
14+
kubebuilder.io/generated-by: kubebuilder

dist/chart/templates/NOTES.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Thank you for installing {{ .Chart.Name }}.
2+
3+
Your release is named {{ .Release.Name }}.
4+
5+
The controller and CRDs have been installed in namespace {{ .Release.Namespace }}.
6+
7+
To verify the installation:
8+
9+
kubectl get pods -n {{ .Release.Namespace }}
10+
kubectl get customresourcedefinitions
11+
12+
To learn more about the release, try:
13+
14+
$ helm status {{ .Release.Name }} -n {{ .Release.Namespace }}
15+
$ helm get all {{ .Release.Name }} -n {{ .Release.Namespace }}

dist/chart/templates/_helpers.tpl

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "mcp-lifecycle-operator.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 "mcp-lifecycle-operator.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+
Namespace for generated references.
28+
Always uses the Helm release namespace.
29+
*/}}
30+
{{- define "mcp-lifecycle-operator.namespaceName" -}}
31+
{{- .Release.Namespace }}
32+
{{- end }}
33+
34+
{{/*
35+
Resource name with proper truncation for Kubernetes 63-character limit.
36+
Takes a dict with:
37+
- .suffix: Resource name suffix (e.g., "metrics", "webhook")
38+
- .context: Template context (root context with .Values, .Release, etc.)
39+
Dynamically calculates safe truncation to ensure total name length <= 63 chars.
40+
*/}}
41+
{{- define "mcp-lifecycle-operator.resourceName" -}}
42+
{{- $fullname := include "mcp-lifecycle-operator.fullname" .context }}
43+
{{- $suffix := .suffix }}
44+
{{- $maxLen := sub 62 (len $suffix) | int }}
45+
{{- if gt (len $fullname) $maxLen }}
46+
{{- printf "%s-%s" (trunc $maxLen $fullname | trimSuffix "-") $suffix | trunc 63 | trimSuffix "-" }}
47+
{{- else }}
48+
{{- printf "%s-%s" $fullname $suffix | trunc 63 | trimSuffix "-" }}
49+
{{- end }}
50+
{{- end }}

0 commit comments

Comments
 (0)