Skip to content

Commit a8567cd

Browse files
committed
fix: SGShardedCluster Endpoints are not generated in some scenarios
1 parent d29110f commit a8567cd

3 files changed

Lines changed: 50 additions & 3 deletions

File tree

stackgres-k8s/src/common/src/main/java/io/stackgres/common/crd/JsonArray.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,23 @@ public JsonArray(List<Object> list) {
3131
this.list = list;
3232
}
3333

34+
public JsonArray deepCopy() {
35+
return new JsonArray(stream()
36+
.map(this::deepCopy)
37+
.toList());
38+
}
39+
40+
@SuppressWarnings("unchecked")
41+
private Object deepCopy(Object value) {
42+
if (value instanceof Map map) {
43+
return new JsonObject((Map<String, Object>) map).deepCopy();
44+
}
45+
if (value instanceof List list) {
46+
return new JsonArray((List<Object>) list).deepCopy();
47+
}
48+
return value;
49+
}
50+
3451
@SuppressWarnings("unchecked")
3552
public Stream<JsonObject> streamObjects() {
3653
return stream()

stackgres-k8s/src/common/src/main/java/io/stackgres/common/crd/JsonObject.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,28 @@ public JsonObject(Map<String, Object> map) {
3030
this.map = map;
3131
}
3232

33+
public JsonObject deepCopy() {
34+
return new JsonObject(entrySet().stream()
35+
.reduce(
36+
new HashMap<String, Object>(size()),
37+
(map, entry) -> {
38+
map.put(entry.getKey(), deepCopy(entry.getValue()));
39+
return map;
40+
},
41+
(u, v) -> v));
42+
}
43+
44+
@SuppressWarnings("unchecked")
45+
private Object deepCopy(Object value) {
46+
if (value instanceof Map map) {
47+
return new JsonObject((Map<String, Object>) map).deepCopy();
48+
}
49+
if (value instanceof List list) {
50+
return new JsonArray((List<Object>) list).deepCopy();
51+
}
52+
return value;
53+
}
54+
3355
public boolean hasObject(String key) {
3456
Object value = get(key);
3557
return value != null && value instanceof Map;

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,20 @@ private void setConfigurationsPatroniInitialConfig(
8888
if (spec.getConfigurations() == null) {
8989
spec.setConfigurations(new StackGresClusterConfigurations());
9090
}
91-
if (spec.getConfigurations().getPatroni() == null) {
92-
spec.getConfigurations().setPatroni(new StackGresClusterPatroni());
91+
StackGresClusterPatroni patroni = spec.getConfigurations().getPatroni();
92+
spec.getConfigurations().setPatroni(new StackGresClusterPatroni());
93+
if (patroni == null) {
94+
patroni = new StackGresClusterPatroni();
9395
}
94-
if (spec.getConfigurations().getPatroni().getInitialConfig() == null) {
96+
spec.getConfigurations().getPatroni().setDynamicConfig(patroni.getDynamicConfig());
97+
if (patroni.getInitialConfig() == null) {
9598
spec.getConfigurations().getPatroni()
9699
.setInitialConfig(new StackGresClusterPatroniConfig());
100+
} else {
101+
spec.getConfigurations().getPatroni()
102+
.setInitialConfig(
103+
new StackGresClusterPatroniConfig(
104+
patroni.getInitialConfig().deepCopy()));
97105
}
98106
spec.getConfigurations().getPatroni().getInitialConfig()
99107
.put("scope", cluster.getMetadata().getName());

0 commit comments

Comments
 (0)