Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feature/refactor-role
Browse files Browse the repository at this point in the history
  • Loading branch information
cjc7373 committed Jan 14, 2025
2 parents 253a236 + 982672d commit adbf63c
Show file tree
Hide file tree
Showing 113 changed files with 2,612 additions and 1,252 deletions.
11 changes: 11 additions & 0 deletions apis/apps/v1/cluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,17 @@ type ClusterBackup struct {
// +kubebuilder:default=false
// +optional
PITREnabled *bool `json:"pitrEnabled,omitempty"`

// Specifies whether to enable incremental backup.
//
// +kubebuilder:default=false
// +optional
IncrementalBackupEnabled *bool `json:"incrementalBackupEnabled,omitempty"`

// The cron expression for the incremental backup schedule. The timezone is in UTC. See https://en.wikipedia.org/wiki/Cron.
//
// +optional
IncrementalCronExpression string `json:"incrementalCronExpression,omitempty"`
}

// ClusterPhase defines the phase of the Cluster within the .status.phase field.
Expand Down
17 changes: 9 additions & 8 deletions apis/apps/v1/deprecated.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,21 +160,22 @@ func (r *ClusterComponentVolumeClaimTemplate) toVolumeClaimTemplate() corev1.Per

func (r *PersistentVolumeClaimSpec) ToV1PersistentVolumeClaimSpec() corev1.PersistentVolumeClaimSpec {
return corev1.PersistentVolumeClaimSpec{
AccessModes: r.AccessModes,
Resources: r.Resources,
StorageClassName: r.getStorageClassName(viper.GetString(constant.CfgKeyDefaultStorageClass)),
VolumeMode: r.VolumeMode,
AccessModes: r.AccessModes,
Resources: r.Resources,
StorageClassName: r.getStorageClassName(viper.GetString(constant.CfgKeyDefaultStorageClass)),
VolumeMode: r.VolumeMode,
VolumeAttributesClassName: r.VolumeAttributesClassName,
}
}

