-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from FINTLabs/feat/standalone-workflow
FLA-510 Migrate to Standalone Workflow for Enhanced Customization and Improved Error Handling
- Loading branch information
Showing
5 changed files
with
197 additions
and
87 deletions.
There are no files selected for viewing
15 changes: 14 additions & 1 deletion
15
src/main/kotlin/no/fintlabs/operator/ApplicationReconcilerModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,21 @@ | ||
package no.fintlabs.operator | ||
|
||
import io.javaoperatorsdk.operator.api.reconciler.Reconciler | ||
import org.koin.core.qualifier.named | ||
import org.koin.dsl.module | ||
|
||
fun applicationReconcilerModule() = module { | ||
single<Reconciler<*>> { no.fintlabs.operator.FlaisApplicationReconciler() } | ||
single<Reconciler<*>>(named("flais-application-reconciler")) { FlaisApplicationReconciler() } | ||
single { DeploymentDR() } | ||
single { ServiceDR() } | ||
single { PodMetricsDR() } | ||
single { OnePasswordDR() } | ||
single { IngressDR() } | ||
single { PostgresUserDR() } | ||
single { KafkaDR() } | ||
single { CreatePodMetricsCondition() } | ||
single { CreateOnePasswordCondition() } | ||
single { CreateIngressCondition() } | ||
single { CreatePostgresUserCondition() } | ||
single { CreateKafkaCondition() } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/test/integration/kotlin/no/fintlabs/operator/FlaisApplicationReconcilerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package no.fintlabs.operator | ||
|
||
import no.fintlabs.extensions.KubernetesOperatorContext | ||
import no.fintlabs.operator.Utils.createAndGetResource | ||
import no.fintlabs.operator.Utils.createKoinTestExtension | ||
import no.fintlabs.operator.Utils.createKubernetesOperatorExtension | ||
import no.fintlabs.operator.Utils.createTestFlaisApplication | ||
import no.fintlabs.operator.Utils.waitUntil | ||
import no.fintlabs.operator.api.v1alpha1.FlaisApplicationCrd | ||
import no.fintlabs.operator.api.v1alpha1.FlaisApplicationState | ||
import org.junit.jupiter.api.extension.RegisterExtension | ||
import org.koin.core.component.inject | ||
import org.koin.test.KoinTest | ||
import kotlin.test.Test | ||
import kotlin.test.assertContains | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertNotNull | ||
|
||
class FlaisApplicationReconcilerTest : KoinTest { | ||
|
||
@Test | ||
fun `should set correlation id on FlaisApplication`(context: KubernetesOperatorContext) { | ||
val flaisApplication = createTestFlaisApplication() | ||
val app = context.createAndGetApplication(flaisApplication) | ||
|
||
assertNotNull(app) | ||
assertContains(app.metadata.annotations, "fintlabs.no/deployment-correlation-id") | ||
assertNotNull(app.status.correlationId) | ||
assertEquals(app.metadata.annotations["fintlabs.no/deployment-correlation-id"], app.status.correlationId) | ||
} | ||
|
||
@Test | ||
fun `should not set correlation id on FlaisApplication if exists`(context: KubernetesOperatorContext) { | ||
val flaisApplication = createTestFlaisApplication().apply { | ||
metadata.annotations["fintlabs.no/deployment-correlation-id"] = "123" | ||
} | ||
val app = context.createAndGetApplication(flaisApplication) | ||
|
||
assertNotNull(app) | ||
assertContains(app.metadata.annotations, "fintlabs.no/deployment-correlation-id") | ||
assertEquals("123", app.metadata.annotations["fintlabs.no/deployment-correlation-id"]) | ||
assertNotNull(app.status.correlationId) | ||
assertEquals("123", app.status.correlationId) | ||
} | ||
|
||
@Test | ||
fun `should handle dependent errors`(context: KubernetesOperatorContext) { | ||
val service: ServiceDR by inject() | ||
service.setResourceDiscriminator { _, _, _ -> | ||
throw RuntimeException("test") | ||
} | ||
|
||
val flaisApplication = createTestFlaisApplication() | ||
context.create(flaisApplication) | ||
context.waitUntil<FlaisApplicationCrd>(flaisApplication.metadata.name) { it.status.state != FlaisApplicationState.PENDING } | ||
val app = context.get<FlaisApplicationCrd>(flaisApplication.metadata.name) | ||
|
||
assertNotNull(app) | ||
assertEquals(1, app.status.dependentErrors?.size) | ||
assertEquals("test", app.status.dependentErrors?.get("Service")) | ||
} | ||
|
||
|
||
private fun KubernetesOperatorContext.createAndGetApplication(app: FlaisApplicationCrd) = | ||
createAndGetResource<FlaisApplicationCrd>(app) | ||
|
||
companion object { | ||
@RegisterExtension | ||
val koinTestExtension = createKoinTestExtension() | ||
|
||
@RegisterExtension | ||
val kubernetesOperatorExtension = createKubernetesOperatorExtension() | ||
} | ||
} |