-
Notifications
You must be signed in to change notification settings - Fork 72
Check if the server is cleaned out #775
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| // | ||
| // DISCLAIMER | ||
| // | ||
| // Copyright 2021 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 | ||
| // | ||
| // Author Tomasz Mielech | ||
| // | ||
|
|
||
| package reconcile | ||
|
|
||
| import ( | ||
| "context" | ||
| "strconv" | ||
|
|
||
| "github.com/rs/zerolog" | ||
|
|
||
| api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" | ||
| "github.com/arangodb/kube-arangodb/pkg/util/errors" | ||
| ) | ||
|
|
||
| func init() { | ||
| registerAction(api.ActionTypeSetMemberCondition, setMemberCondition) | ||
| } | ||
|
|
||
| func setMemberCondition(log zerolog.Logger, action api.Action, actionCtx ActionContext) Action { | ||
| a := &actionSetMemberCondition{} | ||
|
|
||
| a.actionImpl = newActionImplDefRef(log, action, actionCtx, defaultTimeout) | ||
|
|
||
| return a | ||
| } | ||
|
|
||
| type actionSetMemberCondition struct { | ||
| // actionImpl implement timeout and member id functions | ||
| actionImpl | ||
|
|
||
| actionEmptyCheckProgress | ||
| } | ||
|
|
||
| // Start starts the action for changing conditions on the provided member. | ||
| func (a actionSetMemberCondition) Start(ctx context.Context) (bool, error) { | ||
| m, ok := a.actionCtx.GetMemberStatusByID(a.action.MemberID) | ||
| if !ok { | ||
| a.log.Info().Msg("can not set the condition because the member is gone already") | ||
| return true, nil | ||
| } | ||
|
|
||
| if len(a.action.Params) == 0 { | ||
| a.log.Info().Msg("can not start the action with the empty list of conditions") | ||
| return true, nil | ||
| } | ||
|
|
||
| for condition, value := range a.action.Params { | ||
| set, err := strconv.ParseBool(value) | ||
| if err != nil { | ||
| a.log.Error().Err(err).Str("value", value).Msg("can not parse string to boolean") | ||
| continue | ||
| } | ||
|
|
||
| a.log.Debug().Msg("set the condition") | ||
|
|
||
| m.Conditions.Update(api.ConditionType(condition), set, a.action.Reason, "action set the member condition") | ||
| } | ||
|
|
||
| if err := a.actionCtx.UpdateMember(ctx, m); err != nil { | ||
| return false, errors.Wrap(errors.WithStack(err), "can not update the member") | ||
| } | ||
|
|
||
| return true, nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| // | ||
| // DISCLAIMER | ||
| // | ||
| // Copyright 2021 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 | ||
| // | ||
| // Author Tomasz Mielech | ||
| // | ||
|
|
||
| package reconcile | ||
|
|
||
| import ( | ||
| "context" | ||
| "strconv" | ||
|
|
||
| "github.com/arangodb/go-driver" | ||
| "github.com/rs/zerolog" | ||
|
|
||
| api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" | ||
| "github.com/arangodb/kube-arangodb/pkg/util/arangod" | ||
| "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" | ||
| inspectorInterface "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector" | ||
| ) | ||
|
|
||
| // createCleanOutPlan creates clean out action if the server is cleaned out and the operator is not aware of it. | ||
| func createCleanOutPlan(ctx context.Context, log zerolog.Logger, _ k8sutil.APIObject, spec api.DeploymentSpec, | ||
| status api.DeploymentStatus, _ inspectorInterface.Inspector, planCtx PlanBuilderContext) api.Plan { | ||
|
|
||
| if spec.GetMode() != api.DeploymentModeCluster { | ||
| return nil | ||
| } | ||
|
|
||
| cluster, err := getCluster(ctx, planCtx) | ||
| if err != nil { | ||
| log.Warn().Err(err).Msgf("Unable to get cluster") | ||
| return nil | ||
| } | ||
|
|
||
| ctxChild, cancel := context.WithTimeout(ctx, arangod.GetRequestTimeout()) | ||
| defer cancel() | ||
| health, err := cluster.Health(ctxChild) | ||
| if err != nil { | ||
| log.Warn().Err(err).Msgf("Unable to get cluster health") | ||
| return nil | ||
| } | ||
|
|
||
| for id, member := range health.Health { | ||
| switch member.Role { | ||
| case driver.ServerRoleDBServer: | ||
| memberStatus, ok := status.Members.DBServers.ElementByID(string(id)) | ||
| if !ok { | ||
| continue | ||
| } | ||
|
|
||
| if memberStatus.Conditions.IsTrue(api.ConditionTypeCleanedOut) { | ||
| continue | ||
| } | ||
|
|
||
| if isCleanedOut, err := cluster.IsCleanedOut(ctx, string(id)); err != nil { | ||
| log.Warn().Err(err).Str("id", string(id)).Msgf("Unable to get clean out status") | ||
| return nil | ||
| } else if isCleanedOut { | ||
| log.Info(). | ||
| Str("role", string(member.Role)). | ||
| Str("id", string(id)). | ||
| Msgf("server is cleaned out so operator must do the same") | ||
|
|
||
| action := api.NewAction(api.ActionTypeSetMemberCondition, api.ServerGroupDBServers, string(id), | ||
| "server is cleaned out so operator must do the same") | ||
| action = action.AddParam(string(api.ConditionTypeCleanedOut), strconv.FormatBool(true)) | ||
|
|
||
| return api.Plan{action} | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.