Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
Signed-off-by: sjcsjc123 <[email protected]>
  • Loading branch information
sjcsjc123 committed Jan 12, 2024
1 parent e3929d3 commit 6b17394
Showing 1 changed file with 29 additions and 22 deletions.
51 changes: 29 additions & 22 deletions test/e2e/conformance/utils/kubernetes/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ func (a Applier) MustApplyObjectsWithCleanup(t *testing.T, c client.Client, time
ctx, cancel := context.WithTimeout(context.Background(), timeoutConfig.CreateTimeout)
defer cancel()

t.Logf("๐Ÿ— Creating %s %s", resource.GetName(), resource.GetObjectKind().GroupVersionKind().Kind)

err := c.Create(ctx, resource)
if err != nil {
if !apierrors.IsAlreadyExists(err) {
require.NoError(t, err, "error creating resource")
}
}

if cleanup {
t.Cleanup(func() {
ctx, cancel = context.WithTimeout(context.Background(), timeoutConfig.DeleteTimeout)
Expand All @@ -105,16 +114,6 @@ func (a Applier) MustApplyObjectsWithCleanup(t *testing.T, c client.Client, time
err := c.Delete(ctx, resource)
require.NoErrorf(t, err, "error deleting resource")
})
return
}

t.Logf("๐Ÿ— Creating %s %s", resource.GetName(), resource.GetObjectKind().GroupVersionKind().Kind)

err := c.Create(ctx, resource)
if err != nil {
if !apierrors.IsAlreadyExists(err) {
require.NoError(t, err, "error creating resource")
}
}
}
}
Expand Down Expand Up @@ -142,18 +141,6 @@ func (a Applier) MustApplyWithCleanup(t *testing.T, c client.Client, timeoutConf

namespacedName := types.NamespacedName{Namespace: uObj.GetNamespace(), Name: uObj.GetName()}
fetchedObj := uObj.DeepCopy()

if cleanup {
t.Cleanup(func() {
ctx, cancel = context.WithTimeout(context.Background(), timeoutConfig.DeleteTimeout)
defer cancel()
t.Logf("๐Ÿšฎ Deleting %s %s", uObj.GetName(), uObj.GetKind())
err = c.Delete(ctx, uObj)
require.NoErrorf(t, err, "error deleting resource")
})
continue
}

err := c.Get(ctx, namespacedName, fetchedObj)
if err != nil {
if !apierrors.IsNotFound(err) {
Expand All @@ -162,12 +149,32 @@ func (a Applier) MustApplyWithCleanup(t *testing.T, c client.Client, timeoutConf
t.Logf("๐Ÿ— Creating %s %s", uObj.GetName(), uObj.GetKind())
err = c.Create(ctx, uObj)
require.NoErrorf(t, err, "error creating resource")

if cleanup {
t.Cleanup(func() {
ctx, cancel = context.WithTimeout(context.Background(), timeoutConfig.DeleteTimeout)
defer cancel()
t.Logf("๐Ÿšฎ Deleting %s %s", uObj.GetName(), uObj.GetKind())
err = c.Delete(ctx, uObj)
require.NoErrorf(t, err, "error deleting resource")
})
}
continue
}

uObj.SetResourceVersion(fetchedObj.GetResourceVersion())
t.Logf("๐Ÿ— Updating %s %s", uObj.GetName(), uObj.GetKind())
err = c.Update(ctx, uObj)

if cleanup {
t.Cleanup(func() {
ctx, cancel = context.WithTimeout(context.Background(), timeoutConfig.DeleteTimeout)
defer cancel()
t.Logf("๐Ÿšฎ Deleting %s %s", uObj.GetName(), uObj.GetKind())
err = c.Delete(ctx, uObj)
require.NoErrorf(t, err, "error deleting resource")
})
}
require.NoErrorf(t, err, "error updating resource")
}
}
Expand Down

0 comments on commit 6b17394

Please sign in to comment.