Skip to content

Commit

Permalink
Modify createReactor to set the CreationTimestamp field
Browse files Browse the repository at this point in the history
Signed-off-by: Tom Pantelis <[email protected]>
  • Loading branch information
tpantelis committed Aug 23, 2024
1 parent 129ea41 commit db26789
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/fake/basic_reactors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ var _ = Describe("Create", func() {
Expect(actual.UID).ToNot(BeEmpty())
})

It("should set the CreationTimestamp field", func() {
now := metav1.Now()
actual := t.assertCreateSuccess(t.pod)
Expect(actual.CreationTimestamp.After(now.Add(-time.Second * 5))).To(BeTrue())
})

When("the Name and GenerateName fields are empty", func() {
It("should return an error", func() {
t.pod.GenerateName = ""
Expand Down
2 changes: 2 additions & 0 deletions pkg/fake/create_reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/submariner-io/admiral/pkg/resource"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
utilrand "k8s.io/apimachinery/pkg/util/rand"
"k8s.io/apimachinery/pkg/util/uuid"
Expand Down Expand Up @@ -63,6 +64,7 @@ func (r *createReactor) react(a testing.Action) (bool, runtime.Object, error) {
}

target.SetResourceVersion("1")
target.SetCreationTimestamp(metav1.Now())

if !target.GetDeletionTimestamp().IsZero() {
target.SetDeletionTimestamp(nil)
Expand Down
1 change: 1 addition & 0 deletions pkg/util/create_or_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ func createResource[T runtime.Object](ctx context.Context, client resource.Inter
// do a separate UpdateStatus call.
objMeta.SetResourceVersion(resource.MustToMeta(created).GetResourceVersion())
objMeta.SetUID(resource.MustToMeta(created).GetUID())
objMeta.SetCreationTimestamp(resource.MustToMeta(created).GetCreationTimestamp())

_, err := client.UpdateStatus(ctx, obj, metav1.UpdateOptions{})
if err != nil && !apierrors.IsNotFound(err) {
Expand Down

0 comments on commit db26789

Please sign in to comment.