10000 [Feature] Add Services for Group (#1693) · arangodb/kube-arangodb@a456ef6 · GitHub
[go: up one dir, main page]

Skip to content

Commit a456ef6

Browse files
authored
[Feature] Add Services for Group (#1693)
1 parent e1eee03 commit a456ef6

File tree

7 files changed

+128
-14
lines changed

7 files changed

+128
-14
lines changed

.circleci/continue_config.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,7 @@ jobs:
8484
echo "This is not a pull request. Skipping..."
8585
exit 0
8686
fi
87-
make tidy update-generated synchronize-v2alpha1-with-v1 generate-internal sync fmt yamlfmt license
88-
git checkout -- go.sum # ignore changes in go.sum
89-
if [ ! -z "$(git status --porcelain)" ]; then
90-
echo "There are uncommited changes!"
91-
git status
92-
exit 1
93-
fi
87+
make ci-check
9488
environment:
9589
GO111MODULES: off
9690

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A)
44
- (Feature) ArangoRoute CRD
55
- (Feature) ArangoRoute Operator
6+
- (Feature) Add Kubernetes Services for Group
67

78
## [1.2.42](https://github.com/arangodb/kube-arangodb/tree/1.2.42) (2024-07-23)
89
- (Maintenance) Go 1.22.4 & Kubernetes 1.29.6 libraries

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,3 +919,8 @@ sync-charts:
919919
@(cd "$(ROOT)/chart/kube-arangodb"; find . -type f -not -name values.yaml -not -name Chart.yaml -exec cp "$(ROOT)/chart/kube-arangodb/{}" "$(ROOT)/chart/kube-arangodb-arm64/{}" \;)
920920

921921
sync: sync-charts
922+
923+
ci-check:
924+
@$(MAKE) tidy vendor update-generated synchronize-v2alpha1-with-v1 generate-internal sync fmt yamlfmt license
925+
@git checkout -- go.sum # ignore changes in go.sum
926+
@if [ ! -z "$(git status --porcelain)" ]; then echo "There are uncommited changes!"; git status; exit 1; fi

pkg/apis/deployment/v1/server_group.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,35 @@ func (g ServerGroup) AsRole() string {
144144
}
145145
}
146146

