1
1
/*
2
- * Copyright (c) 2020, 2024 , Oracle and/or its affiliates.
2
+ * Copyright (c) 2020, 2025 , Oracle and/or its affiliates.
3
3
* Licensed under the Universal Permissive License v 1.0 as shown at
4
4
* http://oss.oracle.com/licenses/upl.
5
5
*/
@@ -9,22 +9,24 @@ package remote
9
9
import (
10
10
goctx "context"
11
11
"fmt"
12
+ "io"
13
+ "strings"
14
+ "testing"
15
+ "time"
16
+
12
17
cohv1 "github.com/oracle/coherence-operator/api/v1"
13
18
"github.com/oracle/coherence-operator/test/e2e/helper"
14
19
"golang.org/x/net/context"
15
- "io"
16
20
appsv1 "k8s.io/api/apps/v1"
21
+ "k8s.io/apimachinery/pkg/types"
17
22
"k8s.io/utils/ptr"
18
23
"sigs.k8s.io/testing_frameworks/integration"
19
- "strings"
20
- "testing"
21
- "time"
22
24
23
25
. "github.com/onsi/gomega"
24
26
)
25
27
26
28
// Test scaling up and down with different policies.
27
- // This test is an example of using sub-tests to run the test with different test cases.
29
+ // This test is an example of using subtests to run the test with different test cases.
28
30
func TestScaling (t * testing.T ) {
29
31
// Ensure that everything is cleaned up after the test!
30
32
testContext .CleanupAfterTest (t )
@@ -91,7 +93,7 @@ func TestScaleDownToZeroWithSuspendFalse(t *testing.T) {
91
93
}
92
94
93
95
// If a deployment is scaled down to zero it should be deleted and just its parent Coherence resource should remain.
94
- // This test scales down using the "kubectl scale --relicas =0" command
96
+ // This test scales down using the "kubectl scale --replicas =0" command
95
97
func TestScaleDownToZeroUsingKubectl (t * testing.T ) {
96
98
// Ensure that everything is cleaned up after the test!
97
99
testContext .CleanupAfterTest (t )
@@ -138,7 +140,7 @@ var kubeCtlScaler = func(t *testing.T, d *cohv1.Coherence, replicas int32) error
138
140
}
139
141
140
142
// Assert that a deployment can be created and scaled using the specified policy.
141
- func assertScale (t * testing.T , id string , policy cohv1.ScalingPolicy , replicasStart , replicasScale int32 , scaler ScaleFunction ) {
143
+ func assertScale (t * testing.T , id string , policy cohv1.ScalingPolicy , replicasStart , replicasScale int32 , scaler ScaleFunction ) types. NamespacedName {
142
144
g := NewGomegaWithT (t )
143
145
144
146
testContext .CleanupAfterTest (t )
@@ -153,16 +155,24 @@ func assertScale(t *testing.T, id string, policy cohv1.ScalingPolicy, replicasSt
153
155
// Give the deployment a unique name based on the test name
154
156
deployment .SetName (fmt .Sprintf ("%s-%s" , deployment .GetName (), strings .ToLower (id )))
155
157
156
- // update the replica count and scaling policy
157
- deployment .SetReplicas (replicasStart )
158
+ // update the replica count if greater than or equal zero, otherwise do not set the replica count field
159
+ var initialReplicas int32
160
+ if replicasStart >= 0 {
161
+ deployment .SetReplicas (replicasStart )
162
+ initialReplicas = replicasStart
163
+ } else {
164
+ deployment .Spec .Replicas = nil
165
+ initialReplicas = cohv1 .DefaultReplicas
166
+ }
158
167
168
+ // update the scaling policy
159
169
if deployment .Spec .Scaling == nil {
160
170
deployment .Spec .Scaling = & cohv1.ScalingSpec {}
161
171
}
162
172
deployment .Spec .Scaling .Policy = & policy
163
173
164
174
// Do the canary test unless parallel scaling down
165
- doCanary := replicasStart < replicasScale || policy != cohv1 .ParallelScaling
175
+ doCanary := initialReplicas < replicasScale || policy != cohv1 .ParallelScaling
166
176
167
177
t .Logf ("assertScale() - doCanary=%t" , doCanary )
168
178
t .Log ("assertScale() - Installing Coherence deployment..." )
@@ -186,6 +196,8 @@ func assertScale(t *testing.T, id string, policy cohv1.ScalingPolicy, replicasSt
186
196
err = helper .CheckCanary (testContext , namespace , deployment .Name )
187
197
g .Expect (err ).NotTo (HaveOccurred ())
188
198
}
199
+
200
+ return types.NamespacedName {Namespace : deployment .Namespace , Name : deployment .Name }
189
201
}
190
202
191
203
func assertScaleDownToZero (t * testing.T , id string , scaler ScaleFunction , suspend * bool ) {
0 commit comments