Skip to content

Commit 453f28c

Browse files
Merge pull request cri-o#6557 from navisidhu/update_status_command_1
FEAT: Convert status cli as a subcommand of crio
2 parents a3d3edc + 937ed8c commit 453f28c

File tree

17 files changed

+208
-143
lines changed

17 files changed

+208
-143
lines changed

cmd/crio-status/main.go

Lines changed: 5 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ package main
33
import (
44
"fmt"
55
"os"
6-
"strings"
76

8-
"github.com/cri-o/cri-o/internal/client"
97
"github.com/cri-o/cri-o/internal/criocli"
108
"github.com/cri-o/cri-o/internal/version"
119
"github.com/sirupsen/logrus"
@@ -16,13 +14,15 @@ const (
1614
defaultSocket = "/var/run/crio/crio.sock"
1715
idArg = "id"
1816
socketArg = "socket"
17+
18+
deprecatedNotice = "\n[Deprecation Warning: This command has been deprecated and will be removed in future versions. Please use `crio status` instead.]"
1919
)
2020

2121
func main() {
2222
app := cli.NewApp()
2323
app.Name = "crio-status"
2424
app.Authors = []*cli.Author{{Name: "The CRI-O Maintainers"}}
25-
app.Usage = "A tool for CRI-O status retrieval"
25+
app.Usage = "A tool for CRI-O status retrieval" + deprecatedNotice
2626
app.Description = app.Usage
2727

2828
i, err := version.Get(false)
@@ -34,7 +34,7 @@ func main() {
3434
app.CommandNotFound = func(*cli.Context, string) { os.Exit(1) }
3535
app.OnUsageError = func(c *cli.Context, e error, b bool) error { return e }
3636
app.Action = func(c *cli.Context) error {
37-
return fmt.Errorf("expecting a valid subcommand")
37+
return fmt.Errorf("expecting a valid subcommand" + deprecatedNotice)
3838
}
3939

4040
app.Flags = []cli.Flag{
@@ -47,117 +47,10 @@ func main() {
4747
},
4848
}
4949
app.Commands = criocli.DefaultCommands
50-
app.Commands = append(app.Commands, []*cli.Command{{
51-
Action: config,
52-
Aliases: []string{"c"},
53-
Name: "config",
54-
Usage: "Show the configuration of CRI-O as TOML string.",
55-
}, {
56-
Action: containers,
57-
Aliases: []string{"container", "cs", "s"},
58-
Flags: []cli.Flag{&cli.StringFlag{
59-
Name: idArg,
60-
Aliases: []string{"i"},
61-
Usage: "the container ID",
62-
}},
63-
Name: "containers",
64-
Usage: "Display detailed information about the provided container ID.",
65-
}, {
66-
Action: info,
67-
Aliases: []string{"i"},
68-
Name: "info",
69-
Usage: "Retrieve generic information about CRI-O, like the cgroup and storage driver.",
70-
}}...)
50+
app.Commands = append(app.Commands, criocli.StatusCommand.Subcommands...)
7151

7252
if err := app.Run(os.Args); err != nil {
7353
fmt.Fprintln(os.Stderr, err)
7454
os.Exit(1)
7555
}
7656
}
77-
78-
func config(c *cli.Context) error {
79-
crioClient, err := crioClient(c)
80-
if err != nil {
81-
return err
82-
}
83-
84-
info, err := crioClient.ConfigInfo()
85-
if err != nil {
86-
return err
87-
}
88-
89-
fmt.Print(info)
90-
return nil
91-
}
92-
93-
func containers(c *cli.Context) error {
94-
crioClient, err := crioClient(c)
95-
if err != nil {
96-
return err
97-
}
98-
99-
id := c.String(idArg)
100-
if id == "" {
101-
return fmt.Errorf("the argument --%s cannot be empty", idArg)
102-
}
103-
104-
info, err := crioClient.ContainerInfo(c.String(idArg))
105-
if err != nil {
106-
return err
107-
}
108-
109-
fmt.Printf("name: %s\n", info.Name)
110-
fmt.Printf("pid: %d\n", info.Pid)
111-
fmt.Printf("image: %s\n", info.Image)
112-
fmt.Printf("image ref: %s\n", info.ImageRef)
113-
fmt.Printf("created: %v\n", info.CreatedTime)
114-
fmt.Printf("labels:\n")
115-
for k, v := range info.Labels {
116-
fmt.Printf(" %s: %s\n", k, v)
117-
}
118-
fmt.Printf("annotations:\n")
119-
for k, v := range info.Annotations {
120-
fmt.Printf(" %s: %s\n", k, v)
121-
}
122-
fmt.Printf("CRI-O annotations:\n")
123-
for k, v := range info.CrioAnnotations {
124-
fmt.Printf(" %s: %s\n", k, v)
125-
}
126-
fmt.Printf("log path: %s\n", info.LogPath)
127-
fmt.Printf("root: %s\n", info.Root)
128-
fmt.Printf("sandbox: %s\n", info.Sandbox)
129-
fmt.Printf("ips: %s\n", strings.Join(info.IPs, ", "))
130-
131-
return nil
132-
}
133-
134-
func info(c *cli.Context) error {
135-
crioClient, err := crioClient(c)
136-
if err != nil {
137-
return err
138-
}
139-
140-
info, err := crioClient.DaemonInfo()
141-
if err != nil {
142-
return err
143-
}
144-
145-
fmt.Printf("cgroup driver: %s\n", info.CgroupDriver)
146-
fmt.Printf("storage driver: %s\n", info.StorageDriver)
147-
fmt.Printf("storage root: %s\n", info.StorageRoot)
148-
149-
fmt.Printf("default GID mappings (format <container>:<host>:<size>):\n")
150-
for _, m := range info.DefaultIDMappings.Gids {
151-
fmt.Printf(" %d:%d:%d\n", m.ContainerID, m.HostID, m.Size)
152-
}
153-
fmt.Printf("default UID mappings (format <container>:<host>:<size>):\n")
154-
for _, m := range info.DefaultIDMappings.Uids {
155-
fmt.Printf(" %d:%d:%d\n", m.ContainerID, m.HostID, m.Size)
156-
}
157-
158-
return nil
159-
}
160-
161-
func crioClient(c *cli.Context) (client.CrioClient, error) {
162-
return client.New(c.String(socketArg))
163-
}

cmd/crio/main.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,18 +140,19 @@ func main() {
140140
}
141141

142142
sort.Sort(cli.FlagsByName(app.Flags))
143-
sort.Sort(cli.FlagsByName(configCommand.Flags))
143+
sort.Sort(cli.FlagsByName(criocli.ConfigCommand.Flags))
144144

145145
app.Metadata["Env"] = map[string]string{
146146
kubensmnt.EnvName: kubensmntHelp,
147147
}
148148

149149
app.Commands = criocli.DefaultCommands
150150
app.Commands = append(app.Commands, []*cli.Command{
151-
configCommand,
152-
publishCommand,
153-
versionCommand,
154-
wipeCommand,
151+
criocli.ConfigCommand,
152+
criocli.PublishCommand,
153+
criocli.VersionCommand,
154+
criocli.WipeCommand,
155+
criocli.StatusCommand,
155156
}...)
156157

157158
app.Before = func(c *cli.Context) (err error) {

completions/bash/crio

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ md
1010
config
1111
version
1212
wipe
13+
status
1314
help
1415
h
1516
--absent-mount-sources-to-reject

completions/fish/crio-status.fish

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ complete -r -c crio-status -n '__fish_crio-status_no_subcommand' -a 'man' -d 'Ge
2424
complete -c crio-status -n '__fish_seen_subcommand_from markdown md' -f -l help -s h -d 'show help'
2525
complete -r -c crio-status -n '__fish_crio-status_no_subcommand' -a 'markdown md' -d 'Generate the markdown documentation.'
2626
complete -c crio-status -n '__fish_seen_subcommand_from config c' -f -l help -s h -d 'show help'
27-
complete -r -c crio-status -n '__fish_crio-status_no_subcommand' -a 'config c' -d 'Show the configuration of CRI-O as TOML string.'
27+
complete -r -c crio-status -n '__fish_crio-status_no_subcommand' -a 'config c' -d 'Show the configuration of CRI-O as a TOML string.'
2828
complete -c crio-status -n '__fish_seen_subcommand_from containers container cs s' -f -l help -s h -d 'show help'
2929
complete -r -c crio-status -n '__fish_crio-status_no_subcommand' -a 'containers container cs s' -d 'Display detailed information about the provided container ID.'
3030
complete -c crio-status -n '__fish_seen_subcommand_from containers container cs s' -f -l id -s i -r -d 'the container ID'
3131
complete -c crio-status -n '__fish_seen_subcommand_from info i' -f -l help -s h -d 'show help'
32-
complete -r -c crio-status -n '__fish_crio-status_no_subcommand' -a 'info i' -d 'Retrieve generic information about CRI-O, like the cgroup and storage driver.'
32+
complete -r -c crio-status -n '__fish_crio-status_no_subcommand' -a 'info i' -d 'Retrieve generic information about CRI-O, such as the cgroup and storage driver.'
3333
complete -c crio-status -n '__fish_seen_subcommand_from help h' -f -l help -s h -d 'show help'
3434
complete -r -c crio-status -n '__fish_crio-status_no_subcommand' -a 'help h' -d 'Shows a list of commands or help for one command'

completions/fish/crio.fish

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
function __fish_crio_no_subcommand --description 'Test if there has been any subcommand yet'
44
for i in (commandline -opc)
5-
if contains -- $i complete completion help h man markdown md config version wipe help h
5+
if contains -- $i complete completion help h man markdown md config version wipe status config c containers container cs s info i help h
66
return 1
77
end
88
end
@@ -196,5 +196,14 @@ complete -c crio -n '__fish_seen_subcommand_from version' -f -l verbose -s v -d
196196
complete -c crio -n '__fish_seen_subcommand_from wipe' -f -l help -s h -d 'show help'
197197
complete -r -c crio -n '__fish_crio_no_subcommand' -a 'wipe' -d 'wipe CRI-O\'s container and image storage'
198198
complete -c crio -n '__fish_seen_subcommand_from wipe' -f -l force -s f -d 'force wipe by skipping the version check'
199+
complete -r -c crio -n '__fish_crio_no_subcommand' -a 'status' -d 'Display status information'
200+
complete -c crio -n '__fish_seen_subcommand_from status' -l socket -s s -r -d 'absolute path to the unix socket'
201+
complete -c crio -n '__fish_seen_subcommand_from config c' -f -l help -s h -d 'show help'
202+
complete -r -c crio -n '__fish_seen_subcommand_from status' -a 'config c' -d 'Show the configuration of CRI-O as a TOML string.'
203+
complete -c crio -n '__fish_seen_subcommand_from containers container cs s' -f -l help -s h -d 'show help'
204+
complete -r -c crio -n '__fish_seen_subcommand_from status' -a 'containers container cs s' -d 'Display detailed information about the provided container ID.'
205+
complete -c crio -n '__fish_seen_subcommand_from containers container cs s' -f -l id -s i -r -d 'the container ID'
206+
complete -c crio -n '__fish_seen_subcommand_from info i' -f -l help -s h -d 'show help'
207+
complete -r -c crio -n '__fish_seen_subcommand_from status' -a 'info i' -d 'Retrieve generic information about CRI-O, such as the cgroup and storage driver.'
199208
complete -c crio -n '__fish_seen_subcommand_from help h' -f -l help -s h -d 'show help'
200209
complete -r -c crio -n '__fish_crio_no_subcommand' -a 'help h' -d 'Shows a list of commands or help for one command'

completions/zsh/_crio

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ by CRI-O. This allows you to save you current configuration setup and then load
1212
it later with **--config**. Global options will modify the output.'
1313
'version:display detailed version information'
1414
"wipe:wipe CRI-O's container and image storage"
15+
'status:Display status information'
1516
'help:Shows a list of commands or help for one command'
1617
'h:Shows a list of commands or help for one command'
1718
)

completions/zsh/_crio-status

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ _cli_zsh_autocomplete() {
77
'man:Generate the man page documentation.'
88
'markdown:Generate the markdown documentation.'
99
'md:Generate the markdown documentation.'
10-
'config:Show the configuration of CRI-O as TOML string.'
11-
'c:Show the configuration of CRI-O as TOML string.'
10+
'config:Show the configuration of CRI-O as a TOML string.'
11+
'c:Show the configuration of CRI-O as a TOML string.'
1212
'containers:Display detailed information about the provided container ID.'
1313
'container:Display detailed information about the provided container ID.'
1414
'cs:Display detailed information about the provided container ID.'
1515
's:Display detailed information about the provided container ID.'
16-
'info:Retrieve generic information about CRI-O, like the cgroup and storage driver.'
17-
'i:Retrieve generic information about CRI-O, like the cgroup and storage driver.'
16+
'info:Retrieve generic information about CRI-O, such as the cgroup and storage driver.'
17+
'i:Retrieve generic information about CRI-O, such as the cgroup and storage driver.'
1818
'help:Shows a list of commands or help for one command'
1919
'h:Shows a list of commands or help for one command'
2020
)

docs/crio-status.8.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# NAME
66

77
crio-status - A tool for CRI-O status retrieval
8+
[Deprecation Warning: This command has been deprecated and will be removed in future versions. Please use `crio status` instead.]
89

910
# SYNOPSIS
1011

@@ -53,7 +54,7 @@ Shows a list of commands or help for one command
5354

5455
## config, c
5556

56-
Show the configuration of CRI-O as TOML string.
57+
Show the configuration of CRI-O as a TOML string.
5758

5859
## containers, container, cs, s
5960

@@ -63,7 +64,7 @@ Display detailed information about the provided container ID.
6364

6465
## info, i
6566

66-
Retrieve generic information about CRI-O, like the cgroup and storage driver.
67+
Retrieve generic information about CRI-O, such as the cgroup and storage driver.
6768

6869
## help, h
6970

docs/crio.8.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,26 @@ wipe CRI-O's container and image storage
467467

468468
**--force, -f**: force wipe by skipping the version check
469469

470+
## status
471+
472+
Display status information
473+
474+
**--socket, -s**="": absolute path to the unix socket (default: /var/run/crio/crio.sock)
475+
476+
### config, c
477+
478+
Show the configuration of CRI-O as a TOML string.
479+
480+
### containers, container, cs, s
481+
482+
Display detailed information about the provided container ID.
483+
484+
**--id, -i**="": the container ID
485+
486+
### info, i
487+
488+
Retrieve generic information about CRI-O, such as the cgroup and storage driver.
489+
470490
## help, h
471491

472492
Shows a list of commands or help for one command
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
package main
1+
package criocli
22

33
import (
44
"fmt"
55
"os"
66

77
"github.com/cri-o/cri-o/internal/config/migrate"
8-
"github.com/cri-o/cri-o/internal/criocli"
98
"github.com/cri-o/cri-o/pkg/config"
109
"github.com/sirupsen/logrus"
1110
"github.com/urfave/cli/v2"
1211
)
1312

1413
var from string
1514

16-
var configCommand = &cli.Command{
15+
var ConfigCommand = &cli.Command{
1716
Name: "config",
1817
Usage: `Outputs a commented version of the configuration file that could be used
1918
by CRI-O. This allows you to save you current configuration setup and then load
@@ -48,7 +47,7 @@ it later with **--config**. Global options will modify the output.`,
4847
})
4948
logrus.SetLevel(logrus.InfoLevel)
5049

51-
conf, err := criocli.GetConfigFromContext(c)
50+
conf, err := GetConfigFromContext(c)
5251
if err != nil {
5352
return err
5453
}

0 commit comments

Comments
 (0)