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
# 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

View File

@ -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"`
}

View File

@ -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
}

View File

@ -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)

View File

@ -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)