From fa9d7d89a816bbcc65c8b18951cb41b1ddb48a4b Mon Sep 17 00:00:00 2001 From: Peter Hunt Date: Thu, 30 Jun 2022 13:36:59 -0400 Subject: [PATCH 1/3] version: don't wipe if filename is empty Signed-off-by: Peter Hunt --- internal/version/version.go | 15 +++++++-------- internal/version/version_test.go | 6 +++--- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/internal/version/version.go b/internal/version/version.go index 35728887843..3177586e028 100644 --- a/internal/version/version.go +++ b/internal/version/version.go @@ -1,9 +1,7 @@ package version import ( - "bufio" "fmt" - "io/ioutil" "os" "path/filepath" "reflect" @@ -56,14 +54,12 @@ func ShouldCrioWipe(versionFileName string) (bool, error) { // shouldCrioWipe is an internal function for testing purposes func shouldCrioWipe(versionFileName, versionString string) (bool, error) { - f, err := os.Open(versionFileName) - if err != nil { - return true, errors.Errorf("version file %s not found: %v", versionFileName, err) + if versionFileName == "" { + return false, nil } - r := bufio.NewReader(f) - versionBytes, err := ioutil.ReadAll(r) + versionBytes, err := os.ReadFile(versionFileName) if err != nil { - return true, errors.Errorf("reading version file %s failed: %v", versionFileName, err) + return true, errors.Errorf("version file %s not found: %v", versionFileName, err) } // parse the version that was laid down by a previous invocation of crio @@ -99,6 +95,9 @@ func LogVersion() { // writeVersionFile is an internal function for testing purposes func writeVersionFile(file, gitCommit, version string) error { + if file == "" { + return nil + } current, err := parseVersionConstant(version, gitCommit) // Sanity check-this should never happen if err != nil { diff --git a/internal/version/version_test.go b/internal/version/version_test.go index ec031167df3..bb71d7604ad 100644 --- a/internal/version/version_test.go +++ b/internal/version/version_test.go @@ -74,10 +74,10 @@ var _ = t.Describe("Version", func() { _, err = ioutil.ReadFile(filename) Expect(err).To(BeNil()) }) - It("should fail to upgrade with unspecified version", func() { + It("should not wipe with empty version file", func() { upgrade, err := shouldCrioWipe("", tempVersion) - Expect(upgrade).To(BeTrue()) - Expect(err).ToNot(BeNil()) + Expect(upgrade).To(BeFalse()) + Expect(err).To(BeNil()) }) It("should fail to upgrade with empty version file", func() { tempFileName := tempFileName From 32034c789d1c485340cf444b624ac15486fc0278 Mon Sep 17 00:00:00 2001 From: Peter Hunt Date: Thu, 30 Jun 2022 13:37:12 -0400 Subject: [PATCH 2/3] config: set version-file-persist to empty by default Signed-off-by: Peter Hunt --- docs/crio.conf.5.md | 2 +- pkg/config/config.go | 17 ++++++++--------- pkg/config/config_unix.go | 4 ---- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/docs/crio.conf.5.md b/docs/crio.conf.5.md index fcedfba38dd..11557b62b57 100644 --- a/docs/crio.conf.5.md +++ b/docs/crio.conf.5.md @@ -49,7 +49,7 @@ CRI-O reads its storage defaults from the containers-storage.conf(5) file locate It is used to check if crio wipe should wipe containers, which should always happen on a node reboot -**version_file_persist**="/var/lib/crio/version" +**version_file_persist**="" Location for CRI-O to lay down the persistent version file. It is used to check if crio wipe should wipe images, which should only happen when CRI-O has been upgraded diff --git a/pkg/config/config.go b/pkg/config/config.go index c8b3a5d3f62..3d0797902c6 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -760,15 +760,14 @@ func DefaultConfig() (*Config, error) { DockerRegistryUserAgent: useragent.Get(), }, RootConfig: RootConfig{ - Root: storeOpts.GraphRoot, - RunRoot: storeOpts.RunRoot, - Storage: storeOpts.GraphDriverName, - StorageOptions: storeOpts.GraphDriverOptions, - LogDir: "/var/log/crio/pods", - VersionFile: CrioVersionPathTmp, - VersionFilePersist: CrioVersionPathPersist, - CleanShutdownFile: CrioCleanShutdownFile, - InternalWipe: true, + Root: storeOpts.GraphRoot, + RunRoot: storeOpts.RunRoot, + Storage: storeOpts.GraphDriverName, + StorageOptions: storeOpts.GraphDriverOptions, + LogDir: "/var/log/crio/pods", + VersionFile: CrioVersionPathTmp, + CleanShutdownFile: CrioCleanShutdownFile, + InternalWipe: true, }, APIConfig: APIConfig{ Listen: CrioSocketPath, diff --git a/pkg/config/config_unix.go b/pkg/config/config_unix.go index 4c72673e78c..156098504fd 100644 --- a/pkg/config/config_unix.go +++ b/pkg/config/config_unix.go @@ -23,10 +23,6 @@ const ( // used to check if we should wipe containers CrioVersionPathTmp = "/var/run/crio/version" - // CrioVersionPathPersist is where the CRI-O version file is located - // used to check whether we've upgraded, and thus need to remove images - CrioVersionPathPersist = "/var/lib/crio/version" - // CrioCleanShutdownFile is the location CRI-O will lay down the clean shutdown file // that checks whether we've had time to sync before shutting down. // If not, crio wipe will clear the storage directory. From 3aed67c3407d9068be31fe2e6f98ed60311db848 Mon Sep 17 00:00:00 2001 From: Peter Hunt Date: Thu, 30 Jun 2022 13:37:12 -0400 Subject: [PATCH 3/3] config: set version-file-persist to empty by default Signed-off-by: Peter Hunt --- docs/crio.8.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/crio.8.md b/docs/crio.8.md index 7983168dc9d..95551a4bf79 100644 --- a/docs/crio.8.md +++ b/docs/crio.8.md @@ -337,7 +337,7 @@ crio [GLOBAL OPTIONS] command [COMMAND OPTIONS] [ARGUMENTS...] **--seccomp-use-default-when-empty**: Use the default seccomp profile when an empty one is specified -**--selinux**: Enable selinux support (default: false) +**--selinux**: Enable selinux support (default: true) **--separate-pull-cgroup**="": [EXPERIMENTAL] Pull in new cgroup (default: "")