From 23ce4a8a69e09db7fde7796030166a006d152599 Mon Sep 17 00:00:00 2001 From: Miguel Duarte Barroso Date: Fri, 18 Nov 2022 15:50:33 +0100 Subject: [PATCH 1/2] ci: lint e2e tests Signed-off-by: Miguel Duarte Barroso --- .github/workflows/check.yaml | 2 +- e2e/client/types.go | 27 ++++++++++++++------------- e2e/status/helpers.go | 8 +++++--- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index b5e1fbeb..703b7886 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -32,7 +32,7 @@ jobs: uses: golangci/golangci-lint-action@v3 with: version: v1.47.3 - args: --timeout 3m --verbose cmd/... pkg/... + args: --timeout 3m --verbose cmd/... pkg/... e2e/... - name: Test run: make test diff --git a/e2e/client/types.go b/e2e/client/types.go index 8840ce24..5aa5dbf9 100644 --- a/e2e/client/types.go +++ b/e2e/client/types.go @@ -76,8 +76,8 @@ func (c *E2EClient) DeleteNamespace(name string) error { return nil } -func (c *E2EClient) ProvisionPod(podName string, namespace string, label, annotations map[string]string) (*corev1.Pod, error) { - pod := PodObject(podName, namespace, label, annotations) +func (c *E2EClient) ProvisionPod(podName string, namespace string, label, podAnnotations map[string]string) (*corev1.Pod, error) { + pod := PodObject(podName, namespace, label, podAnnotations) pod, err := c.k8sClient.CoreV1().Pods(pod.Namespace).Create(context.Background(), pod, metav1.CreateOptions{}) if err != nil { return nil, err @@ -144,8 +144,9 @@ func (c *E2EClient) WaitForPodBySelector(namespace, selector string, timeout tim return nil } - for _, pod := range podList.Items { - if err := c.WaitForPodReady(namespace, pod.Name, timeout); err != nil { + pods := podList.Items + for i := range pods { + if err := c.WaitForPodReady(namespace, pods[i].Name, timeout); err != nil { return err } } @@ -196,9 +197,9 @@ func isPodGone(cs kubernetes.Interface, podName, namespace string) wait.Conditio } } -func PodObject(podName string, namespace string, label, annotations map[string]string) *corev1.Pod { +func PodObject(podName string, namespace string, label, podAnnotations map[string]string) *corev1.Pod { return &corev1.Pod{ - ObjectMeta: podMeta(podName, namespace, label, annotations), + ObjectMeta: podMeta(podName, namespace, label, podAnnotations), Spec: podSpec("samplepod"), } } @@ -220,31 +221,31 @@ func containerCmd() []string { return []string{"/bin/ash", "-c", "trap : TERM INT; sleep infinity & wait"} } -func podMeta(podName string, namespace string, label map[string]string, annotations map[string]string) metav1.ObjectMeta { +func podMeta(podName string, namespace string, label map[string]string, podAnnotations map[string]string) metav1.ObjectMeta { return metav1.ObjectMeta{ Name: podName, Namespace: namespace, Labels: label, - Annotations: annotations, + Annotations: podAnnotations, } } func dynamicNetworksAnnotation(pod *corev1.Pod, newIfaceConfigs ...*nettypes.NetworkSelectionElement) string { - currentNetworkSelectionElements, err := extractPodNetworkSelectionElements(pod) + networkSelectionElements, err := extractPodNetworkSelectionElements(pod) if err != nil { return "" } - updatedNetworkSelectionElements := append( - currentNetworkSelectionElements, + networkSelectionElements = append( + networkSelectionElements, newIfaceConfigs..., ) - newSelectionElements, err := json.Marshal(updatedNetworkSelectionElements) + updatedNetworkSelectionElements, err := json.Marshal(networkSelectionElements) if err != nil { return "" } - return string(newSelectionElements) + return string(updatedNetworkSelectionElements) } func removeFromDynamicNetworksAnnotation(pod *corev1.Pod, networkName string, netNamespace string, ifaceName string) string { diff --git a/e2e/status/helpers.go b/e2e/status/helpers.go index 79d91c85..b6eb583b 100644 --- a/e2e/status/helpers.go +++ b/e2e/status/helpers.go @@ -18,10 +18,12 @@ func FilterPodsNetworkStatus(clients *client.E2EClient, namespace, podName strin if err != nil { return nil } + + podsCurrentNetworks := PodDynamicNetworks(&pods.Items[0]) var podNetworkStatus []nettypes.NetworkStatus - for _, netStatus := range PodDynamicNetworks(&pods.Items[0]) { - if p(netStatus) { - podNetworkStatus = append(podNetworkStatus, netStatus) + for i := range podsCurrentNetworks { + if p(podsCurrentNetworks[i]) { + podNetworkStatus = append(podNetworkStatus, podsCurrentNetworks[i]) } } return podNetworkStatus From 4857f09f1fd2c9cb12e592dd0e9f6aba10d96c52 Mon Sep 17 00:00:00 2001 From: Miguel Duarte Barroso Date: Fri, 18 Nov 2022 15:52:37 +0100 Subject: [PATCH 2/2] ci: bump linters to v.1.50.1 Signed-off-by: Miguel Duarte Barroso --- .github/workflows/check.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index 703b7886..843bf4a4 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -31,7 +31,7 @@ jobs: - name: Linters uses: golangci/golangci-lint-action@v3 with: - version: v1.47.3 + version: v1.50.1 args: --timeout 3m --verbose cmd/... pkg/... e2e/... - name: Test