Skip to content

Commit 0a15328

Browse files
committed
setup: Add InVm option to Validate()
If in vm, we don't need --privileged. Also, we can also support rootless containers.
1 parent 3ed2d55 commit 0a15328

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

cmd/image-builder/bib_main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ func bibCmdBuild(cmd *cobra.Command, args []string) error {
282282
progressType, _ := cmd.Flags().GetString("progress")
283283

284284
logrus.Debug("Validating environment")
285-
if err := setup.Validate(targetArch); err != nil {
285+
if err := setup.Validate(targetArch, false); err != nil {
286286
return fmt.Errorf("cannot validate the setup: %w", err)
287287
}
288288
logrus.Debug("Ensuring environment setup")

pkg/setup/setup.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ func EnsureEnvironment(storePath string, inVm bool) error {
8282

8383
// Validate checks that the environment is supported (e.g. caller set up the
8484
// container correctly)
85-
func Validate(targetArch string) error {
85+
func Validate(targetArch string, inVm bool) error {
8686
isRootless, err := podmanutil.IsRootless()
8787
if err != nil {
8888
return fmt.Errorf("checking rootless: %w", err)
8989
}
90-
if isRootless {
90+
if isRootless && !inVm {
9191
return fmt.Errorf("this command must be run in rootful (not rootless) podman")
9292
}
9393

@@ -97,7 +97,7 @@ func Validate(targetArch string) error {
9797
if err := unix.Statfs("/sys", &stvfsbuf); err != nil {
9898
return fmt.Errorf("failed to stat /sys: %w", err)
9999
}
100-
if (stvfsbuf.Flags & unix.ST_RDONLY) > 0 {
100+
if !inVm && (stvfsbuf.Flags&unix.ST_RDONLY) > 0 {
101101
return fmt.Errorf("this command requires a privileged container")
102102
}
103103

0 commit comments

Comments
 (0)