From 07ac754880d873de02bc13effe5ac9fd71c52044 Mon Sep 17 00:00:00 2001 From: Abhinav Pathak <31713659+abhipth@users.noreply.github.com> Date: Wed, 5 May 2021 05:23:51 +0530 Subject: [PATCH] decouple test helper input struct from netlink library (#1455) netlink library has dependency on linux specific go libraries, so in order to allow cross OS compilation moving input that will be be used outside the agent (in ginkgo tests to send inputs) to a seperate package. --- test/agent/Makefile | 21 +++++++---- test/agent/README.md | 2 +- test/agent/cmd/networking/main.go | 3 +- test/agent/cmd/networking/tester/input.go | 35 ------------------- test/agent/cmd/networking/tester/network.go | 8 +++-- test/agent/pkg/input/input.go | 21 +++++++++++ ...networking_test.go => pod_traffic_test.go} | 0 7 files changed, 43 insertions(+), 47 deletions(-) delete mode 100644 test/agent/cmd/networking/tester/input.go rename test/integration-new/cni/{pod_networking_test.go => pod_traffic_test.go} (100%) diff --git a/test/agent/Makefile b/test/agent/Makefile index ea03f9bd27..429aeca6d2 100644 --- a/test/agent/Makefile +++ b/test/agent/Makefile @@ -11,10 +11,10 @@ # ANY KIND, either express or implied. See the License for the specific # language governing permissions and limitations under the License. -VERSION ?= $(shell git describe --tags --always || echo "unknown") -IMAGE_NAME = amazon/amazon-k8s-cni/test/agent -REPO=$(AWS_ACCOUNT).dkr.ecr.$(AWS_REGION).amazonaws.com/$(IMAGE_NAME) -IMAGE ?= $(REPO):$(VERSION) +VERSION ?= $(shell git rev-parse --short HEAD || echo "unknown") +IMAGE_NAME =aws-vpc-cni-test-helper +PUBLIC_REPO_IMAGE=public.ecr.aws/$(REGISTRY_ID)/${IMAGE_NAME}:$(VERSION) +PRIVATE_REPO_IMAGE=$(AWS_ACCOUNT).dkr.ecr.$(AWS_REGION).amazonaws.com/$(IMAGE_NAME):$(VERSION) fmt: go fmt . @@ -24,18 +24,25 @@ vet: go vet . docker-build: check-env - docker build . -t ${IMAGE} + docker build . -t ${PRIVATE_REPO_IMAGE} docker-push: check-env - docker push ${IMAGE} + docker push ${PRIVATE_REPO_IMAGE} + +publish-public-image: check-env-public + docker build . -t ${PUBLIC_REPO_IMAGE} + docker push ${PUBLIC_REPO_IMAGE} check-env: @:$(call check_var, AWS_ACCOUNT, AWS account ID for publishing docker images) @:$(call check_var, AWS_REGION, AWS region for publishing docker images) +check-env-public: + @:$(call check_var, REGISTRY_ID, Registery ID for publishing docker images to public ECR Repo) + check_var = \ $(strip $(foreach 1,$1, \ $(call __check_var,$1,$(strip $(value 2))))) __check_var = \ $(if $(value $1),, \ - $(error Undefined variable $1$(if $2, ($2)))) \ No newline at end of file + $(error Undefined variable $1$(if $2, ($2)))) diff --git a/test/agent/README.md b/test/agent/README.md index f0a61dbf70..6c96cb30d4 100644 --- a/test/agent/README.md +++ b/test/agent/README.md @@ -56,7 +56,7 @@ Apart from running the tests on your local environment. For some test cases wher #### Running the docker Image -Run the following command to build the agent image and push to ECR. This needs an existing repository with name "amazon/amazon-k8s-cni/test/agent" +Run the following command to build the agent image and push to ECR. This needs an existing repository with name "aws-vpc-cni-test-helper" ``` AWS_ACCOUNT= AWS_REGION= make docker-build docker-push ``` diff --git a/test/agent/cmd/networking/main.go b/test/agent/cmd/networking/main.go index a62474554f..d95c3ab833 100644 --- a/test/agent/cmd/networking/main.go +++ b/test/agent/cmd/networking/main.go @@ -19,12 +19,13 @@ import ( "log" "github.com/aws/amazon-vpc-cni-k8s/test/agent/cmd/networking/tester" + "github.com/aws/amazon-vpc-cni-k8s/test/agent/pkg/input" ) // TODO: Instead of passing the list of pods, get the pods from API Server so this agent can run as DS // TODO: Export metrics via Prometheus for debugging and analysis purposes func main() { - var podNetworkingValidationInput tester.PodNetworkingValidationInput + var podNetworkingValidationInput input.PodNetworkingValidationInput var podNetworkingValidationInputString string var shouldTestSetup bool var shouldTestCleanup bool diff --git a/test/agent/cmd/networking/tester/input.go b/test/agent/cmd/networking/tester/input.go deleted file mode 100644 index 2e6f8b1455..0000000000 --- a/test/agent/cmd/networking/tester/input.go +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"). You may -// not use this file except in compliance with the License. A copy of the -// License is located at -// -// http://aws.amazon.com/apache2.0/ -// -// or in the "license" file accompanying this file. This file is distributed -// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either -// express or implied. See the License for the specific language governing -// permissions and limitations under the License. - -package tester - -type PodNetworkingValidationInput struct { - // CIDR Range associated with the VPC - VPCCidrRange []string - // Prefix for the veth pair on host network ns - VethPrefix string - // List of pod to validate the networking - PodList []Pod -} - -type Pod struct { - // Name of the pod - PodName string - // Namespace of the pod, used to generate the Link - PodNamespace string - // IPv4 Address of the pod - PodIPv4Address string - // Set to true when the Pod is scheduled on IP - // from the Secondary ENI - IsIPFromSecondaryENI bool -} diff --git a/test/agent/cmd/networking/tester/network.go b/test/agent/cmd/networking/tester/network.go index 3be897483a..de9ccfa929 100644 --- a/test/agent/cmd/networking/tester/network.go +++ b/test/agent/cmd/networking/tester/network.go @@ -23,13 +23,15 @@ import ( "sort" "strings" + "github.com/aws/amazon-vpc-cni-k8s/test/agent/pkg/input" + "github.com/vishvananda/netlink" "golang.org/x/sys/unix" ) // TestNetworkingSetupForRegularPod tests networking set by the CNI Plugin for a list of Pod is as // expected -func TestNetworkingSetupForRegularPod(podNetworkingValidationInput PodNetworkingValidationInput) []error { +func TestNetworkingSetupForRegularPod(podNetworkingValidationInput input.PodNetworkingValidationInput) []error { // Get the list of IP rules ruleList, err := netlink.RuleList(netlink.FAMILY_V4) if err != nil { @@ -180,7 +182,7 @@ func TestNetworkingSetupForRegularPod(podNetworkingValidationInput PodNetworking // TestNetworkTearedDownForRegularPods test pod networking is correctly teared down by the CNI Plugin // The test assumes that the IP assigned to the older Pod is not assigned to a new Pod while this test // is being executed -func TestNetworkTearedDownForRegularPods(podNetworkingValidationInput PodNetworkingValidationInput) []error { +func TestNetworkTearedDownForRegularPods(podNetworkingValidationInput input.PodNetworkingValidationInput) []error { // Get the list of IP rules ruleList, err := netlink.RuleList(netlink.FAMILY_V4) if err != nil { @@ -260,7 +262,7 @@ func isRuleToOrFromIP(rule netlink.Rule, ip net.IP) bool { return false } -func getHostVethPairName(input Pod, vethPrefix string) string { +func getHostVethPairName(input input.Pod, vethPrefix string) string { h := sha1.New() h.Write([]byte(fmt.Sprintf("%s.%s", input.PodNamespace, input.PodName))) return fmt.Sprintf("%s%s", vethPrefix, hex.EncodeToString(h.Sum(nil))[:11]) diff --git a/test/agent/pkg/input/input.go b/test/agent/pkg/input/input.go index 9b1de5f991..1fb187b475 100644 --- a/test/agent/pkg/input/input.go +++ b/test/agent/pkg/input/input.go @@ -24,3 +24,24 @@ type Failure struct { DestinationIP string FailureReason string } + +type PodNetworkingValidationInput struct { + // CIDR Range associated with the VPC + VPCCidrRange []string + // Prefix for the veth pair on host network ns + VethPrefix string + // List of pod to validate the networking + PodList []Pod +} + +type Pod struct { + // Name of the pod + PodName string + // Namespace of the pod, used to generate the Link + PodNamespace string + // IPv4 Address of the pod + PodIPv4Address string + // Set to true when the Pod is scheduled on IP + // from the Secondary ENI + IsIPFromSecondaryENI bool +} diff --git a/test/integration-new/cni/pod_networking_test.go b/test/integration-new/cni/pod_traffic_test.go similarity index 100% rename from test/integration-new/cni/pod_networking_test.go rename to test/integration-new/cni/pod_traffic_test.go