Skip to content

Commit 61c02f1

Browse files
committed
Ref #27576: rebase with k8s 1.22
1 parent bca1b4b commit 61c02f1

7 files changed

Lines changed: 17 additions & 32 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>eu.openanalytics</groupId>
77
<artifactId>shinyproxy-operator</artifactId>
8-
<version>1.1.0</version>
8+
<version>1.2.0-SNAPSHOT</version>
99

1010
<organization>
1111
<name>Open Analytics NV</name>

src/main/kotlin/eu/openanalytics/shinyproxyoperator/Operator.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,12 @@ class Operator(client: NamespacedKubernetesClient? = null,
150150
replicaSetListener = ResourceListener(sendChannel, this.client.inAnyNamespace().apps().replicaSets())
151151
serviceListener = ResourceListener(sendChannel, this.client.inAnyNamespace().services())
152152
configMapListener = ResourceListener(sendChannel, this.client.inAnyNamespace().configMaps())
153-
ingressController = IngressController(sendChannel, this.client.inAnyNamespace(), this.client.inAnyNamespace().network().ingress())
153+
ingressController = IngressController(sendChannel, this.client.inAnyNamespace(), this.client.inAnyNamespace().network().v1().ingresses())
154154
} else {
155155
replicaSetListener = ResourceListener(sendChannel, this.client.inNamespace(namespace).apps().replicaSets())
156156
serviceListener = ResourceListener(sendChannel, this.client.inNamespace(namespace).services())
157157
configMapListener = ResourceListener(sendChannel, this.client.inNamespace(namespace).configMaps())
158-
ingressController = IngressController(sendChannel, this.client.inNamespace(namespace), this.client.inNamespace(namespace).network().ingress())
158+
ingressController = IngressController(sendChannel, this.client.inNamespace(namespace), this.client.inNamespace(namespace).network().v1().ingresses())
159159
}
160160
}
161161

src/main/kotlin/eu/openanalytics/shinyproxyoperator/crd/ShinyProxy.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class ShinyProxy : CustomResource<JsonNode, ShinyProxyStatus>(), Namespaced {
131131
return@lazy path
132132
}
133133

134-
return@lazy ""
134+
return@lazy "/"
135135
}
136136

