Skip to content

Commit bb21a29

Browse files
committed
feat: allow to override SGInstanceProfile, SGPostgresConfig and SGPoolingConfig
1 parent 8b9ab61 commit bb21a29

23 files changed

Lines changed: 749 additions & 180 deletions

stackgres-k8s/src/common/src/main/java/io/stackgres/common/crd/sgcluster/StackGresClusterConfigurations.java

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import com.fasterxml.jackson.annotation.JsonInclude;
1414
import io.quarkus.runtime.annotations.RegisterForReflection;
1515
import io.stackgres.common.StackGresUtil;
16+
import io.stackgres.common.crd.sgpgconfig.StackGresPostgresConfigSpec;
17+
import io.stackgres.common.crd.sgpooling.StackGresPoolingConfigSpec;
1618
import io.stackgres.common.validation.FieldReference;
1719
import io.stackgres.common.validation.FieldReference.ReferencedField;
1820
import io.sundr.builder.annotations.Buildable;
@@ -31,6 +33,10 @@ public class StackGresClusterConfigurations {
3133

3234
private String sgPoolingConfig;
3335

36+
private StackGresPostgresConfigSpec postgres;
37+
38+
private StackGresPoolingConfigSpec pooling;
39+
3440
@Valid
3541
private List<StackGresClusterBackupConfiguration> backups;
3642

@@ -76,6 +82,22 @@ public void setSgPoolingConfig(String sgPoolingConfig) {
7682
this.sgPoolingConfig = sgPoolingConfig;
7783
}
7884

85+
public StackGresPostgresConfigSpec getPostgres() {
86+
return postgres;
87+
}
88+
89+
public void setPostgres(StackGresPostgresConfigSpec postgres) {
90+
this.postgres = postgres;
91+
}
92+
93+
public StackGresPoolingConfigSpec getPooling() {
94+
return pooling;
95+
}
96+
97+
public void setPooling(StackGresPoolingConfigSpec pooling) {
98+
this.pooling = pooling;
99+
}
100+
79101
public List<StackGresClusterBackupConfiguration> getBackups() {
80102
return backups;
81103
}
@@ -127,8 +149,8 @@ public void setPostgresExporter(StackGresClusterPostgresExporter postgresExporte
127149

128150
@Override
129151
public int hashCode() {
130-
return Objects.hash(backups, binding, credentials, observability, patroni, postgresExporter,
131-
sgPoolingConfig, sgPostgresConfig);
152+
return Objects.hash(backups, binding, credentials, observability, patroni, pooling, postgres,
153+
postgresExporter, sgPoolingConfig, sgPostgresConfig);
132154
}
133155

134156
@Override
@@ -143,7 +165,8 @@ public boolean equals(Object obj) {
143165
return Objects.equals(backups, other.backups) && Objects.equals(binding, other.binding)
144166
&& Objects.equals(credentials, other.credentials)
145167
&& Objects.equals(observability, other.observability)
146-
&& Objects.equals(patroni, other.patroni)
168+
&& Objects.equals(patroni, other.patroni) && Objects.equals(pooling, other.pooling)
169+
&& Objects.equals(postgres, other.postgres)
147170
&& Objects.equals(postgresExporter, other.postgresExporter)
148171
&& Objects.equals(sgPoolingConfig, other.sgPoolingConfig)
149172
&& Objects.equals(sgPostgresConfig, other.sgPostgresConfig);

stackgres-k8s/src/common/src/main/java/io/stackgres/common/crd/sgcluster/StackGresClusterResources.java

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55

66
package io.stackgres.common.crd.sgcluster;
77

8+
import java.util.Map;
89
import java.util.Objects;
910

1011
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
1112
import com.fasterxml.jackson.annotation.JsonInclude;
13+
import io.fabric8.kubernetes.api.model.ResourceRequirements;
1214
import io.quarkus.runtime.annotations.RegisterForReflection;
1315
import io.stackgres.common.StackGresUtil;
1416
import io.sundr.builder.annotations.Buildable;
@@ -21,12 +23,32 @@
2123
builderPackage = "io.fabric8.kubernetes.api.builder")
2224
public class StackGresClusterResources {
2325

26+
private Map<String, ResourceRequirements> containers;
27+
28+
private Map<String, ResourceRequirements> initContainers;
29+
2430
private Boolean enableClusterLimitsRequirements;
2531

2632
private Boolean disableResourcesRequestsSplitFromTotal;
2733

2834
private Boolean failWhenTotalIsHigher;
2935

36+
public Map<String, ResourceRequirements> getContainers() {
37+
return containers;
38+
}
39+
40+
public void setContainers(Map<String, ResourceRequirements> containers) {
41+
this.containers = containers;
42+
}
43+
44+
public Map<String, ResourceRequirements> getInitContainers() {
45+
return initContainers;
46+
}
47+
48+
public void setInitContainers(Map<String, ResourceRequirements> initContainers) {
49+
this.initContainers = initContainers;
50+
}
51+
3052
public Boolean getEnableClusterLimitsRequirements() {
3153
return enableClusterLimitsRequirements;
3254
}
@@ -54,8 +76,8 @@ public void setFailWhenTotalIsHigher(Boolean failWhenTotalIsHigher) {
5476

5577
@Override
5678
public int hashCode() {
57-
return Objects.hash(disableResourcesRequestsSplitFromTotal, enableClusterLimitsRequirements,
58-
failWhenTotalIsHigher);
79+
return Objects.hash(containers, disableResourcesRequestsSplitFromTotal,
80+
enableClusterLimitsRequirements, failWhenTotalIsHigher, initContainers);
5981
}
6082

6183
@Override
@@ -67,10 +89,12 @@ public boolean equals(Object obj) {
6789
return false;
6890
}
6991
StackGresClusterResources other = (StackGresClusterResources) obj;
70-
return Objects.equals(disableResourcesRequestsSplitFromTotal,
71-
other.disableResourcesRequestsSplitFromTotal)
92+
return Objects.equals(containers, other.containers)
93+
&& Objects.equals(disableResourcesRequestsSplitFromTotal,
94+
other.disableResourcesRequestsSplitFromTotal)
7295
&& Objects.equals(enableClusterLimitsRequirements, other.enableClusterLimitsRequirements)
73-
&& Objects.equals(failWhenTotalIsHigher, other.failWhenTotalIsHigher);
96+
&& Objects.equals(failWhenTotalIsHigher, other.failWhenTotalIsHigher)
97+
&& Objects.equals(initContainers, other.initContainers);
7498
}
7599

76100
@Override

stackgres-k8s/src/common/src/main/resources/crds/SGCluster.yaml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,15 @@ spec:
842842
type: object
843843
description: Pod custom resources configuration.
844844
properties:
845+
containers:
846+
type: object
847+
description: Resources configuration to be merged with the specified container on top of SGInstanceProfile referenced by `sgInstanceProfile` field if specified.
848+
additionalProperties: &resources #!jq_placeholder .definitions["io.k8s.api.core.v1.Container"].properties.resources
849+
{"description":"ResourceRequirements describes the compute resource requirements.","properties":{"claims":{"description":"Claims lists the names of resources, defined in spec.resourceClaims, that are used by this container.\n\nThis is an alpha field and requires enabling the DynamicResourceAllocation feature gate.\n\nThis field is immutable. It can only be set for containers.","items":{"description":"ResourceClaim references one entry in PodSpec.ResourceClaims.","properties":{"name":{"description":"Name must match the name of one entry in pod.spec.resourceClaims of the Pod where this field is used. It makes that resource available inside a container.","type":"string"},"request":{"description":"Request is the name chosen for a request in the referenced claim. If empty, everything from the claim is made available, otherwise only the result of this request.","type":"string"}},"required":["name"],"type":"object"},"type":"array"},"limits":{"additionalProperties":{"description":"Quantity is a fixed-point representation of a number. It provides convenient marshaling/unmarshaling in JSON and YAML, in addition to String() and AsInt64() accessors.\n\nThe serialization format is:\n\n``` <quantity> ::= <signedNumber><suffix>\n\n\t(Note that <suffix> may be empty, from the \"\" case in <decimalSI>.)\n\n<digit> ::= 0 | 1 | ... | 9 <digits> ::= <digit> | <digit><digits> <number> ::= <digits> | <digits>.<digits> | <digits>. | .<digits> <sign> ::= \"+\" | \"-\" <signedNumber> ::= <number> | <sign><number> <suffix> ::= <binarySI> | <decimalExponent> | <decimalSI> <binarySI> ::= Ki | Mi | Gi | Ti | Pi | Ei\n\n\t(International System of units; See: http://physics.nist.gov/cuu/Units/binary.html)\n\n<decimalSI> ::= m | \"\" | k | M | G | T | P | E\n\n\t(Note that 1024 = 1Ki but 1000 = 1k; I didn't choose the capitalization.)\n\n<decimalExponent> ::= \"e\" <signedNumber> | \"E\" <signedNumber> ```\n\nNo matter which of the three exponent forms is used, no quantity may represent a number greater than 2^63-1 in magnitude, nor may it have more than 3 decimal places. Numbers larger or more precise will be capped or rounded up. (E.g.: 0.1m will rounded up to 1m.) This may be extended in the future if we require larger or smaller quantities.\n\nWhen a Quantity is parsed from a string, it will remember the type of suffix it had, and will use the same type again when it is serialized.\n\nBefore serializing, Quantity will be put in \"canonical form\". This means that Exponent/suffix will be adjusted up or down (with a corresponding increase or decrease in Mantissa) such that:\n\n- No precision is lost - No fractional digits will be emitted - The exponent (or suffix) is as large as possible.\n\nThe sign will be omitted unless the number is negative.\n\nExamples:\n\n- 1.5 will be serialized as \"1500m\" - 1.5Gi will be serialized as \"1536Mi\"\n\nNote that the quantity will NEVER be internally represented by a floating point number. That is the whole point of this exercise.\n\nNon-canonical values will still parse as long as they are well formed, but will be re-emitted in their canonical form. (So always use canonical form, or don't diff.)\n\nThis format is intended to make it difficult to use these numbers without writing some sort of special handling code in the hopes that that will cause implementors to also use a fixed point implementation.","type":"string"},"description":"Limits describes the maximum amount of compute resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/","type":"object"},"requests":{"additionalProperties":{"description":"Quantity is a fixed-point representation of a number. It provides convenient marshaling/unmarshaling in JSON and YAML, in addition to String() and AsInt64() accessors.\n\nThe serialization format is:\n\n``` <quantity> ::= <signedNumber><suffix>\n\n\t(Note that <suffix> may be empty, from the \"\" case in <decimalSI>.)\n\n<digit> ::= 0 | 1 | ... | 9 <digits> ::= <digit> | <digit><digits> <number> ::= <digits> | <digits>.<digits> | <digits>. | .<digits> <sign> ::= \"+\" | \"-\" <signedNumber> ::= <number> | <sign><number> <suffix> ::= <binarySI> | <decimalExponent> | <decimalSI> <binarySI> ::= Ki | Mi | Gi | Ti | Pi | Ei\n\n\t(International System of units; See: http://physics.nist.gov/cuu/Units/binary.html)\n\n<decimalSI> ::= m | \"\" | k | M | G | T | P | E\n\n\t(Note that 1024 = 1Ki but 1000 = 1k; I didn't choose the capitalization.)\n\n<decimalExponent> ::= \"e\" <signedNumber> | \"E\" <signedNumber> ```\n\nNo matter which of the three exponent forms is used, no quantity may represent a number greater than 2^63-1 in magnitude, nor may it have more than 3 decimal places. Numbers larger or more precise will be capped or rounded up. (E.g.: 0.1m will rounded up to 1m.) This may be extended in the future if we require larger or smaller quantities.\n\nWhen a Quantity is parsed from a string, it will remember the type of suffix it had, and will use the same type again when it is serialized.\n\nBefore serializing, Quantity will be put in \"canonical form\". This means that Exponent/suffix will be adjusted up or down (with a corresponding increase or decrease in Mantissa) such that:\n\n- No precision is lost - No fractional digits will be emitted - The exponent (or suffix) is as large as possible.\n\nThe sign will be omitted unless the number is negative.\n\nExamples:\n\n- 1.5 will be serialized as \"1500m\" - 1.5Gi will be serialized as \"1536Mi\"\n\nNote that the quantity will NEVER be internally represented by a floating point number. That is the whole point of this exercise.\n\nNon-canonical values will still parse as long as they are well formed, but will be re-emitted in their canonical form. (So always use canonical form, or don't diff.)\n\nThis format is intended to make it difficult to use these numbers without writing some sort of special handling code in the hopes that that will cause implementors to also use a fixed point implementation.","type":"string"},"description":"Requests describes the minimum amount of compute resources required. If Requests is omitted for a container, it defaults to Limits if that is explicitly specified, otherwise to an implementation-defined value. Requests cannot exceed Limits. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/","type":"object"}},"type":"object"}
850+
initContainers:
851+
type: object
852+
description: Resources configuration to be merged with the specified init container on top of SGInstanceProfile referenced by `sgInstanceProfile` field if specified.
853+
additionalProperties: *resources
845854
enableClusterLimitsRequirements:
846855
type: boolean
847856
description: |
@@ -1080,6 +1089,56 @@ spec:
10801089
If not set, a default configuration will be used. Disabling connection pooling altogether is possible if the disableConnectionPooling property of the pods object is set to true.
10811090
10821091
**Changing this field may require a restart.**
1092+
postgres:
1093+
type: object
1094+
description: Section for postgres configuration.
1095+
properties:
1096+
postgresql.conf:
1097+
type: object
1098+
additionalProperties:
1099+
type: string
1100+
description: |
1101+
The `postgresql.conf` parameters that overwrite those specified in the referenced [SGPostgresConfig](https://stackgres.io/doc/latest/reference/crd/sgpgconfig).
1102+
1103+
**Changing this field may require a restart.**
1104+
pooling:
1105+
type: object
1106+
properties:
1107+
pgBouncer:
1108+
type: object
1109+
properties:
1110+
pgbouncer.ini:
1111+
type: object
1112+
description: |
1113+
The `pgbouncer.ini` parameters that overwrite those specified in the referenced [SGPoolingConfig](https://stackgres.io/doc/latest/reference/crd/sgpoolconfig).
1114+
1115+
**Changing this field may require a restart.**
1116+
properties:
1117+
pgbouncer:
1118+
type: object
1119+
additionalProperties: true
1120+
description: |
1121+
The `pgbouncer.ini` (Section [pgbouncer]) parameters the configuration contains, represented as an object where the keys are valid names for the `pgbouncer.ini` configuration file parameters.
1122+
1123+
Check [pgbouncer configuration](https://www.pgbouncer.org/config.html#generic-settings) for more information about supported parameters
1124+
databases:
1125+
type: object
1126+
additionalProperties:
1127+
type: object
1128+
additionalProperties: true
1129+
description: |
1130+
The `pgbouncer.ini` (Section [databases]) parameters the configuration contains, represented as an object where the keys are valid names for the `pgbouncer.ini` configuration file parameters.
1131+
1132+
Check [pgbouncer configuration](https://www.pgbouncer.org/config.html#section-databases) for more information about supported parameters.
1133+
users:
1134+
type: object
1135+
additionalProperties:
1136+
type: object
1137+
additionalProperties: true
1138+
description: |
1139+
The `pgbouncer.ini` (Section [users]) parameters the configuration contains, represented as an object where the keys are valid names for the `pgbouncer.ini` configuration file parameters.
1140+
1141+
Check [pgbouncer configuration](https://www.pgbouncer.org/config.html#section-users) for more information about supported parameters.
10831142
postgresExporter:
10841143
type: object
10851144
description: Section to configure the [postgres_exporter](https://github.com/prometheus-community/postgres_exporter) component.

0 commit comments

Comments
 (0)