@@ -17,12 +17,14 @@ limitations under the License.
17
17
package remote
18
18
19
19
import (
20
+ "errors"
20
21
"fmt"
21
22
"strings"
22
23
"time"
23
24
24
25
"github.com/golang/glog"
25
26
"google.golang.org/grpc"
27
+
26
28
internalapi "k8s.io/kubernetes/pkg/kubelet/api"
27
29
runtimeapi "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime"
28
30
utilexec "k8s.io/kubernetes/pkg/util/exec"
@@ -62,6 +64,10 @@ func (r *RemoteRuntimeService) Version(apiVersion string) (*runtimeapi.VersionRe
62
64
return nil , err
63
65
}
64
66
67
+ if typedVersion .Version == "" || typedVersion .RuntimeName == "" || typedVersion .RuntimeApiVersion == "" || typedVersion .RuntimeVersion == "" {
68
+ return nil , fmt .Errorf ("not all fields are set in VersionResponse (%q)" , * typedVersion )
69
+ }
70
+
65
71
return typedVersion , err
66
72
}
67
73
@@ -79,6 +85,12 @@ func (r *RemoteRuntimeService) RunPodSandbox(config *runtimeapi.PodSandboxConfig
79
85
return "" , err
80
86
}
81
87
88
+ if resp .PodSandboxId == "" {
89
+ errorMessage := fmt .Sprintf ("PodSandboxId is not set for sandbox %q" , config .GetMetadata ())
90
+ glog .Errorf ("RunPodSandbox failed: %s" , errorMessage )
91
+ return "" , errors .New (errorMessage )
92
+ }
93
+
82
94
return resp .PodSandboxId , nil
83
95
}
84
96
@@ -125,10 +137,15 @@ func (r *RemoteRuntimeService) PodSandboxStatus(podSandBoxID string) (*runtimeap
125
137
PodSandboxId : podSandBoxID ,
126
138
})
127
139
if err != nil {
128
- glog .Errorf ("PodSandboxStatus %q from runtime service failed: %v" , podSandBoxID , err )
129
140
return nil , err
130
141
}
131
142
143
+ if resp .Status != nil {
144
+ if err := verifySandboxStatus (resp .Status ); err != nil {
145
+ return nil , err
146
+ }
147
+ }
148
+
132
149
return resp .Status , nil
133
150
}
134
151
@@ -163,6 +180,12 @@ func (r *RemoteRuntimeService) CreateContainer(podSandBoxID string, config *runt
163
180
return "" , err
164
181
}
165
182
183
+ if resp .ContainerId == "" {
184
+ errorMessage := fmt .Sprintf ("ContainerId is not set for container %q" , config .GetMetadata ())
185
+ glog .Errorf ("CreateContainer failed: %s" , errorMessage )
186
+ return "" , errors .New (errorMessage )
187
+ }
188
+
166
189
return resp .ContainerId , nil
167
190
}
168
191
@@ -245,6 +268,13 @@ func (r *RemoteRuntimeService) ContainerStatus(containerID string) (*runtimeapi.
245
268
return nil , err
246
269
}
247
270
271
+ if resp .Status != nil {
272
+ if err := verifyContainerStatus (resp .Status ); err != nil {
273
+ glog .Errorf ("ContainerStatus of %q failed: %v" , containerID , err )
274
+ return nil , err
275
+ }
276
+ }
277
+
248
278
return resp .Status , nil
249
279
}
250
280
@@ -288,6 +318,12 @@ func (r *RemoteRuntimeService) Exec(req *runtimeapi.ExecRequest) (*runtimeapi.Ex
288
318
return nil , err
289
319
}
290
320
321
+ if resp .Url == "" {
322
+ errorMessage := "URL is not set"
323
+ glog .Errorf ("Exec failed: %s" , errorMessage )
324
+ return nil , errors .New (errorMessage )
325
+ }
326
+
291
327
return resp , nil
292
328
}
293
329
@@ -302,6 +338,11 @@ func (r *RemoteRuntimeService) Attach(req *runtimeapi.AttachRequest) (*runtimeap
302
338
return nil , err
303
339
}
304
340
341
+ if resp .Url == "" {
342
+ errorMessage := "URL is not set"
343
+ glog .Errorf ("Exec failed: %s" , errorMessage )
344
+ return nil , errors .New (errorMessage )
345
+ }
305
346
return resp , nil
306
347
}
307
348
@@ -316,6 +357,12 @@ func (r *RemoteRuntimeService) PortForward(req *runtimeapi.PortForwardRequest) (
316
357
return nil , err
317
358
}
318
359
360
+ if resp .Url == "" {
361
+ errorMessage := "URL is not set"
362
+ glog .Errorf ("Exec failed: %s" , errorMessage )
363
+ return nil , errors .New (errorMessage )
364
+ }
365
+
319
366
return resp , nil
320
367
}
321
368
@@ -351,5 +398,11 @@ func (r *RemoteRuntimeService) Status() (*runtimeapi.RuntimeStatus, error) {
351
398
return nil , err
352
399
}
353
400
401
+ if resp .Status == nil || len (resp .Status .Conditions ) < 2 {
402
+ errorMessage := "RuntimeReady or NetworkReady condition are not set"
403
+ glog .Errorf ("Status failed: %s" , errorMessage )
404
+ return nil , errors .New (errorMessage )
405
+ }
406
+
354
407
return resp .Status , nil
355
408
}
0 commit comments