Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-1.8] 🌱 Add dry-run CreateOrUpdate call in clusterctl upgrade e2e tests #11458

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions test/e2e/clusterctl_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down
20 changes: 18 additions & 2 deletions test/framework/cluster_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -320,15 +336,15 @@ 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 {
retErrs = append(retErrs, err)
}
} 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)
}
}
Expand Down