Merge pull request #1565 from anderbubble/issues/1419

Remove wwctl overlay build --host
This commit is contained in:
Christian Goll
2024-11-28 08:43:05 +01:00
committed by GitHub
3 changed files with 14 additions and 34 deletions

View File

@@ -73,6 +73,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- `wwctl node list --fullall` has been removed - `wwctl node list --fullall` has been removed
- `wwctl profile list --fullall` has been removed - `wwctl profile list --fullall` has been removed
- Remove `wwctl server <start,stop,status,restart,reload>` #508 - Remove `wwctl server <start,stop,status,restart,reload>` #508
- Remove `wwctl overlay build --host` #1419
- Remove `wwctl overlay build --nodes` #1419
### Fixed ### Fixed

View File

@@ -3,20 +3,16 @@ package build
import ( import (
"errors" "errors"
"fmt" "fmt"
"os"
"strings" "strings"
"syscall" "syscall"
"github.com/spf13/cobra" "github.com/spf13/cobra"
warewulfconf "github.com/warewulf/warewulf/internal/pkg/config"
"github.com/warewulf/warewulf/internal/pkg/hostlist" "github.com/warewulf/warewulf/internal/pkg/hostlist"
"github.com/warewulf/warewulf/internal/pkg/node" "github.com/warewulf/warewulf/internal/pkg/node"
"github.com/warewulf/warewulf/internal/pkg/overlay" "github.com/warewulf/warewulf/internal/pkg/overlay"
"github.com/warewulf/warewulf/internal/pkg/wwlog"
) )
func CobraRunE(cmd *cobra.Command, args []string) error { func CobraRunE(cmd *cobra.Command, args []string) error {
controller := warewulfconf.Get()
nodeDB, err := node.New() nodeDB, err := node.New()
if err != nil { if err != nil {
return fmt.Errorf("could not open node configuration: %s", err) return fmt.Errorf("could not open node configuration: %s", err)
@@ -54,43 +50,29 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
if len(args) > 0 { if len(args) > 0 {
if len(db) != 1 { if len(db) != 1 {
return errors.New("nust specify one node to build overlay") return errors.New("must specify one node to build overlay")
} }
for _, node := range db { for _, node := range db {
return overlay.BuildOverlayIndir(node, OverlayNames, OverlayDir) return overlay.BuildOverlayIndir(node, OverlayNames, OverlayDir)
} }
} else { } else {
// TODO this seems different than what is set in BuildHostOverlay return errors.New("must specify a node to build overlay")
hostname, _ := os.Hostname()
node := node.NewNode(hostname)
wwlog.Info("building overlay for host: %s", hostname)
return overlay.BuildOverlayIndir(node, OverlayNames, OverlayDir)
} }
} }
if BuildHost && controller.Warewulf.EnableHostOverlay() { oldMask := syscall.Umask(007)
err := overlay.BuildHostOverlay() defer syscall.Umask(oldMask)
if err != nil {
return fmt.Errorf("host overlay could not be built: %s", err) if len(OverlayNames) > 0 {
} err = overlay.BuildSpecificOverlays(db, OverlayNames)
} else {
err = overlay.BuildAllOverlays(db)
} }
if BuildNodes || (!BuildHost && !BuildNodes) { if err != nil {
oldMask := syscall.Umask(007) return fmt.Errorf("some overlays failed to be generated: %s", err)
defer syscall.Umask(oldMask)
if len(OverlayNames) > 0 {
err = overlay.BuildSpecificOverlays(db, OverlayNames)
} else {
err = overlay.BuildAllOverlays(db)
}
if err != nil {
return fmt.Errorf("some overlays failed to be generated: %s", err)
}
} }
return nil return nil
} }

View File

@@ -29,15 +29,11 @@ var (
return node_names, cobra.ShellCompDirectiveNoFileComp return node_names, cobra.ShellCompDirectiveNoFileComp
}, },
} }
BuildHost bool
BuildNodes bool
OverlayNames []string OverlayNames []string
OverlayDir string OverlayDir string
) )
func init() { func init() {
baseCmd.PersistentFlags().BoolVarP(&BuildHost, "host", "H", false, "Build overlays only for the host")
baseCmd.PersistentFlags().BoolVarP(&BuildNodes, "nodes", "N", false, "Build overlays only for the nodes")
baseCmd.PersistentFlags().StringSliceVarP(&OverlayNames, "overlay", "O", []string{}, "Build only specific overlay(s)") baseCmd.PersistentFlags().StringSliceVarP(&OverlayNames, "overlay", "O", []string{}, "Build only specific overlay(s)")
if err := baseCmd.RegisterFlagCompletionFunc("overlay", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { if err := baseCmd.RegisterFlagCompletionFunc("overlay", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
@@ -46,7 +42,7 @@ func init() {
}); err != nil { }); err != nil {
log.Println(err) log.Println(err)
} }
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.`)
} }