Skip to content
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 @@ -3,6 +3,7 @@
## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A)
- Do not check License V2 on Community images
- Add status.members.<group>.
- Define MemberReplacementRequired condition

## [1.2.7](https://github.com/arangodb/kube-arangodb/tree/1.2.7) (2022-01-17)
- Add Plan BackOff functionality
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/deployment/v1/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ const (
ConditionTypePendingRestart ConditionType = "PendingRestart"
// ConditionTypeRestart indicates that restart will be started
ConditionTypeRestart ConditionType = "Restart"
// MemberReplacementRequired indicates that the member requires a replacement to proceed with next actions.
MemberReplacementRequired ConditionType = "MemberReplacementRequired"

// ConditionTypePendingTLSRotation indicates that TLS rotation is pending
ConditionTypePendingTLSRotation ConditionType = "PendingTLSRotation"
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/deployment/v2alpha1/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ const (
ConditionTypePendingRestart ConditionType = "PendingRestart"
// ConditionTypeRestart indicates that restart will be started
ConditionTypeRestart ConditionType = "Restart"
// MemberReplacementRequired indicates that the member requires a replacement to proceed with next actions.
MemberReplacementRequired ConditionType = "MemberReplacementRequired"

// ConditionTypePendingTLSRotation indicates that TLS rotation is pending
ConditionTypePendingTLSRotation ConditionType = "PendingTLSRotation"
Expand Down
78 changes: 78 additions & 0 deletions pkg/deployment/reconcile/condition_member_recreation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
//
// DISCLAIMER
//
// Copyright 2016-2022 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 reconcile

import (
"context"
"strings"

api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
inspectorInterface "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector"
"github.com/rs/zerolog"
)

func createMemberRecreationConditionsPlan(ctx context.Context,
log zerolog.Logger, apiObject k8sutil.APIObject,
spec api.DeploymentSpec, status api.DeploymentStatus,
cachedStatus inspectorInterface.Inspector, context PlanBuilderContext) api.Plan {
var p api.Plan

for _, m := range status.Members.AsList() {
resp, recreate := EvaluateMemberRecreationCondition(ctx, log, apiObject, spec, status, m.Group, m.Member, cachedStatus, context)

if !recreate {
if _, ok := m.Member.Conditions.Get(api.MemberReplacementRequired); ok {
// Unset condition
p = append(p, removeMemberConditionActionV2("Member replacement not required", api.MemberReplacementRequired, m.Group, m.Member.ID))
}
} else {
if c, ok := m.Member.Conditions.Get(api.MemberReplacementRequired); !ok || !c.IsTrue() || c.Message != resp {
// Update condition
p = append(p, updateMemberConditionActionV2("Member replacement required", api.MemberReplacementRequired, m.Group, m.Member.ID, true, "Member replacement required", resp, ""))
}
}
}

return p
}

type MemberRecreationConditionEvaluator func(ctx context.Context,
log zerolog.Logger, apiObject k8sutil.APIObject,
spec api.DeploymentSpec, status api.DeploymentStatus,
group api.ServerGroup, member api.MemberStatus,
cachedStatus inspectorInterface.Inspector, context PlanBuilderContext) (string, bool)

func EvaluateMemberRecreationCondition(ctx context.Context,
log zerolog.Logger, apiObject k8sutil.APIObject,
spec api.DeploymentSpec, status api.DeploymentStatus,
group api.ServerGroup, member api.MemberStatus,
cachedStatus inspectorInterface.Inspector, context PlanBuilderContext, evaluators ...MemberRecreationConditionEvaluator) (string, bool) {
args := make([]string, 0, len(evaluators))

for _, e := range evaluators {
if s, ok := e(ctx, log, apiObject, spec, status, group, member, cachedStatus, context); ok {
args = append(args, s)
}
}

return strings.Join(args, ", "), len(args) > 0
}
1 change: 1 addition & 0 deletions pkg/deployment/reconcile/plan_builder_high.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func createHighPlan(ctx context.Context, log zerolog.Logger, apiObject k8sutil.A
ApplyIfEmpty(createCleanOutPlan).
ApplyIfEmpty(updateMemberUpdateConditionsPlan).
ApplyIfEmpty(updateMemberRotationConditionsPlan).
ApplyIfEmpty(createMemberRecreationConditionsPlan).
ApplyIfEmpty(createTopologyMemberUpdatePlan).
ApplyIfEmptyWithBackOff(LicenseCheck, 30*time.Second, updateClusterLicense).
ApplyIfEmpty(createTopologyMemberConditionPlan).
Expand Down
21 changes: 21 additions & 0 deletions pkg/deployment/reconcile/plan_builder_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,24 @@ func updateConditionActionV2(actionReason string, conditionType api.ConditionTyp
AddParam(setConditionActionV2KeyMessage, message).
AddParam(setConditionActionV2KeyHash, hash)
}

func removeMemberConditionActionV2(actionReason string, conditionType api.ConditionType, group api.ServerGroup, member string) api.Action {
return api.NewAction(api.ActionTypeSetMemberConditionV2, group, member, actionReason).
AddParam(setConditionActionV2KeyAction, string(conditionType)).
AddParam(setConditionActionV2KeyType, setConditionActionV2KeyTypeRemove)
}

func updateMemberConditionActionV2(actionReason string, conditionType api.ConditionType, group api.ServerGroup, member string, status bool, reason, message, hash string) api.Action {
statusBool := core.ConditionTrue
if !status {
statusBool = core.ConditionFalse
}

return api.NewAction(api.ActionTypeSetMemberConditionV2, group, member, actionReason).
AddParam(setConditionActionV2KeyAction, string(conditionType)).
AddParam(setConditionActionV2KeyType, setConditionActionV2KeyTypeAdd).
AddParam(setConditionActionV2KeyStatus, string(statusBool)).
AddParam(setConditionActionV2KeyReason, reason).
AddParam(setConditionActionV2KeyMessage, message).
AddParam(setConditionActionV2KeyHash, hash)
}