Skip to content

Commit f8572cb

Browse files
api: refactor TopoServer API to be polymorphic and restrict CoreTemplate scope
Updates the `TopoServer` and `CoreTemplate` definitions to improve extensibility and strictness. Changes: - Updates `TopoServerSpec` (Child CR) to wrap its configuration under an `etcd` key. This creates a polymorphic structure that can be extended with other backends (e.g., `consul`) in the future without breaking changes. - Updates `CoreTemplate` to use `TopoServerSpec` for `GlobalTopoServer` instead of the cluster-level spec. This: 1. Prevents templates from referencing other templates (removing recursion risks). 2. Restricts templates to defining "Managed" workloads only, excluding environment-specific `external` configurations. - Consolidates the usage of `EtcdSpec` across both Parent and Child resources for consistent schema definitions.
1 parent 1d02795 commit f8572cb

File tree

5 files changed

+104
-144
lines changed

5 files changed

+104
-144
lines changed

api/v1alpha1/coretemplate_types.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ import (
2727
// CoreTemplateSpec defines reusable config for core components (GlobalTopo, MultiAdmin).
2828
type CoreTemplateSpec struct {
2929
// GlobalTopoServer configuration.
30+
// Uses TopoServerSpec directly (Managed Etcd only).
3031
// +optional
31-
GlobalTopoServer *GlobalTopoServerSpec `json:"globalTopoServer,omitempty"`
32+
GlobalTopoServer *TopoServerSpec `json:"globalTopoServer,omitempty"`
3233

3334
// MultiAdmin configuration.
3435
// +optional

api/v1alpha1/toposerver_types.go

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,11 @@ import (
3232
// +kubebuilder:validation:MaxLength=2048
3333
type EndpointUrl string
3434

35-
// TopoServerSpec defines the desired state of TopoServer.
35+
// TopoServerSpec defines the desired state of TopoServer (Child CR).
36+
// +kubebuilder:validation:XValidation:rule="has(self.etcd)",message="must specify 'etcd' configuration"
3637
type TopoServerSpec struct {
37-
// Replicas is the desired number of etcd members.
38-
// +kubebuilder:validation:Minimum=1
39-
Replicas int32 `json:"replicas"`
40-
41-
// Storage configuration.
42-
Storage StorageSpec `json:"storage"`
43-
44-
// Image to use for Etcd.
45-
// +kubebuilder:validation:MinLength=1
46-
// +kubebuilder:validation:MaxLength=512
47-
Image string `json:"image"`
48-
49-
// Resources defines the compute resource requirements.
50-
// +optional
51-
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
38+
// Etcd defines the configuration if using Etcd.
39+
Etcd *EtcdSpec `json:"etcd,omitempty"`
5240
}
5341

5442
// ============================================================================

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 6 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/multigres.com_coretemplates.yaml

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,12 @@ spec:
4141
(GlobalTopo, MultiAdmin).
4242
properties:
4343
globalTopoServer:
44-
description: GlobalTopoServer configuration.
44+
description: |-
45+
GlobalTopoServer configuration.
46+
Uses TopoServerSpec directly (Managed Etcd only).
4547
properties:
4648
etcd:
47-
description: Etcd defines an inline managed Etcd cluster.
49+
description: Etcd defines the configuration if using Etcd.
4850
properties:
4951
image:
5052
description: Image is the Etcd container image.
@@ -130,48 +132,10 @@ spec:
130132
type: string
131133
type: object
132134
type: object
133-
external:
134-
description: External defines connection details for an unmanaged,
135-
external topo server.
136-
properties:
137-
caSecret:
138-
description: CASecret is the name of the secret containing
139-
the CA certificate.
140-
maxLength: 253
141-
type: string
142-
clientCertSecret:
143-
description: ClientCertSecret is the name of the secret containing
144-
the client cert/key.
145-
maxLength: 253
146-
type: string
147-
endpoints:
148-
description: Endpoints is a list of client URLs.
149-
items:
150-
description: EndpointUrl is a string restricted to 2048
151-
characters for strict validation budgeting.
152-
maxLength: 2048
153-
minLength: 1
154-
type: string
155-
maxItems: 20
156-
minItems: 1
157-
type: array
158-
x-kubernetes-validations:
159-
- message: endpoints must be valid URLs
160-
rule: self.all(x, x.matches('^https?://'))
161-
required:
162-
- endpoints
163-
type: object
164-
templateRef:
165-
description: TemplateRef refers to a CoreTemplate to load configuration
166-
from.
167-
maxLength: 63
168-
minLength: 1
169-
type: string
170135
type: object
171136
x-kubernetes-validations:
172-
- message: must specify exactly one of 'etcd', 'external', or 'templateRef'
173-
rule: '[has(self.etcd), has(self.external), has(self.templateRef)].filter(x,
174-
x).size() == 1'
137+
- message: must specify 'etcd' configuration
138+
rule: has(self.etcd)
175139
multiadmin:
176140
description: MultiAdmin configuration.
177141
properties:

config/crd/bases/multigres.com_toposervers.yaml

Lines changed: 86 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -41,96 +41,100 @@ spec:
4141
metadata:
4242
type: object
4343
spec:
44-
description: TopoServerSpec defines the desired state of TopoServer.
44+
description: TopoServerSpec defines the desired state of TopoServer (Child
45+
CR).
4546
properties:
46-
image:
47-
description: Image to use for Etcd.
48-
maxLength: 512
49-
minLength: 1
50-
type: string
51-
replicas:
52-
description: Replicas is the desired number of etcd members.
53-
format: int32
54-
minimum: 1
55-
type: integer
56-
resources:
57-
description: Resources defines the compute resource requirements.
47+
etcd:
48+
description: Etcd defines the configuration if using Etcd.
5849
properties:
59-
claims:
60-
description: |-
61-
Claims lists the names of resources, defined in spec.resourceClaims,
62-
that are used by this container.
50+
image:
51+
description: Image is the Etcd container image.
52+
maxLength: 512
53+
minLength: 1
54+
type: string
55+
replicas:
56+
description: Replicas is the desired number of etcd members.
57+
format: int32
58+
minimum: 1
59+
type: integer
60+
resources:
61+
description: Resources defines the compute resource requirements.
62+
properties:
63+
claims:
64+
description: |-
65+
Claims lists the names of resources, defined in spec.resourceClaims,
66+
that are used by this container.
6367
64-
This field depends on the
65-
DynamicResourceAllocation feature gate.
68+
This field depends on the
69+
DynamicResourceAllocation feature gate.
6670
67-
This field is immutable. It can only be set for containers.
68-
items:
69-
description: ResourceClaim references one entry in PodSpec.ResourceClaims.
70-
properties:
71-
name:
72-
description: |-
73-
Name must match the name of one entry in pod.spec.resourceClaims of
74-
the Pod where this field is used. It makes that resource available
75-
inside a container.
76-
type: string
77-
request:
78-
description: |-
79-
Request is the name chosen for a request in the referenced claim.
80-
If empty, everything from the claim is made available, otherwise
81-
only the result of this request.
82-
type: string
83-
required:
84-
- name
85-
type: object
86-
type: array
87-
x-kubernetes-list-map-keys:
88-
- name
89-
x-kubernetes-list-type: map
90-
limits:
91-
additionalProperties:
92-
anyOf:
93-
- type: integer
94-
- type: string
95-
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
96-
x-kubernetes-int-or-string: true
97-
description: |-
98-
Limits describes the maximum amount of compute resources allowed.
99-
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
71+
This field is immutable. It can only be set for containers.
72+
items:
73+
description: ResourceClaim references one entry in PodSpec.ResourceClaims.
74+
properties:
75+
name:
76+
description: |-
77+
Name must match the name of one entry in pod.spec.resourceClaims of
78+
the Pod where this field is used. It makes that resource available
79+
inside a container.
80+
type: string
81+
request:
82+
description: |-
83+
Request is the name chosen for a request in the referenced claim.
84+
If empty, everything from the claim is made available, otherwise
85+
only the result of this request.
86+
type: string
87+
required:
88+
- name
89+
type: object
90+
type: array
91+
x-kubernetes-list-map-keys:
92+
- name
93+
x-kubernetes-list-type: map
94+
limits:
95+
additionalProperties:
96+
anyOf:
97+
- type: integer
98+
- type: string
99+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
100+
x-kubernetes-int-or-string: true
101+
description: |-
102+
Limits describes the maximum amount of compute resources allowed.
103+
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
104+
type: object
105+
requests:
106+
additionalProperties:
107+
anyOf:
108+
- type: integer
109+
- type: string
110+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
111+
x-kubernetes-int-or-string: true
112+
description: |-
113+
Requests describes the minimum amount of compute resources required.
114+
If Requests is omitted for a container, it defaults to Limits if that is explicitly specified,
115+
otherwise to an implementation-defined value. Requests cannot exceed Limits.
116+
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
117+
type: object
100118
type: object
101-
requests:
102-
additionalProperties:
103-
anyOf:
104-
- type: integer
105-
- type: string
106-
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
107-
x-kubernetes-int-or-string: true
108-
description: |-
109-
Requests describes the minimum amount of compute resources required.
110-
If Requests is omitted for a container, it defaults to Limits if that is explicitly specified,
111-
otherwise to an implementation-defined value. Requests cannot exceed Limits.
112-
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
119+
storage:
120+
description: Storage configuration for Etcd data.
121+
properties:
122+
class:
123+
description: Class is the StorageClass name.
124+
maxLength: 63
125+
minLength: 1
126+
type: string
127+
size:
128+
description: Size of the persistent volume.
129+
maxLength: 63
130+
pattern: ^([0-9]+)(.+)$
131+
type: string
113132
type: object
114133
type: object
115-
storage:
116-
description: Storage configuration.
117-
properties:
118-
class:
119-
description: Class is the StorageClass name.
120-
maxLength: 63
121-
minLength: 1
122-
type: string
123-
size:
124-
description: Size of the persistent volume.
125-
maxLength: 63
126-
pattern: ^([0-9]+)(.+)$
127-
type: string
128-
type: object
129-
required:
130-
- image
131-
- replicas
132-
- storage
133134
type: object
135+
x-kubernetes-validations:
136+
- message: must specify 'etcd' configuration
137+
rule: has(self.etcd)
134138
status:
135139
description: TopoServerStatus defines the observed state of TopoServer.
136140
properties:

0 commit comments

Comments
 (0)