Address comments.

Signed-off-by: Lantao Liu <lantaol@google.com>
This commit is contained in:
Lantao Liu 2018-04-09 18:11:57 +00:00
parent b2099c2061
commit d8a3c5f254
5 changed files with 24 additions and 15 deletions

View File

@ -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 # conf_template is the file path of golang template used to generate
# cni config. # cni config.
# If this is set, containerd will generate a cni config file from the # If this is set, containerd will generate a cni config file from the
# template. Otherwise, containerd will wait for the system admin or pod # template. Otherwise, containerd will wait for the system admin or cni
# network addon to drop the config file into the conf_dir. # 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 = "" conf_template = ""
# "plugins.cri.registry" contains config related to the registry # "plugins.cri.registry" contains config related to the registry

View File

@ -47,12 +47,14 @@ type CniConfig struct {
NetworkPluginConfDir string `toml:"conf_dir" json:"confDir"` NetworkPluginConfDir string `toml:"conf_dir" json:"confDir"`
// NetworkPluginConfTemplate is the file path of golang template used to generate // NetworkPluginConfTemplate is the file path of golang template used to generate
// cni config. // cni config.
// Usually the cni config should be placed by system admin or pod network // When it is set, containerd will get cidr from kubelet to replace {{.PodCIDR}} in
// addons like calico, weaveworks etc. However, in some cases only a simple cni // the template, and write the config into NetworkPluginConfDir.
// config is needed with pod cidr dynamically set. // Ideally the cni config should be placed by system admin or cni daemon like calico,
// NetworkPluginConfTemplate can be used in those cases. When it is set, // weaveworks etc. However, there are still users using kubenet
// containerd will get cidr from kubelet to replace {{.PodCIDR}} in the template, // (https://kubernetes.io/docs/concepts/cluster-administration/network-plugins/#kubenet)
// and write the config into NetworkPluginConfDir. // 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"` NetworkPluginConfTemplate string `toml:"conf_template" json:"confTemplate"`
} }

View File

@ -23,6 +23,7 @@ import (
// FakeCNIPlugin is a fake plugin used for test. // FakeCNIPlugin is a fake plugin used for test.
type FakeCNIPlugin struct { type FakeCNIPlugin struct {
StatusErr error StatusErr error
LoadErr error
} }
// NewFakeCNIPlugin create a FakeCNIPlugin. // NewFakeCNIPlugin create a FakeCNIPlugin.
@ -47,5 +48,5 @@ func (f *FakeCNIPlugin) Status() error {
// Load loads the network config. // Load loads the network config.
func (f *FakeCNIPlugin) Load(opts ...cni.LoadOption) error { func (f *FakeCNIPlugin) Load(opts ...cni.LoadOption) error {
return nil return f.LoadErr
} }

View File

@ -21,6 +21,7 @@ import (
"path/filepath" "path/filepath"
"text/template" "text/template"
cni "github.com/containerd/go-cni"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"golang.org/x/net/context" "golang.org/x/net/context"
@ -44,16 +45,17 @@ func (c *criService) UpdateRuntimeConfig(ctx context.Context, r *runtime.UpdateR
return &runtime.UpdateRuntimeConfigResponse{}, nil return &runtime.UpdateRuntimeConfigResponse{}, nil
} }
confTemplate := c.config.NetworkPluginConfTemplate 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 == "" { if confTemplate == "" {
logrus.Info("No cni config template is specified, wait for other system components to drop the config.") logrus.Info("No cni config template is specified, wait for other system components to drop the config.")
return &runtime.UpdateRuntimeConfigResponse{}, nil 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) logrus.Infof("Generating cni config from template %q", confTemplate)
// generate cni config file from the template with updated pod cidr. // generate cni config file from the template with updated pod cidr.
t, err := template.ParseFiles(confTemplate) t, err := template.ParseFiles(confTemplate)

View File

@ -125,6 +125,7 @@ func TestUpdateRuntimeConfig(t *testing.T) {
} }
if !test.networkReady { if !test.networkReady {
c.netPlugin.(*servertesting.FakeCNIPlugin).StatusErr = errors.New("random error") c.netPlugin.(*servertesting.FakeCNIPlugin).StatusErr = errors.New("random error")
c.netPlugin.(*servertesting.FakeCNIPlugin).LoadErr = errors.New("random error")
} }
_, err = c.UpdateRuntimeConfig(context.Background(), req) _, err = c.UpdateRuntimeConfig(context.Background(), req)
assert.NoError(t, err) assert.NoError(t, err)