Skip to content

Commit 6987cd0

Browse files
gl-johnsonGitHub Enterprise
authored andcommitted
Merge pull request #7 from Conjur-Enterprise/pr186-fork
CNJR-11606: Added unit tests and the ability to define container resources
2 parents da12133 + 4a6fb04 commit 6987cd0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1565
-35
lines changed

.devops/gitleaks.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
config:
2+
exclusions:
3+
- "conjur-oss/tests"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ values-private.yaml
1010

1111
# Example temp files
1212
examples/kubernetes-in-docker/temp*
13+
.debug/

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
66

77
## Unreleased
88

9+
## [2.1.1] - 2025-11-21
10+
11+
### Added
12+
13+
- Support resource limits on containers
14+
- Unit tests for the Helm chart, using [Helm plugin: Unittest](https://github.com/helm-unittest/helm-unittest)
15+
916
## [2.1.0] - 2025-08-28
1017

1118
### Added

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ if you would like to contribute.
3535

3636
## Testing
3737

38+
There is a complete set of unit tests for the chart which are executed using [Helm unittest plugin](https://github.com/helm-unittest/helm-unittest/tree/main) from this root folder. For example:
39+
40+
```bash
41+
helm unittest conjur-oss -v conjur-oss/unittest-values.yaml
42+
```
43+
44+
As snapshots of the default rendered templates are used for many of the tests, if you make template changes that affect the defaults you will need to update the snapshots like so:
45+
46+
```bash
47+
helm unittest conjur-oss -u -v conjur-oss/unittest-values.yaml
48+
```
49+
3850
This repository includes basic smoke testing on GKE. The Conjur OSS Helm Chart is also exercised more thoroughly by the [cyberark/conjur-authn-k8s-client](https://github.com/cyberark/conjur-authn-k8s-client) project, which clones the OSS Helm Chart repo and uses it while testing across several versions of Kubernetes and OpenShift.
3951

4052
## License

ci/Dockerfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ RUN apt-get update && \
1717
wget && \
1818
distro="$(. /etc/os-release; echo $ID)" && \
1919
release="$(lsb_release -cs)" && \
20-
curl -fsSL "https://download.docker.com/linux/$distro/gpg" > /tmp/docker_repo_key && \
20+
wget -q -O /tmp/docker_repo_key "https://download.docker.com/linux/$distro/gpg" && \
2121
apt-key add /tmp/docker_repo_key && \
2222
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/$distro $release stable" && \
2323
apt-get update && \
@@ -32,6 +32,9 @@ RUN wget https://get.helm.sh/helm-v${HELM_VERSION}-linux-amd64.tar.gz && \
3232
rm helm-v${HELM_VERSION}-linux-amd64.tar.gz && \
3333
rm -rf linux-amd64
3434

35+
# Install Helm unittest plugin
36+
RUN helm plugin install https://github.com/helm-unittest/helm-unittest.git
37+
3538
# Install Kubernetes client
36-
RUN wget -O /usr/local/bin/kubectl https://storage.googleapis.com/kubernetes-release/release/v${KUBECTL_VERSION}/bin/linux/amd64/kubectl && \
39+
RUN wget -O /usr/local/bin/kubectl https://dl.k8s.io/release/${KUBECTL_VERSION}/bin/linux/amd64/kubectl && \
3740
chmod +x /usr/local/bin/kubectl

ci/jenkins_build.sh

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ source ../utils.sh
1717
# HELM_TEST_LOGGING: Set to true to enable Helm test log collection.
1818
# Defaults to false.
1919
# HELM_VERSION: Helm client version to use for the test.
20-
# Defaults to '3.1.3'.
20+
# Defaults to '3.19.0'.
2121
# KUBECTL_VERSION: Kubectl client version to use for the test.
22-
# Defaults to '1.16.9'.
22+
# Defaults to latest stable release.
2323
# SKIP_GCLOUD_LOGIN: If set to 'true', then skip Gcloud authentication.
2424
# This is useful for local testing whereby you've
2525
# already authenticated with GCP and/or have 'kubectl'
@@ -28,12 +28,13 @@ source ../utils.sh
2828
# authn-k8s, defaults to authn-k8s
2929

3030
test_id="$(random_string)"
31+
kubectl_curr_ver=$(curl -L -s https://dl.k8s.io/release/stable.txt)
3132

3233
export CONJUR_NAMESPACE="${CONJUR_NAMESPACE:-conjur-oss-test-$test_id}"
3334
export HELM_INSTALL_TIMEOUT="${HELM_INSTALL_TIMEOUT:-180}"
3435
export HELM_TEST_LOGGING="${HELM_TEST_LOGGING:-true}"
35-
export HELM_VERSION="${HELM_VERSION:-3.1.3}"
36-
export KUBECTL_VERSION="${KUBECTL_VERSION:-1.16.9}"
36+
export HELM_VERSION="${HELM_VERSION:-3.19.0}"
37+
export KUBECTL_VERSION="${KUBECTL_VERSION:-$kubectl_curr_ver}"
3738
export RELEASE_NAME="$CONJUR_NAMESPACE"
3839
export SKIP_GCLOUD_LOGIN="${SKIP_GCLOUD_LOGIN:-false}"
3940
export AUTHN_STRATEGY="${AUTHN_STRATEGY:-authn-k8s}"
@@ -130,8 +131,15 @@ else
130131
helm init --upgrade
131132
fi
132133

133-
announce "Deploying and testing Conjur OSS"
134134
cd ..
135+
announce "Running Helm unit tests..."
136+
helm unittest conjur-oss -v conjur-oss/unittest-values.yaml
137+
if [ $? -ne 0 ]; then
138+
announce "Helm unit tests failed"
139+
exit 1
140+
fi
141+
142+
announce "Deploying and testing Conjur OSS"
135143
trap delete_namespace EXIT
136144
if ! ./test.sh; then
137145
announce " FAILED"

conjur-oss/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,15 +385,18 @@ The following table lists the configurable parameters of the Conjur Open Source
385385
|`nginx.image.repository`|NGINX Docker image repository|`"nginx"`|
386386
|`nginx.image.tag`|NGINX Docker image tag|`"1.15"`|
387387
|`nginx.image.pullPolicy`|Pull policy for NGINX Docker image|`"IfNotPresent"`|
388+
|`nginx.resources`|Resource requests and limits for nginx pod|`{}`|
388389
|`openshift.enabled`|Indicates that Conjur is to be installed on an OpenShift platform|`false`|
389390
|`postgres.image.pullPolicy`|Pull policy for postgres Docker image|`"IfNotPresent"`|
390391
|`postgres.image.repository`|postgres Docker image repository|`"postgres"`|
391392
|`postgres.image.tag`|postgres Docker image tag|`"10.16"`|
392393
|`postgres.persistentVolume.create`|Create a peristent volume to back the PostgreSQL data|`true`|
393394
|`postgres.persistentVolume.size`|Size of persistent volume to be created for PostgreSQL|`"8Gi"`|
394395
|`postgres.persistentVolume.storageClass`|Storage class to be used for PostgreSQL persistent volume claim|`nil`|
396+
|`postgres.resources`|Resource requests and limits for postgres pod|`{}`|
395397
|`rbac.create`|Controls whether or not RBAC resources are created. This setting is deprecated and will be replaced in the next major release with two separate settings: `rbac.createClusterRole` (defaulting to true) and `rbac.createClusterRoleBinding` (defaulting to false), and the creation of RoleBindings will be recommended over relying on this ClusterRoleBinding.|`true`|
396398
|`replicaCount`|Number of desired Conjur pods|`1`|
399+
|`resources`|Resource requests and limits for conjur pod|`{}`|
397400
|`service.external.annotations`|Annotations for the external LoadBalancer|`[service.beta.kubernetes.io/aws-load-balancer-backend-protocol: tcp]`|
398401
|`service.external.enabled`|Expose service to the Internet|`true`|
399402
|`service.external.port`|Conjur external service port|`443`|

conjur-oss/templates/NOTES.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,16 @@
7575

7676
Start a container with Conjur CLI and authenticate with the new user:
7777

78-
docker run --rm -it --entrypoint bash cyberark/conjur-cli:8
79-
# Or if using MiniKube, use the following command from the host:
80-
# docker run --rm -it --network host --entrypoint bash cyberark/conjur-cli:8
78+
docker run --rm -it --entrypoint bash cyberark/conjur-cli:9
79+
# Or if using MiniKube/KinD/Docker Desktop, use the following command from the host:
80+
# docker run --rm -it --add-host conjur.myorg.com:host-gateway --entrypoint bash cyberark/conjur-cli:9
8181

8282
# Here ENDPOINT is the DNS name https endpoint for your Conjur service.
8383
# NOTE: Ensure that the target endpoint matches at least one of the expected server
8484
# SSL certificate names otherwise SSL verification will fail and you will not
8585
# be able to log in.
8686
# NOTE: Also ensure that the URL does not contain a slash (`/`) at the end of the URL
87-
conjur init -u <ENDPOINT> -a {{ .Values.account.name | quote }} --self-signed
87+
conjur init oss -u <ENDPOINT> -a {{ .Values.account.name | quote }} --self-signed
8888

8989
# API key here is the key that creation of the account provided you in step #2
9090
conjur login -i admin -p <API_KEY>

conjur-oss/templates/_helpers.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ If release name contains chart name it will be used as a full name.
2828
Create chart name and version as used by the chart label.
2929
*/}}
3030
{{- define "conjur-oss.chart" -}}
31-
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
31+
{{- printf "%s-%s" .Chart.Name (.Values.unittestChartVersion | default .Chart.Version) | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
3232
{{- end -}}
3333

3434
{{/*

conjur-oss/templates/deployment.yaml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ spec:
104104
mountPath: /etc/nginx
105105
readOnly: true
106106
{{- end }}
107-
107+
{{- if .Values.nginx.resources }}
108+
resources: {{- toYaml .Values.nginx.resources | nindent 10 }}
109+
{{- end }}
108110
- name: {{ .Chart.Name }}
109111
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
110112
imagePullPolicy: {{ .Values.image.pullPolicy }}
@@ -173,9 +175,10 @@ spec:
173175
- name: {{ .Release.Name }}-authn-local-socket-volume
174176
mountPath: /run/authn-local
175177
readOnly: false
176-
{{- end }}
177-
resources:
178-
{{ toYaml .Values.resources | indent 12 }}
178+
{{- end }}
179+
{{- if .Values.resources }}
180+
resources: {{- toYaml .Values.resources | nindent 10 }}
181+
{{- end }}
179182
{{- if .Values.exportAPIkey.enabled }}
180183
- name: {{ .Release.Name }}-export-api-key
181184
image: "{{ .Values.exportAPIkey.image.repository }}:{{ .Values.exportAPIkey.image.tag }}"

0 commit comments

Comments
 (0)