mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-04 09:49:50 +00:00
Start returning PodSyncResult in SyncPod
This commit is contained in:
parent
e953f4a074
commit
e93febfd61
@ -174,7 +174,7 @@ func (f *FakeRuntime) GetPods(all bool) ([]*Pod, error) {
|
|||||||
return f.PodList, f.Err
|
return f.PodList, f.Err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FakeRuntime) SyncPod(pod *api.Pod, _ api.PodStatus, _ *PodStatus, _ []api.Secret, backOff *util.Backoff) error {
|
func (f *FakeRuntime) SyncPod(pod *api.Pod, _ api.PodStatus, _ *PodStatus, _ []api.Secret, backOff *util.Backoff) (result PodSyncResult) {
|
||||||
f.Lock()
|
f.Lock()
|
||||||
defer f.Unlock()
|
defer f.Unlock()
|
||||||
|
|
||||||
@ -183,7 +183,11 @@ func (f *FakeRuntime) SyncPod(pod *api.Pod, _ api.PodStatus, _ *PodStatus, _ []a
|
|||||||
for _, c := range pod.Spec.Containers {
|
for _, c := range pod.Spec.Containers {
|
||||||
f.StartedContainers = append(f.StartedContainers, c.Name)
|
f.StartedContainers = append(f.StartedContainers, c.Name)
|
||||||
}
|
}
|
||||||
return f.Err
|
// TODO(random-liu): Add SyncResult for starting and killing containers
|
||||||
|
if f.Err != nil {
|
||||||
|
result.Fail(f.Err)
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FakeRuntime) KillPod(pod *api.Pod, runningPod Pod) error {
|
func (f *FakeRuntime) KillPod(pod *api.Pod, runningPod Pod) error {
|
||||||
|
@ -65,8 +65,9 @@ type Runtime interface {
|
|||||||
// GarbageCollect removes dead containers using the specified container gc policy
|
// GarbageCollect removes dead containers using the specified container gc policy
|
||||||
GarbageCollect(gcPolicy ContainerGCPolicy) error
|
GarbageCollect(gcPolicy ContainerGCPolicy) error
|
||||||
// Syncs the running pod into the desired pod.
|
// Syncs the running pod into the desired pod.
|
||||||
SyncPod(pod *api.Pod, apiPodStatus api.PodStatus, podStatus *PodStatus, pullSecrets []api.Secret, backOff *util.Backoff) error
|
SyncPod(pod *api.Pod, apiPodStatus api.PodStatus, podStatus *PodStatus, pullSecrets []api.Secret, backOff *util.Backoff) PodSyncResult
|
||||||
// KillPod kills all the containers of a pod. Pod may be nil, running pod must not be.
|
// KillPod kills all the containers of a pod. Pod may be nil, running pod must not be.
|
||||||
|
// TODO(random-liu): Return PodSyncResult in KillPod.
|
||||||
KillPod(pod *api.Pod, runningPod Pod) error
|
KillPod(pod *api.Pod, runningPod Pod) error
|
||||||
// GetAPIPodStatus retrieves the api.PodStatus of the pod, including the information of
|
// GetAPIPodStatus retrieves the api.PodStatus of the pod, including the information of
|
||||||
// all containers in the pod. Clients of this interface assume the
|
// all containers in the pod. Clients of this interface assume the
|
||||||
|
@ -57,9 +57,9 @@ func (r *Mock) GetPods(all bool) ([]*Pod, error) {
|
|||||||
return args.Get(0).([]*Pod), args.Error(1)
|
return args.Get(0).([]*Pod), args.Error(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Mock) SyncPod(pod *api.Pod, apiStatus api.PodStatus, status *PodStatus, secrets []api.Secret, backOff *util.Backoff) error {
|
func (r *Mock) SyncPod(pod *api.Pod, apiStatus api.PodStatus, status *PodStatus, secrets []api.Secret, backOff *util.Backoff) PodSyncResult {
|
||||||
args := r.Called(pod, apiStatus, status, secrets, backOff)
|
args := r.Called(pod, apiStatus, status, secrets, backOff)
|
||||||
return args.Error(0)
|
return args.Get(0).(PodSyncResult)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Mock) KillPod(pod *api.Pod, runningPod Pod) error {
|
func (r *Mock) KillPod(pod *api.Pod, runningPod Pod) error {
|
||||||
|
@ -1814,13 +1814,7 @@ func (dm *DockerManager) clearReasonCache(pod *api.Pod, container *api.Container
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Sync the running pod to match the specified desired pod.
|
// Sync the running pod to match the specified desired pod.
|
||||||
func (dm *DockerManager) SyncPod(pod *api.Pod, apiPodStatus api.PodStatus, podStatus *kubecontainer.PodStatus, pullSecrets []api.Secret, backOff *util.Backoff) error {
|
func (dm *DockerManager) SyncPod(pod *api.Pod, _ api.PodStatus, podStatus *kubecontainer.PodStatus, pullSecrets []api.Secret, backOff *util.Backoff) (result kubecontainer.PodSyncResult) {
|
||||||
result := dm.syncPodWithSyncResult(pod, apiPodStatus, podStatus, pullSecrets, backOff)
|
|
||||||
return result.Error()
|
|
||||||
}
|
|
||||||
|
|
||||||
// (random-liu) This is just a temporary function, will be removed when we acturally add PodSyncEvent
|
|
||||||
func (dm *DockerManager) syncPodWithSyncResult(pod *api.Pod, _ api.PodStatus, podStatus *kubecontainer.PodStatus, pullSecrets []api.Secret, backOff *util.Backoff) (result kubecontainer.PodSyncResult) {
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
defer func() {
|
defer func() {
|
||||||
metrics.ContainerManagerLatency.WithLabelValues("SyncPod").Observe(metrics.SinceInMicroseconds(start))
|
metrics.ContainerManagerLatency.WithLabelValues("SyncPod").Observe(metrics.SinceInMicroseconds(start))
|
||||||
|
@ -551,7 +551,9 @@ func runSyncPod(t *testing.T, dm *DockerManager, fakeDocker *FakeDockerClient, p
|
|||||||
if backOff == nil {
|
if backOff == nil {
|
||||||
backOff = util.NewBackOff(time.Second, time.Minute)
|
backOff = util.NewBackOff(time.Second, time.Minute)
|
||||||
}
|
}
|
||||||
err = dm.SyncPod(pod, *apiPodStatus, podStatus, []api.Secret{}, backOff)
|
//TODO(random-liu): Add test for PodSyncResult
|
||||||
|
result := dm.SyncPod(pod, *apiPodStatus, podStatus, []api.Secret{}, backOff)
|
||||||
|
err = result.Error()
|
||||||
if err != nil && !expectErr {
|
if err != nil && !expectErr {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
} else if err == nil && expectErr {
|
} else if err == nil && expectErr {
|
||||||
|
@ -1675,7 +1675,8 @@ func (kl *Kubelet) syncPod(pod *api.Pod, mirrorPod *api.Pod, runningPod kubecont
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = kl.containerRuntime.SyncPod(pod, apiPodStatus, podStatus, pullSecrets, kl.backOff)
|
result := kl.containerRuntime.SyncPod(pod, apiPodStatus, podStatus, pullSecrets, kl.backOff)
|
||||||
|
err = result.Error()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -976,7 +976,13 @@ func (r *Runtime) APIVersion() (kubecontainer.Version, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SyncPod syncs the running pod to match the specified desired pod.
|
// SyncPod syncs the running pod to match the specified desired pod.
|
||||||
func (r *Runtime) SyncPod(pod *api.Pod, podStatus api.PodStatus, internalPodStatus *kubecontainer.PodStatus, pullSecrets []api.Secret, backOff *util.Backoff) error {
|
func (r *Runtime) SyncPod(pod *api.Pod, podStatus api.PodStatus, internalPodStatus *kubecontainer.PodStatus, pullSecrets []api.Secret, backOff *util.Backoff) (result kubecontainer.PodSyncResult) {
|
||||||
|
var err error
|
||||||
|
defer func() {
|
||||||
|
if err != nil {
|
||||||
|
result.Fail(err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
// TODO: (random-liu) Stop using running pod in SyncPod()
|
// TODO: (random-liu) Stop using running pod in SyncPod()
|
||||||
// TODO: (random-liu) Rename podStatus to apiPodStatus, rename internalPodStatus to podStatus, and use new pod status as much as possible,
|
// TODO: (random-liu) Rename podStatus to apiPodStatus, rename internalPodStatus to podStatus, and use new pod status as much as possible,
|
||||||
// we may stop using apiPodStatus someday.
|
// we may stop using apiPodStatus someday.
|
||||||
@ -1031,15 +1037,15 @@ func (r *Runtime) SyncPod(pod *api.Pod, podStatus api.PodStatus, internalPodStat
|
|||||||
if restartPod {
|
if restartPod {
|
||||||
// Kill the pod only if the pod is actually running.
|
// Kill the pod only if the pod is actually running.
|
||||||
if len(runningPod.Containers) > 0 {
|
if len(runningPod.Containers) > 0 {
|
||||||
if err := r.KillPod(pod, runningPod); err != nil {
|
if err = r.KillPod(pod, runningPod); err != nil {
|
||||||
return err
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := r.RunPod(pod, pullSecrets); err != nil {
|
if err = r.RunPod(pod, pullSecrets); err != nil {
|
||||||
return err
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// GarbageCollect collects the pods/containers.
|
// GarbageCollect collects the pods/containers.
|
||||||
|
Loading…
Reference in New Issue
Block a user