本文整理匯總了Golang中k8s/io/kubernetes/pkg/api/v1.Pod.UID方法的典型用法代碼示例。如果您正苦於以下問題:Golang Pod.UID方法的具體用法?Golang Pod.UID怎麽用?Golang Pod.UID使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類k8s/io/kubernetes/pkg/api/v1.Pod
的用法示例。
在下文中一共展示了Pod.UID方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ToAPIPod
// ToAPIPod converts Pod to v1.Pod. Note that if a field in v1.Pod has no
// corresponding field in Pod, the field would not be populated.
func (p *Pod) ToAPIPod() *v1.Pod {
var pod v1.Pod
pod.UID = p.ID
pod.Name = p.Name
pod.Namespace = p.Namespace
for _, c := range p.Containers {
var container v1.Container
container.Name = c.Name
container.Image = c.Image
pod.Spec.Containers = append(pod.Spec.Containers, container)
}
return &pod
}
示例2: getTestPod
func getTestPod() *v1.Pod {
container := v1.Container{
Name: testContainerName,
}
pod := v1.Pod{
Spec: v1.PodSpec{
Containers: []v1.Container{container},
RestartPolicy: v1.RestartPolicyNever,
},
}
pod.Name = "testPod"
pod.UID = testPodUID
return &pod
}
示例3: TestSyncBatchNoDeadlock
func TestSyncBatchNoDeadlock(t *testing.T) {
client := &fake.Clientset{}
m := newTestManager(client)
pod := getTestPod()
// Setup fake client.
var ret v1.Pod
var err error
client.AddReactor("*", "pods", func(action core.Action) (bool, runtime.Object, error) {
switch action := action.(type) {
case core.GetAction:
assert.Equal(t, pod.Name, action.GetName(), "Unexpeted GetAction: %+v", action)
case core.UpdateAction:
assert.Equal(t, pod.Name, action.GetObject().(*v1.Pod).Name, "Unexpeted UpdateAction: %+v", action)
default:
assert.Fail(t, "Unexpected Action: %+v", action)
}
return true, &ret, err
})
pod.Status.ContainerStatuses = []v1.ContainerStatus{{State: v1.ContainerState{Running: &v1.ContainerStateRunning{}}}}
getAction := core.GetActionImpl{ActionImpl: core.ActionImpl{Verb: "get", Resource: schema.GroupVersionResource{Resource: "pods"}}}
updateAction := core.UpdateActionImpl{ActionImpl: core.ActionImpl{Verb: "update", Resource: schema.GroupVersionResource{Resource: "pods"}, Subresource: "status"}}
// Pod not found.
ret = *pod
err = errors.NewNotFound(api.Resource("pods"), pod.Name)
m.SetPodStatus(pod, getRandomPodStatus())
m.testSyncBatch()
verifyActions(t, client, []core.Action{getAction})
client.ClearActions()
// Pod was recreated.
ret.UID = "other_pod"
err = nil
m.SetPodStatus(pod, getRandomPodStatus())
m.testSyncBatch()
verifyActions(t, client, []core.Action{getAction})
client.ClearActions()
// Pod not deleted (success case).
ret = *pod
m.SetPodStatus(pod, getRandomPodStatus())
m.testSyncBatch()
verifyActions(t, client, []core.Action{getAction, updateAction})
client.ClearActions()
// Pod is terminated, but still running.
pod.DeletionTimestamp = new(metav1.Time)
m.SetPodStatus(pod, getRandomPodStatus())
m.testSyncBatch()
verifyActions(t, client, []core.Action{getAction, updateAction})
client.ClearActions()
// Pod is terminated successfully.
pod.Status.ContainerStatuses[0].State.Running = nil
pod.Status.ContainerStatuses[0].State.Terminated = &v1.ContainerStateTerminated{}
m.SetPodStatus(pod, getRandomPodStatus())
m.testSyncBatch()
verifyActions(t, client, []core.Action{getAction, updateAction})
client.ClearActions()
// Error case.
err = fmt.Errorf("intentional test error")
m.SetPodStatus(pod, getRandomPodStatus())
m.testSyncBatch()
verifyActions(t, client, []core.Action{getAction})
client.ClearActions()
}