Skip to content

Commit 5407033

Browse files
authored
[Feature] Active Member condition (#1123)
1 parent 8bfabc0 commit 5407033

File tree

8 files changed

+50
-1
lines changed

8 files changed

+50
-1
lines changed

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) Define Actions PlaceHolder
55
- (Feature) Add Member Update helpers
6+
- (Feature) Active Member condition
67

78
## [1.2.17](https://github.com/arangodb/kube-arangodb/tree/1.2.17) (2022-09-22)
89
- (Feature) Add new field to DeploymentReplicationStatus with details on DC2DC sync status=

pkg/apis/deployment/v1/conditions.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ const (
4343
ConditionTypeReachable ConditionType = "Reachable"
4444
// ConditionTypeServing indicates that the member core services are running.
4545
ConditionTypeServing ConditionType = "Serving"
46+
// ConditionTypeActive indicates that the member server container started.
47+
ConditionTypeActive ConditionType = "Active"
4648
// ConditionTypeTerminated indicates that the member has terminated and will not restart.
4749
ConditionTypeTerminated ConditionType = "Terminated"
4850
// ConditionTypeAutoUpgrade indicates that the member has to be started with `--database.auto-upgrade` once.

pkg/apis/deployment/v2alpha1/conditions.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ const (
4343
ConditionTypeReachable ConditionType = "Reachable"
4444
// ConditionTypeServing indicates that the member core services are running.
4545
ConditionTypeServing ConditionType = "Serving"
46+
// ConditionTypeActive indicates that the member server container started.
47+
ConditionTypeActive ConditionType = "Active"
4648
// ConditionTypeTerminated indicates that the member has terminated and will not restart.
4749
ConditionTypeTerminated ConditionType = "Terminated"
4850
// ConditionTypeAutoUpgrade indicates that the member has to be started with `--database.auto-upgrade` once.

pkg/deployment/member/phase_updates.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ var phase = phaseMap{
8282
func removeMemberConditionsMapFunc(m *api.MemberStatus) {
8383
// Clean conditions
8484
m.Conditions.Remove(api.ConditionTypeReady)
85+
m.Conditions.Remove(api.ConditionTypeActive)
8586
m.Conditions.Remove(api.ConditionTypeStarted)
8687
m.Conditions.Remove(api.ConditionTypeReachable)
8788
m.Conditions.Remove(api.ConditionTypeServing)

pkg/deployment/resources/pod_inspector.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
3131

3232
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
33+
"github.com/arangodb/kube-arangodb/pkg/apis/shared"
3334
"github.com/arangodb/kube-arangodb/pkg/deployment/agency"
3435
"github.com/arangodb/kube-arangodb/pkg/deployment/patch"
3536
"github.com/arangodb/kube-arangodb/pkg/metrics"
@@ -288,6 +289,23 @@ func (r *Resources) InspectPods(ctx context.Context, cachedStatus inspectorInter
288289
}
289290
}
290291

292+
if k8sutil.IsContainerStarted(pod, shared.ServerContainerName) {
293+
if memberStatus.Conditions.Update(api.ConditionTypeActive, true, "Core Pod Container started", "") {
294+
updateMemberStatusNeeded = true
295+
nextInterval = nextInterval.ReduceTo(recheckSoonPodInspectorInterval)
296+
}
297+
}
298+
299+
if memberStatus.Conditions.IsTrue(api.ConditionTypeActive) {
300+
if v, ok := pod.Labels[k8sutil.LabelKeyArangoActive]; !ok || v != k8sutil.LabelValueArangoActive {
301+
pod.Labels[k8sutil.LabelKeyArangoActive] = k8sutil.LabelValueArangoActive
302+
if err := r.context.ApplyPatchOnPod(ctx, pod, patch.ItemReplace(patch.NewPath("metadata", "labels"), pod.Labels)); err != nil {
303+
log.Str("pod-name", pod.GetName()).Err(err).Error("Unable to update labels")
304+
}
305+
}
306+
307+
}
308+
291309
if k8sutil.IsPodReady(pod) && k8sutil.AreContainersReady(pod, coreContainers) {
292310
// Pod is now ready
293311
if anyOf(memberStatus.Conditions.Update(api.ConditionTypeReady, true, "Pod Ready", ""),

pkg/deployment/resources/services.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func (r *Resources) EnsureServices(ctx context.Context, cachedStatus inspectorIn
129129
}
130130

131131
ports := CreateServerServicePortsWithSidecars(podInspector, e.Member.PodName, e.Group)
132-
selector := k8sutil.LabelsForMember(deploymentName, e.Group.AsRole(), e.Member.ID)
132+
selector := k8sutil.LabelsForActiveMember(deploymentName, e.Group.AsRole(), e.Member.ID)
133133
if s, ok := cachedStatus.Service().V1().GetSimple(member.GetName()); !ok {
134134
s := r.createService(member.GetName(), member.GetNamespace(), member.AsOwner(), ports, selector)
135135

pkg/util/k8sutil/pods.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,18 @@ func IsPodReady(pod *core.Pod) bool {
7777
return condition != nil && condition.Status == core.ConditionTrue
7878
}
7979

80+
func IsContainerStarted(pod *core.Pod, container string) bool {
81+
for _, c := range pod.Status.ContainerStatuses {
82+
if c.Name != container {
83+
continue
84+
}
85+
86+
return c.State.Terminated != nil || c.State.Running != nil
87+
}
88+
89+
return false
90+
}
91+
8092
// AreContainersReady checks whether Pod is considered as ready.
8193
// Returns true if the PodReady condition on the given pod is set to true,
8294
// or all provided containers' names are running and are not in the list of failed containers.

pkg/util/k8sutil/util.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ const (
4646
LabelKeyArangoTopology = "deployment.arangodb.com/topology"
4747
// LabelKeyArangoLeader is the key of the label used to store the current leader of a group instances.
4848
LabelKeyArangoLeader = "deployment.arangodb.com/leader"
49+
// LabelKeyArangoActive is the key of the label used to mark members as active.
50+
LabelKeyArangoActive = "deployment.arangodb.com/active"
51+
// LabelValueArangoActive is the value of the label used to mark members as active.
52+
LabelValueArangoActive = "true"
4953
// AppName is the fixed value for the "app" label
5054
AppName = "arangodb"
5155
)
@@ -133,6 +137,15 @@ func LabelsForMember(deploymentName, role, id string) map[string]string {
133137
return l
134138
}
135139

140+
// LabelsForActiveMember returns a map of labels, given to active members for given deployment name and member id
141+
func LabelsForActiveMember(deploymentName, role, id string) map[string]string {
142+
l := LabelsForMember(deploymentName, role, id)
143+
144+
l[LabelKeyArangoActive] = LabelValueArangoActive
145+
146+
return l
147+
}
148+
136149
// LabelsForLeaderMember returns a map of labels for given deployment name and member id and role and leadership.
137150
func LabelsForLeaderMember(deploymentName, role, id string) map[string]string {
138151
l := LabelsForMember(deploymentName, role, id)

0 commit comments

Comments
 (0)