Skip to content
This repository was archived by the owner on Dec 4, 2025. It is now read-only.

Commit 13d5172

Browse files
authored
fix(cherry-pick:): regression on creationTimestamp with server-side diff (#793)
* fix(cherry-pick): regression on creationTimestamp with server-side diff Signed-off-by: Peter Jiang <[email protected]> * add diff test Signed-off-by: Peter Jiang <[email protected]> * format Signed-off-by: Peter Jiang <[email protected]> --------- Signed-off-by: Peter Jiang <[email protected]>
1 parent b89b087 commit 13d5172

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

pkg/diff/diff.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ func serverSideDiff(config, live *unstructured.Unstructured, opts ...Option) (*D
183183
}
184184
}
185185

186+
// Remarshal predictedLive to ensure it receives the same normalization as live.
187+
predictedLive = remarshal(predictedLive, o)
188+
186189
Normalize(predictedLive, opts...)
187190
unstructured.RemoveNestedField(predictedLive.Object, "metadata", "managedFields")
188191

pkg/diff/diff_test.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
16121674
func 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

Comments
 (0)