Skip to content

Commit

Permalink
feat: add leader election configuration (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrejpetras authored Oct 9, 2024
1 parent 53cb404 commit 3a29e71
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,87 +11,87 @@ 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.32.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-cdi.adoc[Link]
| 2.32.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.32.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-rs.adoc[Link]
| 2.32.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.32.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-json.adoc[Link]
| 2.32.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.14.4
| 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.14.4
| 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.14.4
| 3.15.1
| quarkus-jdbc-postgresql
| https://quarkus.io/guides/datasource[Link]
| https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-jdbc-postgresql.adoc[Link]
| 3.14.4
| 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.32.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-security.adoc[Link]
| 2.32.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.30.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.14.4
| 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.14.4
| 3.15.1
| quarkus-operator-sdk-bundle-generator
|
|
| 6.8.0
| 6.7.3
| quarkus-operator-sdk
|
|
| 6.8.0
| 6.7.3
| quarkus-agroal
|
|
| 3.14.4
| 3.15.1
|===
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ h|[.header-title]##Configuration property##
h|Type
h|Default

a| [[onecx-k8s-db-postgresql-operator_onecx-k8s-db-postgresql-operator-host]] [.property-path]##`onecx.k8s.db.postgresql.operator.host`##
a| [[onecx-k8s-db-postgresql-operator_onecx-k8s-db-postgresql-operator-host]] [.property-path]##link:#onecx-k8s-db-postgresql-operator_onecx-k8s-db-postgresql-operator-host[`onecx.k8s.db.postgresql.operator.host`]##

[.description]
--
Expand All @@ -25,6 +25,23 @@ endif::add-copy-button-to-env-var[]
|string
|`postgresql`

a| [[onecx-k8s-db-postgresql-operator_onecx-k8s-db-postgresql-operator-leader-election-lease-name]] [.property-path]##link:#onecx-k8s-db-postgresql-operator_onecx-k8s-db-postgresql-operator-leader-election-lease-name[`onecx.k8s.db.postgresql.operator.leader-election.lease-name`]##

[.description]
--
Lease name


ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++ONECX_K8S_DB_POSTGRESQL_OPERATOR_LEADER_ELECTION_LEASE_NAME+++[]
endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++ONECX_K8S_DB_POSTGRESQL_OPERATOR_LEADER_ELECTION_LEASE_NAME+++`
endif::add-copy-button-to-env-var[]
--
|string
|`onecx-product-store-slot-operator-lease`

|===


Expand Down
9 changes: 9 additions & 0 deletions src/main/helm/templates/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,12 @@ rules:
- get
- list
- watch
- verbs:
- "get"
- "update"
- "create"
- "patch"
apiGroups:
- "coordination.k8s.io"
resources:
- "leases"
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,23 @@ public interface DatabaseConfig {
@WithName("host")
@WithDefault("postgresql")
String host();

/**
* Leader election configuration
*/
@WithName("leader-election")
LeaderElectionConfig leaderElectionConfig();

/**
* Leader election config
*/
interface LeaderElectionConfig {

/**
* Lease name
*/
@WithName("lease-name")
@WithDefault("onecx-product-store-slot-operator-lease")
String leaseName();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.tkit.onecx.k8s.db.postgresql.operator;

import jakarta.inject.Singleton;

import io.javaoperatorsdk.operator.api.config.LeaderElectionConfiguration;

@Singleton
public class LeaderConfiguration extends LeaderElectionConfiguration {

public LeaderConfiguration(DatabaseConfig config) {
super(config.leaderElectionConfig().leaseName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.tkit.onecx.k8s.db.postgresql.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 {

@Inject
DatabaseConfig 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());
}
}

0 comments on commit 3a29e71

Please sign in to comment.