(t *testing.T)
| 107 | } |
| 108 | |
| 109 | func TestNriPluginNetworkingLifecycle(t *testing.T) { |
| 110 | skipNriTestIfNecessary(t) |
| 111 | |
| 112 | t.Log("Test that NRI plugins get pod networking attributes during the pod lifecycle.") |
| 113 | |
| 114 | var ( |
| 115 | tc = &nriTest{ |
| 116 | t: t, |
| 117 | } |
| 118 | podName = "pod-net-lifecycle" |
| 119 | ) |
| 120 | |
| 121 | tc.setup() |
| 122 | |
| 123 | hookExecs := 0 |
| 124 | // override hooks are executed after the sync events, use channels to synchronize the test |
| 125 | runPodSandboxCh := make(chan struct{}) |
| 126 | stopPodSandboxCh := make(chan struct{}) |
| 127 | removePodSandboxCh := make(chan struct{}) |
| 128 | |
| 129 | plugin := &mockPlugin{ |
| 130 | runPodSandbox: func(mp *mockPlugin, pod *api.PodSandbox) error { |
| 131 | t.Logf("runPodSandbox pod %s/%s: namespace=%s ips=%v", pod.GetNamespace(), pod.GetName(), getNetworkNamespace(pod), pod.GetIps()) |
| 132 | if pod.Name != podName { |
| 133 | return nil |
| 134 | } |
| 135 | defer close(runPodSandboxCh) |
| 136 | // get the pod network namespace |
| 137 | ns := getNetworkNamespace(pod) |
| 138 | // test only creates pods with network |
| 139 | require.NotEmpty(t, ns) |
| 140 | require.ElementsMatch(t, pod.GetIps(), getNetworkNamespaceIPs(ns)) |
| 141 | hookExecs++ |
| 142 | return nil |
| 143 | }, |
| 144 | stopPodSandbox: func(mp *mockPlugin, pod *api.PodSandbox) error { |
| 145 | t.Logf("stopPodSandbox pod %s/%s: namespace=%s ips=%v", pod.GetNamespace(), pod.GetName(), getNetworkNamespace(pod), pod.GetIps()) |
| 146 | if pod.Name != podName { |
| 147 | return nil |
| 148 | } |
| 149 | defer close(stopPodSandboxCh) |
| 150 | // get the pod network namespace |
| 151 | ns := getNetworkNamespace(pod) |
| 152 | // test only creates pods with network |
| 153 | require.NotEmpty(t, ns) |
| 154 | require.ElementsMatch(t, pod.GetIps(), getNetworkNamespaceIPs(ns)) |
| 155 | hookExecs++ |
| 156 | return nil |
| 157 | }, |
| 158 | removePodSandbox: func(mp *mockPlugin, pod *api.PodSandbox) error { |
| 159 | t.Logf("removePodSandbox pod %s/%s: namespace=%s ips=%v", pod.GetNamespace(), pod.GetName(), getNetworkNamespace(pod), pod.GetIps()) |
| 160 | if pod.Name != podName { |
| 161 | return nil |
| 162 | } |
| 163 | defer close(removePodSandboxCh) |
| 164 | // get the pod network namespace |
| 165 | ns := getNetworkNamespace(pod) |
| 166 | // test only creates pods with network but at this point networking namespace is not present |
nothing calls this directly
no test coverage detected
searching dependent graphs…