Skip to content
This repository was archived by the owner on Dec 4, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pkg/diff/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ func serverSideDiff(config, live *unstructured.Unstructured, opts ...Option) (*D
}
}

// Remarshal predictedLive to ensure it receives the same normalization as live.
predictedLive = remarshal(predictedLive, o)

Normalize(predictedLive, opts...)
unstructured.RemoveNestedField(predictedLive.Object, "metadata", "managedFields")

Expand Down
62 changes: 62 additions & 0 deletions pkg/diff/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1609,6 +1609,68 @@ metadata:
assert.False(t, ok)
}

func TestRemarshalStatefulSetCreationTimestamp(t *testing.T) {
manifest := []byte(`
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: test-sts
creationTimestamp: "2025-11-06T19:35:31Z"
spec:
serviceName: test
selector:
matchLabels:
app: test
template:
metadata:
creationTimestamp: null
labels:
app: test
spec:
containers:
- name: test
image: nginx
volumeClaimTemplates:
- metadata:
name: data
creationTimestamp: null
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
`)
var un unstructured.Unstructured
require.NoError(t, yaml.Unmarshal(manifest, &un))

// Verify creationTimestamp exists in nested metadata before remarshal
spec := un.Object["spec"].(map[string]any)
templateMetadata := spec["template"].(map[string]any)["metadata"].(map[string]any)
_, ok := templateMetadata["creationTimestamp"]
assert.True(t, ok, "creationTimestamp should exist in template.metadata before remarshal")

volumeClaimTemplates := spec["volumeClaimTemplates"].([]any)
vctMetadata := volumeClaimTemplates[0].(map[string]any)["metadata"].(map[string]any)
_, ok = vctMetadata["creationTimestamp"]
assert.True(t, ok, "creationTimestamp should exist in volumeClaimTemplates[0].metadata before remarshal")

// Remarshal
newUn := remarshal(&un, applyOptions(diffOptionsForTest()))

// Verify creationTimestamp is removed from nested metadata after remarshal
// (top-level metadata.creationTimestamp is preserved as it's part of the resource identity)
spec = newUn.Object["spec"].(map[string]any)
templateMetadata = spec["template"].(map[string]any)["metadata"].(map[string]any)
_, ok = templateMetadata["creationTimestamp"]
assert.False(t, ok, "creationTimestamp should be removed from template.metadata after remarshal")

volumeClaimTemplates = spec["volumeClaimTemplates"].([]any)
vctMetadata = volumeClaimTemplates[0].(map[string]any)["metadata"].(map[string]any)
_, ok = vctMetadata["creationTimestamp"]
assert.False(t, ok, "creationTimestamp should be removed from volumeClaimTemplates[0].metadata after remarshal")
}

func TestRemarshalResources(t *testing.T) {
getRequests := func(un *unstructured.Unstructured) map[string]any {
return un.Object["spec"].(map[string]any)["containers"].([]any)[0].(map[string]any)["resources"].(map[string]any)["requests"].(map[string]any)
Expand Down