add diagnostic for data mover exposer

Signed-off-by: Lyndon-Li <lyonghui@vmware.com>
This commit is contained in:
Lyndon-Li
2024-12-13 15:09:17 +08:00
parent 8087c7f13a
commit 1e2ef374d6
11 changed files with 996 additions and 36 deletions
+28 -22
View File
@@ -776,42 +776,48 @@ func WaitUntilVSCHandleIsReady(
func DiagnoseVS(vs *snapshotv1api.VolumeSnapshot) string {
vscName := ""
if vs.Status.BoundVolumeSnapshotContentName != nil {
vscName = *vs.Status.BoundVolumeSnapshotContentName
}
readyToUse := false
if vs.Status.ReadyToUse != nil {
readyToUse = *vs.Status.ReadyToUse
}
errMessage := ""
if vs.Status.Error != nil && vs.Status.Error.Message != nil {
errMessage = *vs.Status.Error.Message
if vs.Status != nil {
if vs.Status.BoundVolumeSnapshotContentName != nil {
vscName = *vs.Status.BoundVolumeSnapshotContentName
}
if vs.Status.ReadyToUse != nil {
readyToUse = *vs.Status.ReadyToUse
}
if vs.Status.Error != nil && vs.Status.Error.Message != nil {
errMessage = *vs.Status.Error.Message
}
}
diag := fmt.Sprintf("VS %s/%s, bind to %s, readToUse %v, errMessage %s\n", vs.Namespace, vs.Name, vscName, readyToUse, errMessage)
diag := fmt.Sprintf("VS %s/%s, bind to %s, readyToUse %v, errMessage %s\n", vs.Namespace, vs.Name, vscName, readyToUse, errMessage)
return diag
}
func DiagnoseVSC(vsc *snapshotv1api.VolumeSnapshotContent) string {
handle := ""
if vsc.Status.SnapshotHandle != nil {
handle = *vsc.Status.SnapshotHandle
}
readyToUse := false
if vsc.Status.ReadyToUse != nil {
readyToUse = *vsc.Status.ReadyToUse
}
errMessage := ""
if vsc.Status.Error != nil && vsc.Status.Error.Message != nil {
errMessage = *vsc.Status.Error.Message
if vsc.Status != nil {
if vsc.Status.SnapshotHandle != nil {
handle = *vsc.Status.SnapshotHandle
}
if vsc.Status.ReadyToUse != nil {
readyToUse = *vsc.Status.ReadyToUse
}
if vsc.Status.Error != nil && vsc.Status.Error.Message != nil {
errMessage = *vsc.Status.Error.Message
}
}
diag := fmt.Sprintf("VSC %s, readToUse %v, errMessage %s, handle %s\n", vsc.Name, readyToUse, errMessage, handle)
diag := fmt.Sprintf("VSC %s, readyToUse %v, errMessage %s, handle %s\n", vsc.Name, readyToUse, errMessage, handle)
return diag
}
+194
View File
@@ -1655,3 +1655,197 @@ func TestWaitUntilVSCHandleIsReady(t *testing.T) {
})
}
}
func TestDiagnoseVS(t *testing.T) {
vscName := "fake-vsc"
readyToUse := true
message := "fake-message"
testCases := []struct {
name string
vs *snapshotv1api.VolumeSnapshot
expected string
}{
{
name: "VS with no status",
vs: &snapshotv1api.VolumeSnapshot{
ObjectMeta: metav1.ObjectMeta{
Name: "fake-vs",
Namespace: "fake-ns",
},
},
expected: "VS fake-ns/fake-vs, bind to , readyToUse false, errMessage \n",
},
{
name: "VS with empty status",
vs: &snapshotv1api.VolumeSnapshot{
ObjectMeta: metav1.ObjectMeta{
Name: "fake-vs",
Namespace: "fake-ns",
},
Status: &snapshotv1api.VolumeSnapshotStatus{},
},
expected: "VS fake-ns/fake-vs, bind to , readyToUse false, errMessage \n",
},
{
name: "VS with VSC name",
vs: &snapshotv1api.VolumeSnapshot{
ObjectMeta: metav1.ObjectMeta{
Name: "fake-vs",
Namespace: "fake-ns",
},
Status: &snapshotv1api.VolumeSnapshotStatus{
BoundVolumeSnapshotContentName: &vscName,
},
},
expected: "VS fake-ns/fake-vs, bind to fake-vsc, readyToUse false, errMessage \n",
},
{
name: "VS with VSC name+ready",
vs: &snapshotv1api.VolumeSnapshot{
ObjectMeta: metav1.ObjectMeta{
Name: "fake-vs",
Namespace: "fake-ns",
},
Status: &snapshotv1api.VolumeSnapshotStatus{
BoundVolumeSnapshotContentName: &vscName,
ReadyToUse: &readyToUse,
},
},
expected: "VS fake-ns/fake-vs, bind to fake-vsc, readyToUse true, errMessage \n",
},
{
name: "VS with VSC name+ready+empty error",
vs: &snapshotv1api.VolumeSnapshot{
ObjectMeta: metav1.ObjectMeta{
Name: "fake-vs",
Namespace: "fake-ns",
},
Status: &snapshotv1api.VolumeSnapshotStatus{
BoundVolumeSnapshotContentName: &vscName,
ReadyToUse: &readyToUse,
Error: &snapshotv1api.VolumeSnapshotError{},
},
},
expected: "VS fake-ns/fake-vs, bind to fake-vsc, readyToUse true, errMessage \n",
},
{
name: "VS with VSC name+ready+error",
vs: &snapshotv1api.VolumeSnapshot{
ObjectMeta: metav1.ObjectMeta{
Name: "fake-vs",
Namespace: "fake-ns",
},
Status: &snapshotv1api.VolumeSnapshotStatus{
BoundVolumeSnapshotContentName: &vscName,
ReadyToUse: &readyToUse,
Error: &snapshotv1api.VolumeSnapshotError{
Message: &message,
},
},
},
expected: "VS fake-ns/fake-vs, bind to fake-vsc, readyToUse true, errMessage fake-message\n",
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
diag := DiagnoseVS(tc.vs)
assert.Equal(t, tc.expected, diag)
})
}
}
func TestDiagnoseVSC(t *testing.T) {
readyToUse := true
message := "fake-message"
handle := "fake-handle"
testCases := []struct {
name string
vsc *snapshotv1api.VolumeSnapshotContent
expected string
}{
{
name: "VS with no status",
vsc: &snapshotv1api.VolumeSnapshotContent{
ObjectMeta: metav1.ObjectMeta{
Name: "fake-vsc",
},
},
expected: "VSC fake-vsc, readyToUse false, errMessage , handle \n",
},
{
name: "VSC with empty status",
vsc: &snapshotv1api.VolumeSnapshotContent{
ObjectMeta: metav1.ObjectMeta{
Name: "fake-vsc",
},
Status: &snapshotv1api.VolumeSnapshotContentStatus{},
},
expected: "VSC fake-vsc, readyToUse false, errMessage , handle \n",
},
{
name: "VSC with ready",
vsc: &snapshotv1api.VolumeSnapshotContent{
ObjectMeta: metav1.ObjectMeta{
Name: "fake-vsc",
},
Status: &snapshotv1api.VolumeSnapshotContentStatus{
ReadyToUse: &readyToUse,
},
},
expected: "VSC fake-vsc, readyToUse true, errMessage , handle \n",
},
{
name: "VSC with ready+handle",
vsc: &snapshotv1api.VolumeSnapshotContent{
ObjectMeta: metav1.ObjectMeta{
Name: "fake-vsc",
},
Status: &snapshotv1api.VolumeSnapshotContentStatus{
ReadyToUse: &readyToUse,
SnapshotHandle: &handle,
},
},
expected: "VSC fake-vsc, readyToUse true, errMessage , handle fake-handle\n",
},
{
name: "VSC with ready+handle+empty error",
vsc: &snapshotv1api.VolumeSnapshotContent{
ObjectMeta: metav1.ObjectMeta{
Name: "fake-vsc",
},
Status: &snapshotv1api.VolumeSnapshotContentStatus{
ReadyToUse: &readyToUse,
SnapshotHandle: &handle,
Error: &snapshotv1api.VolumeSnapshotError{},
},
},
expected: "VSC fake-vsc, readyToUse true, errMessage , handle fake-handle\n",
},
{
name: "VSC with ready+handle+error",
vsc: &snapshotv1api.VolumeSnapshotContent{
ObjectMeta: metav1.ObjectMeta{
Name: "fake-vsc",
},
Status: &snapshotv1api.VolumeSnapshotContentStatus{
ReadyToUse: &readyToUse,
SnapshotHandle: &handle,
Error: &snapshotv1api.VolumeSnapshotError{
Message: &message,
},
},
},
expected: "VSC fake-vsc, readyToUse true, errMessage fake-message, handle fake-handle\n",
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
diag := DiagnoseVSC(tc.vsc)
assert.Equal(t, tc.expected, diag)
})
}
}
+1 -1
View File
@@ -262,7 +262,7 @@ func DiagnosePod(pod *corev1api.Pod) string {
diag := fmt.Sprintf("Pod %s/%s, phase %s, node name %s\n", pod.Namespace, pod.Name, pod.Status.Phase, pod.Spec.NodeName)
for _, condition := range pod.Status.Conditions {
diag += fmt.Sprintf("Pod condition %s, reason %s, message %s\n", condition.Type, condition.Reason, condition.Message)
diag += fmt.Sprintf("Pod condition %s, status %s, reason %s, message %s\n", condition.Type, condition.Status, condition.Reason, condition.Message)
}
return diag
+46
View File
@@ -846,3 +846,49 @@ func TestToSystemAffinity(t *testing.T) {
})
}
}
func TestDiagnosePod(t *testing.T) {
testCases := []struct {
name string
pod *corev1api.Pod
expected string
}{
{
name: "pod with all info",
pod: &corev1api.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "fake-pod",
Namespace: "fake-ns",
},
Spec: corev1api.PodSpec{
NodeName: "fake-node",
},
Status: corev1api.PodStatus{
Phase: corev1api.PodPending,
Conditions: []corev1api.PodCondition{
{
Type: corev1api.PodInitialized,
Status: corev1api.ConditionTrue,
Reason: "fake-reason-1",
Message: "fake-message-1",
},
{
Type: corev1api.PodScheduled,
Status: corev1api.ConditionFalse,
Reason: "fake-reason-2",
Message: "fake-message-2",
},
},
},
},
expected: "Pod fake-ns/fake-pod, phase Pending, node name fake-node\nPod condition Initialized, status True, reason fake-reason-1, message fake-message-1\nPod condition PodScheduled, status False, reason fake-reason-2, message fake-message-2\n",
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
diag := DiagnosePod(tc.pod)
assert.Equal(t, tc.expected, diag)
})
}
}
+1 -9
View File
@@ -414,15 +414,7 @@ func GetPVCForPodVolume(vol *corev1api.Volume, pod *corev1api.Pod, crClient crcl
}
func DiagnosePVC(pvc *corev1api.PersistentVolumeClaim) string {
diag := fmt.Sprintf("PVC %s/%s, phase %s\n", pvc.Namespace, pvc.Name, pvc.Status.Phase)
for _, condition := range pvc.Status.Conditions {
diag += fmt.Sprintf("PVC condition %s, reason %s, message %s\n", condition.Type, condition.Reason, condition.Message)
}
diag += fmt.Sprintf("PVC is binding to %s\n", pvc.Spec.VolumeName)
return diag
return fmt.Sprintf("PVC %s/%s, phase %s, binding to %s\n", pvc.Namespace, pvc.Name, pvc.Status.Phase, pvc.Spec.VolumeName)
}
func DiagnosePV(pv *corev1api.PersistentVolume) string {
+59
View File
@@ -1465,4 +1465,63 @@ func TestMakePodPVCAttachment(t *testing.T) {
}
func TestDiagnosePVC(t *testing.T) {
testCases := []struct {
name string
pvc *corev1api.PersistentVolumeClaim
expected string
}{
{
name: "pvc with all info",
pvc: &corev1api.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{
Name: "fake-pvc",
Namespace: "fake-ns",
},
Spec: corev1api.PersistentVolumeClaimSpec{
VolumeName: "fake-pv",
},
Status: corev1api.PersistentVolumeClaimStatus{
Phase: corev1api.ClaimPending,
},
},
expected: "PVC fake-ns/fake-pvc, phase Pending, binding to fake-pv\n",
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
diag := DiagnosePVC(tc.pvc)
assert.Equal(t, tc.expected, diag)
})
}
}
func TestDiagnosePV(t *testing.T) {
testCases := []struct {
name string
pv *corev1api.PersistentVolume
expected string
}{
{
name: "pv with all info",
pv: &corev1api.PersistentVolume{
ObjectMeta: metav1.ObjectMeta{
Name: "fake-pv",
},
Status: corev1api.PersistentVolumeStatus{
Phase: corev1api.VolumePending,
Message: "fake-message",
Reason: "fake-reason",
},
},
expected: "PV fake-pv, phase Pending, reason fake-reason, message fake-message\n",
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
diag := DiagnosePV(tc.pv)
assert.Equal(t, tc.expected, diag)
})
}
}