From 0b3eace4034e6635b8ed2a26f55aa198eed652fc Mon Sep 17 00:00:00 2001 From: xu yang Date: Tue, 6 Aug 2024 08:15:59 +0000 Subject: [PATCH 1/3] Add syncuser to wwctl container shell and switch to mtime Signed-off-by: xu yang --- CHANGELOG.md | 4 ++++ internal/app/wwctl/container/exec/main.go | 6 +++++- internal/app/wwctl/container/shell/root.go | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b14d43a..c33834a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## v4.5.8, unreleased +### Added + +- Added `--syncuser` flag to `wwctl container shell`. #1358 + ### Changed - Interleave tmpfs across all available NUMA nodes. #1347, #1348 diff --git a/internal/app/wwctl/container/exec/main.go b/internal/app/wwctl/container/exec/main.go index 336218a9..c57cc731 100644 --- a/internal/app/wwctl/container/exec/main.go +++ b/internal/app/wwctl/container/exec/main.go @@ -124,6 +124,10 @@ func CobraRunE(cmd *cobra.Command, args []string) error { } } + // getting syncuser from cmd, e.g., shell comamnd will call exec command and passing --syncuser + if syncUserFlag, err := cmd.Flags().GetBool("syncuser"); err == nil { + SyncUser = SyncUser || syncUserFlag + } userdbChanged := false if !beforePasswdTime.IsZero() { afterPasswdTime := getTime(path.Join(containerPath, "/etc/passwd")) @@ -166,7 +170,7 @@ func getTime(path string) time.Time { return time.Time{} } else { unixStat := fileStat.Sys().(*syscall.Stat_t) - return time.Unix(int64(unixStat.Ctim.Sec), int64(unixStat.Ctim.Nsec)) + return time.Unix(int64(unixStat.Mtim.Sec), int64(unixStat.Mtim.Nsec)) } } diff --git a/internal/app/wwctl/container/shell/root.go b/internal/app/wwctl/container/shell/root.go index e1ae01d3..b6d2e60b 100644 --- a/internal/app/wwctl/container/shell/root.go +++ b/internal/app/wwctl/container/shell/root.go @@ -25,6 +25,7 @@ var ( } binds []string nodeName string + syncUser bool ) func init() { @@ -33,6 +34,7 @@ Bind a local path which must exist into the container. If destination is not set, uses the same path as source. "ro" binds read-only. "copy" temporarily copies the file into the container.`) baseCmd.PersistentFlags().StringVarP(&nodeName, "node", "n", "", "Create a read only view of the container for the given node") + baseCmd.PersistentFlags().BoolVar(&syncUser, "syncuser", false, "Synchronize UIDs/GIDs from host to container") } // GetRootCommand returns the root cobra.Command for the application. From 96119484d855ef61ac9695fa4703fab4d316b50a Mon Sep 17 00:00:00 2001 From: Jonathon Anderson Date: Sat, 14 Sep 2024 22:38:55 -0600 Subject: [PATCH 2/3] Move syncuser pass from shell to exec Signed-off-by: Jonathon Anderson --- internal/app/wwctl/container/exec/main.go | 4 ---- internal/app/wwctl/container/shell/main.go | 6 +----- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/internal/app/wwctl/container/exec/main.go b/internal/app/wwctl/container/exec/main.go index c57cc731..a0d1787e 100644 --- a/internal/app/wwctl/container/exec/main.go +++ b/internal/app/wwctl/container/exec/main.go @@ -124,10 +124,6 @@ func CobraRunE(cmd *cobra.Command, args []string) error { } } - // getting syncuser from cmd, e.g., shell comamnd will call exec command and passing --syncuser - if syncUserFlag, err := cmd.Flags().GetBool("syncuser"); err == nil { - SyncUser = SyncUser || syncUserFlag - } userdbChanged := false if !beforePasswdTime.IsZero() { afterPasswdTime := getTime(path.Join(containerPath, "/etc/passwd")) diff --git a/internal/app/wwctl/container/shell/main.go b/internal/app/wwctl/container/shell/main.go index 2d2cc5a9..d31ecdc6 100644 --- a/internal/app/wwctl/container/shell/main.go +++ b/internal/app/wwctl/container/shell/main.go @@ -22,11 +22,6 @@ func CobraRunE(cmd *cobra.Command, args []string) error { wwlog.Error("Unknown Warewulf container: %s", containerName) os.Exit(1) } - /* - for _, b := range binds { - allargs = append(allargs, "--bind", b) - } - */ shellName := os.Getenv("SHELL") if !container.ValidSource(containerName) { wwlog.Error("Unknown Warewulf container: %s", containerName) @@ -49,5 +44,6 @@ func CobraRunE(cmd *cobra.Command, args []string) error { wwlog.Debug("Calling exec with args: %s", allargs) cntexec.SetBinds(binds) cntexec.SetNode(nodeName) + cntexec.SyncUser = syncUser return cntexec.CobraRunE(cmd, allargs) } From 93dc8e35918189351e9411099f64cac43d2416ff Mon Sep 17 00:00:00 2001 From: Jonathon Anderson Date: Sat, 14 Sep 2024 22:45:42 -0600 Subject: [PATCH 3/3] Update CHANGELOG to indicate mtime change Signed-off-by: Jonathon Anderson --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c33834a8..8271a999 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Changed - Interleave tmpfs across all available NUMA nodes. #1347, #1348 +- Syncuser watches for changes in mtime rather than ctime. #1358 ### Fixed