Skip to content

Commit

Permalink
Merge pull request #107 from sclorg/nginx_shared_cluster
Browse files Browse the repository at this point in the history
Allows to test NginX Helm Chart on shared cluster.
  • Loading branch information
phracek authored Oct 29, 2024
2 parents fc9d592 + e29d1bb commit e8a0442
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 12 deletions.
4 changes: 2 additions & 2 deletions charts/centos/nginx-imagestreams/src/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ description: |-
annotations:
charts.openshift.io/name: CentOS Nginx HTTP server and a reverse proxy (nginx) (experimental)
apiVersion: v2
appVersion: 0.0.2
appVersion: 0.0.3
kubeVersion: '>=1.20.0'
name: nginx-imagestreams
tags: builder,nginx
sources:
- https://github.com/sclorg/helm-charts
version: 0.0.2
version: 0.0.3
9 changes: 9 additions & 0 deletions charts/redhat/nginx-template/src/templates/buildconfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,19 @@ metadata:
template: {{ .Values.name }}
name: {{ .Values.name }}
spec:
{{ if .Values.registry.enabled }}
output:
to:
kind: DockerImage
name: "{{ .Values.registry.name }}/{{ .Values.registry.namespace }}/{{ .Values.name }}:latest"
pushSecret:
name: {{ .Values.registry.push_secret }}
{{ else }}
output:
to:
kind: ImageStreamTag
name: {{ .Values.name }}:latest
{{ end }}
source:
contextDir: {{ .Values.context_dir }}
git:
Expand Down
6 changes: 6 additions & 0 deletions charts/redhat/nginx-template/src/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ metadata:
annotations:
description: Defines how to deploy the application server
template.alpha.openshift.io/wait-for-ready: "true"
{{ if not .Values.registry.enabled }}
image.openshift.io/triggers: |-
[
{
Expand All @@ -14,6 +15,7 @@ metadata:
"fieldPath": "spec.template.spec.containers[0].image"
}
]
{{ end }}
labels:
app: nginx-template
template: nginx-template
Expand All @@ -33,7 +35,11 @@ spec:
spec:
containers:
- env: []
{{ if .Values.registry.enabled }}
image: "{{ .Values.registry.name }}/{{ .Values.registry.namespace }}/{{ .Values.name }}:latest"
{{ else }}
image: " "
{{ end }}
livenessProbe:
httpGet:
path: /
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ spec:
#serviceAccount: {{ .Values.serviceAccount }}
containers:
- name: "nginx-connection-test"
image: "registry.redhat.io/ubi8/nginx-122:latest"
image: "registry.redhat.io/ubi9/nginx-122:latest"
imagePullPolicy: IfNotPresent
command:
- '/bin/bash'
Expand Down
20 changes: 20 additions & 0 deletions charts/redhat/nginx-template/src/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,26 @@
},
"expected_str": {
"type": "string"
},
"registry": {
"type": "object",
"properties": {
"enabled": {
"type": "boolean"
},
"name": {
"type": "string",
"description": "The name of registry that will be used for pushing built image."
},
"namespace": {
"type": "string",
"description": "The namespace of registry that will be used for pushing built image."
},
"push_secret": {
"type": "string",
"description": "The push secret to push image to registry."
}
}
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions charts/redhat/nginx-template/src/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@ nginx_version: 1.20-ubi8
source_repository_ref: master # TODO: must define a default value for .source_repository_ref
source_repository_url: https://github.com/sclorg/nginx-ex.git
expected_str: Welcome to your static nginx application on OpenShift
registry:
enabled: false
name: "quay.io"
namespace: ""
push_secret: ""
42 changes: 33 additions & 9 deletions tests/test_nginx_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,63 @@ def setup_method(self):
def teardown_method(self):
self.hc_api.delete_project()

def test_curl_connection(self):
@pytest.mark.parametrize(
"version",
[
"1.24-ubi9",
"1.24-ubi8",
"1.22-ubi9",
"1.22-ubi8",
"1.20-ubi9",
]
)
def test_curl_connection(self, version):
if self.hc_api.oc_api.shared_cluster:
pytest.skip("Do NOT test on shared cluster")
self.hc_api.package_name = "nginx-imagestreams"
assert self.hc_api.helm_package()
assert self.hc_api.helm_installation()
self.hc_api.package_name = "nginx-template"
assert self.hc_api.helm_package()
pod_name = f"nginx-ex-{version}".replace(".", "-")
assert self.hc_api.helm_installation(
values={
"nginx_version": "1.24-ubi8",
"namespace": self.hc_api.namespace
"nginx_version": version,
"namespace": self.hc_api.namespace,
"name": pod_name
}
)
expected_str = "Welcome to your static nginx application on OpenShift"
assert self.hc_api.is_s2i_pod_running(pod_name_prefix="nginx-example")
assert self.hc_api.is_s2i_pod_running(pod_name_prefix=pod_name)
assert self.hc_api.test_helm_curl_output(
route_name="nginx-example",
route_name=pod_name,
expected_str=expected_str
)

def test_helm_connection(self):
@pytest.mark.parametrize(
"version",
[
"1.24-ubi9",
"1.24-ubi8",
"1.22-ubi9",
"1.22-ubi8",
"1.20-ubi9",
]
)
def test_helm_connection(self, version):
self.hc_api.package_name = "nginx-imagestreams"
assert self.hc_api.helm_package()
assert self.hc_api.helm_installation()
self.hc_api.package_name = "nginx-template"
assert self.hc_api.helm_package()
pod_name = f"nginx-ex-{version}".replace(".", "-")
assert self.hc_api.helm_installation(
values={
"nginx_version": "1.24-ubi8",
"namespace": self.hc_api.namespace
"nginx_version": version,
"namespace": self.hc_api.namespace,
"name": pod_name
}
)
expected_str = "Welcome to your static nginx application on OpenShift"
assert self.hc_api.is_s2i_pod_running(pod_name_prefix="nginx-example")
assert self.hc_api.is_s2i_pod_running(pod_name_prefix=pod_name)
assert self.hc_api.test_helm_chart(expected_str=[expected_str])

0 comments on commit e8a0442

Please sign in to comment.