From 5a0c13225e22c3623740f583b51031d8ba115d5b Mon Sep 17 00:00:00 2001 From: Gregory Kurtzer Date: Tue, 15 Feb 2022 06:49:24 +0000 Subject: [PATCH] Utilize containerized kernel and remove kernel Support --- etc/ipxe/bigimage.ipxe | 6 +- etc/ipxe/default.ipxe | 3 +- internal/app/wwctl/container/list/main.go | 10 +- internal/app/wwctl/kernel/delete/main.go | 41 ---- internal/app/wwctl/kernel/delete/root.go | 33 --- internal/app/wwctl/kernel/imprt/main.go | 92 -------- internal/app/wwctl/kernel/imprt/root.go | 46 ---- internal/app/wwctl/kernel/list/main.go | 35 --- internal/app/wwctl/kernel/list/root.go | 23 -- internal/app/wwctl/kernel/root.go | 28 --- internal/app/wwctl/node/list/main.go | 5 +- internal/app/wwctl/node/set/main.go | 5 - internal/app/wwctl/node/set/root.go | 9 - internal/app/wwctl/profile/list/main.go | 1 - internal/app/wwctl/profile/set/main.go | 7 +- internal/app/wwctl/profile/set/root.go | 9 - internal/app/wwctl/root.go | 20 +- internal/pkg/container/kernel.go | 47 ++++ internal/pkg/kernel/kernel.go | 257 ---------------------- internal/pkg/node/constructors.go | 3 - internal/pkg/node/datastructure.go | 2 - internal/pkg/node/modifiers.go | 2 - internal/pkg/overlay/overlay.go | 1 - internal/pkg/warewulfd/ipxe.go | 1 - internal/pkg/warewulfd/kernel.go | 9 +- internal/pkg/warewulfd/kmods.go | 45 ---- internal/pkg/warewulfd/warewulfd.go | 1 - 27 files changed, 73 insertions(+), 668 deletions(-) delete mode 100644 internal/app/wwctl/kernel/delete/main.go delete mode 100644 internal/app/wwctl/kernel/delete/root.go delete mode 100644 internal/app/wwctl/kernel/imprt/main.go delete mode 100644 internal/app/wwctl/kernel/imprt/root.go delete mode 100644 internal/app/wwctl/kernel/list/main.go delete mode 100644 internal/app/wwctl/kernel/list/root.go delete mode 100644 internal/app/wwctl/kernel/root.go create mode 100644 internal/pkg/container/kernel.go delete mode 100644 internal/pkg/kernel/kernel.go delete mode 100644 internal/pkg/warewulfd/kmods.go diff --git a/etc/ipxe/bigimage.ipxe b/etc/ipxe/bigimage.ipxe index 1308b998..7527fbb9 100644 --- a/etc/ipxe/bigimage.ipxe +++ b/etc/ipxe/bigimage.ipxe @@ -11,13 +11,13 @@ echo set base http://{{.Ipaddr}}:{{.Port}} -kernel --name kernel ${base}/kernel/{{.Hwaddr}}?assetkey=${asset}&uuid=${uuid} || goto reboot +kernel --name kernel ${base}/kernel/{{.Hwaddr}}?assetkey=${asset}&uuid=${uuid} || goto reboot imgextract --name container ${base}/container/{{.Hwaddr}}?assetkey=${asset}&uuid=${uuid} || goto reboot -imgextract --name kmods ${base}/kmods/{{.Hwaddr}}?assetkey=${asset}&uuid=${uuid} || goto reboot imgextract --name system ${base}/overlay-system/{{.Hwaddr}}?assetkey=${asset}&uuid=${uuid} || goto reboot imgextract --name runtime ${base}/overlay-runtime/{{.Hwaddr}}?assetkey=${asset}&uuid=${uuid} || goto reboot +imgextract --name runtime ${base}/overlay-runtime/{{.Hwaddr}}?assetkey=${asset}&uuid=${uuid} || goto reboot -boot kernel initrd=container initrd=kmods initrd=system initrd=runtime wwid={{.Hwaddr}} {{.KernelArgs}} || goto reboot +boot kernel initrd=container initrd=system initrd=runtime wwid={{.Hwaddr}} {{.KernelArgs}} || goto reboot :reboot echo diff --git a/etc/ipxe/default.ipxe b/etc/ipxe/default.ipxe index 5014dec5..ef1d879f 100644 --- a/etc/ipxe/default.ipxe +++ b/etc/ipxe/default.ipxe @@ -13,11 +13,10 @@ set base http://{{.Ipaddr}}:{{.Port}} kernel --name kernel ${base}/kernel/{{.Hwaddr}}?assetkey=${asset}&uuid=${uuid} || goto reboot initrd --name container ${base}/container/{{.Hwaddr}}?assetkey=${asset}&uuid=${uuid} || goto reboot -initrd --name kmods ${base}/kmods/{{.Hwaddr}}?assetkey=${asset}&uuid=${uuid} || goto reboot initrd --name system ${base}/overlay-system/{{.Hwaddr}}?assetkey=${asset}&uuid=${uuid} || goto reboot initrd --name runtime ${base}/overlay-runtime/{{.Hwaddr}}?assetkey=${asset}&uuid=${uuid} || goto reboot -boot kernel initrd=container initrd=kmods initrd=system initrd=runtime wwid={{.Hwaddr}} {{.KernelArgs}} || goto reboot +boot kernel initrd=container initrd=system initrd=runtime wwid={{.Hwaddr}} {{.KernelArgs}} || goto reboot :reboot echo diff --git a/internal/app/wwctl/container/list/main.go b/internal/app/wwctl/container/list/main.go index 6568e192..f228a5f9 100644 --- a/internal/app/wwctl/container/list/main.go +++ b/internal/app/wwctl/container/list/main.go @@ -3,10 +3,10 @@ package list import ( "fmt" "os" + "path" "github.com/hpcng/warewulf/internal/pkg/container" "github.com/hpcng/warewulf/internal/pkg/node" - "github.com/hpcng/warewulf/internal/pkg/util" "github.com/hpcng/warewulf/internal/pkg/wwlog" "github.com/spf13/cobra" ) @@ -27,14 +27,14 @@ func CobraRunE(cmd *cobra.Command, args []string) error { nodemap[n.ContainerName.Get()]++ } - fmt.Printf("%-35s %-6s %-6s\n", "CONTAINER NAME", "BUILT", "NODES") + fmt.Printf("%-25s %-6s %-6s\n", "CONTAINER NAME", "NODES", "KERNEL") for _, source := range sources { - image := container.ImageFile(source) - if nodemap[source] == 0 { nodemap[source] = 0 } - fmt.Printf("%-35s %-6t %-6d\n", source, util.IsFile(image), nodemap[source]) + + kernel := container.KernelFind(source) + fmt.Printf("%-25s %-6d %s\n", source, nodemap[source], path.Base(kernel)) } return nil diff --git a/internal/app/wwctl/kernel/delete/main.go b/internal/app/wwctl/kernel/delete/main.go deleted file mode 100644 index c289a27d..00000000 --- a/internal/app/wwctl/kernel/delete/main.go +++ /dev/null @@ -1,41 +0,0 @@ -package delete - -import ( - "fmt" - "os" - - "github.com/hpcng/warewulf/internal/pkg/kernel" - "github.com/hpcng/warewulf/internal/pkg/node" - "github.com/hpcng/warewulf/internal/pkg/wwlog" - "github.com/spf13/cobra" -) - -func CobraRunE(cmd *cobra.Command, args []string) error { - - nodeDB, err := node.New() - if err != nil { - wwlog.Printf(wwlog.ERROR, "Could not open nodeDB: %s\n", err) - os.Exit(1) - } - - nodes, _ := nodeDB.FindAllNodes() - -ARG_LOOP: - for _, arg := range args { - for _, n := range nodes { - if n.KernelVersion.Get() == arg { - wwlog.Printf(wwlog.ERROR, "Kernel is configured for nodes, skipping: %s\n", arg) - continue ARG_LOOP - } - } - - err := kernel.DeleteKernel(arg) - if err != nil { - wwlog.Printf(wwlog.ERROR, "Could not delete kernel: %s\n", arg) - } else { - fmt.Printf("Kernel has been deleted: %s\n", arg) - } - } - - return nil -} diff --git a/internal/app/wwctl/kernel/delete/root.go b/internal/app/wwctl/kernel/delete/root.go deleted file mode 100644 index 5fc68bea..00000000 --- a/internal/app/wwctl/kernel/delete/root.go +++ /dev/null @@ -1,33 +0,0 @@ -package delete - -import ( - "github.com/hpcng/warewulf/internal/pkg/kernel" - "github.com/spf13/cobra" -) - -var ( - baseCmd = &cobra.Command{ - DisableFlagsInUseLine: true, - Use: "delete [OPTIONS] KERNEL [...]", - Short: "Delete imported kernels", - Long: "This command will delete KERNEL versions that have been imported into Warewulf.", - RunE: CobraRunE, - Args: cobra.MinimumNArgs(1), - ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - if len(args) != 0 { - return nil, cobra.ShellCompDirectiveNoFileComp - } - list, _ := kernel.ListKernels() - return list, cobra.ShellCompDirectiveNoFileComp - }, - } -) - -func init() { - -} - -// GetRootCommand returns the root cobra.Command for the application. -func GetCommand() *cobra.Command { - return baseCmd -} diff --git a/internal/app/wwctl/kernel/imprt/main.go b/internal/app/wwctl/kernel/imprt/main.go deleted file mode 100644 index 97e3e219..00000000 --- a/internal/app/wwctl/kernel/imprt/main.go +++ /dev/null @@ -1,92 +0,0 @@ -package imprt - -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" - "github.com/hpcng/warewulf/internal/pkg/wwlog" - "github.com/pkg/errors" - "github.com/spf13/cobra" -) - -func CobraRunE(cmd *cobra.Command, args []string) error { - if len(args) == 0 && !OptDetect { - wwlog.Printf(wwlog.ERROR, "the '--detect' flag is needed, if no kernel version is suppiled") - os.Exit(1) - } - if OptDetect && (OptRoot == "" || OptContainer == "") { - wwlog.Printf(wwlog.ERROR, "the '--detect flag needs the '--container' or '--root' flag") - os.Exit(1) - } - // Checking if container flag was set, then overwriting OptRoot - if OptContainer != "" { - if container.ValidSource(OptContainer) { - OptRoot = container.RootFsDir(OptContainer) - } else { - wwlog.Printf(wwlog.ERROR, " %s is not a valid container", OptContainer) - os.Exit(1) - } - } - - var kernelVersion string - var err error - if len(args) > 0 { - kernelVersion = args[0] - } else { - kernelVersion, err = kernel.FindKernelVersion(OptRoot) - if err != nil { - wwlog.Printf(wwlog.ERROR, "could not detect kernel under %s\n", OptRoot) - os.Exit(1) - } - } - kernelName := kernelVersion - if len(args) > 1 { - kernelName = args[1] - } else if OptDetect && (OptContainer != "") { - kernelName = OptContainer - } - output, err := kernel.Build(kernelVersion, kernelName, OptRoot) - if err != nil { - wwlog.Printf(wwlog.ERROR, "Failed building kernel: %s\n", err) - os.Exit(1) - } else { - fmt.Printf("%s: %s\n", kernelName, output) - } - - if SetDefault { - - nodeDB, err := node.New() - if err != nil { - wwlog.Printf(wwlog.ERROR, "Could not open node configuration: %s\n", err) - os.Exit(1) - } - //TODO: Don't loop through profiles, instead have a nodeDB function that goes directly to the map - profiles, _ := nodeDB.FindAllProfiles() - for _, profile := range profiles { - wwlog.Printf(wwlog.DEBUG, "Looking for profile default: %s\n", profile.Id.Get()) - if profile.Id.Get() == "default" { - wwlog.Printf(wwlog.DEBUG, "Found profile default, setting kernel version to: %s\n", args[0]) - profile.KernelVersion.Set(args[0]) - err := nodeDB.ProfileUpdate(profile) - if err != nil { - return errors.Wrap(err, "failed to update node profile") - } - } - } - err = nodeDB.Persist() - if err != nil { - return errors.Wrap(err, "failed to persist nodedb") - } - fmt.Printf("Set default kernel version to: %s\n", args[0]) - err = warewulfd.DaemonReload() - if err != nil { - return errors.Wrap(err, "failed to reload warewulf daemon") - } - } - - return nil -} diff --git a/internal/app/wwctl/kernel/imprt/root.go b/internal/app/wwctl/kernel/imprt/root.go deleted file mode 100644 index c8521a7b..00000000 --- a/internal/app/wwctl/kernel/imprt/root.go +++ /dev/null @@ -1,46 +0,0 @@ -package imprt - -import ( - "log" - - "github.com/hpcng/warewulf/internal/pkg/container" - "github.com/spf13/cobra" -) - -var ( - baseCmd = &cobra.Command{ - DisableFlagsInUseLine: true, - Use: "import [OPTIONS] KERNEL", - Short: "Import Kernel version into Warewulf", - Long: "This will import a boot KERNEL version from the control node into Warewulf", - RunE: CobraRunE, - Args: cobra.MinimumNArgs(0), - } - BuildAll bool - ByNode bool - SetDefault bool - OptRoot string - OptContainer string - OptDetect bool -) - -func init() { - baseCmd.PersistentFlags().BoolVarP(&BuildAll, "all", "a", false, "Build all overlays (runtime and system)") - 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") - err := baseCmd.RegisterFlagCompletionFunc("container", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - list, _ := container.ListSources() - return list, cobra.ShellCompDirectiveNoFileComp - }) - if err != nil { - log.Println(err) - } - baseCmd.PersistentFlags().BoolVarP(&OptDetect, "detect", "D", false, "Try to detect the kernel version in an automated way, needs the -C or -r option") -} - -// GetRootCommand returns the root cobra.Command for the application. -func GetCommand() *cobra.Command { - return baseCmd -} diff --git a/internal/app/wwctl/kernel/list/main.go b/internal/app/wwctl/kernel/list/main.go deleted file mode 100644 index a3a8d4ad..00000000 --- a/internal/app/wwctl/kernel/list/main.go +++ /dev/null @@ -1,35 +0,0 @@ -package list - -import ( - "fmt" - "os" - - "github.com/hpcng/warewulf/internal/pkg/kernel" - "github.com/hpcng/warewulf/internal/pkg/node" - "github.com/hpcng/warewulf/internal/pkg/wwlog" - "github.com/spf13/cobra" -) - -func CobraRunE(cmd *cobra.Command, args []string) error { - - kernels, err := kernel.ListKernels() - if err != nil { - wwlog.Printf(wwlog.ERROR, "%s\n", err) - os.Exit(1) - } - - nconfig, _ := node.New() - nodes, _ := nconfig.FindAllNodes() - nodemap := make(map[string]int) - - for _, n := range nodes { - nodemap[n.KernelVersion.Get()]++ - } - - fmt.Printf("%-35s %-25s %-6s\n", "KERNEL NAME", "KERNEL VERSION", "NODES") - for _, k := range kernels { - fmt.Printf("%-35s %-25s %6d\n", k, kernel.GetKernelVersion(k), nodemap[k]) - } - - return nil -} diff --git a/internal/app/wwctl/kernel/list/root.go b/internal/app/wwctl/kernel/list/root.go deleted file mode 100644 index fba84101..00000000 --- a/internal/app/wwctl/kernel/list/root.go +++ /dev/null @@ -1,23 +0,0 @@ -package list - -import "github.com/spf13/cobra" - -var ( - baseCmd = &cobra.Command{ - DisableFlagsInUseLine: true, - Use: "list [OPTIONS]", - Short: "List imported Kernel images", - Long: "This command will list the kernels that have been imported into Warewulf.", - RunE: CobraRunE, - Args: cobra.ExactArgs(0), - Aliases: []string{"ls"}, - } -) - -func init() { -} - -// GetRootCommand returns the root cobra.Command for the application. -func GetCommand() *cobra.Command { - return baseCmd -} diff --git a/internal/app/wwctl/kernel/root.go b/internal/app/wwctl/kernel/root.go deleted file mode 100644 index bb0cdb8d..00000000 --- a/internal/app/wwctl/kernel/root.go +++ /dev/null @@ -1,28 +0,0 @@ -package kernel - -import ( - "github.com/hpcng/warewulf/internal/app/wwctl/kernel/delete" - "github.com/hpcng/warewulf/internal/app/wwctl/kernel/imprt" - "github.com/hpcng/warewulf/internal/app/wwctl/kernel/list" - "github.com/spf13/cobra" -) - -var ( - baseCmd = &cobra.Command{ - DisableFlagsInUseLine: true, - Use: "kernel COMMAND [OPTIONS]", - Short: "Kernel Image Management", - Long: "This command manages Warewulf Kernels used for bootstrapping nodes", - } -) - -func init() { - baseCmd.AddCommand(imprt.GetCommand()) - baseCmd.AddCommand(list.GetCommand()) - baseCmd.AddCommand(delete.GetCommand()) -} - -// GetRootCommand returns the root cobra.Command for the application. -func GetCommand() *cobra.Command { - return baseCmd -} diff --git a/internal/app/wwctl/node/list/main.go b/internal/app/wwctl/node/list/main.go index 0e6845c8..76db8201 100644 --- a/internal/app/wwctl/node/list/main.go +++ b/internal/app/wwctl/node/list/main.go @@ -41,7 +41,6 @@ func CobraRunE(cmd *cobra.Command, args []string) error { fmt.Printf("%-20s %-18s %-12s %t\n", node.Id.Get(), "Discoverable", node.Discoverable.Source(), node.Discoverable.PrintB()) fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), "Container", node.ContainerName.Source(), node.ContainerName.Print()) - fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), "Kernel", node.KernelVersion.Source(), node.KernelVersion.Print()) fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), "KernelArgs", node.KernelArgs.Source(), node.KernelArgs.Print()) fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), "SystemOverlay", node.SystemOverlay.Source(), node.SystemOverlay.Print()) fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), "RuntimeOverlay", node.RuntimeOverlay.Source(), node.RuntimeOverlay.Print()) @@ -97,11 +96,11 @@ func CobraRunE(cmd *cobra.Command, args []string) error { } } else if ShowLong { - fmt.Printf("%-22s %-26s %-35s %s\n", "NODE NAME", "KERNEL", "CONTAINER", "OVERLAYS (S/R)") + fmt.Printf("%-22s %-35s %s\n", "NODE NAME", "CONTAINER", "OVERLAYS (S/R)") fmt.Println(strings.Repeat("=", 120)) for _, node := range node.FilterByName(nodes, args) { - fmt.Printf("%-22s %-26s %-35s %s\n", node.Id.Get(), node.KernelVersion.Print(), node.ContainerName.Print(), node.SystemOverlay.Print()+"/"+node.RuntimeOverlay.Print()) + fmt.Printf("%-22s %-35s %s\n", node.Id.Get(), node.ContainerName.Print(), node.SystemOverlay.Print()+"/"+node.RuntimeOverlay.Print()) } } else { diff --git a/internal/app/wwctl/node/set/main.go b/internal/app/wwctl/node/set/main.go index 59f3e7c5..2e2c4861 100644 --- a/internal/app/wwctl/node/set/main.go +++ b/internal/app/wwctl/node/set/main.go @@ -70,11 +70,6 @@ func CobraRunE(cmd *cobra.Command, args []string) error { n.AssetKey.Set(SetAssetKey) } - if SetKernel != "" { - wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting kernel to: %s\n", n.Id.Get(), SetKernel) - n.KernelVersion.Set(SetKernel) - } - if SetKernelArgs != "" { wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting kernel args to: %s\n", n.Id.Get(), SetKernelArgs) n.KernelArgs.Set(SetKernelArgs) diff --git a/internal/app/wwctl/node/set/root.go b/internal/app/wwctl/node/set/root.go index a3feec62..0dcbc865 100644 --- a/internal/app/wwctl/node/set/root.go +++ b/internal/app/wwctl/node/set/root.go @@ -4,7 +4,6 @@ import ( "log" "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/overlay" "github.com/spf13/cobra" @@ -34,7 +33,6 @@ var ( } SetComment string SetContainer string - SetKernel string SetKernelArgs string SetNetName string SetNetDev string @@ -82,13 +80,6 @@ func init() { }); err != nil { log.Println(err) } - baseCmd.PersistentFlags().StringVarP(&SetKernel, "kernel", "K", "", "Set Kernel version for nodes") - if err := baseCmd.RegisterFlagCompletionFunc("kernel", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - list, _ := kernel.ListKernels() - return list, cobra.ShellCompDirectiveNoFileComp - }); err != nil { - log.Println(err) - } baseCmd.PersistentFlags().StringVarP(&SetKernelArgs, "kernelargs", "A", "", "Set Kernel argument for nodes") baseCmd.PersistentFlags().StringVarP(&SetClusterName, "cluster", "c", "", "Set the node's cluster group") baseCmd.PersistentFlags().StringVar(&SetIpxe, "ipxe", "", "Set the node's iPXE template name") diff --git a/internal/app/wwctl/profile/list/main.go b/internal/app/wwctl/profile/list/main.go index a419952e..d1120cbc 100644 --- a/internal/app/wwctl/profile/list/main.go +++ b/internal/app/wwctl/profile/list/main.go @@ -33,7 +33,6 @@ func CobraRunE(cmd *cobra.Command, args []string) error { fmt.Printf("%-20s %-18s %s\n", profile.Id.Get(), "Cluster", profile.ClusterName.Print()) fmt.Printf("%-20s %-18s %s\n", profile.Id.Get(), "Container", profile.ContainerName.Print()) - fmt.Printf("%-20s %-18s %s\n", profile.Id.Get(), "Kernel", profile.KernelVersion.Print()) fmt.Printf("%-20s %-18s %s\n", profile.Id.Get(), "KernelArgs", profile.KernelArgs.Print()) fmt.Printf("%-20s %-18s %s\n", profile.Id.Get(), "Init", profile.Init.Print()) fmt.Printf("%-20s %-18s %s\n", profile.Id.Get(), "Root", profile.Root.Print()) diff --git a/internal/app/wwctl/profile/set/main.go b/internal/app/wwctl/profile/set/main.go index 09d4c288..e4957be3 100644 --- a/internal/app/wwctl/profile/set/main.go +++ b/internal/app/wwctl/profile/set/main.go @@ -75,13 +75,8 @@ func CobraRunE(cmd *cobra.Command, args []string) error { p.AssetKey.Set(SetAssetKey) } - if SetKernel != "" { - wwlog.Printf(wwlog.VERBOSE, "Profile: %s, Setting Kernel to: %s\n", p.Id.Get(), SetKernel) - p.KernelVersion.Set(SetKernel) - } - if SetKernelArgs != "" { - wwlog.Printf(wwlog.VERBOSE, "Profile: %s, Setting Kernel args to: %s\n", p.Id.Get(), SetKernelArgs) + wwlog.Printf(wwlog.VERBOSE, "Profile: %s, Setting kernel args to: %s\n", p.Id.Get(), SetKernelArgs) p.KernelArgs.Set(SetKernelArgs) } diff --git a/internal/app/wwctl/profile/set/root.go b/internal/app/wwctl/profile/set/root.go index d8b08dc6..e7da4c20 100644 --- a/internal/app/wwctl/profile/set/root.go +++ b/internal/app/wwctl/profile/set/root.go @@ -4,7 +4,6 @@ import ( "log" "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/overlay" "github.com/spf13/cobra" @@ -37,7 +36,6 @@ var ( SetForce bool SetComment string SetContainer string - SetKernel string SetKernelArgs string SetClusterName string SetIpxe string @@ -79,13 +77,6 @@ func init() { }); err != nil { log.Println(err) } - baseCmd.PersistentFlags().StringVarP(&SetKernel, "kernel", "K", "", "Set Kernel version for nodes") - if err := baseCmd.RegisterFlagCompletionFunc("kernel", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - list, _ := kernel.ListKernels() - return list, cobra.ShellCompDirectiveNoFileComp - }); err != nil { - log.Println(err) - } baseCmd.PersistentFlags().StringVarP(&SetKernelArgs, "kernelargs", "A", "", "Set Kernel argument for nodes") baseCmd.PersistentFlags().StringVarP(&SetClusterName, "cluster", "c", "", "Set the node's cluster group") baseCmd.PersistentFlags().StringVarP(&SetIpxe, "ipxe", "P", "", "Set the node's iPXE template name") diff --git a/internal/app/wwctl/root.go b/internal/app/wwctl/root.go index 059b38db..f6e7137d 100644 --- a/internal/app/wwctl/root.go +++ b/internal/app/wwctl/root.go @@ -3,15 +3,14 @@ package wwctl import ( "github.com/hpcng/warewulf/internal/app/wwctl/configure" "github.com/hpcng/warewulf/internal/app/wwctl/container" - "github.com/hpcng/warewulf/internal/app/wwctl/kernel" "github.com/hpcng/warewulf/internal/app/wwctl/node" "github.com/hpcng/warewulf/internal/app/wwctl/overlay" "github.com/hpcng/warewulf/internal/app/wwctl/power" "github.com/hpcng/warewulf/internal/app/wwctl/profile" "github.com/hpcng/warewulf/internal/app/wwctl/server" "github.com/hpcng/warewulf/internal/app/wwctl/version" - "github.com/hpcng/warewulf/internal/pkg/wwlog" "github.com/hpcng/warewulf/internal/pkg/help" + "github.com/hpcng/warewulf/internal/pkg/wwlog" "github.com/spf13/cobra" "github.com/spf13/cobra/doc" @@ -21,12 +20,12 @@ import ( var ( rootCmd = &cobra.Command{ DisableFlagsInUseLine: true, - Use: "wwctl COMMAND [OPTIONS]", - Short: "Warewulf Control", - Long: "Control interface to the Warewulf Cluster Provisioning System.", - PersistentPreRunE: rootPersistentPreRunE, - SilenceUsage: true, - SilenceErrors: true, + Use: "wwctl COMMAND [OPTIONS]", + Short: "Warewulf Control", + Long: "Control interface to the Warewulf Cluster Provisioning System.", + PersistentPreRunE: rootPersistentPreRunE, + SilenceUsage: true, + SilenceErrors: true, } verboseArg bool DebugFlag bool @@ -36,13 +35,12 @@ func init() { rootCmd.PersistentFlags().BoolVarP(&verboseArg, "verbose", "v", false, "Run with increased verbosity.") rootCmd.PersistentFlags().BoolVarP(&DebugFlag, "debug", "d", false, "Run with debugging messages enabled.") - rootCmd.SetUsageTemplate(help.UsageTemplate) - rootCmd.SetHelpTemplate(help.HelpTemplate) + rootCmd.SetUsageTemplate(help.UsageTemplate) + rootCmd.SetHelpTemplate(help.HelpTemplate) rootCmd.AddCommand(overlay.GetCommand()) rootCmd.AddCommand(container.GetCommand()) rootCmd.AddCommand(node.GetCommand()) - rootCmd.AddCommand(kernel.GetCommand()) rootCmd.AddCommand(power.GetCommand()) rootCmd.AddCommand(profile.GetCommand()) rootCmd.AddCommand(configure.GetCommand()) diff --git a/internal/pkg/container/kernel.go b/internal/pkg/container/kernel.go new file mode 100644 index 00000000..e1279e60 --- /dev/null +++ b/internal/pkg/container/kernel.go @@ -0,0 +1,47 @@ +package container + +import ( + "path" + "path/filepath" + "sort" + + "github.com/hpcng/warewulf/internal/pkg/wwlog" +) + +var ( + kernelSearchPaths = []string{ + // This is a printf format where the %s will be the kernel version + "/boot/vmlinuz-*", + "/lib/modules/*/vmlinuz*", + } +) + +func KernelFind(container string) string { + container_path := RootFsDir(container) + if container_path == "" { + return "" + } + + for _, searchPath := range kernelSearchPaths { + + check_path := path.Join(container_path, searchPath) + + wwlog.Printf(wwlog.DEBUG, "Searching for kernel(s) at: %s\n", check_path) + kernels, err := filepath.Glob(check_path) + if err != nil { + return "" + } + + if len(kernels) > 1 { + sort.Slice(kernels, func(i, j int) bool { + return kernels[i] > kernels[j] + }) + wwlog.Printf(wwlog.VERBOSE, "Multiple kernels found in container: %s\n", container) + return kernels[0] + } else if len(kernels) == 1 { + return kernels[0] + } + + } + return "NOT_FOUND" +} diff --git a/internal/pkg/kernel/kernel.go b/internal/pkg/kernel/kernel.go deleted file mode 100644 index 37941032..00000000 --- a/internal/pkg/kernel/kernel.go +++ /dev/null @@ -1,257 +0,0 @@ -package kernel - -import ( - "compress/gzip" - "fmt" - "io" - "io/ioutil" - "os" - "os/exec" - "path" - "path/filepath" - "regexp" - - "github.com/pkg/errors" - - "github.com/hpcng/warewulf/internal/pkg/buildconfig" - "github.com/hpcng/warewulf/internal/pkg/util" - "github.com/hpcng/warewulf/internal/pkg/wwlog" -) - -var ( - kernelSearchPaths = []string{ - // This is a printf format where the %s will be the kernel version - "/boot/vmlinuz-%s", - "/boot/vmlinuz-%s.gz", - "/lib/mmodules/%s/vmlinuz", - "/lib/mmodules/%s/vmlinuz.gz", - } -) - -func KernelImageTopDir() string { - return path.Join(buildconfig.WWPROVISIONDIR(), "kernel") -} - -func KernelImage(kernelName string) string { - if kernelName == "" { - wwlog.Printf(wwlog.ERROR, "Kernel Name is not defined\n") - return "" - } - - if !util.ValidString(kernelName, "^[a-zA-Z0-9-._]+$") { - wwlog.Printf(wwlog.ERROR, "Runtime overlay name contains illegal characters: %s\n", kernelName) - return "" - } - - return path.Join(KernelImageTopDir(), kernelName, "vmlinuz") -} - -func GetKernelVersion(kernelName string) string { - if kernelName == "" { - wwlog.Printf(wwlog.ERROR, "Kernel Name is not defined\n") - return "" - } - kernelVersion, err := ioutil.ReadFile(KernelVersionFile(kernelName)) - if err != nil { - return "" - } - return string(kernelVersion) -} - -func KmodsImage(kernelName string) string { - if kernelName == "" { - wwlog.Printf(wwlog.ERROR, "Kernel Name is not defined\n") - return "" - } - - if !util.ValidString(kernelName, "^[a-zA-Z0-9-._]+$") { - wwlog.Printf(wwlog.ERROR, "Runtime overlay name contains illegal characters: %s\n", kernelName) - return "" - } - - return path.Join(KernelImageTopDir(), kernelName, "kmods.img") -} - -func KernelVersionFile(kernelName string) string { - if kernelName == "" { - wwlog.Printf(wwlog.ERROR, "Kernel Name is not defined\n") - return "" - } - - if !util.ValidString(kernelName, "^[a-zA-Z0-9-._]+$") { - wwlog.Printf(wwlog.ERROR, "Runtime overlay name contains illegal characters: %s\n", kernelName) - return "" - } - - return path.Join(KernelImageTopDir(), kernelName, "version") -} - -func ListKernels() ([]string, error) { - var ret []string - - err := os.MkdirAll(KernelImageTopDir(), 0755) - if err != nil { - return ret, errors.New("Could not create Kernel parent directory: " + KernelImageTopDir()) - } - - wwlog.Printf(wwlog.DEBUG, "Searching for Kernel image directories: %s\n", KernelImageTopDir()) - - kernels, err := ioutil.ReadDir(KernelImageTopDir()) - if err != nil { - return ret, err - } - - for _, kernel := range kernels { - wwlog.Printf(wwlog.VERBOSE, "Found Kernel: %s\n", kernel.Name()) - - ret = append(ret, kernel.Name()) - - } - - return ret, nil -} - -func Build(kernelVersion, kernelName, root string) (string, error) { - kernelDrivers := path.Join(root, "/lib/modules/", kernelVersion) - kernelDriversRelative := path.Join("/lib/modules/", kernelVersion) - kernelDestination := KernelImage(kernelName) - driversDestination := KmodsImage(kernelName) - versionDestination := KernelVersionFile(kernelName) - var kernelSource string - - // Create the destination paths just in case it doesn't exist - err := os.MkdirAll(path.Dir(kernelDestination), 0755) - if err != nil { - return "", errors.Wrap(err, "failed to create kernel dest") - } - - err = os.MkdirAll(path.Dir(driversDestination), 0755) - if err != nil { - return "", errors.Wrap(err, "failed to create driver dest") - } - - err = os.MkdirAll(path.Dir(versionDestination), 0755) - if err != nil { - return "", fmt.Errorf("failed to create version dest: %s", err) - } - - for _, searchPath := range kernelSearchPaths { - testPath := fmt.Sprintf(path.Join(root, searchPath), kernelVersion) - wwlog.Printf(wwlog.VERBOSE, "Looking for kernel at: %s\n", testPath) - if util.IsFile(testPath) { - kernelSource = testPath - break - } - } - - if kernelSource == "" { - wwlog.Printf(wwlog.ERROR, "Could not locate kernel image\n") - return "", errors.New("could not locate kernel image") - } else { - wwlog.Printf(wwlog.INFO, "Found kernel at: %s\n", kernelSource) - } - - if !util.IsDir(kernelDrivers) { - return "", errors.New("Could not locate kernel drivers") - } - - wwlog.Printf(wwlog.VERBOSE, "Setting up Kernel\n") - if _, err := os.Stat(kernelSource); err == nil { - kernel, err := os.Open(kernelSource) - if err != nil { - return "", errors.Wrap(err, "could not open kernel") - } - defer kernel.Close() - - gzipreader, err := gzip.NewReader(kernel) - if err == nil { - defer gzipreader.Close() - - writer, err := os.Create(kernelDestination) - if err != nil { - return "", errors.Wrap(err, "could not decompress kernel") - } - defer writer.Close() - - _, err = io.Copy(writer, gzipreader) - if err != nil { - return "", errors.Wrap(err, "could not write decompressed kernel") - } - - } else { - - err := util.CopyFile(kernelSource, kernelDestination) - if err != nil { - return "", errors.Wrap(err, "could not copy kernel") - } - } - - } - - wwlog.Printf(wwlog.VERBOSE, "Building Kernel driver image\n") - if _, err := os.Stat(kernelDrivers); err == nil { - compressor, err := exec.LookPath("pigz") - if err != nil { - wwlog.Printf(wwlog.VERBOSE, "Could not locate PIGZ, using GZIP\n") - compressor = "gzip" - } else { - wwlog.Printf(wwlog.VERBOSE, "Using PIGZ to compress the container: %s\n", compressor) - } - - cmd := fmt.Sprintf("cd %s; find .%s | cpio --quiet -o -L -H newc | %s -c > \"%s\"", root, kernelDriversRelative, compressor, driversDestination) - - wwlog.Printf(wwlog.DEBUG, "RUNNING: %s\n", cmd) - err = exec.Command("/bin/sh", "-c", cmd).Run() - if err != nil { - return "", err - } - } - - wwlog.Printf(wwlog.VERBOSE, "Creating version file\n") - file, err := os.Create(versionDestination) - if err != nil { - return "", errors.Wrap(err, "Failed to create version file") - } - defer file.Close() - _, err = io.WriteString(file, kernelVersion) - if err != nil { - return "", errors.Wrap(err, "Could not write kernel version") - } - err = file.Sync() - if err != nil { - return "", errors.Wrap(err, "Could not sync kernel version") - } - return "Done", nil -} - -func DeleteKernel(name string) error { - fullPath := path.Join(KernelImageTopDir(), name) - - wwlog.Printf(wwlog.VERBOSE, "Removing path: %s\n", fullPath) - return os.RemoveAll(fullPath) -} - -func FindKernelVersion(root string) (string, error) { - for _, searchPath := range kernelSearchPaths { - testPattern := fmt.Sprintf(path.Join(root, searchPath), `*`) - wwlog.Printf(wwlog.VERBOSE, "Looking for kernel version with pattern at: %s\n", testPattern) - potentialKernel, _ := filepath.Glob(testPattern) - if len(potentialKernel) == 0 { - continue - } - for _, foundKernel := range potentialKernel { - wwlog.Printf(wwlog.VERBOSE, "Parsing out kernel version for %s\n", foundKernel) - re := regexp.MustCompile(fmt.Sprintf(path.Join(root, searchPath), `([\w\d-\.]*)`)) - version := re.FindAllStringSubmatch(foundKernel, -1) - if version == nil { - return "", fmt.Errorf("could not parse kernel version") - } - wwlog.Printf(wwlog.VERBOSE, "found kernel version %s\n", version) - return version[0][1], nil - - } - - } - return "", fmt.Errorf("could not find kernel version") - -} diff --git a/internal/pkg/node/constructors.go b/internal/pkg/node/constructors.go index ebf35397..1f73bd98 100644 --- a/internal/pkg/node/constructors.go +++ b/internal/pkg/node/constructors.go @@ -72,7 +72,6 @@ func (config *nodeYaml) FindAllNodes() ([]NodeInfo, error) { n.Id.Set(nodename) n.Comment.Set(node.Comment) n.ContainerName.Set(node.ContainerName) - n.KernelVersion.Set(node.KernelVersion) n.KernelArgs.Set(node.KernelArgs) n.ClusterName.Set(node.ClusterName) n.Ipxe.Set(node.Ipxe) @@ -134,7 +133,6 @@ func (config *nodeYaml) FindAllNodes() ([]NodeInfo, error) { n.Comment.SetAlt(config.NodeProfiles[p].Comment, p) n.ClusterName.SetAlt(config.NodeProfiles[p].ClusterName, p) n.ContainerName.SetAlt(config.NodeProfiles[p].ContainerName, p) - n.KernelVersion.SetAlt(config.NodeProfiles[p].KernelVersion, p) n.KernelArgs.SetAlt(config.NodeProfiles[p].KernelArgs, p) n.Ipxe.SetAlt(config.NodeProfiles[p].Ipxe, p) n.Init.SetAlt(config.NodeProfiles[p].Init, p) @@ -218,7 +216,6 @@ func (config *nodeYaml) FindAllProfiles() ([]NodeInfo, error) { p.ContainerName.Set(profile.ContainerName) p.Ipxe.Set(profile.Ipxe) p.Init.Set(profile.Init) - p.KernelVersion.Set(profile.KernelVersion) p.KernelArgs.Set(profile.KernelArgs) p.IpmiNetmask.Set(profile.IpmiNetmask) p.IpmiPort.Set(profile.IpmiPort) diff --git a/internal/pkg/node/datastructure.go b/internal/pkg/node/datastructure.go index 7b273f82..a55b71f1 100644 --- a/internal/pkg/node/datastructure.go +++ b/internal/pkg/node/datastructure.go @@ -19,7 +19,6 @@ type NodeConf struct { ClusterName string `yaml:"cluster name,omitempty"` ContainerName string `yaml:"container name,omitempty"` Ipxe string `yaml:"ipxe template,omitempty"` - KernelVersion string `yaml:"kernel version,omitempty"` KernelArgs string `yaml:"kernel args,omitempty"` IpmiUserName string `yaml:"ipmi username,omitempty"` IpmiPassword string `yaml:"ipmi password,omitempty"` @@ -71,7 +70,6 @@ type NodeInfo struct { ClusterName Entry ContainerName Entry Ipxe Entry - KernelVersion Entry KernelArgs Entry IpmiIpaddr Entry IpmiNetmask Entry diff --git a/internal/pkg/node/modifiers.go b/internal/pkg/node/modifiers.go index 6502be84..2a147a5d 100644 --- a/internal/pkg/node/modifiers.go +++ b/internal/pkg/node/modifiers.go @@ -60,7 +60,6 @@ func (config *nodeYaml) NodeUpdate(node NodeInfo) error { config.Nodes[nodeID].ClusterName = node.ClusterName.GetReal() config.Nodes[nodeID].Ipxe = node.Ipxe.GetReal() config.Nodes[nodeID].Init = node.Init.GetReal() - config.Nodes[nodeID].KernelVersion = node.KernelVersion.GetReal() config.Nodes[nodeID].KernelArgs = node.KernelArgs.GetReal() config.Nodes[nodeID].IpmiIpaddr = node.IpmiIpaddr.GetReal() config.Nodes[nodeID].IpmiNetmask = node.IpmiNetmask.GetReal() @@ -148,7 +147,6 @@ func (config *nodeYaml) ProfileUpdate(profile NodeInfo) error { config.NodeProfiles[profileID].Ipxe = profile.Ipxe.GetReal() config.NodeProfiles[profileID].Init = profile.Init.GetReal() config.NodeProfiles[profileID].ClusterName = profile.ClusterName.GetReal() - config.NodeProfiles[profileID].KernelVersion = profile.KernelVersion.GetReal() config.NodeProfiles[profileID].KernelArgs = profile.KernelArgs.GetReal() config.NodeProfiles[profileID].IpmiIpaddr = profile.IpmiIpaddr.GetReal() config.NodeProfiles[profileID].IpmiNetmask = profile.IpmiNetmask.GetReal() diff --git a/internal/pkg/overlay/overlay.go b/internal/pkg/overlay/overlay.go index 36083519..08a72065 100644 --- a/internal/pkg/overlay/overlay.go +++ b/internal/pkg/overlay/overlay.go @@ -174,7 +174,6 @@ func BuildOverlay(nodeInfo node.NodeInfo, overlayName string) error { tstruct.Hostname = nodeInfo.Id.Get() tstruct.ClusterName = nodeInfo.ClusterName.Get() tstruct.Container = nodeInfo.ContainerName.Get() - tstruct.KernelVersion = nodeInfo.KernelVersion.Get() tstruct.KernelArgs = nodeInfo.KernelArgs.Get() tstruct.Init = nodeInfo.Init.Get() tstruct.Root = nodeInfo.Root.Get() diff --git a/internal/pkg/warewulfd/ipxe.go b/internal/pkg/warewulfd/ipxe.go index 84c11808..1cb3d605 100644 --- a/internal/pkg/warewulfd/ipxe.go +++ b/internal/pkg/warewulfd/ipxe.go @@ -140,7 +140,6 @@ func IpxeSend(w http.ResponseWriter, req *http.Request) { replace.Hwaddr = rinfo.hwaddr replace.ContainerName = node.ContainerName.Get() replace.KernelArgs = node.KernelArgs.Get() - replace.KernelVersion = node.KernelVersion.Get() err = tmpl.Execute(w, replace) if err != nil { diff --git a/internal/pkg/warewulfd/kernel.go b/internal/pkg/warewulfd/kernel.go index 22958f5f..74286ee7 100644 --- a/internal/pkg/warewulfd/kernel.go +++ b/internal/pkg/warewulfd/kernel.go @@ -2,9 +2,10 @@ package warewulfd import ( "net/http" + "path" "strings" - "github.com/hpcng/warewulf/internal/pkg/kernel" + "github.com/hpcng/warewulf/internal/pkg/container" ) func KernelSend(w http.ResponseWriter, req *http.Request) { @@ -28,10 +29,10 @@ func KernelSend(w http.ResponseWriter, req *http.Request) { return } - if node.KernelVersion.Defined() { - fileName := kernel.KernelImage(node.KernelVersion.Get()) + if node.ContainerName.Defined() { + fileName := container.KernelFind(node.ContainerName.Get()) - updateStatus(node.Id.Get(), "KERNEL", node.KernelVersion.Get(), strings.Split(req.RemoteAddr, ":")[0]) + updateStatus(node.Id.Get(), "KERNEL", path.Base(fileName), strings.Split(req.RemoteAddr, ":")[0]) err := sendFile(w, fileName, node.Id.Get()) if err != nil { diff --git a/internal/pkg/warewulfd/kmods.go b/internal/pkg/warewulfd/kmods.go deleted file mode 100644 index 13ace42b..00000000 --- a/internal/pkg/warewulfd/kmods.go +++ /dev/null @@ -1,45 +0,0 @@ -package warewulfd - -import ( - "net/http" - "strings" - - "github.com/hpcng/warewulf/internal/pkg/kernel" -) - -func KmodsSend(w http.ResponseWriter, req *http.Request) { - rinfo, err := parseReq(req) - if err != nil { - w.WriteHeader(404) - daemonLogf("ERROR: %s\n", err) - return - } - node, err := GetNode(rinfo.hwaddr) - if err != nil { - w.WriteHeader(403) - daemonLogf("ERROR(%s): %s\n", rinfo.hwaddr, err) - return - } - - if node.AssetKey.Defined() && node.AssetKey.Get() != rinfo.assetkey { - w.WriteHeader(404) - daemonLogf("ERROR: Incorrect asset key for node: %s\n", node.Id.Get()) - updateStatus(node.Id.Get(), "KMODS_OVERLAY", "BAD_ASSET", rinfo.ipaddr) - return - } - - if node.KernelVersion.Defined() { - fileName := kernel.KmodsImage(node.KernelVersion.Get()) - - updateStatus(node.Id.Get(), "KMODS_OVERLAY", node.KernelVersion.Get()+".img", strings.Split(req.RemoteAddr, ":")[0]) - - err := sendFile(w, fileName, node.Id.Get()) - if err != nil { - daemonLogf("ERROR: %s\n", err) - } - - } else { - w.WriteHeader(503) - daemonLogf("WARNING: No 'kernel version' set for node %s\n", node.Id.Get()) - } -} diff --git a/internal/pkg/warewulfd/warewulfd.go b/internal/pkg/warewulfd/warewulfd.go index 1600a637..7406d782 100644 --- a/internal/pkg/warewulfd/warewulfd.go +++ b/internal/pkg/warewulfd/warewulfd.go @@ -48,7 +48,6 @@ func RunServer() error { http.HandleFunc("/ipxe/", IpxeSend) http.HandleFunc("/kernel/", KernelSend) - http.HandleFunc("/kmods/", KmodsSend) http.HandleFunc("/container/", ContainerSend) http.HandleFunc("/overlay-system/", SystemOverlaySend) http.HandleFunc("/overlay-runtime/", RuntimeOverlaySend)