Skip to content

Commit 6b7c03d

Browse files
authored
Update libs to support Apple silicon (#164)
Re-use test-env, mocks, and linter
1 parent 6a76946 commit 6b7c03d

File tree

10 files changed

+39
-38
lines changed

10 files changed

+39
-38
lines changed

Makefile

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ GOBIN=$(shell go env GOBIN)
1515
endif
1616

1717
# Setting SHELL to bash allows bash commands to be executed by recipes.
18-
# This is a requirement for 'setup-envtest.sh' in the test target.
1918
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
2019
SHELL = /usr/bin/env bash -o pipefail
2120
.SHELLFLAGS = -ec
@@ -58,33 +57,40 @@ mod:
5857
tidy:
5958
go mod tidy
6059

60+
GOLANGCI_LINT=$(shell pwd)/bin/golangci-lint
6161
golangci-lint: ## Download golangci-lint
62+
ifneq ($(shell test -f $(GOLANGCI_LINT); echo $$?), 0)
63+
@echo Getting golangci-lint...
6264
@mkdir -p $(shell pwd)/bin
63-
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell pwd)/bin v1.45.2
65+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell pwd)/bin v1.46.2
66+
endif
6467

6568
.PHONY: lint
6669
lint: golangci-lint ## Run linter
67-
$(shell pwd)/bin/golangci-lint run
70+
$(GOLANGCI_LINT) run
6871

6972
.PHONY: goimports
7073
goimports: ## run goimports updating files in place
7174
goimports -w .
7275

7376
ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
74-
test: manifests generate generate-mocks fmt vet test-setup ## Run tests.
75-
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out -covermode=atomic
77+
KUBEBUILDER_ASSETS?="$(shell $(ENVTEST) use -i $(ENVTEST_KUBERNETES_VERSION) --bin-dir=$(ENVTEST_ASSETS_DIR) -p path)"
78+
test: manifests generate generate-mocks fmt vet test-setup ## Run tests
79+
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) go test ./... -coverprofile cover.out -covermode=atomic
7680

77-
test-setup: ## setup test environment
81+
test-setup: setup-envtest ## Ensure test environment has been downloaded
82+
ifneq ($(shell test -d $(ENVTEST_ASSETS_DIR); echo $$?), 0)
83+
@echo Setting up K8s test environment...
7884
mkdir -p ${ENVTEST_ASSETS_DIR}
79-
test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.8.3/hack/setup-envtest.sh
80-
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR)
85+
$(ENVTEST) use 1.24.x --bin-dir $(ENVTEST_ASSETS_DIR)
86+
endif
8187

8288
kind-integration-suite: ## Provision and run integration tests with cleanup
8389
make kind-integration-setup && \
8490
make kind-integration-run && \
8591
make kind-integration-cleanup
8692

87-
kind-integration-setup: build kind test-setup ## Setup the integration test using kind clusters
93+
kind-integration-setup: build kind ## Setup the integration test using kind clusters
8894
@./integration/kind-test/scripts/setup-kind.sh
8995

9096
kind-integration-run: ## Run the integration test controller
@@ -98,7 +104,7 @@ eks-integration-suite: ## Provision and run EKS integration tests with cleanup
98104
make eks-integration-run && \
99105
make eks-integration-cleanup
100106

101-
eks-integration-setup: build test-setup ## Setup the integration test using EKS clusters
107+
eks-integration-setup: build ## Setup the integration test using EKS clusters
102108
@./integration/eks-test/scripts/eks-setup.sh
103109

104110
eks-integration-run: ## Run the integration test controller
@@ -129,7 +135,8 @@ docker-push: ## Push docker image with the manager.
129135
clean:
130136
@echo Cleaning...
131137
go clean
132-
rm -rf $(MOCKS_DESTINATION) bin/ testbin/ cover.out
138+
if test -d $(ENVTEST_ASSETS_DIR) ; then chmod -R +w $(ENVTEST_ASSETS_DIR) ; fi
139+
rm -rf $(MOCKS_DESTINATION)/ bin/ $(ENVTEST_ASSETS_DIR)/ cover.out
133140

134141
##@ Deployment
135142

@@ -148,6 +155,8 @@ undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/confi
148155

