Skip to content

Commit a087b02

Browse files
authored
Merge pull request kubernetes-sigs#6987 from CecileRobertMichon/e2e-failure-msgs
🌱 Add error messages for all e2e Ginkgo expects
2 parents d761e1b + fe70e9e commit a087b02

25 files changed

+144
-142
lines changed

cmd/clusterctl/client/cluster/mover_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ var moveTests = []struct {
557557
},
558558
wantMoveGroups: [][]string{
559559
{ // group1
560-
"external.cluster.x-k8s.io/v1beta1, Kind=GenericClusterExternalObject, /externalObject1",
560+
"external.cluster.x-k8s.io/v1beta1, Kind=GenericClusterExternalObject, externalObject1",
561561
},
562562
},
563563
wantErr: false,
@@ -591,7 +591,7 @@ var moveTests = []struct {
591591
},
592592
wantMoveGroups: [][]string{
593593
{ // group 1
594-
"infrastructure.cluster.x-k8s.io/v1beta1, Kind=GenericClusterInfrastructureIdentity, /infra1-identity",
594+
"infrastructure.cluster.x-k8s.io/v1beta1, Kind=GenericClusterInfrastructureIdentity, infra1-identity",
595595
},
596596
{ // group 2 (objects with ownerReferences in group 1)
597597
// owned by Clusters

cmd/clusterctl/client/cluster/objectgraph_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,7 @@ var objectGraphsTests = []struct {
12451245
},
12461246
want: wantGraph{
12471247
nodes: map[string]wantGraphItem{
1248-
"external.cluster.x-k8s.io/v1beta1, Kind=GenericClusterExternalObject, /externalObject1": {
1248+
"external.cluster.x-k8s.io/v1beta1, Kind=GenericClusterExternalObject, externalObject1": {
12491249
forceMove: true,
12501250
isGlobal: true,
12511251
},
@@ -1310,14 +1310,14 @@ var objectGraphsTests = []struct {
13101310
},
13111311
want: wantGraph{
13121312
nodes: map[string]wantGraphItem{
1313-
"infrastructure.cluster.x-k8s.io/v1beta1, Kind=GenericClusterInfrastructureIdentity, /infra1-identity": {
1313+
"infrastructure.cluster.x-k8s.io/v1beta1, Kind=GenericClusterInfrastructureIdentity, infra1-identity": {
13141314
isGlobal: true,
13151315
forceMove: true,
13161316
forceMoveHierarchy: true,
13171317
},
13181318
"/v1, Kind=Secret, infra1-system/infra1-identity-credentials": {
13191319
owners: []string{
1320-
"infrastructure.cluster.x-k8s.io/v1beta1, Kind=GenericClusterInfrastructureIdentity, /infra1-identity",
1320+
"infrastructure.cluster.x-k8s.io/v1beta1, Kind=GenericClusterInfrastructureIdentity, infra1-identity",
13211321
},
13221322
},
13231323
},
@@ -2288,8 +2288,8 @@ func Test_objectGraph_setGlobalIdentityTenants(t *testing.T) {
22882288
Objs(),
22892289
},
22902290
wantIdentity: map[string][]string{ // wantCRDs is a map[ClusterResourceSet.UID] --> list of UIDs
2291-
"infrastructure.cluster.x-k8s.io/v1beta1, Kind=GenericClusterInfrastructureIdentity, /infra1-identity": {
2292-
"infrastructure.cluster.x-k8s.io/v1beta1, Kind=GenericClusterInfrastructureIdentity, /infra1-identity", // the global identity should be tenant of itself
2291+
"infrastructure.cluster.x-k8s.io/v1beta1, Kind=GenericClusterInfrastructureIdentity, infra1-identity": {
2292+
"infrastructure.cluster.x-k8s.io/v1beta1, Kind=GenericClusterInfrastructureIdentity, infra1-identity", // the global identity should be tenant of itself
22932293
"/v1, Kind=Secret, infra1-system/infra1-identity-credentials",
22942294
},
22952295
},

cmd/clusterctl/internal/test/fake_objects.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2727
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2828
"k8s.io/apimachinery/pkg/types"
29+
"k8s.io/klog/v2"
2930
"sigs.k8s.io/controller-runtime/pkg/client"
3031
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
3132

@@ -1302,9 +1303,9 @@ func SelectClusterObj(objs []client.Object, namespace, name string) *clusterv1.C
13021303
func setUID(obj client.Object) {
13031304
accessor, err := meta.Accessor(obj)
13041305
if err != nil {
1305-
panic(fmt.Sprintf("failde to get accessor for test object: %v", err))
1306+
panic(fmt.Sprintf("failed to get accessor for test object: %v", err))
13061307
}
1307-
uid := fmt.Sprintf("%s, %s/%s", obj.GetObjectKind().GroupVersionKind().String(), accessor.GetNamespace(), accessor.GetName())
1308+
uid := fmt.Sprintf("%s, %s", obj.GetObjectKind().GroupVersionKind().String(), klog.KObj(accessor))
13081309
accessor.SetUID(types.UID(uid))
13091310
}
13101311

test/e2e/cluster_upgrade_runtimesdk.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
apierrors "k8s.io/apimachinery/pkg/api/errors"
3333
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3434
"k8s.io/apimachinery/pkg/types"
35+
"k8s.io/klog/v2"
3536
"k8s.io/utils/pointer"
3637
"sigs.k8s.io/controller-runtime/pkg/client"
3738

@@ -337,7 +338,7 @@ func checkLifecycleHookResponses(ctx context.Context, c client.Client, namespace
337338
for hookName, expectedResponse := range expectedHookResponses {
338339
actualResponse, ok := responseData[hookName+"-actualResponseStatus"]
339340
if !ok {
340-
return errors.Errorf("hook %s call not recorded in configMap %s/%s", hookName, namespace, clusterName+"-hookresponses")
341+
return errors.Errorf("hook %s call not recorded in configMap %s", hookName, klog.KRef(namespace, clusterName+"-hookresponses"))
341342
}
342343
if expectedResponse != "" && expectedResponse != actualResponse {
343344
return errors.Errorf("hook %s was expected to be %s in configMap got %s", hookName, expectedResponse, actualResponse)
@@ -351,7 +352,7 @@ func checkLifecycleHooksCalledAtLeastOnce(ctx context.Context, c client.Client,
351352
responseData := getLifecycleHookResponsesFromConfigMap(ctx, c, namespace, clusterName)
352353
for _, hookName := range expectedHooks {
353354
if _, ok := responseData[hookName+"-actualResponseStatus"]; !ok {
354-
return errors.Errorf("hook %s call not recorded in configMap %s/%s", hookName, namespace, clusterName+"-hookresponses")
355+
return errors.Errorf("hook %s call not recorded in configMap %s", hookName, klog.KRef(namespace, clusterName+"-hookresponses"))
355356
}
356357
}
357358
return nil
@@ -475,12 +476,12 @@ func runtimeHookTestHandler(ctx context.Context, c client.Client, namespace, clu
475476
configMap := &corev1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Name: clusterName + "-hookresponses", Namespace: namespace}}
476477
Eventually(func() error {
477478
return c.Get(ctx, util.ObjectKey(configMap), configMap)
478-
}).Should(Succeed())
479+
}).Should(Succeed(), "Failed to get ConfigMap %s", klog.KObj(configMap))
479480
patch := client.RawPatch(types.MergePatchType,
480481
[]byte(fmt.Sprintf(`{"data":{"%s-preloadedResponse":%s}}`, hookName, "\"{\\\"Status\\\": \\\"Success\\\"}\"")))
481482
Eventually(func() error {
482483
return c.Patch(ctx, configMap, patch)
483-
}).Should(Succeed())
484+
}).Should(Succeed(), "Failed to set %s response to Status:Success to unblock the reconciliation", hookName)
484485

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

test/e2e/clusterclass_changes.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/pkg/errors"
2929
corev1 "k8s.io/api/core/v1"
3030
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
31+
"k8s.io/klog/v2"
3132
"k8s.io/utils/pointer"
3233
"sigs.k8s.io/controller-runtime/pkg/client"
3334

@@ -192,7 +193,7 @@ func modifyControlPlaneViaClusterClassAndWait(ctx context.Context, input modifyC
192193

193194
mgmtClient := input.ClusterProxy.GetClient()
194195

195-
log.Logf("Modifying the ControlPlaneTemplate of ClusterClass %s/%s", input.ClusterClass.Namespace, input.ClusterClass.Name)
196+
log.Logf("Modifying the ControlPlaneTemplate of ClusterClass %s", klog.KObj(input.ClusterClass))
196197

197198
// Get ControlPlaneTemplate object.
198199
controlPlaneTemplateRef := input.ClusterClass.Spec.ControlPlane.Ref
@@ -265,7 +266,7 @@ func modifyMachineDeploymentViaClusterClassAndWait(ctx context.Context, input mo
265266
continue
266267
}
267268

268-
log.Logf("Modifying the BootstrapConfigTemplate of MachineDeploymentClass %q of ClusterClass %s/%s", mdClass.Class, input.ClusterClass.Namespace, input.ClusterClass.Name)
269+
log.Logf("Modifying the BootstrapConfigTemplate of MachineDeploymentClass %q of ClusterClass %s", mdClass.Class, klog.KObj(input.ClusterClass))
269270

270271
// Retrieve BootstrapConfigTemplate object.
271272
bootstrapConfigTemplateRef := mdClass.Template.Bootstrap.Ref

test/e2e/clusterctl_upgrade.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
apierrors "k8s.io/apimachinery/pkg/api/errors"
3333
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3434
"k8s.io/client-go/discovery"
35+
"k8s.io/klog/v2"
3536
"k8s.io/utils/pointer"
3637
"sigs.k8s.io/controller-runtime/pkg/client"
3738

@@ -285,7 +286,7 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg
285286
}
286287
}
287288
return n, nil
288-
}, input.E2EConfig.GetIntervals(specName, "wait-worker-nodes")...).Should(Equal(*controlPlaneMachineCount + *workerMachineCount))
289+
}, input.E2EConfig.GetIntervals(specName, "wait-worker-nodes")...).Should(Equal(*controlPlaneMachineCount+*workerMachineCount), "Timed out waiting for all machines to be exist")
289290

290291
By("THE MANAGEMENT CLUSTER WITH OLDER VERSION OF PROVIDERS WORKS!")
291292

@@ -390,7 +391,7 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg
390391
log.Logf("Management Cluster does not appear to support CAPI resources.")
391392
}
392393

393-
Byf("Deleting cluster %s/%s", testNamespace.Name, managementClusterName)
394+
Byf("Deleting cluster %s", klog.KRef(testNamespace.Name, managementClusterName))
394395
framework.DeleteAllClustersAndWait(ctx, framework.DeleteAllClustersAndWaitInput{
395396
Client: managementClusterProxy.GetClient(),
396397
Namespace: testNamespace.Name,
@@ -456,7 +457,7 @@ func deleteAllClustersAndWaitV1alpha3(ctx context.Context, input framework.Delet
456457
}
457458

458459
for _, c := range clusters {
459-
log.Logf("Waiting for the Cluster %s/%s to be deleted", c.Namespace, c.Name)
460+
log.Logf("Waiting for the Cluster %s to be deleted", klog.KObj(c))
460461
waitForClusterDeletedV1alpha3(ctx, waitForClusterDeletedV1alpha3Input{
461462
Getter: input.Client,
462463
Cluster: c,
@@ -526,7 +527,7 @@ func deleteAllClustersAndWaitV1alpha4(ctx context.Context, input framework.Delet
526527
}
527528

528529
for _, c := range clusters {
529-
log.Logf("Waiting for the Cluster %s/%s to be deleted", c.Namespace, c.Name)
530+
log.Logf("Waiting for the Cluster %s to be deleted", klog.KObj(c))
530531
waitForClusterDeletedV1alpha4(ctx, waitForClusterDeletedV1alpha4Input{
531532
Getter: input.Client,
532533
Cluster: c,

test/e2e/common.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
. "github.com/onsi/ginkgo"
2626
"github.com/onsi/gomega/types"
2727
corev1 "k8s.io/api/core/v1"
28+
"k8s.io/klog/v2"
2829

2930
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
3031
"sigs.k8s.io/cluster-api/test/framework"
@@ -78,7 +79,7 @@ func dumpSpecResourcesAndCleanup(ctx context.Context, specName string, clusterPr
7879
})
7980

8081
if !skipCleanup {
81-
Byf("Deleting cluster %s/%s", cluster.Namespace, cluster.Name)
82+
Byf("Deleting cluster %s", klog.KObj(cluster))
8283
// While https://github.com/kubernetes-sigs/cluster-api/issues/2955 is addressed in future iterations, there is a chance
8384
// that cluster variable is not set even if the cluster exists, so we are calling DeleteAllClustersAndWait
8485
// instead of DeleteClusterAndWait

test/e2e/self_hosted.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
. "github.com/onsi/ginkgo"
2727
. "github.com/onsi/gomega"
2828
corev1 "k8s.io/api/core/v1"
29+
"k8s.io/klog/v2"
2930
"k8s.io/utils/pointer"
3031
"sigs.k8s.io/controller-runtime/pkg/client"
3132

@@ -122,7 +123,7 @@ func SelfHostedSpec(ctx context.Context, inputGetter func() SelfHostedSpecInput)
122123
return nil
123124
}
124125
return errors.New("cluster object not yet reconciled")
125-
}, "1m", "5s").Should(Succeed())
126+
}, "1m", "5s").Should(Succeed(), "Failed to get the Cluster %s", klog.KObj(cluster))
126127

127128
if isDockerCluster {
128129
Expect(bootstrap.LoadImagesToKindCluster(ctx, bootstrap.LoadImagesToKindClusterInput{

test/extension/handlers/lifecycle/handlers.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/pkg/errors"
2525
corev1 "k8s.io/api/core/v1"
2626
"k8s.io/apimachinery/pkg/types"
27+
"k8s.io/klog/v2"
2728
ctrl "sigs.k8s.io/controller-runtime"
2829
"sigs.k8s.io/controller-runtime/pkg/client"
2930
"sigs.k8s.io/yaml"
@@ -148,7 +149,7 @@ func (h *Handler) readResponseFromConfigMap(ctx context.Context, name, namespace
148149
configMap := &corev1.ConfigMap{}
149150
configMapName := name + "-hookresponses"
150151
if err := h.Client.Get(ctx, client.ObjectKey{Namespace: namespace, Name: configMapName}, configMap); err != nil {
151-
return errors.Wrapf(err, "failed to read the ConfigMap %s/%s", namespace, configMapName)
152+
return errors.Wrapf(err, "failed to read the ConfigMap %s", klog.KRef(namespace, configMapName))
152153
}
153154
if err := yaml.Unmarshal([]byte(configMap.Data[hookName+"-preloadedResponse"]), response); err != nil {
154155
return errors.Wrapf(err, "failed to read %q response information from ConfigMap", hook)
@@ -165,7 +166,7 @@ func (h *Handler) recordCallInConfigMap(ctx context.Context, name, namespace str
165166
configMap := &corev1.ConfigMap{}
166167
configMapName := name + "-hookresponses"
167168
if err := h.Client.Get(ctx, client.ObjectKey{Namespace: namespace, Name: configMapName}, configMap); err != nil {
168-
return errors.Wrapf(err, "failed to read the ConfigMap %s/%s", namespace, configMapName)
169+
return errors.Wrapf(err, "failed to read the ConfigMap %s", klog.KRef(namespace, configMapName))
169170
}
170171
var patch client.Patch
171172
if r, ok := response.(runtimehooksv1.RetryResponseObject); ok {
@@ -177,7 +178,7 @@ func (h *Handler) recordCallInConfigMap(ctx context.Context, name, namespace str
177178
[]byte(fmt.Sprintf(`{"data":{"%s-actualResponseStatus":"%s"}}`, hookName, response.GetStatus()))) //nolint:gocritic
178179
}
179180
if err := h.Client.Patch(ctx, configMap, patch); err != nil {
180-
return errors.Wrapf(err, "failed to update the ConfigMap %s/%s", namespace, configMapName)
181+
return errors.Wrapf(err, "failed to update the ConfigMap %s", klog.KRef(namespace, configMapName))
181182
}
182183
return nil
183184
}

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

0 commit comments

Comments
 (0)