@@ -37,62 +37,11 @@ func newRemoteRuntimeService(endpoint string, connectionTimeout time.Duration) (
3737 }, nil
3838}
3939
40- func (r * remoteRuntimeService ) getRunningKubeletContainers () ([]* runtimeapi.Container , error ) {
41- filter := & runtimeapi.ContainerFilter {}
42-
43- // Filter out non-running containers
44- filter .State = & runtimeapi.ContainerStateValue {
45- State : runtimeapi .ContainerState_CONTAINER_RUNNING ,
46- }
47-
48- return r .listContainers (filter )
49- }
50-
51- func (r * remoteRuntimeService ) getRunningKubeletSandboxes () ([]* runtimeapi.PodSandbox , error ) {
52- filter := & runtimeapi.PodSandboxFilter {}
53-
54- // Filter out non-running sandboxes
55- filter .State = & runtimeapi.PodSandboxStateValue {
56- State : runtimeapi .PodSandboxState_SANDBOX_READY ,
57- }
58- return r .listPodSandbox (filter )
59- }
60-
61- func (r * remoteRuntimeService ) listPodSandbox (filter * runtimeapi.PodSandboxFilter ) ([]* runtimeapi.PodSandbox , error ) {
62- ctx , cancel := context .WithTimeout (context .Background (), r .timeout )
63- defer cancel ()
64-
65- resp , err := r .runtimeClient .ListPodSandbox (ctx , & runtimeapi.ListPodSandboxRequest {
66- Filter : filter ,
67- })
68- if err != nil {
69- glog .Errorf ("ListPodSandbox with filter %q from runtime sevice failed: %v" , filter , err )
70- return nil , err
71- }
72-
73- return resp .Items , nil
74- }
75-
76- func (r * remoteRuntimeService ) listContainers (filter * runtimeapi.ContainerFilter ) ([]* runtimeapi.Container , error ) {
77- ctx , cancel := context .WithTimeout (context .Background (), r .timeout )
78- defer cancel ()
79-
80- resp , err := r .runtimeClient .ListContainers (ctx , & runtimeapi.ListContainersRequest {
81- Filter : filter ,
82- })
83- if err != nil {
84- glog .Errorf ("ListContainers with filter %q from runtime service failed: %v" , filter , err )
85- return nil , err
86- }
87-
88- return resp .Containers , nil
89- }
90-
9140// localRunningPods uses the CRI shim to retrieve the local container runtime pod state
9241func (r * remoteRuntimeService ) localRunningPods () map [string ]* v1.Pod {
9342 pods := make (map [string ]* v1.Pod )
9443
95- // Retrieving sandboxes is likely redudant but is done to maintain sameness with what the kubelet does
44+ // Retrieving sandboxes is likely redundant but is done to maintain sameness with what the kubelet does
9645 sandboxes , err := r .getRunningKubeletSandboxes ()
9746 if err != nil {
9847 glog .Errorf ("failed to list running sandboxes: %v" , err )
@@ -143,3 +92,54 @@ func (r *remoteRuntimeService) localRunningPods() map[string]*v1.Pod {
14392
14493 return pods
14594}
95+
96+ func (r * remoteRuntimeService ) getRunningKubeletContainers () ([]* runtimeapi.Container , error ) {
97+ filter := & runtimeapi.ContainerFilter {}
98+
99+ // Filter out non-running containers
100+ filter .State = & runtimeapi.ContainerStateValue {
101+ State : runtimeapi .ContainerState_CONTAINER_RUNNING ,
102+ }
103+
104+ return r .listContainers (filter )
105+ }
106+
107+ func (r * remoteRuntimeService ) getRunningKubeletSandboxes () ([]* runtimeapi.PodSandbox , error ) {
108+ filter := & runtimeapi.PodSandboxFilter {}
109+
110+ // Filter out non-running sandboxes
111+ filter .State = & runtimeapi.PodSandboxStateValue {
112+ State : runtimeapi .PodSandboxState_SANDBOX_READY ,
113+ }
114+ return r .listPodSandbox (filter )
115+ }
116+
117+ func (r * remoteRuntimeService ) listPodSandbox (filter * runtimeapi.PodSandboxFilter ) ([]* runtimeapi.PodSandbox , error ) {
118+ ctx , cancel := context .WithTimeout (context .Background (), r .timeout )
119+ defer cancel ()
120+
121+ resp , err := r .runtimeClient .ListPodSandbox (ctx , & runtimeapi.ListPodSandboxRequest {
122+ Filter : filter ,
123+ })
124+ if err != nil {
125+ glog .Errorf ("ListPodSandbox with filter %q from runtime sevice failed: %v" , filter , err )
126+ return nil , err
127+ }
128+
129+ return resp .Items , nil
130+ }
131+
132+ func (r * remoteRuntimeService ) listContainers (filter * runtimeapi.ContainerFilter ) ([]* runtimeapi.Container , error ) {
133+ ctx , cancel := context .WithTimeout (context .Background (), r .timeout )
134+ defer cancel ()
135+
136+ resp , err := r .runtimeClient .ListContainers (ctx , & runtimeapi.ListContainersRequest {
137+ Filter : filter ,
138+ })
139+ if err != nil {
140+ glog .Errorf ("ListContainers with filter %q from runtime service failed: %v" , filter , err )
141+ return nil , err
142+ }
143+
144+ return resp .Containers , nil
145+ }
0 commit comments