Skip to content

Commit

Permalink
Merge branch 'apecloud:main' into support/refactor-addon-controller
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuyi1159 authored Aug 8, 2024
2 parents 3178ae6 + a22856f commit 56cd472
Show file tree
Hide file tree
Showing 353 changed files with 19,112 additions and 52,871 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ KubeCon 2024 in HongKong from 21-23 August 2024: [KuaiShou's 100% Resource Utili

## Community

- KubeBlocks [Slack Channel](https://join.slack.com/t/kubeblocks/shared_invite/zt-2lyc3cwsg-m07xaaN8Rle~ao3soPWKUw)
- KubeBlocks [Slack Channel](https://join.slack.com/t/kubeblocks/shared_invite/zt-2njvf6bxx-WwWIEH9MlWp5LrkS7h8qFQ)
- KubeBlocks Github [Discussions](https://github.com/apecloud/kubeblocks/discussions)
- KubeBlocks Wechat Account:
<img src=".\docs\img\wechat-assistant.jpg" alt="wechat" width="100" height="100">
Expand Down
62 changes: 8 additions & 54 deletions apis/apps/v1alpha1/backuppolicytemplate_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,6 @@ import (

// BackupPolicyTemplateSpec contains the settings in a BackupPolicyTemplate.
type BackupPolicyTemplateSpec struct {
// Specifies the name of a ClusterDefinition.
// This is an immutable attribute that cannot be changed after creation.
// And this field is deprecated since v0.9, consider using the ComponentDef instead.
//
// +kubebuilder:validation:Pattern:=`^[a-z0-9]([a-z0-9\.\-]*[a-z0-9])?$`
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="clusterDefinitionRef is immutable"
// +kubebuilder:deprecatedversion:warning="This field has been deprecated since 0.9.0, consider using the ComponentDef instead"
ClusterDefRef string `json:"clusterDefinitionRef,omitempty"`

// Represents an array of BackupPolicy templates, with each template corresponding to a specified ComponentDefinition
// or to a group of ComponentDefinitions that are different versions of definitions of the same component.
//
Expand All @@ -56,18 +47,6 @@ type BackupPolicyTemplateSpec struct {
// BackupPolicy is the template corresponding to a specified ComponentDefinition
// or to a group of ComponentDefinitions that are different versions of definitions of the same component.
type BackupPolicy struct {
// Specifies the name of ClusterComponentDefinition defined in the ClusterDefinition.
// Must comply with the IANA Service Naming rule.
//
// Deprecated since v0.9, should use `componentDefs` instead.
// This field is maintained for backward compatibility and its use is discouraged.
// Existing usage should be updated to the current preferred approach to avoid compatibility issues in future releases.
//
// +kubebuilder:validation:MaxLength=22
// +kubebuilder:validation:Pattern:=`^[a-z]([a-z0-9\-]*[a-z0-9])?$`
// +optional
ComponentDefRef string `json:"componentDefRef,omitempty"`

// Specifies a list of names of ComponentDefinitions that the specified ClusterDefinition references.
// They should be different versions of definitions of the same component,
// thus allowing them to share a single BackupPolicy.
Expand Down Expand Up @@ -149,8 +128,7 @@ type ValueFrom struct {
}

type ValueMapping struct {
// Represents an array of names of ClusterVersion or ComponentDefinition that can be mapped to
// the appropriate version of the backup tool image.
// Represents an array of names of ComponentDefinition that can be mapped to the appropriate version of the backup tool image.
//
// This mapping allows different versions of component images to correspond to specific versions of backup tool images.
//
Expand Down Expand Up @@ -211,13 +189,16 @@ type TargetInstance struct {
// the `strategy` field below.
Role string `json:"role"`

// Specifies the fallback role to select one replica for backup, this only takes effect when the
// `strategy` field below is set to `Any`.
//
// +optional
FallbackRole string `json:"fallbackRole,omitempty"`

// If `backupPolicy.componentDefs` is set, this field is required to specify the system account name.
// This account must match one listed in `componentDefinition.spec.systemAccounts[*].name`.
// The corresponding secret created by this account is used to connect to the database.
//
// If `backupPolicy.componentDefRef` (a legacy and deprecated API) is set, the secret defined in
// `clusterDefinition.spec.ConnectionCredential` is used instead.
//
// +optional
Account string `json:"account,omitempty"`

Expand All @@ -230,37 +211,10 @@ type TargetInstance struct {
//
// +optional
Strategy dpv1alpha1.PodSelectionStrategy `json:"strategy,omitempty"`

// Specifies the keys of the connection credential secret defined in `clusterDefinition.spec.ConnectionCredential`.
// It will be ignored when the `account` is set.
//
// +optional
ConnectionCredentialKey ConnectionCredentialKey `json:"connectionCredentialKey,omitempty"`
}

type ConnectionCredentialKey struct {
// Represents the key of the password in the connection credential secret.
// If not specified, the default key "password" is used.
//
// +optional
PasswordKey *string `json:"passwordKey,omitempty"`

// Represents the key of the username in the connection credential secret.
// If not specified, the default key "username" is used.
//
// +optional
UsernameKey *string `json:"usernameKey,omitempty"`

// Defines the key of the host in the connection credential secret.
HostKey *string `json:"hostKey,omitempty"`

// Indicates map key of the port in the connection credential secret.
PortKey *string `json:"portKey,omitempty"`
}

// BackupPolicyTemplateStatus defines the observed state of BackupPolicyTemplate.
type BackupPolicyTemplateStatus struct {
}
type BackupPolicyTemplateStatus struct{}

// BackupPolicyTemplate should be provided by addon developers and is linked to a ClusterDefinition
// and its associated ComponentDefinitions.
Expand Down
40 changes: 10 additions & 30 deletions apis/apps/v1alpha1/cluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import (
"fmt"
"strings"

"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"

dpv1alpha1 "github.com/apecloud/kubeblocks/apis/dataprotection/v1alpha1"
workloads "github.com/apecloud/kubeblocks/apis/workloads/v1alpha1"
Expand Down Expand Up @@ -742,7 +742,7 @@ type ClusterComponentSpec struct {
// +optional
Configs []ClusterComponentConfig `json:"configs,omitempty"`

// Defines the strategy for switchover and failover when workloadType is Replication.
// Defines the strategy for switchover and failover.
//
// Deprecated since v0.9.
// This field is maintained for backward compatibility and its use is discouraged.
Expand Down Expand Up @@ -800,6 +800,13 @@ type ClusterComponentSpec struct {
// +optional
UpdateStrategy *UpdateStrategy `json:"updateStrategy,omitempty"`

// Controls the concurrency of pods during initial scale up, when replacing pods on nodes,
// or when scaling down. It only used when `PodManagementPolicy` is set to `Parallel`.
// The default Concurrency is 100%.
//
// +optional
ParallelPodManagementConcurrency *intstr.IntOrString `json:"parallelPodManagementConcurrency,omitempty"`

// PodUpdatePolicy indicates how pods should be updated
//
// - `StrictInPlace` indicates that only allows in-place upgrades.
Expand Down Expand Up @@ -986,7 +993,7 @@ type PersistentVolumeClaimSpec struct {
//
// +kubebuilder:pruning:PreserveUnknownFields
// +optional
Resources corev1.ResourceRequirements `json:"resources,omitempty" protobuf:"bytes,2,opt,name=resources"`
Resources corev1.VolumeResourceRequirements `json:"resources,omitempty" protobuf:"bytes,2,opt,name=resources"`

// The name of the StorageClass required by the claim.
// More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#class-1.
Expand Down Expand Up @@ -1576,33 +1583,6 @@ func (r ClusterSpec) GetComponentDefRefName(componentName string) string {
return ""
}

// ValidateEnabledLogs validates enabledLogs config in cluster.yaml, and returns metav1.Condition when detecting invalid values.
func (r ClusterSpec) ValidateEnabledLogs(cd *ClusterDefinition) error {
message := make([]string, 0)
for _, comp := range r.ComponentSpecs {
invalidLogNames := cd.ValidateEnabledLogConfigs(comp.ComponentDefRef, comp.EnabledLogs)
if len(invalidLogNames) == 0 {
continue
}
message = append(message, fmt.Sprintf("EnabledLogs: %s are not defined in Component: %s of the clusterDefinition", invalidLogNames, comp.Name))
}
if len(message) > 0 {
return errors.New(strings.Join(message, ";"))
}
return nil
}

// GetDefNameMappingComponents returns ComponentDefRef name mapping ClusterComponentSpec.
func (r ClusterSpec) GetDefNameMappingComponents() map[string][]ClusterComponentSpec {
m := map[string][]ClusterComponentSpec{}
for _, c := range r.ComponentSpecs {
v := m[c.ComponentDefRef]
v = append(v, c)
m[c.ComponentDefRef] = v
}
return m
}

// GetMessage gets message map deep copy object.
func (r ClusterComponentStatus) GetMessage() ComponentMessageMap {
messageMap := map[string]string{}
Expand Down
57 changes: 0 additions & 57 deletions apis/apps/v1alpha1/cluster_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/yaml"

"github.com/apecloud/kubeblocks/pkg/constant"
viper "github.com/apecloud/kubeblocks/pkg/viperx"
Expand Down Expand Up @@ -136,15 +135,6 @@ var _ = Describe("", func() {
Expect(r.GetVolumeClaimNames(compName)).Should(ContainElement(fmt.Sprintf("%s-%s-%s-%d", compName, r.Name, compName, 0)))
})

It("test GetDefNameMappingComponents", func() {
r := ClusterSpec{}
key := "comp-def-ref"
comp := ClusterComponentSpec{}
comp.ComponentDefRef = key
r.ComponentSpecs = []ClusterComponentSpec{comp}
Expect(r.GetDefNameMappingComponents()[key]).Should(ContainElement(comp))
})

It("test SetComponentStatus", func() {
r := ClusterStatus{}
status := ClusterComponentStatus{}
Expand Down Expand Up @@ -208,53 +198,6 @@ var _ = Describe("", func() {
})
})

func TestValidateEnabledLogs(t *testing.T) {
cluster := &Cluster{}
clusterDef := &ClusterDefinition{}
clusterByte := `
apiVersion: apps.kubeblocks.io/v1alpha1
kind: Cluster
metadata:
name: wesql
spec:
clusterVersionRef: cluster-version-consensus
clusterDefinitionRef: cluster-definition-consensus
componentSpecs:
- name: wesql-test
componentDefRef: replicasets
enabledLogs: [error, slow]
`
clusterDefByte := `
apiVersion: apps.kubeblocks.io/v1alpha1
kind: ClusterDefinition
metadata:
name: cluster-definition-consensus
spec:
componentDefs:
- name: replicasets
workloadType: Consensus
logConfigs:
- name: error
filePathPattern: /log/mysql/mysqld.err
- name: slow
filePathPattern: /log/mysql/*slow.log
podSpec:
containers:
- name: mysql
imagePullPolicy: IfNotPresent`
_ = yaml.Unmarshal([]byte(clusterByte), cluster)
_ = yaml.Unmarshal([]byte(clusterDefByte), clusterDef)
// normal case
if err := cluster.Spec.ValidateEnabledLogs(clusterDef); err != nil {
t.Error("Expected empty conditionList")
}
// corner case
cluster.Spec.ComponentSpecs[0].EnabledLogs = []string{"error-test", "slow"}
if err := cluster.Spec.ValidateEnabledLogs(clusterDef); err == nil {
t.Error("Expected one element conditionList")
}
}

func TestGetMessage(t *testing.T) {
podKey := "Pod/test-01"
compStatus := ClusterComponentStatus{
Expand Down
Loading

0 comments on commit 56cd472

Please sign in to comment.