Skip to content

Commit

Permalink
test(chart): add helm unittest tests
Browse files Browse the repository at this point in the history
  • Loading branch information
basti1302 committed Jun 6, 2024
1 parent 03205e2 commit 6c48530
Show file tree
Hide file tree
Showing 7 changed files with 212 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/verify.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ jobs:
run: |
make lint
- name: install Helm unittest plugin
shell: bash
run: |
helm plugin install https://github.com/helm-unittest/helm-unittest.git
- name: test
run: |
make test
Expand Down
8 changes: 7 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Contributing
- Docker
- kubectl version v1.11.3+.
- Access to a Kubernetes v1.11.3+ cluster.
- [helm](https://helm.sh/docs/intro/install/)
- [helm unittest plug-in](https://github.com/helm-unittest/helm-unittest/tree/main)

## Deploying to a Local Cluster for Testing Purposes

Expand Down Expand Up @@ -79,12 +81,17 @@ make undeploy-via-kustomize

When undeploying the controllor, the same tool (helm vs. kustomiz) should be used as when deploying it.

This will also remove the custom resource definition. However, the custom resource definition can also be removed
separately via `make uninstall` without removing the operator.

## Run Tests

```
make test
```

This will run the go unit tests as well as the helm chart tests.

### End-to-End Tests

The end-to-end tests currently only support Kubernetes via Docker Desktop on Mac.
Expand All @@ -102,4 +109,3 @@ More information can be found via the [Kubebuilder Documentation](https://book.k
## Contributing

No contribution guidelines are available at this point.

1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ vet: ## Run go vet against code.
.PHONY: test
test: manifests generate fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v /e2e) -coverprofile cover.out
cd helm-chart/dash0-operator && helm unittest -f 'tests/**/*.yaml' .

# Invoking ginkgo via go run makes sure we use the version from go.mod and not a version installed globally, which
# would be used when simply running `ginkgo -v test/e2e`. An alternative would be to invoke ginkgo via go test, that
Expand Down
1 change: 1 addition & 0 deletions helm-chart/dash0-operator/.helmignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
*.tmp
*.orig
*~
tests/
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
deployment should match snapshot (default values):
1: |
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app.kubernetes.io/component: manager
app.kubernetes.io/instance: controller-manager
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: deployment
app.kubernetes.io/part-of: dash0-operator
app.kubernetes.io/version: 1.0.0
control-plane: controller-manager
helm.sh/chart: dash0-operator-1.0.0
name: dash0-operator-controller-manager
namespace: NAMESPACE
spec:
replicas: 1
selector:
matchLabels:
control-plane: controller-manager
template:
metadata:
annotations:
kubectl.kubernetes.io/default-container: manager
labels:
control-plane: controller-manager
spec:
containers:
- args:
- --health-probe-bind-address=:8081
- --metrics-bind-address=127.0.0.1:8080
- --leader-elect
command:
- /manager
env:
- name: DASH0_OPERATOR_IMAGE
value: dash0-operator-controller:1.0.0
- name: DASH0_INIT_CONTAINER_IMAGE
value: dash0-instrumentation:1.0.0
image: dash0-operator-controller:1.0.0
livenessProbe:
httpGet:
path: /healthz
port: 8081
initialDelaySeconds: 15
periodSeconds: 20
name: manager
ports:
- containerPort: 9443
name: webhook-server
protocol: TCP
readinessProbe:
httpGet:
path: /readyz
port: 8081
initialDelaySeconds: 5
periodSeconds: 10
resources:
limits:
cpu: 500m
ephemeral-storage: 500Mi
memory: 128Mi
requests:
cpu: 10m
ephemeral-storage: 500Mi
memory: 64Mi
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
volumeMounts:
- mountPath: /tmp/k8s-webhook-server/serving-certs
name: cert
readOnly: true
- args:
- --secure-listen-address=0.0.0.0:8443
- --upstream=http://127.0.0.1:8080/
- --logtostderr=true
- --v=0
image: gcr.io/kubebuilder/kube-rbac-proxy:v0.15.0
name: kube-rbac-proxy
ports:
- containerPort: 8443
name: https
protocol: TCP
resources:
limits:
cpu: 500m
memory: 128Mi
requests:
cpu: 5m
memory: 64Mi
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
securityContext:
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
serviceAccountName: dash0-operator-controller-manager
terminationGracePeriodSeconds: 10
volumes:
- name: cert
secret:
defaultMode: 420
secretName: webhook-server-cert
86 changes: 86 additions & 0 deletions helm-chart/dash0-operator/tests/operator/deployment_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
suite: test deployment
templates:
- operator/deployment.yaml
tests:
- it: deployment should match snapshot (default values)
asserts:
- matchSnapshot: {}

- it: render deployment with custom settings
set:
operator:
additionalLabels:
label1: "value 1"
label2: "value 2"
deploymentAnnotations:
annotation1: "value 1"
annotation2: "value 2"
replicaCount: 3
podAnnotations:
annotation1: "value 1"
annotation2: "value 2"
podLabels:
label1: "value 1"
label2: "value 2"
image: custom-operator-image:1.2.3
imagePullPolicy: Never
initContainerImage: custom-init-container-image:4.5.6
managerPodResources:
limits:
cpu: 123m
memory: 456Mi
requests:
cpu: 5m
memory: 32Mi
asserts:
- equal:
path: metadata.labels['label1']
value: "value 1"
- equal:
path: metadata.labels['label2']
value: "value 2"
- equal:
path: metadata.annotations['annotation1']
value: "value 1"
- equal:
path: metadata.annotations['annotation2']
value: "value 2"
- equal:
path: spec.replicas
value: 3
- equal:
path: spec.template.metadata.annotations['annotation1']
value: "value 1"
- equal:
path: spec.template.metadata.annotations['annotation2']
value: "value 2"
- equal:
path: spec.template.metadata.labels['label1']
value: "value 1"
- equal:
path: spec.template.metadata.labels['label2']
value: "value 2"
- equal:
path: spec.template.spec.containers[0].image
value: custom-operator-image:1.2.3
- equal:
path: spec.template.spec.containers[0].imagePullPolicy
value: Never
- equal:
path: spec.template.spec.containers[0].env[0].value
value: custom-operator-image:1.2.3
- equal:
path: spec.template.spec.containers[0].env[1].value
value: custom-init-container-image:4.5.6
- equal:
path: spec.template.spec.containers[0].resources.limits.cpu
value: 123m
- equal:
path: spec.template.spec.containers[0].resources.limits.memory
value: 456Mi
- equal:
path: spec.template.spec.containers[0].resources.requests.cpu
value: 5m
- equal:
path: spec.template.spec.containers[0].resources.requests.memory
value: 32Mi
4 changes: 2 additions & 2 deletions helm-chart/dash0-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ operator:

# settings for the service account to be used
serviceAccount:
# whether or not to create a dedicated service account, set this to false if you want to provide a separately
# whether to create a dedicated service account, set this to false if you want to provide a separately
# created service account
create: true
# can be used to override the default name of the serviceaccount (defaults to "dash0-operator-controller-manager")
Expand Down Expand Up @@ -41,7 +41,7 @@ operator:
# additional labels for the controller manager pod(s), example:
# podLabels:
# label1: "value 1"
# labels: "value 2"
# label2: "value 2"
podLabels: {}

# resources for the controller manager pod(s)
Expand Down

0 comments on commit 6c48530

Please sign in to comment.