-
Notifications
You must be signed in to change notification settings - Fork 501
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
Compare k8s pod running info with pd client health info , improve inspection mechanism #1484
Changes from 8 commits
8f190ce
da3c1e6
761c65a
6546985
78d37c1
3feb36b
2a1fd7a
76c2234
9f958ab
f28e245
0bd31c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -499,12 +499,13 @@ type Service struct { | |
|
||
// PDStatus is PD status | ||
type PDStatus struct { | ||
Synced bool `json:"synced,omitempty"` | ||
Phase MemberPhase `json:"phase,omitempty"` | ||
StatefulSet *apps.StatefulSetStatus `json:"statefulSet,omitempty"` | ||
Members map[string]PDMember `json:"members,omitempty"` | ||
Leader PDMember `json:"leader,omitempty"` | ||
FailureMembers map[string]PDFailureMember `json:"failureMembers,omitempty"` | ||
Synced bool `json:"synced,omitempty"` | ||
Phase MemberPhase `json:"phase,omitempty"` | ||
StatefulSet *apps.StatefulSetStatus `json:"statefulSet,omitempty"` | ||
Members map[string]PDMember `json:"members,omitempty"` | ||
Leader PDMember `json:"leader,omitempty"` | ||
FailureMembers map[string]PDFailureMember `json:"failureMembers,omitempty"` | ||
UnjoinedMembers map[string]UnjoinedMember `json:"unJoinedMembers,omitempty"` | ||
} | ||
|
||
// PDMember is PD member | ||
|
@@ -528,6 +529,13 @@ type PDFailureMember struct { | |
CreatedAt metav1.Time `json:"createdAt,omitempty"` | ||
} | ||
|
||
// UnjoinedMember is the pd unjoin cluster member information | ||
type UnjoinedMember struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of add an attribute to User can use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think event flow can't express my meaning in a concise manner , as a user, I need to understand and integrate the event flow and sort out each step. Use |
||
PodName string `json:"podName,omitempty"` | ||
PVCUID types.UID `json:"pvcUID,omitempty"` | ||
CreatedAt metav1.Time `json:"createdAt,omitempty"` | ||
} | ||
|
||
// TiDBStatus is TiDB status | ||
type TiDBStatus struct { | ||
Phase MemberPhase `json:"phase,omitempty"` | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -15,6 +15,7 @@ package member | |||||||
|
||||||||
import ( | ||||||||
"fmt" | ||||||||
"github.com/pingcap/tidb-operator/pkg/util" | ||||||||
"strconv" | ||||||||
"strings" | ||||||||
|
||||||||
|
@@ -407,6 +408,11 @@ func (pmm *pdMemberManager) syncTidbClusterStatus(tc *v1alpha1.TidbCluster, set | |||||||
tc.Status.PD.Members = pdStatus | ||||||||
tc.Status.PD.Leader = tc.Status.PD.Members[leader.GetName()] | ||||||||
|
||||||||
// k8s check | ||||||||
err = pmm.collectUnjoinedMembers(tc, set, pdStatus) | ||||||||
if err != nil { | ||||||||
return err | ||||||||
} | ||||||||
return nil | ||||||||
} | ||||||||
|
||||||||
|
@@ -756,6 +762,52 @@ func getPDConfigMap(tc *v1alpha1.TidbCluster) (*corev1.ConfigMap, error) { | |||||||
return cm, nil | ||||||||
} | ||||||||
|
||||||||
func (pmm *pdMemberManager) collectUnjoinedMembers(tc *v1alpha1.TidbCluster, set *apps.StatefulSet, pdStatus map[string]v1alpha1.PDMember) error { | ||||||||
podSelector, podSelectErr := metav1.LabelSelectorAsSelector(set.Spec.Selector) | ||||||||
if podSelectErr != nil { | ||||||||
return podSelectErr | ||||||||
} | ||||||||
pods, podErr := pmm.podLister.Pods(tc.Namespace).List(podSelector) | ||||||||
if podErr != nil { | ||||||||
return podErr | ||||||||
} | ||||||||
for _, pod := range pods { | ||||||||
var joined = false | ||||||||
for podName := range pdStatus { | ||||||||
if strings.EqualFold(pod.Name, podName) { | ||||||||
joined = true | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||||||||
} | ||||||||
} | ||||||||
if !joined { | ||||||||
if tc.Status.PD.UnjoinedMembers == nil { | ||||||||
tc.Status.PD.UnjoinedMembers = map[string]v1alpha1.UnjoinedMember{} | ||||||||
} | ||||||||
ordinal, err := util.GetOrdinalFromPodName(pod.Name) | ||||||||
if err != nil { | ||||||||
return err | ||||||||
} | ||||||||
pvcName := ordinalPVCName(v1alpha1.PDMemberType, controller.PDMemberName(tc.Name), ordinal) | ||||||||
pvc, err := pmm.pvcLister.PersistentVolumeClaims(tc.Namespace).Get(pvcName) | ||||||||
if err != nil { | ||||||||
return err | ||||||||
} | ||||||||
tc.Status.PD.UnjoinedMembers[pod.Name] = v1alpha1.UnjoinedMember{ | ||||||||
PodName: pod.Name, | ||||||||
PVCUID: pvc.UID, | ||||||||
CreatedAt: metav1.Now(), | ||||||||
} | ||||||||
} else { | ||||||||
if tc.Status.PD.UnjoinedMembers != nil { | ||||||||
if _, ok := tc.Status.PD.UnjoinedMembers[pod.Name]; ok { | ||||||||
delete(tc.Status.PD.UnjoinedMembers, pod.Name) | ||||||||
} | ||||||||
|
||||||||
} | ||||||||
} | ||||||||
} | ||||||||
return nil | ||||||||
} | ||||||||
|
||||||||
type FakePDMemberManager struct { | ||||||||
err error | ||||||||
} | ||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done