Skip to content

Commit 6d2fe04

Browse files
authored
Merge pull request #12766 from sbueringer/pr-fix-e2e-chained
🐛 Fix e2e test issues introduced by chained upgrades
2 parents 26c8b19 + 06e3828 commit 6d2fe04

File tree

8 files changed

+42
-27
lines changed

8 files changed

+42
-27
lines changed

internal/webhooks/cluster.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,10 @@ func (webhook *Cluster) pollClusterClassForCluster(ctx context.Context, cluster
974974
return true, nil
975975
})
976976
if clusterClassPollErr != nil {
977+
if errors.Is(clusterClassPollErr, errClusterClassNotReconciled) {
978+
// Return ClusterClass if we were able to get it and it's just not reconciled.
979+
return clusterClass, clusterClassPollErr
980+
}
977981
return nil, clusterClassPollErr
978982
}
979983
return clusterClass, nil

test/e2e/cluster_upgrade_runtimesdk.go

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -892,13 +892,7 @@ func runtimeHookTestHandler(ctx context.Context, c client.Client, cluster *clust
892892

893893
// Check if the hook keeps blocking.
894894
Consistently(func(_ Gomega) bool {
895-
if !topologyConditionCheck() {
896-
return false
897-
}
898-
if !blockingCondition() {
899-
return false
900-
}
901-
return true
895+
return topologyConditionCheck() && blockingCondition()
902896
}, 60*time.Second).Should(BeTrue(),
903897
fmt.Sprintf("Cluster Topology reconciliation continued unexpectedly: hook %s not blocking", hookName))
904898

@@ -924,19 +918,19 @@ func runtimeHookTestHandler(ctx context.Context, c client.Client, cluster *clust
924918
Byf("Waiting for %s hook to stop blocking", hookName)
925919

926920
Eventually(func(_ Gomega) bool {
927-
if topologyConditionCheck() {
928-
return false
921+
if hook == "BeforeClusterDelete" {
922+
// Only check blockingCondition for BeforeClusterDelete, because topologyConditionCheck
923+
// always returns true for the BeforeClusterDelete hook.
924+
return blockingCondition()
929925
}
930-
if blockingCondition() {
931-
return false
932-
}
933-
return true
926+
return topologyConditionCheck() || blockingCondition()
934927
}, intervals...).Should(BeFalse(),
935928
fmt.Sprintf("ClusterTopology reconcile did not proceed as expected when calling %s", hookName))
936929
}
937930

938931
func computeHookName(hook string, attributes []string) string {
939-
return strings.Join(append([]string{hook}, attributes...), "-")
932+
// Note: + is not a valid character for ConfigMap keys (only alphanumeric characters, '-', '_' or '.')
933+
return strings.ReplaceAll(strings.Join(append([]string{hook}, attributes...), "-"), "+", "_")
940934
}
941935

942936
// clusterConditionShowsHookBlocking checks if the TopologyReconciled condition message contains both the hook name and hookFailedMessage.

test/e2e/cluster_upgrade_runtimesdk_test.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,12 @@ 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+
// Note: KUBERNETES_VERSION_UPGRADE_TO has to be set either to one version in kind.GetKubernetesVersions() or
107+
// to a version greater than the last in the list by at most one minor version.
108+
KubernetesVersions: appendIfNecessary(kind.GetKubernetesVersions(), e2eConfig.MustGetVariable(KubernetesVersionUpgradeTo)),
105109
// The runtime extension gets deployed to the test-extension-system namespace and is exposed
106110
// by the test-extension-webhook-service.
107111
// The below values are used when creating the cluster-wide ExtensionConfig to refer
@@ -112,3 +116,12 @@ var _ = Describe("When performing chained upgrades for workload cluster using Cl
112116
}
113117
})
114118
})
119+
120+
func appendIfNecessary(versions []string, v string) []string {
121+
for _, version := range versions {
122+
if version == v {
123+
return versions
124+
}
125+
}
126+
return append(versions, v)
127+
}

test/e2e/config/docker.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,8 @@ intervals:
410410
default/wait-machine-pool-nodes: ["5m", "10s"]
411411
default/wait-delete-cluster: ["3m", "10s"]
412412
default/wait-machine-upgrade: ["20m", "10s"]
413-
default/wait-control-plane-upgrade: ["5m", "10s"]
414-
default/wait-machine-deployment-upgrade: ["5m", "10s"]
413+
default/wait-control-plane-upgrade: ["15m", "10s"]
414+
default/wait-machine-deployment-upgrade: ["10m", "10s"]
415415
default/wait-machine-pool-upgrade: ["5m", "10s"]
416416
default/wait-nodes-ready: ["10m", "10s"]
417417
default/wait-machine-remediation: ["5m", "10s"]
@@ -426,3 +426,4 @@ intervals:
426426
scale/wait-cluster: ["10m", "10s"]
427427
scale/wait-control-plane: ["20m", "10s"]
428428
scale/wait-worker-nodes: ["20m", "10s"]
429+
self-hosted/wait-control-plane-upgrade: ["20m", "10s"]

test/extension/config/default/kustomization.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ labels:
66
- includeSelectors: true
77
pairs:
88
# Label to identify all the providers objects; As per the clusterctl contract the value should be unique.
9-
cluster.x-k8s.io/provider: runtime-extension-test
9+
cluster.x-k8s.io/provider: runtime-extension-test-extension
1010

1111
resources:
1212
- namespace.yaml

test/extension/handlers/lifecycle/handlers.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,5 +293,6 @@ func configMapName(clusterName, extensionConfigName string) string {
293293
}
294294

295295
func computeHookName(hook runtimecatalog.Hook, attributes []string) string {
296-
return strings.Join(append([]string{runtimecatalog.HookName(hook)}, attributes...), "-")
296+
// Note: + is not a valid character for ConfigMap keys (only alphanumeric characters, '-', '_' or '.')
297+
return strings.ReplaceAll(strings.Join(append([]string{runtimecatalog.HookName(hook)}, attributes...), "-"), "+", "_")
297298
}

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.WithMessagef(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)