Skip to content

Commit 0fec3ca

Browse files
Merge pull request #100 from numtide/default-restrictions
feat(api): enforce strict single-database topology via CEL validation and image settings to children
2 parents 5f1abed + 1e0225a commit 0fec3ca

File tree

4 files changed

+42
-11
lines changed

4 files changed

+42
-11
lines changed

api/v1alpha1/cell_types.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package v1alpha1
1818

1919
import (
20+
corev1 "k8s.io/api/core/v1"
2021
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2122
)
2223

@@ -45,9 +46,8 @@ type CellSpec struct {
4546
// +kubebuilder:validation:MaxLength=63
4647
Region string `json:"region,omitempty"`
4748

48-
// MultiGatewayImage is the image used for the gateway in this cell.
49-
// +kubebuilder:validation:MaxLength=512
50-
MultiGatewayImage string `json:"multigatewayImage"`
49+
// Images defines the container images used in this cell.
50+
Images CellImages `json:"images"`
5151

5252
// MultiGateway fully resolved config.
5353
MultiGateway StatelessSpec `json:"multigateway"`
@@ -69,6 +69,22 @@ type CellSpec struct {
6969
TopologyReconciliation TopologyReconciliation `json:"topologyReconciliation,omitempty"`
7070
}
7171

72+
// CellImages defines the images required for a Cell.
73+
type CellImages struct {
74+
// ImagePullPolicy overrides the default image pull policy.
75+
// +optional
76+
// +kubebuilder:validation:Enum=Always;Never;IfNotPresent
77+
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"`
78+
79+
// ImagePullSecrets is a list of references to secrets in the same namespace.
80+
// +optional
81+
ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
82+
83+
// MultiGateway is the image used for the gateway.
84+
// +kubebuilder:validation:MaxLength=512
85+
MultiGateway string `json:"multigateway"`
86+
}
87+
7288
// TopologyReconciliation defines flags for the cell controller.
7389
type TopologyReconciliation struct {
7490
// RegisterCell indicates if the cell should register itself in the topology.

api/v1alpha1/multigrescluster_types.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ type MultigresClusterSpec struct {
5555
// +optional
5656
// +listType=map
5757
// +listMapKey=name
58-
// +kubebuilder:validation:XValidation:rule="self.filter(x, has(x.default) && x.default).size() <= 1",message="only one database can be marked as default"
59-
// +kubebuilder:validation:MaxItems=50
58+
// +kubebuilder:validation:MaxItems=1
59+
// +kubebuilder:validation:XValidation:rule="self.all(db, db.name == 'postgres' && db.default == true)",message="in v1alpha1, only the single system database named 'postgres' (marked default: true) is supported"
6060
Databases []DatabaseConfig `json:"databases,omitempty"`
6161
}
6262

@@ -217,12 +217,13 @@ type DatabaseConfig struct {
217217
// +optional
218218
// +listType=map
219219
// +listMapKey=name
220-
// +kubebuilder:validation:XValidation:rule="self.filter(x, has(x.default) && x.default).size() <= 1",message="only one tablegroup can be marked as default"
220+
// +kubebuilder:validation:XValidation:rule="self.filter(x, has(x.default) && x.default).size() == 1",message="every database must have exactly one tablegroup marked as default"
221221
// +kubebuilder:validation:MaxItems=20
222222
TableGroups []TableGroupConfig `json:"tablegroups,omitempty"`
223223
}
224224

225225
// TableGroupConfig defines a table group within a database.
226+
// +kubebuilder:validation:XValidation:rule="!self.default || self.name == 'default'",message="the default tablegroup must be named 'default'"
226227
type TableGroupConfig struct {
227228
// Name is the logical name of the table group.
228229
// +kubebuilder:validation:MinLength=1

api/v1alpha1/shard_types.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,15 @@ type ShardSpec struct {
112112

113113
// ShardImages defines the images required for a Shard.
114114
type ShardImages struct {
115+
// ImagePullPolicy overrides the default image pull policy.
116+
// +optional
117+
// +kubebuilder:validation:Enum=Always;Never;IfNotPresent
118+
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"`
119+
120+
// ImagePullSecrets is a list of references to secrets in the same namespace.
121+
// +optional
122+
ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
123+
115124
// MultiOrch is the image for the shard orchestrator.
116125
// +kubebuilder:validation:MaxLength=512
117126
MultiOrch string `json:"multiorch"`

config/crd/bases/multigres.com_multigresclusters.yaml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6864,26 +6864,31 @@ spec:
68646864
required:
68656865
- name
68666866
type: object
6867+
x-kubernetes-validations:
6868+
- message: the default tablegroup must be named 'default'
6869+
rule: '!self.default || self.name == ''default'''
68676870
maxItems: 20
68686871
type: array
68696872
x-kubernetes-list-map-keys:
68706873
- name
68716874
x-kubernetes-list-type: map
68726875
x-kubernetes-validations:
6873-
- message: only one tablegroup can be marked as default
6874-
rule: self.filter(x, has(x.default) && x.default).size() <=
6876+
- message: every database must have exactly one tablegroup marked
6877+
as default
6878+
rule: self.filter(x, has(x.default) && x.default).size() ==
68756879
1
68766880
required:
68776881
- name
68786882
type: object
6879-
maxItems: 50
6883+
maxItems: 1
68806884
type: array
68816885
x-kubernetes-list-map-keys:
68826886
- name
68836887
x-kubernetes-list-type: map
68846888
x-kubernetes-validations:
6885-
- message: only one database can be marked as default
6886-
rule: self.filter(x, has(x.default) && x.default).size() <= 1
6889+
- message: 'in v1alpha1, only the single system database named ''postgres''
6890+
(marked default: true) is supported'
6891+
rule: self.all(db, db.name == 'postgres' && db.default == true)
68876892
globalTopoServer:
68886893
description: GlobalTopoServer defines the cluster-wide global topology
68896894
server.

0 commit comments

Comments
 (0)