149156
MOCKS_DESTINATION=mocks
150157
generate-mocks: mockgen
158+
ifneq ($(shell test -d $(MOCKS_DESTINATION); echo $$?), 0)
159+
@echo Generating mocks...
151160
$(MOCKGEN) --source pkg/cloudmap/client.go --destination $(MOCKS_DESTINATION)/pkg/cloudmap/client_mock.go --package cloudmap_mock
152161
$(MOCKGEN) --source pkg/cloudmap/cache.go --destination $(MOCKS_DESTINATION)/pkg/cloudmap/cache_mock.go --package cloudmap_mock
153162
$(MOCKGEN) --source pkg/cloudmap/operation_poller.go --destination $(MOCKS_DESTINATION)/pkg/cloudmap/operation_poller_mock.go --package cloudmap_mock
@@ -156,23 +165,27 @@ generate-mocks: mockgen
156165
$(MOCKGEN) --source pkg/cloudmap/aws_facade.go --destination $(MOCKS_DESTINATION)/pkg/cloudmap/aws_facade_mock.go --package cloudmap_mock
157166
$(MOCKGEN) --source integration/janitor/api.go --destination $(MOCKS_DESTINATION)/integration/janitor/api_mock.go --package janitor_mock
158167
$(MOCKGEN) --source integration/janitor/aws_facade.go --destination $(MOCKS_DESTINATION)/integration/janitor/aws_facade_mock.go --package janitor_mock
159-
168+
endif
160169

161170
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
162171
controller-gen: ## Download controller-gen locally if necessary.
163-
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.8.0)
172+
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.9.2)
164173

165174
KUSTOMIZE = $(shell pwd)/bin/kustomize
166175
kustomize: ## Download kustomize locally if necessary.
167-
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected])
176+
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected])
177+
178+
ENVTEST = $(shell pwd)/bin/setup-envtest
179+
setup-envtest: ## Download setup-envtest
180+
$(call go-get-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)
168181

169182
MOCKGEN = $(shell pwd)/bin/mockgen
170183
mockgen: ## Download mockgen
171184
$(call go-get-tool,$(MOCKGEN),github.com/golang/mock/[email protected])
172185

173186
KIND = $(shell pwd)/bin/kind
174187
kind: ## Download kind
175-
$(call go-get-tool,$(KIND),sigs.k8s.io/kind@v0.13.0)
188+
$(call go-get-tool,$(KIND),sigs.k8s.io/kind@v0.14.0)
176189

177190
# go-get-tool will 'go get' any package $2 and install it to $1.
178191
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))

config/crd/bases/multicluster.x-k8s.io_serviceexports.yaml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
33
kind: CustomResourceDefinition
44
metadata:
55
annotations:
6-
controller-gen.kubebuilder.io/version: v0.8.0
6+
controller-gen.kubebuilder.io/version: v0.9.2
77
creationTimestamp: null
88
name: serviceexports.multicluster.x-k8s.io
99
spec:
@@ -114,9 +114,3 @@ spec:
114114
type: object
115115
served: true
116116
storage: true
117-
status:
118-
acceptedNames:
119-
kind: ""
120-
plural: ""
121-
conditions: []
122-
storedVersions: []

config/crd/bases/multicluster.x-k8s.io_serviceimports.yaml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
33
kind: CustomResourceDefinition
44
metadata:
55
annotations:
6-
controller-gen.kubebuilder.io/version: v0.8.0
6+
controller-gen.kubebuilder.io/version: v0.9.2
77
creationTimestamp: null
88
name: serviceimports.multicluster.x-k8s.io
99
spec:
@@ -136,9 +136,3 @@ spec:
136136
type: object
137137
served: true
138138
storage: true
139-
status:
140-
acceptedNames:
141-
kind: ""
142-
plural: ""
143-
conditions: []
144-
storedVersions: []

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ require (
1515
k8s.io/api v0.24.2
1616
k8s.io/apimachinery v0.24.2
1717
k8s.io/client-go v0.24.2
18-
sigs.k8s.io/controller-runtime v0.12.2
18+
sigs.k8s.io/controller-runtime v0.12.3
1919
)
2020

