Merge pull request #3954 from mheon/hardcode_default_storepaths
Ensure good defaults on blank c/storage configuration
This commit is contained in:
		
						commit
						24171ae060
					
				|  | @ -281,10 +281,17 @@ func defaultRuntimeConfig() (RuntimeConfig, error) { | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return RuntimeConfig{}, err | 		return RuntimeConfig{}, err | ||||||
| 	} | 	} | ||||||
|  | 	graphRoot := storeOpts.GraphRoot | ||||||
|  | 	if graphRoot == "" { | ||||||
|  | 		logrus.Warnf("Storage configuration is unset - using hardcoded default paths") | ||||||
|  | 		graphRoot = "/var/lib/containers/storage" | ||||||
|  | 	} | ||||||
|  | 	volumePath := filepath.Join(graphRoot, "volumes") | ||||||
|  | 	staticDir := filepath.Join(graphRoot, "libpod") | ||||||
| 	return RuntimeConfig{ | 	return RuntimeConfig{ | ||||||
| 		// Leave this empty so containers/storage will use its defaults
 | 		// Leave this empty so containers/storage will use its defaults
 | ||||||
| 		StorageConfig:         storage.StoreOptions{}, | 		StorageConfig:         storage.StoreOptions{}, | ||||||
| 		VolumePath:            filepath.Join(storeOpts.GraphRoot, "volumes"), | 		VolumePath:            volumePath, | ||||||
| 		ImageDefaultTransport: DefaultTransport, | 		ImageDefaultTransport: DefaultTransport, | ||||||
| 		StateType:             BoltDBStateStore, | 		StateType:             BoltDBStateStore, | ||||||
| 		OCIRuntime:            "runc", | 		OCIRuntime:            "runc", | ||||||
|  | @ -314,7 +321,7 @@ func defaultRuntimeConfig() (RuntimeConfig, error) { | ||||||
| 		}, | 		}, | ||||||
| 		InitPath:              define.DefaultInitPath, | 		InitPath:              define.DefaultInitPath, | ||||||
| 		CgroupManager:         SystemdCgroupsManager, | 		CgroupManager:         SystemdCgroupsManager, | ||||||
| 		StaticDir:             filepath.Join(storeOpts.GraphRoot, "libpod"), | 		StaticDir:             staticDir, | ||||||
| 		TmpDir:                "", | 		TmpDir:                "", | ||||||
| 		MaxLogSize:            -1, | 		MaxLogSize:            -1, | ||||||
| 		NoPivotRoot:           false, | 		NoPivotRoot:           false, | ||||||
|  | @ -789,6 +796,20 @@ func probeConmon(conmonBinary string) error { | ||||||
| // Make a new runtime based on the given configuration
 | // Make a new runtime based on the given configuration
 | ||||||
| // Sets up containers/storage, state store, OCI runtime
 | // Sets up containers/storage, state store, OCI runtime
 | ||||||
| func makeRuntime(ctx context.Context, runtime *Runtime) (err error) { | func makeRuntime(ctx context.Context, runtime *Runtime) (err error) { | ||||||
|  | 	// Let's sanity-check some paths first.
 | ||||||
|  | 	// Relative paths can cause nasty bugs, because core paths we use could
 | ||||||
|  | 	// shift between runs (or even parts of the program - the OCI runtime
 | ||||||
|  | 	// uses a different working directory than we do, for example.
 | ||||||
|  | 	if !filepath.IsAbs(runtime.config.StaticDir) { | ||||||
|  | 		return errors.Wrapf(define.ErrInvalidArg, "static directory must be an absolute path - instead got %q", runtime.config.StaticDir) | ||||||
|  | 	} | ||||||
|  | 	if !filepath.IsAbs(runtime.config.TmpDir) { | ||||||
|  | 		return errors.Wrapf(define.ErrInvalidArg, "temporary directory must be an absolute path - instead got %q", runtime.config.TmpDir) | ||||||
|  | 	} | ||||||
|  | 	if !filepath.IsAbs(runtime.config.VolumePath) { | ||||||
|  | 		return errors.Wrapf(define.ErrInvalidArg, "volume path must be an absolute path - instead got %q", runtime.config.VolumePath) | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	// Find a working conmon binary
 | 	// Find a working conmon binary
 | ||||||
| 	foundConmon := false | 	foundConmon := false | ||||||
| 	foundOutdatedConmon := false | 	foundOutdatedConmon := false | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue