From 5c995f9d0f4b866893b867980fff336fe67f952e Mon Sep 17 00:00:00 2001 From: Gregory Kurtzer Date: Sun, 6 Dec 2020 22:29:25 -0800 Subject: [PATCH] Added `Init` to datastructure, fixups to container interface, and --setdefault to kernel and container build --- Makefile | 2 +- internal/app/wwctl/container/build/main.go | 27 +++++++++++++++++++ internal/app/wwctl/container/build/root.go | 2 ++ .../app/wwctl/container/exec/child/main.go | 2 +- internal/app/wwctl/kernel/build/main.go | 27 +++++++++++++++++++ internal/app/wwctl/kernel/build/root.go | 6 +++-- internal/app/wwctl/node/list/main.go | 1 + internal/app/wwctl/node/set/main.go | 10 +++++++ internal/app/wwctl/node/set/root.go | 2 ++ internal/app/wwctl/profile/list/main.go | 2 ++ internal/app/wwctl/profile/set/main.go | 11 ++++++++ internal/app/wwctl/profile/set/root.go | 3 +++ internal/pkg/container/vnfs.go | 7 +---- internal/pkg/node/constructors.go | 4 +++ internal/pkg/node/datastructure.go | 2 ++ internal/pkg/node/modifiers.go | 2 ++ internal/pkg/overlay/overlay.go | 2 ++ overlays/system/default/{init => init.ww} | 4 +-- 18 files changed, 104 insertions(+), 12 deletions(-) rename overlays/system/default/{init => init.ww} (95%) diff --git a/Makefile b/Makefile index 4675addf..d4e74189 100644 --- a/Makefile +++ b/Makefile @@ -52,7 +52,7 @@ files: all # cp -r tftpboot/* /var/lib/tftpboot/warewulf/ipxe/ # restorecon -r /var/lib/tftpboot/warewulf cp -r overlays /var/warewulf/ - chmod +x /var/warewulf/overlays/system/default/init + chmod +x /var/warewulf/overlays/system/default/init.ww mkdir -p /var/warewulf/overlays/system/default/warewulf/bin/ cp wwclient /var/warewulf/overlays/system/default/warewulf/bin/ diff --git a/internal/app/wwctl/container/build/main.go b/internal/app/wwctl/container/build/main.go index 81b6bb66..236bf712 100644 --- a/internal/app/wwctl/container/build/main.go +++ b/internal/app/wwctl/container/build/main.go @@ -1,7 +1,9 @@ package build import ( + "fmt" "github.com/hpcng/warewulf/internal/pkg/container" + "github.com/hpcng/warewulf/internal/pkg/node" "github.com/hpcng/warewulf/internal/pkg/wwlog" "github.com/spf13/cobra" "os" @@ -25,6 +27,31 @@ func CobraRunE(cmd *cobra.Command, args []string) error { container.Build(c, BuildForce) } + if SetDefault == true { + if len(containers) != 1 { + wwlog.Printf(wwlog.ERROR, "Can only set default for one container\n") + } else { + 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 container name to: %s\n", containers[0]) + profile.ContainerName.Set(containers[0]) + nodeDB.ProfileUpdate(profile) + } + } + nodeDB.Persist() + fmt.Printf("Set default profile to container: %s\n", containers[0]) + } + } + /* var nodes []node.NodeInfo set := make(map[string]int) diff --git a/internal/app/wwctl/container/build/root.go b/internal/app/wwctl/container/build/root.go index f174053d..49ab376b 100644 --- a/internal/app/wwctl/container/build/root.go +++ b/internal/app/wwctl/container/build/root.go @@ -12,11 +12,13 @@ var ( } BuildForce bool BuildAll bool + SetDefault bool ) func init() { baseCmd.PersistentFlags().BoolVarP(&BuildAll, "all", "a", false, "(re)Build all VNFS images for all nodes") baseCmd.PersistentFlags().BoolVarP(&BuildForce, "force", "f", false, "Force rebuild, even if it isn't necessary") + baseCmd.PersistentFlags().BoolVar(&SetDefault, "setdefault", false, "Set this container for the default profile") } // GetRootCommand returns the root cobra.Command for the application. diff --git a/internal/app/wwctl/container/exec/child/main.go b/internal/app/wwctl/container/exec/child/main.go index 928de7a0..64222022 100644 --- a/internal/app/wwctl/container/exec/child/main.go +++ b/internal/app/wwctl/container/exec/child/main.go @@ -1,4 +1,4 @@ -// + build linux +// +build linux package child diff --git a/internal/app/wwctl/kernel/build/main.go b/internal/app/wwctl/kernel/build/main.go index 1e1c474d..39ac088f 100644 --- a/internal/app/wwctl/kernel/build/main.go +++ b/internal/app/wwctl/kernel/build/main.go @@ -1,7 +1,9 @@ package build import ( + "fmt" "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" "os" @@ -17,6 +19,31 @@ func CobraRunE(cmd *cobra.Command, args []string) error { } } + if SetDefault == true { + if len(args) != 1 { + wwlog.Printf(wwlog.ERROR, "Can only set default for one kernel version\n") + } else { + 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]) + nodeDB.ProfileUpdate(profile) + } + } + nodeDB.Persist() + fmt.Printf("Set default kernel version to: %s\n", args[0]) + } + } + /* var nodes []node.NodeInfo set := make(map[string]int) diff --git a/internal/app/wwctl/kernel/build/root.go b/internal/app/wwctl/kernel/build/root.go index 82f04fdf..9e873996 100644 --- a/internal/app/wwctl/kernel/build/root.go +++ b/internal/app/wwctl/kernel/build/root.go @@ -12,13 +12,15 @@ var ( RunE: CobraRunE, Args: cobra.MinimumNArgs(1), } - BuildAll bool - ByNode bool + BuildAll bool + ByNode bool + SetDefault 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") } // GetRootCommand returns the root cobra.Command for the application. diff --git a/internal/app/wwctl/node/list/main.go b/internal/app/wwctl/node/list/main.go index b2103686..4150db2d 100644 --- a/internal/app/wwctl/node/list/main.go +++ b/internal/app/wwctl/node/list/main.go @@ -56,6 +56,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error { fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), "RuntimeOverlay", node.RuntimeOverlay.Source(), node.RuntimeOverlay.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(), "Ipxe", node.Ipxe.Source(), node.Ipxe.Print()) + fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), "Init", node.Init.Source(), node.Init.Print()) fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), "IpmiIpaddr", node.IpmiIpaddr.Source(), node.IpmiIpaddr.Print()) fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), "IpmiNetmask", node.IpmiNetmask.Source(), node.IpmiNetmask.Print()) fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), "IpmiUserName", node.IpmiUserName.Source(), node.IpmiUserName.Print()) diff --git a/internal/app/wwctl/node/set/main.go b/internal/app/wwctl/node/set/main.go index a6dba01b..942620d8 100644 --- a/internal/app/wwctl/node/set/main.go +++ b/internal/app/wwctl/node/set/main.go @@ -84,6 +84,16 @@ func CobraRunE(cmd *cobra.Command, args []string) error { os.Exit(1) } } + if SetInit != "" { + wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting init command to: %s\n", n.Id.Get(), SetInit) + + n.Init.Set(SetInit) + err := nodeDB.NodeUpdate(n) + if err != nil { + wwlog.Printf(wwlog.ERROR, "%s\n", err) + os.Exit(1) + } + } if SetKernel != "" { wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting kernel to: %s\n", n.Id.Get(), SetKernel) diff --git a/internal/app/wwctl/node/set/root.go b/internal/app/wwctl/node/set/root.go index 24cb0f73..c0eff8c5 100644 --- a/internal/app/wwctl/node/set/root.go +++ b/internal/app/wwctl/node/set/root.go @@ -31,6 +31,7 @@ var ( SetAddProfile []string SetDelProfile []string SetForce bool + SetInit string ) func init() { @@ -39,6 +40,7 @@ func init() { baseCmd.PersistentFlags().StringVarP(&SetKernel, "kernel", "K", "", "Set Kernel version 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") + baseCmd.PersistentFlags().StringVarP(&SetInit, "init", "i", "", "Define the init process to boot the container") baseCmd.PersistentFlags().StringVarP(&SetRuntimeOverlay, "runtime", "R", "", "Set the node's runtime overlay") baseCmd.PersistentFlags().StringVarP(&SetSystemOverlay, "system", "S", "", "Set the node's system overlay") baseCmd.PersistentFlags().StringVar(&SetIpmiIpaddr, "ipmi", "", "Set the node's IPMI IP address") diff --git a/internal/app/wwctl/profile/list/main.go b/internal/app/wwctl/profile/list/main.go index 1c4e8762..e4f2e288 100644 --- a/internal/app/wwctl/profile/list/main.go +++ b/internal/app/wwctl/profile/list/main.go @@ -40,6 +40,8 @@ func CobraRunE(cmd *cobra.Command, args []string) error { fmt.Printf("%-20s %-18s %s\n", profile.Id.Get(), "ContainerName", profile.ContainerName.Print()) fmt.Printf("%-20s %-18s %s\n", profile.Id.Get(), "KernelVersion", 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(), "RuntimeOverlay", profile.RuntimeOverlay.Print()) fmt.Printf("%-20s %-18s %s\n", profile.Id.Get(), "SystemOverlay", profile.SystemOverlay.Print()) fmt.Printf("%-20s %-18s %s\n", profile.Id.Get(), "Ipxe", profile.Ipxe.Print()) diff --git a/internal/app/wwctl/profile/set/main.go b/internal/app/wwctl/profile/set/main.go index c146574b..f0573fe6 100644 --- a/internal/app/wwctl/profile/set/main.go +++ b/internal/app/wwctl/profile/set/main.go @@ -98,6 +98,17 @@ func CobraRunE(cmd *cobra.Command, args []string) error { os.Exit(1) } } + if SetInit != "" { + wwlog.Printf(wwlog.VERBOSE, "Profile: %s, Setting init command to: %s\n", p.Id, SetInit) + + p.Init.Set(SetInit) + err := nodeDB.ProfileUpdate(p) + if err != nil { + wwlog.Printf(wwlog.ERROR, "%s\n", err) + os.Exit(1) + } + } + if SetKernel != "" { wwlog.Printf(wwlog.VERBOSE, "Profile: %s, Setting Kernel version to: %s\n", p.Id, SetKernel) diff --git a/internal/app/wwctl/profile/set/root.go b/internal/app/wwctl/profile/set/root.go index cd610b94..8fc2f997 100644 --- a/internal/app/wwctl/profile/set/root.go +++ b/internal/app/wwctl/profile/set/root.go @@ -27,6 +27,7 @@ var ( SetGateway string SetHwaddr string SetNetDevDel bool + SetInit string ) func init() { @@ -35,6 +36,8 @@ func init() { baseCmd.PersistentFlags().StringVarP(&SetKernel, "kernel", "K", "", "Set Kernel version 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") + baseCmd.PersistentFlags().StringVarP(&SetInit, "init", "i", "", "Define the init process to boot the container") + baseCmd.PersistentFlags().StringVarP(&SetRuntimeOverlay, "runtime", "R", "", "Set the node's runtime overlay") baseCmd.PersistentFlags().StringVarP(&SetSystemOverlay, "system", "S", "", "Set the node's system overlay") baseCmd.PersistentFlags().StringVar(&SetIpmiNetmask, "ipminetmask", "", "Set the node's IPMI netmask") diff --git a/internal/pkg/container/vnfs.go b/internal/pkg/container/vnfs.go index 0a3e6991..e86b8e45 100644 --- a/internal/pkg/container/vnfs.go +++ b/internal/pkg/container/vnfs.go @@ -77,12 +77,7 @@ func ValidSource(name string) bool { } if util.IsDir(fullPath) == false { - wwlog.Printf(wwlog.VERBOSE, "Location is not a VNFS source directory: %s\n", name) - return false - } - - if util.IsFile(path.Join(fullPath, "/sbin/init")) == false { - wwlog.Printf(wwlog.VERBOSE, "VNFS Source does not have a valid /sbin/init: %s\n", name) + wwlog.Printf(wwlog.WARN, "Location is not a VNFS source directory: %s\n", name) return false } diff --git a/internal/pkg/node/constructors.go b/internal/pkg/node/constructors.go index c7baedaa..1211b384 100644 --- a/internal/pkg/node/constructors.go +++ b/internal/pkg/node/constructors.go @@ -45,6 +45,7 @@ func (self *nodeYaml) FindAllNodes() ([]NodeInfo, error) { n.SystemOverlay.SetDefault("default") n.RuntimeOverlay.SetDefault("default") n.Ipxe.SetDefault("default") + n.Init.SetDefault("/sbin/init") fullname := strings.SplitN(nodename, ".", 2) if len(fullname) > 1 { @@ -64,6 +65,7 @@ func (self *nodeYaml) FindAllNodes() ([]NodeInfo, error) { n.KernelArgs.Set(node.KernelArgs) n.ClusterName.Set(node.ClusterName) n.Ipxe.Set(node.Ipxe) + n.Init.Set(node.Init) n.IpmiIpaddr.Set(node.IpmiIpaddr) n.IpmiNetmask.Set(node.IpmiNetmask) n.IpmiUserName.Set(node.IpmiUserName) @@ -101,6 +103,7 @@ func (self *nodeYaml) FindAllNodes() ([]NodeInfo, error) { n.KernelVersion.SetAlt(self.NodeProfiles[p].KernelVersion, pstring) n.KernelArgs.SetAlt(self.NodeProfiles[p].KernelArgs, pstring) n.Ipxe.SetAlt(self.NodeProfiles[p].Ipxe, pstring) + n.Init.SetAlt(self.NodeProfiles[p].Init, pstring) n.IpmiIpaddr.SetAlt(self.NodeProfiles[p].IpmiIpaddr, pstring) n.IpmiNetmask.SetAlt(self.NodeProfiles[p].IpmiNetmask, pstring) n.IpmiUserName.SetAlt(self.NodeProfiles[p].IpmiUserName, pstring) @@ -142,6 +145,7 @@ func (self *nodeYaml) FindAllProfiles() ([]NodeInfo, error) { p.Comment.Set(profile.Comment) 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) diff --git a/internal/pkg/node/datastructure.go b/internal/pkg/node/datastructure.go index cd7ea2eb..d4e8077e 100644 --- a/internal/pkg/node/datastructure.go +++ b/internal/pkg/node/datastructure.go @@ -29,6 +29,7 @@ type NodeConf struct { IpmiNetmask string `yaml:"ipmi netmask,omitempty"` RuntimeOverlay string `yaml:"runtime overlay files,omitempty"` SystemOverlay string `yaml:"system overlay files,omitempty"` + Init string `yaml:"init,omitempty"` Profiles []string `yaml:"profiles,omitempty"` NetDevs map[string]*NetDevs `yaml:"network devices,omitempty"` } @@ -70,6 +71,7 @@ type NodeInfo struct { IpmiPassword Entry RuntimeOverlay Entry SystemOverlay Entry + Init Entry //TODO: Finish adding this... Profiles []string GroupProfiles []string NetDevs map[string]*NetDevEntry diff --git a/internal/pkg/node/modifiers.go b/internal/pkg/node/modifiers.go index 9b5773f4..9905f28c 100644 --- a/internal/pkg/node/modifiers.go +++ b/internal/pkg/node/modifiers.go @@ -57,6 +57,7 @@ func (self *nodeYaml) NodeUpdate(node NodeInfo) error { self.Nodes[nodeID].ContainerName = node.ContainerName.GetReal() self.Nodes[nodeID].ClusterName = node.ClusterName.GetReal() self.Nodes[nodeID].Ipxe = node.Ipxe.GetReal() + self.Nodes[nodeID].Init = node.Init.GetReal() self.Nodes[nodeID].KernelVersion = node.KernelVersion.GetReal() self.Nodes[nodeID].KernelArgs = node.KernelArgs.GetReal() self.Nodes[nodeID].IpmiIpaddr = node.IpmiIpaddr.GetReal() @@ -127,6 +128,7 @@ func (self *nodeYaml) ProfileUpdate(profile NodeInfo) error { self.NodeProfiles[profileID].Comment = profile.Comment.GetReal() self.NodeProfiles[profileID].ContainerName = profile.ContainerName.GetReal() self.NodeProfiles[profileID].Ipxe = profile.Ipxe.GetReal() + self.NodeProfiles[profileID].Init = profile.Init.GetReal() self.NodeProfiles[profileID].ClusterName = profile.ClusterName.GetReal() self.NodeProfiles[profileID].KernelVersion = profile.KernelVersion.GetReal() self.NodeProfiles[profileID].KernelArgs = profile.KernelArgs.GetReal() diff --git a/internal/pkg/overlay/overlay.go b/internal/pkg/overlay/overlay.go index 3ac359a4..d133aa14 100644 --- a/internal/pkg/overlay/overlay.go +++ b/internal/pkg/overlay/overlay.go @@ -22,6 +22,7 @@ type TemplateStruct struct { Hostname string GroupName string Container string + Init string IpmiIpaddr string IpmiNetmask string IpmiUserName string @@ -132,6 +133,7 @@ func buildOverlay(nodeList []node.NodeInfo, overlayType string) error { t.Id = n.Id.Get() t.Hostname = n.Id.Get() t.Container = n.ContainerName.Get() + t.Init = n.Init.Get() t.IpmiIpaddr = n.IpmiIpaddr.Get() t.IpmiNetmask = n.IpmiNetmask.Get() t.IpmiUserName = n.IpmiUserName.Get() diff --git a/overlays/system/default/init b/overlays/system/default/init.ww similarity index 95% rename from overlays/system/default/init rename to overlays/system/default/init.ww index 3a21f341..547912b3 100755 --- a/overlays/system/default/init +++ b/overlays/system/default/init.ww @@ -33,8 +33,8 @@ mount -t devtmpfs devtmpfs /dev nohup /warewulf/bin/wwclient >/var/log/wwclient.log 2>&1