Skip to content

Commit a20db10

Browse files
Cecile Robert-Michonfabriziopandini
andcommitted
🌱 Add error messages for all e2e Ginkgo expects
Co-Authored-By: Fabrizio Pandini <[email protected]>
1 parent ac42ba2 commit a20db10

14 files changed

+47
-65
lines changed

test/e2e/cluster_upgrade_runtimesdk.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,12 +475,12 @@ func runtimeHookTestHandler(ctx context.Context, c client.Client, namespace, clu
475475
configMap := &corev1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Name: clusterName + "-hookresponses", Namespace: namespace}}
476476
Eventually(func() error {
477477
return c.Get(ctx, util.ObjectKey(configMap), configMap)
478-
}).Should(Succeed())
478+
}).Should(Succeed(), "Failed to get ConfigMap %s/%s", namespace, configMap.Name)
479479
patch := client.RawPatch(types.MergePatchType,
480480
[]byte(fmt.Sprintf(`{"data":{"%s-preloadedResponse":%s}}`, hookName, "\"{\\\"Status\\\": \\\"Success\\\"}\"")))
481481
Eventually(func() error {
482482
return c.Patch(ctx, configMap, patch)
483-
}).Should(Succeed())
483+
}).Should(Succeed(), "Failed to set %s response to Status:Success to unblock the reconciliation", hookName)
484484

485485
// Expect the Hook to pass, setting the blockingCondition to false before the timeout ends.
486486
Eventually(func() bool {

test/e2e/clusterctl_upgrade.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg
285285
}
286286
}
287287
return n, nil
288-
}, input.E2EConfig.GetIntervals(specName, "wait-worker-nodes")...).Should(Equal(*controlPlaneMachineCount + *workerMachineCount))
288+
}, input.E2EConfig.GetIntervals(specName, "wait-worker-nodes")...).Should(Equal(*controlPlaneMachineCount+*workerMachineCount), "Timed out waiting for all machines to be exist")
289289

290290
By("THE MANAGEMENT CLUSTER WITH OLDER VERSION OF PROVIDERS WORKS!")
291291

test/e2e/self_hosted.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func SelfHostedSpec(ctx context.Context, inputGetter func() SelfHostedSpecInput)
122122
return nil
123123
}
124124
return errors.New("cluster object not yet reconciled")
125-
}, "1m", "5s").Should(Succeed())
125+
}, "1m", "5s").Should(Succeed(), "Failed to get the Cluster %s/%s", cluster.Namespace, cluster.Name)
126126

127127
if isDockerCluster {
128128
Expect(bootstrap.LoadImagesToKindCluster(ctx, bootstrap.LoadImagesToKindClusterInput{

test/framework/alltypes_helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func CreateRelatedResources(ctx context.Context, input CreateRelatedResourcesInp
171171
Byf("creating a/an %s resource", obj.GetObjectKind().GroupVersionKind())
172172
Eventually(func() error {
173173
return input.Creator.Create(ctx, obj)
174-
}, intervals...).Should(Succeed())
174+
}, intervals...).Should(Succeed(), "failed to create %s", obj.GetObjectKind().GroupVersionKind())
175175
}
176176
}
177177

test/framework/cluster_helpers.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func CreateCluster(ctx context.Context, input CreateClusterInput, intervals ...i
4343
By("creating an InfrastructureCluster resource")
4444
Eventually(func() error {
4545
return input.Creator.Create(ctx, input.InfraCluster)
46-
}, retryableOperationTimeout, retryableOperationInterval).Should(Succeed())
46+
}, retryableOperationTimeout, retryableOperationInterval).Should(Succeed(), "Failed to create InfrastructureCluster %s/%s", input.InfraCluster.GetNamespace(), input.InfraCluster.GetName())
4747

4848
// This call happens in an eventually because of a race condition with the
4949
// webhook server. If the latter isn't fully online then this call will
@@ -55,7 +55,7 @@ func CreateCluster(ctx context.Context, input CreateClusterInput, intervals ...i
5555
return err
5656
}
5757
return nil
58-
}, intervals...).Should(Succeed())
58+
}, intervals...).Should(Succeed(), "Failed to create Cluster %s/%s", input.Cluster.Namespace, input.Cluster.Name)
5959
}
6060

