Skip to content

Commit

Permalink
remove redundant code
Browse files Browse the repository at this point in the history
Signed-off-by: husharp <jinhao.hu@pingcap.com>
  • Loading branch information
HuSharp committed Nov 29, 2023
1 parent 2c967d9 commit e79d304
Show file tree
Hide file tree
Showing 21 changed files with 221 additions and 211 deletions.
35 changes: 1 addition & 34 deletions docs/api-references/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -10860,39 +10860,7 @@ Kubernetes apps/v1.StatefulSetStatus
</em>
</td>
<td>
<p>Members contains PDs in current TidbCluster</p>
</td>
</tr>
<tr>
<td>
<code>apiEndpoints</code></br>
<em>
[]string
</em>
</td>
<td>
</td>
</tr>
<tr>
<td>
<code>leader</code></br>
<em>
string
</em>
</td>
<td>
</td>
</tr>
<tr>
<td>
<code>unjoinedMembers</code></br>
<em>
<a href="#unjoinedmember">
map[string]github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.UnjoinedMember
</a>
</em>
</td>
<td>
<p>Members contains other service in current TidbCluster</p>
</td>
</tr>
<tr>
Expand Down Expand Up @@ -26181,7 +26149,6 @@ uint
<p>
(<em>Appears on:</em>
<a href="#masterstatus">MasterStatus</a>,
<a href="#pdmsstatus">PDMSStatus</a>,
<a href="#pdstatus">PDStatus</a>)
</p>
<p>
Expand Down
7 changes: 4 additions & 3 deletions examples/basic/tidb-cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ metadata:
name: basic
namespace: pingcap
spec:
version: v7.1.1
timezone: UTC
pvReclaimPolicy: Retain
enableDynamicConfiguration: true
Expand All @@ -16,7 +17,7 @@ spec:
image: alpine:3.16.0
pd:
baseImage: hub.pingcap.net/devbuild/pd
version: v7.5.0-2622
version: v7.5.0-2711
maxFailoverCount: 0
replicas: 1
# if storageClassName is not set, the default Storage Class of the Kubernetes cluster will be used
Expand All @@ -28,12 +29,12 @@ spec:
pdms:
- name: "tso"
baseImage: hub.pingcap.net/devbuild/pd
version: v7.5.0-2622
version: v7.5.0-2711
replicas: 1
config: {}
- name: "scheduling"
baseImage: hub.pingcap.net/devbuild/pd
version: v7.5.0-2622
version: v7.5.0-2711
replicas: 1
config: {}
tikv:
Expand Down
23 changes: 0 additions & 23 deletions manifests/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39966,10 +39966,6 @@ spec:
pdms:
additionalProperties:
properties:
apiEndpoints:
items:
type: string
type: array
conditions:
items:
properties:
Expand Down Expand Up @@ -40009,8 +40005,6 @@ spec:
type: array
image:
type: string
leader:
type: string
members:
items:
type: string
Expand Down Expand Up @@ -40070,23 +40064,6 @@ spec:
type: object
synced:
type: boolean
unjoinedMembers:
additionalProperties:
properties:
createdAt:
format: date-time
nullable: true
type: string
podName:
type: string
pvcUID:
type: string
pvcUIDSet:
additionalProperties:
type: object
type: object
type: object
type: object
volReplaceInProgress:
type: boolean
volumes:
Expand Down
23 changes: 0 additions & 23 deletions manifests/crd/v1/pingcap.com_tidbclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24199,10 +24199,6 @@ spec:
pdms:
additionalProperties:
properties:
apiEndpoints:
items:
type: string
type: array
conditions:
items:
properties:
Expand Down Expand Up @@ -24242,8 +24238,6 @@ spec:
type: array
image:
type: string
leader:
type: string
members:
items:
type: string
Expand Down Expand Up @@ -24303,23 +24297,6 @@ spec:
type: object
synced:
type: boolean
unjoinedMembers:
additionalProperties:
properties:
createdAt:
format: date-time
nullable: true
type: string
podName:
type: string
pvcUID:
type: string
pvcUIDSet:
additionalProperties:
type: object
type: object
type: object
type: object
volReplaceInProgress:
type: boolean
volumes:
Expand Down
5 changes: 0 additions & 5 deletions pkg/apis/pingcap/v1alpha1/tidbcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -874,8 +874,6 @@ func (tc *TidbCluster) PDIsAvailable() bool {
}

