Skip to content

Commit

Permalink
🌱 Add dry-run CreateOrUpdate call in clusterctl upgrade e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cahillsf committed Oct 29, 2024
1 parent c3ae478 commit 5536da8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
3 changes: 3 additions & 0 deletions test/e2e/clusterctl_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,9 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg
})
Expect(workloadClusterTemplate).ToNot(BeNil(), "Failed to get the cluster template")

log.Logf("Applying the cluster template yaml to the cluster in dry-run")
Eventually(managementClusterProxy.CreateOrUpdate(ctx, workloadClusterTemplate, framework.WithCreateOpts([]client.CreateOption{client.DryRunAll}...), framework.WithUpdateOpts([]client.UpdateOption{client.DryRunAll}...)), "1m", "10s").ShouldNot(HaveOccurred())

Check failure on line 451 in test/e2e/clusterctl_upgrade.go

View workflow job for this annotation

GitHub Actions / lint (test)

ginkgo-linter: use a function call in Eventually. This actually checks nothing, because Eventually receives the function returned value, instead of function itself, and this value is never changed. Consider using `Eventually(managementClusterProxy.CreateOrUpdate, "1m", "10s").WithArguments(ctx, workloadClusterTemplate, framework.WithCreateOpts([]client.CreateOption{client.DryRunAll}...), framework.WithUpdateOpts([]client.UpdateOption{client.DryRunAll}...)).ShouldNot(HaveOccurred())` instead (ginkgolinter)

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 5536da8

Please sign in to comment.