6161
// GetAllClustersByNamespaceInput is the input for GetAllClustersByNamespace.
@@ -118,7 +118,7 @@ func PatchClusterLabel(ctx context.Context, input PatchClusterLabelInput) {
118118
input.Cluster.SetLabels(input.Labels)
119119
Eventually(func() error {
120120
return patchHelper.Patch(ctx, input.Cluster)
121-
}, retryableOperationTimeout, retryableOperationInterval).Should(Succeed())
121+
}, retryableOperationTimeout, retryableOperationInterval).Should(Succeed(), "Failed to patch label to cluster %s/%s", input.Cluster.Namespace, input.Cluster.Name)
122122
}
123123

124124
// WaitForClusterToProvisionInput is the input for WaitForClusterToProvision.
@@ -140,7 +140,7 @@ func WaitForClusterToProvision(ctx context.Context, input WaitForClusterToProvis
140140
return "", err
141141
}
142142
return cluster.Status.Phase, nil
143-
}, intervals...).Should(Equal(string(clusterv1.ClusterPhaseProvisioned)))
143+
}, intervals...).Should(Equal(string(clusterv1.ClusterPhaseProvisioned)), "Timed out waiting for Cluster %s/%s to provision", input.Cluster.GetNamespace(), input.Cluster.GetName())
144144
return cluster
145145
}
146146

test/framework/cluster_topology_helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func UpgradeClusterTopologyAndWaitForUpgrade(ctx context.Context, input UpgradeC
102102
}
103103
Eventually(func() error {
104104
return patchHelper.Patch(ctx, input.Cluster)
105-
}, retryableOperationTimeout, retryableOperationInterval).Should(Succeed())
105+
}, retryableOperationTimeout, retryableOperationInterval).Should(Succeed(), "Failed to patch Cluster topology %s/%s with version %s", input.Cluster.Namespace, input.Cluster.Name, input.KubernetesUpgradeVersion)
106106

107107
// Once we have patched the Kubernetes Cluster we can run PreWaitForControlPlaneToBeUpgraded.
108108
// Note: This can e.g. be used to verify the BeforeClusterUpgrade lifecycle hook is executed

test/framework/control_plane.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,5 @@ func WaitForControlPlaneToBeUpToDate(ctx context.Context, input WaitForControlPl
4545
return 0, err
4646
}
4747
return controlplane.Status.UpdatedReplicas, nil
48-
}, intervals...).Should(Equal(*input.ControlPlane.Spec.Replicas))
48+
}, intervals...).Should(Equal(*input.ControlPlane.Spec.Replicas), "Timed waiting for all control plane replicas to be updated")
4949
}

test/framework/controlplane_helpers.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func CreateKubeadmControlPlane(ctx context.Context, input CreateKubeadmControlPl
4949
By("creating the machine template")
5050
Eventually(func() error {
5151
return input.Creator.Create(ctx, input.MachineTemplate)
52-
}, retryableOperationTimeout, retryableOperationInterval).Should(Succeed())
52+
}, retryableOperationTimeout, retryableOperationInterval).Should(Succeed(), "Failed to create MachineTemplate %s", input.MachineTemplate.GetName())
5353

5454
By("creating a KubeadmControlPlane")
5555
Eventually(func() error {
@@ -58,7 +58,7 @@ func CreateKubeadmControlPlane(ctx context.Context, input CreateKubeadmControlPl
5858
log.Logf("Failed to create the KubeadmControlPlane: %+v", err)
5959
}
6060
return err
61-
}, intervals...).Should(Succeed())
61+
}, intervals...).Should(Succeed(), "Failed to create the KubeadmControlPlane %s/%s", input.ControlPlane.Namespace, input.ControlPlane.Name)
6262
}
6363

6464
// GetKubeadmControlPlaneByClusterInput is the input for GetKubeadmControlPlaneByCluster.
@@ -113,7 +113,7 @@ func WaitForKubeadmControlPlaneMachinesToExist(ctx context.Context, input WaitFo
113113
}
114114
}
115115
return count, nil
116-
}, intervals...).Should(Equal(int(*input.ControlPlane.Spec.Replicas)))
116+
}, intervals...).Should(Equal(int(*input.ControlPlane.Spec.Replicas)), "Timed out waiting for %d control plane machines to exist", int(*input.ControlPlane.Spec.Replicas))
117117
}
118118

119119
// WaitForOneKubeadmControlPlaneMachineToExistInput is the input for WaitForKubeadmControlPlaneMachinesToExist.
@@ -242,7 +242,7 @@ func DiscoveryAndWaitForControlPlaneInitialized(ctx context.Context, input Disco
242242
Namespace: input.Cluster.Namespace,
243243
})
244244
g.Expect(controlPlane).ToNot(BeNil())
245-
}, "10s", "1s").Should(Succeed())
245+
}, "10s", "1s").Should(Succeed(), "Couldn't get the control plane for the cluster %q", input.Cluster.Name)
246246

