diff --git a/internal/app/wwctl/kernel/imprt/main.go b/internal/app/wwctl/kernel/imprt/main.go index 745f9f48..50f241b8 100644 --- a/internal/app/wwctl/kernel/imprt/main.go +++ b/internal/app/wwctl/kernel/imprt/main.go @@ -4,6 +4,7 @@ import ( "fmt" "os" + "github.com/hpcng/warewulf/internal/pkg/container" "github.com/hpcng/warewulf/internal/pkg/kernel" "github.com/hpcng/warewulf/internal/pkg/node" "github.com/hpcng/warewulf/internal/pkg/warewulfd" @@ -14,6 +15,15 @@ import ( func CobraRunE(cmd *cobra.Command, args []string) error { for _, arg := range args { + // Checking if container flag was set, then overwriting OptRoot + if OptContainer != "" { + if container.ValidSource(OptContainer) == true { + OptRoot = container.RootFsDir(OptContainer) + } else { + wwlog.Printf(wwlog.ERROR, " %s is not a valid container", OptContainer) + os.Exit(1) + } + } output, err := kernel.Build(arg, OptRoot) if err != nil { wwlog.Printf(wwlog.ERROR, "Failed building kernel: %s\n", err) diff --git a/internal/app/wwctl/kernel/imprt/root.go b/internal/app/wwctl/kernel/imprt/root.go index b529e680..b8e49b8e 100644 --- a/internal/app/wwctl/kernel/imprt/root.go +++ b/internal/app/wwctl/kernel/imprt/root.go @@ -13,10 +13,11 @@ var ( RunE: CobraRunE, Args: cobra.MinimumNArgs(1), } - BuildAll bool - ByNode bool - SetDefault bool - OptRoot string + BuildAll bool + ByNode bool + SetDefault bool + OptRoot string + OptContainer string ) func init() { @@ -24,6 +25,7 @@ func init() { baseCmd.PersistentFlags().BoolVarP(&ByNode, "node", "n", false, "Build overlay for a particular node(s)") baseCmd.PersistentFlags().BoolVar(&SetDefault, "setdefault", false, "Set this kernel for the default profile") baseCmd.PersistentFlags().StringVarP(&OptRoot, "root", "r", "/", "Import kernel from root (chroot) directory") + baseCmd.PersistentFlags().StringVarP(&OptContainer, "container", "c", "", "Import kernel from container") } // GetRootCommand returns the root cobra.Command for the application.