Use wwctl overlay <import|build> --workers=0 to indicate default value

By default, uses `runtime.NumCPU()`

The default value is rendered in the generated man pages, which made
their content dependent on build system characteristics.

Signed-off-by: Jonathon Anderson <janderson@ciq.com>
This commit is contained in:
Christian Goll
2025-02-26 17:07:31 +01:00
parent f4b65fca90
commit a97c204f53
5 changed files with 20 additions and 9 deletions

View File

@@ -18,6 +18,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Fix nightly builds. - Fix nightly builds.
### Changed
- User `wwctl overlay <import|build> --workers=0` to indicate `runtime.NumCPU()`. #1782
## v4.6.0rc3, 2025-02-23 ## v4.6.0rc3, 2025-02-23
### Added ### Added

View File

@@ -3,6 +3,7 @@ package build
import ( import (
"errors" "errors"
"fmt" "fmt"
"runtime"
"strings" "strings"
"syscall" "syscall"
@@ -67,10 +68,15 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
oldMask := syscall.Umask(000) oldMask := syscall.Umask(000)
defer syscall.Umask(oldMask) defer syscall.Umask(oldMask)
workers := Workers
if workers <= 0 {
workers = runtime.NumCPU()
}
if len(OverlayNames) > 0 { if len(OverlayNames) > 0 {
err = overlay.BuildSpecificOverlays(filteredNodes, allNodes, OverlayNames, Workers) err = overlay.BuildSpecificOverlays(filteredNodes, allNodes, OverlayNames, workers)
} else { } else {
err = overlay.BuildAllOverlays(filteredNodes, allNodes, Workers) err = overlay.BuildAllOverlays(filteredNodes, allNodes, workers)
} }
if err != nil { if err != nil {

View File

@@ -1,8 +1,6 @@
package build package build
import ( import (
"runtime"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/warewulf/warewulf/internal/app/wwctl/completions" "github.com/warewulf/warewulf/internal/app/wwctl/completions"
) )
@@ -29,7 +27,7 @@ func init() {
} }
baseCmd.PersistentFlags().StringVarP(&OverlayDir, "output", "o", "", `Do not create an overlay image for distribution but write to baseCmd.PersistentFlags().StringVarP(&OverlayDir, "output", "o", "", `Do not create an overlay image for distribution but write to
the given directory. An overlay must also be ge given to use this option.`) the given directory. An overlay must also be ge given to use this option.`)
baseCmd.PersistentFlags().IntVar(&Workers, "workers", runtime.NumCPU(), "The number of parallel workers building overlays") baseCmd.PersistentFlags().IntVar(&Workers, "workers", 0, "The number of parallel workers building overlays (<=0 indicates 1 worker per CPU)")
} }
// GetRootCommand returns the root cobra.Command for the application. // GetRootCommand returns the root cobra.Command for the application.

View File

@@ -5,6 +5,7 @@ import (
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
"runtime"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/warewulf/warewulf/internal/pkg/node" "github.com/warewulf/warewulf/internal/pkg/node"
@@ -88,7 +89,11 @@ func CobraRunE(cmd *cobra.Command, args []string) (err error) {
} }
} }
return overlay.BuildSpecificOverlays(updateNodes, nodes, []string{overlayName}, Workers) workers := Workers
if workers <= 0 {
workers = runtime.NumCPU()
}
return overlay.BuildSpecificOverlays(updateNodes, nodes, []string{overlayName}, workers)
} }
return nil return nil

View File

@@ -1,8 +1,6 @@
package imprt package imprt
import ( import (
"runtime"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/warewulf/warewulf/internal/app/wwctl/completions" "github.com/warewulf/warewulf/internal/app/wwctl/completions"
) )
@@ -34,7 +32,7 @@ var (
func init() { func init() {
baseCmd.PersistentFlags().BoolVarP(&NoOverlayUpdate, "noupdate", "n", false, "Don't update overlays") baseCmd.PersistentFlags().BoolVarP(&NoOverlayUpdate, "noupdate", "n", false, "Don't update overlays")
baseCmd.PersistentFlags().BoolVarP(&CreateDirs, "parents", "p", false, "Create any necessary parent directories") baseCmd.PersistentFlags().BoolVarP(&CreateDirs, "parents", "p", false, "Create any necessary parent directories")
baseCmd.PersistentFlags().IntVar(&Workers, "workers", runtime.NumCPU(), "The number of parallel workers building overlays") baseCmd.PersistentFlags().IntVar(&Workers, "workers", 0, "The number of parallel workers building overlays (<=0 indicates 1 worker per CPU)")
} }
// GetRootCommand returns the root cobra.Command for the application. // GetRootCommand returns the root cobra.Command for the application.