// getStorageClassName returns PersistentVolumeClaimSpec.StorageClassName if a value is assigned; otherwise,
// it returns preferSC argument.
func (r *PersistentVolumeClaimSpec) getStorageClassName(preferSC string) *string {
// it returns the defaultStorageClass argument.
func (r *PersistentVolumeClaimSpec) getStorageClassName(defaultStorageClass string) *string {
if r.StorageClassName != nil && *r.StorageClassName != "" {
return r.StorageClassName
}
if preferSC != "" {
return &preferSC
if defaultStorageClass != "" {
return &defaultStorageClass
}
return nil
}
Expand Down
7 changes: 7 additions & 0 deletions apis/apps/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,13 @@ type PersistentVolumeClaimSpec struct {
//
// +optional
VolumeMode *corev1.PersistentVolumeMode `json:"volumeMode,omitempty" protobuf:"bytes,6,opt,name=volumeMode,casttype=PersistentVolumeMode"`

// volumeAttributesClassName may be used to set the VolumeAttributesClass used by this claim.
//
// More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#volumeattributesclass
//
// +optional
VolumeAttributesClassName *string `json:"volumeAttributesClassName,omitempty"`
}

type Service struct {
Expand Down
10 changes: 10 additions & 0 deletions apis/apps/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

91 changes: 59 additions & 32 deletions apis/apps/v1alpha1/cluster_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,19 +131,26 @@ func (r *Cluster) changesToCluster(cluster *appsv1.Cluster) {
compSpec := r.Spec.ComponentSpecs[i]
r.toComponentSpec(compSpec, &cluster.Spec.ComponentSpecs[i], compSpec.Name)
}
var shardingRequiredPodAntiAffinity []string
for i := range r.Spec.ShardingSpecs {
shardingSpec := r.Spec.ShardingSpecs[i]
podAntiAffinityRequired := r.toComponentSpec(shardingSpec.Template, &cluster.Spec.Shardings[i].Template, shardingSpec.Name)
if podAntiAffinityRequired {
shardingRequiredPodAntiAffinity = append(shardingRequiredPodAntiAffinity, shardingSpec.Name)

if len(r.Spec.ShardingSpecs) > 0 {
var shardingRequiredPodAntiAffinity []string
cluster.Spec.Shardings = make([]appsv1.ClusterSharding, len(r.Spec.ShardingSpecs))
for i := range r.Spec.ShardingSpecs {
shardingSpec := r.Spec.ShardingSpecs[i]
// copy sharding spec
_ = copier.Copy(&cluster.Spec.Shardings[i], &shardingSpec)
// transformer schedulePolicy
podAntiAffinityRequired := r.toComponentSpec(shardingSpec.Template, &cluster.Spec.Shardings[i].Template, shardingSpec.Name)
if podAntiAffinityRequired {
shardingRequiredPodAntiAffinity = append(shardingRequiredPodAntiAffinity, shardingSpec.Name)
}
}
}
if len(shardingRequiredPodAntiAffinity) > 0 {
if cluster.Annotations == nil {
cluster.Annotations = make(map[string]string)
if len(shardingRequiredPodAntiAffinity) > 0 {
if cluster.Annotations == nil {
cluster.Annotations = make(map[string]string)
}
cluster.Annotations["apps.kubeblocks.io/shard-pod-anti-affinity"] = strings.Join(shardingRequiredPodAntiAffinity, ",")
}
cluster.Annotations["apps.kubeblocks.io/shard-pod-anti-affinity"] = strings.Join(shardingRequiredPodAntiAffinity, ",")
}
}

Expand Down Expand Up @@ -192,7 +199,7 @@ func (r *Cluster) changesFromCluster(cluster *appsv1.Cluster) {
// spec:
// resources: corev1.ResourceRequirements -> corev1.VolumeResourceRequirements
// podUpdatePolicy: *workloads.PodUpdatePolicyType -> *PodUpdatePolicyType
// sharings
// shardingSpecs -> shardings
// - template
// volumeClaimTemplates
// spec:
Expand All @@ -205,6 +212,12 @@ func (r *Cluster) changesFromCluster(cluster *appsv1.Cluster) {
if len(cluster.Spec.ClusterDef) > 0 {
r.Spec.ClusterDefRef = cluster.Spec.ClusterDef
}

for i := range cluster.Spec.Shardings {
shardingSpec := cluster.Spec.Shardings[i]
// copy from sharding spec
_ = copier.Copy(&r.Spec.ShardingSpecs[i], &shardingSpec)
}
}

type clusterConverter struct {
Expand All @@ -213,19 +226,19 @@ type clusterConverter struct {
}

type clusterSpecConverter struct {
ClusterDefRef string `json:"clusterDefinitionRef,omitempty"`
ClusterVersionRef string `json:"clusterVersionRef,omitempty"`
TerminationPolicy TerminationPolicyType `json:"terminationPolicy"`
Affinity *Affinity `json:"affinity,omitempty"`
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
Tenancy TenancyType `json:"tenancy,omitempty"`
AvailabilityPolicy AvailabilityPolicyType `json:"availabilityPolicy,omitempty"`
Replicas *int32 `json:"replicas,omitempty"`
Resources ClusterResources `json:"resources,omitempty"`
Storage ClusterStorage `json:"storage,omitempty"`
Network *ClusterNetwork `json:"network,omitempty"`
Components map[string]clusterCompConverter `json:"components,omitempty"`
Shardings map[string]clusterCompConverter `json:"shardings,omitempty"`
ClusterDefRef string `json:"clusterDefinitionRef,omitempty"`
ClusterVersionRef string `json:"clusterVersionRef,omitempty"`
TerminationPolicy TerminationPolicyType `json:"terminationPolicy"`
Affinity *Affinity `json:"affinity,omitempty"`
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
Tenancy TenancyType `json:"tenancy,omitempty"`
AvailabilityPolicy AvailabilityPolicyType `json:"availabilityPolicy,omitempty"`
Replicas *int32 `json:"replicas,omitempty"`
Resources ClusterResources `json:"resources,omitempty"`
Storage ClusterStorage `json:"storage,omitempty"`
Network *ClusterNetwork `json:"network,omitempty"`
Components map[string]clusterCompConverter `json:"components,omitempty"`
Shardings map[string]clusterShardConverter `json:"shardings,omitempty"`
}

type clusterCompConverter struct {
Expand All @@ -241,6 +254,12 @@ type clusterCompConverter struct {
Monitor *bool `json:"monitor,omitempty"`
}

type clusterShardConverter struct {
shards int32
index int
clusterCompConverter
}

type clusterStatusConverter struct {
Components map[string]clusterCompStatusConverter `json:"components,omitempty"`
}
Expand Down Expand Up @@ -285,9 +304,13 @@ func (c *clusterConverter) fromCluster(cluster *Cluster) {
}
}
if len(cluster.Spec.ShardingSpecs) > 0 {
c.Spec.Shardings = make(map[string]clusterCompConverter)
for _, sharding := range cluster.Spec.ShardingSpecs {
c.Spec.Shardings[sharding.Name] = deletedComp(sharding.Template)
c.Spec.Shardings = make(map[string]clusterShardConverter)
for i, sharding := range cluster.Spec.ShardingSpecs {
c.Spec.Shardings[sharding.Name] = clusterShardConverter{
shards: sharding.Shards,
index: i,
clusterCompConverter: deletedComp(sharding.Template),
}
}
}

Expand Down Expand Up @@ -334,10 +357,14 @@ func (c *clusterConverter) toCluster(cluster *Cluster) {
deletedComp(comp, &cluster.Spec.ComponentSpecs[i])
}
}
for i, spec := range cluster.Spec.ShardingSpecs {
template, ok := c.Spec.Shardings[spec.Name]
if ok {
deletedComp(template, &cluster.Spec.ShardingSpecs[i].Template)
if len(c.Spec.Shardings) > 0 {
cluster.Spec.ShardingSpecs = make([]ShardingSpec, len(c.Spec.Shardings))
for shardName, shardSpec := range c.Spec.Shardings {
cluster.Spec.ShardingSpecs[shardSpec.index] = ShardingSpec{
Name: shardName,
Shards: shardSpec.shards,
}
deletedComp(shardSpec.clusterCompConverter, &cluster.Spec.ShardingSpecs[shardSpec.index].Template)
}
}

Expand Down
11 changes: 11 additions & 0 deletions apis/apps/v1alpha1/cluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,17 @@ type ClusterBackup struct {
// +kubebuilder:default=false
// +optional
PITREnabled *bool `json:"pitrEnabled,omitempty"`

// Specifies whether to enable incremental backup.
//
// +kubebuilder:default=false
// +optional
IncrementalBackupEnabled *bool `json:"incrementalBackupEnabled,omitempty"`

// The cron expression for the incremental backup schedule. The timezone is in UTC. See https://en.wikipedia.org/wiki/Cron.
//
// +optional
IncrementalCronExpression string `json:"incrementalCronExpression,omitempty"`
}

// ClusterResources is deprecated since v0.9.
Expand Down
5 changes: 5 additions & 0 deletions apis/apps/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 21 additions & 7 deletions apis/operations/v1alpha1/opsrequest_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,6 @@ type SpecificOpsRequest struct {
// Lists Switchover objects, each specifying a Component to perform the switchover operation.
//
// +optional
// +patchMergeKey=componentName
// +patchStrategy=merge,retainKeys
// +listType=map
// +listMapKey=componentName
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="forbidden to update spec.switchover"
SwitchoverList []Switchover `json:"switchover,omitempty" patchStrategy:"merge,retainKeys" patchMergeKey:"componentName"`

Expand Down Expand Up @@ -239,7 +235,7 @@ type SpecificOpsRequest struct {

// ComponentOps specifies the Component to be operated on.
type ComponentOps struct {
// Specifies the name of the Component.
// Specifies the name of the Component as defined in the cluster.spec
// +kubebuilder:validation:Required
ComponentName string `json:"componentName"`
}
Expand Down Expand Up @@ -270,6 +266,10 @@ type RebuildInstance struct {
// +optional
BackupName string `json:"backupName,omitempty"`

// When multiple source targets exist of the backup, you must specify the source target to restore.
// +optional
SourceBackupTargetName string `json:"sourceBackupTargetName,omitempty"`

// Defines container environment variables for the restore process.
// merged with the ones specified in the Backup and ActionSet resources.
//
Expand Down Expand Up @@ -298,9 +298,16 @@ type Instance struct {
TargetNodeName string `json:"targetNodeName,omitempty"`
}

// +kubebuilder:validation:XValidation:rule="(has(self.componentName) && !has(self.componentObjectName)) || (!has(self.componentName) && has(self.componentObjectName))",message="need to specified only componentName or componentObjectName"

type Switchover struct {
// Specifies the name of the Component.
ComponentOps `json:",inline"`
// Specifies the name of the Component as defined in the cluster.spec.
// +optional
ComponentName string `json:"componentName,omitempty"`

// Specifies the name of the Component object.
// +optional
ComponentObjectName string `json:"componentObjectName,omitempty"`

// Specifies the instance whose role will be transferred. A typical usage is to transfer the leader role
// in a consensus system.
Expand Down Expand Up @@ -1334,3 +1341,10 @@ func (p *ProgressStatusDetail) SetStatusAndMessage(status ProgressStatus, messag
p.Message = message
p.Status = status
}

func (s *Switchover) GetComponentName() string {
if len(s.ComponentObjectName) > 0 {
return s.ComponentObjectName
}
return s.ComponentName
}
11 changes: 8 additions & 3 deletions apis/operations/v1alpha1/opsrequest_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,9 +499,14 @@ func (r *OpsRequest) validateSwitchover(cluster *appsv1.Cluster) error {
if len(switchoverList) == 0 {
return notEmptyError("spec.switchover")
}
compOpsList := make([]ComponentOps, len(switchoverList))
for i, v := range switchoverList {
compOpsList[i] = v.ComponentOps
compOpsList := make([]ComponentOps, 0)
for _, v := range switchoverList {
if len(v.ComponentName) == 0 {
continue
}
compOpsList = append(compOpsList, ComponentOps{
ComponentName: v.ComponentName,
})

}
if err := r.checkComponentExistence(cluster, compOpsList); err != nil {
Expand Down
1 change: 0 additions & 1 deletion apis/operations/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ import (
workloadsv1 "github.com/apecloud/kubeblocks/apis/workloads/v1"
workloadsv1alpha1 "github.com/apecloud/kubeblocks/apis/workloads/v1alpha1"
appscontrollers "github.com/apecloud/kubeblocks/controllers/apps"
"github.com/apecloud/kubeblocks/controllers/apps/cluster"
"github.com/apecloud/kubeblocks/controllers/apps/component"
"github.com/apecloud/kubeblocks/controllers/apps/configuration"
experimentalcontrollers "github.com/apecloud/kubeblocks/controllers/experimental"
extensionscontrollers "github.com/apecloud/kubeblocks/controllers/extensions"
Expand Down Expand Up @@ -443,7 +445,7 @@ func main() {
os.Exit(1)
}

if err = (&appscontrollers.ClusterReconciler{
if err = (&cluster.ClusterReconciler{
Client: client,
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor("cluster-controller"),
Expand All @@ -453,7 +455,7 @@ func main() {
os.Exit(1)
}

if err = (&appscontrollers.ComponentReconciler{
if err = (&component.ComponentReconciler{
Client: client,
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor("component-controller"),
Expand Down
Loading

0 comments on commit adbf63c

Please sign in to comment.