Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pdms: randomly run pdms in e2e test #5559

Merged
merged 7 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions examples/basic/pd-micro-service-cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ spec:
image: alpine:3.16.0
pd:
# TODO: use a stable version
baseImage: pingcap/pd
version: nightly
baseImage: hub-new.pingcap.net/orchestration/pd
version: v8.0.0
maxFailoverCount: 0
Comment on lines +20 to 22
Copy link
Contributor Author

@HuSharp HuSharp Mar 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As tikv/pd#7819 changed pdms interface, we need to update it when releasing pd 8.0.0

replicas: 1
# if storageClassName is not set, the default Storage Class of the Kubernetes cluster will be used
Expand All @@ -29,16 +29,18 @@ spec:
mode: "ms"
pdms:
- name: "tso"
baseImage: pingcap/pd
version: nightly
# TODO: use a stable version
baseImage: hub-new.pingcap.net/orchestration/pd
version: v8.0.0
replicas: 2
- name: "scheduling"
baseImage: pingcap/pd
version: nightly
# TODO: use a stable version
baseImage: hub-new.pingcap.net/orchestration/pd
version: v8.0.0
replicas: 1
tikv:
baseImage: pingcap/tikv
version: v7.4.0
version: v7.5.0
maxFailoverCount: 0
# If only 1 TiKV is deployed, the TiKV region leader
# cannot be transferred during upgrade, so we have
Expand All @@ -61,7 +63,7 @@ spec:
max-open-files: 256
tidb:
baseImage: pingcap/tidb
version: v7.4.0
version: v7.5.0
maxFailoverCount: 0
replicas: 1
service:
Expand Down
13 changes: 6 additions & 7 deletions pkg/controller/tidbcluster/tidb_cluster_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,20 @@
package tidbcluster

import (
"github.com/pingcap/tidb-operator/pkg/features"
v1 "k8s.io/api/core/v1"
apiequality "k8s.io/apimachinery/pkg/api/equality"
errorutils "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/client-go/tools/record"
"k8s.io/klog/v2"

"github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1"
"github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1/defaulting"
v1alpha1validation "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1/validation"
"github.com/pingcap/tidb-operator/pkg/controller"
"github.com/pingcap/tidb-operator/pkg/features"
"github.com/pingcap/tidb-operator/pkg/manager"
"github.com/pingcap/tidb-operator/pkg/manager/member"
"github.com/pingcap/tidb-operator/pkg/manager/volumes"
"github.com/pingcap/tidb-operator/pkg/metrics"
v1 "k8s.io/api/core/v1"
apiequality "k8s.io/apimachinery/pkg/api/equality"
errorutils "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/client-go/tools/record"
"k8s.io/klog/v2"
)

// ControlInterface implements the control logic for updating TidbClusters and their children StatefulSets.
Expand Down
5 changes: 3 additions & 2 deletions pkg/manager/member/pd_member_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ func (m *pdMemberManager) Sync(tc *v1alpha1.TidbCluster) error {
return nil
}

