Skip to content

Commit 4d95d48

Browse files
committed
Skipper: setRequestHeader with instance values
1 parent a70cb6f commit 4d95d48

3 files changed

Lines changed: 61 additions & 25 deletions

File tree

src/main/kotlin/eu/openanalytics/shinyproxyoperator/ingress/skipper/IngressFactory.kt

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,28 @@ class IngressFactory(private val kubeClient: KubernetesClient) {
5555

5656
val annotations = if (isLatest) {
5757
mapOf(
58-
"kubernetes.io/ingress.class" to "skipper",
59-
"zalando.org/skipper-predicate" to "True()",
60-
"zalando.org/skipper-filter" to """appendResponseHeader("Set-Cookie", "sp-instance=$hashOfSpec; $security Path=$cookiePath") -> appendResponseHeader("Set-Cookie", "sp-latest-instance=${shinyProxy.hashOfCurrentSpec}; $security Path=$cookiePath")"""
58+
"kubernetes.io/ingress.class" to "skipper",
59+
"zalando.org/skipper-predicate" to "True()",
60+
"zalando.org/skipper-filter" to
61+
"""setRequestHeader("X-ShinyProxy-Instance", "$hashOfSpec")""" +
62+
""" -> """ +
63+
"""setRequestHeader("X-ShinyProxy-Latest-Instance", "${shinyProxy.hashOfCurrentSpec}")""" +
64+
""" -> """ +
65+
"""appendResponseHeader("Set-Cookie", "sp-instance=$hashOfSpec; $security Path=$cookiePath")""" +
66+
""" -> """ +
67+
"""appendResponseHeader("Set-Cookie", "sp-latest-instance=${shinyProxy.hashOfCurrentSpec}; $security Path=$cookiePath")"""
6168

6269
)
6370
} else {
6471
mapOf(
65-
"kubernetes.io/ingress.class" to "skipper",
66-
"zalando.org/skipper-predicate" to """True() && Cookie("sp-instance", "$hashOfSpec")""",
67-
"zalando.org/skipper-filter" to """appendResponseHeader("Set-Cookie", "sp-latest-instance=${shinyProxy.hashOfCurrentSpec}; $security Path=$cookiePath")"""
72+
"kubernetes.io/ingress.class" to "skipper",
73+
"zalando.org/skipper-predicate" to """True() && Cookie("sp-instance", "$hashOfSpec")""",
74+
"zalando.org/skipper-filter" to
75+
"""setRequestHeader("X-ShinyProxy-Instance", "$hashOfSpec")""" +
76+
""" -> """ +
77+
"""setRequestHeader("X-ShinyProxy-Latest-Instance", "${shinyProxy.hashOfCurrentSpec}")""" +
78+
""" -> """ +
79+
"""appendResponseHeader("Set-Cookie", "sp-latest-instance=${shinyProxy.hashOfCurrentSpec}; $security Path=$cookiePath")"""
6880
)
6981
}
7082

@@ -96,7 +108,8 @@ class IngressFactory(private val kubeClient: KubernetesClient) {
96108
.build()
97109
//@formatter:on
98110

99-
val createdIngress = kubeClient.network().ingress().inNamespace(shinyProxy.metadata.namespace).createOrReplace(ingressDefinition)
111+
val createdIngress =
112+
kubeClient.network().ingress().inNamespace(shinyProxy.metadata.namespace).createOrReplace(ingressDefinition)
100113
logger.debug { "${shinyProxy.logPrefix(shinyProxyInstance)} [Component/Ingress] Created ${createdIngress.metadata.name} [latest=$isLatest]" }
101114
}
102115

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

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -684,13 +684,18 @@ class MainIntegrationTest : IntegrationTestBase() {
684684
ingress.metadata.ownerReferences[0].name
685685
)
686686

687-
assertEquals(
688-
mapOf(
689-
"kubernetes.io/ingress.class" to "skipper",
690-
"zalando.org/skipper-predicate" to "True()",
691-
"zalando.org/skipper-filter" to """appendResponseHeader("Set-Cookie", "sp-instance=${sp.hashOfCurrentSpec}; Secure; Path=/sub-path/") -> appendResponseHeader("Set-Cookie", "sp-latest-instance=${sp.hashOfCurrentSpec}; Secure; Path=/sub-path/")"""
692-
), ingress.metadata.annotations
693-
)
687+
assertEquals(mapOf(
688+
"kubernetes.io/ingress.class" to "skipper",
689+
"zalando.org/skipper-predicate" to "True()",
690+
"zalando.org/skipper-filter" to
691+
"""setRequestHeader("X-ShinyProxy-Instance", "${sp.hashOfCurrentSpec}")""" +
692+
""" -> """ +
693+
"""setRequestHeader("X-ShinyProxy-Latest-Instance", "${sp.hashOfCurrentSpec}")""" +
694+
""" -> """ +
695+
"""appendResponseHeader("Set-Cookie", "sp-instance=${sp.hashOfCurrentSpec}; Secure; Path=/sub-path/")""" +
696+
""" -> """ +
697+
"""appendResponseHeader("Set-Cookie", "sp-latest-instance=${sp.hashOfCurrentSpec}; Secure; Path=/sub-path/")"""
698+
), ingress.metadata.annotations)
694699

695700
assertEquals(1, ingress.spec.rules.size)
696701
val rule = ingress.spec.rules[0]
@@ -752,13 +757,18 @@ class MainIntegrationTest : IntegrationTestBase() {
752757
ingress.metadata.ownerReferences[0].name
753758
)
754759

755-
assertEquals(
756-
mapOf(
760+
assertEquals(mapOf(
757761
"kubernetes.io/ingress.class" to "skipper",
758762
"zalando.org/skipper-predicate" to "True()",
759-
"zalando.org/skipper-filter" to """appendResponseHeader("Set-Cookie", "sp-instance=${sp.hashOfCurrentSpec}; Path=/") -> appendResponseHeader("Set-Cookie", "sp-latest-instance=${sp.hashOfCurrentSpec}; Path=/")"""
760-
), ingress.metadata.annotations
761-
)
763+
"zalando.org/skipper-filter" to
764+
"""setRequestHeader("X-ShinyProxy-Instance", "${sp.hashOfCurrentSpec}")""" +
765+
""" -> """ +
766+
"""setRequestHeader("X-ShinyProxy-Latest-Instance", "${sp.hashOfCurrentSpec}")""" +
767+
""" -> """ +
768+
"""appendResponseHeader("Set-Cookie", "sp-instance=${sp.hashOfCurrentSpec}; Path=/")""" +
769+
""" -> """ +
770+
"""appendResponseHeader("Set-Cookie", "sp-latest-instance=${sp.hashOfCurrentSpec}; Path=/")"""
771+
), ingress.metadata.annotations)
762772

763773
job.cancel()
764774
}

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

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,28 @@ class ShinyProxyTestInstance(private val namespace: String,
101101

102102
if (isLatest) {
103103
assertEquals(mapOf(
104-
"kubernetes.io/ingress.class" to "skipper",
105-
"zalando.org/skipper-predicate" to "True()",
106-
"zalando.org/skipper-filter" to """appendResponseHeader("Set-Cookie", "sp-instance=${sp.hashOfCurrentSpec}; Secure; Path=/") -> appendResponseHeader("Set-Cookie", "sp-latest-instance=${sp.hashOfCurrentSpec}; Secure; Path=/")"""
104+
"kubernetes.io/ingress.class" to "skipper",
105+
"zalando.org/skipper-predicate" to "True()",
106+
"zalando.org/skipper-filter" to
107+
"""setRequestHeader("X-ShinyProxy-Instance", "${sp.hashOfCurrentSpec}")""" +
108+
""" -> """ +
109+
"""setRequestHeader("X-ShinyProxy-Latest-Instance", "${sp.hashOfCurrentSpec}")""" +
110+
""" -> """ +
111+
"""appendResponseHeader("Set-Cookie", "sp-instance=${sp.hashOfCurrentSpec}; Secure; Path=/")""" +
112+
""" -> """ +
113+
"""appendResponseHeader("Set-Cookie", "sp-latest-instance=${sp.hashOfCurrentSpec}; Secure; Path=/")"""
107114
), ingress.metadata.annotations)
108115
} else {
109116
assertEquals(mapOf(
110-
"kubernetes.io/ingress.class" to "skipper",
111-
"zalando.org/skipper-predicate" to """True() && Cookie("sp-instance", "$hash")""",
112-
"zalando.org/skipper-filter" to """appendResponseHeader("Set-Cookie", "sp-latest-instance=${sp.hashOfCurrentSpec}; Secure; Path=/")"""
117+
"kubernetes.io/ingress.class" to "skipper",
118+
"zalando.org/skipper-predicate" to """True() && Cookie("sp-instance", "$hash")""",
119+
"zalando.org/skipper-filter" to
120+
"""setRequestHeader("X-ShinyProxy-Instance", "$hash")""" +
121+
""" -> """ +
122+
"""setRequestHeader("X-ShinyProxy-Latest-Instance", "${sp.hashOfCurrentSpec}")""" +
123+
""" -> """ +
124+
"""appendResponseHeader("Set-Cookie", "sp-latest-instance=${sp.hashOfCurrentSpec}; Secure; Path=/")"""
125+
113126
), ingress.metadata.annotations)
114127
}
115128

0 commit comments

Comments
 (0)