-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Use custom storage check options for CRI-O internal wipe #8417
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-bot
merged 10 commits into
cri-o:main
from
kwilczynski:feature/internal-repair-changes
Aug 9, 2024
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
46b167d
Use custom set of checks over the CheckEverything() for storage checks
8f55574
Replace open-coded repair options with the RepairEverything() helper
7b058f2
Move log message from HandleUncleanShutdown() function
895c2ca
Make the storage shutdown force unmount images on error
1348885
Remove orphaned mounts before removing storage directory
1a20443
Wipe storage only after giving storage.Repair() a chance
fc7a26b
Allow for storage directory removal to be forced
a79fa8b
Make internal repair the new default and disable internal wipe
ba0bd3e
Add crio check sub-command used to check storage for errors
aa6d034
Skip storage directory corruption recovery tests on Kata Containers
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
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,195 @@ | ||
| package criocli | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/containers/storage" | ||
| "github.com/sirupsen/logrus" | ||
| "github.com/urfave/cli/v2" | ||
|
|
||
| "github.com/cri-o/cri-o/internal/lib" | ||
| "github.com/cri-o/cri-o/utils" | ||
| ) | ||
|
|
||
| type checkErrors map[string][]error | ||
|
|
||
| var CheckCommand = &cli.Command{ | ||
| Name: "check", | ||
| Usage: usageText, | ||
| Action: crioCheck, | ||
| Flags: []cli.Flag{ | ||
| &cli.StringFlag{ | ||
| Name: "age", | ||
| Aliases: []string{"a"}, | ||
| Value: "24h", | ||
| Usage: "Maximum allowed age for unreferenced layers", | ||
| }, | ||
| &cli.BoolFlag{ | ||
| Name: "force", | ||
| Aliases: []string{"f"}, | ||
| Usage: "Remove damaged containers", | ||
| }, | ||
| &cli.BoolFlag{ | ||
| Name: "repair", | ||
| Aliases: []string{"r"}, | ||
| Usage: "Remove damaged images and layers", | ||
| }, | ||
| &cli.BoolFlag{ | ||
| Name: "quick", | ||
| Aliases: []string{"q"}, | ||
| Usage: "Perform only quick checks", | ||
| }, | ||
| &cli.BoolFlag{ | ||
| Name: "wipe", | ||
| Aliases: []string{"w"}, | ||
| Usage: "Wipe storage directory on repair failure", | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| func crioCheck(c *cli.Context) error { | ||
| config, err := GetConfigFromContext(c) | ||
| if err != nil { | ||
| return fmt.Errorf("unable to load configuration: %w", err) | ||
| } | ||
|
|
||
| store, err := config.GetStore() | ||
| if err != nil { | ||
| return fmt.Errorf("unable to open storage: %w", err) | ||
| } | ||
| defer func() { | ||
| if _, err := store.Shutdown(true); err != nil { | ||
| logrus.Errorf("Unable to shutdown storage: %v", err) | ||
| } | ||
| }() | ||
|
|
||
| graphRoot := store.GraphRoot() | ||
| logrus.Infof("Checking storage directory %s for errors", graphRoot) | ||
|
|
||
| checkOptions := storage.CheckEverything() | ||
| if c.Bool("quick") { | ||
| // This is not the same as the "quick" check that CRI-O performs during its start-up | ||
| // following an unclean shutdown, as this one would set the `LayerDigests` option, | ||
| // which is I/O and CPU intensive, whereas the other one does not. | ||
| checkOptions = storage.CheckMost() | ||
| } | ||
|
|
||
| // The maximum unreferenced layer age. | ||
| layerAge := c.String("age") | ||
| if layerAge != "" { | ||
| age, err := utils.ParseDuration(layerAge) | ||
| if err != nil { | ||
| return fmt.Errorf("unable to parse age duration: %w", err) | ||
| } | ||
| checkOptions.LayerUnreferencedMaximumAge = &age | ||
| } | ||
|
|
||
| report, err := store.Check(checkOptions) | ||
| if err != nil { | ||
| return fmt.Errorf("unable to check storage: %w", err) | ||
| } | ||
|
|
||
| // Walk each report and show details... | ||
| for prefix, checkReport := range map[string]checkErrors{ | ||
| "layer": report.Layers, | ||
| "read-only layer": report.ROLayers, | ||
| "image": report.Images, | ||
| "read-only image": report.ROImages, | ||
| "container": report.Containers, | ||
| } { | ||
| for identifier, errs := range checkReport { | ||
| for _, err := range errs { | ||
| logrus.Debugf("%s: %s: %v", prefix, identifier, err) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| seenStorageErrors := lib.CheckReportHasErrors(report) | ||
| logrus.Debugf("Storage directory %s has errors: %t", graphRoot, seenStorageErrors) | ||
|
|
||
| if !c.Bool("repair") { | ||
| if seenStorageErrors { | ||
| logrus.Warnf("Errors found while checking storage directory %s for errors", graphRoot) | ||
| return fmt.Errorf( | ||
| "%d layer errors, %d read-only layer errors, %d image errors, %d read-only image errors, %d container errors", | ||
| len(report.Layers), | ||
| len(report.ROLayers), | ||
| len(report.Images), | ||
| len(report.ROImages), | ||
| len(report.Containers), | ||
| ) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| force := c.Bool("force") | ||
| if force { | ||
| logrus.Warn("The `force` option has been set, repair will attempt to remove damaged containers") | ||
| } | ||
| logrus.Infof("Attempting to repair storage directory %s", graphRoot) | ||
|
|
||
| errs := store.Repair(report, &storage.RepairOptions{ | ||
| RemoveContainers: force, | ||
| }) | ||
| if len(errs) != 0 { | ||
| for _, err := range errs { | ||
| logrus.Error(err) | ||
| } | ||
|
|
||
| if c.Bool("wipe") { | ||
| // Depending on whether the `force` option is set or not, this will remove the | ||
| // storage directory completely while ignoring any running containers. Otherwise, | ||
| // this will fail if there are any containers currently running. | ||
| if force { | ||
| logrus.Warn("The `force` option has been set, storage directory will be forcefully removed") | ||
| } | ||
| logrus.Infof("Wiping storage directory %s", graphRoot) | ||
| return lib.RemoveStorageDirectory(config, store, force) | ||
| } | ||
|
|
||
| return errs[0] | ||
| } | ||
|
|
||
| if len(report.ROLayers) > 0 || len(report.ROImages) > 0 || (!force && len(report.Containers) > 0) { | ||
| if force { | ||
| // Any damaged containers would have been deleted at this point. | ||
| return fmt.Errorf( | ||
| "%d read-only layer errors, %d read-only image errors", | ||
| len(report.ROLayers), | ||
| len(report.ROImages), | ||
| ) | ||
| } | ||
| return fmt.Errorf( | ||
| "%d read-only layer errors, %d read-only image errors, %d container errors", | ||
| len(report.ROLayers), | ||
| len(report.ROImages), | ||
| len(report.Containers), | ||
| ) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // The `Description` field will not be rendered when the documentation | ||
| // is generated, and using `Usage` makes the formatting wrong when the | ||
| // command-line help is rendered. Shell completions might also be | ||
| // incorrect. | ||
| var usageText = `Check CRI-O storage directory for errors. | ||
|
|
||
| This command can also repair damaged containers, images and layers. | ||
|
|
||
| By default, the data integrity of the storage directory is verified, | ||
| which can be an I/O and CPU-intensive operation. The --quick option | ||
| can be used to reduce the number of checks run. | ||
|
|
||
| When using the --repair option, especially with the --force option, | ||
| CRI-O and any currently running containers should be stopped if | ||
| possible to ensure no concurrent access to the storage directory | ||
| occurs. | ||
|
|
||
| The --wipe option can be used to automatically attempt to remove | ||
| containers and images on a repair failure. This option, combined | ||
| with the --force option, can be used to entirely remove the storage | ||
| directory content in case of irrecoverable errors. This should be | ||
| used as a last resort, and similarly to the --repair option, it's | ||
| best if CRI-O and any currently running containers are stopped.` | ||
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.
Uh oh!
There was an error while loading. Please reload this page.