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 <abhi@docker.com>
This commit is contained in:
parent
e3d57d240f
commit
263b0b99d0
@ -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
|
// Try to load the config if it exists. Just log the error if load fails
|
||||||
// This is not disruptive for containerd to panic
|
// 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")
|
logrus.WithError(err).Error("Failed to load cni during init, please check CRI plugin status before setting up network for pods")
|
||||||
}
|
}
|
||||||
// prepare streaming server
|
// prepare streaming server
|
||||||
|
@ -22,6 +22,7 @@ import (
|
|||||||
goruntime "runtime"
|
goruntime "runtime"
|
||||||
|
|
||||||
cni "github.com/containerd/go-cni"
|
cni "github.com/containerd/go-cni"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2"
|
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,
|
Type: runtime.NetworkReady,
|
||||||
Status: true,
|
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
|
// Check the status of the cni initialization
|
||||||
if err := c.netPlugin.Status(); err != nil {
|
if err := c.netPlugin.Status(); err != nil {
|
||||||
// If it is not initialized, then load the config and retry
|
networkCondition.Status = false
|
||||||
if err = c.netPlugin.Load(cni.WithLoNetwork(), cni.WithDefaultConf()); err != nil {
|
networkCondition.Reason = networkNotReadyReason
|
||||||
networkCondition.Status = false
|
networkCondition.Message = fmt.Sprintf("Network plugin returns error: %v", err)
|
||||||
networkCondition.Reason = networkNotReadyReason
|
|
||||||
networkCondition.Message = fmt.Sprintf("Network plugin returns error: %v", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := &runtime.StatusResponse{
|
resp := &runtime.StatusResponse{
|
||||||
|
@ -47,6 +47,6 @@ 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.CNIOpt) error {
|
||||||
return f.LoadErr
|
return f.LoadErr
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ func (c *criService) UpdateRuntimeConfig(ctx context.Context, r *runtime.UpdateR
|
|||||||
if err := c.netPlugin.Status(); err == nil {
|
if err := c.netPlugin.Status(); err == nil {
|
||||||
logrus.Infof("Network plugin is ready, skip generating cni config from template %q", confTemplate)
|
logrus.Infof("Network plugin is ready, skip generating cni config from template %q", confTemplate)
|
||||||
return &runtime.UpdateRuntimeConfigResponse{}, nil
|
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)
|
logrus.Infof("CNI config is successfully loaded, skip generating cni config from template %q", confTemplate)
|
||||||
return &runtime.UpdateRuntimeConfigResponse{}, nil
|
return &runtime.UpdateRuntimeConfigResponse{}, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user