@@ -1609,6 +1609,68 @@ metadata:
16091609 assert .False (t , ok )
16101610}
16111611
1612+ func TestRemarshalStatefulSetCreationTimestamp (t * testing.T ) {
1613+ manifest := []byte (`
1614+ apiVersion: apps/v1
1615+ kind: StatefulSet
1616+ metadata:
1617+ name: test-sts
1618+ creationTimestamp: "2025-11-06T19:35:31Z"
1619+ spec:
1620+ serviceName: test
1621+ selector:
1622+ matchLabels:
1623+ app: test
1624+ template:
1625+ metadata:
1626+ creationTimestamp: null
1627+ labels:
1628+ app: test
1629+ spec:
1630+ containers:
1631+ - name: test
1632+ image: nginx
1633+ volumeClaimTemplates:
1634+ - metadata:
1635+ name: data
1636+ creationTimestamp: null
1637+ spec:
1638+ accessModes:
1639+ - ReadWriteOnce
1640+ resources:
1641+ requests:
1642+ storage: 1Gi
1643+ ` )
1644+ var un unstructured.Unstructured
1645+ require .NoError (t , yaml .Unmarshal (manifest , & un ))
1646+
1647+ // Verify creationTimestamp exists in nested metadata before remarshal
1648+ spec := un .Object ["spec" ].(map [string ]any )
1649+ templateMetadata := spec ["template" ].(map [string ]any )["metadata" ].(map [string ]any )
1650+ _ , ok := templateMetadata ["creationTimestamp" ]
1651+ assert .True (t , ok , "creationTimestamp should exist in template.metadata before remarshal" )
1652+
1653+ volumeClaimTemplates := spec ["volumeClaimTemplates" ].([]any )
1654+ vctMetadata := volumeClaimTemplates [0 ].(map [string ]any )["metadata" ].(map [string ]any )
1655+ _ , ok = vctMetadata ["creationTimestamp" ]
1656+ assert .True (t , ok , "creationTimestamp should exist in volumeClaimTemplates[0].metadata before remarshal" )
1657+
1658+ // Remarshal
1659+ newUn := remarshal (& un , applyOptions (diffOptionsForTest ()))
1660+
1661+ // Verify creationTimestamp is removed from nested metadata after remarshal
1662+ // (top-level metadata.creationTimestamp is preserved as it's part of the resource identity)
1663+ spec = newUn .Object ["spec" ].(map [string ]any )
1664+ templateMetadata = spec ["template" ].(map [string ]any )["metadata" ].(map [string ]any )
1665+ _ , ok = templateMetadata ["creationTimestamp" ]
1666+ assert .False (t , ok , "creationTimestamp should be removed from template.metadata after remarshal" )
1667+
1668+ volumeClaimTemplates = spec ["volumeClaimTemplates" ].([]any )
1669+ vctMetadata = volumeClaimTemplates [0 ].(map [string ]any )["metadata" ].(map [string ]any )
1670+ _ , ok = vctMetadata ["creationTimestamp" ]
1671+ assert .False (t , ok , "creationTimestamp should be removed from volumeClaimTemplates[0].metadata after remarshal" )
1672+ }
1673+
16121674func TestRemarshalResources (t * testing.T ) {
16131675 getRequests := func (un * unstructured.Unstructured ) map [string ]any {
16141676 return un .Object ["spec" ].(map [string ]any )["containers" ].([]any )[0 ].(map [string ]any )["resources" ].(map [string ]any )["requests" ].(map [string ]any )
0 commit comments