Skip to content

Commit

Permalink
Ref #27576: rebase with k8s 1.22
Browse files Browse the repository at this point in the history
  • Loading branch information
LEDfan committed Jun 23, 2022
1 parent bca1b4b commit 61c02f1
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 32 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>eu.openanalytics</groupId>
<artifactId>shinyproxy-operator</artifactId>
<version>1.1.0</version>
<version>1.2.0-SNAPSHOT</version>

<organization>
<name>Open Analytics NV</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,12 @@ class Operator(client: NamespacedKubernetesClient? = null,
replicaSetListener = ResourceListener(sendChannel, this.client.inAnyNamespace().apps().replicaSets())
serviceListener = ResourceListener(sendChannel, this.client.inAnyNamespace().services())
configMapListener = ResourceListener(sendChannel, this.client.inAnyNamespace().configMaps())
ingressController = IngressController(sendChannel, this.client.inAnyNamespace(), this.client.inAnyNamespace().network().ingress())
ingressController = IngressController(sendChannel, this.client.inAnyNamespace(), this.client.inAnyNamespace().network().v1().ingresses())
} else {
replicaSetListener = ResourceListener(sendChannel, this.client.inNamespace(namespace).apps().replicaSets())
serviceListener = ResourceListener(sendChannel, this.client.inNamespace(namespace).services())
configMapListener = ResourceListener(sendChannel, this.client.inNamespace(namespace).configMaps())
ingressController = IngressController(sendChannel, this.client.inNamespace(namespace), this.client.inNamespace(namespace).network().ingress())
ingressController = IngressController(sendChannel, this.client.inNamespace(namespace), this.client.inNamespace(namespace).network().v1().ingresses())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class ShinyProxy : CustomResource<JsonNode, ShinyProxyStatus>(), Namespaced {
return@lazy path
}

return@lazy ""
return@lazy "/"
}