lowerLimit := (tc.Spec.PD.Replicas+int32(len(tc.Status.PD.PeerMembers)))/2 + 1
println("PDIsAvailable: tc.Spec.PD.Replicas, len(tc.Status.PD.Members), len(tc.Status.PD.PeerMembers), lowerLimit",
tc.Spec.PD.Replicas, len(tc.Status.PD.Members), len(tc.Status.PD.PeerMembers), lowerLimit)
if int32(len(tc.Status.PD.Members)+len(tc.Status.PD.PeerMembers)) < lowerLimit {
return false
}
Expand All @@ -896,17 +894,14 @@ func (tc *TidbCluster) PDIsAvailable() bool {

availableNum += peerAvailableNum
if availableNum < lowerLimit {
println("PDIsAvailable: availableNum < lowerLimit", availableNum, lowerLimit)
return false
}

if tc.Status.PD.StatefulSet == nil || tc.Status.PD.StatefulSet.ReadyReplicas+peerAvailableNum < lowerLimit {
println("PDIsAvailable: ReadyReplicas+peerAvailableNum < lowerLimit", tc.Status.PD.StatefulSet.ReadyReplicas, peerAvailableNum, lowerLimit)
return false
}

if tc.Status.PD.Phase == SuspendPhase {
println("PDIsAvailable: tc.Status.PD.Phase == SuspendPhase")
return false
}

Expand Down
12 changes: 4 additions & 8 deletions pkg/apis/pingcap/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ func PDMSMemberType(name string) MemberType {
case "scheduling":
return SchedulingMemberType
default:
println("unknown pdms member type", name)
panic("unknown pdms member type")
}
}
Expand Down Expand Up @@ -1412,13 +1411,10 @@ type PDMSStatus struct {
Synced bool `json:"synced"`
Phase MemberPhase `json:"phase,omitempty"`
StatefulSet *apps.StatefulSetStatus `json:"statefulSet,omitempty"`
// Members contains PDs in current TidbCluster
Members []string `json:"members,omitempty"`
PDArrs []string `json:"apiEndpoints,omitempty"`
Leader string `json:"leader,omitempty"`
UnjoinedMembers map[string]UnjoinedMember `json:"unjoinedMembers,omitempty"`
Image string `json:"image,omitempty"`
Volumes map[StorageVolumeName]*StorageVolumeStatus `json:"volumes,omitempty"`
// Members contains other service in current TidbCluster
Members []string `json:"members,omitempty"`
Image string `json:"image,omitempty"`
Volumes map[StorageVolumeName]*StorageVolumeStatus `json:"volumes,omitempty"`
// Represents the latest available observations of a component's state.
// +optional
// +nullable
Expand Down
12 changes: 0 additions & 12 deletions pkg/apis/pingcap/v1alpha1/zz_generated.deepcopy.go

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

21 changes: 19 additions & 2 deletions pkg/controller/pd_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ func getPDClientFromService(pdControl pdapi.PDControlInterface, tc *v1alpha1.Tid
return pdControl.GetPDClient(pdapi.Namespace(tc.GetNamespace()), tc.GetName(), tc.IsTLSClusterEnabled())
}

// getPDClientFromService gets the pd client from the TidbCluster
func getPDMSClientFromService(pdControl pdapi.PDControlInterface, tc *v1alpha1.TidbCluster, serviceName string) pdapi.PDMSClient {
return pdControl.GetPDMSClient(pdapi.Namespace(tc.GetNamespace()), tc.GetName(), serviceName, tc.IsTLSClusterEnabled())
}

// GetPDClient tries to return an available PDClient
// If the pdClient built from the PD service name is unavailable, try to
// build another one with the ClientURL in the PeerMembers.
Expand All @@ -49,7 +54,7 @@ func GetPDClient(pdControl pdapi.PDControlInterface, tc *v1alpha1.TidbCluster) p

for _, pdMember := range tc.Status.PD.PeerMembers {
pdPeerClient := pdControl.GetPDClient(pdapi.Namespace(tc.GetNamespace()), tc.GetName(), tc.IsTLSClusterEnabled(), pdapi.SpecifyClient(pdMember.ClientURL, pdMember.Name))
_, err := pdPeerClient.GetHealth()
_, err = pdPeerClient.GetHealth()
if err == nil {
return pdPeerClient
}
Expand All @@ -58,6 +63,18 @@ func GetPDClient(pdControl pdapi.PDControlInterface, tc *v1alpha1.TidbCluster) p
return pdClient
}

// GetPDMSClient tries to return an available PDMSClient
func GetPDMSClient(pdControl pdapi.PDControlInterface, tc *v1alpha1.TidbCluster, serviceName string) (pdapi.PDMSClient, error) {
pdMSClient := getPDMSClientFromService(pdControl, tc, serviceName)

err := pdMSClient.GetHealth()
if err == nil {
return pdMSClient, nil
}

return nil, err
}

// NewFakePDClient creates a fake pdclient that is set as the pd client
func NewFakePDClient(pdControl *pdapi.FakePDControl, tc *v1alpha1.TidbCluster) *pdapi.FakePDClient {
pdClient := pdapi.NewFakePDClient()
Expand All @@ -69,7 +86,7 @@ func NewFakePDClient(pdControl *pdapi.FakePDControl, tc *v1alpha1.TidbCluster) *
return pdClient
}

// NewFakePDClient creates a fake pdclient that is set as the pd client
// NewFakePDClientWithAddress creates a fake pdclient that is set as the pd client
func NewFakePDClientWithAddress(pdControl *pdapi.FakePDControl, peerURL string) *pdapi.FakePDClient {
pdClient := pdapi.NewFakePDClient()
pdControl.SetPDClientWithAddress(peerURL, pdClient)
Expand Down
17 changes: 11 additions & 6 deletions pkg/controller/tidbcluster/tidb_cluster_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,17 @@ func (c *defaultTidbClusterControl) updateTidbCluster(tc *v1alpha1.TidbCluster)
}
}

