Skip to content

Commit

Permalink
feat: cn pool and cn claim support
Browse files Browse the repository at this point in the history
  • Loading branch information
aylei committed Jan 5, 2024
1 parent 78c9524 commit e60fd25
Show file tree
Hide file tree
Showing 41 changed files with 4,158 additions and 126 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.20 as builder
FROM golang:1.21 as builder

ARG GOPROXY="https://proxy.golang.org,direct"

Expand Down
134 changes: 134 additions & 0 deletions api/core/v1alpha1/cnclaim_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
// Copyright 2024 Matrix Origin
//
// 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"
)

type CNClaimPhase string

const (
CNClaimPhasePending CNClaimPhase = "Pending"
CNClaimPhaseBound CNClaimPhase = "Bound"
CNClaimPhaseLost CNClaimPhase = "Lost"
)

type CNClaimSpec struct {
Selector *metav1.LabelSelector `json:"selector"`
// +optional
CNLabels []CNLabel `json:"cnLabels,omitempty"`

// +optional
// PodName is usually populated by controller and would be part of the claim spec
// that must be persisted once bound
PodName string `json:"podName,omitempty"`

// +optional
// PoolName is usually populated by controller that which pool the claim is nominated
PoolName string `json:"poolName,omitempty"`
}

type CNClaimStatus struct {
Phase CNClaimPhase `json:"phase,omitempty"`
Store CNStoreStatus `json:"store,omitempty"`
}

type CNStoreStatus struct {
ServiceID string `json:"serviceID,omitempty"`
LockServiceAddress string `json:"lockServiceAddress,omitempty"`
PipelineServiceAddress string `json:"pipelineServiceAddress,omitempty"`
SQLAddress string `json:"sqlAddress,omitempty"`
QueryAddress string `json:"queryAddress,omitempty"`
WorkState int32 `json:"workState,omitempty"`
Labels []CNLabel `json:"labels,omitempty"`
}

// +kubebuilder:object:root=true

// CNClaim claim a CN to use
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Pod",type="string",JSONPath=".spec.podName"
// +kubebuilder:printcolumn:name="Phase",type="string",JSONPath=".status.phase"
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
// +kubebuilder:resource:scope="Namespaced"
type CNClaim struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec CNClaimSpec `json:"spec,omitempty"`

// +optional
Status CNClaimStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// CNClaimList contains a list of CNClaims
type CNClaimList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`

Items []CNClaim `json:"items"`
}

type CNClaimSetSpec struct {
Replicas int32 `json:"replicas"`
Template CNClaimTemplate `json:"template"`

Selector *metav1.LabelSelector `json:"selector,omitempty"`
}

type CNClaimTemplate struct {
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec CNClaimSpec `json:"spec,omitempty"`
}

type CNClaimSetStatus struct {
Replicas int32 `json:"replicas"`
Claims []CNClaimStatus `json:"claims,omitempty"`
}

// +kubebuilder:object:root=true

// CNClaimSet orchestrates a set of CNClaims
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
// +kubebuilder:resource:scope="Namespaced"
type CNClaimSet struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec CNClaimSetSpec `json:"spec,omitempty"`

// +optional
Status CNClaimSetStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// CNClaimSetList contains a list of CNClaimSet
type CNClaimSetList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`

Items []CNClaimSet `json:"items"`
}

func init() {
SchemeBuilder.Register(&CNClaim{}, &CNClaimList{})
SchemeBuilder.Register(&CNClaimSet{}, &CNClaimSetList{})
}
21 changes: 21 additions & 0 deletions api/core/v1alpha1/cnpool_helper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2024 Matrix Origin
//
// 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"

func IsPoolingPolicy(pod *corev1.Pod) bool {
return pod.Annotations[PodManagementPolicyAnno] == PodManagementPolicyPooling
}
117 changes: 117 additions & 0 deletions api/core/v1alpha1/cnpool_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// Copyright 2024 Matrix Origin
//
// 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"
"math"
)

