diff --git a/CHANGELOG.md b/CHANGELOG.md index 30101940..a36b77a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,12 +5,6 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [development] - -### Changed -- resolv.conf is not copied but now bind mounted (ro) in the container. Additional - mounts can be configured in warewulf.conf - ## [4.4.0] 2023-01-18 ### Added diff --git a/internal/app/wwctl/container/exec/child/main.go b/internal/app/wwctl/container/exec/child/main.go index 65dacdcb..a6bbc152 100644 --- a/internal/app/wwctl/container/exec/child/main.go +++ b/internal/app/wwctl/container/exec/child/main.go @@ -13,6 +13,8 @@ import ( "github.com/hpcng/warewulf/internal/pkg/buildconfig" "github.com/hpcng/warewulf/internal/pkg/container" + "github.com/hpcng/warewulf/internal/pkg/node" + "github.com/hpcng/warewulf/internal/pkg/overlay" "github.com/hpcng/warewulf/internal/pkg/util" "github.com/hpcng/warewulf/internal/pkg/warewulfconf" "github.com/hpcng/warewulf/internal/pkg/wwlog" @@ -56,6 +58,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error { // ignore errors as we are doomed if a tmp dir couldn't be written _ = os.Mkdir(path.Join(tempDir, "work"), os.ModePerm) _ = os.Mkdir(path.Join(tempDir, "lower"), os.ModePerm) + _ = os.Mkdir(path.Join(tempDir, "nodeoverlay"), os.ModePerm) for _, obj := range lowerObjects { newFile := "" if !strings.HasSuffix(obj, "/") { @@ -81,7 +84,8 @@ func CobraRunE(cmd *cobra.Command, args []string) error { if err != nil { return errors.Wrap(err, "failed to mount") } - if len(lowerObjects) != 0 { + ps1Str := fmt.Sprintf("[%s] Warewulf> ", containerName) + if len(lowerObjects) != 0 && nodename == "" { options := fmt.Sprintf("lowerdir=%s,upperdir=%s,workdir=%s", path.Join(tempDir, "lower"), containerPath, path.Join(tempDir, "work")) wwlog.Debug("overlay options: %s", options) @@ -89,11 +93,43 @@ func CobraRunE(cmd *cobra.Command, args []string) error { if err != nil { wwlog.Warn(fmt.Sprintf("Couldn't create overlay for ephermal mount points: %s", err)) } + } else if nodename != "" { + nodeDB, err := node.New() + if err != nil { + wwlog.Error("Could not open node configuration: %s", err) + os.Exit(1) + } + + nodes, err := nodeDB.FindAllNodes() + if err != nil { + wwlog.Error("Could not get node list: %s", err) + os.Exit(1) + } + nodes = node.FilterByName(nodes, []string{nodename}) + if len(nodes) != 1 { + wwlog.Error("No single node idendified with %s", nodename) + os.Exit(1) + } + overlays := nodes[0].SystemOverlay.GetSlice() + overlays = append(overlays, nodes[0].RuntimeOverlay.GetSlice()...) + err = overlay.BuildOverlayIndir(nodes[0], overlays, path.Join(tempDir, "nodeoverlay")) + if err != nil { + wwlog.Error("Could not build overlay: %s", err) + os.Exit(1) + } + options := fmt.Sprintf("lowerdir=%s:%s:%s", + path.Join(tempDir, "lower"), containerPath, path.Join(tempDir, "nodeoverlay")) + wwlog.Debug("overlay options: %s", options) + err = syscall.Mount("overlay", containerPath, "overlay", 0, options) + if err != nil { + wwlog.Warn(fmt.Sprintf("Couldn't create overlay for node render overlay: %s", err)) + os.Exit(1) + } + ps1Str = fmt.Sprintf("[%s|ro|%s] Warewulf> ", containerName, nodename) } - ps1Str := fmt.Sprintf("[%s] Warewulf> ", containerName) - if !util.IsWriteAble(containerPath) { + if !util.IsWriteAble(containerPath) && nodename == "" { wwlog.Verbose("mounting %s ro", containerPath) - ps1Str = fmt.Sprintf("[%s] (ro) Warewulf> ", containerName) + ps1Str = fmt.Sprintf("[%s|ro] Warewulf> ", containerName) err = syscall.Mount(containerPath, containerPath, "", syscall.MS_BIND, "") if err != nil { return errors.Wrap(err, "failed to prepare bind mount") diff --git a/internal/app/wwctl/container/exec/child/root.go b/internal/app/wwctl/container/exec/child/root.go index 7bf8ff63..d7060995 100644 --- a/internal/app/wwctl/container/exec/child/root.go +++ b/internal/app/wwctl/container/exec/child/root.go @@ -11,11 +11,13 @@ var ( Args: cobra.MinimumNArgs(1), FParseErrWhitelist: cobra.FParseErrWhitelist{UnknownFlags: true}, } - binds []string - tempDir string + binds []string + tempDir string + nodename string ) func init() { + baseCmd.Flags().StringVarP(&nodename, "node", "n", "", "create ro overlay for given node") baseCmd.Flags().StringArrayVarP(&binds, "bind", "b", []string{}, "bind points") baseCmd.Flags().StringVar(&tempDir, "tempdir", "", "tempdir") } diff --git a/internal/app/wwctl/container/exec/main.go b/internal/app/wwctl/container/exec/main.go index 5311a307..2324530f 100644 --- a/internal/app/wwctl/container/exec/main.go +++ b/internal/app/wwctl/container/exec/main.go @@ -68,6 +68,9 @@ func CobraRunE(cmd *cobra.Command, args []string) error { for _, b := range binds { allargs = append(allargs, "--bind", b) } + if nodeName != "" { + allargs = append(allargs, "--node", nodeName) + } allargs = append(allargs, args...) containerPath := container.RootFsDir(containerName) diff --git a/internal/app/wwctl/container/exec/root.go b/internal/app/wwctl/container/exec/root.go index ad1cbf4c..e5fc577b 100644 --- a/internal/app/wwctl/container/exec/root.go +++ b/internal/app/wwctl/container/exec/root.go @@ -28,6 +28,7 @@ var ( SyncUser bool binds []string tempDir string + nodeName string ) func init() { @@ -35,6 +36,7 @@ func init() { baseCmd.PersistentFlags().StringArrayVarP(&binds, "bind", "b", []string{}, "Bind a local path into the container (must exist)") baseCmd.PersistentFlags().BoolVar(&SyncUser, "syncuser", false, "Synchronize UIDs/GIDs from host to container") baseCmd.PersistentFlags().StringVar(&tempDir, "tempdir", "", "Use tempdir for constructing the overlay fs (only used if mount points don't exist in container)") + baseCmd.PersistentFlags().StringVarP(&nodeName, "node", "n", "", "Create a read only view of the container for the given node") } // GetRootCommand returns the root cobra.Command for the application.