-
Notifications
You must be signed in to change notification settings - Fork 230
USHIFT-1085: feat: support prerun with minimal services #1978
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
openshift-merge-robot
merged 1 commit into
openshift:main
from
eggfoobar:minimal_microshift_run
Jun 30, 2023
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| package prerun | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "os" | ||
| "os/signal" | ||
| "syscall" | ||
| "time" | ||
|
|
||
| "github.com/openshift/microshift/pkg/config" | ||
| "github.com/openshift/microshift/pkg/controllers" | ||
| "github.com/openshift/microshift/pkg/node" | ||
| "github.com/openshift/microshift/pkg/servicemanager" | ||
| "github.com/openshift/microshift/pkg/util" | ||
|
|
||
| "k8s.io/klog/v2" | ||
| ) | ||
|
|
||
| const ( | ||
| gracefulShutdownTimeout = time.Second * 30 | ||
| readyStateTimeout = time.Second * 10 | ||
| ) | ||
|
|
||
| // runMinimalMicroshift initializes a minimum run of microshift core services during pre-run | ||
| // to help with storage migration. | ||
| // | ||
| // Returns a handler to shutdown MicroShfit services and error if services never became ready. | ||
| func runMinimalMicroshift(cfg *config.Config) (context.CancelFunc, error) { | ||
| // Establish the context we will use to control execution | ||
| runCtx, runCancel := context.WithCancel(context.Background()) | ||
| m := servicemanager.NewServiceManager() | ||
| util.Must(m.AddService(node.NewNetworkConfiguration(cfg))) | ||
| util.Must(m.AddService(controllers.NewEtcd(cfg))) | ||
| util.Must(m.AddService(controllers.NewKubeAPIServer(cfg))) | ||
|
|
||
| // Start core services up | ||
| ready, stopped := make(chan struct{}), make(chan struct{}) | ||
| go func() { | ||
| klog.Infof("Started %s", m.Name()) | ||
| if err := m.Run(runCtx, ready, stopped); err != nil { | ||
| klog.Errorf("Stopped %s: %v", m.Name(), err) | ||
| } else { | ||
| klog.Infof("%s completed", m.Name()) | ||
| } | ||
| }() | ||
|
|
||
| // Connect os signal handler | ||
| sigTerm := make(chan os.Signal, 1) | ||
| signal.Notify(sigTerm, os.Interrupt, syscall.SIGTERM) | ||
|
|
||
| go func() { | ||
| select { | ||
| case <-sigTerm: | ||
| klog.Info("Interrupt received") | ||
| klog.Info("Stopping services") | ||
| runCancel() | ||
| case <-runCtx.Done(): | ||
| klog.Info("Done signal from context received") | ||
| } | ||
| }() | ||
|
|
||
| // Provides a function to call when you want to stop the services | ||
| // because this is a blocking call it serves as a call and wait for | ||
| // all the services to stop. | ||
| stopFunc := func() { | ||
| runCancel() | ||
| select { | ||
| case <-stopped: | ||
| case <-time.After(gracefulShutdownTimeout): | ||
| klog.Infof("Timed out waiting for services to stop") | ||
| } | ||
| klog.Infof("MicroShift Sevices stopped") | ||
| } | ||
|
|
||
| // If Microshift does not become ready by the deadline, we consider that an error | ||
| select { | ||
| case <-ready: | ||
| klog.Infof("MicroShift is ready in minimal state") | ||
| case <-time.After(readyStateTimeout): | ||
| klog.Error("MicroShift never became ready in minimal state") | ||
| stopFunc() | ||
| return nil, fmt.Errorf("services failed to be in ready state by timeout(%s)", readyStateTimeout) | ||
| } | ||
|
|
||
| return stopFunc, 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
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.
We can put these lines and L220-L224 to a separate function, like a
migrateStoragethat would callrunMinimalMicroshift()and run the migratorThere 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.
Sounds like a plan, do you want me to put that in a separate function in this PR, or do it in #1956 ?