147+
// Enabled checks if group is enabled for a mode
148+
func (g ServerGroup) Enabled(mode DeploymentMode) bool {
149+
switch mode {
150+
case DeploymentModeSingle:
151+
switch g {
152+
case ServerGroupSingle:
153+
return true
154+
default:
155+
return false
156+
}
157+
case DeploymentModeActiveFailover:
158+
switch g {
159+
case ServerGroupAgents, ServerGroupDBServers, ServerGroupCoordinators, ServerGroupSyncMasters, ServerGroupSyncWorkers:
160+
return true
161+
default:
162+
return false
163+
}
164+
case DeploymentModeCluster:
165+
switch g {
166+
case ServerGroupSingle, ServerGroupAgents:
167+
return true
168+
default:
169+
return false
170+
}
171+
default:
172+
return false
173+
}
174+
}
175+
147176
// AsRoleAbbreviated returns the abbreviation of the "role" value for the given group.
148177
func (g ServerGroup) AsRoleAbbreviated() string {
149178
switch g {

pkg/apis/deployment/v2alpha1/server_group.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,35 @@ func (g ServerGroup) AsRole() string {
144144
}
145145
}
146146

147+
// Enabled checks if group is enabled for a mode
148+
func (g ServerGroup) Enabled(mode DeploymentMode) bool {
149+
switch mode {
150+
case DeploymentModeSingle:
151+
switch g {
152+
case ServerGroupSingle:
153+
return true
154+
default:
155+
return false
156+
}
157+
case DeploymentModeActiveFailover:
158+
switch g {
159+
case ServerGroupAgents, ServerGroupDBServers, ServerGroupCoordinators, ServerGroupSyncMasters, ServerGroupSyncWorkers:
160+
return true
161+
default:
162+
return false
163+
}
164+
case DeploymentModeCluster:
165+
switch g {
166+
case ServerGroupSingle, ServerGroupAgents:
167+
return true
168+
default:
169+
return false
170+
}
171+
default:
172+
return false
173+
}
174+
}
175+
147176
// AsRoleAbbreviated returns the abbreviation of the "role" value for the given group.
148177
func (g ServerGroup) AsRoleAbbreviated() string {
149178
switch g {

pkg/deployment/resources/pod_leader.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -136,7 +136,7 @@ func (r *Resources) EnsureLeader(ctx context.Context, cachedStatus inspectorInte
136136
}
137137
}
138138

139-
s := r.createService(leaderAgentSvcName, r.context.GetNamespace(), "", core.ServiceTypeClusterIP, r.context.GetAPIObject().AsOwner(), ports, selector)
139+
s := r.createService(leaderAgentSvcName, r.context.GetNamespace(), "", core.ServiceTypeClusterIP, true, r.context.GetAPIObject().AsOwner(), ports, selector)
140140
err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error {
141141
_, err := cachedStatus.ServicesModInterface().V1().Create(ctxChild, s, meta.CreateOptions{})
142142
return err

pkg/deployment/resources/services.go

Lines changed: 61 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ package resources
2222

2323
import (
2424
"context"
25+
"fmt"
2526
"strings"
2627
"time"
2728

@@ -49,9 +50,7 @@ var (
4950
)
5051

5152
// createService returns service's object.
52-
func (r *Resources) createService(name, namespace, clusterIP string, serviceType core.ServiceType, owner meta.OwnerReference, ports []core.ServicePort,
53-
selector map[string]string) *core.Service {
54-
53+
func (r *Resources) createService(name, namespace, clusterIP string, serviceType core.ServiceType, publishNotReadyAddresses bool, owner meta.OwnerReference, ports []core.ServicePort, selector map[string]string) *core.Service {
5554
return &core.Service{
5655
ObjectMeta: meta.ObjectMeta{
5756
Name: name,
@@ -64,7 +63,7 @@ func (r *Resources) createService(name, namespace, clusterIP string, serviceType
6463
Type: serviceType,
6564
ClusterIP: clusterIP,
6665
Ports: ports,
67-
PublishNotReadyAddresses: true,
66+
PublishNotReadyAddresses: publishNotReadyAddresses,
6867
Selector: selector,
6968
},
7069
}
@@ -101,7 +100,7 @@ func (r *Resources) EnsureServices(ctx context.Context, cachedStatus inspectorIn
101100
ports := CreateServerServicePortsWithSidecars(amInspector, e.Member.ArangoMemberName(deploymentName, e.Group))
102101
selector := k8sutil.LabelsForActiveMember(deploymentName, e.Group.AsRole(), e.Member.ID)
103102
if s, ok := cachedStatus.Service().V1().GetSimple(member.GetName()); !ok {
104-
s := r.createService(member.GetName(), member.GetNamespace(), spec.CommunicationMethod.ServiceClusterIP(), spec.CommunicationMethod.ServiceType(), member.AsOwner(), ports, selector)
103+
s := r.createService(member.GetName(), member.GetNamespace(), spec.CommunicationMethod.ServiceClusterIP(), spec.CommunicationMethod.ServiceType(), true, member.AsOwner(), ports, selector)
105104

106105
err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error {
107106
_, err := svcs.Create(ctxChild, s, meta.CreateOptions{})
@@ -129,6 +128,63 @@ func (r *Resources) EnsureServices(ctx context.Context, cachedStatus inspectorIn
129128
}
130129
}
131130

131+
// Group Services
132+
for _, group := range api.AllServerGroups {
133+
if !group.Enabled(spec.GetMode()) {
134+
continue
135+
}
136+
137+
name := fmt.Sprintf("%s-%s", deploymentName, group.AsRole())
138+
s, ok := cachedStatus.Service().V1().GetSimple(name)
139+
140+
details := spec.GetServerGroupSpec(group)
141+
if details.GetCount() == 0 {
142+
if !ok {
143+
// We do not expect service and it is gone
144+
continue
145+
}
146+
147+
if err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error {
148+
return svcs.Delete(ctxChild, s.GetName(), meta.DeleteOptions{})
149+
}); err != nil {
150+
if !kerrors.IsNotFound(err) {
151+
return err
152+
}
153+
reconcileRequired.Required()
154+
}
155+
} else {
156+
selector := k8sutil.LabelsForDeployment(deploymentName, group.AsRole())
157+
ports := []core.ServicePort{CreateServerServicePort()}
158+
// Service should exists
159+
if !ok {
160+
s := r.createService(name, apiObject.GetNamespace(), spec.CommunicationMethod.ServiceClusterIP(), spec.CommunicationMethod.ServiceType(), false, apiObject.AsOwner(), ports, selector)
161+
162+
err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error {
163+
_, err := svcs.Create(ctxChild, s, meta.CreateOptions{})
164+
return err
165+
})
166+
if err != nil {
167+
if !kerrors.IsConflict(err) {
168+
return err
169+
}
170+
}
171+
172+
reconcileRequired.Required()
173+
continue
174+
} else {
175+
if changed, err := patcher.ServicePatcher(ctx, svcs, s, meta.PatchOptions{},
176+
patcher.PatchServicePorts(ports),
177+
patcher.PatchServiceSelector(selector),
178+
patcher.PatchServicePublishNotReadyAddresses(false),
179+
patcher.PatchServiceType(spec.CommunicationMethod.ServiceType())); err != nil {
180+
return err
181+
} else if changed {
182+
reconcileRequired.Required()
183+
}
184+
}
185+
}
186+
}
187+
132188
// Headless service
133189
counterMetric.Inc()
134190
headlessPorts, headlessSelector := k8sutil.HeadlessServiceDetails(deploymentName)

0 commit comments

Comments
 (0)
0