Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Add ScheduleSpecChanged Condition #1645

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
- (Feature) Parametrize Scheduling Graceful Duration
- (Bugfix) Change Accepted Spec Propagation
- (Bugfix) Pass SecurityContext Pod Settings for SELinux and Seccomp
- (Feature) Add ScheduleSpecChanged Condition

## [1.2.39](https://github.com/arangodb/kube-arangodb/tree/1.2.39) (2024-03-11)
- (Feature) Extract Scheduler API
Expand Down
4 changes: 3 additions & 1 deletion pkg/apis/deployment/v1/conditions.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
// Copyright 2023-2024 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.
Expand Down Expand Up @@ -43,6 +43,8 @@ const (
ConditionTypeReachable ConditionType = "Reachable"
// ConditionTypeScheduled indicates that the member primary pod is scheduled.
ConditionTypeScheduled ConditionType = "Scheduled"
// ConditionTypeScheduleSpecChanged indicates that the member schedule spec was changed.
ConditionTypeScheduleSpecChanged ConditionType = "ScheduleSpecChanged"
// ConditionTypeServing indicates that the member core services are running.
ConditionTypeServing ConditionType = "Serving"
// ConditionTypeActive indicates that the member server container started.
Expand Down
4 changes: 3 additions & 1 deletion pkg/apis/deployment/v2alpha1/conditions.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
// Copyright 2023-2024 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.
Expand Down Expand Up @@ -43,6 +43,8 @@ const (
ConditionTypeReachable ConditionType = "Reachable"
// ConditionTypeScheduled indicates that the member primary pod is scheduled.
ConditionTypeScheduled ConditionType = "Scheduled"
// ConditionTypeScheduleSpecChanged indicates that the member schedule spec was changed.
ConditionTypeScheduleSpecChanged ConditionType = "ScheduleSpecChanged"
// ConditionTypeServing indicates that the member core services are running.
ConditionTypeServing ConditionType = "Serving"
// ConditionTypeActive indicates that the member server container started.
Expand Down
3 changes: 2 additions & 1 deletion pkg/deployment/member/phase_updates.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
// Copyright 2016-2024 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.
Expand Down Expand Up @@ -85,6 +85,7 @@ func removeMemberConditionsMapFunc(m *api.MemberStatus) {
m.Conditions.Remove(api.ConditionTypeActive)
m.Conditions.Remove(api.ConditionTypeStarted)
m.Conditions.Remove(api.ConditionTypeScheduled)
m.Conditions.Remove(api.ConditionTypeScheduleSpecChanged)
m.Conditions.Remove(api.ConditionTypeReachable)
m.Conditions.Remove(api.ConditionTypeServing)
m.Conditions.Remove(api.ConditionTypeTerminated)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ func (r *Reconciler) createMemberPodSchedulingFailurePlan(ctx context.Context,
return p
}

q := r.log.Str("step", "CreateMemberPodSchedulingFailurePlan")

for _, m := range status.Members.AsList() {
l := r.log.Str("id", m.Member.ID).Str("role", m.Group.AsRole())
l := q.Str("id", m.Member.ID).Str("role", m.Group.AsRole())

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

if c, ok := m.Member.Conditions.Get(api.ConditionTypeScheduled); !ok {
// Action cant proceed if pod is not scheduled
l.Debug("Unable to find scheduled condition")
continue
} else if c.LastTransitionTime.IsZero() {
// LastTransitionTime is not set
l.Debug("Scheduled condition LastTransitionTime is zero")
continue
} else {
if time.Since(c.LastTransitionTime.Time) <= globals.GetGlobalTimeouts().PodSchedulingGracePeriod().Get() {
if d := time.Since(c.LastTransitionTime.Time); d <= globals.GetGlobalTimeouts().PodSchedulingGracePeriod().Get() {
// In grace period
l.Dur("since", d).Debug("Still in grace period")
continue
}
}

imageInfo, imageFound := context.SelectImageForMember(spec, status, m.Member)
if !imageFound {
l.Warn("could not find image for already created member")
continue
}

renderedPod, err := context.RenderPodForMember(ctx, context.ACS(), spec, status, m.Member.ID, imageInfo)
if err != nil {
l.Err(err).Warn("could not render pod for already created member")
continue
}

cache, ok := context.ACS().ClusterCache(m.Member.ClusterID)
if !ok {
l.Warn("Unable to get member name")
continue
}

memberName := m.Member.ArangoMemberName(context.GetName(), m.Group)
member, ok := cache.ArangoMember().V1().GetSimple(memberName)
if !ok {
l.Warn("Unable to get ArangoMember")
continue
}

if template := member.Spec.Template; template != nil {
if pod := template.PodSpec; pod != nil {
if !r.schedulingParametersAreTheSame(renderedPod.Spec, pod.Spec) {
l.Info("Adding KillMemberPod action: scheduling failed and parameters already updated")
p = append(p,
actions.NewAction(api.ActionTypeKillMemberPod, m.Group, m.Member, "Scheduling failed"),
)
if m.Member.Conditions.IsTrue(api.ConditionTypeScheduleSpecChanged) {
l.Info("Adding KillMemberPod action: scheduling failed and scheduling changed condition is present")
p = append(p,
actions.NewAction(api.ActionTypeKillMemberPod, m.Group, m.Member, "Scheduling failed"),
)
} else {
if statusTemplate, specTemplate := member.Status.Template, member.Spec.Template; statusTemplate != nil && specTemplate != nil {
if statusTemplateSpec, specTemplateSpec := statusTemplate.PodSpec, specTemplate.PodSpec; statusTemplateSpec != nil && specTemplateSpec != nil {
if !r.schedulingParametersAreTheSame(specTemplateSpec.Spec, statusTemplateSpec.Spec) {
l.Info("Adding KillMemberPod action: scheduling failed and parameters already updated")
p = append(p,
actions.NewAction(api.ActionTypeKillMemberPod, m.Group, m.Member, "Scheduling failed"),
)
} else {
l.Info("Scheduling parameters are not updated")
}
} else {
l.Warn("Pod TemplateSpec is nil")
}
} else {
l.Warn("Pod Template is nil")
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/deployment/rotation/arangod.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
// Copyright 2016-2024 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.
Expand Down Expand Up @@ -54,6 +54,7 @@ func affinityCompare(_ api.DeploymentSpec, _ api.ServerGroup, spec, status *core
e = err
return
} else if specC != statusC {
plan = append(plan, SchedulingChangeAction(builder))
mode = mode.And(compare.SilentRotation)
status.Spec.Affinity = spec.Spec.Affinity.DeepCopy()
return
Expand Down
8 changes: 6 additions & 2 deletions pkg/deployment/rotation/arangod_tolerations.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
// Copyright 2016-2024 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.
Expand Down Expand Up @@ -32,7 +32,10 @@ import (
func comparePodTolerations(_ api.DeploymentSpec, _ api.ServerGroup, spec, status *core.PodTemplateSpec) compare.Func {
return func(builder api.ActionBuilder) (mode compare.Mode, plan api.Plan, err error) {
if !reflect.DeepEqual(spec.Spec.Tolerations, status.Spec.Tolerations) {
plan = append(plan, builder.NewAction(api.ActionTypeRuntimeContainerSyncTolerations))
plan = append(plan,
SchedulingChangeAction(builder),
builder.NewAction(api.ActionTypeRuntimeContainerSyncTolerations),
)

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

return
}

}
30 changes: 30 additions & 0 deletions pkg/deployment/rotation/helper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// DISCLAIMER
//
// Copyright 2024 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 rotation

import (
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
sharedReconcile "github.com/arangodb/kube-arangodb/pkg/deployment/reconcile/shared"
)

func SchedulingChangeAction(builder api.ActionBuilder) api.Action {
return sharedReconcile.UpdateMemberConditionActionV2("Scheduling Changed", api.ConditionTypeScheduleSpecChanged, builder.Group(), builder.MemberID(), true, "Scheduling Changed", "", "")
}