Skip to content

Commit dec6cdc

Browse files
authored
Merge pull request #3220 from CecileRobertMichon/cherry-pick-3198
[release-1.7] Fix e2e Helm chart retry when install fails
2 parents 24d98ff + 1f5c003 commit dec6cdc

File tree

4 files changed

+35
-16
lines changed

4 files changed

+35
-16
lines changed

test/e2e/azure_privatecluster.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ func AzurePrivateClusterSpec(ctx context.Context, inputGetter func() AzurePrivat
103103

104104
By("Ensure public API server is stable before creating private cluster")
105105
Consistently(func() error {
106-
kubeSystem := &corev1.Namespace{}
107-
return publicClusterProxy.GetClient().Get(ctx, client.ObjectKey{Name: "kube-system"}, kubeSystem)
106+
ns := &corev1.Namespace{}
107+
return publicClusterProxy.GetClient().Get(ctx, client.ObjectKey{Name: kubesystem}, ns)
108108
}, "5s", "100ms").Should(BeNil(), "Failed to assert public API server stability")
109109

110110
// **************

test/e2e/azure_selfhosted.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,12 @@ func SelfHostedSpec(ctx context.Context, inputGetter func() SelfHostedSpecInput)
153153
// More specifically, we were observing the test failing to get objects from the API server during move, so we
154154
// are now testing the API servers are stable before starting move.
155155
Consistently(func() error {
156-
kubeSystem := &corev1.Namespace{}
157-
return input.BootstrapClusterProxy.GetClient().Get(ctx, client.ObjectKey{Name: "kube-system"}, kubeSystem)
156+
ns := &corev1.Namespace{}
157+
return input.BootstrapClusterProxy.GetClient().Get(ctx, client.ObjectKey{Name: kubesystem}, ns)
158158
}, "5s", "100ms").Should(BeNil(), "Failed to assert bootstrap API server stability")
159159
Consistently(func() error {
160-
kubeSystem := &corev1.Namespace{}
161-
return selfHostedClusterProxy.GetClient().Get(ctx, client.ObjectKey{Name: "kube-system"}, kubeSystem)
160+
ns := &corev1.Namespace{}
161+
return selfHostedClusterProxy.GetClient().Get(ctx, client.ObjectKey{Name: kubesystem}, ns)
162162
}, "5s", "100ms").Should(BeNil(), "Failed to assert self-hosted API server stability")
163163

164164
By("Moving the cluster to self hosted")
@@ -205,12 +205,12 @@ func SelfHostedSpec(ctx context.Context, inputGetter func() SelfHostedSpecInput)
205205
// More specifically, we were observing the test failing to get objects from the API server during move, so we
206206
// are now testing the API servers are stable before starting move.
207207
Consistently(func() error {
208-
kubeSystem := &corev1.Namespace{}
209-
return input.BootstrapClusterProxy.GetClient().Get(ctx, client.ObjectKey{Name: "kube-system"}, kubeSystem)
208+
ns := &corev1.Namespace{}
209+
return input.BootstrapClusterProxy.GetClient().Get(ctx, client.ObjectKey{Name: kubesystem}, ns)
210210
}, "5s", "100ms").Should(BeNil(), "Failed to assert bootstrap API server stability")
211211
Consistently(func() error {
212-
kubeSystem := &corev1.Namespace{}
213-
return selfHostedClusterProxy.GetClient().Get(ctx, client.ObjectKey{Name: "kube-system"}, kubeSystem)
212+
ns := &corev1.Namespace{}
213+
return selfHostedClusterProxy.GetClient().Get(ctx, client.ObjectKey{Name: kubesystem}, ns)
214214
}, "5s", "100ms").Should(BeNil(), "Failed to assert self-hosted API server stability")
215215

216216
By("Moving the cluster back to bootstrap")

test/e2e/common.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import (
4545
"sigs.k8s.io/cluster-api/test/framework"
4646
"sigs.k8s.io/cluster-api/test/framework/clusterctl"
4747
"sigs.k8s.io/cluster-api/util/kubeconfig"
48-
crclient "sigs.k8s.io/controller-runtime/pkg/client"
48+
"sigs.k8s.io/controller-runtime/pkg/client"
4949
)
5050

5151
// Test suite constants for e2e config variables
@@ -219,7 +219,7 @@ func redactLogs() {
219219
}
220220

221221
func createRestConfig(ctx context.Context, tmpdir, namespace, clusterName string) *rest.Config {
222-
cluster := crclient.ObjectKey{
222+
cluster := client.ObjectKey{
223223
Namespace: namespace,
224224
Name: clusterName,
225225
}
@@ -247,13 +247,24 @@ func EnsureControlPlaneInitialized(ctx context.Context, input clusterctl.ApplyCl
247247
Namespace: input.ConfigCluster.Namespace,
248248
})
249249
kubeadmControlPlane := &kubeadmv1.KubeadmControlPlane{}
250-
key := crclient.ObjectKey{
250+
key := client.ObjectKey{
251251
Namespace: cluster.Spec.ControlPlaneRef.Namespace,
252252
Name: cluster.Spec.ControlPlaneRef.Name,
253253
}
254-
Eventually(func() error {
255-
return getter.Get(ctx, key, kubeadmControlPlane)
256-
}, input.WaitForControlPlaneIntervals...).Should(Succeed(), "Failed to get KubeadmControlPlane object %s/%s", cluster.Spec.ControlPlaneRef.Namespace, cluster.Spec.ControlPlaneRef.Name)
254+
255+
By("Ensuring KubeadmControlPlane is initialized")
256+
Eventually(func(g Gomega) {
257+
g.Expect(getter.Get(ctx, key, kubeadmControlPlane)).To(Succeed(), "Failed to get KubeadmControlPlane object %s/%s", cluster.Spec.ControlPlaneRef.Namespace, cluster.Spec.ControlPlaneRef.Name)
258+
g.Expect(kubeadmControlPlane.Status.Initialized).To(BeTrue(), "KubeadmControlPlane is not yet initialized")
259+
}, input.WaitForControlPlaneIntervals...).Should(Succeed(), "KubeadmControlPlane object %s/%s was not initialized in time", cluster.Spec.ControlPlaneRef.Namespace, cluster.Spec.ControlPlaneRef.Name)
260+
261+
By("Ensuring API Server is reachable before applying Helm charts")
262+
Eventually(func(g Gomega) {
263+
ns := &corev1.Namespace{}
264+
clusterProxy := input.ClusterProxy.GetWorkloadCluster(ctx, input.ConfigCluster.Namespace, input.ConfigCluster.ClusterName)
265+
g.Expect(clusterProxy.GetClient().Get(ctx, client.ObjectKey{Name: kubesystem}, ns)).To(Succeed(), "Failed to get kube-system namespace")
266+
}, input.WaitForControlPlaneIntervals...).Should(Succeed(), "API Server was not reachable in time")
267+
257268
_, hasWindows := cluster.Labels["cni-windows"]
258269
if kubeadmControlPlane.Spec.KubeadmConfigSpec.ClusterConfiguration.ControllerManager.ExtraArgs["cloud-provider"] == "external" {
259270
// There is a co-dependency between cloud-provider and CNI so we install both together if cloud-provider is external.

test/e2e/helpers.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,14 @@ func InstallHelmChart(ctx context.Context, input clusterctl.ApplyClusterTemplate
874874
}
875875
release, err := i.RunWithContext(ctx, chartRequested, vals)
876876
if err != nil {
877+
Logf("Failed to install release %s, attempting to cleanup so we can retry", releaseName)
878+
// Best effort attempt to delete the failed release so we can retry.
879+
_, delErr := helmAction.NewUninstall(actionConfig).Run(releaseName)
880+
if delErr != nil {
881+
Logf("Failed to delete release %s", releaseName)
882+
} else {
883+
Logf("Deleted failed release %s", releaseName)
884+
}
877885
return err
878886
}
879887
Logf(release.Info.Description)

0 commit comments

Comments
 (0)