Skip to content

Commit

Permalink
Cherry-pick #5149 #5154 #5157 (#5160)
Browse files Browse the repository at this point in the history
* Add note to RELEASE file (#5149)

Signed-off-by: khanhtc1202 <[email protected]>
Signed-off-by: pipecd-bot <[email protected]>

* Fix the kubernetes manifest diff (#5154)

* Add TestLoadAndDiff

Signed-off-by: Shinnosuke Sawada <[email protected]>

* Make testcase smaller

Signed-off-by: Shinnosuke Sawada <[email protected]>

* Separate test cases

Signed-off-by: Shinnosuke Sawada <[email protected]>

* Add test cases

Signed-off-by: Shinnosuke Sawada <[email protected]>

* FIx the k8s diff

normalize both of old and new manifests

Signed-off-by: Shinnosuke Sawada <[email protected]>

* Rename the testcase

Signed-off-by: Shinnosuke Sawada <[email protected]>

---------

Signed-off-by: Shinnosuke Sawada <[email protected]>
Signed-off-by: pipecd-bot <[email protected]>

* Release v0.48.7 (#5157)

Signed-off-by: Shinnosuke Sawada <[email protected]>
Signed-off-by: pipecd-bot <[email protected]>

---------

Signed-off-by: khanhtc1202 <[email protected]>
Signed-off-by: pipecd-bot <[email protected]>
Signed-off-by: Shinnosuke Sawada <[email protected]>
Co-authored-by: Khanh Tran <[email protected]>
Co-authored-by: Shinnosuke Sawada-Dazai <[email protected]>
  • Loading branch information
3 people authored Aug 26, 2024
1 parent f921374 commit 9dc5c4d
Show file tree
Hide file tree
Showing 3 changed files with 178 additions and 4 deletions.
4 changes: 3 additions & 1 deletion RELEASE
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
tag: v0.48.6
# Generated by `make release` command.
# DO NOT EDIT.
tag: v0.48.7

releaseNoteGenerator:
showCommitter: false
Expand Down
13 changes: 10 additions & 3 deletions pkg/app/piped/platformprovider/kubernetes/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,20 @@ func Diff(old, new Manifest, logger *zap.Logger, opts ...diff.Option) (*diff.Res
}

key := old.Key.String()
normalized, err := remarshal(new.u)

normalizedOld, err := remarshal(old.u)
if err != nil {
logger.Info("compare manifests directly since it was unable to remarshal old Kubernetes manifest to normalize special fields", zap.Error(err))
return diff.DiffUnstructureds(*old.u, *new.u, key, opts...)
}

normalizedNew, err := remarshal(new.u)
if err != nil {
logger.Info("compare manifests directly since it was unable to remarshal Kubernetes manifest to normalize special fields", zap.Error(err))
logger.Info("compare manifests directly since it was unable to remarshal new Kubernetes manifest to normalize special fields", zap.Error(err))
return diff.DiffUnstructureds(*old.u, *new.u, key, opts...)
}

return diff.DiffUnstructureds(*old.u, *normalized, key, opts...)
return diff.DiffUnstructureds(*normalizedOld, *normalizedNew, key, opts...)
}

func DiffList(olds, news []Manifest, logger *zap.Logger, opts ...diff.Option) (*DiffListResult, error) {
Expand Down
165 changes: 165 additions & 0 deletions pkg/app/piped/platformprovider/kubernetes/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,3 +405,168 @@ spec:
})
}
}

func TestNoDiff(t *testing.T) {
t.Parallel()

testcases := []struct {
name string
manifest string
}{
{
name: "limits.memory 1.5Gi",
manifest: `apiVersion: apps/v1
kind: Deployment
metadata:
name: simple
spec:
template:
spec:
containers:
- image: ghcr.io/pipe-cd/helloworld:v0.32.0
name: helloworld
resources:
limits:
memory: 1.5Gi`,
},
{
name: "limits.cpu 1.5",
manifest: `apiVersion: apps/v1
kind: Deployment
metadata:
name: simple
spec:
template:
spec:
containers:
- image: ghcr.io/pipe-cd/helloworld:v0.32.0
name: helloworld
resources:
limits:
cpu: "1.5"`,
},
{
name: "limits.memory 1Gi",
manifest: `apiVersion: apps/v1
kind: Deployment
metadata:
name: simple
spec:
template:
spec:
containers:
- image: ghcr.io/pipe-cd/helloworld:v0.32.0
name: helloworld
resources:
limits:
memory: 1Gi`,
},
{
name: "limits.cpu 1",
manifest: `apiVersion: apps/v1
kind: Deployment
metadata:
name: simple
spec:
template:
spec:
containers:
- image: ghcr.io/pipe-cd/helloworld:v0.32.0
name: helloworld
resources:
limits:
cpu: "1"`,
},
{
name: "requests.memory 1.5Gi",
manifest: `apiVersion: apps/v1
kind: Deployment
metadata:
name: simple
spec:
template:
spec:
containers:
- image: ghcr.io/pipe-cd/helloworld:v0.32.0
name: helloworld
resources:
requests:
memory: 1.5Gi`,
},
{
name: "requests.cpu 1.5",
manifest: `apiVersion: apps/v1
kind: Deployment
metadata:
name: simple
spec:
template:
spec:
containers:
- image: ghcr.io/pipe-cd/helloworld:v0.32.0
name: helloworld
resources:
requests:
cpu: "1.5"`,
},
{
name: "requests.memory 1Gi",
manifest: `apiVersion: apps/v1
kind: Deployment
metadata:
name: simple
spec:
template:
spec:
containers:
- image: ghcr.io/pipe-cd/helloworld:v0.32.0
name: helloworld
resources:
requests:
memory: 1Gi`,
},
{
name: "requests.cpu 1",
manifest: `apiVersion: apps/v1
kind: Deployment
metadata:
name: simple
spec:
template:
spec:
containers:
- image: ghcr.io/pipe-cd/helloworld:v0.32.0
name: helloworld
resources:
requests:
cpu: "1"`,
},
}

for _, tc := range testcases {
t.Run(tc.name, func(t *testing.T) {
manifests, err := ParseManifests(tc.manifest)
require.NoError(t, err)

result, err := DiffList(manifests, manifests, zap.NewNop(), diff.WithEquateEmpty(), diff.WithIgnoreAddingMapKeys(), diff.WithCompareNumberAndNumericString())
require.NoError(t, err)

assert.True(t, result.NoChange())
for _, change := range result.Changes {
t.Log(change.Old.Key, change.New.Key)
for _, node := range change.Diff.Nodes() {
t.Log(node.PathString)
t.Log(node.ValueX)
t.Log(node.ValueY)
t.Log("---")
}
}
for _, add := range result.Adds {
t.Log(add.Key)
}
for _, delete := range result.Deletes {
t.Log(delete.Key)
}
})
}
}

0 comments on commit 9dc5c4d

Please sign in to comment.