Skip to content

Commit ea2dc2a

Browse files
authored
[Bugfix] Fix ArangoSync Port (#954)
1 parent 30ea984 commit ea2dc2a

File tree

4 files changed

+99
-33
lines changed

4 files changed

+99
-33
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- (Feature) Allow configuration for securityContext.runAsUser value
55
- (Bugfix) Fix Satellite collections in Agency
66
- (Bugfix) Fix backup creation timeout
7+
- (Bugfix) ArangoSync port fix
78

89
## [1.2.9](https://github.com/arangodb/kube-arangodb/tree/1.2.9) (2022-03-30)
910
- (Feature) Improve Kubernetes clientsets management

pkg/deployment/resources/services.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import (
3434
inspectorInterface "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector"
3535

3636
core "k8s.io/api/core/v1"
37-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
37+
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
3838

3939
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
4040
"github.com/arangodb/kube-arangodb/pkg/apis/shared"
@@ -68,6 +68,15 @@ func (r *Resources) EnsureServices(ctx context.Context, cachedStatus inspectorIn
6868

6969
// Ensure member services
7070
if err := status.Members.ForeachServerGroup(func(group api.ServerGroup, list api.MemberStatusList) error {
71+
var targetPort int32 = shared.ArangoPort
72+
73+
switch group {
74+
case api.ServerGroupSyncMasters:
75+
targetPort = shared.ArangoSyncMasterPort
76+
case api.ServerGroupSyncWorkers:
77+
targetPort = shared.ArangoSyncWorkerPort
78+
}
79+
7180
for _, m := range list {
7281
memberName := m.ArangoMemberName(r.context.GetAPIObject().GetName(), group)
7382

@@ -78,10 +87,10 @@ func (r *Resources) EnsureServices(ctx context.Context, cachedStatus inspectorIn
7887

7988
if s, ok := cachedStatus.Service().V1().GetSimple(member.GetName()); !ok {
8089
s = &core.Service{
81-
ObjectMeta: metav1.ObjectMeta{
90+
ObjectMeta: meta.ObjectMeta{
8291
Name: member.GetName(),
8392
Namespace: member.GetNamespace(),
84-
OwnerReferences: []metav1.OwnerReference{
93+
OwnerReferences: []meta.OwnerReference{
8594
member.AsOwner(),
8695
},
8796
},
@@ -92,7 +101,7 @@ func (r *Resources) EnsureServices(ctx context.Context, cachedStatus inspectorIn
92101
Name: "server",
93102
Protocol: "TCP",
94103
Port: shared.ArangoPort,
95-
TargetPort: intstr.IntOrString{IntVal: shared.ArangoPort},
104+
TargetPort: intstr.IntOrString{IntVal: targetPort},
96105
},
97106
},
98107
PublishNotReadyAddresses: true,
@@ -101,7 +110,7 @@ func (r *Resources) EnsureServices(ctx context.Context, cachedStatus inspectorIn
101110
}
102111

103112
err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error {
104-
_, err := svcs.Create(ctxChild, s, metav1.CreateOptions{})
113+
_, err := svcs.Create(ctxChild, s, meta.CreateOptions{})
105114
return err
106115
})
107116
if err != nil {
@@ -121,7 +130,7 @@ func (r *Resources) EnsureServices(ctx context.Context, cachedStatus inspectorIn
121130
Name: "server",
122131
Protocol: "TCP",
123132
Port: shared.ArangoPort,
124-
TargetPort: intstr.IntOrString{IntVal: shared.ArangoPort},
133+
TargetPort: intstr.IntOrString{IntVal: targetPort},
125134
},
126135
}
127136
spec.PublishNotReadyAddresses = true
@@ -131,7 +140,7 @@ func (r *Resources) EnsureServices(ctx context.Context, cachedStatus inspectorIn
131140
s.Spec = *spec
132141

133142
err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error {
134-
_, err := svcs.Update(ctxChild, s, metav1.UpdateOptions{})
143+
_, err := svcs.Update(ctxChild, s, meta.UpdateOptions{})
135144
return err
136145
})
137146
if err != nil {
@@ -296,7 +305,7 @@ func (r *Resources) ensureExternalAccessServices(ctx context.Context, cachedStat
296305
}
297306
if updateExternalAccessService && !createExternalAccessService && !deleteExternalAccessService {
298307
err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error {
299-
_, err := svcs.Update(ctxChild, existing, metav1.UpdateOptions{})
308+
_, err := svcs.Update(ctxChild, existing, meta.UpdateOptions{})
300309
return err
301310
})
302311
if err != nil {
@@ -314,7 +323,7 @@ func (r *Resources) ensureExternalAccessServices(ctx context.Context, cachedStat
314323
if deleteExternalAccessService {
315324
log.Info().Str("service", eaServiceName).Msgf("Removing obsolete %s external access service", title)
316325
err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error {
317-
return svcs.Delete(ctxChild, eaServiceName, metav1.DeleteOptions{})
326+
return svcs.Delete(ctxChild, eaServiceName, meta.DeleteOptions{})
318327
})
319328
if err != nil {
320329
log.Debug().Err(err).Msgf("Failed to remove %s external access service", title)

pkg/deployment/rotation/arangod_containers.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ func containersCompare(_ api.DeploymentSpec, _ api.ServerGroup, spec, status *co
6969
}
7070
}
7171

72+
if !equality.Semantic.DeepEqual(ac.Ports, bc.Ports) {
73+
bc.Ports = ac.Ports
74+
mode = mode.And(SilentRotation)
75+
}
76+
7277
if !areProbesEqual(ac.StartupProbe, bc.StartupProbe) {
7378
bc.StartupProbe = ac.StartupProbe
7479
mode = mode.And(SilentRotation)

pkg/deployment/rotation/arangod_containers_test.go

Lines changed: 75 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
"testing"
2525

2626
"github.com/stretchr/testify/assert"
27-
v1 "k8s.io/api/core/v1"
27+
core "k8s.io/api/core/v1"
2828

2929
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
3030
"github.com/arangodb/kube-arangodb/pkg/apis/shared"
@@ -63,10 +63,10 @@ func Test_InitContainers(t *testing.T) {
6363
testCases := []TestCase{
6464
{
6565
name: "Same containers",
66-
spec: buildPodSpec(addInitContainer(api.ServerGroupReservedInitContainerNameUUID, nil), addInitContainer("sidecar", func(c *v1.Container) {
66+
spec: buildPodSpec(addInitContainer(api.ServerGroupReservedInitContainerNameUUID, nil), addInitContainer("sidecar", func(c *core.Container) {
6767
c.Image = "local:1.0"
6868
})),
69-
status: buildPodSpec(addInitContainer(api.ServerGroupReservedInitContainerNameUUID, nil), addInitContainer("sidecar", func(c *v1.Container) {
69+
status: buildPodSpec(addInitContainer(api.ServerGroupReservedInitContainerNameUUID, nil), addInitContainer("sidecar", func(c *core.Container) {
7070
c.Image = "local:1.0"
7171
})),
7272

@@ -80,10 +80,10 @@ func Test_InitContainers(t *testing.T) {
8080
},
8181
{
8282
name: "Containers with different image",
83-
spec: buildPodSpec(addInitContainer(api.ServerGroupReservedInitContainerNameUUID, nil), addInitContainer("sidecar", func(c *v1.Container) {
83+
spec: buildPodSpec(addInitContainer(api.ServerGroupReservedInitContainerNameUUID, nil), addInitContainer("sidecar", func(c *core.Container) {
8484
c.Image = "local:1.0"
8585
})),
86-
status: buildPodSpec(addInitContainer(api.ServerGroupReservedInitContainerNameUUID, nil), addInitContainer("sidecar", func(c *v1.Container) {
86+
status: buildPodSpec(addInitContainer(api.ServerGroupReservedInitContainerNameUUID, nil), addInitContainer("sidecar", func(c *core.Container) {
8787
c.Image = "local:2.0"
8888
})),
8989

@@ -104,10 +104,10 @@ func Test_InitContainers(t *testing.T) {
104104
testCases := []TestCase{
105105
{
106106
name: "Containers with different image but init rotation enforced",
107-
spec: buildPodSpec(addInitContainer(api.ServerGroupReservedInitContainerNameUUID, nil), addInitContainer("sidecar", func(c *v1.Container) {
107+
spec: buildPodSpec(addInitContainer(api.ServerGroupReservedInitContainerNameUUID, nil), addInitContainer("sidecar", func(c *core.Container) {
108108
c.Image = "local:1.0"
109109
})),
110-
status: buildPodSpec(addInitContainer(api.ServerGroupReservedInitContainerNameUUID, nil), addInitContainer("sidecar", func(c *v1.Container) {
110+
status: buildPodSpec(addInitContainer(api.ServerGroupReservedInitContainerNameUUID, nil), addInitContainer("sidecar", func(c *core.Container) {
111111
c.Image = "local:2.0"
112112
})),
113113

@@ -121,14 +121,14 @@ func Test_InitContainers(t *testing.T) {
121121
},
122122
{
123123
name: "Core Containers with different image but init rotation enforced",
124-
spec: buildPodSpec(addInitContainer(api.ServerGroupReservedInitContainerNameUUID, func(c *v1.Container) {
124+
spec: buildPodSpec(addInitContainer(api.ServerGroupReservedInitContainerNameUUID, func(c *core.Container) {
125125
c.Image = "local:1.0"
126-
}), addInitContainer("sidecar", func(c *v1.Container) {
126+
}), addInitContainer("sidecar", func(c *core.Container) {
127127
c.Image = "local:1.0"
128128
})),
129-
status: buildPodSpec(addInitContainer(api.ServerGroupReservedInitContainerNameUUID, func(c *v1.Container) {
129+
status: buildPodSpec(addInitContainer(api.ServerGroupReservedInitContainerNameUUID, func(c *core.Container) {
130130
c.Image = "local:2.0"
131-
}), addInitContainer("sidecar", func(c *v1.Container) {
131+
}), addInitContainer("sidecar", func(c *core.Container) {
132132
c.Image = "local:1.0"
133133
})),
134134

@@ -142,12 +142,12 @@ func Test_InitContainers(t *testing.T) {
142142
},
143143
{
144144
name: "Only core container change",
145-
spec: buildPodSpec(addInitContainer(api.ServerGroupReservedInitContainerNameUUID, func(c *v1.Container) {
145+
spec: buildPodSpec(addInitContainer(api.ServerGroupReservedInitContainerNameUUID, func(c *core.Container) {
146146
c.Image = "local:1.0"
147-
}), addInitContainer(api.ServerGroupReservedInitContainerNameUpgrade, func(c *v1.Container) {
147+
}), addInitContainer(api.ServerGroupReservedInitContainerNameUpgrade, func(c *core.Container) {
148148
c.Image = "local:1.0"
149149
})),
150-
status: buildPodSpec(addInitContainer(api.ServerGroupReservedInitContainerNameUUID, func(c *v1.Container) {
150+
status: buildPodSpec(addInitContainer(api.ServerGroupReservedInitContainerNameUUID, func(c *core.Container) {
151151
c.Image = "local:2.0"
152152
})),
153153

@@ -161,16 +161,16 @@ func Test_InitContainers(t *testing.T) {
161161
},
162162
{
163163
name: "Only core container change with sidecar",
164-
spec: buildPodSpec(addInitContainer(api.ServerGroupReservedInitContainerNameUUID, func(c *v1.Container) {
164+
spec: buildPodSpec(addInitContainer(api.ServerGroupReservedInitContainerNameUUID, func(c *core.Container) {
165165
c.Image = "local:1.0"
166-
}), addInitContainer(api.ServerGroupReservedInitContainerNameUpgrade, func(c *v1.Container) {
166+
}), addInitContainer(api.ServerGroupReservedInitContainerNameUpgrade, func(c *core.Container) {
167167
c.Image = "local:1.0"
168-
}), addInitContainer("sidecar", func(c *v1.Container) {
168+
}), addInitContainer("sidecar", func(c *core.Container) {
169169
c.Image = "local:1.0"
170170
})),
171-
status: buildPodSpec(addInitContainer(api.ServerGroupReservedInitContainerNameUUID, func(c *v1.Container) {
171+
status: buildPodSpec(addInitContainer(api.ServerGroupReservedInitContainerNameUUID, func(c *core.Container) {
172172
c.Image = "local:2.0"
173-
}), addInitContainer("sidecar", func(c *v1.Container) {
173+
}), addInitContainer("sidecar", func(c *core.Container) {
174174
c.Image = "local:1.0"
175175
})),
176176

@@ -184,16 +184,16 @@ func Test_InitContainers(t *testing.T) {
184184
},
185185
{
186186
name: "Only core container change with sidecar change",
187-
spec: buildPodSpec(addInitContainer(api.ServerGroupReservedInitContainerNameUUID, func(c *v1.Container) {
187+
spec: buildPodSpec(addInitContainer(api.ServerGroupReservedInitContainerNameUUID, func(c *core.Container) {
188188
c.Image = "local:1.0"
189-
}), addInitContainer(api.ServerGroupReservedInitContainerNameUpgrade, func(c *v1.Container) {
189+
}), addInitContainer(api.ServerGroupReservedInitContainerNameUpgrade, func(c *core.Container) {
190190
c.Image = "local:1.0"
191-
}), addInitContainer("sidecar", func(c *v1.Container) {
191+
}), addInitContainer("sidecar", func(c *core.Container) {
192192
c.Image = "local:1.0"
193193
})),
194-
status: buildPodSpec(addInitContainer(api.ServerGroupReservedInitContainerNameUUID, func(c *v1.Container) {
194+
status: buildPodSpec(addInitContainer(api.ServerGroupReservedInitContainerNameUUID, func(c *core.Container) {
195195
c.Image = "local:2.0"
196-
}), addInitContainer("sidecar", func(c *v1.Container) {
196+
}), addInitContainer("sidecar", func(c *core.Container) {
197197
c.Image = "local:2.0"
198198
})),
199199

@@ -271,6 +271,57 @@ func Test_Container_Args(t *testing.T) {
271271
runTestCases(t)(testCases...)
272272
}
273273

274+
func Test_Container_Ports(t *testing.T) {
275+
testCases := []TestCase{
276+
{
277+
name: "Ports of server pod changed",
278+
spec: buildPodSpec(addContainer("server", func(c *core.Container) {
279+
c.Ports = []core.ContainerPort{
280+
{
281+
Name: "server",
282+
ContainerPort: 8526,
283+
Protocol: "tcp",
284+
},
285+
}
286+
})),
287+
status: buildPodSpec(addContainer("server", func(c *core.Container) {
288+
c.Ports = []core.ContainerPort{
289+
{
290+
Name: "server",
291+
ContainerPort: 8626,
292+
Protocol: "tcp",
293+
},
294+
}
295+
})),
296+
expectedMode: SilentRotation,
297+
},
298+
{
299+
name: "Ports of sidecar pod changed",
300+
spec: buildPodSpec(addContainer("sidecar", func(c *core.Container) {
301+
c.Ports = []core.ContainerPort{
302+
{
303+
Name: "server",
304+
ContainerPort: 8526,
305+
Protocol: "tcp",
306+
},
307+
}
308+
})),
309+
status: buildPodSpec(addContainer("sidecar", func(c *core.Container) {
310+
c.Ports = []core.ContainerPort{
311+
{
312+
Name: "server",
313+
ContainerPort: 8626,
314+
Protocol: "tcp",
315+
},
316+
}
317+
})),
318+
expectedMode: GracefulRotation,
319+
},
320+
}
321+
322+
runTestCases(t)(testCases...)
323+
}
324+
274325
func TestIsOnlyLogLevelChanged(t *testing.T) {
275326
type args struct {
276327
specArgs []string

0 commit comments

Comments
 (0)