Skip to content

Commit 767e140

Browse files
committed
Add tests for ingress and service patch
1 parent ed2aed0 commit 767e140

15 files changed

Lines changed: 187 additions & 19 deletions

src/test/kotlin/eu/openanalytics/shinyproxyoperator/MainIntegrationTest.kt

Lines changed: 80 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ class MainIntegrationTest : IntegrationTestBase() {
210210

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

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

1095-
// check replicaset
1095+
// check replicaset
10961096
spTestInstance.assertReplicaSetIsCorrect(sp)
10971097

10981098
// check service
@@ -1134,5 +1134,82 @@ class MainIntegrationTest : IntegrationTestBase() {
11341134
job.cancel()
11351135
}
11361136

1137+
@Test
1138+
fun `ingress patch`() =
1139+
setup(Mode.NAMESPACED) { namespace, shinyProxyClient, namespacedClient, _, operator, reconcileListener, _ ->
1140+
// 1. create a SP instance
1141+
val spTestInstance = ShinyProxyTestInstance(
1142+
namespace,
1143+
namespacedClient,
1144+
shinyProxyClient,
1145+
"simple_config_with_ingress_patches.yaml",
1146+
reconcileListener
1147+
)
1148+
spTestInstance.create()
1149+
1150+
val (resourceRetriever, shinyProxyLister) = operator.prepare()
1151+
// 2. start the operator and let it do it's work
1152+
val job = GlobalScope.launch {
1153+
operator.run(resourceRetriever, shinyProxyLister)
1154+
}
1155+
1156+
// 3. wait until instance is created
1157+
spTestInstance.waitForOneReconcile()
1158+
1159+
// 4. assert correctness
1160+
spTestInstance.assertInstanceIsCorrect()
1161+
val sp = spTestInstance.retrieveInstance()
1162+
1163+
val allIngresses = namespacedClient.network().v1().ingresses().list().items
1164+
assertEquals(1, allIngresses.size)
1165+
val ingress = allIngresses.firstOrNull { it.metadata.name == "sp-${sp.metadata.name}-ing".take(63) }
1166+
assertNotNull(ingress)
1167+
1168+
assertEquals(mapOf(
1169+
"nginx.ingress.kubernetes.io/proxy-buffer-size" to "128k",
1170+
"nginx.ingress.kubernetes.io/ssl-redirect" to "true",
1171+
"nginx.ingress.kubernetes.io/proxy-body-size" to "300m"
1172+
), ingress.metadata.annotations)
1173+
1174+
job.cancel()
1175+
}
1176+
1177+
@Test
1178+
fun `service patch`() =
1179+
setup(Mode.NAMESPACED) { namespace, shinyProxyClient, namespacedClient, _, operator, reconcileListener, _ ->
1180+
// 1. create a SP instance
1181+
val spTestInstance = ShinyProxyTestInstance(
1182+
namespace,
1183+
namespacedClient,
1184+
shinyProxyClient,
1185+
"simple_config_with_service_patches.yaml",
1186+
reconcileListener
1187+
)
1188+
spTestInstance.create()
1189+
1190+
val (resourceRetriever, shinyProxyLister) = operator.prepare()
1191+
// 2. start the operator and let it do it's work
1192+
val job = GlobalScope.launch {
1193+
operator.run(resourceRetriever, shinyProxyLister)
1194+
}
1195+
1196+
// 3. wait until instance is created
1197+
spTestInstance.waitForOneReconcile()
1198+
1199+
// 4. assert correctness
1200+
spTestInstance.assertInstanceIsCorrect()
1201+
val sp = spTestInstance.retrieveInstance()
1202+
1203+
val services = namespacedClient.inNamespace(namespace).services().list().items
1204+
assertEquals(1, services.size)
1205+
val service = services.firstOrNull { it.metadata.name == "sp-${sp.metadata.name}-svc".take(63) }
1206+
assertNotNull(service)
1207+
1208+
assertEquals(mapOf(
1209+
"my-service-ingress-patch" to "abc"
1210+
), service.metadata.annotations)
1211+
1212+
job.cancel()
1213+
}
11371214

11381215
}

