Skip to content

Commit

Permalink
Merge pull request #11349 from cahillsf/add-dry-run-to-clusterctl-upg…
Browse files Browse the repository at this point in the history
…rade-e2e

🌱 Add dry-run CreateOrUpdate call in clusterctl upgrade e2e tests
  • Loading branch information
k8s-ci-robot authored Oct 29, 2024
2 parents d1ca160 + b837c34 commit 7c0dd0c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
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

0 comments on commit 7c0dd0c

Please sign in to comment.