forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
runtime.go
55 lines (49 loc) · 1.54 KB
/
runtime.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package plugin
import (
"fmt"
"time"
kwait "k8s.io/apimachinery/pkg/util/wait"
kubeletapi "k8s.io/kubernetes/pkg/kubelet/api"
kruntimeapi "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime"
kubeletremote "k8s.io/kubernetes/pkg/kubelet/remote"
)
func (node *OsdnNode) getRuntimeService() (kubeletapi.RuntimeService, error) {
if node.runtimeService != nil {
return node.runtimeService, nil
}
// Kubelet starts asynchronously and when we get an Update op, kubelet may not have created runtime endpoint.
// So try couple of times before bailing out (~30 seconds timeout).
err := kwait.ExponentialBackoff(
kwait.Backoff{
Duration: 100 * time.Millisecond,
Factor: 1.2,
Steps: 23,
},
func() (bool, error) {
runtimeService, err := kubeletremote.NewRemoteRuntimeService(node.runtimeEndpoint, node.runtimeRequestTimeout)
if err != nil {
// Wait longer
return false, nil
}
node.runtimeService = runtimeService
return true, nil
})
if err != nil {
return nil, fmt.Errorf("Failed to fetch runtime service: %v", err)
}
return node.runtimeService, nil
}
func (node *OsdnNode) getPodSandboxID(filter *kruntimeapi.PodSandboxFilter) (string, error) {
runtimeService, err := node.getRuntimeService()
if err != nil {
return "", err
}
podSandboxList, err := runtimeService.ListPodSandbox(filter)
if err != nil {
return "", fmt.Errorf("Failed to list pod sandboxes: %v", err)
}
if len(podSandboxList) == 0 {
return "", fmt.Errorf("Pod sandbox not found for filter: %v", filter)
}
return podSandboxList[0].Id, nil
}