Skip to content

Commit

Permalink
decouple test helper input struct from netlink library (#1455)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
abhipth authored May 4, 2021
1 parent f96e713 commit 07ac754
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 47 deletions.
21 changes: 14 additions & 7 deletions test/agent/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
Expand All @@ -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))))
$(error Undefined variable $1$(if $2, ($2))))
2 changes: 1 addition & 1 deletion test/agent/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<account> AWS_REGION=<region> make docker-build docker-push
```
Expand Down
3 changes: 2 additions & 1 deletion test/agent/cmd/networking/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 0 additions & 35 deletions test/agent/cmd/networking/tester/input.go

This file was deleted.

8 changes: 5 additions & 3 deletions test/agent/cmd/networking/tester/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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])
Expand Down
21 changes: 21 additions & 0 deletions test/agent/pkg/input/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 07ac754

Please sign in to comment.