mirror of
https://github.com/arangodb/kube-arangodb.git
synced 2024-12-14 11:57:37 +00:00
[Feature] Add member replacement condition (#898)
This commit is contained in:
parent
024a7b75de
commit
b296b837d4
6 changed files with 105 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
78
pkg/deployment/reconcile/condition_member_recreation.go
Normal file
78
pkg/deployment/reconcile/condition_member_recreation.go
Normal file
|
@ -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
|
||||
}
|
|
@ -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).
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue