diff --git a/pkg/server/service.go b/pkg/server/service.go index 86ec5bb73..89074705a 100644 --- a/pkg/server/service.go +++ b/pkg/server/service.go @@ -144,7 +144,7 @@ func NewCRIService(config criconfig.Config, client *containerd.Client) (CRIServi // Try to load the config if it exists. Just log the error if load fails // This is not disruptive for containerd to panic - if err := c.netPlugin.Load(cni.WithLoNetwork(), cni.WithDefaultConf()); err != nil { + if err := c.netPlugin.Load(cni.WithLoNetwork, cni.WithDefaultConf); err != nil { logrus.WithError(err).Error("Failed to load cni during init, please check CRI plugin status before setting up network for pods") } // prepare streaming server diff --git a/pkg/server/status.go b/pkg/server/status.go index 059036239..f71b78196 100644 --- a/pkg/server/status.go +++ b/pkg/server/status.go @@ -22,6 +22,7 @@ import ( goruntime "runtime" cni "github.com/containerd/go-cni" + "github.com/sirupsen/logrus" "golang.org/x/net/context" runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2" ) @@ -41,14 +42,16 @@ func (c *criService) Status(ctx context.Context, r *runtime.StatusRequest) (*run Type: runtime.NetworkReady, Status: true, } + + // Load the latest cni configuration to be in sync with the latest network configuration + if err := c.netPlugin.Load(cni.WithLoNetwork, cni.WithDefaultConf); err != nil { + logrus.WithError(err).Errorf("Failed to load cni configuration") + } // Check the status of the cni initialization if err := c.netPlugin.Status(); err != nil { - // If it is not initialized, then load the config and retry - if err = c.netPlugin.Load(cni.WithLoNetwork(), cni.WithDefaultConf()); err != nil { - networkCondition.Status = false - networkCondition.Reason = networkNotReadyReason - networkCondition.Message = fmt.Sprintf("Network plugin returns error: %v", err) - } + networkCondition.Status = false + networkCondition.Reason = networkNotReadyReason + networkCondition.Message = fmt.Sprintf("Network plugin returns error: %v", err) } resp := &runtime.StatusResponse{ diff --git a/pkg/server/testing/fake_cni_plugin.go b/pkg/server/testing/fake_cni_plugin.go index b88896fc9..4a7e8d602 100644 --- a/pkg/server/testing/fake_cni_plugin.go +++ b/pkg/server/testing/fake_cni_plugin.go @@ -47,6 +47,6 @@ func (f *FakeCNIPlugin) Status() error { } // Load loads the network config. -func (f *FakeCNIPlugin) Load(opts ...cni.LoadOption) error { +func (f *FakeCNIPlugin) Load(opts ...cni.CNIOpt) error { return f.LoadErr } diff --git a/pkg/server/update_runtime_config.go b/pkg/server/update_runtime_config.go index 8682da66d..0f55aedf8 100644 --- a/pkg/server/update_runtime_config.go +++ b/pkg/server/update_runtime_config.go @@ -52,7 +52,7 @@ func (c *criService) UpdateRuntimeConfig(ctx context.Context, r *runtime.UpdateR if err := c.netPlugin.Status(); err == nil { logrus.Infof("Network plugin is ready, skip generating cni config from template %q", confTemplate) return &runtime.UpdateRuntimeConfigResponse{}, nil - } else if err := c.netPlugin.Load(cni.WithLoNetwork(), cni.WithDefaultConf()); err == nil { + } else if err := c.netPlugin.Load(cni.WithLoNetwork, cni.WithDefaultConf); err == nil { logrus.Infof("CNI config is successfully loaded, skip generating cni config from template %q", confTemplate) return &runtime.UpdateRuntimeConfigResponse{}, nil }