-
Notifications
You must be signed in to change notification settings - Fork 461
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update k8s to 53965 and add verbose
for crictl status
#167
Conversation
Signed-off-by: Yanqiang Miao <[email protected]>
cmd/crictl/status.go
Outdated
@@ -43,8 +51,8 @@ var runtimeStatusCommand = cli.Command{ | |||
} | |||
|
|||
// Status sends a StatusRequest to the server, and parses the returned StatusResponse. | |||
func Status(client pb.RuntimeServiceClient) error { | |||
request := &pb.StatusRequest{} | |||
func Status(client pb.RuntimeServiceClient, verbose bool) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about this.
I think the extra information should be part of crictl info
which is similar with docker info
.
Questions:
- If we already have
crictl info
, do we still need a separatecrictl status
. I think we don't. - How do we display
crictl info
? Do we need to organize the information a little bit or just print json output? I feel like json is good enough for now, we could keep the yaml option. - Whether we should add the
verbose
flag? I feel like we should always retrieve verbose information, and display it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do we display crictl info? Do we need to organize the information a little bit or just print json output? I feel like json is good enough for now, we could keep the yaml option.
In map<string, string> info = 2
, the value have been in json format, so if we encode the info
to json format, the value will not be formatted. Is there any way to make the value formatted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we have both version and status API in CRI, I'm ok with mapping info
command to status API while version
command to version API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we encode the info to json format, the value will not be formatted
what about convert the whole info
to json first and then convert to json or yaml?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also not work, I make a test locally:
func main() {
test := make(map[string]interface{})
test["Int"] = 100
test["String"] = "string"
jsonMap := make(map[string]interface{})
jsonMap["Num"] = 123
jsonMap["Str"] = "abc"
jsonByt, _ := json.Marshal(&jsonMap)
test["JsonStr"] = string(jsonByt)
byt, _ := json.Marshal(&test)
fmt.Println("test-json:\n", string(byt))
marshaledYaml, _ := yaml.Marshal(&test)
fmt.Println("\ntest-yaml:\n",string(marshaledYaml))
strJson := string(byt)
marshaledYaml, _ = yaml.Marshal(&strJson)
fmt.Println("test-yaml-json:\n", string(marshaledYaml))
marshaledJson, _ := json.Marshal(&strJson)
fmt.Println("test-json-json:\n", string(marshaledJson))
}
The results are as follows:
$ go run main.go
test-json:
{"Int":100,"JsonStr":"{\"Num\":123,\"Str\":\"abc\"}","String":"string"}
test-yaml:
Int: 100
JsonStr: '{"Num":123,"Str":"abc"}'
String: string
test-yaml-json:
'{"Int":100,"JsonStr":"{\"Num\":123,\"Str\":\"abc\"}","String":"string"}'
test-json-json:
"{\"Int\":100,\"JsonStr\":\"{\\\"Num\\\":123,\\\"Str\\\":\\\"abc\\\"}\",\"String\":\"string\"}"
cmd/crictl/version.go
Outdated
@@ -30,7 +30,7 @@ const ( | |||
) | |||
|
|||
var runtimeVersionCommand = cli.Command{ | |||
Name: "info", | |||
Name: "version", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with this change.
Agree with you. I have rename |
841ddb6
to
93c8113
Compare
@Random-Liu @feiskyer I have addressed above comments, PTAL
# crictl info
{
"Status": {
"conditions": [
{
"type": "RuntimeReady",
"status": true
},
{
"type": "NetworkReady",
"status": true
}
]
},
"ExtrInfo": null
} |
cmd/crictl/version.go
Outdated
if err != nil { | ||
return fmt.Errorf("Getting status of runtime failed: %v", err) | ||
return fmt.Errorf("Getting the runtime version failed: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/Getting/getting.
It seems that the cri-tools repo doesn't follow convention very well. Let's try to change it gradually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please address this.
cmd/crictl/info.go
Outdated
Usage: "Display runtime version information", | ||
var runtimeStatusCommand = cli.Command{ | ||
Name: "info", | ||
Usage: "Display status and extra information of the container runtime", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Display information of the container runtime.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: change usage according to Random's comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for missing this.
cmd/crictl/info.go
Outdated
if err != nil { | ||
return fmt.Errorf("Getting the runtime version failed: %v", err) | ||
return fmt.Errorf("Getting status of runtime failed: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/Getting/getting
cmd/crictl/info.go
Outdated
|
||
statusInfo := struct { | ||
Status *pb.RuntimeStatus | ||
ExtrInfo map[string]interface{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer combine the extra information into the result directly.
cmd/crictl/info.go
Outdated
if err != nil { | ||
return err | ||
} | ||
statusInfo.ExtrInfo[key] = buf |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess in this way buf
will be escaped, which is not what we want.
@miaoyq Could you verify?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Random-Liu I have verified, it worked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is my validation codes:
package main
import "fmt"
import "encoding/json"
func main() {
test := make(map[string]interface{})
test["Int"] = 100
test["String"] = "string"
jsonMap := make(map[string]interface{})
jsonMap["Num"] = 123
jsonMap["Str"] = "abc"
jsonByt, _ := json.Marshal(&jsonMap)
test["JsonStr"] = string(jsonByt)
var jsonMap1 map[string]interface{}
if err := json.Unmarshal(jsonByt, &jsonMap1); err == nil {
fmt.Println(jsonMap1)
}
test["JsonStr"] = jsonMap1
byt, _ := json.Marshal(&test)
fmt.Println("test-json-New:\n", string(byt))
var testMap map[string]interface{}
if err := json.Unmarshal(byt, &testMap); err == nil {
fmt.Printf("%#v \n",testMap)
}
}
output:
# go run main.go
map[Num:123 Str:abc]
test-json-New:
{"Int":100,"JsonStr":{"Num":123,"Str":"abc"},"String":"string"}
map[string]interface {}{"Int":100, "JsonStr":map[string]interface {}{"Num":123, "Str":"abc"}, "String":"string"}
But seems not strict, I will use your opinion. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The value in map itself could be a json.
@miaoyq @feiskyer Actually we just need to do something like this: package main
import (
"bytes"
"encoding/json"
"os"
)
type Status struct {
Name string
Value string
}
func main() {
status := Status{
Name: "name",
Value: "value",
}
info := map[string]string{
"Pid": "1234",
"Config": `{
"a": "b",
"c": [
"d",
"e"
]
}`,
}
statusB, err := json.Marshal(&status)
if err != nil {
panic(err)
}
value := "{" + "\"Status\":" + string(statusB) + ","
for k, v := range info {
value += "\"" + k + "\"" + ":" + v + ","
}
value = value[:len(value)-1]
value += "}"
var out bytes.Buffer
if err := json.Indent(&out, []byte(value), "", " "); err != nil {
panic(err)
}
out.WriteTo(os.Stdout)
} $ ./test
{
"Status": {
"Name": "name",
"Value": "value"
},
"Pid": 1234,
"Config": {
"a": "b",
"c": [
"d",
"e"
]
}
} The code is ugly, we could clean it up a little bit, but this works. :) |
And we may need to decide whether field should start with capitalized letter or not. |
Cool. @miaoyq could you format json in this way?
Shouldn't we keep consistent with what runtimes returns? |
@feiskyer OK, I'm working on this. |
93c8113
to
75791e8
Compare
@feiskyer @Random-Liu Updated. |
@miaoyq Could you also format output when user chooses yaml format? @Random-Liu Does containerd provide those extra info now? need to verity the output. |
@feiskyer OK. |
75791e8
to
4131c65
Compare
@feiskyer Updated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change LGTM.
@Random-Liu Does containerd provide those extra info now? need to verity the output.
4131c65
to
7403734
Compare
@feiskyer Thanks for reminder, Done. |
Not yet. We are planning to add it this release. @miaoyq Could you add some basic information for |
return err | ||
} | ||
|
||
statusByte, err := json.Marshal(r.Status) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can make this a helper function, because we'll need it for container/sandbox/image status.
I'm fine with doing that in another PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do late. :)
cmd/crictl/version.go
Outdated
if err != nil { | ||
return fmt.Errorf("Getting status of runtime failed: %v", err) | ||
return fmt.Errorf("Getting the runtime version failed: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please address this.
LGTM other than one comment. |
7403734
to
2512e54
Compare
@Random-Liu Addressed. |
…l status` Signed-off-by: Yanqiang Miao <[email protected]>
@Random-Liu Do you means adding some basic information for |
@miaoyq I mean return those information from Then |
/lgtm |
@Random-Liu Ok, got it, thanks. |
Partly fixes #166
info
toversion
verbose
forcrictl status
Maybe we could rename
status
toinfo
./cc @Random-Liu @feiskyer
Signed-off-by: Yanqiang Miao [email protected]