Merge pull request #6495 from thaJeztah/improve_versions

strip path-info from `-v` (version) output, and implement -v flag for containerd-shim
This commit is contained in:
Phil Estes 2022-03-08 13:57:34 -05:00 committed by GitHub
commit b521429b67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 9 deletions

View File

@ -42,6 +42,7 @@ import (
"github.com/containerd/containerd/runtime/v1/shim"
shimapi "github.com/containerd/containerd/runtime/v1/shim/v1"
"github.com/containerd/containerd/sys/reaper"
"github.com/containerd/containerd/version"
"github.com/containerd/ttrpc"
"github.com/containerd/typeurl"
ptypes "github.com/gogo/protobuf/types"
@ -52,6 +53,7 @@ import (
var (
debugFlag bool
versionFlag bool
namespaceFlag string
socketFlag string
addressFlag string
@ -68,8 +70,9 @@ var (
}
)
func init() {
func parseFlags() {
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(&socketFlag, "socket", "", "socket path to serve")
flag.StringVar(&addressFlag, "address", "", "grpc address back to main containerd")
@ -83,23 +86,36 @@ func init() {
flag.Parse()
}
func main() {
func setRuntime() {
debug.SetGCPercent(40)
go func() {
for range time.Tick(30 * time.Second) {
debug.FreeOSMemory()
}
}()
if debugFlag {
logrus.SetLevel(logrus.DebugLevel)
}
if os.Getenv("GOMAXPROCS") == "" {
// If GOMAXPROCS hasn't been set, we default to a value of 2 to reduce
// the number of Go stacks present in the shim.
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)
if err != nil {

View File

@ -26,7 +26,7 @@ import (
func main() {
if len(os.Args) != 2 {
fmt.Printf("Usage: %s file_or_directory\n", os.Args[0])
fmt.Println("Usage: get_owner_windows.exe file_or_directory")
os.Exit(1)
}

View File

@ -23,6 +23,7 @@ import (
"fmt"
"io"
"os"
"path/filepath"
"runtime"
"runtime/debug"
"strings"
@ -240,7 +241,7 @@ func RunManager(ctx context.Context, manager Manager, opts ...BinaryOpts) {
func run(ctx context.Context, manager Manager, initFunc Init, name string, config Config) error {
parseFlags()
if versionFlag {
fmt.Printf("%s:\n", os.Args[0])
fmt.Printf("%s:\n", filepath.Base(os.Args[0]))
fmt.Println(" Version: ", version.Version)
fmt.Println(" Revision:", version.Revision)
fmt.Println(" Go version:", version.GoVersion)