Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 48 additions & 4 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,76 @@ resources:
namespaced: true
controller: true
domain: multigres.com
group: multigres
kind: MultiGateway
path: github.com/numtide/multigres-operator/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
domain: multigres.com
group: multigres
kind: MultiPooler
path: github.com/numtide/multigres-operator/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
domain: multigres.com
group: multigres
kind: Etcd
path: github.com/numtide/multigres-operator/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
domain: multigres.com
group: multigres
kind: MultiOrch
path: github.com/numtide/multigres-operator/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: multigres.com
kind: MultigresCluster
path: github.com/numtide/multigres-operator/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: false
domain: multigres.com
kind: DeploymentTemplate
path: github.com/numtide/multigres-operator/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: multigres.com
kind: TopoServer
path: github.com/numtide/multigres-operator/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: multigres.com
kind: Cell
path: github.com/numtide/multigres-operator/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: multigres.com
kind: TableGroup
path: github.com/numtide/multigres-operator/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: multigres.com
kind: Shard
path: github.com/numtide/multigres-operator/api/v1alpha1
version: v1alpha1
version: "3"
197 changes: 197 additions & 0 deletions api/v1alpha1/cell_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
/*
Copyright 2025.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// ============================================================================
// Cell Spec (Read-only API)
// ============================================================================

// CellSpec defines the desired state of Cell
// This spec is populated by the MultigresCluster controller.
type CellSpec struct {
// Name is the logical name of the cell.
// +kubebuilder:validation:MinLength:=1
// +kubebuilder:validation:MaxLength:=63
// +kubebuilder:validation:Pattern:="^[a-z0-9]([-a-z0-9]*[a-z0-9])?$"
Name string `json:"name"`

// Images required for this cell's components.
// +optional
Images CellImagesSpec `json:"images,omitempty"`

// MultiGateway defines the desired state of the MultiGateway deployment.
MultiGateway StatelessSpec `json:"multigateway"`

// MultiOrch defines the desired state of the MultiOrch deployment.
MultiOrch StatelessSpec `json:"multiorch"`

// GlobalTopoServer is a reference to the cluster-wide global topo server.
// This is always populated by the parent controller.
GlobalTopoServer GlobalTopoServerRefSpec `json:"globalTopoServer"`

// TopoServer defines the topology server configuration for this cell.
// If this is empty, the cell defaults to using the GlobalTopoServer.
TopoServer CellTopoServerSpec `json:"topoServer"`

// AllCells is a list of all cell names in the cluster for discovery.
// +optional
AllCells []string `json:"allCells,omitempty"`

// TopologyReconciliation defines flags for the cell controller's reconciliation logic.
// +optional
TopologyReconciliation TopologyReconciliationSpec `json:"topologyReconciliation,omitempty"`
}

// CellImagesSpec defines the images required for a Cell.
type CellImagesSpec struct {
// +optional
// +kubebuilder:validation:MinLength=1
MultiGateway string `json:"multigateway,omitempty"`
// +optional
// +kubebuilder:validation:MinLength=1
MultiOrch string `json:"multiorch,omitempty"`
}

// StatelessSpec defines the desired state for a scalable, stateless component
// like MultiAdmin, MultiOrch, or MultiGateway.
type StatelessSpec struct {
// Replicas is the desired number of pods.
// +kubebuilder:validation:Minimum=0
// +optional
Replicas *int32 `json:"replicas,omitempty"`

// Affinity defines the pod's scheduling constraints.
// +optional
Affinity *corev1.Affinity `json:"affinity,omitempty"`

// Resources defines the compute resource requirements.
// +optional
corev1.ResourceRequirements `json:"resources,omitempty"`
}
Comment on lines +74 to +89
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this is used by multiple resources, let's move this to a separate file


// GlobalTopoServerRefSpec defines a reference to the global topo server.
type GlobalTopoServerRefSpec struct {
// RootPath is the root path being used in the global topo server.
// +optional
RootPath string `json:"rootPath,omitempty"`

// ClientServiceName is the name of the etcd client service.
// +kubebuilder:validation:MinLength=1
// +optional
ClientServiceName string `json:"clientServiceName,omitempty"`
}

// CellTopoServerSpec defines the topology server configuration for this cell.
// Only one of External or ManagedSpec should be set.
// If neither is set, the cell uses the top-level GlobalTopoServer.
// +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"
type CellTopoServerSpec struct {
// External defines connection details for an unmanaged, external topo server.
// +optional
External *ExternalTopoServerSpec `json:"external,omitempty"`

// ManagedSpec defines the spec for a managed, cell-local topo server.
// If set, the Cell controller will create a child TopoServer CR.
// +optional
ManagedSpec *TopoServerSpec `json:"managedSpec,omitempty"`
}

// TopologyReconciliationSpec defines flags for the cell controller.
type TopologyReconciliationSpec struct {
// RegisterCell instructs the controller to register this cell in the topology.
// +optional
RegisterCell bool `json:"registerCell,omitempty"`

// PruneTablets instructs the controller to prune old tablets from the topology.
// +optional
PruneTablets bool `json:"pruneTablets,omitempty"`
}

// ============================================================================
// CR Controller Status Specs
// ============================================================================

// CellStatus defines the observed state of Cell
type CellStatus struct {
// ObservedGeneration is the most recent generation observed by the controller.
// +optional
ObservedGeneration int64 `json:"observedGeneration,omitempty"`

// Conditions represent the latest available observations of the Cell's state.
// +optional
Conditions []metav1.Condition `json:"conditions,omitempty"`

// GatewayReplicas is the current number of MultiGateway pods.
// +optional
GatewayReplicas int32 `json:"gatewayReplicas,omitempty"`

// GatewayReadyReplicas is the number of MultiGateway pods ready to serve requests.
// +optional
GatewayReadyReplicas int32 `json:"gatewayReadyReplicas,omitempty"`

// GatewayServiceName is the name of the MultiGateway service.
// +optional
GatewayServiceName string `json:"gatewayServiceName,omitempty"`

// MultiOrchAvailable indicates whether the MultiOrch deployment is available.
// +optional
MultiOrchAvailable metav1.ConditionStatus `json:"multiorchAvailable,omitempty"`

// TopoServerAvailable indicates whether the cell's topo server (local or global) is available.
// +optional
TopoServerAvailable metav1.ConditionStatus `json:"topoServerAvailable,omitempty"`
}

// ============================================================================
// Kind Definition and registration
// ============================================================================

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.conditions[?(@.type=='Available')].status",description="Current availability status"
// +kubebuilder:printcolumn:name="Gateway Ready",type="string",JSONPath=".status.gatewayReadyReplicas",description="Gateway ready replicas"
// +kubebuilder:printcolumn:name="Gateway Total",type="string",JSONPath=".status.gatewayReplicas",description="Gateway total replicas"
// +kubebuilder:printcolumn:name="Orch Ready",type="string",JSONPath=".status.multiorchAvailable",description="Orchestrator status"
// +kubebuilder:printcolumn:name="Topo Ready",type="string",JSONPath=".status.topoServerAvailable",description="Topo server status"
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"

// Cell is the Schema for the Cells API
type Cell struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec CellSpec `json:"spec,omitempty"`
Status CellStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// CellList contains a list of Cell
type CellList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Cell `json:"items"`
}

func init() {
SchemeBuilder.Register(&Cell{}, &CellList{})
}
86 changes: 86 additions & 0 deletions api/v1alpha1/deploymenttemplate_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
Copyright 2025.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// ============================================================================
// DeploymentTemplateSpec Spec (User-editable API)
// ============================================================================

// DeploymentTemplateSpec defines the desired state of DeploymentTemplate
// These are user editable and watched by MultigresCluster controller ONLY when referenced.
// +kubebuilder:validation:XValidation:rule="has(self.shardPool) || has(self.multiOrch) || has(self.multiGateway) || has(self.multiAdmin) || has(self.managedTopoServer)",message="a deployment template must define at least one template spec (e.g., shardPool, MultiOrch, etc.)"
type DeploymentTemplateSpec struct {
// ShardPool is the template for a MultiShard pool.
// +optional
ShardPool *ShardPoolSpec `json:"shardPool,omitempty"`

// MultiOrch is the template for a MultiOrch deployment.
// +optional
MultiOrch *StatelessSpec `json:"multiorch,omitempty"`

// MultiGateway is the template for a MultiGateway deployment.
// +optional
MultiGateway *StatelessSpec `json:"multigateway,omitempty"`

// MultiAdmin is the template for a MultiAdmin deployment.
// +optional
MultiAdmin *StatelessSpec `json:"multiadmin,omitempty"`

// ManagedTopoServer is the template for a managed TopoServer.
// +optional
ManagedTopoServer *TopoServerSpec `json:"managedTopoServer,omitempty"`
}

// ============================================================================
// CR Controller Status Specs
// ============================================================================
// No status is currently defined for this resource as per the design.

// ============================================================================
// Kind Definition and registration
// ============================================================================

// +kubebuilder:object:root=true
// +kubebuilder:resource:scope=Namespaced
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"

// DeploymentTemplate is the Schema for the DeploymentTemplates API
type DeploymentTemplate struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec DeploymentTemplateSpec `json:"spec,omitempty"`
// Status field removed as per design doc
// Status DeploymentTemplateStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// DeploymentTemplateList contains a list of DeploymentTemplate
type DeploymentTemplateList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []DeploymentTemplate `json:"items"`
}

func init() {
SchemeBuilder.Register(&DeploymentTemplate{}, &DeploymentTemplateList{})
}
Loading
Loading