From d8a3c5f254d7aa5b0e20622af980cb7fe2c57a9e Mon Sep 17 00:00:00 2001 From: Lantao Liu Date: Mon, 9 Apr 2018 18:11:57 +0000 Subject: [PATCH] Address comments. Signed-off-by: Lantao Liu --- docs/config.md | 7 +++++-- pkg/config/config.go | 14 ++++++++------ pkg/server/testing/fake_cni_plugin.go | 3 ++- pkg/server/update_runtime_config.go | 14 ++++++++------ pkg/server/update_runtime_config_test.go | 1 + 5 files changed, 24 insertions(+), 15 deletions(-) diff --git a/docs/config.md b/docs/config.md index 0c0f6b157..d5c481ff2 100644 --- a/docs/config.md +++ b/docs/config.md @@ -66,8 +66,11 @@ The explanation and default value of each configuration item are as follows: # conf_template is the file path of golang template used to generate # cni config. # If this is set, containerd will generate a cni config file from the - # template. Otherwise, containerd will wait for the system admin or pod - # network addon to drop the config file into the conf_dir. + # template. Otherwise, containerd will wait for the system admin or cni + # daemon to drop the config file into the conf_dir. + # This is a temporary backward-compatible solution for kubenet users + # who don't have a cni daemonset in production yet. + # This will be deprecated when kubenet is deprecated. conf_template = "" # "plugins.cri.registry" contains config related to the registry diff --git a/pkg/config/config.go b/pkg/config/config.go index 47c4371cb..d9e417d75 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -47,12 +47,14 @@ type CniConfig struct { NetworkPluginConfDir string `toml:"conf_dir" json:"confDir"` // NetworkPluginConfTemplate is the file path of golang template used to generate // cni config. - // Usually the cni config should be placed by system admin or pod network - // addons like calico, weaveworks etc. However, in some cases only a simple cni - // config is needed with pod cidr dynamically set. - // NetworkPluginConfTemplate can be used in those cases. When it is set, - // containerd will get cidr from kubelet to replace {{.PodCIDR}} in the template, - // and write the config into NetworkPluginConfDir. + // When it is set, containerd will get cidr from kubelet to replace {{.PodCIDR}} in + // the template, and write the config into NetworkPluginConfDir. + // Ideally the cni config should be placed by system admin or cni daemon like calico, + // weaveworks etc. However, there are still users using kubenet + // (https://kubernetes.io/docs/concepts/cluster-administration/network-plugins/#kubenet) + // today, who don't have a cni daemonset in production. NetworkPluginConfTemplate is + // a temporary backward-compatible solution for them. + // TODO(random-liu): Deprecate this option when kubenet is deprecated. NetworkPluginConfTemplate string `toml:"conf_template" json:"confTemplate"` } diff --git a/pkg/server/testing/fake_cni_plugin.go b/pkg/server/testing/fake_cni_plugin.go index 651d7690b..b88896fc9 100644 --- a/pkg/server/testing/fake_cni_plugin.go +++ b/pkg/server/testing/fake_cni_plugin.go @@ -23,6 +23,7 @@ import ( // FakeCNIPlugin is a fake plugin used for test. type FakeCNIPlugin struct { StatusErr error + LoadErr error } // NewFakeCNIPlugin create a FakeCNIPlugin. @@ -47,5 +48,5 @@ func (f *FakeCNIPlugin) Status() error { // Load loads the network config. func (f *FakeCNIPlugin) Load(opts ...cni.LoadOption) error { - return nil + return f.LoadErr } diff --git a/pkg/server/update_runtime_config.go b/pkg/server/update_runtime_config.go index 55e298b66..8682da66d 100644 --- a/pkg/server/update_runtime_config.go +++ b/pkg/server/update_runtime_config.go @@ -21,6 +21,7 @@ import ( "path/filepath" "text/template" + cni "github.com/containerd/go-cni" "github.com/pkg/errors" "github.com/sirupsen/logrus" "golang.org/x/net/context" @@ -44,16 +45,17 @@ func (c *criService) UpdateRuntimeConfig(ctx context.Context, r *runtime.UpdateR return &runtime.UpdateRuntimeConfigResponse{}, nil } confTemplate := c.config.NetworkPluginConfTemplate - if err := c.netPlugin.Status(); err == nil { - if confTemplate != "" { - logrus.Infof("Network plugin is ready, skip generating cni config from template %q", confTemplate) - } - return &runtime.UpdateRuntimeConfigResponse{}, nil - } if confTemplate == "" { logrus.Info("No cni config template is specified, wait for other system components to drop the config.") return &runtime.UpdateRuntimeConfigResponse{}, nil } + 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 { + logrus.Infof("CNI config is successfully loaded, skip generating cni config from template %q", confTemplate) + return &runtime.UpdateRuntimeConfigResponse{}, nil + } logrus.Infof("Generating cni config from template %q", confTemplate) // generate cni config file from the template with updated pod cidr. t, err := template.ParseFiles(confTemplate) diff --git a/pkg/server/update_runtime_config_test.go b/pkg/server/update_runtime_config_test.go index b9e6ed90a..a929927c1 100644 --- a/pkg/server/update_runtime_config_test.go +++ b/pkg/server/update_runtime_config_test.go @@ -125,6 +125,7 @@ func TestUpdateRuntimeConfig(t *testing.T) { } if !test.networkReady { c.netPlugin.(*servertesting.FakeCNIPlugin).StatusErr = errors.New("random error") + c.netPlugin.(*servertesting.FakeCNIPlugin).LoadErr = errors.New("random error") } _, err = c.UpdateRuntimeConfig(context.Background(), req) assert.NoError(t, err)