mirror of
https://github.com/k8snetworkplumbingwg/multus-cni.git
synced 2025-09-15 05:54:06 +00:00
Default network readiness fix conflicts after rebase
This commit is contained in:
committed by
Tomofumi Hayashi
parent
1caddaef4f
commit
21cdfe5485
16
README.md
16
README.md
@@ -17,6 +17,7 @@
|
|||||||
* [Using with Multus conf file](#using-with-multus-conf-file)
|
* [Using with Multus conf file](#using-with-multus-conf-file)
|
||||||
* [Logging Options](#logging-options)
|
* [Logging Options](#logging-options)
|
||||||
* [How to use with Network Device plugins?](#cni-running-with-network-device-plugin)
|
* [How to use with Network Device plugins?](#cni-running-with-network-device-plugin)
|
||||||
|
* [Default Network Readiness Checks](#default-network-readiness-checks)
|
||||||
* [Testing Multus CNI](#testing-multus-cni)
|
* [Testing Multus CNI](#testing-multus-cni)
|
||||||
* [Multiple flannel networks](#multiple-flannel-networks)
|
* [Multiple flannel networks](#multiple-flannel-networks)
|
||||||
* [Configure Kubernetes with CNI](#configure-kubernetes-with-cni)
|
* [Configure Kubernetes with CNI](#configure-kubernetes-with-cni)
|
||||||
@@ -500,6 +501,21 @@ Allocation of the Network device(such as SRIOV VFs) are done by Device plugins(E
|
|||||||
* [Device plugin & CNI, NUMA Manager alignment - technical architecture document](https://docs.google.com/document/d/1Ewe9Of84GkP0b2Q2PC0y9RVZNkN2WeVEagX9m99Nrzc/edit)
|
* [Device plugin & CNI, NUMA Manager alignment - technical architecture document](https://docs.google.com/document/d/1Ewe9Of84GkP0b2Q2PC0y9RVZNkN2WeVEagX9m99Nrzc/edit)
|
||||||
* Reference implementation : [SRIOV Network device plugin](https://github.com/intel/sriov-network-device-plugin)
|
* Reference implementation : [SRIOV Network device plugin](https://github.com/intel/sriov-network-device-plugin)
|
||||||
* Example: [How to make Multus work with device plugin?](https://github.com/intel/multus-cni/tree/master/examples#passing-down-device-information)
|
* Example: [How to make Multus work with device plugin?](https://github.com/intel/multus-cni/tree/master/examples#passing-down-device-information)
|
||||||
|
|
||||||
|
## Default Network Readiness Checks
|
||||||
|
|
||||||
|
You may wish for your "default network" (that is, the CNI plugin & its configuration you specify as your default delegate) to become ready before you attach networks with Multus. This is disabled by default and not used unless you add the readiness check option(s) to your CNI configuration file.
|
||||||
|
|
||||||
|
For example, if you use Flannel as a default network, the recommended method for Flannel to be installed is via a daemonset that also drops a configuration file in `/etc/cni/net.d/`. This may apply to other plugins that place that configuration file upon their readiness, hence, Multus uses their configuration filename as a semaphore and optionally waits to attach networks to pods until that file exists.
|
||||||
|
|
||||||
|
In this manner, you may prevent pods from crash looping, and instead wait for that default network to be ready.
|
||||||
|
|
||||||
|
Only one option is necessary to configure this functionality:
|
||||||
|
|
||||||
|
* `readinessindicatorfile`: The path to a file whose existance denotes that the default network is ready.
|
||||||
|
|
||||||
|
*NOTE*: If `readinessindicatorfile` is unset, or is an empty string, this functionality will be disabled, and is disabled by default.
|
||||||
|
|
||||||
## Testing Multus CNI
|
## Testing Multus CNI
|
||||||
|
|
||||||
### Multiple flannel networks
|
### Multiple flannel networks
|
||||||
|
@@ -24,6 +24,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/containernetworking/cni/libcni"
|
"github.com/containernetworking/cni/libcni"
|
||||||
"github.com/containernetworking/cni/pkg/invoke"
|
"github.com/containernetworking/cni/pkg/invoke"
|
||||||
@@ -35,8 +36,16 @@ import (
|
|||||||
"github.com/intel/multus-cni/logging"
|
"github.com/intel/multus-cni/logging"
|
||||||
"github.com/intel/multus-cni/types"
|
"github.com/intel/multus-cni/types"
|
||||||
"github.com/vishvananda/netlink"
|
"github.com/vishvananda/netlink"
|
||||||
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var defaultReadinessBackoff = wait.Backoff{
|
||||||
|
Steps: 4,
|
||||||
|
Duration: 250 * time.Millisecond,
|
||||||
|
Factor: 4.0,
|
||||||
|
Jitter: 0.1,
|
||||||
|
}
|
||||||
|
|
||||||
func saveScratchNetConf(containerID, dataDir string, netconf []byte) error {
|
func saveScratchNetConf(containerID, dataDir string, netconf []byte) error {
|
||||||
logging.Debugf("saveScratchNetConf: %s, %s, %s", containerID, dataDir, string(netconf))
|
logging.Debugf("saveScratchNetConf: %s, %s, %s", containerID, dataDir, string(netconf))
|
||||||
if err := os.MkdirAll(dataDir, 0700); err != nil {
|
if err := os.MkdirAll(dataDir, 0700); err != nil {
|
||||||
@@ -228,6 +237,16 @@ func cmdAdd(args *skel.CmdArgs, exec invoke.Exec, kubeClient k8s.KubeClient) (cn
|
|||||||
return nil, logging.Errorf("Multus: Err in getting k8s args: %v", err)
|
return nil, logging.Errorf("Multus: Err in getting k8s args: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wait.ExponentialBackoff(defaultReadinessBackoff, func() (bool, error) {
|
||||||
|
_, err := os.Stat(n.ReadinessIndicatorFile)
|
||||||
|
switch {
|
||||||
|
case err == nil:
|
||||||
|
return true, nil
|
||||||
|
default:
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
numK8sDelegates, kc, err := k8s.TryLoadK8sDelegates(k8sArgs, n, kubeClient)
|
numK8sDelegates, kc, err := k8s.TryLoadK8sDelegates(k8sArgs, n, kubeClient)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, logging.Errorf("Multus: Err in loading K8s Delegates k8s args: %v", err)
|
return nil, logging.Errorf("Multus: Err in loading K8s Delegates k8s args: %v", err)
|
||||||
|
@@ -173,6 +173,8 @@ var _ = Describe("multus operations", func() {
|
|||||||
StdinData: []byte(`{
|
StdinData: []byte(`{
|
||||||
"name": "node-cni-network",
|
"name": "node-cni-network",
|
||||||
"type": "multus",
|
"type": "multus",
|
||||||
|
"defaultnetworkfile": "/tmp/foo.multus.conf",
|
||||||
|
"defaultnetworkwaitseconds": 3,
|
||||||
"delegates": [{
|
"delegates": [{
|
||||||
"name": "weave1",
|
"name": "weave1",
|
||||||
"cniVersion": "0.2.0",
|
"cniVersion": "0.2.0",
|
||||||
@@ -185,6 +187,10 @@ var _ = Describe("multus operations", func() {
|
|||||||
}`),
|
}`),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Touch the default network file.
|
||||||
|
configPath := "/tmp/foo.multus.conf"
|
||||||
|
os.OpenFile(configPath, os.O_RDONLY|os.O_CREATE, 0755)
|
||||||
|
|
||||||
fExec := &fakeExec{}
|
fExec := &fakeExec{}
|
||||||
expectedResult1 := &types020.Result{
|
expectedResult1 := &types020.Result{
|
||||||
CNIVersion: "0.2.0",
|
CNIVersion: "0.2.0",
|
||||||
@@ -226,6 +232,13 @@ var _ = Describe("multus operations", func() {
|
|||||||
err = cmdDel(args, fExec, nil)
|
err = cmdDel(args, fExec, nil)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(fExec.delIndex).To(Equal(len(fExec.plugins)))
|
Expect(fExec.delIndex).To(Equal(len(fExec.plugins)))
|
||||||
|
|
||||||
|
// Cleanup default network file.
|
||||||
|
if _, errStat := os.Stat(configPath); errStat == nil {
|
||||||
|
errRemove := os.Remove(configPath)
|
||||||
|
Expect(errRemove).NotTo(HaveOccurred())
|
||||||
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
It("executes delegates and kubernetes networks", func() {
|
It("executes delegates and kubernetes networks", func() {
|
||||||
|
@@ -30,6 +30,7 @@ const (
|
|||||||
defaultCNIDir = "/var/lib/cni/multus"
|
defaultCNIDir = "/var/lib/cni/multus"
|
||||||
defaultConfDir = "/etc/cni/multus/net.d"
|
defaultConfDir = "/etc/cni/multus/net.d"
|
||||||
defaultBinDir = "/opt/cni/bin"
|
defaultBinDir = "/opt/cni/bin"
|
||||||
|
defaultReadinessIndicatorFile = ""
|
||||||
)
|
)
|
||||||
|
|
||||||
func LoadDelegateNetConfList(bytes []byte, delegateConf *DelegateNetConf) error {
|
func LoadDelegateNetConfList(bytes []byte, delegateConf *DelegateNetConf) error {
|
||||||
@@ -200,6 +201,10 @@ func LoadNetConf(bytes []byte) (*NetConf, error) {
|
|||||||
netconf.BinDir = defaultBinDir
|
netconf.BinDir = defaultBinDir
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if netconf.ReadinessIndicatorFile == "" {
|
||||||
|
netconf.ReadinessIndicatorFile = defaultReadinessIndicatorFile
|
||||||
|
}
|
||||||
|
|
||||||
for idx, rawConf := range netconf.RawDelegates {
|
for idx, rawConf := range netconf.RawDelegates {
|
||||||
bytes, err := json.Marshal(rawConf)
|
bytes, err := json.Marshal(rawConf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -88,4 +88,40 @@ var _ = Describe("config operations", func() {
|
|||||||
_, err := LoadNetConf([]byte(conf))
|
_, err := LoadNetConf([]byte(conf))
|
||||||
Expect(err).To(HaveOccurred())
|
Expect(err).To(HaveOccurred())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("has defaults set for network readiness", func() {
|
||||||
|
conf := `{
|
||||||
|
"name": "defaultnetwork",
|
||||||
|
"type": "multus",
|
||||||
|
"kubeconfig": "/etc/kubernetes/kubelet.conf",
|
||||||
|
"delegates": [{
|
||||||
|
"cniVersion": "0.3.0",
|
||||||
|
"name": "defaultnetwork",
|
||||||
|
"type": "flannel",
|
||||||
|
"isDefaultGateway": true
|
||||||
|
}]
|
||||||
|
}`
|
||||||
|
netConf, err := LoadNetConf([]byte(conf))
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
Expect(netConf.ReadinessIndicatorFile).To(Equal(""))
|
||||||
|
})
|
||||||
|
|
||||||
|
It("honors overrides for network readiness", func() {
|
||||||
|
conf := `{
|
||||||
|
"name": "defaultnetwork",
|
||||||
|
"type": "multus",
|
||||||
|
"readinessindicatorfile": "/etc/cni/net.d/foo",
|
||||||
|
"kubeconfig": "/etc/kubernetes/kubelet.conf",
|
||||||
|
"delegates": [{
|
||||||
|
"cniVersion": "0.3.0",
|
||||||
|
"name": "defaultnetwork",
|
||||||
|
"type": "flannel",
|
||||||
|
"isDefaultGateway": true
|
||||||
|
}]
|
||||||
|
}`
|
||||||
|
netConf, err := LoadNetConf([]byte(conf))
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
Expect(netConf.ReadinessIndicatorFile).To(Equal("/etc/cni/net.d/foo"))
|
||||||
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
@@ -43,6 +43,8 @@ type NetConf struct {
|
|||||||
LogFile string `json:"logFile"`
|
LogFile string `json:"logFile"`
|
||||||
LogLevel string `json:"logLevel"`
|
LogLevel string `json:"logLevel"`
|
||||||
RuntimeConfig *RuntimeConfig `json:"runtimeConfig,omitempty"`
|
RuntimeConfig *RuntimeConfig `json:"runtimeConfig,omitempty"`
|
||||||
|
// Default network readiness options
|
||||||
|
ReadinessIndicatorFile string `json:readinessindicatorfile`
|
||||||
}
|
}
|
||||||
|
|
||||||
type RuntimeConfig struct {
|
type RuntimeConfig struct {
|
||||||
|
Reference in New Issue
Block a user