137137
@get:JsonIgnore

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

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class IngressFactory(private val kubeClient: KubernetesClient) {
6464
.withAnnotations<String, String>(routeAnnotations)
6565
.endMetadata()
6666
.withNewSpec()
67+
.withIngressClassName("skipper")
6768
.addNewRule()
6869
.withHost(shinyProxy.fqdn)
6970
.withNewHttp()
@@ -74,7 +75,7 @@ class IngressFactory(private val kubeClient: KubernetesClient) {
7475
.build()
7576
//@formatter:on
7677

77-
val createdIngress = kubeClient.network().ingress().inNamespace(shinyProxy.metadata.namespace).createOrReplace(ingressDefinition)
78+
val createdIngress = kubeClient.network().v1().ingresses().inNamespace(shinyProxy.metadata.namespace).createOrReplace(ingressDefinition)
7879
logger.debug { "${shinyProxy.logPrefix(shinyProxyInstance)} [Component/Ingress] Created ${createdIngress.metadata.name} [latest=$isLatest]" }
7980
}
8081

@@ -103,11 +104,6 @@ class IngressFactory(private val kubeClient: KubernetesClient) {
103104
"Secure;"
104105
}
105106

106-
val cookiePath = if (shinyProxy.subPath != "") {
107-
shinyProxy.subPath
108-
} else {
109-
"/"
110-
}
111107
return mapOf(
112108
"zalando.org/skipper-predicate" to predicate,
113109
"zalando.org/skipper-filter" to
@@ -116,12 +112,12 @@ class IngressFactory(private val kubeClient: KubernetesClient) {
116112
"""setRequestHeader("X-ShinyProxy-Latest-Instance", "${shinyProxy.hashOfCurrentSpec}")""" +
117113
if (isDefaultRoute) {
118114
""" -> """ +
119-
"""appendResponseHeader("Set-Cookie", "sp-instance=$hashOfSpec; $security Path=$cookiePath")"""
115+
"""appendResponseHeader("Set-Cookie", "sp-instance=$hashOfSpec; $security Path=${shinyProxy.subPath}")"""
120116
} else {
121117
""
122118
} +
123119
""" -> """ +
124-
"""appendResponseHeader("Set-Cookie", "sp-latest-instance=${shinyProxy.hashOfCurrentSpec}; $security Path=$cookiePath")""",
120+
"""appendResponseHeader("Set-Cookie", "sp-latest-instance=${shinyProxy.hashOfCurrentSpec}; $security Path=${shinyProxy.subPath}")""",
125121
)
126122

127123
}
@@ -130,6 +126,7 @@ class IngressFactory(private val kubeClient: KubernetesClient) {
130126
//@formatter:off
131127
val builder = HTTPIngressPathBuilder()
132128
.withPathType("Prefix")
129+
.withPath(shinyProxy.subPath)
133130
.withNewBackend()
134131
.withNewService()
135132
.withName(ResourceNameFactory.createNameForService(shinyProxy, shinyProxyInstance))
@@ -140,12 +137,6 @@ class IngressFactory(private val kubeClient: KubernetesClient) {
140137
.endBackend()
141138
//@formatter:on
142139

143-
if (shinyProxy.subPath != "") {
144-
builder.withPath(shinyProxy.subPath)
145-
} else {
146-
builder.withPath("/")
147-
}
148-
149140
return builder.build()
150141
}
151142

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,7 @@ class MetadataRouteGroupFactory(private val routeGroupClient: MixedOperation<Rou
4040
fun createOrReplaceRouteGroup(shinyProxy: ShinyProxy) {
4141
val metadata = objectMapper.writeValueAsString(mapOf("instances" to shinyProxy.status.instances)).replace("\"", "\\\"")
4242

43-
val path = if (shinyProxy.subPath != "") {
44-
shinyProxy.subPath + "operator/metadata"
45-
} else {
46-
"/operator/metadata"
47-
}
43+
val path = shinyProxy.subPath + "operator/metadata"
4844

4945
val routeGroupSpec = RouteGroupSpec(
5046
hosts = listOf(shinyProxy.fqdn),

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ class MainIntegrationTest : IntegrationTestBase() {
553553
spTestInstance.assertInstanceIsCorrect(1, true)
554554

555555
// 5. additional assert correctness of ingress
556-
val ingresses = namespacedClient.inNamespace(namespace).network().ingresses().list().items
556+
val ingresses = namespacedClient.inNamespace(namespace).network().v1().ingresses().list().items
557557
assertEquals(3, ingresses.size)
558558
for (ingress in ingresses) {
559559
assertTrue(ingress.metadata.annotations["zalando.org/skipper-filter"]?.contains("Path=/sub-path/") == true)
@@ -590,7 +590,7 @@ class MainIntegrationTest : IntegrationTestBase() {
590590
spTestInstance.assertInstanceIsCorrect(1, true)
591591

592592
// 5. additional assert correctness of ingress
593-
val ingresses = namespacedClient.inNamespace(namespace).network().ingresses().list().items
593+
val ingresses = namespacedClient.inNamespace(namespace).network().v1().ingresses().list().items
594594
assertEquals(3, ingresses.size)
595595
for (ingress in ingresses) {
596596
assertTrue(ingress.metadata.annotations["zalando.org/skipper-filter"]?.contains("Path=/sub-path/") == true)
@@ -628,7 +628,7 @@ class MainIntegrationTest : IntegrationTestBase() {
628628
spTestInstance.assertInstanceIsCorrect(1, true)
629629

630630
// 5. additional assert correctness of ingress
631-
val ingresses = namespacedClient.inNamespace(namespace).network().ingresses().list().items
631+
val ingresses = namespacedClient.inNamespace(namespace).network().v1().ingresses().list().items
632632
assertEquals(3, ingresses.size)
633633
for (ingress in ingresses) {
634634
assertTrue(ingress.metadata.annotations["zalando.org/skipper-filter"]?.contains("Secure;") == false)

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class ShinyProxyTestInstance(private val namespace: String,
149149
fun assertIngressIsCorrect(sp: ShinyProxy, numInstancesRunning: Int = 1, isLatest: Boolean = true) {
150150
val allIngresses = client.inNamespace(namespace).network().v1().ingresses().list().items
151151
assertEquals(numInstancesRunning * 3, allIngresses.size)
152-
val ingresses = client.inNamespace(namespace).network().ingresses().withLabel(LabelFactory.INSTANCE_LABEL, hash).list().items
152+
val ingresses = client.inNamespace(namespace).network().v1().ingresses().withLabel(LabelFactory.INSTANCE_LABEL, hash).list().items
153153
assertEquals(3, ingresses.size)
154154
val mainIngress = ingresses.firstOrNull { it.metadata.name == "sp-${sp.metadata.name}-ing-${hash}".take(63) }
155155
assertNotNull(mainIngress)
@@ -171,6 +171,7 @@ class ShinyProxyTestInstance(private val namespace: String,
171171
assertEquals("ReplicaSet", ingress.metadata.ownerReferences[0].kind)
172172
assertEquals("apps/v1", ingress.metadata.ownerReferences[0].apiVersion)
173173
assertEquals("sp-${sp.metadata.name}-rs-${hash}".take(63), ingress.metadata.ownerReferences[0].name)
174+
assertEquals(ingress.spec.ingressClassName, "skipper")
174175
}
175176

176177
val security = if (Operator.getOperatorInstance().disableSecureCookies) {
@@ -184,7 +185,6 @@ class ShinyProxyTestInstance(private val namespace: String,
184185
"/"
185186
}
186187

187-
assertEquals(ingress.spec.ingressClassName, "skipper")
188188

189189
if (isLatest) {
190190
assertEquals(mapOf(
@@ -210,7 +210,6 @@ class ShinyProxyTestInstance(private val namespace: String,
210210
), mainIngress.metadata.annotations)
211211
}
212212
assertEquals(mapOf(
213-
"kubernetes.io/ingress.class" to "skipper",
214213
"zalando.org/skipper-predicate" to """Cookie("sp-instance-override", "$hash") && Weight(20)""",
215214
"zalando.org/skipper-filter" to
216215
"""setRequestHeader("X-ShinyProxy-Instance", "$hash")""" +
@@ -220,7 +219,6 @@ class ShinyProxyTestInstance(private val namespace: String,
220219
"""appendResponseHeader("Set-Cookie", "sp-latest-instance=${sp.hashOfCurrentSpec}; $security Path=$cookiePath")""",
221220
), cookieOverrideIngress.metadata.annotations)
222221
assertEquals(mapOf(
223-
"kubernetes.io/ingress.class" to "skipper",
224222
"zalando.org/skipper-predicate" to """QueryParam("sp_instance_override", "$hash") && Weight(20)""",
225223
"zalando.org/skipper-filter" to
226224
"""setRequestHeader("X-ShinyProxy-Instance", "$hash")""" +
@@ -238,8 +236,8 @@ class ShinyProxyTestInstance(private val namespace: String,
238236
assertEquals(1, rule.http.paths.size)
239237
val path = rule.http.paths[0]
240238
assertNotNull(path)
241-
assertEquals("sp-${sp.metadata.name}-svc-${hash}".take(63), path.backend.serviceName)
242-
assertEquals(IntOrString(80), path.backend.servicePort)
239+
assertEquals("sp-${sp.metadata.name}-svc-${hash}".take(63), path.backend.service.name)
240+
assertEquals(80, path.backend.service.port.number)
243241
}
244242

245243
}

0 commit comments

Comments
 (0)