Skip to content
This repository has been archived by the owner on Mar 9, 2022. It is now read-only.

Commit

Permalink
Status: async reload latest CNI network conf
Browse files Browse the repository at this point in the history
Signed-off-by: Wei Fu <fuweid89@gmail.com>
  • Loading branch information
fuweid committed Feb 27, 2020
1 parent f4b3cdb commit 80027f4
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 12 deletions.
3 changes: 3 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ type CniConfig struct {
// a temporary backward-compatible solution for them.
// TODO(random-liu): Deprecate this option when kubenet is deprecated.
NetworkPluginConfTemplate string `toml:"conf_template" json:"confTemplate"`
// NetworkPluginConfReloadPeriod is the period (in seconds) of reloading
// CNI conf. The default value is 10 seconds.
NetworkPluginConfReloadPeriod int `toml:"conf_reload_period" json:"confReloadPeriod"`
}

// Mirror contains the config related to the registry mirror
Expand Down
9 changes: 5 additions & 4 deletions pkg/config/config_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ import (
func DefaultConfig() PluginConfig {
return PluginConfig{
CniConfig: CniConfig{
NetworkPluginBinDir: "/opt/cni/bin",
NetworkPluginConfDir: "/etc/cni/net.d",
NetworkPluginMaxConfNum: 1, // only one CNI plugin config file will be loaded
NetworkPluginConfTemplate: "",
NetworkPluginBinDir: "/opt/cni/bin",
NetworkPluginConfDir: "/etc/cni/net.d",
NetworkPluginMaxConfNum: 1, // only one CNI plugin config file will be loaded
NetworkPluginConfTemplate: "",
NetworkPluginConfReloadPeriod: 10,
},
ContainerdConfig: ContainerdConfig{
Snapshotter: containerd.DefaultSnapshotter,
Expand Down
9 changes: 5 additions & 4 deletions pkg/config/config_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ import (
func DefaultConfig() PluginConfig {
return PluginConfig{
CniConfig: CniConfig{
NetworkPluginBinDir: filepath.Join(os.Getenv("ProgramFiles"), "containerd", "cni", "bin"),
NetworkPluginConfDir: filepath.Join(os.Getenv("ProgramFiles"), "containerd", "cni", "conf"),
NetworkPluginMaxConfNum: 1,
NetworkPluginConfTemplate: "",
NetworkPluginBinDir: filepath.Join(os.Getenv("ProgramFiles"), "containerd", "cni", "bin"),
NetworkPluginConfDir: filepath.Join(os.Getenv("ProgramFiles"), "containerd", "cni", "conf"),
NetworkPluginMaxConfNum: 1,
NetworkPluginConfTemplate: "",
NetworkPluginConfReloadPeriod: 10,
},
ContainerdConfig: ContainerdConfig{
Snapshotter: containerd.DefaultSnapshotter,
Expand Down
27 changes: 27 additions & 0 deletions pkg/server/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,17 @@ func (c *criService) Run() error {
)
snapshotsSyncer.start()

// Start CNI network conf syncer
//
// NOTE(fuweid): When there are a lot of requests to create or stop
// sandbox pod, the CNI plugin might need more time to allocate/release
// IP resources because of throttling. In this case, CNI plugin will
// hold lock for a while, which impacts that Status service can not
// reply to kubelet in time. Kubelet will be not ready. To prevent this,
// load latest CNI network conf async.
logrus.Info("Start CNI network conf syncer")
c.cniNetworkConfSyncer(time.Duration(c.config.NetworkPluginConfReloadPeriod) * time.Second)

// Start streaming server.
logrus.Info("Start streaming server")
streamServerErrCh := make(chan error)
Expand Down Expand Up @@ -243,6 +254,22 @@ func (c *criService) register(s *grpc.Server) error {
return nil
}

// cniNetworkConfSyncer loads latest CNI network conf.
func (c *criService) cniNetworkConfSyncer(du time.Duration) {
var tick = time.NewTicker(du)

go func() {
defer tick.Stop()

for {
if err := c.netPlugin.Load(c.cniLoadOptions()...); err != nil {
logrus.WithError(err).Errorf("Failed to load cni configuration")
}
<-tick.C
}
}()
}

// imageFSPath returns containerd image filesystem path.
// Note that if containerd changes directory layout, we also needs to change this.
func imageFSPath(rootDir, snapshotter string) string {
Expand Down
4 changes: 0 additions & 4 deletions pkg/server/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ 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(c.cniLoadOptions()...); err != nil {
log.G(ctx).WithError(err).Errorf("Failed to load cni configuration")
}
// Check the status of the cni initialization
if err := c.netPlugin.Status(); err != nil {
networkCondition.Status = false
Expand Down

0 comments on commit 80027f4

Please sign in to comment.