Skip to content

Commit 7c0dd0c

Browse files
authored
Merge pull request #11349 from cahillsf/add-dry-run-to-clusterctl-upgrade-e2e
🌱 Add dry-run CreateOrUpdate call in clusterctl upgrade e2e tests
2 parents d1ca160 + b837c34 commit 7c0dd0c

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

test/e2e/clusterctl_upgrade.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,12 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg
447447
})
448448
Expect(workloadClusterTemplate).ToNot(BeNil(), "Failed to get the cluster template")
449449

450+
// Applying the cluster template in dry-run to ensure mgmt cluster webhooks are up and available
451+
log.Logf("Applying the cluster template yaml to the cluster in dry-run")
452+
Eventually(func() error {
453+
return managementClusterProxy.CreateOrUpdate(ctx, workloadClusterTemplate, framework.WithCreateOpts([]client.CreateOption{client.DryRunAll}...), framework.WithUpdateOpts([]client.UpdateOption{client.DryRunAll}...))
454+
}, "1m", "10s").ShouldNot(HaveOccurred())
455+
450456
log.Logf("Applying the cluster template yaml to the cluster")
451457
Expect(managementClusterProxy.CreateOrUpdate(ctx, workloadClusterTemplate)).To(Succeed())
452458

test/framework/cluster_proxy.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ type ClusterProxy interface {
109109
// createOrUpdateConfig contains options for use with CreateOrUpdate.
110110
type createOrUpdateConfig struct {
111111
labelSelector labels.Selector
112+
createOpts []client.CreateOption
113+
updateOpts []client.UpdateOption
112114
}
113115

114116
// CreateOrUpdateOption is a configuration option supplied to CreateOrUpdate.
@@ -121,6 +123,20 @@ func WithLabelSelector(labelSelector labels.Selector) CreateOrUpdateOption {
121123
}
122124
}
123125

126+
// WithCreateOpts allows definition of the Create options to be used in resource Create.
127+
func WithCreateOpts(createOpts ...client.CreateOption) CreateOrUpdateOption {
128+
return func(c *createOrUpdateConfig) {
129+
c.createOpts = createOpts
130+
}
131+
}
132+
133+
// WithUpdateOpts allows definition of the Update options to be used in resource Update.
134+
func WithUpdateOpts(updateOpts ...client.UpdateOption) CreateOrUpdateOption {
135+
return func(c *createOrUpdateConfig) {
136+
c.updateOpts = updateOpts
137+
}
138+
}
139+
124140
// ClusterLogCollector defines an object that can collect logs from a machine.
125141
type ClusterLogCollector interface {
126142
// CollectMachineLog collects log from a machine.
@@ -320,15 +336,15 @@ func (p *clusterProxy) CreateOrUpdate(ctx context.Context, resources []byte, opt
320336
if err := p.GetClient().Get(ctx, objectKey, existingObject); err != nil {
321337
// Expected error -- if the object does not exist, create it
322338
if apierrors.IsNotFound(err) {
323-
if err := p.GetClient().Create(ctx, &o); err != nil {
339+
if err := p.GetClient().Create(ctx, &o, config.createOpts...); err != nil {
324340
retErrs = append(retErrs, err)
325341
}
326342
} else {
327343
retErrs = append(retErrs, err)
328344
}
329345
} else {
330346
o.SetResourceVersion(existingObject.GetResourceVersion())
331-
if err := p.GetClient().Update(ctx, &o); err != nil {
347+
if err := p.GetClient().Update(ctx, &o, config.updateOpts...); err != nil {
332348
retErrs = append(retErrs, err)
333349
}
334350
}

0 commit comments

Comments
 (0)