src/test/kotlin/eu/openanalytics/shinyproxyoperator/helpers/IntegrationTestBase.kt

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import eu.openanalytics.shinyproxyoperator.ShinyProxyClient
2626
import eu.openanalytics.shinyproxyoperator.components.LabelFactory
2727
import eu.openanalytics.shinyproxyoperator.crd.ShinyProxy
2828
import eu.openanalytics.shinyproxyoperator.createKubernetesClient
29+
import eu.openanalytics.shinyproxyoperator.logger
2930
import io.fabric8.kubernetes.api.model.NamespaceBuilder
3031
import io.fabric8.kubernetes.api.model.PodList
3132
import io.fabric8.kubernetes.client.KubernetesClient
@@ -184,15 +185,22 @@ abstract class IntegrationTestBase {
184185
val oldNumApps = getPodsForInstance(instance.hash)?.items?.filter { it.status.phase.equals("Running") }?.size ?: 0
185186
val serviceName = "sp-${shinyProxy.metadata.name}-svc".take(63)
186187
stableClient.run().inNamespace(shinyProxy.metadata.namespace)
187-
.withRunConfig(RunConfigBuilder()
188-
.withName("itest-curl-helper")
189-
.withImage("curlimages/curl")
190-
.withArgs("-X", "POST", "-u", "demo:demo", "${serviceName}/api/proxy/01_hello")
191-
.withRestartPolicy("Never")
192-
.build())
188+
.withNewRunConfig()
189+
.withName("itest-curl-helper")
190+
.withImage("curlimages/curl")
191+
.withArgs("-X", "POST", "-u", "demo:demo", "${serviceName}/api/proxy/01_hello")
192+
.withRestartPolicy("Never")
193193
.done()
194+
delay(5_000)
194195
withTimeout(60_000) {
195196
while (true) {
197+
try {
198+
logger.info { "Pod: ${stableClient.kubernetesSerialization.asJson(stableClient.pods().inNamespace(shinyProxy.metadata.namespace).withName("itest-curl-helper").get())}" }
199+
logger.info { "Pod: ${stableClient.pods().inNamespace(shinyProxy.metadata.namespace).withName("itest-curl-helper").log}" }
200+
} catch (e: Throwable) {
201+
logger. info { e }
202+
}
203+
196204
val newNumApps = getPodsForInstance(instance.hash)?.items?.filter { it.status.phase.equals("Running") }?.size ?: continue
197205
if (newNumApps > oldNumApps) {
198206
break

src/test/resources/configs/additional_fqdns.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ spec:
66
fqdn: itest.local
77
additionalFqdns:
88
- itest2.locals
9-
image: openanalytics/shinyproxy:2.6.1
9+
image: openanalytics/shinyproxy-snapshot:3.1.0-SNAPSHOT-20240219.093646
1010
proxy:
1111
title: Open Analytics Shiny Proxy
1212
logoUrl: http://www.openanalytics.eu/sites/www.openanalytics.eu/themes/oa/logo.png

src/test/resources/configs/affinity_required.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ metadata:
55
spec:
66
antiAffinityRequired: true
77
fqdn: itest.local
8-
image: openanalytics/shinyproxy:2.6.1
8+
image: openanalytics/shinyproxy-snapshot:3.1.0-SNAPSHOT-20240219.093646
99
proxy:
1010
title: Open Analytics Shiny Proxy
1111
logoUrl: http://www.openanalytics.eu/sites/www.openanalytics.eu/themes/oa/logo.png

src/test/resources/configs/affinity_topologykey.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ metadata:
55
spec:
66
antiAffinityTopologyKey: example.com/custom-topology-key
77
fqdn: itest.local
8-
image: openanalytics/shinyproxy:2.6.1
8+
image: openanalytics/shinyproxy-snapshot:3.1.0-SNAPSHOT-20240219.093646
99
proxy:
1010
title: Open Analytics Shiny Proxy
1111
logoUrl: http://www.openanalytics.eu/sites/www.openanalytics.eu/themes/oa/logo.png

src/test/resources/configs/serviceaccount.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ rules:
77
- apiGroups: [ "" ]
88
resources: [ "pods" ]
99
verbs: [ "get", "list", "watch", "create", "update", "patch", "delete" ]
10+
- apiGroups: [ "" ]
11+
resources: [ "services" ]
12+
verbs: [ "get", "list", "watch", "create", "update", "patch", "delete" ]
1013
---
1114
kind: RoleBinding
1215
apiVersion: rbac.authorization.k8s.io/v1

src/test/resources/configs/simple_config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ metadata:
44
name: example-shinyproxy
55
spec:
66
fqdn: itest.local
7-
image: openanalytics/shinyproxy:2.6.1
7+
image: openanalytics/shinyproxy-snapshot:3.1.0-SNAPSHOT-20240219.093646
88
proxy:
99
title: Open Analytics Shiny Proxy
1010
logoUrl: http://www.openanalytics.eu/sites/www.openanalytics.eu/themes/oa/logo.png

src/test/resources/configs/simple_config_clustered.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ metadata:
44
name: example-shinyproxy
55
spec:
66
fqdn: itest2.local
7-
image: openanalytics/shinyproxy:2.6.1
7+
image: openanalytics/shinyproxy-snapshot:3.1.0-SNAPSHOT-20240219.093646
88
proxy:
99
title: Open Analytics Shiny Proxy
1010
logoUrl: http://www.openanalytics.eu/sites/www.openanalytics.eu/themes/oa/logo.png

src/test/resources/configs/simple_config_multiple_namespaces.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ metadata:
44
name: example-shinyproxy
55
spec:
66
fqdn: itest.local
7-
image: openanalytics/shinyproxy:2.6.1
7+
image: openanalytics/shinyproxy-snapshot:3.1.0-SNAPSHOT-20240219.093646
88
proxy:
99
title: Open Analytics Shiny Proxy
1010
logoUrl: http://www.openanalytics.eu/sites/www.openanalytics.eu/themes/oa/logo.png

src/test/resources/configs/simple_config_subpath1.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ metadata:
44
name: example-shinyproxy
55
spec:
66
fqdn: itest.local
7-
image: openanalytics/shinyproxy:2.6.1
7+
image: openanalytics/shinyproxy-snapshot:3.1.0-SNAPSHOT-20240219.093646
88
proxy:
99
title: Open Analytics Shiny Proxy
1010
logoUrl: http://www.openanalytics.eu/sites/www.openanalytics.eu/themes/oa/logo.png

0 commit comments

Comments
 (0)