Skip to content

Commit a19a933

Browse files
authored
chore: Makefile improvements to increase developer velocity (#265)
* chore: Makefile improvements to increase developer velocity * Use error wrapping to reduce log spam
1 parent a173e2e commit a19a933

File tree

16 files changed

+169
-161
lines changed

16 files changed

+169
-161
lines changed

.github/workflows/automated-tests.yaml

Lines changed: 0 additions & 61 deletions
This file was deleted.

.github/workflows/presubmit.yaml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Presubmit
2+
on:
3+
push:
4+
branches: [master]
5+
pull_request:
6+
workflow_dispatch:
7+
permissions:
8+
contents: read
9+
jobs:
10+
presubmit:
11+
name: Presubmit
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
- uses: actions/setup-go@v4
16+
with:
17+
go-version-file: go.mod
18+
check-latest: true
19+
cache-dependency-path: "**/go.sum"
20+
- uses: actions/cache@v3
21+
with:
22+
path: |
23+
~/.kubebuilder/bin
24+
~/go/bin
25+
key: ${{ runner.os }}-toolchain-cache-${{ hashFiles('hack/toolchain.sh') }}
26+
- run: make toolchain
27+
- run: make presubmit
28+
deprecated-apigroups:
29+
name: Detect deprecated apiGroups
30+
runs-on: ubuntu-latest
31+
steps:
32+
- uses: actions/checkout@v3
33+
- run: |
34+
version=$(curl -sL https://api.github.com/repos/FairwindsOps/pluto/releases/latest | jq -r ".tag_name")
35+
number=${version:1}
36+
wget https://github.com/FairwindsOps/pluto/releases/download/${version}/pluto_${number}_linux_amd64.tar.gz
37+
sudo tar -C /usr/local -xzf pluto_${number}_linux_amd64.tar.gz
38+
- run: |
39+
/usr/local/pluto detect-files -d .

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ scripts/gen_vpc_limits.go
2020
*.out
2121

2222
# Kubernetes Generated files - skip generated files, except for vendored files
23-
2423
!vendor/**/zz_generated.*
25-
2624
# editor and IDE paraphernalia
2725
.idea
2826
*.swp

.ko.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
defaultBaseImage: public.ecr.aws/eks-distro-build-tooling/eks-distro-minimal-base-nonroot:latest.2

DEVELOPER_GUIDE.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Developer Guide
2+
3+
## Setup
4+
5+
```sh
6+
make toolchain # Install required to develop the project
7+
```
8+
9+
## Testing a code change
10+
11+
Deploy your changes to a local development cluster and run the tests against it.
12+
13+
```sh
14+
make apply # Apply your changes
15+
make e2etest # Run the integration test suite
16+
```
17+
18+
In another terminal, you can tail the logs with stern
19+
```sh
20+
stern -l app=vpc-resource-controller -n kube-system
21+
```
22+
23+
## Submitting a PR
24+
Run the presubmit target and check in all generated code before submitting a PR.
25+
26+
```sh
27+
make presubmit
28+
```
29+
30+
## Troubleshooting
31+
32+
### Invalid value 'trunk' for InterfaceType
33+
34+
The following error means that must be allowlisted for EC2 Networking
35+
```
36+
{"level":"error","timestamp":"2023-06-09T21:53:00.705Z","logger":"branch eni provider","msg":"failed to create trunk interface","node name":"ip-192-168-60-153.us-west-2.compute.internal","request":"initialize","instance ID":"i-0d892c7fa08bf7bbd","error":"InvalidParameterValue: Invalid value 'trunk' for InterfaceType. Allowed values are ('EFA')\n\tstatus code: 400, request id: 7b94401f-686f-46a4-a5e9-3cfda8e12cd6","stacktrace":"github.com/aws/amazon-vpc-resource-controller-k8s/pkg/provider/branch/trunk.(*trunkENI).InitTrunk\n\tgithub.com/aws/amazon-vpc-resource-controller-k8s/pkg/provider/branch/trunk/trunk.go:194\ngithub.com/aws/amazon-vpc-resource-controller-k8s/pkg/provider/branch.(*branchENIProvider).InitResource\n\tgithub.com/aws/amazon-vpc-resource-controller-k8s/pkg/provider/branch/provider.go:154\ngithub.com/aws/amazon-vpc-resource-controller-k8s/pkg/node.(*node).InitResources\n\tgithub.com/aws/amazon-vpc-resource-controller-k8s/pkg/node/node.go:156\ngithub.com/aws/amazon-vpc-resource-controller-k8s/pkg/node/manager.(*manager).performAsyncOperation\n\tgithub.com/aws/amazon-vpc-resource-controller-k8s/pkg/node/manager/manager.go:316\ngithub.com/aws/amazon-vpc-resource-controller-k8s/pkg/worker.(*worker).processNextItem\n\tgithub.com/aws/amazon-vpc-resource-controller-k8s/pkg/worker/worker.go:162\ngithub.com/aws/amazon-vpc-resource-controller-k8s/pkg/worker.(*worker).runWorker\n\tgithub.com/aws/amazon-vpc-resource-controller-k8s/pkg/worker/worker.go:147"}
37+
```

Makefile

Lines changed: 44 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,67 @@
11
# Image URL to use all building/pushing image targets
2-
IMAGE_NAME=eks/vpc-resource-controller
3-
REPO=$(AWS_ACCOUNT).dkr.ecr.$(AWS_REGION).amazonaws.com/$(IMAGE_NAME)
2+
AWS_ACCOUNT ?= ${AWS_ACCOUNT_ID}
3+
AWS_REGION ?= ${AWS_DEFAULT_REGION}
4+
CLUSTER_NAME ?= $(shell kubectl config view --minify -o jsonpath='{.clusters[].name}' | rev | cut -d"/" -f1 | rev | cut -d"." -f1)
5+
REPO=$(AWS_ACCOUNT_ID).dkr.ecr.${AWS_REGION}.amazonaws.com/aws/amazon-vpc-resource-controller-k8s
6+
KO_DOCKER_REPO ?= ${REPO} # Used for development images
7+
48
GIT_VERSION=$(shell git describe --tags --always)
59
MAKEFILE_PATH = $(dir $(realpath -s $(firstword $(MAKEFILE_LIST))))
610

7-
export GOPROXY = direct
8-
911
VERSION ?= $(GIT_VERSION)
1012
IMAGE ?= $(REPO):$(VERSION)
1113
BASE_IMAGE ?= public.ecr.aws/eks-distro-build-tooling/eks-distro-minimal-base-nonroot:latest.2
12-
BUILD_IMAGE ?= public.ecr.aws/bitnami/golang:1.20.1
13-
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
14-
CRD_OPTIONS ?= "crd:trivialVersions=true"
14+
BUILD_IMAGE ?= public.ecr.aws/bitnami/golang:1.20.5
1515
GOARCH ?= amd64
1616
PLATFORM ?= linux/amd64
1717

18+
help: ## Display help
19+
@awk 'BEGIN {FS = ":.*##"; printf "Usage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
1820

19-
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
20-
ifeq (,$(shell go env GOBIN))
21-
GOBIN=$(shell go env GOPATH)/bin
22-
else
23-
GOBIN=$(shell go env GOBIN)
24-
endif
25-
26-
all: controller
21+
## Execute before submitting code
22+
presubmit: verify test
2723

28-
# Run tests
29-
test: generate fmt vet manifests
24+
## Verify dependencies, correctness, and formatting
25+
verify:
26+
go mod tidy
27+
go generate ./...
28+
go vet ./...
29+
go fmt ./...
30+
controller-gen crd:trivialVersions=true rbac:roleName=controller-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
31+
controller-gen object:headerFile="scripts/templates/boilerplate.go.txt" paths="./..."
32+
@git diff --quiet ||\
33+
{ echo "New file modification detected in the Git working tree. Please check in before commit."; git --no-pager diff --name-only | uniq | awk '{print " - " $$0}'; \
34+
if [ "${CI}" = true ]; then\
35+
exit 1;\
36+
fi;}
37+
38+
## Run unit tests
39+
test: verify
3040
go test ./pkg/... ./controllers/... ./webhooks/... -coverprofile cover.out
3141

32-
# Build controller binary
33-
controller: generate fmt vet
34-
go build -o bin/controller main.go
42+
toolchain: ## Install developer toolchain
43+
./hack/toolchain.sh
3544

36-
# Run against the configured Kubernetes cluster in ~/.kube/config
37-
run: generate fmt vet manifests
38-
go run ./main.go
39-
40-
# Install CRDs into a cluster
41-
install: manifests
42-
kustomize build config/crd | kubectl apply -f -
43-
44-
# Uninstall CRDs from a cluster
45-
uninstall: manifests
46-
kustomize build config/crd | kubectl delete -f -
45+
image: ## Build the images using ko build
46+
$(eval IMAGE=$(shell KO_DOCKER_REPO=$(KO_DOCKER_REPO) $(WITH_GOFLAGS) ko build --bare github.com/aws/amazon-vpc-resource-controller-k8s))
4747

4848
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
49-
deploy: check-deployment-env check-env manifests
49+
apply: image check-deployment-env check-env
50+
eksctl create iamserviceaccount vpc-resource-controller --namespace kube-system --cluster ${CLUSTER_NAME} \
51+
--role-name VPCResourceControllerRole \
52+
--attach-policy-arn arn:aws:iam::aws:policy/AmazonEKSVPCResourceController \
53+
--attach-policy-arn arn:aws:iam::aws:policy/AmazonEKSClusterPolicy \
54+
--override-existing-serviceaccounts \
55+
--approve
56+
kustomize build config/crd | kubectl apply -f -
5057
cd config/controller && kustomize edit set image controller=${IMAGE}
5158
kustomize build config/default | sed "s|CLUSTER_NAME|${CLUSTER_NAME}|g;s|USER_ROLE_ARN|${USER_ROLE_ARN}|g" | kubectl apply -f -
59+
kubectl patch rolebinding eks-vpc-resource-controller-rolebinding -n kube-system --patch '{"subjects":[{"kind":"ServiceAccount","name":"vpc-resource-controller","namespace":"kube-system"}]}'
5260

53-
undeploy: check-env
54-
cd config/controller && kustomize edit set image controller=${IMAGE}
55-
kustomize build config/default | kubectl delete -f -
56-
57-
# Generate manifests e.g. CRD, RBAC etc.
58-
manifests: controller-gen
59-
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=controller-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
60-
61-
# Run go fmt against code
62-
fmt:
63-
go fmt ./...
64-
65-
# Run go vet against code
66-
vet:
67-
go vet ./...
68-
69-
# Generate code
70-
generate: controller-gen
71-
$(CONTROLLER_GEN) object:headerFile="scripts/templates/boilerplate.go.txt" paths="./..."
61+
delete:
62+
kustomize build config/default | kubectl delete --ignore-not-found -f -
63+
eksctl delete iamserviceaccount vpc-resource-controller --namespace kube-system --cluster ${CLUSTER_NAME}
64+
kubectl patch rolebinding eks-vpc-resource-controller-rolebinding -n kube-system --patch '{"subjects":[{"kind":"ServiceAccount","name":"eks-vpc-resource-controller","namespace":"kube-system"},{"apiGroup":"rbac.authorization.k8s.io","kind":"User","name":"eks:vpc-resource-controller"}]}'
7265

7366
# Build the docker image with buildx
7467
docker-buildx: check-env test
@@ -82,34 +75,12 @@ docker-build: check-env test
8275
docker-push: check-env
8376
docker push ${IMAGE}
8477

85-
# find or download controller-gen
86-
# download controller-gen if necessary
87-
controller-gen:
88-
ifeq (, $(findstring v0.6.2,$(shell controller-gen --version)))
89-
@{ \
90-
set -e ;\
91-
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
92-
cd $$CONTROLLER_GEN_TMP_DIR ;\
93-
go mod init tmp ;\
94-
go install sigs.k8s.io/controller-tools/cmd/[email protected] ;\
95-
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
96-
}
97-
CONTROLLER_GEN=$(GOBIN)/controller-gen
98-
else
99-
CONTROLLER_GEN=$(shell which controller-gen)
100-
endif
101-
102-
# If more than 1 files need formatting then error out
103-
check-format:
104-
@exit $(shell gofmt -l . | grep -v internal | wc -l)
105-
10678
check-env:
10779
@:$(call check_var, AWS_ACCOUNT, AWS account ID for publishing docker images)
10880
@:$(call check_var, AWS_REGION, AWS region for publishing docker images)
10981

11082
check-deployment-env:
11183
@:$(call check_var, CLUSTER_NAME, Cluster name where the controller is deployed)
112-
@:$(call check_var, USER_ROLE_ARN, User Role ARN which is assumed to manage Trunk/Branch ENI for users)
11384

11485
check_var = \
11586
$(strip $(foreach 1,$1, \

config/controller/controller.yaml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,8 @@ spec:
1717
control-plane: controller
1818
app: vpc-resource-controller
1919
spec:
20-
serviceAccountName: vpc-resource-controller
2120
containers:
22-
- command:
23-
- /controller
24-
args:
21+
- args:
2522
- --cluster-name=CLUSTER_NAME
2623
- --role-arn=USER_ROLE_ARN
2724
- --enable-leader-election
@@ -50,6 +47,7 @@ spec:
5047
- containerPort: 8443
5148
name: metrics
5249
protocol: TCP
50+
serviceAccountName: vpc-resource-controller
5351
terminationGracePeriodSeconds: 10
5452
nodeSelector:
55-
kubernetes.io/os: linux
53+
kubernetes.io/os: linux

config/controller/kustomization.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ namePrefix: local-
77
# for Windows test, as it checks the same deployment name should not be deployed to enable Windows
88
# IPAM
99
images:
10-
- name: controller
11-
newName: controller
12-
newTag: latest
10+
- digest: latest
11+
name: controller
12+
newName: controller

config/crd/kustomization.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# since it depends on service name and namespace that are out of this kustomize package.
33
# It should be run by config/default
44
resources:
5+
- bases/vpcresources.k8s.aws_cninodes.yaml
56
- bases/vpcresources.k8s.aws_securitygrouppolicies.yaml
67
# +kubebuilder:scaffold:crdkustomizeresource
78

config/default/kustomization.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ vars:
4747
objref:
4848
kind: Certificate
4949
group: cert-manager.io
50-
version: v1alpha2
50+
version: v1
5151
name: serving-cert # this name should match the one in certificate.yaml
5252
fieldref:
5353
fieldpath: metadata.namespace
5454
- name: CERTIFICATE_NAME
5555
objref:
5656
kind: Certificate
5757
group: cert-manager.io
58-
version: v1alpha2
58+
version: v1
5959
name: serving-cert # this name should match the one in certificate.yaml
6060
- name: SERVICE_NAMESPACE # namespace of the service
6161
objref:

0 commit comments

Comments
 (0)