From 0b3eace4034e6635b8ed2a26f55aa198eed652fc Mon Sep 17 00:00:00 2001 From: xu yang Date: Tue, 6 Aug 2024 08:15:59 +0000 Subject: [PATCH] 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.