-
Notifications
You must be signed in to change notification settings - Fork 223
OCPEDGE-2038: Add promote-learner command #5706
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
Draft
pacevedom
wants to merge
8
commits into
openshift:main
Choose a base branch
from
pacevedom:OCPEDGE-2038
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8a8df4f
OCPEDGE-2038: Rename several functions for add-node
pacevedom b6fcb75
OCPEDGE-2038: Add promote-learner command
pacevedom 68339f8
OCPEDGE-2038: Rework kubelet controller functions
pacevedom 6a5c66d
OCPEDGE-2038: Propagate context in promote-learner
pacevedom 67b18ad
OCPEDGE-2038: Remove auto restart of microshift after promotion
pacevedom f974d56
OCPEDGE-2038: Add etcd client helper function
pacevedom 993e793
OCPEDGE-2038: Rework etcd client logic in promote-learner
pacevedom 9874210
OCPEDGE-2038: Hide command in downstream build
pacevedom 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| "github.com/openshift/microshift/pkg/config" | ||
| "github.com/openshift/microshift/pkg/controllers" | ||
| "github.com/openshift/microshift/pkg/version" | ||
| "github.com/spf13/cobra" | ||
|
|
||
| "k8s.io/klog/v2" | ||
| ) | ||
|
|
||
| func NewPromoteLearnerCommand() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "promote-learner", | ||
| Short: "Promote learner node to member in the etcd cluster", | ||
| Long: `This command promotes the local etcd instance from a learner node to a full voting member within an existing MicroShift etcd cluster. | ||
| It: | ||
| - Connects to the etcd cluster using the current node's configuration. | ||
| - Verifies that the local etcd instance is currently a learner. | ||
| - Issues a promote request to the cluster. | ||
| - Restarts the MicroShift service to make the membership change effective to apiserver. | ||
| Use this command only after the learner node has fully caught up with the cluster and you are ready for it to become a voting member. | ||
| `, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| return runPromoteLearner(cmd.Context()) | ||
| }, | ||
| } | ||
|
|
||
| if version.Get().BuildVariant != version.BuildVariantCommunity { | ||
| cmd.Hidden = true | ||
| } | ||
|
|
||
| return cmd | ||
| } | ||
|
|
||
| func runPromoteLearner(ctx context.Context) error { | ||
| klog.Info("Starting learner promotion process") | ||
|
|
||
| cfg, err := config.ActiveConfig() | ||
| if err != nil { | ||
| return fmt.Errorf("failed to load MicroShift configuration: %w", err) | ||
| } | ||
|
|
||
| klog.Info("Promoting etcd learner to member") | ||
| if err := promoteEtcdLearner(ctx, cfg); err != nil { | ||
| return fmt.Errorf("failed to promote etcd learner: %w", err) | ||
| } | ||
|
|
||
| klog.Info("etcd node successfully promoted to member. Restart MicroShift service") | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func promoteEtcdLearner(ctx context.Context, cfg *config.Config) error { | ||
| client, err := controllers.GetClusterEtcdClient(ctx, cfg.KubeConfigPath(config.KubeAdmin)) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to create etcd client: %v", err) | ||
| } | ||
| defer func() { _ = client.Close() }() | ||
|
|
||
| memberResponse, err := client.MemberList(ctx) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to list etcd members: %v", err) | ||
| } | ||
|
|
||
| found, learner := false, false | ||
| var id uint64 = 0 | ||
|
|
||
| for _, member := range memberResponse.Members { | ||
| if member.Name == cfg.CanonicalNodeName() { | ||
| found = true | ||
| if member.IsLearner { | ||
| learner = true | ||
| id = member.ID | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if !found { | ||
| return fmt.Errorf("node %s is not in the etcd cluster", cfg.CanonicalNodeName()) | ||
| } | ||
| if !learner { | ||
| return fmt.Errorf("node %s is not a learner", cfg.CanonicalNodeName()) | ||
| } | ||
|
|
||
| response, err := client.MemberPromote(ctx, id) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to promote etcd learner: %v", err) | ||
| } | ||
| klog.Infof("Successfully promoted etcd learner %s with response: %v", cfg.CanonicalNodeName(), response) | ||
| 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
Oops, something went wrong.
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.
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.
Maybe we should add check in code to do that? Before the step 3: "Issues a promote request to the cluster"