@@ -414,7 +414,7 @@ var _ = Describe("Fake client", func() {
414414 Expect (err ).ToNot (HaveOccurred ())
415415 Expect (obj ).To (Equal (newcm ))
416416 Expect (obj .ObjectMeta .ResourceVersion ).To (Equal ("1" ))
417- Expect (obj .ObjectMeta .CreationTimestamp .IsZero ()).To (BeFalse ())
417+ Expect (obj .ObjectMeta .CreationTimestamp .IsZero ()).To (BeTrue ())
418418 })
419419
420420 It ("should error on create with set resourceVersion" , func (ctx SpecContext ) {
@@ -430,19 +430,6 @@ var _ = Describe("Fake client", func() {
430430 Expect (apierrors .IsBadRequest (err )).To (BeTrue ())
431431 })
432432
433- It ("should error on create with set creationTimestamp" , func (ctx SpecContext ) {
434- By ("Creating a new configmap" )
435- newcm := & corev1.ConfigMap {
436- ObjectMeta : metav1.ObjectMeta {
437- Name : "new-test-cm" ,
438- Namespace : "ns2" ,
439- CreationTimestamp : metav1 .Now (),
440- },
441- }
442- err := cl .Create (ctx , newcm )
443- Expect (apierrors .IsBadRequest (err )).To (BeTrue ())
444- })
445-
446433 It ("should not change the submitted object if Create failed" , func (ctx SpecContext ) {
447434 By ("Trying to create an existing configmap" )
448435 submitted := cm .DeepCopy ()
@@ -1243,7 +1230,6 @@ var _ = Describe("Fake client", func() {
12431230 Expect (err ).ToNot (HaveOccurred ())
12441231 Expect (newObj .Finalizers ).To (BeEmpty ())
12451232 })
1246-
12471233 }
12481234
12491235 Context ("with default scheme.Scheme" , func () {
@@ -1487,6 +1473,48 @@ var _ = Describe("Fake client", func() {
14871473 })
14881474 })
14891475
1476+ Context ("with SetCreationTimestamp option" , func () {
1477+ BeforeEach (func () {
1478+ cl = NewClientBuilder ().
1479+ WithSetCreationTimestamp ().
1480+ Build ()
1481+ })
1482+
1483+ It ("should be able to Create and set metadata.CreationTimestamp" , func (ctx SpecContext ) {
1484+ By ("Creating a new configmap" )
1485+ newcm := & corev1.ConfigMap {
1486+ ObjectMeta : metav1.ObjectMeta {
1487+ Name : "test-cm-with-creation-timestamp" ,
1488+ Namespace : "ns2" ,
1489+ },
1490+ }
1491+ err := cl .Create (ctx , newcm )
1492+ Expect (err ).ToNot (HaveOccurred ())
1493+
1494+ By ("Getting the new configmap" )
1495+ namespacedName := types.NamespacedName {
1496+ Name : "test-cm-with-creation-timestamp" ,
1497+ Namespace : "ns2" ,
1498+ }
1499+ obj := & corev1.ConfigMap {}
1500+ err = cl .Get (ctx , namespacedName , obj )
1501+ Expect (err ).ToNot (HaveOccurred ())
1502+ Expect (obj ).To (Equal (newcm ))
1503+ Expect (obj .ObjectMeta .ResourceVersion ).To (Equal ("1" ))
1504+ Expect (obj .ObjectMeta .CreationTimestamp .IsZero ()).ToNot (BeTrue ())
1505+ })
1506+
1507+ It ("sets creatioTimestamp on SSA create when required to do so" , func (ctx SpecContext ) {
1508+ obj := corev1applyconfigurations .
1509+ ConfigMap ("foo-with-creation-timestamp" , "default" ).
1510+ WithData (map [string ]string {"some" : "data" })
1511+
1512+ cl := NewClientBuilder ().WithSetCreationTimestamp ().Build ()
1513+ Expect (cl .Apply (ctx , obj , client .FieldOwner ("foo" ))).NotTo (HaveOccurred ())
1514+ Expect (obj .CreationTimestamp .IsZero ()).To (BeFalse ())
1515+ })
1516+ })
1517+
14901518 It ("should set the ResourceVersion to 999 when adding an object to the tracker" , func (ctx SpecContext ) {
14911519 cl := NewClientBuilder ().WithObjects (& corev1.Secret {ObjectMeta : metav1.ObjectMeta {Name : "cm" }}).Build ()
14921520
@@ -3082,14 +3110,14 @@ var _ = Describe("Fake client", func() {
30823110 Expect (obj .ResourceVersion ).To (BeEquivalentTo (ptr .To ("1" )))
30833111 })
30843112
3085- It ("sets creatioTimestamp on SSA create" , func (ctx SpecContext ) {
3113+ It ("does not set creatioTimestamp on SSA create" , func (ctx SpecContext ) {
30863114 obj := corev1applyconfigurations .
30873115 ConfigMap ("foo" , "default" ).
30883116 WithData (map [string ]string {"some" : "data" })
30893117
30903118 cl := NewClientBuilder ().Build ()
30913119 Expect (cl .Apply (ctx , obj , client .FieldOwner ("foo" ))).NotTo (HaveOccurred ())
3092- Expect (obj .CreationTimestamp .IsZero ()).To (BeFalse ())
3120+ Expect (obj .CreationTimestamp .IsZero ()).To (BeTrue ())
30933121 })
30943122
30953123 It ("ignores a passed resourceVersion on SSA create" , func (ctx SpecContext ) {
0 commit comments