Skip to content

Commit 981b32e

Browse files
authored
Issue #368 - ensure that all roles have a replica count set
* Issue #368 - ensure that roles always have a replica value * Issue #368 - amend scale to zero test role to not have a replica count * Issue #368 - test modification
1 parent 605d743 commit 981b32e

File tree

4 files changed

+30
-10
lines changed

4 files changed

+30
-10
lines changed

Diff for: pkg/controller/coherencecluster/coherencecluster_controller.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -400,14 +400,22 @@ func (r *ReconcileCoherenceCluster) ensureWkaService(cluster *coherence.Coherenc
400400
func (r *ReconcileCoherenceCluster) getDesiredRoles(cluster *coherence.CoherenceCluster) (map[string]coherence.CoherenceRoleSpec, []string) {
401401
defaultSpec := cluster.Spec.CoherenceRoleSpec
402402
if len(cluster.Spec.Roles) == 0 {
403-
return map[string]coherence.CoherenceRoleSpec{defaultSpec.GetRoleName(): defaultSpec}, []string{defaultSpec.GetRoleName()}
403+
clone := *defaultSpec.DeepCopy()
404+
clone.SetReplicas(clone.GetReplicas())
405+
return map[string]coherence.CoherenceRoleSpec{clone.GetRoleName(): clone}, []string{clone.GetRoleName()}
404406
}
405407

406408
m := make(map[string]coherence.CoherenceRoleSpec)
407409
names := make([]string, len(cluster.Spec.Roles))
408410
index := 0
409411
for _, role := range cluster.Spec.Roles {
410412
clone := role.DeepCopyWithDefaults(&defaultSpec)
413+
414+
// Ensure that the role specifically has a replica value set.
415+
// The original yaml may not have had a replicas field but some versions of kubectl scale
416+
// will not work if the field is missing.
417+
clone.SetReplicas(clone.GetReplicas())
418+
411419
names[index] = role.GetRoleName()
412420
m[names[index]] = *clone
413421
index++

Diff for: pkg/controller/coherencecluster/coherencecluster_controller_test.go

+18-7
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1717
"k8s.io/apimachinery/pkg/runtime"
1818
"k8s.io/apimachinery/pkg/types"
19+
"k8s.io/utils/pointer"
1920
"sigs.k8s.io/controller-runtime/pkg/reconcile"
2021

2122
stubs "github.com/oracle/coherence-operator/pkg/fakes"
@@ -78,7 +79,7 @@ var _ = Describe("coherencecluster_controller", func() {
7879
mgr.AssertCoherenceRoles(testNamespace, 1)
7980
name := cluster.Spec.CoherenceRoleSpec.GetFullRoleName(cluster)
8081
role := mgr.AssertCoherenceRoleExists(testNamespace, name)
81-
Expect(role.Spec).To(Equal(coherence.CoherenceRoleSpec{}))
82+
Expect(role.Spec).To(Equal(coherence.CoherenceRoleSpec{Replicas: pointer.Int32Ptr(coherence.DefaultReplicas)}))
8283
})
8384

8485
It("should fire a successful CoherenceRole create event", func() {
@@ -149,7 +150,9 @@ var _ = Describe("coherencecluster_controller", func() {
149150
mgr.AssertCoherenceRoles(testNamespace, 1)
150151
name := roleSpec.GetFullRoleName(cluster)
151152
role := mgr.AssertCoherenceRoleExists(testNamespace, name)
152-
Expect(role.Spec).To(Equal(roleSpec))
153+
expected := roleSpec.DeepCopy()
154+
expected.SetReplicas(coherence.DefaultReplicas)
155+
Expect(role.Spec).To(Equal(*expected))
153156
})
154157
})
155158
})
@@ -220,13 +223,17 @@ var _ = Describe("coherencecluster_controller", func() {
220223
It("should create a CoherenceRole for the first role", func() {
221224
name := roleSpecOne.GetFullRoleName(cluster)
222225
role := mgr.AssertCoherenceRoleExists(testNamespace, name)
223-
Expect(role.Spec).To(Equal(roleSpecOne))
226+
expected := roleSpecOne.DeepCopy()
227+
expected.SetReplicas(coherence.DefaultReplicas)
228+
Expect(role.Spec).To(Equal(*expected))
224229
})
225230

226231
It("should create a CoherenceRole for the second role", func() {
227232
name := roleSpecTwo.GetFullRoleName(cluster)
228233
role := mgr.AssertCoherenceRoleExists(testNamespace, name)
229-
Expect(role.Spec).To(Equal(roleSpecTwo))
234+
expected := roleSpecTwo.DeepCopy()
235+
expected.SetReplicas(coherence.DefaultReplicas)
236+
Expect(role.Spec).To(Equal(*expected))
230237
})
231238
})
232239
})
@@ -320,7 +327,9 @@ var _ = Describe("coherencecluster_controller", func() {
320327
mgr.AssertCoherenceRoles(testNamespace, 1)
321328
name := existingRoleSpec.GetFullRoleName(cluster)
322329
role := mgr.AssertCoherenceRoleExists(testNamespace, name)
323-
Expect(role.Spec).To(Equal(updatedRoleSpec))
330+
expected := updatedRoleSpec.DeepCopy()
331+
expected.SetReplicas(coherence.DefaultReplicas)
332+
Expect(role.Spec).To(Equal(*expected))
324333
})
325334

326335
It("should fire a successful CoherenceRole update event", func() {
@@ -426,7 +435,8 @@ var _ = Describe("coherencecluster_controller", func() {
426435
Labels: map[string]string{coherence.CoherenceClusterLabel: testClusterName},
427436
},
428437
Spec: coherence.CoherenceRoleSpec{
429-
Role: "storage",
438+
Role: "storage",
439+
Replicas: pointer.Int32Ptr(2),
430440
},
431441
}
432442

@@ -437,7 +447,8 @@ var _ = Describe("coherencecluster_controller", func() {
437447
Labels: map[string]string{coherence.CoherenceClusterLabel: testClusterName},
438448
},
439449
Spec: coherence.CoherenceRoleSpec{
440-
Role: "proxy",
450+
Role: "proxy",
451+
Replicas: pointer.Int32Ptr(2),
441452
},
442453
}
443454

Diff for: pkg/fakes/fake_manager.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func NewFakeManager(initObjs ...runtime.Object) (*FakeManager, error) {
5151

5252
options := manager.Options{
5353
Namespace: helper.GetTestNamespace(),
54-
MapperProvider: apiutil.NewDiscoveryRESTMapper,
54+
MapperProvider: restMapper,
5555
LeaderElection: false,
5656
}
5757

@@ -68,6 +68,8 @@ func NewFakeManager(initObjs ...runtime.Object) (*FakeManager, error) {
6868
return &mgr, nil
6969
}
7070

71+
var restMapper = apiutil.NewDiscoveryRESTMapper
72+
7173
type FakeManager struct {
7274
Scheme *runtime.Scheme
7375
Client ClientWithErrors

Diff for: test/e2e/remote/scaling-to-zero-test.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ metadata:
55
spec:
66
roles:
77
- role: one
8-
replicas: 2
98
scaling:
109
policy: Parallel
1110
readinessProbe:

0 commit comments

Comments
 (0)