Skip to content

Commit 21aeadc

Browse files
committed
fix: avoid overwrite sharded cluster objects during creation of dependent clusters
1 parent 34fbd76 commit 21aeadc

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/shardedcluster/context/ShardedClusterCoordinatorClusterContextAppender.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
package io.stackgres.operator.conciliation.shardedcluster.context;
77

8+
import com.fasterxml.jackson.databind.ObjectMapper;
89
import io.stackgres.common.crd.sgcluster.StackGresCluster;
910
import io.stackgres.common.crd.sgshardedcluster.StackGresShardedCluster;
1011
import io.stackgres.common.crd.sgshardedcluster.StackGresShardingType;
@@ -19,12 +20,15 @@ public class ShardedClusterCoordinatorClusterContextAppender {
1920

2021
private final ShardedClusterCoordinatorPrimaryEndpointsContextAppender
2122
shardedClusterCoordinatorPrimaryEndpointsContextAppender;
23+
private final ObjectMapper objectMapper;
2224

2325
public ShardedClusterCoordinatorClusterContextAppender(
2426
ShardedClusterCoordinatorPrimaryEndpointsContextAppender
25-
shardedClusterCoordinatorPrimaryEndpointsContextAppender) {
27+
shardedClusterCoordinatorPrimaryEndpointsContextAppender,
28+
ObjectMapper objectMapper) {
2629
this.shardedClusterCoordinatorPrimaryEndpointsContextAppender =
2730
shardedClusterCoordinatorPrimaryEndpointsContextAppender;
31+
this.objectMapper = objectMapper;
2832
}
2933

3034
public void appendContext(StackGresShardedCluster cluster, Builder contextBuilder) {
@@ -33,7 +37,8 @@ public void appendContext(StackGresShardedCluster cluster, Builder contextBuilde
3337
shardedClusterCoordinatorPrimaryEndpointsContextAppender.appendContext(coordinator, contextBuilder);
3438
}
3539

36-
private StackGresCluster getCoordinatorCluster(StackGresShardedCluster cluster) {
40+
private StackGresCluster getCoordinatorCluster(StackGresShardedCluster original) {
41+
StackGresShardedCluster cluster = objectMapper.convertValue(original, StackGresShardedCluster.class);
3742
switch (StackGresShardingType.fromString(cluster.getSpec().getType())) {
3843
case CITUS:
3944
return StackGresShardedClusterForCitusUtil.getCoordinatorCluster(cluster);

stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/shardedcluster/context/ShardedClusterShardsClustersContextAppender.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.util.List;
99
import java.util.stream.IntStream;
1010

11+
import com.fasterxml.jackson.databind.ObjectMapper;
1112
import io.stackgres.common.crd.sgcluster.StackGresCluster;
1213
import io.stackgres.common.crd.sgshardedcluster.StackGresShardedCluster;
1314
import io.stackgres.common.crd.sgshardedcluster.StackGresShardingType;
@@ -22,12 +23,15 @@ public class ShardedClusterShardsClustersContextAppender {
2223

2324
private final ShardedClusterShardsPrimaryEndpointsContextAppender
2425
shardedClusterShardsPrimaryEndpointsContextAppender;
26+
private final ObjectMapper objectMapper;
2527

2628
public ShardedClusterShardsClustersContextAppender(
2729
ShardedClusterShardsPrimaryEndpointsContextAppender
28-
shardedClusterShardsPrimaryEndpointsContextAppender) {
30+
shardedClusterShardsPrimaryEndpointsContextAppender,
31+
ObjectMapper objectMapper) {
2932
this.shardedClusterShardsPrimaryEndpointsContextAppender =
3033
shardedClusterShardsPrimaryEndpointsContextAppender;
34+
this.objectMapper = objectMapper;
3135
}
3236

3337
public void appendContext(StackGresShardedCluster cluster, Builder contextBuilder) {
@@ -42,7 +46,8 @@ private List<StackGresCluster> getShardsClusters(StackGresShardedCluster cluster
4246
.toList();
4347
}
4448

45-
private StackGresCluster getShardsCluster(StackGresShardedCluster cluster, int index) {
49+
private StackGresCluster getShardsCluster(StackGresShardedCluster original, int index) {
50+
StackGresShardedCluster cluster = objectMapper.convertValue(original, StackGresShardedCluster.class);
4651
switch (StackGresShardingType.fromString(cluster.getSpec().getType())) {
4752
case CITUS:
4853
return StackGresShardedClusterForCitusUtil.getShardsCluster(cluster, index);

0 commit comments

Comments
 (0)