// works that should be done to make the pd microservice current state match the desired state:
// - create or update the pdms service
// - create or update the pdms headless service
// - create the pdms statefulset
// - sync pdms cluster status from pdms to TidbCluster object
// - upgrade the pd cluster
// - scale out/in the pd cluster
if err := c.pdMSMemberManager.Sync(tc); err != nil {
return err
}

// works that should be done to make the pd cluster current state match the desired state:
// - create or update the pd service
// - create or update the pd headless service
Expand All @@ -204,12 +215,6 @@ func (c *defaultTidbClusterControl) updateTidbCluster(tc *v1alpha1.TidbCluster)
return err
}

// mcs
if err := c.pdMSMemberManager.Sync(tc); err != nil {
metrics.ClusterUpdateErrors.WithLabelValues(ns, tcName, "tso").Inc()
return err
}

// works that should be done to make the tiproxy cluster current state match the desired state:
// - create or update the tiproxy service
// - create or update the tiproxy headless service
Expand Down
8 changes: 0 additions & 8 deletions pkg/manager/member/pd_member_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ func (m *pdMemberManager) syncPDStatefulSetForTidbCluster(tc *v1alpha1.TidbClust
return err
}
if setNotExist {
println("syncPDStatefulSetForTidbCluster: setNotExist")
err = mngerutils.SetStatefulSetLastAppliedConfigAnnotation(newPDSet)
if err != nil {
return err
Expand All @@ -222,7 +221,6 @@ func (m *pdMemberManager) syncPDStatefulSetForTidbCluster(tc *v1alpha1.TidbClust
return err
}
tc.Status.PD.StatefulSet = &apps.StatefulSetStatus{}
println("syncPDStatefulSetForTidbCluster: setNotExist done")
return controller.RequeueErrorf("TidbCluster: [%s/%s], waiting for PD cluster running", ns, tcName)
}

Expand Down Expand Up @@ -320,8 +318,6 @@ func (m *pdMemberManager) syncTidbClusterStatus(tc *v1alpha1.TidbCluster, set *a
return nil
}

println("syncTidbClusterStatus: set != nil")

ns := tc.GetNamespace()
tcName := tc.GetName()

Expand All @@ -343,11 +339,8 @@ func (m *pdMemberManager) syncTidbClusterStatus(tc *v1alpha1.TidbCluster, set *a

pdClient := controller.GetPDClient(m.deps.PDControl, tc)

println("syncTidbClusterStatus: pdClient.GetHealth()")

healthInfo, err := pdClient.GetHealth()

println("syncTidbClusterStatus: pdClient.GetHealth() done", healthInfo)
if err != nil {
tc.Status.PD.Synced = false
// get endpoints info
Expand Down Expand Up @@ -695,7 +688,6 @@ func getNewPDSetForTidbCluster(tc *v1alpha1.TidbCluster, cm *corev1.ConfigMap) (
sysctls = sysctls + fmt.Sprintf(" %s=%s", sysctl.Name, sysctl.Value)
}
privileged := true
println("initContainers")
initContainers = append(initContainers, corev1.Container{
Name: "init",
Image: tc.HelperImage(),
Expand Down
Loading

0 comments on commit e79d304

Please sign in to comment.