@get:JsonIgnore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class IngressFactory(private val kubeClient: KubernetesClient) {
.withAnnotations<String, String>(routeAnnotations)
.endMetadata()
.withNewSpec()
.withIngressClassName("skipper")
.addNewRule()
.withHost(shinyProxy.fqdn)
.withNewHttp()
Expand All @@ -74,7 +75,7 @@ class IngressFactory(private val kubeClient: KubernetesClient) {
.build()
//@formatter:on

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

Expand Down Expand Up @@ -103,11 +104,6 @@ class IngressFactory(private val kubeClient: KubernetesClient) {
"Secure;"
}

val cookiePath = if (shinyProxy.subPath != "") {
shinyProxy.subPath
} else {
"/"
}
return mapOf(
"zalando.org/skipper-predicate" to predicate,
"zalando.org/skipper-filter" to
Expand All @@ -116,12 +112,12 @@ class IngressFactory(private val kubeClient: KubernetesClient) {
"""setRequestHeader("X-ShinyProxy-Latest-Instance", "${shinyProxy.hashOfCurrentSpec}")""" +
if (isDefaultRoute) {
""" -> """ +
"""appendResponseHeader("Set-Cookie", "sp-instance=$hashOfSpec; $security Path=$cookiePath")"""
"""appendResponseHeader("Set-Cookie", "sp-instance=$hashOfSpec; $security Path=${shinyProxy.subPath}")"""
} else {
""
} +
""" -> """ +
"""appendResponseHeader("Set-Cookie", "sp-latest-instance=${shinyProxy.hashOfCurrentSpec}; $security Path=$cookiePath")""",
"""appendResponseHeader("Set-Cookie", "sp-latest-instance=${shinyProxy.hashOfCurrentSpec}; $security Path=${shinyProxy.subPath}")""",
)

}
Expand All @@ -130,6 +126,7 @@ class IngressFactory(private val kubeClient: KubernetesClient) {
//@formatter:off
val builder = HTTPIngressPathBuilder()
.withPathType("Prefix")
.withPath(shinyProxy.subPath)
.withNewBackend()
.withNewService()
.withName(ResourceNameFactory.createNameForService(shinyProxy, shinyProxyInstance))
Expand All @@ -140,12 +137,6 @@ class IngressFactory(private val kubeClient: KubernetesClient) {
.endBackend()
//@formatter:on

if (shinyProxy.subPath != "") {
builder.withPath(shinyProxy.subPath)
} else {
builder.withPath("/")
}

return builder.build()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ class MetadataRouteGroupFactory(private val routeGroupClient: MixedOperation<Rou
fun createOrReplaceRouteGroup(shinyProxy: ShinyProxy) {
val metadata = objectMapper.writeValueAsString(mapOf("instances" to shinyProxy.status.instances)).replace("\"", "\\\"")

val path = if (shinyProxy.subPath != "") {
shinyProxy.subPath + "operator/metadata"
} else {
"/operator/metadata"
}
val path = shinyProxy.subPath + "operator/metadata"

val routeGroupSpec = RouteGroupSpec(
hosts = listOf(shinyProxy.fqdn),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ class MainIntegrationTest : IntegrationTestBase() {
spTestInstance.assertInstanceIsCorrect(1, true)

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

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

// 5. additional assert correctness of ingress
val ingresses = namespacedClient.inNamespace(namespace).network().ingresses().list().items
val ingresses = namespacedClient.inNamespace(namespace).network().v1().ingresses().list().items
assertEquals(3, ingresses.size)
for (ingress in ingresses) {
assertTrue(ingress.metadata.annotations["zalando.org/skipper-filter"]?.contains("Secure;") == false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class ShinyProxyTestInstance(private val namespace: String,
fun assertIngressIsCorrect(sp: ShinyProxy, numInstancesRunning: Int = 1, isLatest: Boolean = true) {
val allIngresses = client.inNamespace(namespace).network().v1().ingresses().list().items
assertEquals(numInstancesRunning * 3, allIngresses.size)
val ingresses = client.inNamespace(namespace).network().ingresses().withLabel(LabelFactory.INSTANCE_LABEL, hash).list().items
val ingresses = client.inNamespace(namespace).network().v1().ingresses().withLabel(LabelFactory.INSTANCE_LABEL, hash).list().items
assertEquals(3, ingresses.size)
val mainIngress = ingresses.firstOrNull { it.metadata.name == "sp-${sp.metadata.name}-ing-${hash}".take(63) }
assertNotNull(mainIngress)
Expand All @@ -171,6 +171,7 @@ class ShinyProxyTestInstance(private val namespace: String,
assertEquals("ReplicaSet", ingress.metadata.ownerReferences[0].kind)
assertEquals("apps/v1", ingress.metadata.ownerReferences[0].apiVersion)
assertEquals("sp-${sp.metadata.name}-rs-${hash}".take(63), ingress.metadata.ownerReferences[0].name)
assertEquals(ingress.spec.ingressClassName, "skipper")
}

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

assertEquals(ingress.spec.ingressClassName, "skipper")

if (isLatest) {
assertEquals(mapOf(
Expand All @@ -210,7 +210,6 @@ class ShinyProxyTestInstance(private val namespace: String,
), mainIngress.metadata.annotations)
}
assertEquals(mapOf(
"kubernetes.io/ingress.class" to "skipper",
"zalando.org/skipper-predicate" to """Cookie("sp-instance-override", "$hash") && Weight(20)""",
"zalando.org/skipper-filter" to
"""setRequestHeader("X-ShinyProxy-Instance", "$hash")""" +
Expand All @@ -220,7 +219,6 @@ class ShinyProxyTestInstance(private val namespace: String,
"""appendResponseHeader("Set-Cookie", "sp-latest-instance=${sp.hashOfCurrentSpec}; $security Path=$cookiePath")""",
), cookieOverrideIngress.metadata.annotations)
assertEquals(mapOf(
"kubernetes.io/ingress.class" to "skipper",
"zalando.org/skipper-predicate" to """QueryParam("sp_instance_override", "$hash") && Weight(20)""",
"zalando.org/skipper-filter" to
"""setRequestHeader("X-ShinyProxy-Instance", "$hash")""" +
Expand All @@ -238,8 +236,8 @@ class ShinyProxyTestInstance(private val namespace: String,
assertEquals(1, rule.http.paths.size)
val path = rule.http.paths[0]
assertNotNull(path)
assertEquals("sp-${sp.metadata.name}-svc-${hash}".take(63), path.backend.serviceName)
assertEquals(IntOrString(80), path.backend.servicePort)
assertEquals("sp-${sp.metadata.name}-svc-${hash}".take(63), path.backend.service.name)
assertEquals(80, path.backend.service.port.number)
}

}
Expand Down

0 comments on commit 61c02f1

Please sign in to comment.