Skip to content

Commit 33d90d2

Browse files
authored
Merge pull request #1898 from Starnop/cri-runtime-status
feature: complete the funtion of runtime status
2 parents a77e0da + 604d953 commit 33d90d2

File tree

2 files changed

+52
-6
lines changed

2 files changed

+52
-6
lines changed

cri/v1alpha1/cri.go

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ package v1alpha1
33
import (
44
"bytes"
55
"context"
6+
"encoding/json"
67
"fmt"
78
"io"
89
"os"
910
"path"
1011
"path/filepath"
1112
"reflect"
13+
goruntime "runtime"
1214
"time"
1315

1416
apitypes "github.com/alibaba/pouch/apis/types"
@@ -71,6 +73,9 @@ const (
7173

7274
// snapshotPlugin implements a snapshotter.
7375
snapshotPlugin = "io.containerd.snapshotter.v1"
76+
77+
// networkNotReadyReason is the reason reported when network is not ready.
78+
networkNotReadyReason = "NetworkPluginNotReady"
7479
)
7580

7681
var (
@@ -917,14 +922,32 @@ func (c *CriManager) Status(ctx context.Context, r *runtime.StatusRequest) (*run
917922
Status: true,
918923
}
919924

920-
// TODO: check network status of CRI when it is ready.
925+
// Check the status of the cni initialization
926+
if err := c.CniMgr.Status(); err != nil {
927+
networkCondition.Status = false
928+
networkCondition.Reason = networkNotReadyReason
929+
networkCondition.Message = fmt.Sprintf("Network plugin returns error: %v", err)
930+
}
921931

922-
return &runtime.StatusResponse{
932+
resp := &runtime.StatusResponse{
923933
Status: &runtime.RuntimeStatus{Conditions: []*runtime.RuntimeCondition{
924934
runtimeCondition,
925935
networkCondition,
926936
}},
927-
}, nil
937+
}
938+
939+
if r.Verbose {
940+
resp.Info = make(map[string]string)
941+
versionByt, err := json.Marshal(goruntime.Version())
942+
if err != nil {
943+
return nil, err
944+
}
945+
resp.Info["golang"] = string(versionByt)
946+
947+
// TODO return more info
948+
}
949+
950+
return resp, nil
928951
}
929952

930953
// ListImages lists existing images.

cri/v1alpha2/cri.go

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ package v1alpha2
33
import (
44
"bytes"
55
"context"
6+
"encoding/json"
67
"fmt"
78
"io"
89
"os"
910
"path"
1011
"path/filepath"
1112
"reflect"
13+
goruntime "runtime"
1214
"time"
1315

1416
apitypes "github.com/alibaba/pouch/apis/types"
@@ -71,6 +73,9 @@ const (
7173

7274
// snapshotPlugin implements a snapshotter.
7375
snapshotPlugin = "io.containerd.snapshotter.v1"
76+
77+
// networkNotReadyReason is the reason reported when network is not ready.
78+
networkNotReadyReason = "NetworkPluginNotReady"
7479
)
7580

7681
var (
@@ -930,14 +935,32 @@ func (c *CriManager) Status(ctx context.Context, r *runtime.StatusRequest) (*run
930935
Status: true,
931936
}
932937

933-
// TODO: check network status of CRI when it is ready.
938+
// Check the status of the cni initialization
939+
if err := c.CniMgr.Status(); err != nil {
940+
networkCondition.Status = false
941+
networkCondition.Reason = networkNotReadyReason
942+
networkCondition.Message = fmt.Sprintf("Network plugin returns error: %v", err)
943+
}
934944

935-
return &runtime.StatusResponse{
945+
resp := &runtime.StatusResponse{
936946
Status: &runtime.RuntimeStatus{Conditions: []*runtime.RuntimeCondition{
937947
runtimeCondition,
938948
networkCondition,
939949
}},
940-
}, nil
950+
}
951+
952+
if r.Verbose {
953+
resp.Info = make(map[string]string)
954+
versionByt, err := json.Marshal(goruntime.Version())
955+
if err != nil {
956+
return nil, err
957+
}
958+
resp.Info["golang"] = string(versionByt)
959+
960+
// TODO return more info
961+
}
962+
963+
return resp, nil
941964
}
942965

943966
// ListImages lists existing images.

0 commit comments

Comments
 (0)