Skip to content

Commit b521429

Browse files
authored
Merge pull request containerd#6495 from thaJeztah/improve_versions
strip path-info from `-v` (version) output, and implement -v flag for containerd-shim
2 parents 4fbdb40 + fdbfde5 commit b521429

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

cmd/containerd-shim/main_unix.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import (
4242
"github.com/containerd/containerd/runtime/v1/shim"
4343
shimapi "github.com/containerd/containerd/runtime/v1/shim/v1"
4444
"github.com/containerd/containerd/sys/reaper"
45+
"github.com/containerd/containerd/version"
4546
"github.com/containerd/ttrpc"
4647
"github.com/containerd/typeurl"
4748
ptypes "github.com/gogo/protobuf/types"
@@ -52,6 +53,7 @@ import (
5253

5354
var (
5455
debugFlag bool
56+
versionFlag bool
5557
namespaceFlag string
5658
socketFlag string
5759
addressFlag string
@@ -68,8 +70,9 @@ var (
6870
}
6971
)
7072

71-
func init() {
73+
func parseFlags() {
7274
flag.BoolVar(&debugFlag, "debug", false, "enable debug output in logs")
75+
flag.BoolVar(&versionFlag, "v", false, "show the shim version and exit")
7376
flag.StringVar(&namespaceFlag, "namespace", "", "namespace that owns the shim")
7477
flag.StringVar(&socketFlag, "socket", "", "socket path to serve")
7578
flag.StringVar(&addressFlag, "address", "", "grpc address back to main containerd")
@@ -83,23 +86,36 @@ func init() {
8386
flag.Parse()
8487
}
8588

86-
func main() {
89+
func setRuntime() {
8790
debug.SetGCPercent(40)
8891
go func() {
8992
for range time.Tick(30 * time.Second) {
9093
debug.FreeOSMemory()
9194
}
9295
}()
93-
94-
if debugFlag {
95-
logrus.SetLevel(logrus.DebugLevel)
96-
}
97-
9896
if os.Getenv("GOMAXPROCS") == "" {
9997
// If GOMAXPROCS hasn't been set, we default to a value of 2 to reduce
10098
// the number of Go stacks present in the shim.
10199
runtime.GOMAXPROCS(2)
102100
}
101+
}
102+
103+
func main() {
104+
parseFlags()
105+
if versionFlag {
106+
fmt.Println("containerd-shim")
107+
fmt.Println(" Version: ", version.Version)
108+
fmt.Println(" Revision:", version.Revision)
109+
fmt.Println(" Go version:", version.GoVersion)
110+
fmt.Println("")
111+
return
112+
}
113+
114+
setRuntime()
115+
116+
if debugFlag {
117+
logrus.SetLevel(logrus.DebugLevel)
118+
}
103119

104120
stdout, stderr, err := openStdioKeepAlivePipes(workdirFlag)
105121
if err != nil {

integration/images/volume-ownership/tools/get_owner_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626

2727
func main() {
2828
if len(os.Args) != 2 {
29-
fmt.Printf("Usage: %s file_or_directory\n", os.Args[0])
29+
fmt.Println("Usage: get_owner_windows.exe file_or_directory")
3030
os.Exit(1)
3131
}
3232

runtime/v2/shim/shim.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"fmt"
2424
"io"
2525
"os"
26+
"path/filepath"
2627
"runtime"
2728
"runtime/debug"
2829
"strings"
@@ -240,7 +241,7 @@ func RunManager(ctx context.Context, manager Manager, opts ...BinaryOpts) {
240241
func run(ctx context.Context, manager Manager, initFunc Init, name string, config Config) error {
241242
parseFlags()
242243
if versionFlag {
243-
fmt.Printf("%s:\n", os.Args[0])
244+
fmt.Printf("%s:\n", filepath.Base(os.Args[0]))
244245
fmt.Println(" Version: ", version.Version)
245246
fmt.Println(" Revision:", version.Revision)
246247
fmt.Println(" Go version:", version.GoVersion)

0 commit comments

Comments
 (0)