From b837c344e55233716622e4866992c2872d12984a Mon Sep 17 00:00:00 2001 From: Stephen Cahill Date: Mon, 28 Oct 2024 20:54:00 -0400 Subject: [PATCH] :seedling: Add dry-run CreateOrUpdate call in clusterctl upgrade e2e tests --- test/e2e/clusterctl_upgrade.go | 6 ++++++ test/framework/cluster_proxy.go | 20 ++++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/test/e2e/clusterctl_upgrade.go b/test/e2e/clusterctl_upgrade.go index 6e21ef75fedf..7806eebfd36b 100644 --- a/test/e2e/clusterctl_upgrade.go +++ b/test/e2e/clusterctl_upgrade.go @@ -447,6 +447,12 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg }) Expect(workloadClusterTemplate).ToNot(BeNil(), "Failed to get the cluster template") + // Applying the cluster template in dry-run to ensure mgmt cluster webhooks are up and available + log.Logf("Applying the cluster template yaml to the cluster in dry-run") + Eventually(func() error { + return managementClusterProxy.CreateOrUpdate(ctx, workloadClusterTemplate, framework.WithCreateOpts([]client.CreateOption{client.DryRunAll}...), framework.WithUpdateOpts([]client.UpdateOption{client.DryRunAll}...)) + }, "1m", "10s").ShouldNot(HaveOccurred()) + log.Logf("Applying the cluster template yaml to the cluster") Expect(managementClusterProxy.CreateOrUpdate(ctx, workloadClusterTemplate)).To(Succeed()) diff --git a/test/framework/cluster_proxy.go b/test/framework/cluster_proxy.go index 88e25f5355bf..3dc92278dc1a 100644 --- a/test/framework/cluster_proxy.go +++ b/test/framework/cluster_proxy.go @@ -109,6 +109,8 @@ type ClusterProxy interface { // createOrUpdateConfig contains options for use with CreateOrUpdate. type createOrUpdateConfig struct { labelSelector labels.Selector + createOpts []client.CreateOption + updateOpts []client.UpdateOption } // CreateOrUpdateOption is a configuration option supplied to CreateOrUpdate. @@ -121,6 +123,20 @@ func WithLabelSelector(labelSelector labels.Selector) CreateOrUpdateOption { } } +// WithCreateOpts allows definition of the Create options to be used in resource Create. +func WithCreateOpts(createOpts ...client.CreateOption) CreateOrUpdateOption { + return func(c *createOrUpdateConfig) { + c.createOpts = createOpts + } +} + +// WithUpdateOpts allows definition of the Update options to be used in resource Update. +func WithUpdateOpts(updateOpts ...client.UpdateOption) CreateOrUpdateOption { + return func(c *createOrUpdateConfig) { + c.updateOpts = updateOpts + } +} + // ClusterLogCollector defines an object that can collect logs from a machine. type ClusterLogCollector interface { // CollectMachineLog collects log from a machine. @@ -320,7 +336,7 @@ func (p *clusterProxy) CreateOrUpdate(ctx context.Context, resources []byte, opt if err := p.GetClient().Get(ctx, objectKey, existingObject); err != nil { // Expected error -- if the object does not exist, create it if apierrors.IsNotFound(err) { - if err := p.GetClient().Create(ctx, &o); err != nil { + if err := p.GetClient().Create(ctx, &o, config.createOpts...); err != nil { retErrs = append(retErrs, err) } } else { @@ -328,7 +344,7 @@ func (p *clusterProxy) CreateOrUpdate(ctx context.Context, resources []byte, opt } } else { o.SetResourceVersion(existingObject.GetResourceVersion()) - if err := p.GetClient().Update(ctx, &o); err != nil { + if err := p.GetClient().Update(ctx, &o, config.updateOpts...); err != nil { retErrs = append(retErrs, err) } }