Merge pull request #1336 from agonzalezro/debug-api
Add extra info to verbose requests to PodSandboxStatus
This commit is contained in:
commit
f7c1adf303
5 changed files with 149 additions and 9 deletions
|
@ -35,15 +35,15 @@ jobs:
|
||||||
go: tip
|
go: tip
|
||||||
- stage: Build and Verify
|
- stage: Build and Verify
|
||||||
script:
|
script:
|
||||||
- make testunit
|
- sudo "PATH=$PATH" make testunit
|
||||||
- make
|
- make
|
||||||
go: 1.8.x
|
go: 1.8.x
|
||||||
- script:
|
- script:
|
||||||
- make testunit
|
- sudo "PATH=$PATH" make testunit
|
||||||
- make
|
- make
|
||||||
go: 1.9.x
|
go: 1.9.x
|
||||||
- script:
|
- script:
|
||||||
- make testunit
|
- sudo "PATH=$PATH" make testunit
|
||||||
- make
|
- make
|
||||||
go: tip
|
go: tip
|
||||||
- stage: Integration Test
|
- stage: Integration Test
|
||||||
|
|
|
@ -10,12 +10,6 @@ import (
|
||||||
|
|
||||||
const fixturePath = "fixtures/crio.conf"
|
const fixturePath = "fixtures/crio.conf"
|
||||||
|
|
||||||
func must(t *testing.T, err error) {
|
|
||||||
if err != nil {
|
|
||||||
t.Error(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func assertAllFieldsEquality(t *testing.T, c Config) {
|
func assertAllFieldsEquality(t *testing.T, c Config) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
fieldValue, expected interface{}
|
fieldValue, expected interface{}
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/kubernetes-incubator/cri-o/oci"
|
"github.com/kubernetes-incubator/cri-o/oci"
|
||||||
|
"github.com/kubernetes-incubator/cri-o/version"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
pb "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2"
|
pb "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2"
|
||||||
|
@ -55,6 +57,25 @@ func (s *Server) PodSandboxStatus(ctx context.Context, req *pb.PodSandboxStatusR
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if req.Verbose {
|
||||||
|
resp = amendVerboseInfo(resp)
|
||||||
|
}
|
||||||
|
|
||||||
logrus.Debugf("PodSandboxStatusResponse: %+v", resp)
|
logrus.Debugf("PodSandboxStatusResponse: %+v", resp)
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// VersionPayload is a helper struct to create the JSON payload to show the version
|
||||||
|
type VersionPayload struct {
|
||||||
|
Version string `json:"version"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func amendVerboseInfo(resp *pb.PodSandboxStatusResponse) *pb.PodSandboxStatusResponse {
|
||||||
|
resp.Info = make(map[string]string)
|
||||||
|
bs, err := json.Marshal(VersionPayload{Version: version.Version})
|
||||||
|
if err != nil {
|
||||||
|
return resp // Just ignore the error and don't marshal the info
|
||||||
|
}
|
||||||
|
resp.Info["version"] = string(bs)
|
||||||
|
return resp
|
||||||
|
}
|
||||||
|
|
119
server/sandbox_status_test.go
Normal file
119
server/sandbox_status_test.go
Normal file
|
@ -0,0 +1,119 @@
|
||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"math/rand"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/kubernetes-incubator/cri-o/lib"
|
||||||
|
"github.com/kubernetes-incubator/cri-o/lib/sandbox"
|
||||||
|
"github.com/kubernetes-incubator/cri-o/oci"
|
||||||
|
"github.com/kubernetes-incubator/cri-o/version"
|
||||||
|
pb "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rand.Seed(time.Now().UTC().UnixNano())
|
||||||
|
}
|
||||||
|
|
||||||
|
func newTestContainerServerOrFailNow(t *testing.T) (cs *lib.ContainerServer, dirsToCleanUp []string) {
|
||||||
|
tmpdir := os.Getenv("TMPDIR")
|
||||||
|
|
||||||
|
config := lib.DefaultConfig()
|
||||||
|
runRoot, err := ioutil.TempDir(tmpdir, "")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
config.RootConfig.RunRoot = runRoot
|
||||||
|
root, err := ioutil.TempDir(tmpdir, "")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
config.RootConfig.Root = root
|
||||||
|
config.RootConfig.Storage = "vfs"
|
||||||
|
cs, err = lib.New(config)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
return cs, []string{runRoot, root}
|
||||||
|
}
|
||||||
|
|
||||||
|
func newTestSandboxOrFailNow(t *testing.T) (string, *sandbox.Sandbox) {
|
||||||
|
id := fmt.Sprintf("id-for-sandbox-%d", rand.Int())
|
||||||
|
|
||||||
|
sb, err := sandbox.New(id, "", "", "", "", nil, nil, "", "", nil, "", "", false, false, "", "", nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
return id, sb
|
||||||
|
}
|
||||||
|
|
||||||
|
func newTestContainerOrFailNow(t *testing.T) *oci.Container {
|
||||||
|
id := fmt.Sprintf("id-for-container-%d", rand.Int())
|
||||||
|
|
||||||
|
c, err := oci.NewContainer(id, "", "", "", nil, nil, nil, nil, "", "", "", nil, "", false, false, false, false, false, "", time.Now(), "")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
func setupServer(t *testing.T) (*Server, string, func()) {
|
||||||
|
containerServer, fs := newTestContainerServerOrFailNow(t)
|
||||||
|
teardown := func() {
|
||||||
|
for _, f := range fs {
|
||||||
|
defer os.RemoveAll(f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
server := &Server{ContainerServer: containerServer}
|
||||||
|
sandboxID, sb := newTestSandboxOrFailNow(t)
|
||||||
|
sb.SetInfraContainer(newTestContainerOrFailNow(t))
|
||||||
|
server.PodIDIndex().Add(sandboxID)
|
||||||
|
server.ContainerServer.AddSandbox(sb)
|
||||||
|
|
||||||
|
return server, sandboxID, teardown
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPodSandboxStatus(t *testing.T) {
|
||||||
|
server, sandboxID, teardown := setupServer(t)
|
||||||
|
defer teardown()
|
||||||
|
|
||||||
|
t.Run("Without verbose information", func(t *testing.T) {
|
||||||
|
resp, err := server.PodSandboxStatus(nil, &pb.PodSandboxStatusRequest{
|
||||||
|
PodSandboxId: sandboxID,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if resp.Status == nil {
|
||||||
|
t.Error("expected non nil resp.Status")
|
||||||
|
}
|
||||||
|
if resp.Info != nil {
|
||||||
|
t.Error("expected nil resp.Info")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("With verbose information", func(t *testing.T) {
|
||||||
|
resp, err := server.PodSandboxStatus(nil, &pb.PodSandboxStatusRequest{
|
||||||
|
PodSandboxId: sandboxID,
|
||||||
|
Verbose: true,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
marshaledVersion := resp.Info["version"]
|
||||||
|
var versionPayload VersionPayload
|
||||||
|
must(t, json.Unmarshal([]byte(marshaledVersion), &versionPayload))
|
||||||
|
|
||||||
|
if version.Version != versionPayload.Version {
|
||||||
|
t.Errorf("expected: %s\ngot: %s", version.Version, versionPayload.Version)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
|
@ -15,6 +15,12 @@ const (
|
||||||
dnsPath = "fixtures/resolv.conf"
|
dnsPath = "fixtures/resolv.conf"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func must(t *testing.T, err error) {
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestParseDNSOptions(t *testing.T) {
|
func TestParseDNSOptions(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
Servers, Searches, Options []string
|
Servers, Searches, Options []string
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue