mirror of
https://github.com/containers/podman.git
synced 2025-06-21 17:38:12 +08:00
Merge pull request #5778 from baude/v2removetemplates
podmanv2 history and image remove templates
This commit is contained in:
@ -8,10 +8,11 @@ import (
|
|||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
"text/template"
|
"text/template"
|
||||||
"time"
|
"time"
|
||||||
|
"unicode"
|
||||||
|
|
||||||
"github.com/containers/libpod/cmd/podmanV2/registry"
|
"github.com/containers/libpod/cmd/podmanV2/registry"
|
||||||
"github.com/containers/libpod/cmd/podmanV2/report"
|
|
||||||
"github.com/containers/libpod/pkg/domain/entities"
|
"github.com/containers/libpod/pkg/domain/entities"
|
||||||
|
"github.com/docker/go-units"
|
||||||
jsoniter "github.com/json-iterator/go"
|
jsoniter "github.com/json-iterator/go"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -86,10 +87,13 @@ func history(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
var hr []historyreporter
|
||||||
|
for _, l := range results.Layers {
|
||||||
|
hr = append(hr, historyreporter{l})
|
||||||
|
}
|
||||||
// Defaults
|
// Defaults
|
||||||
hdr := "ID\tCREATED\tCREATED BY\tSIZE\tCOMMENT\n"
|
hdr := "ID\tCREATED\tCREATED BY\tSIZE\tCOMMENT\n"
|
||||||
row := "{{slice .ID 0 12}}\t{{humanDuration .Created}}\t{{ellipsis .CreatedBy 45}}\t{{.Size}}\t{{.Comment}}\n"
|
row := "{{.ID}}\t{{.Created}}\t{{.CreatedBy}}\t{{.Size}}\t{{.Comment}}\n"
|
||||||
|
|
||||||
if len(opts.format) > 0 {
|
if len(opts.format) > 0 {
|
||||||
hdr = ""
|
hdr = ""
|
||||||
@ -100,9 +104,9 @@ func history(cmd *cobra.Command, args []string) error {
|
|||||||
} else {
|
} else {
|
||||||
switch {
|
switch {
|
||||||
case opts.human:
|
case opts.human:
|
||||||
row = "{{slice .ID 0 12}}\t{{humanDuration .Created}}\t{{ellipsis .CreatedBy 45}}\t{{humanSize .Size}}\t{{.Comment}}\n"
|
row = "{{.ID}}\t{{.Created}}\t{{.CreatedBy}}\t{{.Size}}\t{{.Comment}}\n"
|
||||||
case opts.noTrunc:
|
case opts.noTrunc:
|
||||||
row = "{{.ID}}\t{{humanDuration .Created}}\t{{.CreatedBy}}\t{{humanSize .Size}}\t{{.Comment}}\n"
|
row = "{{.ID}}\t{{.Created}}\t{{.CreatedBy}}\t{{.Size}}\t{{.Comment}}\n"
|
||||||
case opts.quiet:
|
case opts.quiet:
|
||||||
hdr = ""
|
hdr = ""
|
||||||
row = "{{.ID}}\n"
|
row = "{{.ID}}\n"
|
||||||
@ -110,14 +114,40 @@ func history(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
format := hdr + "{{range . }}" + row + "{{end}}"
|
format := hdr + "{{range . }}" + row + "{{end}}"
|
||||||
|
|
||||||
tmpl := template.Must(template.New("report").Funcs(report.PodmanTemplateFuncs()).Parse(format))
|
tmpl := template.Must(template.New("report").Parse(format))
|
||||||
w := tabwriter.NewWriter(os.Stdout, 8, 2, 2, ' ', 0)
|
w := tabwriter.NewWriter(os.Stdout, 8, 2, 2, ' ', 0)
|
||||||
|
err = tmpl.Execute(w, hr)
|
||||||
_, _ = w.Write(report.ReportHeader("id", "created", "created by", "size", "comment"))
|
|
||||||
err = tmpl.Execute(w, results.Layers)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, errors.Wrapf(err, "Failed to print report"))
|
fmt.Fprintln(os.Stderr, errors.Wrapf(err, "Failed to print report"))
|
||||||
}
|
}
|
||||||
w.Flush()
|
w.Flush()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type historyreporter struct {
|
||||||
|
entities.ImageHistoryLayer
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h historyreporter) Created() string {
|
||||||
|
return units.HumanDuration(time.Since(time.Unix(h.ImageHistoryLayer.Created, 0))) + " ago"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h historyreporter) Size() string {
|
||||||
|
s := units.HumanSizeWithPrecision(float64(h.ImageHistoryLayer.Size), 3)
|
||||||
|
i := strings.LastIndexFunc(s, unicode.IsNumber)
|
||||||
|
return s[:i+1] + " " + s[i+1:]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h historyreporter) CreatedBy() string {
|
||||||
|
if len(h.ImageHistoryLayer.CreatedBy) > 45 {
|
||||||
|
return h.ImageHistoryLayer.CreatedBy[:45-3] + "..."
|
||||||
|
}
|
||||||
|
return h.ImageHistoryLayer.CreatedBy
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h historyreporter) ID() string {
|
||||||
|
if !opts.noTrunc && len(h.ImageHistoryLayer.ID) >= 12 {
|
||||||
|
return h.ImageHistoryLayer.ID[0:12]
|
||||||
|
}
|
||||||
|
return h.ImageHistoryLayer.ID
|
||||||
|
}
|
||||||
|
@ -9,10 +9,11 @@ import (
|
|||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
"text/template"
|
"text/template"
|
||||||
"time"
|
"time"
|
||||||
|
"unicode"
|
||||||
|
|
||||||
"github.com/containers/libpod/cmd/podmanV2/registry"
|
"github.com/containers/libpod/cmd/podmanV2/registry"
|
||||||
"github.com/containers/libpod/cmd/podmanV2/report"
|
|
||||||
"github.com/containers/libpod/pkg/domain/entities"
|
"github.com/containers/libpod/pkg/domain/entities"
|
||||||
|
"github.com/docker/go-units"
|
||||||
jsoniter "github.com/json-iterator/go"
|
jsoniter "github.com/json-iterator/go"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
@ -133,16 +134,10 @@ func writeTemplate(imageS []*entities.ImageSummary, err error) error {
|
|||||||
var (
|
var (
|
||||||
hdr, row string
|
hdr, row string
|
||||||
)
|
)
|
||||||
type image struct {
|
imgs := make([]imageReporter, 0, len(imageS))
|
||||||
entities.ImageSummary
|
|
||||||
Repository string `json:"repository,omitempty"`
|
|
||||||
Tag string `json:"tag,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
imgs := make([]image, 0, len(imageS))
|
|
||||||
for _, e := range imageS {
|
for _, e := range imageS {
|
||||||
for _, tag := range e.RepoTags {
|
for _, tag := range e.RepoTags {
|
||||||
var h image
|
var h imageReporter
|
||||||
h.ImageSummary = *e
|
h.ImageSummary = *e
|
||||||
h.Repository, h.Tag = tokenRepoTag(tag)
|
h.Repository, h.Tag = tokenRepoTag(tag)
|
||||||
imgs = append(imgs, h)
|
imgs = append(imgs, h)
|
||||||
@ -160,7 +155,7 @@ func writeTemplate(imageS []*entities.ImageSummary, err error) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
format := hdr + "{{range . }}" + row + "{{end}}"
|
format := hdr + "{{range . }}" + row + "{{end}}"
|
||||||
tmpl := template.Must(template.New("list").Funcs(report.PodmanTemplateFuncs()).Parse(format))
|
tmpl := template.Must(template.New("list").Parse(format))
|
||||||
w := tabwriter.NewWriter(os.Stdout, 8, 2, 2, ' ', 0)
|
w := tabwriter.NewWriter(os.Stdout, 8, 2, 2, ' ', 0)
|
||||||
defer w.Flush()
|
defer w.Flush()
|
||||||
return tmpl.Execute(w, imgs)
|
return tmpl.Execute(w, imgs)
|
||||||
@ -208,7 +203,7 @@ func sortFunc(key string, data []*entities.ImageSummary) func(i, j int) bool {
|
|||||||
|
|
||||||
func imageListFormat(flags listFlagType) (string, string) {
|
func imageListFormat(flags listFlagType) (string, string) {
|
||||||
if flags.quiet {
|
if flags.quiet {
|
||||||
return "", "{{slice .ID 0 12}}\n"
|
return "", "{{.ID}}\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Defaults
|
// Defaults
|
||||||
@ -224,15 +219,15 @@ func imageListFormat(flags listFlagType) (string, string) {
|
|||||||
if flags.noTrunc {
|
if flags.noTrunc {
|
||||||
row += "\tsha256:{{.ID}}"
|
row += "\tsha256:{{.ID}}"
|
||||||
} else {
|
} else {
|
||||||
row += "\t{{slice .ID 0 12}}"
|
row += "\t{{.ID}}"
|
||||||
}
|
}
|
||||||
|
|
||||||
hdr += "\tCREATED\tSIZE"
|
hdr += "\tCREATED\tSIZE"
|
||||||
row += "\t{{humanDuration .Created}}\t{{humanSize .Size}}"
|
row += "\t{{.Created}}\t{{.Size}}"
|
||||||
|
|
||||||
if flags.history {
|
if flags.history {
|
||||||
hdr += "\tHISTORY"
|
hdr += "\tHISTORY"
|
||||||
row += "\t{{if .History}}{{join .History \", \"}}{{else}}<none>{{end}}"
|
row += "\t{{if .History}}{{.History}}{{else}}<none>{{end}}"
|
||||||
}
|
}
|
||||||
|
|
||||||
if flags.readOnly {
|
if flags.readOnly {
|
||||||
@ -249,3 +244,30 @@ func imageListFormat(flags listFlagType) (string, string) {
|
|||||||
row += "\n"
|
row += "\n"
|
||||||
return hdr, row
|
return hdr, row
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type imageReporter struct {
|
||||||
|
Repository string `json:"repository,omitempty"`
|
||||||
|
Tag string `json:"tag,omitempty"`
|
||||||
|
entities.ImageSummary
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i imageReporter) ID() string {
|
||||||
|
if !listFlag.noTrunc && len(i.ImageSummary.ID) >= 12 {
|
||||||
|
return i.ImageSummary.ID[0:12]
|
||||||
|
}
|
||||||
|
return i.ImageSummary.ID
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i imageReporter) Created() string {
|
||||||
|
return units.HumanDuration(time.Since(time.Unix(i.ImageSummary.Created, 0))) + " ago"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i imageReporter) Size() string {
|
||||||
|
s := units.HumanSizeWithPrecision(float64(i.ImageSummary.Size), 3)
|
||||||
|
j := strings.LastIndexFunc(s, unicode.IsNumber)
|
||||||
|
return s[:j+1] + " " + s[j+1:]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i imageReporter) History() string {
|
||||||
|
return strings.Join(i.ImageSummary.History, ", ")
|
||||||
|
}
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
package pods
|
package pods
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
|
||||||
"text/template"
|
|
||||||
|
|
||||||
"github.com/containers/libpod/cmd/podmanV2/registry"
|
"github.com/containers/libpod/cmd/podmanV2/registry"
|
||||||
"github.com/containers/libpod/pkg/domain/entities"
|
"github.com/containers/libpod/pkg/domain/entities"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -21,33 +18,6 @@ var (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
var podFuncMap = template.FuncMap{
|
|
||||||
"numCons": func(cons []*entities.ListPodContainer) int {
|
|
||||||
return len(cons)
|
|
||||||
},
|
|
||||||
"podcids": func(cons []*entities.ListPodContainer) string {
|
|
||||||
var ctrids []string
|
|
||||||
for _, c := range cons {
|
|
||||||
ctrids = append(ctrids, c.Id[:12])
|
|
||||||
}
|
|
||||||
return strings.Join(ctrids, ",")
|
|
||||||
},
|
|
||||||
"podconnames": func(cons []*entities.ListPodContainer) string {
|
|
||||||
var ctrNames []string
|
|
||||||
for _, c := range cons {
|
|
||||||
ctrNames = append(ctrNames, c.Names[:12])
|
|
||||||
}
|
|
||||||
return strings.Join(ctrNames, ",")
|
|
||||||
},
|
|
||||||
"podconstatuses": func(cons []*entities.ListPodContainer) string {
|
|
||||||
var statuses []string
|
|
||||||
for _, c := range cons {
|
|
||||||
statuses = append(statuses, c.Status)
|
|
||||||
}
|
|
||||||
return strings.Join(statuses, ",")
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.Commands = append(registry.Commands, registry.CliCommand{
|
registry.Commands = append(registry.Commands, registry.CliCommand{
|
||||||
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
|
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
|
||||||
|
@ -9,9 +9,11 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/docker/go-units"
|
||||||
|
|
||||||
"github.com/containers/libpod/cmd/podmanV2/registry"
|
"github.com/containers/libpod/cmd/podmanV2/registry"
|
||||||
"github.com/containers/libpod/cmd/podmanV2/report"
|
|
||||||
"github.com/containers/libpod/pkg/domain/entities"
|
"github.com/containers/libpod/pkg/domain/entities"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -65,6 +67,7 @@ func pods(cmd *cobra.Command, args []string) error {
|
|||||||
var (
|
var (
|
||||||
w io.Writer = os.Stdout
|
w io.Writer = os.Stdout
|
||||||
row string
|
row string
|
||||||
|
lpr []ListPodReporter
|
||||||
)
|
)
|
||||||
if cmd.Flag("filter").Changed {
|
if cmd.Flag("filter").Changed {
|
||||||
for _, f := range strings.Split(inputFilters, ",") {
|
for _, f := range strings.Split(inputFilters, ",") {
|
||||||
@ -88,6 +91,10 @@ func pods(cmd *cobra.Command, args []string) error {
|
|||||||
fmt.Println(string(b))
|
fmt.Println(string(b))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, r := range responses {
|
||||||
|
lpr = append(lpr, ListPodReporter{r})
|
||||||
|
}
|
||||||
headers, row := createPodPsOut()
|
headers, row := createPodPsOut()
|
||||||
if psInput.Quiet {
|
if psInput.Quiet {
|
||||||
if noTrunc {
|
if noTrunc {
|
||||||
@ -106,15 +113,14 @@ func pods(cmd *cobra.Command, args []string) error {
|
|||||||
if !psInput.Quiet && !cmd.Flag("format").Changed {
|
if !psInput.Quiet && !cmd.Flag("format").Changed {
|
||||||
format = headers + format
|
format = headers + format
|
||||||
}
|
}
|
||||||
funcs := report.AppendFuncMap(podFuncMap)
|
tmpl, err := template.New("listPods").Parse(format)
|
||||||
tmpl, err := template.New("listPods").Funcs(funcs).Parse(format)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if !psInput.Quiet {
|
if !psInput.Quiet {
|
||||||
w = tabwriter.NewWriter(os.Stdout, 8, 2, 2, ' ', 0)
|
w = tabwriter.NewWriter(os.Stdout, 8, 2, 2, ' ', 0)
|
||||||
}
|
}
|
||||||
if err := tmpl.Execute(w, responses); err != nil {
|
if err := tmpl.Execute(w, lpr); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if flusher, ok := w.(interface{ Flush() error }); ok {
|
if flusher, ok := w.(interface{ Flush() error }); ok {
|
||||||
@ -132,20 +138,19 @@ func createPodPsOut() (string, string) {
|
|||||||
row += "{{slice .Id 0 12}}"
|
row += "{{slice .Id 0 12}}"
|
||||||
}
|
}
|
||||||
|
|
||||||
row += "\t{{.Name}}\t{{.Status}}\t{{humanDurationFromTime .Created}}"
|
row += "\t{{.Name}}\t{{.Status}}\t{{.Created}}"
|
||||||
|
|
||||||
//rowFormat string = "{{slice .Id 0 12}}\t{{.Name}}\t{{.Status}}\t{{humanDurationFromTime .Created}}"
|
|
||||||
if psInput.CtrIds {
|
if psInput.CtrIds {
|
||||||
headers += "\tIDS"
|
headers += "\tIDS"
|
||||||
row += "\t{{podcids .Containers}}"
|
row += "\t{{.ContainerIds}}"
|
||||||
}
|
}
|
||||||
if psInput.CtrNames {
|
if psInput.CtrNames {
|
||||||
headers += "\tNAMES"
|
headers += "\tNAMES"
|
||||||
row += "\t{{podconnames .Containers}}"
|
row += "\t{{.ContainerNames}}"
|
||||||
}
|
}
|
||||||
if psInput.CtrStatus {
|
if psInput.CtrStatus {
|
||||||
headers += "\tSTATUS"
|
headers += "\tSTATUS"
|
||||||
row += "\t{{podconstatuses .Containers}}"
|
row += "\t{{.ContainerStatuses}}"
|
||||||
}
|
}
|
||||||
if psInput.Namespace {
|
if psInput.Namespace {
|
||||||
headers += "\tCGROUP\tNAMESPACES"
|
headers += "\tCGROUP\tNAMESPACES"
|
||||||
@ -153,7 +158,7 @@ func createPodPsOut() (string, string) {
|
|||||||
}
|
}
|
||||||
if !psInput.CtrStatus && !psInput.CtrNames && !psInput.CtrIds {
|
if !psInput.CtrStatus && !psInput.CtrNames && !psInput.CtrIds {
|
||||||
headers += "\t# OF CONTAINERS"
|
headers += "\t# OF CONTAINERS"
|
||||||
row += "\t{{numCons .Containers}}"
|
row += "\t{{.NumberOfContainers}}"
|
||||||
|
|
||||||
}
|
}
|
||||||
headers += "\tINFRA ID\n"
|
headers += "\tINFRA ID\n"
|
||||||
@ -164,3 +169,61 @@ func createPodPsOut() (string, string) {
|
|||||||
}
|
}
|
||||||
return headers, row
|
return headers, row
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListPodReporter is a struct for pod ps output
|
||||||
|
type ListPodReporter struct {
|
||||||
|
*entities.ListPodsReport
|
||||||
|
}
|
||||||
|
|
||||||
|
// Created returns a human readable created time/date
|
||||||
|
func (l ListPodReporter) Created() string {
|
||||||
|
return units.HumanDuration(time.Since(l.ListPodsReport.Created)) + " ago"
|
||||||
|
}
|
||||||
|
|
||||||
|
// NumberofContainers returns an int representation for
|
||||||
|
// the number of containers belonging to the pod
|
||||||
|
func (l ListPodReporter) NumberOfContainers() int {
|
||||||
|
return len(l.Containers)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Added for backwards compatibility with podmanv1
|
||||||
|
func (l ListPodReporter) InfraID() string {
|
||||||
|
return l.InfraId()
|
||||||
|
}
|
||||||
|
|
||||||
|
// InfraId returns the infra container id for the pod
|
||||||
|
// depending on trunc
|
||||||
|
func (l ListPodReporter) InfraId() string {
|
||||||
|
if noTrunc {
|
||||||
|
return l.ListPodsReport.InfraId
|
||||||
|
}
|
||||||
|
return l.ListPodsReport.InfraId[0:12]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l ListPodReporter) ContainerIds() string {
|
||||||
|
var ctrids []string
|
||||||
|
for _, c := range l.Containers {
|
||||||
|
id := c.Id
|
||||||
|
if !noTrunc {
|
||||||
|
id = id[0:12]
|
||||||
|
}
|
||||||
|
ctrids = append(ctrids, id)
|
||||||
|
}
|
||||||
|
return strings.Join(ctrids, ",")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l ListPodReporter) ContainerNames() string {
|
||||||
|
var ctrNames []string
|
||||||
|
for _, c := range l.Containers {
|
||||||
|
ctrNames = append(ctrNames, c.Names)
|
||||||
|
}
|
||||||
|
return strings.Join(ctrNames, ",")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l ListPodReporter) ContainerStatuses() string {
|
||||||
|
var statuses []string
|
||||||
|
for _, c := range l.Containers {
|
||||||
|
statuses = append(statuses, c.Status)
|
||||||
|
}
|
||||||
|
return strings.Join(statuses, ",")
|
||||||
|
}
|
||||||
|
@ -1,73 +0,0 @@
|
|||||||
package report
|
|
||||||
|
|
||||||
import (
|
|
||||||
"strings"
|
|
||||||
"text/template"
|
|
||||||
"time"
|
|
||||||
"unicode"
|
|
||||||
|
|
||||||
"github.com/docker/go-units"
|
|
||||||
)
|
|
||||||
|
|
||||||
var defaultFuncMap = template.FuncMap{
|
|
||||||
"ellipsis": func(s string, length int) string {
|
|
||||||
if len(s) > length {
|
|
||||||
return s[:length-3] + "..."
|
|
||||||
}
|
|
||||||
return s
|
|
||||||
},
|
|
||||||
"humanDuration": func(t int64) string {
|
|
||||||
return units.HumanDuration(time.Since(time.Unix(t, 0))) + " ago"
|
|
||||||
},
|
|
||||||
"humanDurationFromTime": func(t time.Time) string {
|
|
||||||
return units.HumanDuration(time.Since(t)) + " ago"
|
|
||||||
},
|
|
||||||
"humanSize": func(sz int64) string {
|
|
||||||
s := units.HumanSizeWithPrecision(float64(sz), 3)
|
|
||||||
i := strings.LastIndexFunc(s, unicode.IsNumber)
|
|
||||||
return s[:i+1] + " " + s[i+1:]
|
|
||||||
},
|
|
||||||
"join": strings.Join,
|
|
||||||
"lower": strings.ToLower,
|
|
||||||
"rfc3339": func(t int64) string {
|
|
||||||
return time.Unix(t, 0).Format(time.RFC3339)
|
|
||||||
},
|
|
||||||
"replace": strings.Replace,
|
|
||||||
"split": strings.Split,
|
|
||||||
"title": strings.Title,
|
|
||||||
"upper": strings.ToUpper,
|
|
||||||
// TODO: Remove after Go 1.14 port
|
|
||||||
"slice": func(s string, i, j int) string {
|
|
||||||
if i > j || len(s) < i {
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
if len(s) < j {
|
|
||||||
return s[i:]
|
|
||||||
}
|
|
||||||
return s[i:j]
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
func ReportHeader(columns ...string) []byte {
|
|
||||||
hdr := make([]string, len(columns))
|
|
||||||
for i, h := range columns {
|
|
||||||
hdr[i] = strings.ToUpper(h)
|
|
||||||
}
|
|
||||||
return []byte(strings.Join(hdr, "\t") + "\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
func AppendFuncMap(funcMap template.FuncMap) template.FuncMap {
|
|
||||||
merged := PodmanTemplateFuncs()
|
|
||||||
for k, v := range funcMap {
|
|
||||||
merged[k] = v
|
|
||||||
}
|
|
||||||
return merged
|
|
||||||
}
|
|
||||||
|
|
||||||
func PodmanTemplateFuncs() template.FuncMap {
|
|
||||||
merged := make(template.FuncMap)
|
|
||||||
for k, v := range defaultFuncMap {
|
|
||||||
merged[k] = v
|
|
||||||
}
|
|
||||||
return merged
|
|
||||||
}
|
|
@ -508,6 +508,7 @@ var _ = Describe("Podman containers ", func() {
|
|||||||
_, err = bt.RunTopContainer(&name2, &bindings.PFalse, nil)
|
_, err = bt.RunTopContainer(&name2, &bindings.PFalse, nil)
|
||||||
Expect(err).To(BeNil())
|
Expect(err).To(BeNil())
|
||||||
containerLatestList, err := containers.List(bt.conn, nil, nil, &latestContainers, nil, nil, nil)
|
containerLatestList, err := containers.List(bt.conn, nil, nil, &latestContainers, nil, nil, nil)
|
||||||
|
Expect(err).To(BeNil())
|
||||||
err = containers.Kill(bt.conn, containerLatestList[0].Names(), "SIGTERM")
|
err = containers.Kill(bt.conn, containerLatestList[0].Names(), "SIGTERM")
|
||||||
Expect(err).To(BeNil())
|
Expect(err).To(BeNil())
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user