@@ -40,62 +40,72 @@ pod node anotation and cns volume metadata
40
40
func verifyAnnotationsAndNodeAffinityForStatefulsetinSvc (ctx context.Context , client clientset.Interface ,
41
41
statefulset * appsv1.StatefulSet , namespace string ,
42
42
allowedTopologies []v1.TopologySelectorLabelRequirement ) error {
43
- // read topology mapping
43
+ // Read topology mapping
44
44
allowedTopologiesMap := createAllowedTopologiesMap (allowedTopologies )
45
45
topologyMap := GetAndExpectStringEnvVar (envTopologyMap )
46
46
_ , topologyCategories := createTopologyMapLevel5 (topologyMap )
47
47
48
48
framework .Logf ("Reading statefulset pod list for node affinity verification" )
49
49
ssPodsBeforeScaleDown := GetListOfPodsInSts (client , statefulset )
50
50
for _ , sspod := range ssPodsBeforeScaleDown .Items {
51
+ // Get Pod details
51
52
_ , err := client .CoreV1 ().Pods (namespace ).Get (ctx , sspod .Name , metav1.GetOptions {})
52
53
if err != nil {
53
- return err
54
+ return fmt . Errorf ( "failed to get pod %s in namespace %s: %w" , sspod . Name , namespace , err )
54
55
}
55
56
56
- framework .Logf ("Verifying PVC annotation and pv affinity rules" )
57
+ framework .Logf ("Verifying PVC annotation and PV affinity rules" )
57
58
for _ , volumespec := range sspod .Spec .Volumes {
58
59
if volumespec .PersistentVolumeClaim != nil {
59
60
svPvcName := volumespec .PersistentVolumeClaim .ClaimName
60
61
pv := getPvFromClaim (client , statefulset .Namespace , svPvcName )
61
- svcPVC , err := client .CoreV1 ().PersistentVolumeClaims (namespace ).Get (ctx , svPvcName ,
62
- metav1.GetOptions {})
63
- gomega .Expect (err ).NotTo (gomega .HaveOccurred ())
64
62
63
+ // Get SVC PVC
64
+ svcPVC , err := client .CoreV1 ().PersistentVolumeClaims (namespace ).Get (ctx , svPvcName , metav1.GetOptions {})
65
+ if err != nil {
66
+ return fmt .Errorf ("failed to get SVC PVC %s in namespace %s: %w" , svPvcName , namespace , err )
67
+ }
68
+
69
+ // Get ready and schedulable nodes
65
70
nodeList , err := fnodes .GetReadySchedulableNodes (ctx , client )
66
71
if err != nil {
67
- return err
72
+ return fmt . Errorf ( "failed to get ready and schedulable nodes: %w" , err )
68
73
}
69
74
if len (nodeList .Items ) <= 0 {
70
- return fmt .Errorf ("unable to find ready and schedulable Node " )
75
+ return fmt .Errorf ("no ready and schedulable nodes found " )
71
76
}
72
77
73
- framework . Logf ( " Verify SV PVC has topology annotations set" )
78
+ // Verify SV PVC topology annotations
74
79
err = checkPvcTopologyAnnotationOnSvc (svcPVC , allowedTopologiesMap , topologyCategories )
75
- gomega .Expect (err ).NotTo (gomega .HaveOccurred ())
76
- framework .Logf ("SVC PVC: %s has topology annotations set" , svcPVC .Name )
80
+ if err != nil {
81
+ return fmt .Errorf ("topology annotation verification failed for SVC PVC %s: %w" , svcPVC .Name , err )
82
+ }
77
83
78
- framework . Logf ( " Verify SV PV has has required PV node affinity details" )
84
+ // Verify SV PV node affinity details
79
85
svcPV := getPvFromClaim (client , namespace , svPvcName )
80
86
_ , err = verifyVolumeTopologyForLevel5 (svcPV , allowedTopologiesMap )
81
- gomega .Expect (err ).NotTo (gomega .HaveOccurred ())
82
- framework .Logf ("SVC PV: %s has required PV node affinity details" , svcPV .Name )
87
+ if err != nil {
88
+ return fmt .Errorf ("topology verification failed for SVC PV %s: %w" , svcPV .Name , err )
89
+ }
83
90
84
- framework . Logf ( " Verify Pod node annotation" )
91
+ // Verify pod node annotation
85
92
_ , err = verifyPodLocationLevel5 (& sspod , nodeList , allowedTopologiesMap )
86
- gomega .Expect (err ).NotTo (gomega .HaveOccurred ())
87
-
88
- framework .Logf ("Verify CNS volume metadata for Pod, PVC and PV" )
89
- err = verifyVolumeMetadataInCNS (& e2eVSphere , pv .Spec .CSI .VolumeHandle ,
90
- svPvcName , pv .ObjectMeta .Name , sspod .Name )
91
- gomega .Expect (err ).NotTo (gomega .HaveOccurred ())
93
+ if err != nil {
94
+ return fmt .Errorf ("pod node annotation verification failed for pod %s: %w" , sspod .Name , err )
95
+ }
92
96
97
+ // Verify CNS volume metadata
98
+ err = verifyVolumeMetadataInCNS (& e2eVSphere , pv .Spec .CSI .VolumeHandle , svPvcName , pv .ObjectMeta .Name , sspod .Name )
99
+ if err != nil {
100
+ return fmt .Errorf ("CNS volume metadata verification failed for pod %s: %w" , sspod .Name , err )
101
+ }
93
102
}
94
103
}
95
104
}
96
105
return nil
97
106
}
98
107
108
+
99
109
// Function to check annotation on a Supervisor PVC
100
110
func checkPvcTopologyAnnotationOnSvc (svcPVC * v1.PersistentVolumeClaim ,
101
111
allowedTopologies map [string ][]string , categories []string ) error {
0 commit comments