2121
require (

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,8 +1002,8 @@ rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8
10021002
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
10031003
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
10041004
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.30/go.mod h1:fEO7lRTdivWO2qYVCVG7dEADOMo/MLDCVr8So2g88Uw=
1005-
sigs.k8s.io/controller-runtime v0.12.2 h1:nqV02cvhbAj7tbt21bpPpTByrXGn2INHRsi39lXy9sE=
1006-
sigs.k8s.io/controller-runtime v0.12.2/go.mod h1:qKsk4WE6zW2Hfj0G4v10EnNB2jMG1C+NTb8h+DwCoU0=
1005+
sigs.k8s.io/controller-runtime v0.12.3 h1:FCM8xeY/FI8hoAfh/V4XbbYMY20gElh9yh+A98usMio=
1006+
sigs.k8s.io/controller-runtime v0.12.3/go.mod h1:qKsk4WE6zW2Hfj0G4v10EnNB2jMG1C+NTb8h+DwCoU0=
10071007
sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2 h1:kDi4JBNAsJWfz1aEXhO8Jg87JJaPNLh5tIzYHgStQ9Y=
10081008
sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2/go.mod h1:B+TnT182UBxE84DiCz4CVE26eOSDAeYCpfDnC2kdKMY=
10091009
sigs.k8s.io/structured-merge-diff/v4 v4.0.2/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK1F7G282QMXDPYydCw=

integration/eks-test/scripts/eks-run-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ if [ "$exit_code" -eq 0 ] ; then
2828
fi
2929

3030
echo "sleeping..."
31-
sleep 2s
31+
sleep 2
3232

3333
# Scaling and verifying deployment
3434
if [ "$exit_code" -eq 0 ] ; then

integration/eks-test/scripts/eks-setup.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ $KUBECTL_BIN apply -f "$CONFIGS/nginx-serviceexport.yaml"
2222
# Create client-hello pod
2323
$KUBECTL_BIN config use-context $IMPORT_CLS
2424
$KUBECTL_BIN apply -f "$CONFIGS/client-hello.yaml"
25-
sleep 15s
25+
sleep 15
2626
$KUBECTL_BIN exec $CLIENT_POD -n $NAMESPACE /bin/sh -- apk add curl ## install curl
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22

33
export KIND_BIN='./bin/kind'
4-
export KUBECTL_BIN='./testbin/bin/kubectl'
4+
export KUBECTL_BIN='kubectl'
55
export LOGS='./integration/kind-test/testlog'
66
export CONFIGS='./integration/kind-test/configs'
77
export SCENARIOS='./integration/shared/scenarios'
@@ -11,6 +11,6 @@ export ENDPT_PORT=80
1111
export SERVICE_PORT=8080
1212
export KIND_SHORT='cloud-map-e2e'
1313
export CLUSTER='kind-cloud-map-e2e'
14-
export IMAGE='kindest/node:v1.19.16@sha256:dec41184d10deca01a08ea548197b77dc99eeacb56ff3e371af3193c86ca99f4'
14+
export IMAGE='kindest/node:v1.20.15@sha256:a6ce604504db064c5e25921c6c0fffea64507109a1f2a512b1b562ac37d652f3'
1515
export EXPECTED_ENDPOINT_COUNT=5
1616
export UPDATED_ENDPOINT_COUNT=6

integration/kind-test/scripts/run-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ if [ "$exit_code" -eq 0 ] ; then
2626
fi
2727

2828
echo "sleeping..."
29-
sleep 2s
29+
sleep 2
3030

3131
deployment=$($KUBECTL_BIN get deployment --namespace "$NAMESPACE" -o json | jq -r '.items[0].metadata.name')
3232

integration/shared/scripts/poll-endpoints.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ do
1313
exit 1
1414
fi
1515

16-
sleep 2s
16+
sleep 2
1717
if ! addresses=$($KUBECTL_BIN get endpointslices -o json --namespace "$NAMESPACE" | \
1818
jq --arg SERVICE "$SERVICE" '.items[] | select(.metadata.ownerReferences[].name==$SERVICE) | .endpoints[].addresses[0]' 2> /dev/null)
1919
then

0 commit comments

Comments
 (0)