From 263b0b99d0e6b76ad597f7c192bdb02775d65662 Mon Sep 17 00:00:00 2001 From: Abhinandan Prativadi Date: Tue, 19 Jun 2018 18:20:14 +0000 Subject: [PATCH] Change to keep in sync with latest cni config This commit contains change to pick the latest cni config from the configured CNIConfDir. With this change any changes made to the cni config file will be picked up on the kubelet's runtime status check call. Ofcourse this would lead to undefined behavior when the cni config change is made in parallel during pod creation. However its reasonable to assume that the operator is aware of the need to drain the nodes of pods before making cni configuration change. The behavior is currently not defined in kubernetes. However I see that similar approach being adopted in the upstream kubernetes with dockershim. Keeping the behavior consistent for now. Signed-off-by: Abhinandan Prativadi --- pkg/server/service.go | 2 +- pkg/server/status.go | 15 +++++++++------ pkg/server/testing/fake_cni_plugin.go | 2 +- pkg/server/update_runtime_config.go | 2 +- 4 files changed, 12 insertions(+), 9 deletions(-) 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 }