Skip to content

Commit 558b70a

Browse files
committed
Fix #25930: Remove ingress before Service and Replicaset
1 parent 48d2eaf commit 558b70a

3 files changed

Lines changed: 31 additions & 10 deletions

File tree

src/main/kotlin/eu/openanalytics/shinyproxyoperator/controller/ShinyProxyController.kt

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -318,19 +318,31 @@ class ShinyProxyController(private val channel: Channel<ShinyProxyEvent>,
318318
}
319319

320320
fun deleteSingleShinyProxyInstance(shinyProxy: ShinyProxy, shinyProxyInstance: ShinyProxyInstance) {
321-
logger.info { "${shinyProxy.logPrefix(shinyProxyInstance)} DeleteSingleShinyProxyInstance" }
321+
logger.info { "${shinyProxy.logPrefix(shinyProxyInstance)} DeleteSingleShinyProxyInstance [Step 1/3]: Update status" }
322322
// Important: update status BEFORE deleting, otherwise we will start reconciling this instance, before it's completely deleted
323323
updateStatus(shinyProxy) {
324324
it.status.instances.remove(shinyProxyInstance)
325325
}
326-
for (service in resourceRetriever.getServiceByLabels(LabelFactory.labelsForShinyProxyInstance(shinyProxy, shinyProxyInstance), shinyProxy.metadata.namespace)) {
327-
kubernetesClient.resource(service).delete()
328-
}
329-
for (replicaSet in resourceRetriever.getReplicaSetByLabels(LabelFactory.labelsForShinyProxyInstance(shinyProxy, shinyProxyInstance), shinyProxy.metadata.namespace)) {
330-
kubernetesClient.resource(replicaSet).delete()
331-
}
332-
for (configMap in resourceRetriever.getConfigMapByLabels(LabelFactory.labelsForShinyProxyInstance(shinyProxy, shinyProxyInstance), shinyProxy.metadata.namespace)) {
333-
kubernetesClient.resource(configMap).delete()
326+
327+
// Important: remove ingress before removing the ReplicaSet. This ensures that the rotues are correclty updated in the Ingress
328+
// and users aren't routed to non-existing pods
329+
logger.info { "${shinyProxy.logPrefix(shinyProxyInstance)} DeleteSingleShinyProxyInstance [Step 2/3]: Update Ingress" }
330+
ingressController.onRemoveInstance(shinyProxy, shinyProxyInstance)
331+
332+
GlobalScope.launch { // run async
333+
// delete resources after delay of 30 seconds to ensure all routes are updated before deleting replicaset
334+
delay(30_000)
335+
logger.info { "${shinyProxy.logPrefix(shinyProxyInstance)} DeleteSingleShinyProxyInstance [Step 3/3]: Delete resources" }
336+
337+
for (service in resourceRetriever.getServiceByLabels(LabelFactory.labelsForShinyProxyInstance(shinyProxy, shinyProxyInstance), shinyProxy.metadata.namespace)) {
338+
kubernetesClient.resource(service).delete()
339+
}
340+
for (replicaSet in resourceRetriever.getReplicaSetByLabels(LabelFactory.labelsForShinyProxyInstance(shinyProxy, shinyProxyInstance), shinyProxy.metadata.namespace)) {
341+
kubernetesClient.resource(replicaSet).delete()
342+
}
343+
for (configMap in resourceRetriever.getConfigMapByLabels(LabelFactory.labelsForShinyProxyInstance(shinyProxy, shinyProxyInstance), shinyProxy.metadata.namespace)) {
344+
kubernetesClient.resource(configMap).delete()
345+
}
334346
}
335347
}
336348

src/main/kotlin/eu/openanalytics/shinyproxyoperator/ingres/IIngressController.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@
2121
package eu.openanalytics.shinyproxyoperator.ingres
2222

2323
import eu.openanalytics.shinyproxyoperator.crd.ShinyProxy
24+
import eu.openanalytics.shinyproxyoperator.crd.ShinyProxyInstance
2425

2526
interface IIngressController {
2627

2728
fun reconcile(shinyProxy: ShinyProxy)
29+
30+
fun onRemoveInstance(shinyProxy: ShinyProxy, shinyProxyInstance: ShinyProxyInstance)
2831
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class IngressController(
4040
channel: Channel<ShinyProxyEvent>,
4141
ingressInformer: SharedIndexInformer<Ingress>,
4242
shinyProxyListener: Lister<ShinyProxy>,
43-
kubernetesClient: KubernetesClient,
43+
private val kubernetesClient: KubernetesClient,
4444
private val resourceRetriever: ResourceRetriever
4545
) : IIngressController {
4646

@@ -65,6 +65,12 @@ class IngressController(
6565
}
6666
}
6767

68+
override fun onRemoveInstance(shinyProxy: ShinyProxy, shinyProxyInstance: ShinyProxyInstance) {
69+
for (ingress in resourceRetriever.getIngressByLabels(LabelFactory.labelsForShinyProxyInstance(shinyProxy, shinyProxyInstance), shinyProxy.metadata.namespace)) {
70+
kubernetesClient.resource(ingress).delete()
71+
}
72+
}
73+
6874
private fun reconcileSingleInstance(shinyProxy: ShinyProxy, shinyProxyInstance: ShinyProxyInstance) {
6975
val ingresses = resourceRetriever.getIngressByLabels(LabelFactory.labelsForShinyProxyInstance(shinyProxy, shinyProxyInstance), shinyProxy.metadata.namespace)
7076

0 commit comments

Comments
 (0)