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

ci: lint e2e tests #87

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ jobs:
- name: Linters
uses: golangci/golangci-lint-action@v3
with:
version: v1.47.3
args: --timeout 3m --verbose cmd/... pkg/...
version: v1.50.1
args: --timeout 3m --verbose cmd/... pkg/... e2e/...

- name: Test
run: make test
Expand Down
27 changes: 14 additions & 13 deletions e2e/client/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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"),
}
}
Expand All @@ -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 {
Expand Down
8 changes: 5 additions & 3 deletions e2e/status/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down