From a442669903683f57e85e49a2c4c346a758ceb9bd Mon Sep 17 00:00:00 2001 From: Andrej Petras Date: Tue, 8 Oct 2024 17:13:48 +0200 Subject: [PATCH] feat: add leader election configuration (#47) * feat: add leader election configuration * feat: add leader election configuration --- .../pages/index.adoc | 2 ++ .../onecx-product-store-ms-operator-docs.adoc | 4 --- ...-product-store-ms-operator-extensions.adoc | 36 +++++++++---------- .../onecx-product-store-ms-operator.adoc | 31 ++++++++++++++++ src/main/helm/templates/role.yaml | 9 +++++ .../ms/operator/LeaderConfiguration.java | 13 +++++++ .../store/ms/operator/MicroserviceConfig.java | 35 ++++++++++++++++++ .../ms/operator/LeaderConfigurationTest.java | 27 ++++++++++++++ 8 files changed, 135 insertions(+), 22 deletions(-) create mode 100644 docs/modules/onecx-product-store-ms-operator/pages/onecx-product-store-ms-operator.adoc create mode 100644 src/main/java/org/tkit/onecx/product/store/ms/operator/LeaderConfiguration.java create mode 100644 src/main/java/org/tkit/onecx/product/store/ms/operator/MicroserviceConfig.java create mode 100644 src/test/java/org/tkit/onecx/product/store/ms/operator/LeaderConfigurationTest.java diff --git a/docs/modules/onecx-product-store-ms-operator/pages/index.adoc b/docs/modules/onecx-product-store-ms-operator/pages/index.adoc index d0ffeb7..447c829 100644 --- a/docs/modules/onecx-product-store-ms-operator/pages/index.adoc +++ b/docs/modules/onecx-product-store-ms-operator/pages/index.adoc @@ -4,5 +4,7 @@ include::onecx-product-store-ms-operator-attributes.adoc[opts=optional] include::docs.adoc[opts=optional] +=== Configuration +include::onecx-product-store-ms-operator.adoc[opts=optional] include::onecx-product-store-ms-operator-docs.adoc[opts=optional] diff --git a/docs/modules/onecx-product-store-ms-operator/pages/onecx-product-store-ms-operator-docs.adoc b/docs/modules/onecx-product-store-ms-operator/pages/onecx-product-store-ms-operator-docs.adoc index 7a2a14f..3c7a771 100644 --- a/docs/modules/onecx-product-store-ms-operator/pages/onecx-product-store-ms-operator-docs.adoc +++ b/docs/modules/onecx-product-store-ms-operator/pages/onecx-product-store-ms-operator-docs.adoc @@ -62,7 +62,3 @@ app: ---- -es: JOSDK_WATCH_CURRENT, JOSDK_ALL_NAMESPACES or comma separated list of namespaces -watchNamespaces: "JOSDK_WATCH_CURRENT" ----- - diff --git a/docs/modules/onecx-product-store-ms-operator/pages/onecx-product-store-ms-operator-extensions.adoc b/docs/modules/onecx-product-store-ms-operator/pages/onecx-product-store-ms-operator-extensions.adoc index 3f1dc60..a784674 100644 --- a/docs/modules/onecx-product-store-ms-operator/pages/onecx-product-store-ms-operator-extensions.adoc +++ b/docs/modules/onecx-product-store-ms-operator/pages/onecx-product-store-ms-operator-extensions.adoc @@ -11,38 +11,38 @@ h| Version | tkit-quarkus-log-cdi | https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-log-cdi.html[Link] -| https://github.com/1000kit/tkit-quarkus/blob/2.31.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-cdi.adoc[Link] -| 2.31.0 +| https://github.com/1000kit/tkit-quarkus/blob/2.33.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-cdi.adoc[Link] +| 2.33.0 | tkit-quarkus-log-rs | https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-log-rs.html[Link] -| https://github.com/1000kit/tkit-quarkus/blob/2.31.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-rs.adoc[Link] -| 2.31.0 +| https://github.com/1000kit/tkit-quarkus/blob/2.33.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-rs.adoc[Link] +| 2.33.0 | tkit-quarkus-log-json | https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-log-json.html[Link] -| https://github.com/1000kit/tkit-quarkus/blob/2.31.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-json.adoc[Link] -| 2.31.0 +| https://github.com/1000kit/tkit-quarkus/blob/2.33.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-json.adoc[Link] +| 2.33.0 | quarkus-arc | https://quarkus.io/guides/cdi-reference[Link] | https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-arc.adoc[Link] -| 3.13.2 +| 3.15.1 | quarkus-micrometer-registry-prometheus | https://quarkus.io/guides/telemetry-micrometer[Link] | https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-micrometer-registry-prometheus.adoc[Link] -| 3.13.2 +| 3.15.1 | quarkus-opentelemetry | https://quarkus.io/guides/opentelemetry[Link] | https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-opentelemetry.adoc[Link] -| 3.13.2 +| 3.15.1 | quarkus-openapi-generator @@ -54,37 +54,37 @@ h| Version | https://quarkus.io/guides/rest-client[Link] | https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-rest-client.adoc[Link] -| 3.13.2 +| 3.15.1 | quarkus-rest-client-jackson | https://quarkus.io/guides/rest-client[Link] | -| 3.13.2 +| 3.15.1 | tkit-quarkus-security | https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-security.html[Link] -| https://github.com/1000kit/tkit-quarkus/blob/2.31.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-security.adoc[Link] -| 2.31.0 +| https://github.com/1000kit/tkit-quarkus/blob/2.33.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-security.adoc[Link] +| 2.33.0 | onecx-core | https://onecx.github.io/docs/onecx-quarkus/current/onecx-quarkus/onecx-core.html[Link] | -| 0.26.0 +| 0.31.0 | quarkus-smallrye-health | https://quarkus.io/guides/smallrye-health[Link] | https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-smallrye-health.adoc[Link] -| 3.13.2 +| 3.15.1 | quarkus-container-image-docker | https://quarkus.io/guides/container-image[Link] | https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-container-image-docker.adoc[Link] -| 3.13.2 +| 3.15.1 | quarkus-operator-sdk-bundle-generator @@ -103,13 +103,13 @@ h| Version | | -| 3.13.2 +| 3.15.1 | quarkus-rest-client-oidc-filter | | -| 3.13.2 +| 3.15.1 |=== \ No newline at end of file diff --git a/docs/modules/onecx-product-store-ms-operator/pages/onecx-product-store-ms-operator.adoc b/docs/modules/onecx-product-store-ms-operator/pages/onecx-product-store-ms-operator.adoc new file mode 100644 index 0000000..346a9f6 --- /dev/null +++ b/docs/modules/onecx-product-store-ms-operator/pages/onecx-product-store-ms-operator.adoc @@ -0,0 +1,31 @@ +:summaryTableId: onecx-product-store-ms-operator +[.configuration-legend] +icon:lock[title=Fixed at build time] Configuration property fixed at build time - All other configuration properties are overridable at runtime +[.configuration-reference.searchable, cols="80,.^10,.^10"] +|=== + +h|[.header-title]##Configuration property## +h|Type +h|Default + +a| [[onecx-product-store-ms-operator_onecx-product-store-operator-ms-leader-election-lease-name]] [.property-path]##link:#onecx-product-store-ms-operator_onecx-product-store-operator-ms-leader-election-lease-name[`onecx.product-store.operator.ms.leader-election.lease-name`]## + +[.description] +-- +Lease name + + +ifdef::add-copy-button-to-env-var[] +Environment variable: env_var_with_copy_button:+++ONECX_PRODUCT_STORE_OPERATOR_MS_LEADER_ELECTION_LEASE_NAME+++[] +endif::add-copy-button-to-env-var[] +ifndef::add-copy-button-to-env-var[] +Environment variable: `+++ONECX_PRODUCT_STORE_OPERATOR_MS_LEADER_ELECTION_LEASE_NAME+++` +endif::add-copy-button-to-env-var[] +-- +|string +|`onecx-permission-operator-lease` + +|=== + + +:!summaryTableId: \ No newline at end of file diff --git a/src/main/helm/templates/role.yaml b/src/main/helm/templates/role.yaml index 0f4ee13..2991636 100644 --- a/src/main/helm/templates/role.yaml +++ b/src/main/helm/templates/role.yaml @@ -17,3 +17,12 @@ rules: - "update" - "create" - "delete" + - verbs: + - "get" + - "update" + - "create" + - "patch" + apiGroups: + - "coordination.k8s.io" + resources: + - "leases" \ No newline at end of file diff --git a/src/main/java/org/tkit/onecx/product/store/ms/operator/LeaderConfiguration.java b/src/main/java/org/tkit/onecx/product/store/ms/operator/LeaderConfiguration.java new file mode 100644 index 0000000..f5b1505 --- /dev/null +++ b/src/main/java/org/tkit/onecx/product/store/ms/operator/LeaderConfiguration.java @@ -0,0 +1,13 @@ +package org.tkit.onecx.product.store.ms.operator; + +import jakarta.inject.Singleton; + +import io.javaoperatorsdk.operator.api.config.LeaderElectionConfiguration; + +@Singleton +public class LeaderConfiguration extends LeaderElectionConfiguration { + + public LeaderConfiguration(MicroserviceConfig config) { + super(config.leaderElectionConfig().leaseName()); + } +} diff --git a/src/main/java/org/tkit/onecx/product/store/ms/operator/MicroserviceConfig.java b/src/main/java/org/tkit/onecx/product/store/ms/operator/MicroserviceConfig.java new file mode 100644 index 0000000..032e924 --- /dev/null +++ b/src/main/java/org/tkit/onecx/product/store/ms/operator/MicroserviceConfig.java @@ -0,0 +1,35 @@ +package org.tkit.onecx.product.store.ms.operator; + +import io.quarkus.runtime.annotations.ConfigDocFilename; +import io.quarkus.runtime.annotations.ConfigPhase; +import io.quarkus.runtime.annotations.ConfigRoot; +import io.quarkus.runtime.annotations.StaticInitSafe; +import io.smallrye.config.ConfigMapping; +import io.smallrye.config.WithDefault; +import io.smallrye.config.WithName; + +@StaticInitSafe +@ConfigDocFilename("onecx-product-store-ms-operator.adoc") +@ConfigMapping(prefix = "onecx.product-store.operator.ms") +@ConfigRoot(phase = ConfigPhase.RUN_TIME) +public interface MicroserviceConfig { + + /** + * Leader election configuration + */ + @WithName("leader-election") + LeaderElectionConfig leaderElectionConfig(); + + /** + * Leader election config + */ + interface LeaderElectionConfig { + + /** + * Lease name + */ + @WithName("lease-name") + @WithDefault("onecx-product-store-ms-operator-lease") + String leaseName(); + } +} diff --git a/src/test/java/org/tkit/onecx/product/store/ms/operator/LeaderConfigurationTest.java b/src/test/java/org/tkit/onecx/product/store/ms/operator/LeaderConfigurationTest.java new file mode 100644 index 0000000..1a14898 --- /dev/null +++ b/src/test/java/org/tkit/onecx/product/store/ms/operator/LeaderConfigurationTest.java @@ -0,0 +1,27 @@ +package org.tkit.onecx.product.store.ms.operator; + +import static org.assertj.core.api.Assertions.assertThat; + +import jakarta.inject.Inject; + +import org.junit.jupiter.api.Test; + +import io.quarkus.test.junit.QuarkusTest; + +@QuarkusTest +class LeaderConfigurationTest extends AbstractTest { + + @Inject + MicroserviceConfig dataConfig; + + @Inject + LeaderConfiguration leaderConfiguration; + + @Test + void testLeaderConfiguration() { + assertThat(dataConfig).isNotNull(); + assertThat(dataConfig.leaderElectionConfig()).isNotNull(); + assertThat(leaderConfiguration).isNotNull(); + assertThat(leaderConfiguration.getLeaseName()).isNotNull().isEqualTo(dataConfig.leaderElectionConfig().leaseName()); + } +}