Skip to content

Commit

Permalink
Ensure version of Kotlin related packages are consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
LEDfan committed Jul 29, 2021
1 parent 558b70a commit 8c5be82
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 21 deletions.
2 changes: 2 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ ij_kotlin_method_parameters_right_paren_on_new_line = false
ij_any_wrap_long_lines = false
ij_formatter_off_tag = "@formatter:off"
ij_formatter_on_tag = "@formatter:on"
ij_kotlin_name_count_to_use_star_import = 50000
ij_kotlin_name_count_to_use_star_import_for_members = 50000
max_line_length = 256
indent_style = space
indent_size = 4
Expand Down
16 changes: 4 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
<maven.compiler.release>11</maven.compiler.release>
<maven.compiler.target>11</maven.compiler.target>
<version.fabric8.client>4.13.2</version.fabric8.client>
<kotlin.version>1.5.21</kotlin.version>
<kotlin.version>1.5.20</kotlin.version>
<kotlin.compiler.incremental>true</kotlin.compiler.incremental>
<version.arquillian_cube>1.18.2</version.arquillian_cube>
<junit.jupiter.version>5.6.0</junit.jupiter.version>
</properties>

Expand All @@ -37,18 +36,11 @@
</repository>
</distributionManagement>

<repositories>
<repository>
<id>jcenter</id>
<url>https://jcenter.bintray.com/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-coroutines-core</artifactId>
<version>1.3.9</version>
<version>1.5.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-reflect -->
<dependency>
Expand All @@ -69,8 +61,8 @@
</dependency>
<dependency>
<groupId>io.github.microutils</groupId>
<artifactId>kotlin-logging</artifactId>
<version>1.7.8</version>
<artifactId>kotlin-logging-jvm</artifactId>
<version>2.0.10</version>
</dependency>
<dependency>
<groupId>javax.json</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.channels.SendChannel
import mu.KotlinLogging
import org.slf4j.LoggerFactory
import java.util.*
import kotlin.system.exitProcess


Expand Down Expand Up @@ -100,7 +101,7 @@ class Operator(client: NamespacedKubernetesClient? = null,
}

this.mode = readConfigValue(mode, Mode.CLUSTERED, "SPO_MODE") {
when (it.toLowerCase()) {
when (it.lowercase(Locale.getDefault())) {
"clustered" -> Mode.CLUSTERED
"namespaced" -> Mode.NAMESPACED
else -> error("Unsupported operator mode: $it")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import io.fabric8.kubernetes.client.informers.cache.Lister
import kotlinx.coroutines.channels.SendChannel
import kotlinx.coroutines.runBlocking
import mu.KotlinLogging
import java.util.*

class ResourceListener<T : HasMetadata>(private val channel: SendChannel<ShinyProxyEvent>,
informer: SharedIndexInformer<T>,
Expand Down Expand Up @@ -82,7 +83,7 @@ class ResourceListener<T : HasMetadata>(private val channel: SendChannel<ShinyPr
private fun getShinyProxyOwnerRef(resource: HasMetadata): OwnerReference? {
val ownerReferences = resource.metadata.ownerReferences
for (ownerReference in ownerReferences) {
if (ownerReference.kind.toLowerCase() == "shinyproxy") {
if (ownerReference.kind.lowercase(Locale.getDefault()) == "shinyproxy") {
return ownerReference
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ import io.fabric8.kubernetes.client.informers.SharedIndexInformer
import io.fabric8.kubernetes.client.informers.cache.Lister
import io.fabric8.kubernetes.client.internal.readiness.Readiness
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
Expand All @@ -59,8 +60,10 @@ class ShinyProxyController(private val channel: Channel<ShinyProxyEvent>,

private val logger = KotlinLogging.logger {}

private val scope = CoroutineScope(Dispatchers.Default)

suspend fun run() {
GlobalScope.launch { scheduleAdditionalEvents() }
scope.launch { scheduleAdditionalEvents() }
while (true) {
try {
receiveAndHandleEvent()
Expand Down Expand Up @@ -284,7 +287,7 @@ class ShinyProxyController(private val channel: Channel<ShinyProxyEvent>,
}
}

private fun checkForObsoleteInstances() {
private suspend fun checkForObsoleteInstances() {
for (shinyProxy in shinyProxyLister.list()) {
if (shinyProxy.status.instances.size > 1) {
// this SP has more than one instance -> check if some of them are obsolete
Expand Down Expand Up @@ -317,7 +320,7 @@ class ShinyProxyController(private val channel: Channel<ShinyProxyEvent>,
}
}

fun deleteSingleShinyProxyInstance(shinyProxy: ShinyProxy, shinyProxyInstance: ShinyProxyInstance) {
suspend fun deleteSingleShinyProxyInstance(shinyProxy: ShinyProxy, shinyProxyInstance: ShinyProxyInstance) {
logger.info { "${shinyProxy.logPrefix(shinyProxyInstance)} DeleteSingleShinyProxyInstance [Step 1/3]: Update status" }
// Important: update status BEFORE deleting, otherwise we will start reconciling this instance, before it's completely deleted
updateStatus(shinyProxy) {
Expand All @@ -329,7 +332,7 @@ class ShinyProxyController(private val channel: Channel<ShinyProxyEvent>,
logger.info { "${shinyProxy.logPrefix(shinyProxyInstance)} DeleteSingleShinyProxyInstance [Step 2/3]: Update Ingress" }
ingressController.onRemoveInstance(shinyProxy, shinyProxyInstance)

GlobalScope.launch { // run async
scope.launch { // run async
// delete resources after delay of 30 seconds to ensure all routes are updated before deleting replicaset
delay(30_000)
logger.info { "${shinyProxy.logPrefix(shinyProxyInstance)} DeleteSingleShinyProxyInstance [Step 3/3]: Delete resources" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import io.fabric8.kubernetes.client.informers.cache.Lister
import kotlinx.coroutines.channels.SendChannel
import kotlinx.coroutines.runBlocking
import mu.KotlinLogging
import java.util.*

// TODO this has some duplicate code with ResourceListener<T>
class IngressListener(private val channel: SendChannel<ShinyProxyEvent>,
Expand Down Expand Up @@ -94,12 +95,12 @@ class IngressListener(private val channel: SendChannel<ShinyProxyEvent>,
private fun getShinyProxyOwnerRefByKind(resource: HasMetadata, kind: String): OwnerReference? {
val ownerReferences = resource.metadata.ownerReferences
for (ownerReference in ownerReferences) {
if (ownerReference.kind.toLowerCase() == kind.toLowerCase()) {
if (ownerReference.kind.lowercase(Locale.getDefault()) == kind.lowercase(Locale.getDefault())) {
return ownerReference
}
}

return null
}

}
}

0 comments on commit 8c5be82

Please sign in to comment.