adds help for load command (#383)
* adds help for load command Signed-off-by: Mike Brown <brownwm@us.ibm.com> * vendor restrom/dedent Signed-off-by: Mike Brown <brownwm@us.ibm.com>
This commit is contained in:
parent
4fa0975f9d
commit
df6f4a3655
@ -26,11 +26,13 @@ import (
|
|||||||
"os/signal"
|
"os/signal"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/docker/docker/pkg/reexec"
|
"github.com/docker/docker/pkg/reexec"
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
"github.com/opencontainers/selinux/go-selinux"
|
"github.com/opencontainers/selinux/go-selinux"
|
||||||
|
"github.com/renstrom/dedent"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
"k8s.io/kubernetes/pkg/util/interrupt"
|
"k8s.io/kubernetes/pkg/util/interrupt"
|
||||||
@ -58,6 +60,30 @@ var cmd = &cobra.Command{
|
|||||||
Long: desc,
|
Long: desc,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
loadLong = dedent.Dedent(`
|
||||||
|
Help for "load TAR" command
|
||||||
|
|
||||||
|
TAR - The path to a tar archive containing a container image.
|
||||||
|
|
||||||
|
Requirement:
|
||||||
|
Containerd and cri-containerd daemons (grpc servers) must already be up and
|
||||||
|
running before the load command is used.
|
||||||
|
|
||||||
|
Description:
|
||||||
|
Running as a client, cri-containerd implements the load command by sending the
|
||||||
|
load request to the already running cri-containerd daemon/server, which in
|
||||||
|
turn loads the image into containerd's image storage via the already running
|
||||||
|
containerd daemon.`)
|
||||||
|
|
||||||
|
loadExample = dedent.Dedent(`
|
||||||
|
- use docker to pull the latest busybox image and save it as a tar archive:
|
||||||
|
$ docker pull busybox:latest
|
||||||
|
$ docker save busybox:latest -o busybox.tar
|
||||||
|
- use cri-containerd to load the image into containerd's image storage:
|
||||||
|
$ cri-containerd load busybox.tar`)
|
||||||
|
)
|
||||||
|
|
||||||
// Add golang flags as persistent flags.
|
// Add golang flags as persistent flags.
|
||||||
func init() {
|
func init() {
|
||||||
cmd.PersistentFlags().AddGoFlagSet(flag.CommandLine)
|
cmd.PersistentFlags().AddGoFlagSet(flag.CommandLine)
|
||||||
@ -85,10 +111,13 @@ func versionCommand() *cobra.Command {
|
|||||||
|
|
||||||
func loadImageCommand() *cobra.Command {
|
func loadImageCommand() *cobra.Command {
|
||||||
c := &cobra.Command{
|
c := &cobra.Command{
|
||||||
Use: "load TAR",
|
Use: "load TAR",
|
||||||
Short: "Load an image from a tar archive.",
|
Long: loadLong,
|
||||||
Args: cobra.ExactArgs(1),
|
Short: "Load an image from a tar archive.",
|
||||||
|
Args: cobra.ExactArgs(1),
|
||||||
|
Example: loadExample,
|
||||||
}
|
}
|
||||||
|
c.SetUsageTemplate(strings.Replace(c.UsageTemplate(), "Examples:", "Example:", 1))
|
||||||
endpoint, timeout := options.AddGRPCFlags(c.Flags())
|
endpoint, timeout := options.AddGRPCFlags(c.Flags())
|
||||||
c.RunE = func(cmd *cobra.Command, args []string) error {
|
c.RunE = func(cmd *cobra.Command, args []string) error {
|
||||||
cl, err := client.NewCRIContainerdClient(*endpoint, *timeout)
|
cl, err := client.NewCRIContainerdClient(*endpoint, *timeout)
|
||||||
|
@ -29,14 +29,14 @@ import (
|
|||||||
// NewCRIContainerdClient creates grpc client of cri-containerd
|
// NewCRIContainerdClient creates grpc client of cri-containerd
|
||||||
// TODO(random-liu): Wrap grpc functions.
|
// TODO(random-liu): Wrap grpc functions.
|
||||||
func NewCRIContainerdClient(endpoint string, timeout time.Duration) (api.CRIContainerdServiceClient, error) {
|
func NewCRIContainerdClient(endpoint string, timeout time.Duration) (api.CRIContainerdServiceClient, error) {
|
||||||
addr, dailer, err := util.GetAddressAndDialer(endpoint)
|
addr, dialer, err := util.GetAddressAndDialer(endpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to get dialer: %v", err)
|
return nil, fmt.Errorf("failed to get dialer: %v", err)
|
||||||
}
|
}
|
||||||
conn, err := grpc.Dial(addr,
|
conn, err := grpc.Dial(addr,
|
||||||
grpc.WithInsecure(),
|
grpc.WithInsecure(),
|
||||||
grpc.WithTimeout(timeout),
|
grpc.WithTimeout(timeout),
|
||||||
grpc.WithDialer(dailer),
|
grpc.WithDialer(dialer),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to dial: %v", err)
|
return nil, fmt.Errorf("failed to dial: %v", err)
|
||||||
|
@ -47,7 +47,8 @@ github.com/pkg/errors v0.8.0
|
|||||||
github.com/pmezard/go-difflib v1.0.0
|
github.com/pmezard/go-difflib v1.0.0
|
||||||
github.com/PuerkitoBio/purell v1.0.0
|
github.com/PuerkitoBio/purell v1.0.0
|
||||||
github.com/PuerkitoBio/urlesc 5bd2802263f21d8788851d5305584c82a5c75d7e
|
github.com/PuerkitoBio/urlesc 5bd2802263f21d8788851d5305584c82a5c75d7e
|
||||||
github.com/seccomp/libseccomp-golang 32f571b70023028bd57d9288c20efbcb237f3ce0
|
github.com/renstrom/dedent 020d11c3b9c0c7a3c2efcc8e5cf5b9ef7bcea21f
|
||||||
|
github.com/seccomp/libseccomp-golang 32f571b70023028bd57d9288c20efbcb237f3ce0
|
||||||
github.com/sirupsen/logrus v1.0.0
|
github.com/sirupsen/logrus v1.0.0
|
||||||
github.com/spf13/cobra v0.0.1
|
github.com/spf13/cobra v0.0.1
|
||||||
github.com/spf13/pflag v1.0.0
|
github.com/spf13/pflag v1.0.0
|
||||||
|
21
vendor/github.com/renstrom/dedent/LICENSE
generated
vendored
Normal file
21
vendor/github.com/renstrom/dedent/LICENSE
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2015 Peter Renström
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
50
vendor/github.com/renstrom/dedent/README.md
generated
vendored
Normal file
50
vendor/github.com/renstrom/dedent/README.md
generated
vendored
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
# Dedent
|
||||||
|
|
||||||
|
[](https://travis-ci.org/renstrom/dedent)
|
||||||
|
[](https://godoc.org/github.com/renstrom/dedent)
|
||||||
|
|
||||||
|
Removes common leading whitespace from multiline strings. Inspired by [`textwrap.dedent`](https://docs.python.org/3/library/textwrap.html#textwrap.dedent) in Python.
|
||||||
|
|
||||||
|
## Usage / example
|
||||||
|
|
||||||
|
Imagine the following snippet that prints a multiline string. You want the indentation to both look nice in the code as well as in the actual output.
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/renstrom/dedent"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
s := `Lorem ipsum dolor sit amet,
|
||||||
|
consectetur adipiscing elit.
|
||||||
|
Curabitur justo tellus, facilisis nec efficitur dictum,
|
||||||
|
fermentum vitae ligula. Sed eu convallis sapien.`
|
||||||
|
fmt.Println(dedent.Dedent(s))
|
||||||
|
fmt.Println("-------------")
|
||||||
|
fmt.Println(s)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
To illustrate the difference, here's the output:
|
||||||
|
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ go run main.go
|
||||||
|
Lorem ipsum dolor sit amet,
|
||||||
|
consectetur adipiscing elit.
|
||||||
|
Curabitur justo tellus, facilisis nec efficitur dictum,
|
||||||
|
fermentum vitae ligula. Sed eu convallis sapien.
|
||||||
|
-------------
|
||||||
|
Lorem ipsum dolor sit amet,
|
||||||
|
consectetur adipiscing elit.
|
||||||
|
Curabitur justo tellus, facilisis nec efficitur dictum,
|
||||||
|
fermentum vitae ligula. Sed eu convallis sapien.
|
||||||
|
```
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
MIT
|
49
vendor/github.com/renstrom/dedent/dedent.go
generated
vendored
Normal file
49
vendor/github.com/renstrom/dedent/dedent.go
generated
vendored
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
package dedent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
whitespaceOnly = regexp.MustCompile("(?m)^[ \t]+$")
|
||||||
|
leadingWhitespace = regexp.MustCompile("(?m)(^[ \t]*)(?:[^ \t\n])")
|
||||||
|
)
|
||||||
|
|
||||||
|
// Dedent removes any common leading whitespace from every line in text.
|
||||||
|
//
|
||||||
|
// This can be used to make multiline strings to line up with the left edge of
|
||||||
|
// the display, while still presenting them in the source code in indented
|
||||||
|
// form.
|
||||||
|
func Dedent(text string) string {
|
||||||
|
var margin string
|
||||||
|
|
||||||
|
text = whitespaceOnly.ReplaceAllString(text, "")
|
||||||
|
indents := leadingWhitespace.FindAllStringSubmatch(text, -1)
|
||||||
|
|
||||||
|
// Look for the longest leading string of spaces and tabs common to all
|
||||||
|
// lines.
|
||||||
|
for i, indent := range indents {
|
||||||
|
if i == 0 {
|
||||||
|
margin = indent[1]
|
||||||
|
} else if strings.HasPrefix(indent[1], margin) {
|
||||||
|
// Current line more deeply indented than previous winner:
|
||||||
|
// no change (previous winner is still on top).
|
||||||
|
continue
|
||||||
|
} else if strings.HasPrefix(margin, indent[1]) {
|
||||||
|
// Current line consistent with and no deeper than previous winner:
|
||||||
|
// it's the new winner.
|
||||||
|
margin = indent[1]
|
||||||
|
} else {
|
||||||
|
// Current line and previous winner have no common whitespace:
|
||||||
|
// there is no margin.
|
||||||
|
margin = ""
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if margin != "" {
|
||||||
|
text = regexp.MustCompile("(?m)^"+margin).ReplaceAllString(text, "")
|
||||||
|
}
|
||||||
|
return text
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user