Skip to content

Commit b90e4be

Browse files
authored
[Feature] ID ServerGroup (#1137)
1 parent 9175d4d commit b90e4be

File tree

10 files changed

+67
-24
lines changed

10 files changed

+67
-24
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- (Feature) Ensure consistency during replication cancellation
66
- (Feature) Add annotation to change architecture of a member
77
- (Bugfix) Prevent Member Maintenance Error log
8+
- (Feature) ID ServerGroup
89

910
## [1.2.19](https://github.com/arangodb/kube-arangodb/tree/1.2.19) (2022-10-05)
1011
- (Bugfix) Prevent changes when UID is wrong

pkg/apis/deployment/v1/server_group.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ const (
8686
ServerGroupCoordinatorsString = "coordinator"
8787
ServerGroupSyncMastersString = "syncmaster"
8888
ServerGroupSyncWorkersString = "syncworker"
89-
ServerGroupImageDiscoveryString = "imagediscovery"
89+
ServerGroupImageDiscoveryString = "id"
9090

9191
ServerGroupSingleAbbreviatedString = "sngl"
9292
ServerGroupAgentsAbbreviatedString = "agnt"
@@ -131,6 +131,8 @@ func (g ServerGroup) AsRole() string {
131131
return ServerGroupSyncMastersString
132132
case ServerGroupSyncWorkers:
133133
return ServerGroupSyncWorkersString
134+
case ServerGroupImageDiscovery:
135+
return ServerGroupImageDiscoveryString
134136
default:
135137
return "?"
136138
}
@@ -151,6 +153,8 @@ func (g ServerGroup) AsRoleAbbreviated() string {
151153
return ServerGroupSyncMastersAbbreviatedString
152154
case ServerGroupSyncWorkers:
153155
return ServerGroupSyncWorkersAbbreviatedString
156+
case ServerGroupImageDiscovery:
157+
return ServerGroupImageDiscoveryAbbreviatedString
154158
default:
155159
return "?"
156160
}
@@ -227,6 +231,8 @@ func ServerGroupFromAbbreviatedRole(label string) ServerGroup {
227231
return ServerGroupSyncMasters
228232
case ServerGroupSyncWorkersAbbreviatedString:
229233
return ServerGroupSyncWorkers
234+
case ServerGroupImageDiscoveryAbbreviatedString:
235+
return ServerGroupImageDiscovery
230236
default:
231237
return ServerGroupUnknown
232238
}
@@ -247,6 +253,8 @@ func ServerGroupFromRole(label string) ServerGroup {
247253
return ServerGroupSyncMasters
248254
case ServerGroupSyncWorkersString:
249255
return ServerGroupSyncWorkers
256+
case ServerGroupImageDiscoveryString:
257+
return ServerGroupImageDiscovery
250258
default:
251259
return ServerGroupUnknown
252260
}

pkg/apis/deployment/v2alpha1/server_group.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ const (
8686
ServerGroupCoordinatorsString = "coordinator"
8787
ServerGroupSyncMastersString = "syncmaster"
8888
ServerGroupSyncWorkersString = "syncworker"
89-
ServerGroupImageDiscoveryString = "imagediscovery"
89+
ServerGroupImageDiscoveryString = "id"
9090

9191
ServerGroupSingleAbbreviatedString = "sngl"
9292
ServerGroupAgentsAbbreviatedString = "agnt"
@@ -131,6 +131,8 @@ func (g ServerGroup) AsRole() string {
131131
return ServerGroupSyncMastersString
132132
case ServerGroupSyncWorkers:
133133
return ServerGroupSyncWorkersString
134+
case ServerGroupImageDiscovery:
135+
return ServerGroupImageDiscoveryString
134136
default:
135137
return "?"
136138
}
@@ -151,6 +153,8 @@ func (g ServerGroup) AsRoleAbbreviated() string {
151153
return ServerGroupSyncMastersAbbreviatedString
152154
case ServerGroupSyncWorkers:
153155
return ServerGroupSyncWorkersAbbreviatedString
156+
case ServerGroupImageDiscovery:
157+
return ServerGroupImageDiscoveryAbbreviatedString
154158
default:
155159
return "?"
156160
}
@@ -227,6 +231,8 @@ func ServerGroupFromAbbreviatedRole(label string) ServerGroup {
227231
return ServerGroupSyncMasters
228232
case ServerGroupSyncWorkersAbbreviatedString:
229233
return ServerGroupSyncWorkers
234+
case ServerGroupImageDiscoveryAbbreviatedString:
235+
return ServerGroupImageDiscovery
230236
default:
231237
return ServerGroupUnknown
232238
}
@@ -247,6 +253,8 @@ func ServerGroupFromRole(label string) ServerGroup {
247253
return ServerGroupSyncMasters
248254
case ServerGroupSyncWorkersString:
249255
return ServerGroupSyncWorkers
256+
case ServerGroupImageDiscoveryString:
257+
return ServerGroupImageDiscovery
250258
default:
251259
return ServerGroupUnknown
252260
}

pkg/apis/shared/constants.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ const (
4242
NodeArchAffinityLabel = "kubernetes.io/arch"
4343
NodeArchAffinityLabelBeta = "beta.kubernetes.io/arch"
4444

45-
// Internal constants
46-
ImageIDAndVersionRole = "id" // Role use by identification pods
47-
4845
// Pod constants
4946
ServerContainerName = "server"
5047
ExporterContainerName = "exporter"

pkg/deployment/images.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func (ib *imagesBuilder) Run(ctx context.Context, cachedStatus inspectorInterfac
131131
// When no pod exists, it is created, otherwise the ID is fetched & version detected.
132132
// Returns: retrySoon, error
133133
func (ib *imagesBuilder) fetchArangoDBImageIDAndVersion(ctx context.Context, cachedStatus inspectorInterface.Inspector, image string) (bool, error) {
134-
role := shared.ImageIDAndVersionRole
134+
role := api.ServerGroupImageDiscovery.AsRole()
135135
id := fmt.Sprintf("%0x", sha1.Sum([]byte(image)))[:6]
136136
podName := k8sutil.CreatePodName(ib.APIObject.GetName(), role, id, "")
137137
log := ib.Log.

pkg/deployment/images_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func TestEnsureImages(t *testing.T) {
5858
// Arange
5959
terminationGracePeriodSeconds := int64((time.Second * 30).Seconds())
6060
id := fmt.Sprintf("%0x", sha1.Sum([]byte(testNewImage)))[:6]
61-
hostname := testDeploymentName + "-" + shared.ImageIDAndVersionRole + "-" + id
61+
hostname := testDeploymentName + "-" + api.ServerGroupImageDiscovery.AsRole() + "-" + id
6262

6363
var securityContext api.ServerGroupSpecSecurityContext
6464

@@ -107,7 +107,7 @@ func TestEnsureImages(t *testing.T) {
107107
Hostname: hostname,
108108
Subdomain: testDeploymentName + "-int",
109109
Affinity: k8sutil.CreateAffinity(testDeploymentName,
110-
shared.ImageIDAndVersionRole, false, ""),
110+
api.ServerGroupImageDiscovery.AsRole(), false, ""),
111111
},
112112
},
113113
},
@@ -170,7 +170,7 @@ func TestEnsureImages(t *testing.T) {
170170
Hostname: hostname,
171171
Subdomain: testDeploymentName + "-int",
172172
Affinity: k8sutil.CreateAffinity(testDeploymentName,
173-
shared.ImageIDAndVersionRole, false, ""),
173+
api.ServerGroupImageDiscovery.AsRole(), false, ""),
174174
},
175175
},
176176
},
@@ -213,7 +213,7 @@ func TestEnsureImages(t *testing.T) {
213213
Hostname: hostname,
214214
Subdomain: testDeploymentName + "-int",
215215
Affinity: k8sutil.CreateAffinity(testDeploymentName,
216-
shared.ImageIDAndVersionRole, false, ""),
216+
api.ServerGroupImageDiscovery.AsRole(), false, ""),
217217
},
218218
},
219219
},
@@ -269,7 +269,7 @@ func TestEnsureImages(t *testing.T) {
269269
Hostname: hostname,
270270
Subdomain: testDeploymentName + "-int",
271271
Affinity: k8sutil.CreateAffinity(testDeploymentName,
272-
shared.ImageIDAndVersionRole, false, ""),
272+
api.ServerGroupImageDiscovery.AsRole(), false, ""),
273273
},
274274
},
275275
},
@@ -283,7 +283,7 @@ func TestEnsureImages(t *testing.T) {
283283
Before: func(t *testing.T, deployment *Deployment) {
284284
pod := core.Pod{
285285
ObjectMeta: meta.ObjectMeta{
286-
Name: k8sutil.CreatePodName(testDeploymentName, shared.ImageIDAndVersionRole, id, ""),
286+
Name: k8sutil.CreatePodName(testDeploymentName, api.ServerGroupImageDiscovery.AsRole(), id, ""),
287287
CreationTimestamp: meta.Now(),
288288
},
289289
Spec: core.PodSpec{},
@@ -310,7 +310,7 @@ func TestEnsureImages(t *testing.T) {
310310
Before: func(t *testing.T, deployment *Deployment) {
311311
pod := core.Pod{
312312
ObjectMeta: meta.ObjectMeta{
313-
Name: k8sutil.CreatePodName(testDeploymentName, shared.ImageIDAndVersionRole, id, ""),
313+
Name: k8sutil.CreatePodName(testDeploymentName, api.ServerGroupImageDiscovery.AsRole(), id, ""),
314314
},
315315
Status: core.PodStatus{
316316
Phase: core.PodFailed,
@@ -335,7 +335,7 @@ func TestEnsureImages(t *testing.T) {
335335
Before: func(t *testing.T, deployment *Deployment) {
336336
pod := core.Pod{
337337
ObjectMeta: meta.ObjectMeta{
338-
Name: k8sutil.CreatePodName(testDeploymentName, shared.ImageIDAndVersionRole, id, ""),
338+
Name: k8sutil.CreatePodName(testDeploymentName, api.ServerGroupImageDiscovery.AsRole(), id, ""),
339339
},
340340
Status: core.PodStatus{
341341
Conditions: []core.PodCondition{
@@ -364,7 +364,7 @@ func TestEnsureImages(t *testing.T) {
364364
Before: func(t *testing.T, deployment *Deployment) {
365365
pod := core.Pod{
366366
ObjectMeta: meta.ObjectMeta{
367-
Name: k8sutil.CreatePodName(testDeploymentName, shared.ImageIDAndVersionRole, id, ""),
367+
Name: k8sutil.CreatePodName(testDeploymentName, api.ServerGroupImageDiscovery.AsRole(), id, ""),
368368
},
369369
Status: core.PodStatus{
370370
Conditions: []core.PodCondition{
@@ -394,7 +394,7 @@ func TestEnsureImages(t *testing.T) {
394394
Before: func(t *testing.T, deployment *Deployment) {
395395
pod := core.Pod{
396396
ObjectMeta: meta.ObjectMeta{
397-
Name: k8sutil.CreatePodName(testDeploymentName, shared.ImageIDAndVersionRole, id, ""),
397+
Name: k8sutil.CreatePodName(testDeploymentName, api.ServerGroupImageDiscovery.AsRole(), id, ""),
398398
},
399399
Status: core.PodStatus{
400400
Conditions: []core.PodCondition{

pkg/deployment/resources/pod_cleanup.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"github.com/arangodb/kube-arangodb/pkg/util/errors"
3434
"github.com/arangodb/kube-arangodb/pkg/util/globals"
3535
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
36+
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/info"
3637
podv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/pod/v1"
3738
)
3839

@@ -51,7 +52,7 @@ func (r *Resources) CleanupTerminatedPods(ctx context.Context) (util.Interval, e
5152
status := r.context.GetStatus()
5253
if err := r.context.ACS().ForEachHealthyCluster(func(item sutil.ACSItem) error {
5354
return item.Cache().Pod().V1().Iterate(func(pod *core.Pod) error {
54-
if k8sutil.IsArangoDBImageIDAndVersionPod(pod) {
55+
if info.GetPodServerGroup(pod) == api.ServerGroupImageDiscovery {
5556
// Image ID pods are not relevant to inspect here
5657
return nil
5758
}

pkg/deployment/resources/pod_inspector.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
"github.com/arangodb/kube-arangodb/pkg/util"
3939
"github.com/arangodb/kube-arangodb/pkg/util/errors"
4040
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
41+
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/info"
4142
inspectorInterface "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector"
4243
podv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/pod/v1"
4344
)
@@ -97,7 +98,7 @@ func (r *Resources) InspectPods(ctx context.Context, cachedStatus inspectorInter
9798
var unscheduledPodNames []string
9899

99100
err := cachedStatus.Pod().V1().Iterate(func(pod *core.Pod) error {
100-
if k8sutil.IsArangoDBImageIDAndVersionPod(pod) {
101+
if info.GetPodServerGroup(pod) == api.ServerGroupImageDiscovery {
101102
// Image ID pods are not relevant to inspect here
102103
return nil
103104
}

pkg/util/k8sutil/info/pods.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
21+
package info
22+
23+
import (
24+
core "k8s.io/api/core/v1"
25+
26+
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
27+
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
28+
)
29+
30+
// GetPodServerGroup returns ServerGroup based on Pod label
31+
func GetPodServerGroup(p *core.Pod) api.ServerGroup {
32+
return api.ServerGroupFromRole(p.GetLabels()[k8sutil.LabelKeyRole])
33+
}

pkg/util/k8sutil/pods.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -296,12 +296,6 @@ func IsPodTerminating(pod *core.Pod) bool {
296296
return IsPodMarkedForDeletion(pod) && pod.Status.Phase == core.PodRunning
297297
}
298298

299-
// IsArangoDBImageIDAndVersionPod returns true if the given pod is used for fetching image ID and ArangoDB version of an image
300-
func IsArangoDBImageIDAndVersionPod(p *core.Pod) bool {
301-
role, found := p.GetLabels()[LabelKeyRole]
302-
return found && role == shared.ImageIDAndVersionRole
303-
}
304-
305299
// getPodCondition returns the condition of given type in the given status.
306300
// If not found, nil is returned.
307301
func getPodCondition(status *core.PodStatus, condType core.PodConditionType) *core.PodCondition {

0 commit comments

Comments
 (0)