node option also for shell and respect env $SHELL

This commit is contained in:
Christian Goll
2023-01-31 17:52:42 +01:00
parent 317cd5d4e0
commit 05237935eb
3 changed files with 18 additions and 2 deletions

View File

@@ -48,6 +48,11 @@ func runContainedCmd(args []string) error {
if err := c.Run(); err != nil { if err := c.Run(); err != nil {
fmt.Printf("Command exited non-zero, not rebuilding/updating VNFS image\n") fmt.Printf("Command exited non-zero, not rebuilding/updating VNFS image\n")
// defer is not called before os.Exit(0)
err = os.RemoveAll(tempDir)
if err != nil {
wwlog.Warn("Couldn't remove temp dir for ephermal mounts:", err)
}
os.Exit(0) os.Exit(0)
} }
return nil return nil
@@ -135,3 +140,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
func SetBinds(myBinds []string) { func SetBinds(myBinds []string) {
binds = append(binds, myBinds...) binds = append(binds, myBinds...)
} }
func SetNode(myNode string) {
nodeName = myNode
}

View File

@@ -26,9 +26,14 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
allargs = append(allargs, "--bind", b) allargs = append(allargs, "--bind", b)
} }
*/ */
args = append(args, "/usr/bin/bash") shellName := os.Getenv("SHELL")
if shellName == "" {
shellName = "/usr/bin/bash"
}
args = append(args, shellName)
allargs = append(allargs, args...) allargs = append(allargs, args...)
wwlog.Debug("Calling exec with args: %s", allargs) wwlog.Debug("Calling exec with args: %s", allargs)
cntexec.SetBinds(binds) cntexec.SetBinds(binds)
cntexec.SetNode(nodeName)
return cntexec.CobraRunE(cmd, allargs) return cntexec.CobraRunE(cmd, allargs)
} }

View File

@@ -22,11 +22,13 @@ var (
}, },
FParseErrWhitelist: cobra.FParseErrWhitelist{UnknownFlags: true}, FParseErrWhitelist: cobra.FParseErrWhitelist{UnknownFlags: true},
} }
binds []string binds []string
nodeName string
) )
func init() { func init() {
baseCmd.PersistentFlags().StringArrayVarP(&binds, "bind", "b", []string{}, "Bind a local path into the container (must exist)") baseCmd.PersistentFlags().StringArrayVarP(&binds, "bind", "b", []string{}, "Bind a local path into the container (must exist)")
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. // GetRootCommand returns the root cobra.Command for the application.