Skip to content

Commit 56c6a51

Browse files
Merge pull request #256 from enxebre/replicas-comparison
bug 1764017: Fix replicas comparison
2 parents ae1f16b + 80dc893 commit 56c6a51

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

lib/resourcemerge/apps.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
func EnsureDeployment(modified *bool, existing *appsv1.Deployment, required appsv1.Deployment) {
1111
EnsureObjectMeta(modified, &existing.ObjectMeta, required.ObjectMeta)
1212

13-
if required.Spec.Replicas != nil && required.Spec.Replicas != existing.Spec.Replicas {
13+
if required.Spec.Replicas != nil && *required.Spec.Replicas != *existing.Spec.Replicas {
1414
*modified = true
1515
existing.Spec.Replicas = required.Spec.Replicas
1616
}

lib/resourcemerge/apps_test.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import (
1010
)
1111

1212
func TestEnsureDeployment(t *testing.T) {
13-
replicas := int32(2)
14-
expectedReplicas := int32(2)
1513
labelSelector := metav1.LabelSelector{}
1614
tests := []struct {
1715
name string
@@ -25,29 +23,29 @@ func TestEnsureDeployment(t *testing.T) {
2523
name: "different replica count",
2624
existing: appsv1.Deployment{
2725
Spec: appsv1.DeploymentSpec{
28-
Replicas: &replicas}},
26+
Replicas: int32Pointer(2)}},
2927
required: appsv1.Deployment{
3028
Spec: appsv1.DeploymentSpec{
31-
Replicas: &expectedReplicas}},
29+
Replicas: int32Pointer(3)}},
3230

3331
expectedModified: true,
3432
expected: appsv1.Deployment{
3533
Spec: appsv1.DeploymentSpec{
36-
Replicas: &expectedReplicas}},
34+
Replicas: int32Pointer(3)}},
3735
},
3836
{
3937
name: "same replica count",
4038
existing: appsv1.Deployment{
4139
Spec: appsv1.DeploymentSpec{
42-
Replicas: &replicas}},
40+
Replicas: int32Pointer(2)}},
4341
required: appsv1.Deployment{
4442
Spec: appsv1.DeploymentSpec{
45-
Replicas: &replicas}},
43+
Replicas: int32Pointer(2)}},
4644

4745
expectedModified: false,
4846
expected: appsv1.Deployment{
4947
Spec: appsv1.DeploymentSpec{
50-
Replicas: &replicas}},
48+
Replicas: int32Pointer(2)}},
5149
},
5250
{
5351
name: "existing-selector-nil-required-selector-non-nil",
@@ -77,3 +75,7 @@ func TestEnsureDeployment(t *testing.T) {
7775
})
7876
}
7977
}
78+
79+
func int32Pointer(i int32) *int32 {
80+
return &i
81+
}

0 commit comments

Comments
 (0)