func (plugin *cniNetworkPlugin) TearDownPod(namespace string, name string, id kubecontainer.DockerID) error { runtime, ok := plugin.host.GetRuntime().(*dockertools.DockerManager) if !ok { return fmt.Errorf("CNI execution called on non-docker runtime") } netns, err := runtime.GetNetNS(id.ContainerID()) if err != nil { return err } return plugin.defaultNetwork.deleteFromNetwork(name, namespace, id.ContainerID(), netns) }
func (plugin *cniNetworkPlugin) SetUpPod(namespace string, name string, id kubecontainer.DockerID) error { runtime, ok := plugin.host.GetRuntime().(*dockertools.DockerManager) if !ok { return fmt.Errorf("CNI execution called on non-docker runtime") } netns, err := runtime.GetNetNS(id.ContainerID()) if err != nil { return err } _, err = plugin.defaultNetwork.addToNetwork(name, namespace, id.ContainerID(), netns) if err != nil { glog.Errorf("Error while adding to cni network: %s", err) return err } return err }
func (plugin *kubenetNetworkPlugin) SetUpPod(namespace string, name string, id kubecontainer.DockerID) error { // Can't set up pods if we don't have a PodCIDR yet if plugin.netConfig == nil { return fmt.Errorf("Kubenet needs a PodCIDR to set up pods") } runtime, ok := plugin.host.GetRuntime().(*dockertools.DockerManager) if !ok { return fmt.Errorf("Kubenet execution called on non-docker runtime") } netnsPath, err := runtime.GetNetNS(id.ContainerID()) if err != nil { return err } rt := buildCNIRuntimeConf(name, namespace, id.ContainerID(), netnsPath) if err != nil { return fmt.Errorf("Error building CNI config: %v", err) } glog.V(3).Infof("Calling cni plugins to add container to network with cni runtime: %+v", rt) res, err := plugin.cniConfig.AddNetwork(plugin.netConfig, rt) if err != nil { return fmt.Errorf("Error adding container to network: %v", err) } if res.IP4 == nil { return fmt.Errorf("CNI plugin reported no IPv4 address for container %v.", id) } plugin.podCIDRs[id] = res.IP4.IP.String() // The first SetUpPod call creates the bridge; ensure shaping is enabled if plugin.shaper == nil { plugin.shaper = bandwidth.NewTCShaper(BridgeName) if plugin.shaper == nil { return fmt.Errorf("Failed to create bandwidth shaper!") } plugin.shaper.ReconcileInterface() } // TODO: get ingress/egress from Pod.Spec and add pod CIDR to shaper return nil }
func (plugin *kubenetNetworkPlugin) TearDownPod(namespace string, name string, id kubecontainer.DockerID) error { if plugin.netConfig == nil { return fmt.Errorf("Kubenet needs a PodCIDR to tear down pods") } runtime, ok := plugin.host.GetRuntime().(*dockertools.DockerManager) if !ok { return fmt.Errorf("Kubenet execution called on non-docker runtime") } netnsPath, err := runtime.GetNetNS(id.ContainerID()) if err != nil { return err } rt := buildCNIRuntimeConf(name, namespace, id.ContainerID(), netnsPath) if err != nil { return fmt.Errorf("Error building CNI config: %v", err) } // no cached CIDR is Ok during teardown if cidr, ok := plugin.podCIDRs[id]; ok { glog.V(5).Infof("Removing pod CIDR %s from shaper", cidr) // shaper wants /32 if addr, _, err := net.ParseCIDR(cidr); err != nil { if err = plugin.shaper.Reset(fmt.Sprintf("%s/32", addr.String())); err != nil { glog.Warningf("Failed to remove pod CIDR %s from shaper: %v", cidr, err) } } } delete(plugin.podCIDRs, id) glog.V(3).Infof("Calling cni plugins to remove container from network with cni runtime: %+v", rt) if err := plugin.cniConfig.DelNetwork(plugin.netConfig, rt); err != nil { return fmt.Errorf("Error removing container from network: %v", err) } return nil }