Skip to content

Commit

Permalink
feat: support heterogeneous pods by managing pods directly (apecloud#…
Browse files Browse the repository at this point in the history
  • Loading branch information
free6om authored Mar 21, 2024
1 parent a7a2301 commit 65c95ba
Show file tree
Hide file tree
Showing 104 changed files with 26,499 additions and 2,130 deletions.
107 changes: 89 additions & 18 deletions apis/apps/v1alpha1/cluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/intstr"

dpv1alpha1 "github.com/apecloud/kubeblocks/apis/dataprotection/v1alpha1"
Expand Down Expand Up @@ -306,6 +305,87 @@ type UserResourceRefs struct {
ConfigMapRefs []ConfigMapRef `json:"configMapRefs,omitempty"`
}

// InstanceTemplate defines values to override in pod template.
type InstanceTemplate struct {
// Number of replicas of this template.
// Default is 1.
// +kubebuilder:default=1
// +kubebuilder:validation:Minimum=0
// +optional
Replicas *int32 `json:"replicas,omitempty"`

// Defines the name of the instance.
// Only applied when Replicas is 1.
//
// +kubebuilder:validation:MaxLength=64
// +kubebuilder:validation:Pattern:=`^[a-z0-9]([a-z0-9\.\-]*[a-z0-9])?$`
// +optional
Name *string `json:"name,omitempty"`

// GenerateName is an optional prefix, used by the server, to generate a unique
// name ONLY IF the Name field has not been provided.
// If this field is used, the name returned to the client will be different
// than the name passed. This value will also be combined with a unique suffix.
// The provided value has the same validation rules as the Name field,
// and may be truncated by the length of the suffix required to make the value
// unique on the server.
//
// Applied only if Name is not specified.
//
// +kubebuilder:validation:MaxLength=54
// +kubebuilder:validation:Pattern:=`^[a-z0-9]([a-z0-9\.\-]*[a-z0-9])?$`
// +optional
GenerateName *string `json:"generateName,omitempty"`

// Defines annotations to override.
// Add new or override existing annotations.
// +optional
Annotations map[string]string `json:"annotations,omitempty"`

// Defines labels to override.
// Add new or override existing labels.
// +optional
Labels map[string]string `json:"labels,omitempty"`

// Defines image to override.
// Will override the first container's image of the pod.
// +optional
Image *string `json:"image,omitempty"`

// Defines NodeName to override.
// +optional
NodeName *string `json:"nodeName,omitempty"`

// Defines NodeSelector to override.
// +optional
NodeSelector map[string]string `json:"nodeSelector,omitempty"`

// Defines Tolerations to override.
// Add new or override existing tolerations.
// +optional
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`

// Defines Resources to override.
// Will override the first container's resources of the pod.
// +optional
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`

// Defines Volumes to override.
// Add new or override existing volumes.
// +optional
Volumes []corev1.Volume `json:"volumes,omitempty"`

// Defines VolumeMounts to override.
// Add new or override existing volume mounts of the first container in the pod.
// +optional
VolumeMounts []corev1.VolumeMount `json:"volumeMounts,omitempty"`

// Defines VolumeClaimTemplates to override.
// Add new or override existing volume claim templates.
// +optional
VolumeClaimTemplates []corev1.PersistentVolumeClaim `json:"volumeClaimTemplates,omitempty"`
}

// ClusterStatus defines the observed state of Cluster.
type ClusterStatus struct {
// The most recent generation number that has been observed by the controller.
Expand Down Expand Up @@ -524,26 +604,17 @@ type ClusterComponentSpec struct {
// +optional
UserResourceRefs *UserResourceRefs `json:"userResourceRefs,omitempty"`

// Defines the policy to generate sts using rsm.
// Overrides values in default Template.
//
// +kubebuilder:validation:Required
// +kubebuilder:default=ToSts
// +optional
RsmTransformPolicy workloads.RsmTransformPolicy `json:"rsmTransformPolicy,omitempty"`

// Defines the list of nodes that pods can schedule.
// If the RsmTransformPolicy is specified as ToPod, the list of nodes will be used. If the list of nodes is empty,
// no specific node will be assigned. However, if the list of nodes is filled, all pods will be evenly scheduled
// across the nodes in the list.
//
// +optional
Nodes []types.NodeName `json:"nodes,omitempty"`

// Defines the list of instances to be deleted priorly.
// If the RsmTransformPolicy is specified as ToPod, the list of instances will be used.
// Instance is the fundamental unit managed by KubeBlocks.
// It represents a Pod with additional objects such as PVCs, Services, ConfigMaps, etc.
// A component manages instances with a total count of Replicas,
// and by default, all these instances are generated from the same template.
// The InstanceTemplate provides a way to override values in the default template,
// allowing the component to manage instances from different templates.
//
// +optional
Instances []string `json:"instances,omitempty"`
Instances []InstanceTemplate `json:"instances,omitempty"`
}

type ComponentMessageMap map[string]string
Expand Down
26 changes: 2 additions & 24 deletions apis/apps/v1alpha1/component_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ package v1alpha1
import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"

workloads "github.com/apecloud/kubeblocks/apis/workloads/v1alpha1"
)

// ComponentSpec defines the desired state of Component
Expand Down Expand Up @@ -119,28 +116,9 @@ type ComponentSpec struct {
// +optional
TLSConfig *TLSConfig `json:"tlsConfig,omitempty"`

// Defines the policy generate sts using rsm.
//
// - ToSts: rsm transform to statefulSet
// - ToPod: rsm transform to pods
//
// +kubebuilder:validation:Required
// +kubebuilder:default=ToSts
// +optional
RsmTransformPolicy workloads.RsmTransformPolicy `json:"rsmTransformPolicy,omitempty"`

// Defines the list of nodes that pods can schedule
// If the RsmTransformPolicy is specified as OneToMul,the list of nodes will be used. If the list of nodes is empty,
// no specific node will be assigned. However, if the list of node is filled, all pods will be evenly scheduled
// across the nodes in the list.
//
// +optional
Nodes []types.NodeName `json:"nodes,omitempty"`

// Defines the list of instance to be deleted priorly
//
// Overrides values in default Template.
// +optional
Instances []string `json:"instances,omitempty"`
Instances []InstanceTemplate `json:"instances,omitempty"`
}

// ComponentStatus represents the observed state of a Component within the cluster.
Expand Down
20 changes: 0 additions & 20 deletions apis/apps/v1alpha1/opsrequest_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/intstr"
)

Expand Down Expand Up @@ -236,25 +235,6 @@ type HorizontalScaling struct {
// +kubebuilder:validation:Required
// +kubebuilder:validation:Minimum=0
Replicas int32 `json:"replicas"`

// Defines the list of nodes where pods can be scheduled during a scale-up operation.
// If the RsmTransformPolicy is set to ToPod and the expected number of replicas is greater than the current number,
// the list of Nodes will be used. If the list of Nodes is empty, pods will not be assigned to any specific node.
// However, if the list of Nodes is populated, pods will be evenly distributed across the nodes in the list during scale-up.
// +optional
Nodes []types.NodeName `json:"nodes,omitempty"`

// Defines the names of instances that the rsm should prioritize for scale-down operations.
// If the RsmTransformPolicy is set to ToPod and the expected number of replicas is less than the current number,
// the list of Instances will be used.
//
// - `current replicas - expected replicas > len(Instances)`: Scale down from the list of Instances priorly, the others
// will select from NodeAssignment.
// - `current replicas - expected replicas < len(Instances)`: Scale down from the list of Instances.
// - `current replicas - expected replicas < len(Instances)`: Scale down from a part of Instances.
//
// +optional
Instances []string `json:"instances,omitempty"`
}

// Reconfigure represents the variables required for updating a configuration.
Expand Down
Loading

0 comments on commit 65c95ba

Please sign in to comment.