cmd/containerd-shim: add -v (version) flag
Unlike the other shims, containerd-shim did not have a -v (version) flag:
./bin/containerd-shim-runc-v1 -v
./bin/containerd-shim-runc-v1:
Version: v1.6.0-rc.1
Revision: ad771115b82a70cfd8018d72ae489c707e63de16.m
Go version: go1.17.2
./bin/containerd-shim -v
flag provided but not defined: -v
Usage of ./bin/containerd-shim:
This patch adds a `-v` flag to be consistent with the other shims. The code was
slightly refactored to match the implementation in the other shims, taking the
same approach as 77d53d2d23/runtime/v2/shim/shim.go (L240-L256)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
e79aba10d4
commit
fdbfde5d81
@ -42,6 +42,7 @@ import (
|
|||||||
"github.com/containerd/containerd/runtime/v1/shim"
|
"github.com/containerd/containerd/runtime/v1/shim"
|
||||||
shimapi "github.com/containerd/containerd/runtime/v1/shim/v1"
|
shimapi "github.com/containerd/containerd/runtime/v1/shim/v1"
|
||||||
"github.com/containerd/containerd/sys/reaper"
|
"github.com/containerd/containerd/sys/reaper"
|
||||||
|
"github.com/containerd/containerd/version"
|
||||||
"github.com/containerd/ttrpc"
|
"github.com/containerd/ttrpc"
|
||||||
"github.com/containerd/typeurl"
|
"github.com/containerd/typeurl"
|
||||||
ptypes "github.com/gogo/protobuf/types"
|
ptypes "github.com/gogo/protobuf/types"
|
||||||
@ -52,6 +53,7 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
debugFlag bool
|
debugFlag bool
|
||||||
|
versionFlag bool
|
||||||
namespaceFlag string
|
namespaceFlag string
|
||||||
socketFlag string
|
socketFlag string
|
||||||
addressFlag string
|
addressFlag string
|
||||||
@ -68,8 +70,9 @@ var (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func parseFlags() {
|
||||||
flag.BoolVar(&debugFlag, "debug", false, "enable debug output in logs")
|
flag.BoolVar(&debugFlag, "debug", false, "enable debug output in logs")
|
||||||
|
flag.BoolVar(&versionFlag, "v", false, "show the shim version and exit")
|
||||||
flag.StringVar(&namespaceFlag, "namespace", "", "namespace that owns the shim")
|
flag.StringVar(&namespaceFlag, "namespace", "", "namespace that owns the shim")
|
||||||
flag.StringVar(&socketFlag, "socket", "", "socket path to serve")
|
flag.StringVar(&socketFlag, "socket", "", "socket path to serve")
|
||||||
flag.StringVar(&addressFlag, "address", "", "grpc address back to main containerd")
|
flag.StringVar(&addressFlag, "address", "", "grpc address back to main containerd")
|
||||||
@ -83,23 +86,36 @@ func init() {
|
|||||||
flag.Parse()
|
flag.Parse()
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func setRuntime() {
|
||||||
debug.SetGCPercent(40)
|
debug.SetGCPercent(40)
|
||||||
go func() {
|
go func() {
|
||||||
for range time.Tick(30 * time.Second) {
|
for range time.Tick(30 * time.Second) {
|
||||||
debug.FreeOSMemory()
|
debug.FreeOSMemory()
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if debugFlag {
|
|
||||||
logrus.SetLevel(logrus.DebugLevel)
|
|
||||||
}
|
|
||||||
|
|
||||||
if os.Getenv("GOMAXPROCS") == "" {
|
if os.Getenv("GOMAXPROCS") == "" {
|
||||||
// If GOMAXPROCS hasn't been set, we default to a value of 2 to reduce
|
// If GOMAXPROCS hasn't been set, we default to a value of 2 to reduce
|
||||||
// the number of Go stacks present in the shim.
|
// the number of Go stacks present in the shim.
|
||||||
runtime.GOMAXPROCS(2)
|
runtime.GOMAXPROCS(2)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
parseFlags()
|
||||||
|
if versionFlag {
|
||||||
|
fmt.Println("containerd-shim")
|
||||||
|
fmt.Println(" Version: ", version.Version)
|
||||||
|
fmt.Println(" Revision:", version.Revision)
|
||||||
|
fmt.Println(" Go version:", version.GoVersion)
|
||||||
|
fmt.Println("")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
setRuntime()
|
||||||
|
|
||||||
|
if debugFlag {
|
||||||
|
logrus.SetLevel(logrus.DebugLevel)
|
||||||
|
}
|
||||||
|
|
||||||
stdout, stderr, err := openStdioKeepAlivePipes(workdirFlag)
|
stdout, stderr, err := openStdioKeepAlivePipes(workdirFlag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user