Commit e14d9a7f authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #48091 from rpothier/kubenet-ipv6

Automatic merge from submit-queue (batch tested with PRs 45467, 48091, 48033, 48498) Allow Kubenet with ipv6 When running kubenet with IPv6, there is a panic as there is IPv4 specific code the Event function. With this change, Event will support IPv4 and IPv6 **What this PR does / why we need it**: This PR allows kubenet to use IPv6. Currently there is a panic in kubenet_linux.go as there is IPv4 specific code. **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #48089 **Special notes for your reviewer**: **Release note**: ```release-note-NONE ```
parents e16b59aa d716557f
...@@ -259,7 +259,7 @@ func (plugin *kubenetNetworkPlugin) Event(name string, details map[string]interf ...@@ -259,7 +259,7 @@ func (plugin *kubenetNetworkPlugin) Event(name string, details map[string]interf
if err == nil { if err == nil {
setHairpin := plugin.hairpinMode == componentconfig.HairpinVeth setHairpin := plugin.hairpinMode == componentconfig.HairpinVeth
// Set bridge address to first address in IPNet // Set bridge address to first address in IPNet
cidr.IP.To4()[3] += 1 cidr.IP[len(cidr.IP)-1] += 1
json := fmt.Sprintf(NET_CONFIG_TEMPLATE, BridgeName, plugin.mtu, network.DefaultInterfaceName, setHairpin, podCIDR, cidr.IP.String()) json := fmt.Sprintf(NET_CONFIG_TEMPLATE, BridgeName, plugin.mtu, network.DefaultInterfaceName, setHairpin, podCIDR, cidr.IP.String())
glog.V(2).Infof("CNI network config set to %v", json) glog.V(2).Infof("CNI network config set to %v", json)
......
...@@ -232,37 +232,61 @@ func TestGenerateMacAddress(t *testing.T) { ...@@ -232,37 +232,61 @@ func TestGenerateMacAddress(t *testing.T) {
// TestInvocationWithoutRuntime invokes the plugin without a runtime. // TestInvocationWithoutRuntime invokes the plugin without a runtime.
// This is how kubenet is invoked from the cri. // This is how kubenet is invoked from the cri.
func TestTearDownWithoutRuntime(t *testing.T) { func TestTearDownWithoutRuntime(t *testing.T) {
fhost := nettest.NewFakeHost(nil) testCases := []struct {
fhost.Legacy = false podCIDR string
fhost.Runtime = nil ip string
mockcni := &mock_cni.MockCNI{} expectedGateway string
}{
fexec := &exec.FakeExec{ {
CommandScript: []exec.FakeCommandAction{}, podCIDR: "10.0.0.1/24",
LookPathFunc: func(file string) (string, error) { ip: "10.0.0.1",
return fmt.Sprintf("/fake-bin/%s", file), nil expectedGateway: "10.0.0.1",
},
{
podCIDR: "2001:beef::1/48",
ip: "2001:beef::1",
expectedGateway: "2001:beef::1",
}, },
} }
for _, tc := range testCases {
fhost := nettest.NewFakeHost(nil)
fhost.Legacy = false
fhost.Runtime = nil
mockcni := &mock_cni.MockCNI{}
fexec := &exec.FakeExec{
CommandScript: []exec.FakeCommandAction{},
LookPathFunc: func(file string) (string, error) {
return fmt.Sprintf("/fake-bin/%s", file), nil
},
}
kubenet := newFakeKubenetPlugin(map[kubecontainer.ContainerID]string{}, fexec, fhost) kubenet := newFakeKubenetPlugin(map[kubecontainer.ContainerID]string{}, fexec, fhost)
kubenet.cniConfig = mockcni kubenet.cniConfig = mockcni
kubenet.iptables = ipttest.NewFake() kubenet.iptables = ipttest.NewFake()
details := make(map[string]interface{}) details := make(map[string]interface{})
details[network.NET_PLUGIN_EVENT_POD_CIDR_CHANGE_DETAIL_CIDR] = "10.0.0.1/24" details[network.NET_PLUGIN_EVENT_POD_CIDR_CHANGE_DETAIL_CIDR] = tc.podCIDR
kubenet.Event(network.NET_PLUGIN_EVENT_POD_CIDR_CHANGE, details) kubenet.Event(network.NET_PLUGIN_EVENT_POD_CIDR_CHANGE, details)
existingContainerID := kubecontainer.BuildContainerID("docker", "123") if kubenet.gateway.String() != tc.expectedGateway {
kubenet.podIPs[existingContainerID] = "10.0.0.1" t.Errorf("generated gateway: %q, expecting: %q", kubenet.gateway.String(), tc.expectedGateway)
}
if kubenet.podCidr != tc.podCIDR {
t.Errorf("generated podCidr: %q, expecting: %q", kubenet.podCidr, tc.podCIDR)
}
existingContainerID := kubecontainer.BuildContainerID("docker", "123")
kubenet.podIPs[existingContainerID] = tc.ip
mockcni.On("DelNetwork", mock.AnythingOfType("*libcni.NetworkConfig"), mock.AnythingOfType("*libcni.RuntimeConf")).Return(nil) mockcni.On("DelNetwork", mock.AnythingOfType("*libcni.NetworkConfig"), mock.AnythingOfType("*libcni.RuntimeConf")).Return(nil)
if err := kubenet.TearDownPod("namespace", "name", existingContainerID); err != nil { if err := kubenet.TearDownPod("namespace", "name", existingContainerID); err != nil {
t.Fatalf("Unexpected error in TearDownPod: %v", err) t.Fatalf("Unexpected error in TearDownPod: %v", err)
}
// Assert that the CNI DelNetwork made it through and we didn't crash
// without a runtime.
mockcni.AssertExpectations(t)
} }
// Assert that the CNI DelNetwork made it through and we didn't crash
// without a runtime.
mockcni.AssertExpectations(t)
} }
//TODO: add unit test for each implementation of network plugin interface //TODO: add unit test for each implementation of network plugin interface
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment