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

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

View File

@@ -1,8 +1,6 @@
package build
import (
"runtime"
"github.com/spf13/cobra"
"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
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.

View File

@@ -5,6 +5,7 @@ import (
"os"
"path"
"path/filepath"
"runtime"
"github.com/spf13/cobra"
"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

View File

@@ -1,8 +1,6 @@
package imprt
import (
"runtime"
"github.com/spf13/cobra"
"github.com/warewulf/warewulf/internal/app/wwctl/completions"
)
@@ -34,7 +32,7 @@ var (
func init() {
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().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.