mirror of
https://github.com/arangodb/kube-arangodb.git
synced 2024-12-14 11:57:37 +00:00
[Feature] ID ServerGroup (#1137)
This commit is contained in:
parent
9175d4d8a1
commit
b90e4bed33
10 changed files with 67 additions and 24 deletions
|
@ -5,6 +5,7 @@
|
|||
- (Feature) Ensure consistency during replication cancellation
|
||||
- (Feature) Add annotation to change architecture of a member
|
||||
- (Bugfix) Prevent Member Maintenance Error log
|
||||
- (Feature) ID ServerGroup
|
||||
|
||||
## [1.2.19](https://github.com/arangodb/kube-arangodb/tree/1.2.19) (2022-10-05)
|
||||
- (Bugfix) Prevent changes when UID is wrong
|
||||
|
|
|
@ -86,7 +86,7 @@ const (
|
|||
ServerGroupCoordinatorsString = "coordinator"
|
||||
ServerGroupSyncMastersString = "syncmaster"
|
||||
ServerGroupSyncWorkersString = "syncworker"
|
||||
ServerGroupImageDiscoveryString = "imagediscovery"
|
||||
ServerGroupImageDiscoveryString = "id"
|
||||
|
||||
ServerGroupSingleAbbreviatedString = "sngl"
|
||||
ServerGroupAgentsAbbreviatedString = "agnt"
|
||||
|
@ -131,6 +131,8 @@ func (g ServerGroup) AsRole() string {
|
|||
return ServerGroupSyncMastersString
|
||||
case ServerGroupSyncWorkers:
|
||||
return ServerGroupSyncWorkersString
|
||||
case ServerGroupImageDiscovery:
|
||||
return ServerGroupImageDiscoveryString
|
||||
default:
|
||||
return "?"
|
||||
}
|
||||
|
@ -151,6 +153,8 @@ func (g ServerGroup) AsRoleAbbreviated() string {
|
|||
return ServerGroupSyncMastersAbbreviatedString
|
||||
case ServerGroupSyncWorkers:
|
||||
return ServerGroupSyncWorkersAbbreviatedString
|
||||
case ServerGroupImageDiscovery:
|
||||
return ServerGroupImageDiscoveryAbbreviatedString
|
||||
default:
|
||||
return "?"
|
||||
}
|
||||
|
@ -227,6 +231,8 @@ func ServerGroupFromAbbreviatedRole(label string) ServerGroup {
|
|||
return ServerGroupSyncMasters
|
||||
case ServerGroupSyncWorkersAbbreviatedString:
|
||||
return ServerGroupSyncWorkers
|
||||
case ServerGroupImageDiscoveryAbbreviatedString:
|
||||
return ServerGroupImageDiscovery
|
||||
default:
|
||||
return ServerGroupUnknown
|
||||
}
|
||||
|
@ -247,6 +253,8 @@ func ServerGroupFromRole(label string) ServerGroup {
|
|||
return ServerGroupSyncMasters
|
||||
case ServerGroupSyncWorkersString:
|
||||
return ServerGroupSyncWorkers
|
||||
case ServerGroupImageDiscoveryString:
|
||||
return ServerGroupImageDiscovery
|
||||
default:
|
||||
return ServerGroupUnknown
|
||||
}
|
||||
|
|
|
@ -86,7 +86,7 @@ const (
|
|||
ServerGroupCoordinatorsString = "coordinator"
|
||||
ServerGroupSyncMastersString = "syncmaster"
|
||||
ServerGroupSyncWorkersString = "syncworker"
|
||||
ServerGroupImageDiscoveryString = "imagediscovery"
|
||||
ServerGroupImageDiscoveryString = "id"
|
||||
|
||||
ServerGroupSingleAbbreviatedString = "sngl"
|
||||
ServerGroupAgentsAbbreviatedString = "agnt"
|
||||
|
@ -131,6 +131,8 @@ func (g ServerGroup) AsRole() string {
|
|||
return ServerGroupSyncMastersString
|
||||
case ServerGroupSyncWorkers:
|
||||
return ServerGroupSyncWorkersString
|
||||
case ServerGroupImageDiscovery:
|
||||
return ServerGroupImageDiscoveryString
|
||||
default:
|
||||
return "?"
|
||||
}
|
||||
|
@ -151,6 +153,8 @@ func (g ServerGroup) AsRoleAbbreviated() string {
|
|||
return ServerGroupSyncMastersAbbreviatedString
|
||||
case ServerGroupSyncWorkers:
|
||||
return ServerGroupSyncWorkersAbbreviatedString
|
||||
case ServerGroupImageDiscovery:
|
||||
return ServerGroupImageDiscoveryAbbreviatedString
|
||||
default:
|
||||
return "?"
|
||||
}
|
||||
|
@ -227,6 +231,8 @@ func ServerGroupFromAbbreviatedRole(label string) ServerGroup {
|
|||
return ServerGroupSyncMasters
|
||||
case ServerGroupSyncWorkersAbbreviatedString:
|
||||
return ServerGroupSyncWorkers
|
||||
case ServerGroupImageDiscoveryAbbreviatedString:
|
||||
return ServerGroupImageDiscovery
|
||||
default:
|
||||
return ServerGroupUnknown
|
||||
}
|
||||
|
@ -247,6 +253,8 @@ func ServerGroupFromRole(label string) ServerGroup {
|
|||
return ServerGroupSyncMasters
|
||||
case ServerGroupSyncWorkersString:
|
||||
return ServerGroupSyncWorkers
|
||||
case ServerGroupImageDiscoveryString:
|
||||
return ServerGroupImageDiscovery
|
||||
default:
|
||||
return ServerGroupUnknown
|
||||
}
|
||||
|
|
|
@ -42,9 +42,6 @@ const (
|
|||
NodeArchAffinityLabel = "kubernetes.io/arch"
|
||||
NodeArchAffinityLabelBeta = "beta.kubernetes.io/arch"
|
||||
|
||||
// Internal constants
|
||||
ImageIDAndVersionRole = "id" // Role use by identification pods
|
||||
|
||||
// Pod constants
|
||||
ServerContainerName = "server"
|
||||
ExporterContainerName = "exporter"
|
||||
|
|
|
@ -131,7 +131,7 @@ func (ib *imagesBuilder) Run(ctx context.Context, cachedStatus inspectorInterfac
|
|||
// When no pod exists, it is created, otherwise the ID is fetched & version detected.
|
||||
// Returns: retrySoon, error
|
||||
func (ib *imagesBuilder) fetchArangoDBImageIDAndVersion(ctx context.Context, cachedStatus inspectorInterface.Inspector, image string) (bool, error) {
|
||||
role := shared.ImageIDAndVersionRole
|
||||
role := api.ServerGroupImageDiscovery.AsRole()
|
||||
id := fmt.Sprintf("%0x", sha1.Sum([]byte(image)))[:6]
|
||||
podName := k8sutil.CreatePodName(ib.APIObject.GetName(), role, id, "")
|
||||
log := ib.Log.
|
||||
|
|
|
@ -58,7 +58,7 @@ func TestEnsureImages(t *testing.T) {
|
|||
// Arange
|
||||
terminationGracePeriodSeconds := int64((time.Second * 30).Seconds())
|
||||
id := fmt.Sprintf("%0x", sha1.Sum([]byte(testNewImage)))[:6]
|
||||
hostname := testDeploymentName + "-" + shared.ImageIDAndVersionRole + "-" + id
|
||||
hostname := testDeploymentName + "-" + api.ServerGroupImageDiscovery.AsRole() + "-" + id
|
||||
|
||||
var securityContext api.ServerGroupSpecSecurityContext
|
||||
|
||||
|
@ -107,7 +107,7 @@ func TestEnsureImages(t *testing.T) {
|
|||
Hostname: hostname,
|
||||
Subdomain: testDeploymentName + "-int",
|
||||
Affinity: k8sutil.CreateAffinity(testDeploymentName,
|
||||
shared.ImageIDAndVersionRole, false, ""),
|
||||
api.ServerGroupImageDiscovery.AsRole(), false, ""),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -170,7 +170,7 @@ func TestEnsureImages(t *testing.T) {
|
|||
Hostname: hostname,
|
||||
Subdomain: testDeploymentName + "-int",
|
||||
Affinity: k8sutil.CreateAffinity(testDeploymentName,
|
||||
shared.ImageIDAndVersionRole, false, ""),
|
||||
api.ServerGroupImageDiscovery.AsRole(), false, ""),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -213,7 +213,7 @@ func TestEnsureImages(t *testing.T) {
|
|||
Hostname: hostname,
|
||||
Subdomain: testDeploymentName + "-int",
|
||||
Affinity: k8sutil.CreateAffinity(testDeploymentName,
|
||||
shared.ImageIDAndVersionRole, false, ""),
|
||||
api.ServerGroupImageDiscovery.AsRole(), false, ""),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -269,7 +269,7 @@ func TestEnsureImages(t *testing.T) {
|
|||
Hostname: hostname,
|
||||
Subdomain: testDeploymentName + "-int",
|
||||
Affinity: k8sutil.CreateAffinity(testDeploymentName,
|
||||
shared.ImageIDAndVersionRole, false, ""),
|
||||
api.ServerGroupImageDiscovery.AsRole(), false, ""),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -283,7 +283,7 @@ func TestEnsureImages(t *testing.T) {
|
|||
Before: func(t *testing.T, deployment *Deployment) {
|
||||
pod := core.Pod{
|
||||
ObjectMeta: meta.ObjectMeta{
|
||||
Name: k8sutil.CreatePodName(testDeploymentName, shared.ImageIDAndVersionRole, id, ""),
|
||||
Name: k8sutil.CreatePodName(testDeploymentName, api.ServerGroupImageDiscovery.AsRole(), id, ""),
|
||||
CreationTimestamp: meta.Now(),
|
||||
},
|
||||
Spec: core.PodSpec{},
|
||||
|
@ -310,7 +310,7 @@ func TestEnsureImages(t *testing.T) {
|
|||
Before: func(t *testing.T, deployment *Deployment) {
|
||||
pod := core.Pod{
|
||||
ObjectMeta: meta.ObjectMeta{
|
||||
Name: k8sutil.CreatePodName(testDeploymentName, shared.ImageIDAndVersionRole, id, ""),
|
||||
Name: k8sutil.CreatePodName(testDeploymentName, api.ServerGroupImageDiscovery.AsRole(), id, ""),
|
||||
},
|
||||
Status: core.PodStatus{
|
||||
Phase: core.PodFailed,
|
||||
|
@ -335,7 +335,7 @@ func TestEnsureImages(t *testing.T) {
|
|||
Before: func(t *testing.T, deployment *Deployment) {
|
||||
pod := core.Pod{
|
||||
ObjectMeta: meta.ObjectMeta{
|
||||
Name: k8sutil.CreatePodName(testDeploymentName, shared.ImageIDAndVersionRole, id, ""),
|
||||
Name: k8sutil.CreatePodName(testDeploymentName, api.ServerGroupImageDiscovery.AsRole(), id, ""),
|
||||
},
|
||||
Status: core.PodStatus{
|
||||
Conditions: []core.PodCondition{
|
||||
|
@ -364,7 +364,7 @@ func TestEnsureImages(t *testing.T) {
|
|||
Before: func(t *testing.T, deployment *Deployment) {
|
||||
pod := core.Pod{
|
||||
ObjectMeta: meta.ObjectMeta{
|
||||
Name: k8sutil.CreatePodName(testDeploymentName, shared.ImageIDAndVersionRole, id, ""),
|
||||
Name: k8sutil.CreatePodName(testDeploymentName, api.ServerGroupImageDiscovery.AsRole(), id, ""),
|
||||
},
|
||||
Status: core.PodStatus{
|
||||
Conditions: []core.PodCondition{
|
||||
|
@ -394,7 +394,7 @@ func TestEnsureImages(t *testing.T) {
|
|||
Before: func(t *testing.T, deployment *Deployment) {
|
||||
pod := core.Pod{
|
||||
ObjectMeta: meta.ObjectMeta{
|
||||
Name: k8sutil.CreatePodName(testDeploymentName, shared.ImageIDAndVersionRole, id, ""),
|
||||
Name: k8sutil.CreatePodName(testDeploymentName, api.ServerGroupImageDiscovery.AsRole(), id, ""),
|
||||
},
|
||||
Status: core.PodStatus{
|
||||
Conditions: []core.PodCondition{
|
||||
|
|
|
@ -33,6 +33,7 @@ import (
|
|||
"github.com/arangodb/kube-arangodb/pkg/util/errors"
|
||||
"github.com/arangodb/kube-arangodb/pkg/util/globals"
|
||||
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
|
||||
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/info"
|
||||
podv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/pod/v1"
|
||||
)
|
||||
|
||||
|
@ -51,7 +52,7 @@ func (r *Resources) CleanupTerminatedPods(ctx context.Context) (util.Interval, e
|
|||
status := r.context.GetStatus()
|
||||
if err := r.context.ACS().ForEachHealthyCluster(func(item sutil.ACSItem) error {
|
||||
return item.Cache().Pod().V1().Iterate(func(pod *core.Pod) error {
|
||||
if k8sutil.IsArangoDBImageIDAndVersionPod(pod) {
|
||||
if info.GetPodServerGroup(pod) == api.ServerGroupImageDiscovery {
|
||||
// Image ID pods are not relevant to inspect here
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@ import (
|
|||
"github.com/arangodb/kube-arangodb/pkg/util"
|
||||
"github.com/arangodb/kube-arangodb/pkg/util/errors"
|
||||
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
|
||||
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/info"
|
||||
inspectorInterface "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector"
|
||||
podv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/pod/v1"
|
||||
)
|
||||
|
@ -97,7 +98,7 @@ func (r *Resources) InspectPods(ctx context.Context, cachedStatus inspectorInter
|
|||
var unscheduledPodNames []string
|
||||
|
||||
err := cachedStatus.Pod().V1().Iterate(func(pod *core.Pod) error {
|
||||
if k8sutil.IsArangoDBImageIDAndVersionPod(pod) {
|
||||
if info.GetPodServerGroup(pod) == api.ServerGroupImageDiscovery {
|
||||
// Image ID pods are not relevant to inspect here
|
||||
return nil
|
||||
}
|
||||
|
|
33
pkg/util/k8sutil/info/pods.go
Normal file
33
pkg/util/k8sutil/info/pods.go
Normal file
|
@ -0,0 +1,33 @@
|
|||
//
|
||||
// DISCLAIMER
|
||||
//
|
||||
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
// Copyright holder is ArangoDB GmbH, Cologne, Germany
|
||||
//
|
||||
|
||||
package info
|
||||
|
||||
import (
|
||||
core "k8s.io/api/core/v1"
|
||||
|
||||
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
|
||||
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
|
||||
)
|
||||
|
||||
// GetPodServerGroup returns ServerGroup based on Pod label
|
||||
func GetPodServerGroup(p *core.Pod) api.ServerGroup {
|
||||
return api.ServerGroupFromRole(p.GetLabels()[k8sutil.LabelKeyRole])
|
||||
}
|
|
@ -296,12 +296,6 @@ func IsPodTerminating(pod *core.Pod) bool {
|
|||
return IsPodMarkedForDeletion(pod) && pod.Status.Phase == core.PodRunning
|
||||
}
|
||||
|
||||
// IsArangoDBImageIDAndVersionPod returns true if the given pod is used for fetching image ID and ArangoDB version of an image
|
||||
func IsArangoDBImageIDAndVersionPod(p *core.Pod) bool {
|
||||
role, found := p.GetLabels()[LabelKeyRole]
|
||||
return found && role == shared.ImageIDAndVersionRole
|
||||
}
|
||||
|
||||
// getPodCondition returns the condition of given type in the given status.
|
||||
// If not found, nil is returned.
|
||||
func getPodCondition(status *core.PodStatus, condType core.PodConditionType) *core.PodCondition {
|
||||
|
|
Loading…
Reference in a new issue