From 8ffed24bc6601ee7a7345702caeb20a43328432a Mon Sep 17 00:00:00 2001 From: Carl Montanari Date: Fri, 22 Mar 2024 14:23:17 -0700 Subject: [PATCH 1/6] test: more and more meaingful e2e test for basic c9s functionality --- .github/vars.env | 4 +- .golangci.yaml | 4 +- .../basic/test-fixtures/20-apply.yaml | 20 +++ .../10-connectivity.topology-basic.yaml | 17 +++ .../10-deployment.topology-basic-srl1.yaml | 136 +++++++++++++++++ .../10-service.topology-basic-srl1-vx.yaml | 39 +++++ .../20-connectivity.topology-basic.yaml | 27 ++++ .../20-deployment.topology-basic-srl1.yaml | 137 ++++++++++++++++++ .../20-deployment.topology-basic-srl2.yaml | 136 +++++++++++++++++ .../20-service.topology-basic-srl1-vx.yaml | 39 +++++ .../20-service.topology-basic-srl1.yaml | 89 ++++++++++++ .../golden/20-topology.topology-basic.yaml | 135 +++++++++++++++++ e2e/topology/basic/topology_basic_test.go | 65 +++++++++ testhelper/kubernetes.go | 39 +++++ testhelper/suite/run.go | 24 ++- 15 files changed, 894 insertions(+), 17 deletions(-) create mode 100644 e2e/topology/basic/test-fixtures/20-apply.yaml create mode 100755 e2e/topology/basic/test-fixtures/golden/10-connectivity.topology-basic.yaml create mode 100755 e2e/topology/basic/test-fixtures/golden/10-deployment.topology-basic-srl1.yaml create mode 100755 e2e/topology/basic/test-fixtures/golden/10-service.topology-basic-srl1-vx.yaml create mode 100755 e2e/topology/basic/test-fixtures/golden/20-connectivity.topology-basic.yaml create mode 100755 e2e/topology/basic/test-fixtures/golden/20-deployment.topology-basic-srl1.yaml create mode 100755 e2e/topology/basic/test-fixtures/golden/20-deployment.topology-basic-srl2.yaml create mode 100755 e2e/topology/basic/test-fixtures/golden/20-service.topology-basic-srl1-vx.yaml create mode 100755 e2e/topology/basic/test-fixtures/golden/20-service.topology-basic-srl1.yaml create mode 100755 e2e/topology/basic/test-fixtures/golden/20-topology.topology-basic.yaml diff --git a/.github/vars.env b/.github/vars.env index de8d072b..4ea766b5 100644 --- a/.github/vars.env +++ b/.github/vars.env @@ -1,8 +1,8 @@ GO_VERSION=1.22 -DEVSPACE_VERSION=v6.3.11 +DEVSPACE_VERSION=v6.3.12 GCI_VERSION=v0.12.3 GOFUMPT_VERSION=v0.6.0 -GOLANGCI_LINT_VERSION=v1.56.2 +GOLANGCI_LINT_VERSION=v1.57.1 GOLINES_VERSION=v0.12.2 GOTESTSUM_VERSION=v1.11.0 HELM_VERSION=v3.14.2 \ No newline at end of file diff --git a/.golangci.yaml b/.golangci.yaml index 431cd705..9b8667c7 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -177,7 +177,7 @@ issues: # prefer to sprintf -- feels more consistent overall - linters: - perfsprint - text: "can be replaced with string addition" + text: "can be replaced with string concatenation" run: go: '1.21' @@ -189,4 +189,4 @@ output: uniq-by-line: false service: - golangci-lint-version: 1.56.x + golangci-lint-version: 1.57.x diff --git a/e2e/topology/basic/test-fixtures/20-apply.yaml b/e2e/topology/basic/test-fixtures/20-apply.yaml new file mode 100644 index 00000000..773c4cf6 --- /dev/null +++ b/e2e/topology/basic/test-fixtures/20-apply.yaml @@ -0,0 +1,20 @@ +--- +apiVersion: clabernetes.containerlab.dev/v1alpha1 +kind: Topology +metadata: + name: topology-basic +spec: + definition: + containerlab: |- + name: topology-basic + + topology: + nodes: + srl1: + kind: srl + image: ghcr.io/nokia/srlinux + srl2: + kind: srl + image: ghcr.io/nokia/srlinux + links: + - endpoints: ["srl1:e1-1", "srl2:e1-1"] \ No newline at end of file diff --git a/e2e/topology/basic/test-fixtures/golden/10-connectivity.topology-basic.yaml b/e2e/topology/basic/test-fixtures/golden/10-connectivity.topology-basic.yaml new file mode 100755 index 00000000..7e96a450 --- /dev/null +++ b/e2e/topology/basic/test-fixtures/golden/10-connectivity.topology-basic.yaml @@ -0,0 +1,17 @@ +apiVersion: clabernetes.containerlab.dev/v1alpha1 +kind: Connectivity +metadata: + labels: + clabernetes/app: clabernetes + clabernetes/name: topology-basic + clabernetes/topologyKind: containerlab + clabernetes/topologyOwner: topology-basic + name: topology-basic + namespace: NAMESPACE + ownerReferences: + - apiVersion: clabernetes.containerlab.dev/v1alpha1 + kind: Topology + name: topology-basic +spec: + pointToPointTunnels: {} +status: {} diff --git a/e2e/topology/basic/test-fixtures/golden/10-deployment.topology-basic-srl1.yaml b/e2e/topology/basic/test-fixtures/golden/10-deployment.topology-basic-srl1.yaml new file mode 100755 index 00000000..e78fedbb --- /dev/null +++ b/e2e/topology/basic/test-fixtures/golden/10-deployment.topology-basic-srl1.yaml @@ -0,0 +1,136 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + annotations: {} + labels: + app.kubernetes.io/name: topology-basic-srl1 + clabernetes/app: clabernetes + clabernetes/name: topology-basic-srl1 + clabernetes/topologyNode: srl1 + clabernetes/topologyOwner: topology-basic + name: topology-basic-srl1 + namespace: NAMESPACE + ownerReferences: + - apiVersion: clabernetes.containerlab.dev/v1alpha1 + kind: Topology + name: topology-basic +spec: + progressDeadlineSeconds: 600 + replicas: 1 + revisionHistoryLimit: 0 + selector: + matchLabels: + app.kubernetes.io/name: topology-basic-srl1 + clabernetes/app: clabernetes + clabernetes/name: topology-basic-srl1 + clabernetes/topologyNode: srl1 + clabernetes/topologyOwner: topology-basic + strategy: + type: Recreate + template: + metadata: + creationTimestamp: null + labels: + app.kubernetes.io/name: topology-basic-srl1 + clabernetes/app: clabernetes + clabernetes/name: topology-basic-srl1 + clabernetes/topologyNode: srl1 + clabernetes/topologyOwner: topology-basic + spec: + containers: + - command: + - /clabernetes/manager + - launch + env: + - name: NODE_NAME + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: spec.nodeName + - name: POD_NAME + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: metadata.name + - name: POD_NAMESPACE + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: metadata.namespace + - name: APP_NAME + value: clabernetes + - name: MANAGER_NAMESPACE + value: clabernetes + - name: LAUNCHER_CRI_KIND + value: containerd + - name: LAUNCHER_IMAGE_PULL_THROUGH_MODE + value: auto + - name: LAUNCHER_LOGGER_LEVEL + value: debug + - name: LAUNCHER_TOPOLOGY_NAME + value: topology-basic + - name: LAUNCHER_NODE_NAME + value: srl1 + - name: LAUNCHER_NODE_IMAGE + value: ghcr.io/nokia/srlinux + - name: LAUNCHER_CONNECTIVITY_KIND + value: vxlan + - name: LAUNCHER_CONTAINERLAB_VERSION + - name: LAUNCHER_CONTAINERLAB_TIMEOUT + - name: LAUNCHER_PRIVILEGED + value: "true" + image: 172.31.254.11/clabernetes-launcher:dev-latest + imagePullPolicy: IfNotPresent + name: srl1 + ports: + - containerPort: 14789 + name: vxlan + protocol: UDP + - containerPort: 4799 + name: slurpeeth + protocol: TCP + resources: + requests: + cpu: 200m + memory: 512Mi + securityContext: + privileged: true + runAsUser: 0 + terminationMessagePath: /dev/termination-log + terminationMessagePolicy: File + volumeMounts: + - mountPath: /clabernetes/topo.clab.yaml + name: topology-basic-config + readOnly: true + subPath: srl1 + - mountPath: /clabernetes/files-from-url.yaml + name: topology-basic-config + readOnly: true + subPath: srl1-files-from-url + - mountPath: /clabernetes/configured-pull-secrets.yaml + name: topology-basic-config + readOnly: true + subPath: configured-pull-secrets + - mountPath: /clabernetes/.node/containerd.sock + name: cri-sock + readOnly: true + subPath: containerd.sock + workingDir: /clabernetes + dnsPolicy: ClusterFirst + hostname: srl1 + restartPolicy: Always + schedulerName: default-scheduler + securityContext: {} + serviceAccount: clabernetes-launcher-service-account + serviceAccountName: clabernetes-launcher-service-account + terminationGracePeriodSeconds: 30 + volumes: + - configMap: + defaultMode: 493 + name: topology-basic + name: topology-basic-config + - hostPath: + path: /run/containerd + type: "" + name: cri-sock +status: {} diff --git a/e2e/topology/basic/test-fixtures/golden/10-service.topology-basic-srl1-vx.yaml b/e2e/topology/basic/test-fixtures/golden/10-service.topology-basic-srl1-vx.yaml new file mode 100755 index 00000000..259df1c1 --- /dev/null +++ b/e2e/topology/basic/test-fixtures/golden/10-service.topology-basic-srl1-vx.yaml @@ -0,0 +1,39 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + clabernetes/app: clabernetes + clabernetes/name: topology-basic-srl1 + clabernetes/topologyKind: containerlab + clabernetes/topologyNode: srl1 + clabernetes/topologyOwner: topology-basic + clabernetes/topologyServiceType: fabric + name: topology-basic-srl1-vx + namespace: NAMESPACE + ownerReferences: + - apiVersion: clabernetes.containerlab.dev/v1alpha1 + kind: Topology + name: topology-basic +spec: + internalTrafficPolicy: Cluster + ipFamilies: + - IPv4 + ipFamilyPolicy: SingleStack + ports: + - name: vxlan + port: 14789 + protocol: UDP + targetPort: 14789 + - name: slurpeeth + port: 4799 + protocol: TCP + targetPort: 4799 + selector: + clabernetes/app: clabernetes + clabernetes/name: topology-basic-srl1 + clabernetes/topologyNode: srl1 + clabernetes/topologyOwner: topology-basic + sessionAffinity: None + type: ClusterIP +status: + loadBalancer: {} diff --git a/e2e/topology/basic/test-fixtures/golden/20-connectivity.topology-basic.yaml b/e2e/topology/basic/test-fixtures/golden/20-connectivity.topology-basic.yaml new file mode 100755 index 00000000..3d78bf91 --- /dev/null +++ b/e2e/topology/basic/test-fixtures/golden/20-connectivity.topology-basic.yaml @@ -0,0 +1,27 @@ +apiVersion: clabernetes.containerlab.dev/v1alpha1 +kind: Connectivity +metadata: + labels: + clabernetes/app: clabernetes + clabernetes/name: topology-basic + clabernetes/topologyKind: containerlab + clabernetes/topologyOwner: topology-basic + name: topology-basic + namespace: NAMESPACE +spec: + pointToPointTunnels: + srl1: + - destination: topology-basic-srl2-vx.NAMESPACE.svc.cluster.local + localInterface: e1-1 + localNode: srl1 + remoteInterface: e1-1 + remoteNode: srl2 + tunnelID: 1 + srl2: + - destination: topology-basic-srl1-vx.NAMESPACE.svc.cluster.local + localInterface: e1-1 + localNode: srl2 + remoteInterface: e1-1 + remoteNode: srl1 + tunnelID: 1 +status: {} diff --git a/e2e/topology/basic/test-fixtures/golden/20-deployment.topology-basic-srl1.yaml b/e2e/topology/basic/test-fixtures/golden/20-deployment.topology-basic-srl1.yaml new file mode 100755 index 00000000..b60a3f85 --- /dev/null +++ b/e2e/topology/basic/test-fixtures/golden/20-deployment.topology-basic-srl1.yaml @@ -0,0 +1,137 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + annotations: {} + labels: + app.kubernetes.io/name: topology-basic-srl1 + clabernetes/app: clabernetes + clabernetes/name: topology-basic-srl1 + clabernetes/topologyNode: srl1 + clabernetes/topologyOwner: topology-basic + name: topology-basic-srl1 + namespace: NAMESPACE + ownerReferences: + - apiVersion: clabernetes.containerlab.dev/v1alpha1 + kind: Topology + name: topology-basic +spec: + progressDeadlineSeconds: 600 + replicas: 1 + revisionHistoryLimit: 0 + selector: + matchLabels: + app.kubernetes.io/name: topology-basic-srl1 + clabernetes/app: clabernetes + clabernetes/name: topology-basic-srl1 + clabernetes/topologyNode: srl1 + clabernetes/topologyOwner: topology-basic + strategy: + type: Recreate + template: + metadata: + annotations: {} + creationTimestamp: null + labels: + app.kubernetes.io/name: topology-basic-srl1 + clabernetes/app: clabernetes + clabernetes/name: topology-basic-srl1 + clabernetes/topologyNode: srl1 + clabernetes/topologyOwner: topology-basic + spec: + containers: + - command: + - /clabernetes/manager + - launch + env: + - name: NODE_NAME + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: spec.nodeName + - name: POD_NAME + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: metadata.name + - name: POD_NAMESPACE + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: metadata.namespace + - name: APP_NAME + value: clabernetes + - name: MANAGER_NAMESPACE + value: clabernetes + - name: LAUNCHER_CRI_KIND + value: containerd + - name: LAUNCHER_IMAGE_PULL_THROUGH_MODE + value: auto + - name: LAUNCHER_LOGGER_LEVEL + value: debug + - name: LAUNCHER_TOPOLOGY_NAME + value: topology-basic + - name: LAUNCHER_NODE_NAME + value: srl1 + - name: LAUNCHER_NODE_IMAGE + value: ghcr.io/nokia/srlinux + - name: LAUNCHER_CONNECTIVITY_KIND + value: vxlan + - name: LAUNCHER_CONTAINERLAB_VERSION + - name: LAUNCHER_CONTAINERLAB_TIMEOUT + - name: LAUNCHER_PRIVILEGED + value: "true" + image: 172.31.254.11/clabernetes-launcher:dev-latest + imagePullPolicy: IfNotPresent + name: srl1 + ports: + - containerPort: 14789 + name: vxlan + protocol: UDP + - containerPort: 4799 + name: slurpeeth + protocol: TCP + resources: + requests: + cpu: 200m + memory: 512Mi + securityContext: + privileged: true + runAsUser: 0 + terminationMessagePath: /dev/termination-log + terminationMessagePolicy: File + volumeMounts: + - mountPath: /clabernetes/topo.clab.yaml + name: topology-basic-config + readOnly: true + subPath: srl1 + - mountPath: /clabernetes/files-from-url.yaml + name: topology-basic-config + readOnly: true + subPath: srl1-files-from-url + - mountPath: /clabernetes/configured-pull-secrets.yaml + name: topology-basic-config + readOnly: true + subPath: configured-pull-secrets + - mountPath: /clabernetes/.node/containerd.sock + name: cri-sock + readOnly: true + subPath: containerd.sock + workingDir: /clabernetes + dnsPolicy: ClusterFirst + hostname: srl1 + restartPolicy: Always + schedulerName: default-scheduler + securityContext: {} + serviceAccount: clabernetes-launcher-service-account + serviceAccountName: clabernetes-launcher-service-account + terminationGracePeriodSeconds: 30 + volumes: + - configMap: + defaultMode: 493 + name: topology-basic + name: topology-basic-config + - hostPath: + path: /run/containerd + type: "" + name: cri-sock +status: {} diff --git a/e2e/topology/basic/test-fixtures/golden/20-deployment.topology-basic-srl2.yaml b/e2e/topology/basic/test-fixtures/golden/20-deployment.topology-basic-srl2.yaml new file mode 100755 index 00000000..e0aa44a0 --- /dev/null +++ b/e2e/topology/basic/test-fixtures/golden/20-deployment.topology-basic-srl2.yaml @@ -0,0 +1,136 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + annotations: {} + labels: + app.kubernetes.io/name: topology-basic-srl2 + clabernetes/app: clabernetes + clabernetes/name: topology-basic-srl2 + clabernetes/topologyNode: srl2 + clabernetes/topologyOwner: topology-basic + name: topology-basic-srl2 + namespace: NAMESPACE + ownerReferences: + - apiVersion: clabernetes.containerlab.dev/v1alpha1 + kind: Topology + name: topology-basic +spec: + progressDeadlineSeconds: 600 + replicas: 1 + revisionHistoryLimit: 0 + selector: + matchLabels: + app.kubernetes.io/name: topology-basic-srl2 + clabernetes/app: clabernetes + clabernetes/name: topology-basic-srl2 + clabernetes/topologyNode: srl2 + clabernetes/topologyOwner: topology-basic + strategy: + type: Recreate + template: + metadata: + creationTimestamp: null + labels: + app.kubernetes.io/name: topology-basic-srl2 + clabernetes/app: clabernetes + clabernetes/name: topology-basic-srl2 + clabernetes/topologyNode: srl2 + clabernetes/topologyOwner: topology-basic + spec: + containers: + - command: + - /clabernetes/manager + - launch + env: + - name: NODE_NAME + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: spec.nodeName + - name: POD_NAME + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: metadata.name + - name: POD_NAMESPACE + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: metadata.namespace + - name: APP_NAME + value: clabernetes + - name: MANAGER_NAMESPACE + value: clabernetes + - name: LAUNCHER_CRI_KIND + value: containerd + - name: LAUNCHER_IMAGE_PULL_THROUGH_MODE + value: auto + - name: LAUNCHER_LOGGER_LEVEL + value: debug + - name: LAUNCHER_TOPOLOGY_NAME + value: topology-basic + - name: LAUNCHER_NODE_NAME + value: srl2 + - name: LAUNCHER_NODE_IMAGE + value: ghcr.io/nokia/srlinux + - name: LAUNCHER_CONNECTIVITY_KIND + value: vxlan + - name: LAUNCHER_CONTAINERLAB_VERSION + - name: LAUNCHER_CONTAINERLAB_TIMEOUT + - name: LAUNCHER_PRIVILEGED + value: "true" + image: 172.31.254.11/clabernetes-launcher:dev-latest + imagePullPolicy: IfNotPresent + name: srl2 + ports: + - containerPort: 14789 + name: vxlan + protocol: UDP + - containerPort: 4799 + name: slurpeeth + protocol: TCP + resources: + requests: + cpu: 200m + memory: 512Mi + securityContext: + privileged: true + runAsUser: 0 + terminationMessagePath: /dev/termination-log + terminationMessagePolicy: File + volumeMounts: + - mountPath: /clabernetes/topo.clab.yaml + name: topology-basic-config + readOnly: true + subPath: srl2 + - mountPath: /clabernetes/files-from-url.yaml + name: topology-basic-config + readOnly: true + subPath: srl2-files-from-url + - mountPath: /clabernetes/configured-pull-secrets.yaml + name: topology-basic-config + readOnly: true + subPath: configured-pull-secrets + - mountPath: /clabernetes/.node/containerd.sock + name: cri-sock + readOnly: true + subPath: containerd.sock + workingDir: /clabernetes + dnsPolicy: ClusterFirst + hostname: srl2 + restartPolicy: Always + schedulerName: default-scheduler + securityContext: {} + serviceAccount: clabernetes-launcher-service-account + serviceAccountName: clabernetes-launcher-service-account + terminationGracePeriodSeconds: 30 + volumes: + - configMap: + defaultMode: 493 + name: topology-basic + name: topology-basic-config + - hostPath: + path: /run/containerd + type: "" + name: cri-sock +status: {} diff --git a/e2e/topology/basic/test-fixtures/golden/20-service.topology-basic-srl1-vx.yaml b/e2e/topology/basic/test-fixtures/golden/20-service.topology-basic-srl1-vx.yaml new file mode 100755 index 00000000..259df1c1 --- /dev/null +++ b/e2e/topology/basic/test-fixtures/golden/20-service.topology-basic-srl1-vx.yaml @@ -0,0 +1,39 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + clabernetes/app: clabernetes + clabernetes/name: topology-basic-srl1 + clabernetes/topologyKind: containerlab + clabernetes/topologyNode: srl1 + clabernetes/topologyOwner: topology-basic + clabernetes/topologyServiceType: fabric + name: topology-basic-srl1-vx + namespace: NAMESPACE + ownerReferences: + - apiVersion: clabernetes.containerlab.dev/v1alpha1 + kind: Topology + name: topology-basic +spec: + internalTrafficPolicy: Cluster + ipFamilies: + - IPv4 + ipFamilyPolicy: SingleStack + ports: + - name: vxlan + port: 14789 + protocol: UDP + targetPort: 14789 + - name: slurpeeth + port: 4799 + protocol: TCP + targetPort: 4799 + selector: + clabernetes/app: clabernetes + clabernetes/name: topology-basic-srl1 + clabernetes/topologyNode: srl1 + clabernetes/topologyOwner: topology-basic + sessionAffinity: None + type: ClusterIP +status: + loadBalancer: {} diff --git a/e2e/topology/basic/test-fixtures/golden/20-service.topology-basic-srl1.yaml b/e2e/topology/basic/test-fixtures/golden/20-service.topology-basic-srl1.yaml new file mode 100755 index 00000000..433c15fd --- /dev/null +++ b/e2e/topology/basic/test-fixtures/golden/20-service.topology-basic-srl1.yaml @@ -0,0 +1,89 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + clabernetes/app: clabernetes + clabernetes/name: topology-basic-srl1 + clabernetes/topologyKind: containerlab + clabernetes/topologyNode: srl1 + clabernetes/topologyOwner: topology-basic + clabernetes/topologyServiceType: expose + name: topology-basic-srl1 + namespace: NAMESPACE + ownerReferences: + - apiVersion: clabernetes.containerlab.dev/v1alpha1 + kind: Topology + name: topology-basic +spec: + allocateLoadBalancerNodePorts: true + externalTrafficPolicy: Cluster + internalTrafficPolicy: Cluster + ipFamilies: + - IPv4 + ipFamilyPolicy: SingleStack + ports: + - name: port-161-udp + port: 161 + protocol: UDP + targetPort: 60000 + - name: port-21-tcp + port: 21 + protocol: TCP + targetPort: 60000 + - name: port-22-tcp + port: 22 + protocol: TCP + targetPort: 60001 + - name: port-23-tcp + port: 23 + protocol: TCP + targetPort: 60002 + - name: port-80-tcp + port: 80 + protocol: TCP + targetPort: 60003 + - name: port-443-tcp + port: 443 + protocol: TCP + targetPort: 60004 + - name: port-830-tcp + port: 830 + protocol: TCP + targetPort: 60005 + - name: port-5000-tcp + port: 5000 + protocol: TCP + targetPort: 60006 + - name: port-5900-tcp + port: 5900 + protocol: TCP + targetPort: 60007 + - name: port-6030-tcp + port: 6030 + protocol: TCP + targetPort: 60008 + - name: port-9339-tcp + port: 9339 + protocol: TCP + targetPort: 60009 + - name: port-9340-tcp + port: 9340 + protocol: TCP + targetPort: 60010 + - name: port-9559-tcp + port: 9559 + protocol: TCP + targetPort: 60011 + - name: port-57400-tcp + port: 57400 + protocol: TCP + targetPort: 60012 + selector: + clabernetes/app: clabernetes + clabernetes/name: topology-basic-srl1 + clabernetes/topologyNode: srl1 + clabernetes/topologyOwner: topology-basic + sessionAffinity: None + type: LoadBalancer +status: + loadBalancer: {} diff --git a/e2e/topology/basic/test-fixtures/golden/20-topology.topology-basic.yaml b/e2e/topology/basic/test-fixtures/golden/20-topology.topology-basic.yaml new file mode 100755 index 00000000..159c87a4 --- /dev/null +++ b/e2e/topology/basic/test-fixtures/golden/20-topology.topology-basic.yaml @@ -0,0 +1,135 @@ +apiVersion: clabernetes.containerlab.dev/v1alpha1 +kind: Topology +metadata: + annotations: {} + name: topology-basic + namespace: NAMESPACE +spec: + connectivity: vxlan + definition: + containerlab: |- + name: topology-basic + + topology: + nodes: + srl1: + kind: srl + image: ghcr.io/nokia/srlinux + srl2: + kind: srl + image: ghcr.io/nokia/srlinux + links: + - endpoints: ["srl1:e1-1", "srl2:e1-1"] + deployment: + containerlabTimeout: "" + persistence: + enabled: false + scheduling: {} + expose: + disableAutoExpose: false + disableExpose: false + imagePull: {} + naming: global +status: + configs: + srl1: | + name: clabernetes-srl1 + prefix: "" + topology: + defaults: + ports: + - 60000:21/tcp + - 60001:22/tcp + - 60002:23/tcp + - 60003:80/tcp + - 60000:161/udp + - 60004:443/tcp + - 60005:830/tcp + - 60006:5000/tcp + - 60007:5900/tcp + - 60008:6030/tcp + - 60009:9339/tcp + - 60010:9340/tcp + - 60011:9559/tcp + - 60012:57400/tcp + nodes: + srl1: + kind: srl + image: ghcr.io/nokia/srlinux + ports: [] + links: + - endpoints: + - srl1:e1-1 + - host:srl1-e1-1 + debug: false + srl2: | + name: clabernetes-srl2 + prefix: "" + topology: + defaults: + ports: + - 60000:21/tcp + - 60001:22/tcp + - 60002:23/tcp + - 60003:80/tcp + - 60000:161/udp + - 60004:443/tcp + - 60005:830/tcp + - 60006:5000/tcp + - 60007:5900/tcp + - 60008:6030/tcp + - 60009:9339/tcp + - 60010:9340/tcp + - 60011:9559/tcp + - 60012:57400/tcp + nodes: + srl2: + kind: srl + image: ghcr.io/nokia/srlinux + ports: [] + links: + - endpoints: + - srl2:e1-1 + - host:srl2-e1-1 + debug: false + exposedPorts: + srl1: + tcpPorts: + - 21 + - 22 + - 23 + - 80 + - 443 + - 830 + - 5000 + - 5900 + - 6030 + - 9339 + - 9340 + - 9559 + - 57400 + udpPorts: + - 161 + srl2: + tcpPorts: + - 21 + - 22 + - 23 + - 80 + - 443 + - 830 + - 5000 + - 5900 + - 6030 + - 9339 + - 9340 + - 9559 + - 57400 + udpPorts: + - 161 + kind: containerlab + reconcileHashes: + config: 25ea403243c3741d3013049756aa02db0ad8dc3d0d9bf803dc1576f9dda33649 + filesFromURL: {} + imagePullSecrets: 37517e5f3dc66819f61f5a7bb8ace1921282415f10551d2defa5c3eb0985b570 + removeTopologyPrefix: false diff --git a/e2e/topology/basic/topology_basic_test.go b/e2e/topology/basic/topology_basic_test.go index 91b6bb0b..29af3a28 100644 --- a/e2e/topology/basic/topology_basic_test.go +++ b/e2e/topology/basic/topology_basic_test.go @@ -46,6 +46,71 @@ func TestContainerlabBasic(t *testing.T) { clabernetestesthelper.NormalizeExposeService, }, }, + { + Name: fmt.Sprintf("%s-srl1-vx", testName), + NormalizeFuncs: []func(t *testing.T, objectData []byte) []byte{ + clabernetestesthelper.NormalizeFabricService, + }, + }, + }, + "deployment": { + { + Name: fmt.Sprintf("%s-srl1", testName), + NormalizeFuncs: []func(t *testing.T, objectData []byte) []byte{}, + }, + }, + "connectivity": { + { + Name: testName, + NormalizeFuncs: []func(t *testing.T, objectData []byte) []byte{}, + }, + }, + }, + }, + { + // this step we add a second node to topo and actually configure some links this time. + Index: 20, + Description: "Add a node and connect them", + AssertObjects: map[string][]clabernetestesthelpersuite.AssertObject{ + "topology": { + { + Name: testName, + NormalizeFuncs: []func(t *testing.T, objectData []byte) []byte{ + clabernetestesthelper.NormalizeTopology, + }, + }, + }, + "service": { + { + Name: fmt.Sprintf("%s-srl1", testName), + NormalizeFuncs: []func(t *testing.T, objectData []byte) []byte{ + clabernetestesthelper.NormalizeExposeService, + }, + }, + { + Name: fmt.Sprintf("%s-srl1-vx", testName), + NormalizeFuncs: []func(t *testing.T, objectData []byte) []byte{ + clabernetestesthelper.NormalizeFabricService, + }, + }, + }, + "deployment": { + { + Name: fmt.Sprintf("%s-srl1", testName), + NormalizeFuncs: []func(t *testing.T, objectData []byte) []byte{}, + }, + { + Name: fmt.Sprintf("%s-srl2", testName), + NormalizeFuncs: []func(t *testing.T, objectData []byte) []byte{}, + }, + }, + "connectivity": { + { + Name: testName, + NormalizeFuncs: []func(t *testing.T, objectData []byte) []byte{ + clabernetestesthelper.NormalizeConnectivity, + }, + }, }, }, }, diff --git a/testhelper/kubernetes.go b/testhelper/kubernetes.go index fc4cf6cc..db1d7f26 100644 --- a/testhelper/kubernetes.go +++ b/testhelper/kubernetes.go @@ -1,6 +1,7 @@ package testhelper import ( + "regexp" "testing" clabernetesutil "github.com/srl-labs/clabernetes/util" @@ -53,6 +54,18 @@ func NormalizeKubernetesObject(t *testing.T, object []byte) []byte { // can also see a uid on owner refs, we should only ever have one owner ref... object = YQCommand(t, object, "del(.metadata.ownerReferences[0].uid)") + // revision and restartedAt annotations obviously will change in tests + object = YQCommand( + t, + object, + "del(.metadata.annotations.\"deployment.kubernetes.io/revision\")", + ) + object = YQCommand( + t, + object, + "del(.spec.template.metadata.annotations.\"kubectl.kubernetes.io/restartedAt\")", + ) + return object } @@ -98,3 +111,29 @@ func NormalizeExposeService(t *testing.T, objectData []byte) []byte { return objectData } + +// NormalizeFabricService normalizes a (fabric) service cr by removing fields that may change +// between ci and local or other folks machines/clusters -- so we can compare results more easily. +func NormalizeFabricService(t *testing.T, objectData []byte) []byte { + t.Helper() + + // cluster ips obviously are going to be different all the time so we'll ignore them + objectData = YQCommand(t, objectData, "del(.spec.clusterIP)") + objectData = YQCommand(t, objectData, "del(.spec.clusterIPs)") + + // remove node ports since they'll be random + objectData = YQCommand(t, objectData, "del(.spec.ports[].nodePort)") + + return objectData +} + +// NormalizeConnectivity normalizes a connectivity cr between ci and local or other folks +// machines/clusters -- so we can compare results more easily. For now this is just replacing the +// namespace in the destinations since those will be random(ish) per test run. +func NormalizeConnectivity(t *testing.T, objectData []byte) []byte { + t.Helper() + + // replace the namespace in the connectivity destinations + return regexp.MustCompile(`\..*\.svc.cluster.local`). + ReplaceAll(objectData, []byte(".NAMESPACE.svc.cluster.local")) +} diff --git a/testhelper/suite/run.go b/testhelper/suite/run.go index 76dab64b..58621687 100644 --- a/testhelper/suite/run.go +++ b/testhelper/suite/run.go @@ -48,23 +48,21 @@ func Run(t *testing.T, steps []Step, namespace string) { //nolint: thelper fileName := fmt.Sprintf("golden/%d-%s.%s.yaml", step.Index, kind, object.Name) if *clabernetestesthelper.Update { + // updating so no reason to fetch/compare object objectData := getter(t, namespace, kind, object.Name, object) clabernetestesthelper.WriteTestFixtureFile(t, fileName, objectData) - - // we just wrote the golden file of course it will match, no need to check - break + } else { + eventually( + t, + eventuallyPollInterval, + eventuallyMaxTime, + func() []byte { + return getter(t, namespace, kind, object.Name, object) + }, + clabernetestesthelper.ReadTestFixtureFile(t, fileName), + ) } - - eventually( - t, - eventuallyPollInterval, - eventuallyMaxTime, - func() []byte { - return getter(t, namespace, kind, object.Name, object) - }, - clabernetestesthelper.ReadTestFixtureFile(t, fileName), - ) } } From a66847beda90169324d749c9db797f78690d46b8 Mon Sep 17 00:00:00 2001 From: Carl Montanari Date: Sat, 23 Mar 2024 09:37:59 -0700 Subject: [PATCH 2/6] test: dont compare image in e2e tests since registry will be different --- .../20-deployment.topology-basic-srl1.yaml | 1 - .../20-deployment.topology-basic-srl2.yaml | 1 - e2e/topology/basic/topology_basic_test.go | 18 ++++++++++++------ testhelper/kubernetes.go | 12 ++++++++++++ 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/e2e/topology/basic/test-fixtures/golden/20-deployment.topology-basic-srl1.yaml b/e2e/topology/basic/test-fixtures/golden/20-deployment.topology-basic-srl1.yaml index b60a3f85..4dc750a9 100755 --- a/e2e/topology/basic/test-fixtures/golden/20-deployment.topology-basic-srl1.yaml +++ b/e2e/topology/basic/test-fixtures/golden/20-deployment.topology-basic-srl1.yaml @@ -80,7 +80,6 @@ spec: - name: LAUNCHER_CONTAINERLAB_TIMEOUT - name: LAUNCHER_PRIVILEGED value: "true" - image: 172.31.254.11/clabernetes-launcher:dev-latest imagePullPolicy: IfNotPresent name: srl1 ports: diff --git a/e2e/topology/basic/test-fixtures/golden/20-deployment.topology-basic-srl2.yaml b/e2e/topology/basic/test-fixtures/golden/20-deployment.topology-basic-srl2.yaml index e0aa44a0..423ab743 100755 --- a/e2e/topology/basic/test-fixtures/golden/20-deployment.topology-basic-srl2.yaml +++ b/e2e/topology/basic/test-fixtures/golden/20-deployment.topology-basic-srl2.yaml @@ -79,7 +79,6 @@ spec: - name: LAUNCHER_CONTAINERLAB_TIMEOUT - name: LAUNCHER_PRIVILEGED value: "true" - image: 172.31.254.11/clabernetes-launcher:dev-latest imagePullPolicy: IfNotPresent name: srl2 ports: diff --git a/e2e/topology/basic/topology_basic_test.go b/e2e/topology/basic/topology_basic_test.go index 29af3a28..c4552017 100644 --- a/e2e/topology/basic/topology_basic_test.go +++ b/e2e/topology/basic/topology_basic_test.go @@ -55,8 +55,10 @@ func TestContainerlabBasic(t *testing.T) { }, "deployment": { { - Name: fmt.Sprintf("%s-srl1", testName), - NormalizeFuncs: []func(t *testing.T, objectData []byte) []byte{}, + Name: fmt.Sprintf("%s-srl1", testName), + NormalizeFuncs: []func(t *testing.T, objectData []byte) []byte{ + clabernetestesthelper.NormalizeDeployment, + }, }, }, "connectivity": { @@ -96,12 +98,16 @@ func TestContainerlabBasic(t *testing.T) { }, "deployment": { { - Name: fmt.Sprintf("%s-srl1", testName), - NormalizeFuncs: []func(t *testing.T, objectData []byte) []byte{}, + Name: fmt.Sprintf("%s-srl1", testName), + NormalizeFuncs: []func(t *testing.T, objectData []byte) []byte{ + clabernetestesthelper.NormalizeDeployment, + }, }, { - Name: fmt.Sprintf("%s-srl2", testName), - NormalizeFuncs: []func(t *testing.T, objectData []byte) []byte{}, + Name: fmt.Sprintf("%s-srl2", testName), + NormalizeFuncs: []func(t *testing.T, objectData []byte) []byte{ + clabernetestesthelper.NormalizeDeployment, + }, }, }, "connectivity": { diff --git a/testhelper/kubernetes.go b/testhelper/kubernetes.go index db1d7f26..e61c9844 100644 --- a/testhelper/kubernetes.go +++ b/testhelper/kubernetes.go @@ -127,6 +127,18 @@ func NormalizeFabricService(t *testing.T, objectData []byte) []byte { return objectData } +// NormalizeDeployment normalizes a deployment by removing fields that may change between ci and +// local or other folks machines/clusters (like image/registry)-- so we can compare results more +// easily. +func NormalizeDeployment(t *testing.T, objectData []byte) []byte { + t.Helper() + + // we dont care about testing that the image was set "right" really, so just remove it + objectData = YQCommand(t, objectData, "del(.spec.template.spec.containers[0].image)") + + return objectData +} + // NormalizeConnectivity normalizes a connectivity cr between ci and local or other folks // machines/clusters -- so we can compare results more easily. For now this is just replacing the // namespace in the destinations since those will be random(ish) per test run. From cfbad6ca2af567e378567183bc9e75580b700675 Mon Sep 17 00:00:00 2001 From: Carl Montanari Date: Wed, 27 Mar 2024 12:32:55 -0700 Subject: [PATCH 3/6] chore: trigger ci From 3c482df2ce07636541631725cacbabb203385447 Mon Sep 17 00:00:00 2001 From: Carl Montanari Date: Wed, 27 Mar 2024 13:23:49 -0700 Subject: [PATCH 4/6] test: add some e2e test logging, try to bump kind version to see if that makes the e2e happier --- .github/workflows/test.yaml | 2 ++ e2e/clabverter/clabverter_basic_test.go | 2 +- e2e/topology/basic/topology_basic_test.go | 2 +- testhelper/suite/run.go | 8 +++++++- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 092615d3..b0718ccb 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -95,6 +95,8 @@ jobs: - name: spin up kind cluster uses: helm/kind-action@v1.9.0 + with: + version: v0.22.0 - name: verify kind cluster run: | diff --git a/e2e/clabverter/clabverter_basic_test.go b/e2e/clabverter/clabverter_basic_test.go index 183bf096..3c3d9865 100644 --- a/e2e/clabverter/clabverter_basic_test.go +++ b/e2e/clabverter/clabverter_basic_test.go @@ -86,5 +86,5 @@ func TestClabverterBasic(t *testing.T) { }, } - clabernetestesthelpersuite.Run(t, steps, namespace) + clabernetestesthelpersuite.Run(t, testName, steps, namespace) } diff --git a/e2e/topology/basic/topology_basic_test.go b/e2e/topology/basic/topology_basic_test.go index c4552017..b8e1f487 100644 --- a/e2e/topology/basic/topology_basic_test.go +++ b/e2e/topology/basic/topology_basic_test.go @@ -122,5 +122,5 @@ func TestContainerlabBasic(t *testing.T) { }, } - clabernetestesthelpersuite.Run(t, steps, namespace) + clabernetestesthelpersuite.Run(t, testName, steps, namespace) } diff --git a/testhelper/suite/run.go b/testhelper/suite/run.go index 58621687..2c0b38a1 100644 --- a/testhelper/suite/run.go +++ b/testhelper/suite/run.go @@ -15,11 +15,13 @@ const ( ) // Run executes a clabernetes e2e test. -func Run(t *testing.T, steps []Step, namespace string) { //nolint: thelper +func Run(t *testing.T, testName string, steps []Step, namespace string) { //nolint: thelper clabernetestesthelper.KubectlCreateNamespace(t, namespace) defer func() { if !*clabernetestesthelper.SkipCleanup { + t.Logf("deleting namespace %q used in test %q", namespace, testName) + clabernetestesthelper.KubectlDeleteNamespace(t, namespace) } }() @@ -42,9 +44,13 @@ func Run(t *testing.T, steps []Step, namespace string) { //nolint: thelper } for kind, objects := range step.AssertObjects { + t.Logf("begin assertion of %q resources", kind) + for idx := range objects { object := step.AssertObjects[kind][idx] + t.Logf("begin assertion of %q resources %q", kind, object.Name) + fileName := fmt.Sprintf("golden/%d-%s.%s.yaml", step.Index, kind, object.Name) if *clabernetestesthelper.Update { From 5f5c851b84bff3504073e23de8c701d9a6f405a7 Mon Sep 17 00:00:00 2001 From: Carl Montanari Date: Wed, 27 Mar 2024 13:43:17 -0700 Subject: [PATCH 5/6] chore: prune docker system in e2e tests to clean up stuff we dont need --- .github/workflows/test.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index b0718ccb..633450d6 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -107,6 +107,12 @@ jobs: - name: deploy clabernetes run: devspace run deploy --profile debug + # actions seem to be running out of disk for e2e -- probably due to all the image build stuff + # floating around, all the junk runners get pre-built with, and runners not being super beefy + # lets just system prune all the docker stuff to get rid of some junk we dont need + - name: docker system prune + run: docker system prune -a -f + - name: setup tmate session uses: mxschmitt/action-tmate@v3 if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_e2e }} From 1fb588e84b69f76a877fa245e2756ffe193d53db Mon Sep 17 00:00:00 2001 From: Carl Montanari Date: Wed, 27 Mar 2024 15:36:55 -0700 Subject: [PATCH 6/6] test: fixup e2e golden, indent some more test logs to be easer on the eyes --- .../golden/10-deployment.topology-basic-srl1.yaml | 1 - testhelper/suite/run.go | 4 +--- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/e2e/topology/basic/test-fixtures/golden/10-deployment.topology-basic-srl1.yaml b/e2e/topology/basic/test-fixtures/golden/10-deployment.topology-basic-srl1.yaml index e78fedbb..3a59355a 100755 --- a/e2e/topology/basic/test-fixtures/golden/10-deployment.topology-basic-srl1.yaml +++ b/e2e/topology/basic/test-fixtures/golden/10-deployment.topology-basic-srl1.yaml @@ -79,7 +79,6 @@ spec: - name: LAUNCHER_CONTAINERLAB_TIMEOUT - name: LAUNCHER_PRIVILEGED value: "true" - image: 172.31.254.11/clabernetes-launcher:dev-latest imagePullPolicy: IfNotPresent name: srl1 ports: diff --git a/testhelper/suite/run.go b/testhelper/suite/run.go index 2c0b38a1..b8f86b74 100644 --- a/testhelper/suite/run.go +++ b/testhelper/suite/run.go @@ -44,12 +44,10 @@ func Run(t *testing.T, testName string, steps []Step, namespace string) { //noli } for kind, objects := range step.AssertObjects { - t.Logf("begin assertion of %q resources", kind) - for idx := range objects { object := step.AssertObjects[kind][idx] - t.Logf("begin assertion of %q resources %q", kind, object.Name) + t.Logf("\tbegin assertion of %q resources %q", kind, object.Name) fileName := fmt.Sprintf("golden/%d-%s.%s.yaml", step.Index, kind, object.Name)