-
Notifications
You must be signed in to change notification settings - Fork 73
[Feature] OptionalReplace Upgrade Mode #1939
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -287,6 +287,11 @@ func (r *Reconciler) createUpgradePlanInternal(apiObject k8sutil.APIObject, spec | |||||||||||
return nil, false | ||||||||||||
} | ||||||||||||
|
||||||||||||
if m.Member.Conditions.IsTrue(api.ConditionTypeMarkedToRemove) { | ||||||||||||
// Server is supposed to be removed, lets not continue | ||||||||||||
return nil, false | ||||||||||||
} | ||||||||||||
|
||||||||||||
if decision.AreGroupsPendingUpgrade(upgradeOrder[:id]...) { | ||||||||||||
// Not all members before were upgraded | ||||||||||||
return nil, false | ||||||||||||
|
@@ -313,20 +318,19 @@ func (r *Reconciler) createUpgradePlanInternal(apiObject k8sutil.APIObject, spec | |||||||||||
switch group { | ||||||||||||
case api.ServerGroupDBServers: | ||||||||||||
// Members are supposed to be replaced | ||||||||||||
if !m.Member.Conditions.IsTrue(api.ConditionTypeMarkedToRemove) { | ||||||||||||
return api.Plan{actions.NewAction(api.ActionTypeMarkToRemoveMember, m.Group, m.Member, "Replace by Upgrade")}, false | ||||||||||||
} | ||||||||||||
return nil, false | ||||||||||||
return api.Plan{actions.NewAction(api.ActionTypeMarkToRemoveMember, m.Group, m.Member, "Replace by Upgrade")}, false | ||||||||||||
} | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This closing brace appears to be orphaned after the removal of the condition check and return statement on the previous lines, which could cause compilation errors.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||
} | ||||||||||||
|
||||||||||||
compact := um.Get() == api.ServerGroupUpgradeModeOptionalReplace | ||||||||||||
|
||||||||||||
if d.updateAllowed { | ||||||||||||
// We are fine, group is alive so we can proceed | ||||||||||||
r.planLogger.Str("member", m.Member.ID).Str("Reason", d.updateMessage).Info("Upgrade allowed") | ||||||||||||
return r.createUpgradeMemberPlan(m.Member, m.Group, "Version upgrade", spec, status, !d.upgradeDecision.AutoUpgradeNeeded, agencyCache), false | ||||||||||||
return r.createUpgradeMemberPlan(m.Member, m.Group, "Version upgrade", spec, status, !d.upgradeDecision.AutoUpgradeNeeded, compact, agencyCache), false | ||||||||||||
} else if d.unsafeUpdateAllowed { | ||||||||||||
r.planLogger.Str("member", m.Member.ID).Str("Reason", d.updateMessage).Info("Pod needs upgrade but cluster is not ready. Either some shards are not in sync or some member is not ready, but unsafe upgrade is allowed") | ||||||||||||
return r.createUpgradeMemberPlan(m.Member, m.Group, "Version upgrade", spec, status, !d.upgradeDecision.AutoUpgradeNeeded, agencyCache), false | ||||||||||||
return r.createUpgradeMemberPlan(m.Member, m.Group, "Version upgrade", spec, status, !d.upgradeDecision.AutoUpgradeNeeded, compact, agencyCache), false | ||||||||||||
} else { | ||||||||||||
r.planLogger.Str("member", m.Member.ID).Str("Reason", d.updateMessage).Info("Pod needs upgrade but cluster is not ready. Either some shards are not in sync or some member is not ready.") | ||||||||||||
return nil, true | ||||||||||||
|
@@ -596,7 +600,7 @@ func (r *Reconciler) createMemberAllowUpgradeConditionPlan(ctx context.Context, | |||||||||||
// createUpgradeMemberPlan creates a plan to upgrade (stop-recreateWithAutoUpgrade-stop-start) an existing | ||||||||||||
// member. | ||||||||||||
func (r *Reconciler) createUpgradeMemberPlan(member api.MemberStatus, | ||||||||||||
group api.ServerGroup, reason string, spec api.DeploymentSpec, status api.DeploymentStatus, rotateStatefull bool, agencyCache state.State) api.Plan { | ||||||||||||
group api.ServerGroup, reason string, spec api.DeploymentSpec, status api.DeploymentStatus, rotateStatefull, compact bool, agencyCache state.State) api.Plan { | ||||||||||||
upgradeAction := api.ActionTypeUpgradeMember | ||||||||||||
if rotateStatefull || group.IsStateless() { | ||||||||||||
upgradeAction = api.ActionTypeRotateMember | ||||||||||||
|
@@ -608,7 +612,7 @@ func (r *Reconciler) createUpgradeMemberPlan(member api.MemberStatus, | |||||||||||
Str("action", string(upgradeAction)). | ||||||||||||
Info("Creating upgrade plan") | ||||||||||||
|
||||||||||||
plan := createRotateMemberPlanWithAction(member, group, upgradeAction, spec, reason, util.CheckConditionalP1Nil(agencyCache.GetRebootID, state.Server(member.ID))) | ||||||||||||
plan := createRotateMemberPlanWithAction(member, group, upgradeAction, spec, reason, util.CheckConditionalP1Nil(agencyCache.GetRebootID, state.Server(member.ID)), compact) | ||||||||||||
|
||||||||||||
if member.Image == nil || member.Image.Image != spec.GetImage() { | ||||||||||||
plan = plan.Before(actions.NewAction(api.ActionTypeSetMemberCurrentImage, group, member, reason).SetImage(spec.GetImage())) | ||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -23,6 +23,7 @@ package resources | |||||
import ( | ||||||
"context" | ||||||
"fmt" | ||||||
"slices" | ||||||
goStrings "strings" | ||||||
"time" | ||||||
|
||||||
|
@@ -136,13 +137,24 @@ func (r *Resources) InspectPods(ctx context.Context, cachedStatus inspectorInter | |||||
switch containers[id] { | ||||||
case api.ServerGroupReservedInitContainerNameVersionCheck: | ||||||
if c, ok := kresources.GetAnyContainerStatusByName(pod.Status.InitContainerStatuses, containers[id]); ok { | ||||||
if t := c.State.Terminated; t != nil && t.ExitCode == 11 { | ||||||
if t := c.State.Terminated; t != nil && t.ExitCode == constants.ArangoDBExitCodeUpgradeRequired { | ||||||
memberStatus.Upgrade = true | ||||||
updateMemberStatusNeeded = true | ||||||
} | ||||||
} | ||||||
case api.ServerGroupReservedInitContainerNameUpgrade: | ||||||
memberStatus.Conditions.Update(api.ConditionTypeUpgradeFailed, true, "Upgrade Failed", "") | ||||||
if group == api.ServerGroupDBServers { | ||||||
if c, ok := kresources.GetAnyContainerStatusByName(pod.Status.InitContainerStatuses, containers[id]); ok { | ||||||
if t := c.State.Terminated; t != nil && slices.Contains([]int32{ | ||||||
constants.ArangoDBExitCodeUpgradeFailedCompaction, | ||||||
//constants.ContainerExitCodeSegmentationFault, // Also in case of Segv | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove commented code or implement it. The TODO-style comment suggests this might be needed but is commented out without clear reasoning.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
constants.ArangoDBExitCodeInvalidArgument, // If Arg is not known | ||||||
}, t.ExitCode) { | ||||||
memberStatus.Conditions.Update(api.ConditionTypeMarkedToRemove, true, "Replace Required due to the mismatch", "") | ||||||
} | ||||||
} | ||||||
} | ||||||
} | ||||||
} | ||||||
} | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// | ||
// DISCLAIMER | ||
// | ||
// Copyright 2025 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 constants | ||
|
||
const ( | ||
ArangoDBExitCodeInvalidArgument = 3 | ||
ArangoDBExitCodeUpgradeRequired = 11 | ||
ArangoDBExitCodeUpgradeFailedCompaction = 30 | ||
|
||
ContainerExitCodeSegmentationFault = 139 | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line appears to be missing proper indentation and logical structure. The condition check for
!m.Member.Conditions.IsTrue(api.ConditionTypeMarkedToRemove)
was removed but the action is still being executed unconditionally.Copilot uses AI. Check for mistakes.