247247
log.Logf("Waiting for the first control plane machine managed by %s/%s to be provisioned", controlPlane.Namespace, controlPlane.Name)
248248
WaitForOneKubeadmControlPlaneMachineToExist(ctx, WaitForOneKubeadmControlPlaneMachineToExistInput{
@@ -339,7 +339,7 @@ func UpgradeControlPlaneAndWaitForUpgrade(ctx context.Context, input UpgradeCont
339339

340340
Eventually(func() error {
341341
return patchHelper.Patch(ctx, input.ControlPlane)
342-
}, retryableOperationTimeout, retryableOperationInterval).Should(Succeed())
342+
}, retryableOperationTimeout, retryableOperationInterval).Should(Succeed(), "Failed to patch the new kubernetes version to KCP %s/%s", input.ControlPlane.Namespace, input.ControlPlane.Name)
343343

344344
log.Logf("Waiting for control-plane machines to have the upgraded kubernetes version")
345345
WaitForControlPlaneMachinesToBeUpgraded(ctx, WaitForControlPlaneMachinesToBeUpgradedInput{
@@ -401,7 +401,7 @@ func ScaleAndWaitControlPlane(ctx context.Context, input ScaleAndWaitControlPlan
401401
log.Logf("Scaling controlplane %s/%s from %v to %v replicas", input.ControlPlane.Namespace, input.ControlPlane.Name, scaleBefore, input.Replicas)
402402
Eventually(func() error {
403403
return patchHelper.Patch(ctx, input.ControlPlane)
404-
}, retryableOperationTimeout, retryableOperationInterval).Should(Succeed())
404+
}, retryableOperationTimeout, retryableOperationInterval).Should(Succeed(), "Failed to scale controlplane %s/%s from %v to %v replicas", input.ControlPlane.Namespace, input.ControlPlane.Name, scaleBefore, input.Replicas)
405405

406406
log.Logf("Waiting for correct number of replicas to exist")
407407
Eventually(func() (int, error) {
@@ -428,5 +428,5 @@ func ScaleAndWaitControlPlane(ctx context.Context, input ScaleAndWaitControlPlan
428428
return -1, errors.New("Machine count does not match existing nodes count")
429429
}
430430
return nodeRefCount, nil
431-
}, input.WaitForControlPlane...).Should(Equal(int(input.Replicas)))
431+
}, input.WaitForControlPlane...).Should(Equal(int(input.Replicas)), "Timed out waiting for %d replicas to exist for control-plane %s/%s", int(input.Replicas), input.ControlPlane.Namespace, input.ControlPlane.Name)
432432
}

test/framework/deployment_helpers.go

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import (
3333
appsv1 "k8s.io/api/apps/v1"
3434
corev1 "k8s.io/api/core/v1"
3535
"k8s.io/api/policy/v1beta1"
36-
apierrors "k8s.io/apimachinery/pkg/api/errors"
3736
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3837
"k8s.io/apimachinery/pkg/util/intstr"
3938
utilversion "k8s.io/apimachinery/pkg/util/version"
@@ -311,24 +310,8 @@ func DeployUnevictablePod(ctx context.Context, input DeployUnevictablePodInput)
311310
Expect(input.DeploymentName).ToNot(BeNil(), "Need a deployment name in DeployUnevictablePod")
312311
Expect(input.Namespace).ToNot(BeNil(), "Need a namespace in DeployUnevictablePod")
313312
Expect(input.WorkloadClusterProxy).ToNot(BeNil(), "Need a workloadClusterProxy in DeployUnevictablePod")
314-
workloadClient := input.WorkloadClusterProxy.GetClientSet()
315313

316-
log.Logf("Check if namespace %s exists", input.Namespace)
317-
Eventually(func() error {
318-
_, err := workloadClient.CoreV1().Namespaces().Get(ctx, input.Namespace, metav1.GetOptions{})
319-
if err != nil {
320-
if apierrors.IsNotFound(err) {
321-
_, errCreateNamespace := workloadClient.CoreV1().Namespaces().Create(ctx, &corev1.Namespace{
322-
ObjectMeta: metav1.ObjectMeta{
323-
Name: input.Namespace,
324-
},
325-
}, metav1.CreateOptions{})
326-
return errCreateNamespace
327-
}
328-
return err
329-
}
330-
return nil
331-
}, retryableOperationTimeout, retryableOperationInterval).Should(Succeed())
314+
EnsureNamespace(ctx, input.WorkloadClusterProxy.GetClient(), input.Namespace)
332315

333316
workloadDeployment := &appsv1.Deployment{
334317
ObjectMeta: metav1.ObjectMeta{
@@ -366,13 +349,14 @@ func DeployUnevictablePod(ctx context.Context, input DeployUnevictablePodInput)
366349
},
367350
},
368351
}
352+
workloadClient := input.WorkloadClusterProxy.GetClientSet()
369353
if input.ControlPlane != nil {
370354
var serverVersion *version.Info
371355
Eventually(func() error {
372356
var err error
373357
serverVersion, err = workloadClient.ServerVersion()
374358
return err
375-
}, retryableOperationTimeout, retryableOperationInterval).Should(Succeed())
359+
}, retryableOperationTimeout, retryableOperationInterval).Should(Succeed(), "failed to get server version")
376360

