Skip to content
Open
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
14 changes: 14 additions & 0 deletions helm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,18 @@ helm install bankapp-dev bankapp/ --set namespace=dev-namespace --set bankapp_sv

Happy Helming!

## Testing

Helm unit tests are located in `bankapp/tests/` and use the [helm-unittest](https://github.com/helm-unittest/helm-unittest) plugin.

### Install the helm-unittest plugin
```bash
helm plugin install https://github.com/helm-unittest/helm-unittest
```

### Run tests
```bash
helm unittest helm/bankapp/
```


24 changes: 3 additions & 21 deletions helm/bankapp/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,6 @@
apiVersion: v2
name: bankapp
description: A Helm chart for Kubernetes

# 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/)
description: A Helm chart for the Spring Boot BankApp with MySQL
version: 0.1.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: "1.16.0"
appVersion: "1.0.0"
type: application
208 changes: 208 additions & 0 deletions helm/bankapp/tests/deployment_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
suite: Deployment tests
templates:
- templates/deployment.yml
tests:
- it: should be a Deployment
asserts:
- isKind:
of: Deployment

- it: should set the default name to bankapp
asserts:
- equal:
path: metadata.name
value: bankapp

- it: should set the default namespace to bankapp-namespace
asserts:
- equal:
path: metadata.namespace
value: bankapp-namespace

- it: should override namespace when set in values
set:
namespace: custom-namespace
asserts:
- equal:
path: metadata.namespace
value: custom-namespace

- it: should have app label on metadata
asserts:
- equal:
path: metadata.labels.app
value: bankapp

- it: should have app label on selector matchLabels
asserts:
- equal:
path: spec.selector.matchLabels.app
value: bankapp

- it: should have app label on pod template
asserts:
- equal:
path: spec.template.metadata.labels.app
value: bankapp

- it: should set replicas to 1
asserts:
- equal:
path: spec.replicas
value: 1

- it: should have init container named wait-for-mysql
asserts:
- equal:
path: spec.template.spec.initContainers[0].name
value: wait-for-mysql

- it: should use busybox 1.28 for init container
asserts:
- equal:
path: spec.template.spec.initContainers[0].image
value: "busybox:1.28"

- it: should check mysql-0.mysql-headless:3306 in init container command
asserts:
- matchRegex:
path: spec.template.spec.initContainers[0].command[2]
pattern: "mysql-0\\.mysql-headless 3306"

- it: should use default app image
asserts:
- equal:
path: spec.template.spec.containers[0].image
value: "trainwithshubham/springboot-bankapp:latest"

- it: should expose container port 8080
asserts:
- equal:
path: spec.template.spec.containers[0].ports[0].containerPort
value: 8080

- it: should get SPRING_DATASOURCE_URL from configMapKeyRef bankapp-config
asserts:
- contains:
path: spec.template.spec.containers[0].env
content:
name: SPRING_DATASOURCE_URL
valueFrom:
configMapKeyRef:
name: bankapp-config
key: SPRING_DATASOURCE_URL

- it: should get SPRING_DATASOURCE_USERNAME from configMapKeyRef bankapp-config
asserts:
- contains:
path: spec.template.spec.containers[0].env
content:
name: SPRING_DATASOURCE_USERNAME
valueFrom:
configMapKeyRef:
name: bankapp-config
key: SPRING_DATASOURCE_USERNAME

- it: should get SPRING_DATASOURCE_PASSWORD from secretKeyRef mysql-secret
asserts:
- contains:
path: spec.template.spec.containers[0].env
content:
name: SPRING_DATASOURCE_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-secret
key: SPRING_DATASOURCE_PASSWORD

- it: should configure liveness probe on /actuator/health port 8080
asserts:
- equal:
path: spec.template.spec.containers[0].livenessProbe.httpGet.path
value: /actuator/health
- equal:
path: spec.template.spec.containers[0].livenessProbe.httpGet.port
value: 8080
- equal:
path: spec.template.spec.containers[0].livenessProbe.initialDelaySeconds
value: 30
- equal:
path: spec.template.spec.containers[0].livenessProbe.periodSeconds
value: 10

- it: should configure readiness probe on /actuator/health port 8080
asserts:
- equal:
path: spec.template.spec.containers[0].readinessProbe.httpGet.path
value: /actuator/health
- equal:
path: spec.template.spec.containers[0].readinessProbe.httpGet.port
value: 8080
- equal:
path: spec.template.spec.containers[0].readinessProbe.initialDelaySeconds
value: 10
- equal:
path: spec.template.spec.containers[0].readinessProbe.periodSeconds
value: 5

- it: should set default resource requests
asserts:
- equal:
path: spec.template.spec.containers[0].resources.requests.cpu
value: 80m
- equal:
path: spec.template.spec.containers[0].resources.requests.memory
value: 150Mi

- it: should set default resource limits
asserts:
- equal:
path: spec.template.spec.containers[0].resources.limits.cpu
value: 800m
- equal:
path: spec.template.spec.containers[0].resources.limits.memory
value: 700Mi

- it: should use custom image when overridden
set:
image.app: myregistry/myapp:v2.0
asserts:
- equal:
path: spec.template.spec.containers[0].image
value: "myregistry/myapp:v2.0"

- it: should use custom resource limits when overridden
set:
app_deployment.cpu_req: 100m
app_deployment.cpu_limit: 1000m
app_deployment.mem_req: 256Mi
app_deployment.mem_limit: 1Gi
asserts:
- equal:
path: spec.template.spec.containers[0].resources.requests.cpu
value: 100m
- equal:
path: spec.template.spec.containers[0].resources.requests.memory
value: 256Mi
- equal:
path: spec.template.spec.containers[0].resources.limits.cpu
value: 1000m
- equal:
path: spec.template.spec.containers[0].resources.limits.memory
value: 1Gi

- it: should use custom deployment name when overridden
set:
app_deployment.name: my-bankapp
asserts:
- equal:
path: metadata.name
value: my-bankapp
- equal:
path: metadata.labels.app
value: my-bankapp
- equal:
path: spec.selector.matchLabels.app
value: my-bankapp
- equal:
path: spec.template.metadata.labels.app
value: my-bankapp
Loading