if tc.Spec.PD.Mode == "ms" && tc.Spec.PDMS == nil {
return fmt.Errorf("tidbcluster: [%s/%s]'s enable micro service but pdMS spec is nil, please check `PDMS`", tc.GetNamespace(), tc.GetName())
if (tc.Spec.PD.Mode == "ms" && tc.Spec.PDMS == nil) ||
(tc.Spec.PDMS != nil && tc.Spec.PD.Mode != "ms") {
klog.Infof("tidbcluster: [%s/%s]'s enable micro service failed, please check `PD.Mode` and `PDMS`", tc.GetNamespace(), tc.GetName())
}

// skip sync if pd is suspended
Expand Down
23 changes: 13 additions & 10 deletions pkg/manager/member/pd_ms_member_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,37 +59,40 @@ func NewPDMSMemberManager(dependencies *controller.Dependencies, pdMSScaler Scal

// Sync for all PD Micro Service components.
func (m *pdMSMemberManager) Sync(tc *v1alpha1.TidbCluster) error {
if tc.Spec.PDMS == nil {
return nil
}

// Need to start PD API
if tc.Spec.PD == nil {
if tc.Spec.PDMS != nil && tc.Spec.PD == nil {
klog.Infof("PD Micro Service is enabled, but PD is not enabled, skip syncing PD Micro Service")
return nil
}
if tc.Spec.PD.Mode != "ms" {
// remove all micro service components
for _, comp := range tc.Spec.PDMS {
// remove all micro service components if PDMS is not enabled
// PDMS need to be enabled when PD.Mode is ms && PDMS is not nil
if tc.Spec.PDMS == nil || (tc.Spec.PD != nil && tc.Spec.PD.Mode != "ms") {
for _, comp := range tc.Status.PDMS {
ns := tc.GetNamespace()
tcName := tc.GetName()
curService := comp.Name

oldPDMSSetTmp, err := m.deps.StatefulSetLister.StatefulSets(ns).Get(controller.PDMSMemberName(tcName, curService))
if err != nil && !errors.IsNotFound(err) {
if err != nil {
if errors.IsNotFound(err) {
continue
}
return fmt.Errorf("syncPDMSStatefulSet: fail to get sts %s PDMS component %s for cluster [%s/%s], error: %s",
controller.PDMSMemberName(tcName, curService), curService, ns, tcName, err)
}

oldPDMSSet := oldPDMSSetTmp.DeepCopy()
newPDMSSet := oldPDMSSetTmp.DeepCopy()
if oldPDMSSet.Status.Replicas == 0 {
continue
}
tc.Status.PDMS[curService].Synced = true
*newPDMSSet.Spec.Replicas = 0
if err := m.scaler.Scale(tc, oldPDMSSet, newPDMSSet); err != nil {
return err
}
mngerutils.UpdateStatefulSetWithPrecheck(m.deps, tc, "FailedUpdatePDMSSTS", newPDMSSet, oldPDMSSet)
}
klog.Infof("PD Micro Service is enabled, but PD is not in `ms` mode, skip syncing PD Micro Service")
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/manager/member/startscript/v1/render_script.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func RenderPDStartScript(tc *v1alpha1.TidbCluster) (string, error) {

pdStartSubScript := ``
mode := ""
if tc.Spec.PD.Mode == "ms" {
if tc.Spec.PD.Mode == "ms" && tc.Spec.PDMS != nil {
mode = "api"
}
pdStartScriptTpl := template.Must(
Expand Down
2 changes: 1 addition & 1 deletion pkg/manager/member/startscript/v2/pd_start_script.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func RenderPDStartScript(tc *v1alpha1.TidbCluster) (string, error) {
tc.Spec.StartScriptV2FeatureFlags, v1alpha1.StartScriptV2FeatureFlagWaitForDnsNameIpMatch)

mode := ""
if tc.Spec.PD.Mode == "ms" {
if tc.Spec.PD.Mode == "ms" && tc.Spec.PDMS != nil {
mode = "api"
}
pdStartScriptTpl := template.Must(
Expand Down
17 changes: 7 additions & 10 deletions pkg/manager/member/tikv_member_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,14 @@ func (m *tikvMemberManager) Sync(tc *v1alpha1.TidbCluster) error {
if tc.Spec.PD != nil && !tc.PDIsAvailable() {
return controller.RequeueErrorf("TidbCluster: [%s/%s], waiting for PD cluster running", ns, tcName)
}
// Need to wait for PDMS
if tc.Spec.PD != nil && tc.Spec.PD.Mode == "ms" && tc.Spec.PDMS == nil {
return controller.RequeueErrorf("TidbCluster: [%s/%s], please make sure pdms is not nil, "+
"then now waiting for PD's micro service running", ns, tcName)
}
// Check if all PD Micro Services are available
for _, pdms := range tc.Spec.PDMS {
_, err = controller.GetPDMSClient(m.deps.PDControl, tc, pdms.Name)
if err != nil {
return controller.RequeueErrorf("PDMS component %s for TidbCluster: [%s/%s], "+
"waiting for PD micro service cluster running, error: %v", pdms.Name, ns, tcName, err)
if tc.Spec.PDMS != nil && (tc.Spec.PD != nil && tc.Spec.PD.Mode == "ms") {
for _, pdms := range tc.Spec.PDMS {
_, err = controller.GetPDMSClient(m.deps.PDControl, tc, pdms.Name)
if err != nil {
return controller.RequeueErrorf("PDMS component %s for TidbCluster: [%s/%s], "+
"waiting for PD micro service cluster running, error: %v", pdms.Name, ns, tcName, err)
}
}
}

Expand Down
46 changes: 46 additions & 0 deletions tests/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,20 @@ func (oa *OperatorActions) memberCheckContextForTC(tc *v1alpha1.TidbCluster, com
expectedImage = tc.PDImage()
services = []string{controller.PDMemberName(name), controller.PDPeerMemberName(name)}
checkComponent = oa.isPDMembersReady
case v1alpha1.PDMSTSOMemberType, v1alpha1.PDMSSchedulingMemberType:
skip = true
if tc.Spec.PD != nil && tc.Spec.PD.Mode == "ms" {
curService := component.String()
for _, service := range tc.Spec.PDMS {
if curService == service.Name {
skip = false
break
}
}
expectedImage = tc.PDImage()
services = []string{controller.PDMSMemberName(name, curService), controller.PDMSPeerMemberName(name, curService)}
checkComponent = oa.isPDMSMembersReady
}
case v1alpha1.TiDBMemberType:
skip = tc.Spec.TiDB == nil
expectedImage = tc.TiDBImage()
Expand Down Expand Up @@ -878,6 +892,36 @@ func (oa *OperatorActions) isPDMembersReady(tc *v1alpha1.TidbCluster, sts *v1.St
return nil
}

func (oa *OperatorActions) isPDMSMembersReady(tc *v1alpha1.TidbCluster, sts *v1.StatefulSet) error {
curService := controller.PDMSTrimName(sts.Name)
if tc.Status.PDMS[curService] == nil || tc.Status.PDMS[curService].StatefulSet == nil {
return fmt.Errorf("sts in tc status is nil, pdms curService is %s", curService)
}

var replicas int32
for _, component := range tc.Spec.PDMS {
if strings.Contains(component.Name, curService) {
replicas = component.Replicas
break
}
}

if *sts.Spec.Replicas != replicas {
return fmt.Errorf("sts.spec.Replicas(%d) != %d, pdms curService is %s\", curService)",
*sts.Spec.Replicas, replicas, curService)
}
if sts.Status.ReadyReplicas != replicas {
return fmt.Errorf("sts.status.ReadyReplicas(%d) != %d, pdms curService is %s\", curService)",
sts.Status.ReadyReplicas, tc.Spec.PD.Replicas, curService)
}
if sts.Status.ReadyReplicas != sts.Status.Replicas {
return fmt.Errorf("sts.status.ReadyReplicas(%d) != sts.status.Replicas(%d), pdms curService is %s\", curService)",
sts.Status.ReadyReplicas, sts.Status.Replicas, curService)
}

return nil
}

func (oa *OperatorActions) isTiDBMembersReady(tc *v1alpha1.TidbCluster, sts *v1.StatefulSet) error {
if tc.Status.TiDB.StatefulSet == nil {
return fmt.Errorf("sts in tc status is nil")
Expand Down Expand Up @@ -1320,6 +1364,8 @@ func (oa *OperatorActions) WaitForTidbClusterReady(tc *v1alpha1.TidbCluster, tim
}

components := []v1alpha1.MemberType{
v1alpha1.PDMSTSOMemberType,
v1alpha1.PDMSSchedulingMemberType,
v1alpha1.PDMemberType,
v1alpha1.TiKVMemberType,
v1alpha1.TiDBMemberType,
Expand Down
Loading
Loading