377361
// Use the control-plane label for Kubernetes version >= v1.20.0.
378362
if utilversion.MustParseGeneric(serverVersion.String()).AtLeast(utilversion.MustParseGeneric("v1.20.0")) {
@@ -445,7 +429,7 @@ func AddDeploymentToWorkloadCluster(ctx context.Context, input AddDeploymentToWo
445429
return nil
446430
}
447431
return fmt.Errorf("deployment %s in namespace %s not successfully created in workload cluster: %v", input.Deployment.Name, input.Namespace, err)
448-
}, retryableOperationTimeout, retryableOperationInterval).Should(Succeed())
432+
}, retryableOperationTimeout, retryableOperationInterval).Should(Succeed(), "Failed to create deployment %s/%s in workload cluster", input.Namespace, input.Deployment.Name)
449433
}
450434

451435
type AddPodDisruptionBudgetInput struct {

test/framework/machine_helpers.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func WaitForControlPlaneMachinesToBeUpgraded(ctx context.Context, input WaitForC
147147
return 0, errors.New("old nodes remain")
148148
}
149149
return upgraded, nil
150-
}, intervals...).Should(Equal(input.MachineCount))
150+
}, intervals...).Should(Equal(input.MachineCount), "Timed out waiting for all control-plane machines in Cluster %s/%s to be upgraded to kubernetes version %s", input.Cluster.Namespace, input.Cluster.Name, input.KubernetesUpgradeVersion)
151151
}
152152

153153
// WaitForMachineDeploymentMachinesToBeUpgradedInput is the input for WaitForMachineDeploymentMachinesToBeUpgraded.
@@ -187,7 +187,7 @@ func WaitForMachineDeploymentMachinesToBeUpgraded(ctx context.Context, input Wai
187187
return 0, errors.New("old nodes remain")
188188
}
189189
return upgraded, nil
190-
}, intervals...).Should(Equal(input.MachineCount))
190+
}, intervals...).Should(Equal(input.MachineCount), "Timed out waiting for all MachineDeployment %s/%s Machines to be upgraded to kubernetes version %s", input.MachineDeployment.Namespace, input.MachineDeployment.Name, input.KubernetesUpgradeVersion)
191191
}
192192

193193
// PatchNodeConditionInput is the input for PatchNodeCondition.
@@ -211,13 +211,13 @@ func PatchNodeCondition(ctx context.Context, input PatchNodeConditionInput) {
211211
node := &corev1.Node{}
212212
Eventually(func() error {
213213
return input.ClusterProxy.GetWorkloadCluster(ctx, input.Cluster.Namespace, input.Cluster.Name).GetClient().Get(ctx, types.NamespacedName{Name: input.Machine.Status.NodeRef.Name, Namespace: input.Machine.Status.NodeRef.Namespace}, node)
214-
}, retryableOperationTimeout, retryableOperationInterval).Should(Succeed())
214+
}, retryableOperationTimeout, retryableOperationInterval).Should(Succeed(), "Failed to get node %s", input.Machine.Status.NodeRef.Name)
215215
patchHelper, err := patch.NewHelper(node, input.ClusterProxy.GetWorkloadCluster(ctx, input.Cluster.Namespace, input.Cluster.Name).GetClient())
216216
Expect(err).ToNot(HaveOccurred())
217217
node.Status.Conditions = append(node.Status.Conditions, input.NodeCondition)
218218
Eventually(func() error {
219219
return patchHelper.Patch(ctx, node)
220-
}, retryableOperationTimeout, retryableOperationInterval).Should(Succeed())
220+
}, retryableOperationTimeout, retryableOperationInterval).Should(Succeed(), "Failed to patch node %s", input.Machine.Status.NodeRef.Name)
221221
}
222222

223223
// MachineStatusCheck is a type that operates a status check on a Machine.

0 commit comments

Comments
 (0)