@@ -55,18 +55,18 @@ class ShinyProxyController(private val kubernetesClient: KubernetesClient,
5555
5656 when (event.eventType) {
5757 ShinyProxyEventType .ADD -> {
58- reconcileSingleShinyProxy(event.shinyProxy, event.shinyProxyInstance)
58+ val newInstance = createNewInstance(event.shinyProxy)
59+ reconcileSingleShinyProxyInstance(event.shinyProxy, newInstance)
5960 }
60- ShinyProxyEventType .UPDATE -> {
61- // TODO calculate hash -> reconcile
62- reconcileSingleShinyProxy (event.shinyProxy, event.shinyProxyInstance )
61+ ShinyProxyEventType .UPDATE_SPEC -> {
62+ val newInstance = createNewInstance(event.shinyProxy)
63+ reconcileSingleShinyProxyInstance (event.shinyProxy, newInstance )
6364 }
6465 ShinyProxyEventType .DELETE -> {
6566 // DELETE is not needed
66- // deleteSingleShinyProxy(event.shinyProxy)
6767 }
68- ShinyProxyEventType .UPDATE_DEPENDENCY -> {
69- reconcileSingleShinyProxy (event.shinyProxy, event.shinyProxyInstance)
68+ ShinyProxyEventType .RECONCILE -> {
69+ reconcileSingleShinyProxyInstance (event.shinyProxy, event.shinyProxyInstance)
7070 }
7171 }
7272
@@ -90,24 +90,37 @@ class ShinyProxyController(private val kubernetesClient: KubernetesClient,
9090// }
9191// }
9292
93- private suspend fun reconcileSingleShinyProxy (shinyProxy : ShinyProxy , shinyProxyInstance : ShinyProxyInstance ? ) {
94- logger.info { " ReconcileSingleShinyProxy: ${ shinyProxy.metadata.name} " }
93+ private fun createNewInstance (shinyProxy : ShinyProxy ) : ShinyProxyInstance {
94+ val existingInstance = shinyProxy.status.getInstanceByHash(shinyProxy.calculateHashOfCurrentSpec())
9595
96- if (shinyProxy.status.instances.isEmpty()) {
97- val instance = ShinyProxyInstance ()
98- instance.hashOfSpec = shinyProxy.calculateHashOfCurrentSpec()
99- instance.isLatestInstance = true
100- shinyProxy.status.instances.add(instance)
96+ if (existingInstance != null && existingInstance.isLatestInstance == true ) {
97+ logger.warn { " Trying to create new instance which already exists and is the latest instance" }
98+ return existingInstance
99+ } else if (existingInstance != null && existingInstance.isLatestInstance == false ) {
100+ shinyProxy.status.instances.forEach { it.isLatestInstance = false }
101+ existingInstance.isLatestInstance = true
101102 shinyProxyClient.updateStatus(shinyProxy)
102- return
103+ return existingInstance
103104 }
104105
106+ val newInstance = ShinyProxyInstance ()
107+ newInstance.hashOfSpec = shinyProxy.calculateHashOfCurrentSpec()
108+ newInstance.isLatestInstance = true
109+ shinyProxy.status.instances.forEach { it.isLatestInstance = false }
110+ shinyProxy.status.instances.add(newInstance)
111+ shinyProxyClient.updateStatus(shinyProxy)
112+ return newInstance
113+ }
114+
115+ private suspend fun reconcileSingleShinyProxyInstance (shinyProxy : ShinyProxy , shinyProxyInstance : ShinyProxyInstance ? ) {
116+ logger.info { " ReconcileSingleShinyProxy: ${shinyProxy.metadata.name} " }
117+
105118 if (shinyProxyInstance == null ) {
106- TODO (" Should not happend " )
119+ TODO (" Should not happen " )
107120 }
108121
109122 if (shinyProxyInstance.hashOfSpec == null ) {
110- TODO (" Should not happend " )
123+ TODO (" Should not happen " )
111124 }
112125
113126 val configMaps = resourceRetriever.getConfigMapByLabels(LabelFactory .labelsForShinyProxyInstance(shinyProxy, shinyProxyInstance))
0 commit comments