1
0
Fork 0
mirror of https://github.com/arangodb/kube-arangodb.git synced 2024-12-14 11:57:37 +00:00

[Feature] Active Member condition (#1123)

This commit is contained in:
Adam Janikowski 2022-09-26 11:31:29 +02:00 committed by GitHub
parent 8bfabc032a
commit 5407033cfd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 50 additions and 1 deletions

View file

@ -3,6 +3,7 @@
## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A)
- (Feature) Define Actions PlaceHolder
- (Feature) Add Member Update helpers
- (Feature) Active Member condition
## [1.2.17](https://github.com/arangodb/kube-arangodb/tree/1.2.17) (2022-09-22)
- (Feature) Add new field to DeploymentReplicationStatus with details on DC2DC sync status=

View file

@ -43,6 +43,8 @@ const (
ConditionTypeReachable ConditionType = "Reachable"
// ConditionTypeServing indicates that the member core services are running.
ConditionTypeServing ConditionType = "Serving"
// ConditionTypeActive indicates that the member server container started.
ConditionTypeActive ConditionType = "Active"
// ConditionTypeTerminated indicates that the member has terminated and will not restart.
ConditionTypeTerminated ConditionType = "Terminated"
// ConditionTypeAutoUpgrade indicates that the member has to be started with `--database.auto-upgrade` once.

View file

@ -43,6 +43,8 @@ const (
ConditionTypeReachable ConditionType = "Reachable"
// ConditionTypeServing indicates that the member core services are running.
ConditionTypeServing ConditionType = "Serving"
// ConditionTypeActive indicates that the member server container started.
ConditionTypeActive ConditionType = "Active"
// ConditionTypeTerminated indicates that the member has terminated and will not restart.
ConditionTypeTerminated ConditionType = "Terminated"
// ConditionTypeAutoUpgrade indicates that the member has to be started with `--database.auto-upgrade` once.

View file

@ -82,6 +82,7 @@ var phase = phaseMap{
func removeMemberConditionsMapFunc(m *api.MemberStatus) {
// Clean conditions
m.Conditions.Remove(api.ConditionTypeReady)
m.Conditions.Remove(api.ConditionTypeActive)
m.Conditions.Remove(api.ConditionTypeStarted)
m.Conditions.Remove(api.ConditionTypeReachable)
m.Conditions.Remove(api.ConditionTypeServing)

View file

@ -30,6 +30,7 @@ import (
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
"github.com/arangodb/kube-arangodb/pkg/apis/shared"
"github.com/arangodb/kube-arangodb/pkg/deployment/agency"
"github.com/arangodb/kube-arangodb/pkg/deployment/patch"
"github.com/arangodb/kube-arangodb/pkg/metrics"
@ -288,6 +289,23 @@ func (r *Resources) InspectPods(ctx context.Context, cachedStatus inspectorInter
}
}
if k8sutil.IsContainerStarted(pod, shared.ServerContainerName) {
if memberStatus.Conditions.Update(api.ConditionTypeActive, true, "Core Pod Container started", "") {
updateMemberStatusNeeded = true
nextInterval = nextInterval.ReduceTo(recheckSoonPodInspectorInterval)
}
}
if memberStatus.Conditions.IsTrue(api.ConditionTypeActive) {
if v, ok := pod.Labels[k8sutil.LabelKeyArangoActive]; !ok || v != k8sutil.LabelValueArangoActive {
pod.Labels[k8sutil.LabelKeyArangoActive] = k8sutil.LabelValueArangoActive
if err := r.context.ApplyPatchOnPod(ctx, pod, patch.ItemReplace(patch.NewPath("metadata", "labels"), pod.Labels)); err != nil {
log.Str("pod-name", pod.GetName()).Err(err).Error("Unable to update labels")
}
}
}
if k8sutil.IsPodReady(pod) && k8sutil.AreContainersReady(pod, coreContainers) {
// Pod is now ready
if anyOf(memberStatus.Conditions.Update(api.ConditionTypeReady, true, "Pod Ready", ""),

View file

@ -129,7 +129,7 @@ func (r *Resources) EnsureServices(ctx context.Context, cachedStatus inspectorIn
}
ports := CreateServerServicePortsWithSidecars(podInspector, e.Member.PodName, e.Group)
selector := k8sutil.LabelsForMember(deploymentName, e.Group.AsRole(), e.Member.ID)
selector := k8sutil.LabelsForActiveMember(deploymentName, e.Group.AsRole(), e.Member.ID)
if s, ok := cachedStatus.Service().V1().GetSimple(member.GetName()); !ok {
s := r.createService(member.GetName(), member.GetNamespace(), member.AsOwner(), ports, selector)

View file

@ -77,6 +77,18 @@ func IsPodReady(pod *core.Pod) bool {
return condition != nil && condition.Status == core.ConditionTrue
}
func IsContainerStarted(pod *core.Pod, container string) bool {
for _, c := range pod.Status.ContainerStatuses {
if c.Name != container {
continue
}
return c.State.Terminated != nil || c.State.Running != nil
}
return false
}
// AreContainersReady checks whether Pod is considered as ready.
// Returns true if the PodReady condition on the given pod is set to true,
// or all provided containers' names are running and are not in the list of failed containers.

View file

@ -46,6 +46,10 @@ const (
LabelKeyArangoTopology = "deployment.arangodb.com/topology"
// LabelKeyArangoLeader is the key of the label used to store the current leader of a group instances.
LabelKeyArangoLeader = "deployment.arangodb.com/leader"
// LabelKeyArangoActive is the key of the label used to mark members as active.
LabelKeyArangoActive = "deployment.arangodb.com/active"
// LabelValueArangoActive is the value of the label used to mark members as active.
LabelValueArangoActive = "true"
// AppName is the fixed value for the "app" label
AppName = "arangodb"
)
@ -133,6 +137,15 @@ func LabelsForMember(deploymentName, role, id string) map[string]string {
return l
}
// LabelsForActiveMember returns a map of labels, given to active members for given deployment name and member id
func LabelsForActiveMember(deploymentName, role, id string) map[string]string {
l := LabelsForMember(deploymentName, role, id)
l[LabelKeyArangoActive] = LabelValueArangoActive
return l
}
// LabelsForLeaderMember returns a map of labels for given deployment name and member id and role and leadership.
func LabelsForLeaderMember(deploymentName, role, id string) map[string]string {
l := LabelsForMember(deploymentName, role, id)