From d4322292e7a9d1f2b11b05aa46a152b72eaf5513 Mon Sep 17 00:00:00 2001 From: Jayanth Varavani <1111446+jayanthvn@users.noreply.github.com> Date: Tue, 15 Aug 2023 19:11:07 +0000 Subject: [PATCH] Vendor option --- .gitignore | 4 ++++ Dockerfile | 7 ++----- Makefile | 23 ++++++++++++++++++++--- go.mod | 9 ++++----- go.sum | 12 +++++++----- scripts/ebpf_sdk_override/cleanup.sh | 5 +++++ scripts/ebpf_sdk_override/setup.sh | 15 +++++++++++++++ 7 files changed, 57 insertions(+), 18 deletions(-) create mode 100755 scripts/ebpf_sdk_override/cleanup.sh create mode 100755 scripts/ebpf_sdk_override/setup.sh diff --git a/.gitignore b/.gitignore index 13f4392..25dc411 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,7 @@ coverage.txt *.h *.o +aws-eks-na-cli +aws-eks-na-cli-v6 +controller +vendor/ diff --git a/Dockerfile b/Dockerfile index ae71ca9..6047bb1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,15 +7,12 @@ ARG TARGETARCH ENV GOPROXY=direct WORKDIR /workspace -# Copy the Go Modules manifests -COPY go.mod go.mod -COPY go.sum go.sum + +COPY . ./ # cache deps before building and copying source so that we don't need to re-download as much # and so that source changes don't invalidate our downloaded layer RUN go mod download -COPY . ./ - RUN make build-linux # Build BPF diff --git a/Makefile b/Makefile index 928d7e1..8dcb156 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,13 @@ TEST_IMAGE_NAME = $(TEST_IMAGE)$(IMAGE_ARCH_SUFFIX):$(VERSION) export GOPROXY = direct +# aws-ebpf-sdk-go override in case we need to build against a custom version +EBPF_SDK_OVERRIDE ?= "n" + +ifeq ($(EBPF_SDK_OVERRIDE), "y") +VENDOR_OVERRIDE_FLAG = -mod=mod +endif + UNAME_ARCH = $(shell uname -m) ARCH = $(lastword $(subst :, ,$(filter $(UNAME_ARCH):%,x86_64:amd64 aarch64:arm64))) # This is only applied to the arm64 container image by default. Override to @@ -65,7 +72,7 @@ fmt: ## Run go fmt against code. go fmt ./... .PHONY: vet -vet: ## Run go vet against code. +vet: setup-ebpf-sdk-override # Run go vet against code. go vet ./... .PHONY: test @@ -144,7 +151,7 @@ build-bpf: vmlinuxh ## Build BPF. .PHONY: docker-build #docker-build: test ## Build docker image with the manager. # docker build -t ${IMAGE_NAME} . -docker-build: ## Build docker image with the manager. +docker-build: setup-ebpf-sdk-override## Build docker image with the manager. docker build -t ${IMAGE_NAME} . .PHONY: docker-push @@ -174,7 +181,7 @@ docker-unit-tests: build-docker-test ## Run unit tests inside of the testing # To properly provided solutions that supports more than one platform you should use this option. PLATFORMS ?= linux/arm64,linux/amd64 .PHONY: docker-buildx -docker-buildx: ## Build and push docker image for the manager for cross-platform support +docker-buildx: setup-ebpf-sdk-override ## Build and push docker image for the manager for cross-platform support # copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross - docker buildx create --name project-v3-builder @@ -258,3 +265,13 @@ format: ## Format all Go source code files. -type f \ -name '*.go' \ -print0 | sort -z | xargs -0 -- goimports $(or $(FORMAT_FLAGS),-w) | wc -l | bc) + +setup-ebpf-sdk-override: + @if [ "$(EBPF_SDK_OVERRIDE)" = "y" ] ; then \ + ./scripts/ebpf_sdk_override/setup.sh ; \ + fi + +cleanup-ebpf-sdk-override: + @if [ "$(EBPF_SDK_OVERRIDE)" = "y" ] ; then \ + ./scripts/ebpf_sdk_override/cleanup.sh ; \ + fi diff --git a/go.mod b/go.mod index 03de2a3..f7922f7 100644 --- a/go.mod +++ b/go.mod @@ -4,20 +4,20 @@ go 1.20 require ( github.com/aws/amazon-vpc-cni-k8s v1.13.4 + github.com/aws/aws-ebpf-sdk-go v0.2.0 github.com/aws/aws-sdk-go v1.44.318 github.com/go-logr/logr v1.2.4 github.com/go-logr/zapr v1.2.4 github.com/golang/mock v1.6.0 github.com/google/go-cmp v0.5.9 github.com/google/uuid v1.3.0 - github.com/aws/aws-ebpf-sdk-go v0.2.0 github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.16.0 github.com/spf13/cobra v1.6.1 github.com/spf13/pflag v1.0.5 - github.com/stretchr/testify v1.8.1 + github.com/stretchr/testify v1.8.4 github.com/vishvananda/netlink v1.1.1-0.20210330154013-f5de75959ad5 - go.uber.org/zap v1.24.0 + go.uber.org/zap v1.25.0 golang.org/x/sys v0.8.0 k8s.io/api v0.27.2 k8s.io/apimachinery v0.27.2 @@ -55,8 +55,7 @@ require ( github.com/prometheus/common v0.42.0 // indirect github.com/prometheus/procfs v0.10.1 // indirect github.com/vishvananda/netns v0.0.4 // indirect - go.uber.org/atomic v1.7.0 // indirect - go.uber.org/multierr v1.6.0 // indirect + go.uber.org/multierr v1.10.0 // indirect golang.org/x/net v0.10.0 // indirect golang.org/x/oauth2 v0.5.0 // indirect golang.org/x/term v0.8.0 // indirect diff --git a/go.sum b/go.sum index ec84587..e89bcc3 100644 --- a/go.sum +++ b/go.sum @@ -7,8 +7,8 @@ github.com/aws/amazon-vpc-cni-k8s v1.13.4 h1:LC3AX3TRagZN1PUJRgx1Y1CnAvzala5xAFC github.com/aws/amazon-vpc-cni-k8s v1.13.4/go.mod h1:eVzV7+2QctvKc+yyr3kLNHFwb9xZQRKl0C8ki4ObzDw= github.com/aws/aws-sdk-go v1.44.318 h1:Yl66rpbQHFUbxe9JBKLcvOvRivhVgP6+zH0b9KzARX8= github.com/aws/aws-sdk-go v1.44.318/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI= -github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= +github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= @@ -162,8 +162,9 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5 github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/vishvananda/netlink v1.1.1-0.20210330154013-f5de75959ad5 h1:+UB2BJA852UkGH42H+Oee69djmxS3ANzl2b/JtT1YiA= github.com/vishvananda/netlink v1.1.1-0.20210330154013-f5de75959ad5/go.mod h1:twkDnbuQxJYemMlGd4JFIcuhgX83tXhKS2B/PRMpOho= github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0= @@ -177,14 +178,15 @@ github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9dec github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= -go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A= -go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= -go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60= +go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ= +go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg= +go.uber.org/zap v1.25.0 h1:4Hvk6GtkucQ790dqmj7l1eEnRdKm3k3ZUrUMS2d5+5c= +go.uber.org/zap v1.25.0/go.mod h1:JIAUzQIH94IC4fOJQm7gMmBJP5k7wQfdcnYdPoEXJYk= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= diff --git a/scripts/ebpf_sdk_override/cleanup.sh b/scripts/ebpf_sdk_override/cleanup.sh new file mode 100755 index 0000000..9b57651 --- /dev/null +++ b/scripts/ebpf_sdk_override/cleanup.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +rm -rf ./vendor +go mod edit -dropreplace github.com/aws/aws-ebpf-sdk-go +go mod tidy diff --git a/scripts/ebpf_sdk_override/setup.sh b/scripts/ebpf_sdk_override/setup.sh new file mode 100755 index 0000000..c39e0a4 --- /dev/null +++ b/scripts/ebpf_sdk_override/setup.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +set -e + +mkdir -p ./vendor/github.com/aws + +SDK_VENDOR_PATH=./vendor/github.com/aws/aws-ebpf-sdk-go + +# Clone the SDK to the vendor path (removing an old one if necessary) +rm -rf $SDK_VENDOR_PATH +git clone --depth 1 git@github.com:aws/aws-ebpf-sdk-go.git $SDK_VENDOR_PATH + +# Use the vendored version of aws-sdk-go +go mod edit -replace github.com/aws/aws-ebpf-sdk-go=./vendor/github.com/aws/aws-ebpf-sdk-go +go mod tidy