-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
41 changed files
with
4,158 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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{}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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{}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.