@@ -67,6 +67,9 @@ func ProjectSpec(ctx context.Context, inputGetter func() CommonSpecInput) {
67
67
if (err != nil ) || (project == nil ) {
68
68
Skip ("Failed to fetch project" )
69
69
}
70
+
71
+ // Initialize affinityIds to an empty slice to avoid nil checks
72
+ affinityIds = make ([]string , 0 )
70
73
})
71
74
72
75
It ("Should create a cluster in a project" , func () {
@@ -90,22 +93,41 @@ func ProjectSpec(ctx context.Context, inputGetter func() CommonSpecInput) {
90
93
WaitForMachineDeployments : input .E2EConfig .GetIntervals (specName , "wait-worker-nodes" ),
91
94
}, clusterResources )
92
95
96
+ // Ensure the cluster was created successfully before proceeding with checks
97
+ Expect (clusterResources .Cluster ).ToNot (BeNil (), "Cluster was not created successfully" )
98
+
99
+ By ("Checking affinity groups and VPC in project" )
93
100
csClient := CreateCloudStackClient (ctx , input .BootstrapClusterProxy .GetKubeconfigPath ())
94
- affinityIds = CheckAffinityGroupInProject (csClient , clusterResources .Cluster .Name , "pro" , projectName )
101
+
102
+ // Check affinity groups
103
+ By (fmt .Sprintf ("Checking affinity groups for cluster %s in project %s" , clusterResources .Cluster .Name , projectName ))
104
+ tempAffinityIds := CheckAffinityGroupInProject (csClient , clusterResources .Cluster .Name , "pro" , projectName )
105
+ Expect (tempAffinityIds ).ToNot (BeEmpty (), "No affinity groups found for cluster" )
106
+ affinityIds = tempAffinityIds
107
+
108
+ // Check VPC
109
+ By (fmt .Sprintf ("Checking if VPC %s exists in project %s" , vpcName , projectName ))
95
110
exists , err := CheckVPCExistsInProject (csClient , vpcName , projectName )
96
- Expect (err ).To (BeNil ())
97
- Expect (exists ).To (BeTrue ())
111
+ Expect (err ).To (BeNil (), "Error checking VPC existence" )
112
+ Expect (exists ).To (BeTrue (), fmt . Sprintf ( "VPC %s does not exist in project %s" , vpcName , projectName ) )
98
113
})
99
114
100
115
AfterEach (func () {
101
116
// Dumps all the resources in the spec namespace, then cleanups the cluster object and the spec namespace itself.
102
117
dumpSpecResourcesAndCleanup (ctx , specName , input .BootstrapClusterProxy , input .ArtifactFolder , namespace , cancelWatches , clusterResources .Cluster , input .E2EConfig .GetIntervals , input .SkipCleanup )
103
118
104
119
csClient := CreateCloudStackClient (ctx , input .BootstrapClusterProxy .GetKubeconfigPath ())
105
- err := CheckAffinityGroupsDeletedInProject (csClient , affinityIds , projectName )
106
- if err != nil {
107
- Fail (err .Error ())
120
+
121
+ // Only check for affinity group deletion if affinity groups were created
122
+ if len (affinityIds ) > 0 {
123
+ err := CheckAffinityGroupsDeletedInProject (csClient , affinityIds , projectName )
124
+ if err != nil {
125
+ Fail (err .Error ())
126
+ }
127
+ } else {
128
+ By ("Skipping affinity group deletion check as no affinity groups were created" )
108
129
}
130
+
109
131
By ("PASSED!" )
110
132
})
111
133
}
0 commit comments