8000 [Feature] Add ScheduleSpecChanged Condition (#1645) · arangodb/kube-arangodb@3892fe4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3892fe4

Browse files
authored
[Feature] Add ScheduleSpecChanged Condition (#1645)
1 parent b4f6166 commit 3892fe4

File tree

8 files changed

+76
-27
lines changed

8 files changed

+76
-27
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
- (Feature) Parametrize Scheduling Graceful Duration
2424
- (Bugfix) Change Accepted Spec Propagation
2525
- (Bugfix) Pass SecurityContext Pod Settings for SELinux and Seccomp
26+
- (Feature) Add ScheduleSpecChanged Condition
2627

2728
## [1.2.39](https://github.com/arangodb/kube-arangodb/tree/1.2.39) (2024-03-11)
2829
- (Feature) Extract Scheduler API

pkg/apis/deployment/v1/conditions.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copy 8000 right 2023 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2023-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.
@@ -43,6 +43,8 @@ const (
4343
ConditionTypeReachable ConditionType = "Reachable"
4444
// ConditionTypeScheduled indicates that the member primary pod is scheduled.
4545
ConditionTypeScheduled ConditionType = "Scheduled"
46+
// ConditionTypeScheduleSpecChanged indicates that the member schedule spec was changed.
47+
ConditionTypeScheduleSpecChanged ConditionType = "ScheduleSpecChanged"
4648
// ConditionTypeServing indicates that the member core services are running.
4749
ConditionTypeServing ConditionType = "Serving"
4850
// ConditionTypeActive indicates that the member server container started.

pkg/apis/deployment/v2alpha1/conditions.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2023-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.
@@ -43,6 +43,8 @@ const (
4343
ConditionTypeReachable ConditionType = "Reachable"
4444
// ConditionTypeScheduled indicates that the member primary pod is scheduled.
4545
ConditionTypeScheduled ConditionType = "Scheduled"
46+
// ConditionTypeScheduleSpecChanged indicates that the member schedule spec was changed.
47+
ConditionTypeScheduleSpecChanged ConditionType = "ScheduleSpecChanged"
4648
// ConditionTypeServing indicates that the member core services are running.
4749
ConditionTypeServing ConditionType = "Serving"
4850
// ConditionTypeActive indicates that the member server container started.

pkg/deployment/member/phase_updates.go

Lines changed: 2 additions & 1 deletion
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.
@@ -85,6 +85,7 @@ func removeMemberConditionsMapFunc(m *api.MemberStatus) {
8585
m.Conditions.Remove(api.ConditionTypeActive)
8686
m.Conditions.Remove(api.ConditionTypeStarted)
8787
m.Conditions.Remove(api.ConditionTypeScheduled)
88+
m.Conditions.Remove(api.ConditionTypeScheduleSpecChanged)
8889
m.Conditions.Remove(api.ConditionTypeReachable)
8990
m.Conditions.Remove(api.ConditionTypeServing)
9091
m.Conditions.Remove(api.ConditionTypeTerminated)

pkg/deployment/reconcile/plan_builder_member_pod_scheduling_failure.go

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@ func (r *Reconciler) createMemberPodSchedulingFailurePlan(ctx context.Context,
5050
return p
5151
}
5252

53+
q := r.log.Str("step", "CreateMemberPodSchedulingFailurePlan")
54+
5355
for _, m := range status.Members.AsList() {
54-
l := r.log.Str("id", m.Member.ID).Str("role", m.Group.AsRole())
56+
l := q.Str("id", m.Member.ID).Str("role", m.Group.AsRole())
5557

5658
if m.Member.Phase != api.MemberPhaseCreated || m.Member.Pod.GetName() == "" {
5759
// Act only when phase is created
@@ -65,48 +67,54 @@ func (r *Reconciler) createMemberPodSchedulingFailurePlan(ctx context.Context,
6567

6668
if c, ok := m.Member.Conditions.Get(api.ConditionTypeScheduled); !ok {
6769
// Action cant proceed if pod is not scheduled
70+
l.Debug("Unable to find scheduled condition")
6871
continue
6972
} else if c.LastTransitionTime.IsZero() {
7073
// LastTransitionTime is not set
74+
l.Debug("Scheduled condition LastTransitionTime is zero")
7175
continue
7276
} else {
73-
if time.Since(c.LastTransitionTime.Time) <= globals.GetGlobalTimeouts().PodSchedulingGracePeriod().Get() {
77+
if d := time.Since(c.LastTransitionTime.Time); d <= globals.GetGlobalTimeouts().PodSchedulingGracePeriod().Get() {
7478
// In grace period
79+
l.Dur("since", d).Debug("Still in grace period")
7580
continue
7681
}
7782
}
7883

79-
imageInfo, imageFound := context.SelectImageForMember(spec, status, m.Member)
80-
if !imageFound {
81-
l.Warn("could not find image for already created member")
82-
continue
83-
}
84-
85-
renderedPod, err := context.RenderPodForMember(ctx, context.ACS(), spec, status, m.Member.ID, imageInfo)
86-
if err != nil {
87-
l.Err(err).Warn("could not render pod for already created member")
88-
continue
89-
}
90-
9184
cache, ok := context.ACS().ClusterCache(m.Member.ClusterID)
9285
if !ok {
86+
l.Warn("Unable to get member name")
9387
continue
9488
}
9589

9690
memberName := m.Member.ArangoMemberName(context.GetName(), m.Group)
9791
member, ok := cache.ArangoMember().V1().GetSimple(memberName)
9892
if !ok {
93+
l.Warn("Unable to get ArangoMember")
9994
continue
10095
}
10196

102-
if template := member.Spec.Template; template != nil {
103-
if pod := template.PodSpec; pod != nil {
104-
if !r.schedulingParametersAreTheSame(renderedPod.Spec, pod.Spec) {
105-
l.Info("Adding KillMemberPod action: scheduling failed and parameters already updated")
106-
p = append(p,
107-
actions.NewAction(api.ActionTypeKillMemberPod, m.Group, m.Member, "Scheduling failed"),
108-
)
97+
if m.Member.Conditions.IsTrue(api.ConditionTypeScheduleSpecChanged) {
98+
l.Info("Adding KillMemberPod action: scheduling failed and scheduling changed condition is present")
99+
p = append(p,
100+
actions.NewAction(api.ActionTypeKillMemberPod, m.Group, m.Member, "Scheduling failed"),
101+
)
102+
} else {
103+
if statusTemplate, specTemplate := member.Status.Template, member.Spec.Template; statusTemplate != nil && specTemplate != nil {
104+
if statusTemplateSpec, specTemplateSpec := statusTemplate.PodSpec, specTemplate.PodSpec; statusTemplateSpec != nil && specTemplateSpec != nil {
105+
if !r.schedulingParametersAreTheSame(specTemplateSpec.Spec, statusTemplateSpec.Spec) {
106+
l.Info("Adding KillMemberPod action: scheduling failed and parameters already updated")
107+
p = append(p,
108+
actions.NewAction(api.ActionTypeKillMemberPod, m.Group, m.Member, "Scheduling failed"),
109+
)
110+
} else {
111+
l.Info("Scheduling parameters are not updated")
112+
}
113+
} else {
114+
l.Warn("Pod TemplateSpec is nil")
109115
}
116+
} else {
117+
l.Warn("Pod Template is nil")
110118
}
111119
}
112120
}

pkg/deployment/rotation/arangod.go

Lines changed: 2 additions & 1 deletion
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.
@@ -54,6 +54,7 @@ func affinityCompare(_ api.DeploymentSpec, _ api.ServerGroup, spec, status *core
5454
e = err
5555
return
5656
} else if specC != statusC {
57+
plan = append(plan, SchedulingChangeAction(builder))
5758
mode = mode.And(compare.SilentRotation)
5859
status.Spec.Affinity = spec.Spec.Affinity.DeepCopy()
5960
return

pkg/deployment/rotation/arangod_tolerations.go

Lines changed: 6 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.
@@ -32,7 +32,10 @@ import (
3232
func comparePodTolerations(_ api.DeploymentSpec, _ api.ServerGroup, spec, status *core.PodTemplateSpec) compare.Func {
3333
return func(builder api.ActionBuilder) (mode compare.Mode, plan api.Plan, err error) {
3434
if !reflect.DeepEqual(spec.Spec.Tolerations, status.Spec.Tolerations) {
35-
plan = append(plan, builder.NewAction(api.ActionTypeRuntimeContainerSyncTolerations))
35+
plan = append(plan,
36+
SchedulingChangeAction(builder),
37+
builder.NewAction(api.ActionTypeRuntimeContainerSyncTolerations),
38+
)
3639

3740
status.Spec.Tolerations = spec.Spec.Tolerations
3841
mode = mode.And(compare.InPlaceRotation)
@@ -42,4 +45,5 @@ func comparePodTolerations(_ api.DeploymentSpec, _ api.ServerGroup, spec, status
4245

4346
return
4447
}
48+
4549
}

pkg/deployment/rotation/helper.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2024 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 rotation
22+
23+
import (
24+
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
25+
sharedReconcile "github.com/arangodb/kube-arangodb/pkg/deployment/reconcile/shared"
26+
)
27+
28+
func SchedulingChangeAction(builder api.ActionBuilder) api.Action {
29+
return sharedReconcile.UpdateMemberConditionActionV2("Scheduling Changed", api.ConditionTypeScheduleSpecChanged, builder.Group(), builder.MemberID(), true, "Scheduling Changed", "", "")
30+
}

0 commit comments

Comments
 (0)
0