Skip to content

Commit f47abbb

Browse files
committed
feat: generate default configs using reconciliation cycle
1 parent ee388a0 commit f47abbb

12 files changed

Lines changed: 78 additions & 75 deletions

stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/factory/cluster/ClusterDefaultInstanceProfile.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import io.stackgres.operator.conciliation.OperatorVersionBinder;
2020
import io.stackgres.operator.conciliation.ResourceGenerator;
2121
import io.stackgres.operator.conciliation.cluster.StackGresClusterContext;
22+
import io.stackgres.operator.initialization.DefaultProfileFactory;
2223
import io.stackgres.operatorframework.resource.ResourceUtil;
2324
import jakarta.inject.Inject;
2425
import jakarta.inject.Singleton;
@@ -28,10 +29,14 @@
2829
public class ClusterDefaultInstanceProfile implements ResourceGenerator<StackGresClusterContext> {
2930

3031
private final LabelFactoryForCluster labelFactory;
32+
private final DefaultProfileFactory defaultProfileFactory;
3133

3234
@Inject
33-
public ClusterDefaultInstanceProfile(LabelFactoryForCluster labelFactory) {
35+
public ClusterDefaultInstanceProfile(
36+
LabelFactoryForCluster labelFactory,
37+
DefaultProfileFactory defaultProfileFactory) {
3438
this.labelFactory = labelFactory;
39+
this.defaultProfileFactory = defaultProfileFactory;
3540
}
3641

3742
@Override
@@ -63,8 +68,7 @@ private StackGresProfile getDefaultProfile(StackGresCluster cluster) {
6368
.withName(cluster.getSpec().getSgInstanceProfile())
6469
.withLabels(labelFactory.defaultConfigLabels(cluster))
6570
.endMetadata()
66-
.withNewSpec()
67-
.endSpec()
71+
.withSpec(defaultProfileFactory.buildResource(cluster).getSpec())
6872
.build();
6973
}
7074

stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/factory/cluster/ClusterDefaultPostgresConfig.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import io.stackgres.operator.conciliation.OperatorVersionBinder;
2020
import io.stackgres.operator.conciliation.ResourceGenerator;
2121
import io.stackgres.operator.conciliation.cluster.StackGresClusterContext;
22+
import io.stackgres.operator.initialization.DefaultClusterPostgresConfigFactory;
2223
import io.stackgres.operatorframework.resource.ResourceUtil;
2324
import jakarta.inject.Inject;
2425
import jakarta.inject.Singleton;
@@ -28,10 +29,14 @@
2829
public class ClusterDefaultPostgresConfig implements ResourceGenerator<StackGresClusterContext> {
2930

3031
private final LabelFactoryForCluster labelFactory;
32+
private final DefaultClusterPostgresConfigFactory defaultClusterPostgresConfigFactory;
3133

3234
@Inject
33-
public ClusterDefaultPostgresConfig(LabelFactoryForCluster labelFactory) {
35+
public ClusterDefaultPostgresConfig(
36+
LabelFactoryForCluster labelFactory,
37+
DefaultClusterPostgresConfigFactory defaultClusterPostgresConfigFactory) {
3438
this.labelFactory = labelFactory;
39+
this.defaultClusterPostgresConfigFactory = defaultClusterPostgresConfigFactory;
3540
}
3641

3742
@Override
@@ -63,15 +68,8 @@ private StackGresPostgresConfig getDefaultConfig(StackGresCluster cluster) {
6368
.withName(cluster.getSpec().getConfigurations().getSgPostgresConfig())
6469
.withLabels(labelFactory.defaultConfigLabels(cluster))
6570
.endMetadata()
66-
.withNewSpec()
67-
.withPostgresVersion(getPostgresMajorVersion(cluster))
68-
.endSpec()
71+
.withSpec(defaultClusterPostgresConfigFactory.buildResource(cluster).getSpec())
6972
.build();
7073
}
7174

72-
private String getPostgresMajorVersion(StackGresCluster cluster) {
73-
String version = cluster.getSpec().getPostgres().getVersion();
74-
return version.split("\\.")[0];
75-
}
76-
7775
}

stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/factory/cluster/sidecars/pooling/PgBouncerDefaultPoolingConfig.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import io.stackgres.operator.conciliation.OperatorVersionBinder;
2121
import io.stackgres.operator.conciliation.ResourceGenerator;
2222
import io.stackgres.operator.conciliation.cluster.StackGresClusterContext;
23+
import io.stackgres.operator.initialization.DefaultPoolingConfigFactory;
2324
import io.stackgres.operatorframework.resource.ResourceUtil;
2425
import jakarta.inject.Inject;
2526
import jakarta.inject.Singleton;
@@ -29,10 +30,14 @@
2930
public class PgBouncerDefaultPoolingConfig implements ResourceGenerator<StackGresClusterContext> {
3031

3132
private final LabelFactoryForCluster labelFactory;
33+
private final DefaultPoolingConfigFactory defaultPoolingConfigFactory;
3234

3335
@Inject
34-
public PgBouncerDefaultPoolingConfig(LabelFactoryForCluster labelFactory) {
36+
public PgBouncerDefaultPoolingConfig(
37+
LabelFactoryForCluster labelFactory,
38+
DefaultPoolingConfigFactory defaultPoolingConfigFactory) {
3539
this.labelFactory = labelFactory;
40+
this.defaultPoolingConfigFactory = defaultPoolingConfigFactory;
3641
}
3742

3843
@Override
@@ -67,12 +72,7 @@ private StackGresPoolingConfig getDefaultConfig(StackGresCluster cluster) {
6772
.withName(cluster.getSpec().getConfigurations().getSgPoolingConfig())
6873
.withLabels(labelFactory.defaultConfigLabels(cluster))
6974
.endMetadata()
70-
.withNewSpec()
71-
.withNewPgBouncer()
72-
.withNewPgbouncerIni()
73-
.endPgbouncerIni()
74-
.endPgBouncer()
75-
.endSpec()
75+
.withSpec(defaultPoolingConfigFactory.buildResource(cluster).getSpec())
7676
.build();
7777
}
7878

stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/factory/distributedlogs/DistributedLogsDefaultInstanceProfile.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import io.stackgres.operator.conciliation.OperatorVersionBinder;
2020
import io.stackgres.operator.conciliation.ResourceGenerator;
2121
import io.stackgres.operator.conciliation.distributedlogs.StackGresDistributedLogsContext;
22+
import io.stackgres.operator.initialization.DefaultProfileFactory;
2223
import io.stackgres.operatorframework.resource.ResourceUtil;
2324
import jakarta.inject.Inject;
2425
import jakarta.inject.Singleton;
@@ -28,10 +29,14 @@
2829
public class DistributedLogsDefaultInstanceProfile implements ResourceGenerator<StackGresDistributedLogsContext> {
2930

3031
private final LabelFactoryForDistributedLogs labelFactory;
32+
private final DefaultProfileFactory defaultProfileFactory;
3133

3234
@Inject
33-
public DistributedLogsDefaultInstanceProfile(LabelFactoryForDistributedLogs labelFactory) {
35+
public DistributedLogsDefaultInstanceProfile(
36+
LabelFactoryForDistributedLogs labelFactory,
37+
DefaultProfileFactory defaultProfileFactory) {
3438
this.labelFactory = labelFactory;
39+
this.defaultProfileFactory = defaultProfileFactory;
3540
}
3641

3742
@Override
@@ -63,8 +68,7 @@ private StackGresProfile getDefaultProfile(StackGresDistributedLogs cluster) {
6368
.withName(cluster.getSpec().getSgInstanceProfile())
6469
.withLabels(labelFactory.defaultConfigLabels(cluster))
6570
.endMetadata()
66-
.withNewSpec()
67-
.endSpec()
71+
.withSpec(defaultProfileFactory.buildResource(cluster).getSpec())
6872
.build();
6973
}
7074

stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/factory/distributedlogs/DistributedLogsDefaultPostgresConfig.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
import io.stackgres.common.crd.sgpgconfig.StackGresPostgresConfig;
1717
import io.stackgres.common.crd.sgpgconfig.StackGresPostgresConfigBuilder;
1818
import io.stackgres.common.labels.LabelFactoryForDistributedLogs;
19-
import io.stackgres.operator.common.StackGresDistributedLogsUtil;
2019
import io.stackgres.operator.conciliation.OperatorVersionBinder;
2120
import io.stackgres.operator.conciliation.ResourceGenerator;
2221
import io.stackgres.operator.conciliation.distributedlogs.StackGresDistributedLogsContext;
22+
import io.stackgres.operator.initialization.DefaultDistributedLogsPostgresConfigFactory;
2323
import io.stackgres.operatorframework.resource.ResourceUtil;
2424
import jakarta.inject.Inject;
2525
import jakarta.inject.Singleton;
@@ -29,10 +29,14 @@
2929
public class DistributedLogsDefaultPostgresConfig implements ResourceGenerator<StackGresDistributedLogsContext> {
3030

3131
private final LabelFactoryForDistributedLogs labelFactory;
32+
private final DefaultDistributedLogsPostgresConfigFactory defaultDistributedLogsPostgresConfigFactory;
3233

3334
@Inject
34-
public DistributedLogsDefaultPostgresConfig(LabelFactoryForDistributedLogs labelFactory) {
35+
public DistributedLogsDefaultPostgresConfig(
36+
LabelFactoryForDistributedLogs labelFactory,
37+
DefaultDistributedLogsPostgresConfigFactory defaultDistributedLogsPostgresConfigFactory) {
3538
this.labelFactory = labelFactory;
39+
this.defaultDistributedLogsPostgresConfigFactory = defaultDistributedLogsPostgresConfigFactory;
3640
}
3741

3842
@Override
@@ -65,16 +69,8 @@ private StackGresPostgresConfig getDefaultConfig(StackGresDistributedLogsContext
6569
.withName(cluster.getSpec().getConfigurations().getSgPostgresConfig())
6670
.withLabels(labelFactory.defaultConfigLabels(cluster))
6771
.endMetadata()
68-
.withNewSpec()
69-
.withPostgresVersion(
70-
getPostgresMajorVersion(
71-
StackGresDistributedLogsUtil.getPostgresVersion(cluster)))
72-
.endSpec()
72+
.withSpec(defaultDistributedLogsPostgresConfigFactory.buildResource(cluster).getSpec())
7373
.build();
7474
}
7575

76-
private String getPostgresMajorVersion(String version) {
77-
return version.split("\\.")[0];
78-
}
79-
8076
}

stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/factory/shardedcluster/ShardedClusterCoordinatorDefaultInstanceProfile.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import io.stackgres.operator.conciliation.OperatorVersionBinder;
2020
import io.stackgres.operator.conciliation.ResourceGenerator;
2121
import io.stackgres.operator.conciliation.shardedcluster.StackGresShardedClusterContext;
22+
import io.stackgres.operator.initialization.DefaultProfileFactory;
2223
import io.stackgres.operatorframework.resource.ResourceUtil;
2324
import jakarta.inject.Inject;
2425
import jakarta.inject.Singleton;
@@ -29,10 +30,14 @@ public class ShardedClusterCoordinatorDefaultInstanceProfile
2930
implements ResourceGenerator<StackGresShardedClusterContext> {
3031

3132
private final LabelFactoryForShardedCluster labelFactory;
33+
private final DefaultProfileFactory defaultProfileFactory;
3234

3335
@Inject
34-
public ShardedClusterCoordinatorDefaultInstanceProfile(LabelFactoryForShardedCluster labelFactory) {
36+
public ShardedClusterCoordinatorDefaultInstanceProfile(
37+
LabelFactoryForShardedCluster labelFactory,
38+
DefaultProfileFactory defaultProfileFactory) {
3539
this.labelFactory = labelFactory;
40+
this.defaultProfileFactory = defaultProfileFactory;
3641
}
3742

3843
@Override
@@ -64,8 +69,7 @@ private StackGresProfile getDefaultProfile(StackGresShardedCluster cluster) {
6469
.withName(cluster.getSpec().getCoordinator().getSgInstanceProfile())
6570
.withLabels(labelFactory.defaultConfigLabels(cluster))
6671
.endMetadata()
67-
.withNewSpec()
68-
.endSpec()
72+
.withSpec(defaultProfileFactory.buildResource(cluster).getSpec())
6973
.build();
7074
}
7175

stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/factory/shardedcluster/ShardedClusterCoordinatorDefaultPostgresConfig.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import io.stackgres.operator.conciliation.OperatorVersionBinder;
2020
import io.stackgres.operator.conciliation.ResourceGenerator;
2121
import io.stackgres.operator.conciliation.shardedcluster.StackGresShardedClusterContext;
22+
import io.stackgres.operator.initialization.DefaultShardedClusterPostgresConfigFactory;
2223
import io.stackgres.operatorframework.resource.ResourceUtil;
2324
import jakarta.inject.Inject;
2425
import jakarta.inject.Singleton;
@@ -29,10 +30,14 @@ public class ShardedClusterCoordinatorDefaultPostgresConfig
2930
implements ResourceGenerator<StackGresShardedClusterContext> {
3031

3132
private final LabelFactoryForShardedCluster labelFactory;
33+
private final DefaultShardedClusterPostgresConfigFactory defaultShardedClusterPostgresConfigFactory;
3234

3335
@Inject
34-
public ShardedClusterCoordinatorDefaultPostgresConfig(LabelFactoryForShardedCluster labelFactory) {
36+
public ShardedClusterCoordinatorDefaultPostgresConfig(
37+
LabelFactoryForShardedCluster labelFactory,
38+
DefaultShardedClusterPostgresConfigFactory defaultShardedClusterPostgresConfigFactory) {
3539
this.labelFactory = labelFactory;
40+
this.defaultShardedClusterPostgresConfigFactory = defaultShardedClusterPostgresConfigFactory;
3641
}
3742

3843
@Override
@@ -64,15 +69,8 @@ private StackGresPostgresConfig getDefaultConfig(StackGresShardedCluster cluster
6469
.withName(cluster.getSpec().getCoordinator().getConfigurationsForCoordinator().getSgPostgresConfig())
6570
.withLabels(labelFactory.defaultConfigLabels(cluster))
6671
.endMetadata()
67-
.withNewSpec()
68-
.withPostgresVersion(getPostgresMajorVersion(cluster))
69-
.endSpec()
72+
.withSpec(defaultShardedClusterPostgresConfigFactory.buildResource(cluster).getSpec())
7073
.build();
7174
}
7275

73-
private String getPostgresMajorVersion(StackGresShardedCluster cluster) {
74-
String version = cluster.getSpec().getPostgres().getVersion();
75-
return version.split("\\.")[0];
76-
}
77-
7876
}

stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/factory/shardedcluster/ShardedClusterCoordinatorPgBouncerDefaultPoolingConfig.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import io.stackgres.operator.conciliation.OperatorVersionBinder;
2121
import io.stackgres.operator.conciliation.ResourceGenerator;
2222
import io.stackgres.operator.conciliation.shardedcluster.StackGresShardedClusterContext;
23+
import io.stackgres.operator.initialization.DefaultPoolingConfigFactory;
2324
import io.stackgres.operatorframework.resource.ResourceUtil;
2425
import jakarta.inject.Inject;
2526
import jakarta.inject.Singleton;
@@ -30,10 +31,14 @@ public class ShardedClusterCoordinatorPgBouncerDefaultPoolingConfig
3031
implements ResourceGenerator<StackGresShardedClusterContext> {
3132

3233
private final LabelFactoryForShardedCluster labelFactory;
34+
private final DefaultPoolingConfigFactory defaultPoolingConfigFactory;
3335

3436
@Inject
35-
public ShardedClusterCoordinatorPgBouncerDefaultPoolingConfig(LabelFactoryForShardedCluster labelFactory) {
37+
public ShardedClusterCoordinatorPgBouncerDefaultPoolingConfig(
38+
LabelFactoryForShardedCluster labelFactory,
39+
DefaultPoolingConfigFactory defaultPoolingConfigFactory) {
3640
this.labelFactory = labelFactory;
41+
this.defaultPoolingConfigFactory = defaultPoolingConfigFactory;
3742
}
3843

3944
@Override
@@ -68,12 +73,7 @@ private StackGresPoolingConfig getDefaultConfig(StackGresShardedCluster cluster)
6873
.withName(cluster.getSpec().getCoordinator().getConfigurationsForCoordinator().getSgPoolingConfig())
6974
.withLabels(labelFactory.defaultConfigLabels(cluster))
7075
.endMetadata()
71-
.withNewSpec()
72-
.withNewPgBouncer()
73-
.withNewPgbouncerIni()
74-
.endPgbouncerIni()
75-
.endPgBouncer()
76-
.endSpec()
76+
.withSpec(defaultPoolingConfigFactory.buildResource(cluster).getSpec())
7777
.build();
7878
}
7979

stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/factory/shardedcluster/ShardedClusterShardsDefaultInstanceProfile.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import io.stackgres.operator.conciliation.OperatorVersionBinder;
2020
import io.stackgres.operator.conciliation.ResourceGenerator;
2121
import io.stackgres.operator.conciliation.shardedcluster.StackGresShardedClusterContext;
22+
import io.stackgres.operator.initialization.DefaultProfileFactory;
2223
import io.stackgres.operatorframework.resource.ResourceUtil;
2324
import jakarta.inject.Inject;
2425
import jakarta.inject.Singleton;
@@ -29,10 +30,14 @@ public class ShardedClusterShardsDefaultInstanceProfile
2930
implements ResourceGenerator<StackGresShardedClusterContext> {
3031

3132
private final LabelFactoryForShardedCluster labelFactory;
33+
private final DefaultProfileFactory defaultProfileFactory;
3234

3335
@Inject
34-
public ShardedClusterShardsDefaultInstanceProfile(LabelFactoryForShardedCluster labelFactory) {
36+
public ShardedClusterShardsDefaultInstanceProfile(
37+
LabelFactoryForShardedCluster labelFactory,
38+
DefaultProfileFactory defaultProfileFactory) {
3539
this.labelFactory = labelFactory;
40+
this.defaultProfileFactory = defaultProfileFactory;
3641
}
3742

3843
@Override
@@ -66,8 +71,7 @@ private StackGresProfile getDefaultProfile(StackGresShardedCluster cluster) {
6671
.withName(cluster.getSpec().getShards().getSgInstanceProfile())
6772
.withLabels(labelFactory.defaultConfigLabels(cluster))
6873
.endMetadata()
69-
.withNewSpec()
70-
.endSpec()
74+
.withSpec(defaultProfileFactory.buildResource(cluster).getSpec())
7175
.build();
7276
}
7377

stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/factory/shardedcluster/ShardedClusterShardsDefaultPostgresConfig.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import io.stackgres.operator.conciliation.OperatorVersionBinder;
2020
import io.stackgres.operator.conciliation.ResourceGenerator;
2121
import io.stackgres.operator.conciliation.shardedcluster.StackGresShardedClusterContext;
22+
import io.stackgres.operator.initialization.DefaultShardedClusterPostgresConfigFactory;
2223
import io.stackgres.operatorframework.resource.ResourceUtil;
2324
import jakarta.inject.Inject;
2425
import jakarta.inject.Singleton;
@@ -29,10 +30,14 @@ public class ShardedClusterShardsDefaultPostgresConfig
2930
implements ResourceGenerator<StackGresShardedClusterContext> {
3031

3132
private final LabelFactoryForShardedCluster labelFactory;
33+
private final DefaultShardedClusterPostgresConfigFactory defaultShardedClusterPostgresConfigFactory;
3234

3335
@Inject
34-
public ShardedClusterShardsDefaultPostgresConfig(LabelFactoryForShardedCluster labelFactory) {
36+
public ShardedClusterShardsDefaultPostgresConfig(
37+
LabelFactoryForShardedCluster labelFactory,
38+
DefaultShardedClusterPostgresConfigFactory defaultShardedClusterPostgresConfigFactory) {
3539
this.labelFactory = labelFactory;
40+
this.defaultShardedClusterPostgresConfigFactory = defaultShardedClusterPostgresConfigFactory;
3641
}
3742

3843
@Override
@@ -67,15 +72,8 @@ private StackGresPostgresConfig getDefaultConfig(StackGresShardedCluster cluster
6772
.withName(cluster.getSpec().getShards().getConfigurations().getSgPostgresConfig())
6873
.withLabels(labelFactory.defaultConfigLabels(cluster))
6974
.endMetadata()
70-
.withNewSpec()
71-
.withPostgresVersion(getPostgresMajorVersion(cluster))
72-
.endSpec()
75+
.withSpec(defaultShardedClusterPostgresConfigFactory.buildResource(cluster).getSpec())
7376
.build();
7477
}
7578

76-
private String getPostgresMajorVersion(StackGresShardedCluster cluster) {
77-
String version = cluster.getSpec().getPostgres().getVersion();
78-
return version.split("\\.")[0];
79-
}
80-
8179
}

0 commit comments

Comments
 (0)