Skip to content

Commit

Permalink
Add tests for ingress and service patch
Browse files Browse the repository at this point in the history
  • Loading branch information
LEDfan committed Feb 19, 2024
1 parent 150f2a1 commit d15b58c
Show file tree
Hide file tree
Showing 3 changed files with 160 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class MainIntegrationTest : IntegrationTestBase() {

@Test
fun `sp in other namespaced should be ignored when using namespaced mode`() =
setup(Mode.NAMESPACED) { namespace, shinyProxyClient, namespacedClient, stableClient, operator, reconcileListener, _->
setup(Mode.NAMESPACED) { namespace, shinyProxyClient, namespacedClient, stableClient, operator, reconcileListener, _ ->
// 1. create a SP instance in other namespace
val spTestInstance = ShinyProxyTestInstance(
"itest-2",
Expand Down Expand Up @@ -494,7 +494,7 @@ class MainIntegrationTest : IntegrationTestBase() {

@Test
fun `configuration with subpath not ending in slash`() =
setup(Mode.NAMESPACED) { namespace, shinyProxyClient, namespacedClient, stableClient, operator, reconcileListener , _->
setup(Mode.NAMESPACED) { namespace, shinyProxyClient, namespacedClient, stableClient, operator, reconcileListener, _ ->
// 1. create a SP instance
val spTestInstance = ShinyProxyTestInstance(
namespace,
Expand Down Expand Up @@ -1092,7 +1092,7 @@ class MainIntegrationTest : IntegrationTestBase() {
// check configmap
spTestInstance.assertConfigMapIsCorrect(sp)

// check replicaset
// check replicaset
spTestInstance.assertReplicaSetIsCorrect(sp)

// check service
Expand Down Expand Up @@ -1134,5 +1134,82 @@ class MainIntegrationTest : IntegrationTestBase() {
job.cancel()
}

@Test
fun `ingress patch`() =
setup(Mode.NAMESPACED) { namespace, shinyProxyClient, namespacedClient, _, operator, reconcileListener, _ ->
// 1. create a SP instance
val spTestInstance = ShinyProxyTestInstance(
namespace,
namespacedClient,
shinyProxyClient,
"simple_config_with_ingress_patches.yaml",
reconcileListener
)
spTestInstance.create()

val (resourceRetriever, shinyProxyLister) = operator.prepare()
// 2. start the operator and let it do it's work
val job = GlobalScope.launch {
operator.run(resourceRetriever, shinyProxyLister)
}

// 3. wait until instance is created
spTestInstance.waitForOneReconcile()

// 4. assert correctness
spTestInstance.assertInstanceIsCorrect()
val sp = spTestInstance.retrieveInstance()

val allIngresses = namespacedClient.network().v1().ingresses().list().items
assertEquals(1, allIngresses.size)
val ingress = allIngresses.firstOrNull { it.metadata.name == "sp-${sp.metadata.name}-ing".take(63) }
assertNotNull(ingress)

assertEquals(mapOf(
"nginx.ingress.kubernetes.io/proxy-buffer-size" to "128k",
"nginx.ingress.kubernetes.io/ssl-redirect" to "true",
"nginx.ingress.kubernetes.io/proxy-body-size" to "300m"
), ingress.metadata.annotations)

job.cancel()
}

@Test
fun `service patch`() =
setup(Mode.NAMESPACED) { namespace, shinyProxyClient, namespacedClient, _, operator, reconcileListener, _ ->
// 1. create a SP instance
val spTestInstance = ShinyProxyTestInstance(
namespace,
namespacedClient,
shinyProxyClient,
"simple_config_with_service_patches.yaml",
reconcileListener
)
spTestInstance.create()

val (resourceRetriever, shinyProxyLister) = operator.prepare()
// 2. start the operator and let it do it's work
val job = GlobalScope.launch {
operator.run(resourceRetriever, shinyProxyLister)
}

// 3. wait until instance is created
spTestInstance.waitForOneReconcile()

// 4. assert correctness
spTestInstance.assertInstanceIsCorrect()
val sp = spTestInstance.retrieveInstance()

val services = namespacedClient.inNamespace(namespace).services().list().items
assertEquals(1, services.size)
val service = services.firstOrNull { it.metadata.name == "sp-${sp.metadata.name}-svc".take(63) }
assertNotNull(service)

assertEquals(mapOf(
"my-service-ingress-patch" to "abc"
), service.metadata.annotations)

job.cancel()
}

}
41 changes: 41 additions & 0 deletions src/test/resources/configs/simple_config_with_ingress_patches.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
apiVersion: openanalytics.eu/v1
kind: ShinyProxy
metadata:
name: example-shinyproxy
spec:
fqdn: itest.local
image: openanalytics/shinyproxy:2.6.1
proxy:
title: Open Analytics Shiny Proxy
logoUrl: http://www.openanalytics.eu/sites/www.openanalytics.eu/themes/oa/logo.png
landingPage: /
heartbeatRate: 10000
heartbeatTimeout: 60000
port: 8080
authentication: simple
containerBackend: kubernetes
kubernetes:
namespace: itest
users:
- name: demo
password: demo
groups: scientists
- name: demo2
password: demo2
groups: mathematicians
specs:
- id: 01_hello
displayName: Hello Application
description: Application which demonstrates the basics of a Shiny app
containerCmd: [ "R", "-e", "shinyproxy::run_01_hello()" ]
containerImage: openanalytics/shinyproxy-demo
- id: 06_tabsets
container-cmd: [ "R", "-e", "shinyproxy::run_06_tabsets()" ]
container-image: openanalytics/shinyproxy-demo
kubernetesIngressPatches: |
- op: add
path: /metadata/annotations
value:
nginx.ingress.kubernetes.io/proxy-buffer-size: "128k"
nginx.ingress.kubernetes.io/ssl-redirect: "true"
nginx.ingress.kubernetes.io/proxy-body-size: 300m
39 changes: 39 additions & 0 deletions src/test/resources/configs/simple_config_with_service_patches.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
apiVersion: openanalytics.eu/v1
kind: ShinyProxy
metadata:
name: example-shinyproxy
spec:
fqdn: itest.local
image: openanalytics/shinyproxy:2.6.1
proxy:
title: Open Analytics Shiny Proxy
logoUrl: http://www.openanalytics.eu/sites/www.openanalytics.eu/themes/oa/logo.png
landingPage: /
heartbeatRate: 10000
heartbeatTimeout: 60000
port: 8080
authentication: simple
containerBackend: kubernetes
kubernetes:
namespace: itest
users:
- name: demo
password: demo
groups: scientists
- name: demo2
password: demo2
groups: mathematicians
specs:
- id: 01_hello
displayName: Hello Application
description: Application which demonstrates the basics of a Shiny app
containerCmd: [ "R", "-e", "shinyproxy::run_01_hello()" ]
containerImage: openanalytics/shinyproxy-demo
- id: 06_tabsets
container-cmd: [ "R", "-e", "shinyproxy::run_06_tabsets()" ]
container-image: openanalytics/shinyproxy-demo
kubernetesServicePatches: |
- op: add
path: /metadata/annotations
value:
my-service-ingress-patch: "abc"

0 comments on commit d15b58c

Please sign in to comment.