Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force to invoke all CNI plugin's delete at pods' tearing down #86

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions pkg/ocicni/ocicni.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ func (plugin *cniNetworkPlugin) loadNetworkFromCache(name string, rt *libcni.Run

type forEachNetworkFn func(*cniNetwork, *PodNetwork, *libcni.RuntimeConf) error

func (plugin *cniNetworkPlugin) forEachNetwork(podNetwork *PodNetwork, fromCache bool, actionFn forEachNetworkFn) error {
func (plugin *cniNetworkPlugin) forEachNetwork(podNetwork *PodNetwork, fromCache bool, actionFn forEachNetworkFn, force bool) error {
networks := podNetwork.Networks
if len(networks) == 0 {
networks = append(networks, NetAttachment{
Expand All @@ -457,6 +457,9 @@ func (plugin *cniNetworkPlugin) forEachNetwork(podNetwork *PodNetwork, fromCache
if req.Ifname != "" {
// Make sure the requested name isn't already assigned
if allIfNames[req.Ifname] {
if force {
continue
}
return fmt.Errorf("network %q requested interface name %q already assigned", req.Name, req.Ifname)
}
allIfNames[req.Ifname] = true
Expand All @@ -482,6 +485,9 @@ func (plugin *cniNetworkPlugin) forEachNetwork(podNetwork *PodNetwork, fromCache
rt, err := buildCNIRuntimeConf(podNetwork, ifName, podNetwork.RuntimeConfig[network.Name])
if err != nil {
logrus.Errorf("error building CNI runtime config: %v", err)
if force {
continue
}
return err
}

Expand All @@ -503,16 +509,25 @@ func (plugin *cniNetworkPlugin) forEachNetwork(podNetwork *PodNetwork, fromCache
// try to load the networks again
if err2 := plugin.syncNetworkConfig(); err2 != nil {
logrus.Error(err2)
if force {
continue
}
return err
}
cniNet, err = plugin.getNetwork(network.Name)
if err != nil {
if force {
continue
}
return err
}
}
}

if err := actionFn(cniNet, podNetwork, rt); err != nil {
if force {
continue
}
return err
}
}
Expand Down Expand Up @@ -552,7 +567,7 @@ func (plugin *cniNetworkPlugin) SetUpPodWithContext(ctx context.Context, podNetw
},
})
return nil
}); err != nil {
}, false); err != nil {
return nil, err
}

Expand Down Expand Up @@ -658,7 +673,7 @@ func (plugin *cniNetworkPlugin) TearDownPodWithContext(ctx context.Context, podN
return fmt.Errorf("Error while removing pod from CNI network %q: %s", network.name, err)
}
return nil
})
}, true)
}

// GetPodNetworkStatus returns IP addressing and interface details for all
Expand Down Expand Up @@ -695,7 +710,7 @@ func (plugin *cniNetworkPlugin) GetPodNetworkStatusWithContext(ctx context.Conte
})
}
return nil
}); err != nil {
}, false); err != nil {
return nil, err
}

Expand Down Expand Up @@ -810,7 +825,7 @@ func buildCNIRuntimeConf(podNetwork *PodNetwork, ifName string, runtimeConfig Ru
}

// Propagate existing CNI_ARGS to non-k8s consumers
for _, kvpairs := range strings.Split(os.Getenv("CNI_ARGS"), ";"){
for _, kvpairs := range strings.Split(os.Getenv("CNI_ARGS"), ";") {
if keyval := strings.SplitN(kvpairs, "=", 2); len(keyval) == 2 {
rt.Args = append(rt.Args, [2]string{keyval[0], keyval[1]})
}
Expand Down