Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14892 from pravisankar/fix-update-pod
Merged by openshift-bot
- Loading branch information
Showing
9 changed files
with
121 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 | ||
} |