const (
CNPodPhaseBound = "Bound"
CNPodPhaseIdle = "Idle"
CNPodPhaseDraining = "Draining"
CNPodPhaseUnknown = "Unknown"
CNPodPhaseTerminating = "Terminating"
)

const (
PodManagementPolicyPooling = "Pooling"
)

const (
// PodClaimedByLabel is a Pod label records the claim the claims the Pod
PodClaimedByLabel = "pool.matrixorigin.io/claimed-by"
// CNPodPhaseLabel is the pod phase in Pool
CNPodPhaseLabel = "pool.matrixorigin.io/phase"
// PoolNameLabel is the pool of CN claim or CN Pod
PoolNameLabel = "pool.matrixorigin.io/pool-name"

// PodManagementPolicyAnno denotes the management policy of a Pod
PodManagementPolicyAnno = "pool.matrixorigin.io/management-policy"
)

type CNPoolSpec struct {
// Template is the CNSet template of the Pool
Template CNSetSpec `json:"template"`

// PodLabels is the Pod labels of the CN in Pool
PodLabels map[string]string `json:"podLabels,omitempty"`

// Deps is the dependencies of the Pool
Deps CNSetDeps `json:"deps"`

Strategy PoolStrategy `json:"strategy"`
}

type PoolStrategy struct {
// UpdateStrategy defines the strategy for pool updating
UpdateStrategy PoolUpdateStrategy `json:"updateStrategy"`

// UpdateStrategy defines the strategy for pool scaling
ScaleStrategy PoolScaleStrategy `json:"scaleStrategy"`
}

type PoolUpdateStrategy struct {
// +optional
ReclaimTimeout *metav1.Duration `json:"reclaimTimeout,omitempty"`
}

type PoolScaleStrategy struct {
MaxIdle int32 `json:"maxIdle"`

// +optional
// MaxPods allowed in this Pool, nil means no limit
MaxPods *int32 `json:"maxPods,omitempty"`
}

func (s *PoolScaleStrategy) GetMaxPods() int32 {
if s.MaxPods == nil {
return math.MaxInt32
}
return *s.MaxPods
}

type CNPoolStatus struct {
}

// +kubebuilder:object:root=true

// CNPool maintains a pool of CN Pods
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
// +kubebuilder:resource:scope="Namespaced"
type CNPool struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec CNPoolSpec `json:"spec"`

// +optional
Status CNPoolStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&CNPool{}, &CNPoolList{})
}
13 changes: 9 additions & 4 deletions api/core/v1alpha1/cnset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@ type CNSetSpec struct {
// Labels are the CN labels for all the CN stores managed by this CNSet
Labels []CNLabel `json:"cnLabels,omitempty"`

// ExternalStoreControl indicates mo-operator should not sync CN store state and label
// so that the store state can be safely managed externally
ExternalStoreControl bool `json:"externalStoreControl,omitempty"`

// ScalingConfig declares the CN scaling behavior
ScalingConfig ScalingConfig `json:"scalingConfig,omitempty"`

Expand All @@ -89,6 +85,15 @@ type CNSetSpec struct {

// PythonUdfSidecar is the python udf server in CN
PythonUdfSidecar PythonUdfSidecar `json:"pythonUdfSidecar,omitempty"`

// PodManagementPolicy is the pod management policy of the Pod in this Set
PodManagementPolicy *string `json:"podManagementPolicy,omitempty"`

// PodsToDelete are the Pods to delete in the CNSet
PodsToDelete []string `json:"podsToDelete,omitempty"`

// PauseUpdate means the CNSet should pause rolling-update
PauseUpdate bool `json:"pauseUpdate,omitempty"`
}

type ScalingConfig struct {
Expand Down
4 changes: 0 additions & 4 deletions api/core/v1alpha1/store_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,4 @@ const (

// StoreCordonAnno cordons a CN store
StoreCordonAnno = "matrixorigin.io/store-cordon"

// StoreExternalControlledAnno marks the CN Pod as externally controlled so that
// CN state and labels performed by mo-operator will be skipped
StoreExternalControlledAnno = "matrixorigin.io/external-controlled"
)
Loading

0 comments on commit e60fd25

Please sign in to comment.