Skip to content

Commit 94e0b6f

Browse files
authored
Merge pull request #66 from numtide/add-testutil-for-resource-watch
Add testutil for resource watching and declarative testing
2 parents 7690ea0 + c75a0bd commit 94e0b6f

19 files changed

+2077
-1465
lines changed

api/v1alpha1/cell_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ type GlobalTopoServerRefSpec struct {
103103
// CellTopoServerSpec defines the topology server configuration for this cell.
104104
// Only one of External or ManagedSpec should be set.
105105
// If neither is set, the cell uses the top-level GlobalTopoServer.
106-
// +kubebuilder:validation:XValidation:rule="(has(self.external) ? 1 : 0) + (has(self.managedSpec) ? 1 : 0) <= 1",message="only one of 'external' or 'managedSpec' can be set for topoServer"
106+
// TODO: Add validation when External field is uncommented
107107
type CellTopoServerSpec struct {
108108
// External defines connection details for an unmanaged, external topo server.
109109
// +optional

api/v1alpha1/shard_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ type ShardImagesSpec struct {
4949

5050
// ShardPoolSpec defines the desired state of a pool of shard replicas (e.g., primary, replica, read-only).
5151
// This is the core reusable spec for a shard's pod.
52-
// +kubebuilder:validation:XValidation:rule="!has(self.dataVolumeClaimTemplate) || (has(self.dataVolumeClaimTemplate.resources) && has(self.dataVolumeClaimTemplate.resources.requests) && has(self.dataVolumeClaimTemplate.resources.requests['storage']))",message="dataVolumeClaimTemplate must include a 'storage' resource request"
52+
// TODO: Re-enable storage validation when CEL cost budget is addressed (add maxItems to pools array)
5353
type ShardPoolSpec struct {
5454
// Type of the pool (e.g., "replica", "readOnly").
5555
// +kubebuilder:validation:Enum=replica;readOnly

api/v1alpha1/toposerver_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type TopoServerChildSpec struct {
4040
// TopoServerSpec defines the desired state of a managed etcd cluster.
4141
// This is reusable for both Global and Local TopoServers.
4242
// +kubebuilder:validation:XValidation:rule="!has(self.replicas) || self.replicas % 2 == 1",message="etcd cluster replicas should be an odd number (1, 3, 5, etc.)"
43-
// +kubebuilder:validation:XValidation:rule="!has(self.dataVolumeClaimTemplate) || (has(self.dataVolumeClaimTemplate.resources) && has(self.dataVolumeClaimTemplate.resources.requests) && has(self.dataVolumeClaimTemplate.resources.requests['storage']))",message="dataVolumeClaimTemplate must include a 'storage' resource request"
43+
// TODO: Re-enable storage validation after adding StorageSize/StorageClassName fields for simpler configuration
4444
type TopoServerSpec struct {
4545
// Image is the etcd container image to use.
4646
// +kubebuilder:validation:MinLength=1

config/.gitkeep

Whitespace-only changes.

config/crd/bases/multigres.com_cells.yaml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3283,17 +3283,7 @@ spec:
32833283
- message: etcd cluster replicas should be an odd number (1, 3,
32843284
5, etc.)
32853285
rule: '!has(self.replicas) || self.replicas % 2 == 1'
3286-
- message: dataVolumeClaimTemplate must include a 'storage' resource
3287-
request
3288-
rule: '!has(self.dataVolumeClaimTemplate) || (has(self.dataVolumeClaimTemplate.resources)
3289-
&& has(self.dataVolumeClaimTemplate.resources.requests) &&
3290-
has(self.dataVolumeClaimTemplate.resources.requests[''storage'']))'
32913286
type: object
3292-
x-kubernetes-validations:
3293-
- message: only one of 'external' or 'managedSpec' can be set for
3294-
topoServer
3295-
rule: '(has(self.external) ? 1 : 0) + (has(self.managedSpec) ? 1
3296-
: 0) <= 1'
32973287
topologyReconciliation:
32983288
description: TopologyReconciliation defines flags for the cell controller's
32993289
reconciliation logic.

config/crd/bases/multigres.com_multiorch_xs.yaml

Lines changed: 0 additions & 1422 deletions
This file was deleted.

config/crd/bases/multigres.com_shards.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,11 +1425,6 @@ spec:
14251425
- readOnly
14261426
type: string
14271427
type: object
1428-
x-kubernetes-validations:
1429-
- message: dataVolumeClaimTemplate must include a 'storage' resource
1430-
request
1431-
rule: '!has(self.dataVolumeClaimTemplate) || (has(self.dataVolumeClaimTemplate.resources)
1432-
&& has(self.dataVolumeClaimTemplate.resources.requests) && has(self.dataVolumeClaimTemplate.resources.requests[''storage'']))'
14331428
type: array
14341429
type: object
14351430
x-kubernetes-validations:

config/crd/bases/multigres.com_tablegroups.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,12 +1443,6 @@ spec:
14431443
- readOnly
14441444
type: string
14451445
type: object
1446-
x-kubernetes-validations:
1447-
- message: dataVolumeClaimTemplate must include a 'storage'
1448-
resource request
1449-
rule: '!has(self.dataVolumeClaimTemplate) || (has(self.dataVolumeClaimTemplate.resources)
1450-
&& has(self.dataVolumeClaimTemplate.resources.requests)
1451-
&& has(self.dataVolumeClaimTemplate.resources.requests[''storage'']))'
14521446
type: array
14531447
type: object
14541448
x-kubernetes-validations:

config/crd/bases/multigres.com_toposervers.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,9 +1250,6 @@ spec:
12501250
x-kubernetes-validations:
12511251
- message: etcd cluster replicas should be an odd number (1, 3, 5, etc.)
12521252
rule: '!has(self.replicas) || self.replicas % 2 == 1'
1253-
- message: dataVolumeClaimTemplate must include a 'storage' resource request
1254-
rule: '!has(self.dataVolumeClaimTemplate) || (has(self.dataVolumeClaimTemplate.resources)
1255-
&& has(self.dataVolumeClaimTemplate.resources.requests) && has(self.dataVolumeClaimTemplate.resources.requests[''storage'']))'
12561253
status:
12571254
description: TopoServerStatus defines the observed state of TopoServer
12581255
properties:

pkg/resource-handler/controller/etcd/etcd_controller.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"k8s.io/apimachinery/pkg/runtime"
1313
ctrl "sigs.k8s.io/controller-runtime"
1414
"sigs.k8s.io/controller-runtime/pkg/client"
15+
"sigs.k8s.io/controller-runtime/pkg/controller"
1516
"sigs.k8s.io/controller-runtime/pkg/log"
1617

1718
multigresv1alpha1 "github.com/numtide/multigres-operator/api/v1alpha1"
@@ -276,11 +277,16 @@ func (r *EtcdReconciler) buildConditions(
276277
}
277278

278279
// SetupWithManager sets up the controller with the Manager.
279-
// TODO: This is missing test coverage, and will need to use envtest setup.
280-
func (r *EtcdReconciler) SetupWithManager(mgr ctrl.Manager) error {
280+
func (r *EtcdReconciler) SetupWithManager(mgr ctrl.Manager, opts ...controller.Options) error {
281+
controllerOpts := controller.Options{}
282+
if len(opts) > 0 {
283+
controllerOpts = opts[0]
284+
}
285+
281286
return ctrl.NewControllerManagedBy(mgr).
282287
For(&multigresv1alpha1.Etcd{}).
283288
Owns(&appsv1.StatefulSet{}).
284289
Owns(&corev1.Service{}).
290+
WithOptions(controllerOpts).
285291
Complete(r)
286292
}

0 commit comments

Comments
 (0)