From e8eb5c656b49ff285b4fb80f014875216a453a7a Mon Sep 17 00:00:00 2001 From: louisgong Date: Mon, 30 Dec 2019 21:35:16 +0800 Subject: [PATCH] fix fake remote CRI --- pkg/kubelet/remote/fake/fake_runtime.go | 9 +++++++++ .../cri-api/pkg/apis/testing/fake_runtime_service.go | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/pkg/kubelet/remote/fake/fake_runtime.go b/pkg/kubelet/remote/fake/fake_runtime.go index af77239ed11..71845820750 100644 --- a/pkg/kubelet/remote/fake/fake_runtime.go +++ b/pkg/kubelet/remote/fake/fake_runtime.go @@ -61,6 +61,15 @@ func (f *RemoteRuntime) Start(endpoint string) error { } go f.server.Serve(l) + + // Set runtime and network conditions ready. + f.RuntimeService.FakeStatus = &kubeapi.RuntimeStatus{ + Conditions: []*kubeapi.RuntimeCondition{ + {Type: kubeapi.RuntimeReady, Status: true}, + {Type: kubeapi.NetworkReady, Status: true}, + }, + } + return nil } diff --git a/staging/src/k8s.io/cri-api/pkg/apis/testing/fake_runtime_service.go b/staging/src/k8s.io/cri-api/pkg/apis/testing/fake_runtime_service.go index 4aae5e773af..e761d308928 100644 --- a/staging/src/k8s.io/cri-api/pkg/apis/testing/fake_runtime_service.go +++ b/staging/src/k8s.io/cri-api/pkg/apis/testing/fake_runtime_service.go @@ -194,6 +194,14 @@ func (r *FakeRuntimeService) RunPodSandbox(config *runtimeapi.PodSandboxConfig, Network: &runtimeapi.PodSandboxNetworkStatus{ Ip: FakePodSandboxIPs[0], }, + // Without setting sandboxStatus's Linux.Namespaces.Options, kubeGenericRuntimeManager's podSandboxChanged will consider it as network + // namespace changed and always recreate sandbox which causes pod creation failed. + // Ref `sandboxStatus.GetLinux().GetNamespaces().GetOptions().GetNetwork() != networkNamespaceForPod(pod)` in podSandboxChanged function. + Linux: &runtimeapi.LinuxPodSandboxStatus{ + Namespaces: &runtimeapi.Namespace{ + Options: config.GetLinux().GetSecurityContext().GetNamespaceOptions(), + }, + }, Labels: config.Labels, Annotations: config.Annotations, RuntimeHandler: runtimeHandler,