Skip to content

Commit e874be3

Browse files
committed
Fix e2e test issues introduced by chained upgrades
Signed-off-by: Stefan Büringer [email protected]
1 parent 4b3a973 commit e874be3

File tree

4 files changed

+24
-22
lines changed

4 files changed

+24
-22
lines changed

internal/webhooks/cluster.go

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,8 @@ func (webhook *Cluster) validateTopology(ctx context.Context, oldCluster, newClu
334334
allErrs = append(allErrs, validateAutoscalerAnnotationsForCluster(newCluster, clusterClass)...)
335335

336336
if oldCluster != nil { // On update
337-
// The ClusterClass must exist to proceed with update validation. Return an error if the ClusterClass was
338-
// not found.
339-
if apierrors.IsNotFound(clusterClassPollErr) {
337+
// Return an error if we couldn't get the ClusterClass (either because it was not found or not reconciled).
338+
if clusterClassPollErr != nil {
340339
allErrs = append(
341340
allErrs, field.InternalError(
342341
fldPath.Child("class"),
@@ -402,16 +401,6 @@ func (webhook *Cluster) validateTopology(ctx context.Context, oldCluster, newClu
402401

403402
// If the ClusterClass referenced in the Topology has changed compatibility checks are needed.
404403
if oldCluster.GetClassKey() != newCluster.GetClassKey() {
405-
if clusterClassPollErr != nil {
406-
allErrs = append(
407-
allErrs, field.Forbidden(
408-
fldPath.Child("class"),
409-
fmt.Sprintf("cannot rebase to ClusterClass %q: %s",
410-
newCluster.GetClassKey(), clusterClassPollErr.Error())))
411-
// Return early with errors if the new ClusterClass can't be retrieved.
412-
return allWarnings, allErrs
413-
}
414-
415404
// Check to see if the ClusterClass referenced in the old version of the Cluster exists.
416405
oldClusterClass, err := webhook.pollClusterClassForCluster(ctx, oldCluster)
417406
if err != nil {

test/e2e/cluster_upgrade_runtimesdk_test.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,10 @@ var _ = Describe("When performing chained upgrades for workload cluster using Cl
100100
DeployClusterClassInSeparateNamespace: true,
101101
// Setting Kubernetes version from
102102
KubernetesVersionFrom: e2eConfig.MustGetVariable(KubernetesVersionChainedUpgradeFrom),
103-
// use Kubernetes versions from the kind mapper.
104-
KubernetesVersions: kind.GetKubernetesVersions(),
103+
// use Kubernetes versions from the kind mapper
104+
// Note: Ensure KUBERNETES_VERSION_UPGRADE_TO is always part of the list, this is required for cases where
105+
// KUBERNETES_VERSION_UPGRADE_TO is not in the kind mapper, e.g. in the `e2e-latestk8s` prowjob.
106+
KubernetesVersions: appendIfNecessary(kind.GetKubernetesVersions(), e2eConfig.MustGetVariable(KubernetesVersionUpgradeTo)),
105107
// The runtime extension gets deployed to the test-extension-system namespace and is exposed
106108
// by the test-extension-webhook-service.
107109
// The below values are used when creating the cluster-wide ExtensionConfig to refer
@@ -112,3 +114,12 @@ var _ = Describe("When performing chained upgrades for workload cluster using Cl
112114
}
113115
})
114116
})
117+
118+
func appendIfNecessary(versions []string, v string) []string {
119+
for _, version := range versions {
120+
if version == v {
121+
return versions
122+
}
123+
}
124+
return append(versions, v)
125+
}

test/framework/deployment_helpers.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,12 +412,12 @@ func dumpPodMetrics(ctx context.Context, client *kubernetes.Clientset, metricsPa
412412
}
413413

414414
if !errorRetrievingMetrics {
415-
Expect(verifyMetrics(data)).To(Succeed())
415+
Expect(verifyMetrics(data, &pod)).To(Succeed())
416416
}
417417
}
418418
}
419419

420-
func verifyMetrics(data []byte) error {
420+
func verifyMetrics(data []byte, pod *corev1.Pod) error {
421421
var parser expfmt.TextParser
422422
mf, err := parser.TextToMetricFamilies(bytes.NewReader(data))
423423
if err != nil {
@@ -458,7 +458,7 @@ func verifyMetrics(data []byte) error {
458458
}
459459

460460
if len(errs) > 0 {
461-
return kerrors.NewAggregate(errs)
461+
return errors.Wrapf(kerrors.NewAggregate(errs), "panics occurred in Pod %s", klog.KObj(pod))
462462
}
463463

464464
return nil

test/framework/deployment_helpers_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import (
2020
"testing"
2121

2222
. "github.com/onsi/gomega"
23+
corev1 "k8s.io/api/core/v1"
24+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2325
)
2426

2527
func Test_verifyMetrics(t *testing.T) {
@@ -68,7 +70,7 @@ controller_runtime_reconcile_panics_total{controller="clusterclass"} 0
6870
# TYPE controller_runtime_webhook_panics_total counter
6971
controller_runtime_webhook_panics_total 0
7072
`),
71-
wantErr: "1 panics occurred in \"cluster\" controller (check logs for more details)",
73+
wantErr: "panics occurred in Pod default/pod1: 1 panics occurred in \"cluster\" controller (check logs for more details)",
7274
},
7375
{
7476
name: "panic occurred in webhooks",
@@ -88,7 +90,7 @@ controller_runtime_webhook_panics_total 1
8890
# TYPE controller_runtime_conversion_webhook_panics_total counter
8991
controller_runtime_conversion_webhook_panics_total 0
9092
`),
91-
wantErr: "1 panics occurred in webhooks (check logs for more details)",
93+
wantErr: "panics occurred in Pod default/pod1: 1 panics occurred in webhooks (check logs for more details)",
9294
},
9395
{
9496
name: "panics occurred in conversion webhooks",
@@ -108,14 +110,14 @@ controller_runtime_webhook_panics_total 0
108110
# TYPE controller_runtime_conversion_webhook_panics_total counter
109111
controller_runtime_conversion_webhook_panics_total 2
110112
`),
111-
wantErr: "2 panics occurred in conversion webhooks (check logs for more details)",
113+
wantErr: "panics occurred in Pod default/pod1: 2 panics occurred in conversion webhooks (check logs for more details)",
112114
},
113115
}
114116
for _, tt := range tests {
115117
t.Run(tt.name, func(t *testing.T) {
116118
g := NewWithT(t)
117119

118-
err := verifyMetrics(tt.data)
120+
err := verifyMetrics(tt.data, &corev1.Pod{ObjectMeta: metav1.ObjectMeta{Namespace: "default", Name: "pod1"}})
119121
if tt.wantErr == "" {
120122
g.Expect(err).ToNot(HaveOccurred())
121123
} else {

0 commit comments

Comments
 (0)