This repository has been archived by the owner on Jul 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 90
/
Makefile
171 lines (142 loc) · 4.56 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# Copyright 2022 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License 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.
.PHONY: all
all: help
# Host info
HOST_ARCH = $(shell which go >/dev/null 2>&1 && go env GOARCH)
export ARCH ?= $(HOST_ARCH)
ifeq ($(ARCH),)
$(error mandatory variable ARCH is empty, either set it when calling the command or make sure 'go env GOARCH' works)
endif
BUILD_DIR=kpng-bin
PLATFORM=""
# Build info
RELEASE ?= UNKNOWN
GIT_REPO_URL ?= $(shell git config --get remote.origin.url)
GIT_COMMIT_HASH ?= git-$(shell git rev-parse --short HEAD)
LDFLAGS="-X main.RELEASE=$(RELEASE) -X main.REPO=$(GIT_REPO_URL) -X main.COMMIT=$(GIT_COMMIT_HASH)"
# Image info
CONTAINER_ENGINE ?= docker
CONTAINER_FILE ?= $(shell echo "${PWD}/Dockerfile")
KPNG_IMAGE_TAG_NAME ?= kpng:test
# Auto Generate help from: https://gist.github.com/prwhite/8168133
# COLORS
GREEN := $(shell tput -Txterm setaf 2)
YELLOW := $(shell tput -Txterm setaf 3)
WHITE := $(shell tput -Txterm setaf 7)
RESET := $(shell tput -Txterm sgr0)
TARGET_MAX_CHAR_NUM=20
.PHONY: help
## Show help
help:
@echo ''
@echo 'Usage:'
@echo ' ${YELLOW}make${RESET} ${GREEN}<target>${RESET}'
@echo ''
@echo 'Targets:'
@awk '/^[a-zA-Z\-_0-9]+:/ { \
helpMessage = match(lastLine, /^## (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")-1); \
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
printf " ${YELLOW}%-$(TARGET_MAX_CHAR_NUM)s${RESET} ${GREEN}%s${RESET}\n", helpCommand, helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)
# Dependecies
go_mod_tests_requirement:
go install golang.org/x/lint/golint@latest
# Development mode - SKIP E2E
# Most of users use IPV4 and iptables as backend
# let's use it as default values
## Starts modd with the template available in-tree
modd:
modd -f modd.conf.template
## Creates k8s cluster with IPV4 and IPTABLES (No E2E involved)
debug:
./hack/test_e2e.sh -i ipv4 -b iptables -d
## Trigger unittests
test: go_mod_tests_requirement ## Execute unittests
./hack/test_unit.sh
## E2E with IPV4 and IPTABLES
e2e-ipv4-iptables: go_mod_tests_requirement
./hack/test_e2e.sh -i ipv4 -b iptables
## E2E with IPV6 and IPTABLES
e2e-ipv6-iptables: go_mod_tests_requirement
./hack/test_e2e.sh -i ipv6 -b iptables
## E2E with DUAL and IPTABLES
e2e-dual-iptables: go_mod_tests_requirement
./hack/test_e2e.sh -i dual -b iptables
## E2E with IPV4 and IPVS
e2e-ipv4-ipvs: go_mod_tests_requirement
./hack/test_e2e.sh -i ipv4 -b ipvs
## E2E with IPV6 and IPVS
e2e-ipv6-ipvs: go_mod_tests_requirement
./hack/test_e2e.sh -i ipv6 -b ipvs
## E2E with DUAL and IPVS
e2e-dual-ipvs: go_mod_tests_requirement
./hack/test_e2e.sh -i dual -b ipvs
## E2E with IPV4 and NFT
e2e-ipv4-nft: go_mod_tests_requirement
./hack/test_e2e.sh -i ipv4 -b nft
## E2E with IPV6 and NFT
e2e-ipv6-nft: go_mod_tests_requirement
./hack/test_e2e.sh -i ipv6 -b nft
## E2E with DUAL and NFT
e2e-dual-nft: go_mod_tests_requirement
./hack/test_e2e.sh -i dual -b nft
## Execute ALL E2E listed above
e2e: e2e-ipv4-iptables \
e2e-ipv6-iptables \
e2e-dual-iptables \
e2e-ipv4-ipvs \
e2e-ipv6-ipvs \
e2e-dual-ipvs \
e2e-ipv4-nft \
e2e-ipv6-nft \
e2e-dual-nft
## Build binary for Windows platform
windows: PLATFORM="windows"
windows:
@$(MAKE) -e build
build:
@mkdir -p $(BUILD_DIR)/$(ARCH)
@cd cmd && \
env GOOS=$(PLATFORM) \
GOARCH=$(ARCH) \
go build \
-trimpath \
-o ../$(BUILD_DIR)/$(ARCH) \
-v \
-ldflags=$(LDFLAGS) \
./...
@echo "\tkpng $(YELLOW)$(ARCH)$(RESET) binaries available in: $(GREEN)$(BUILD_DIR)/$(ARCH)$(RESET)\n"
image:
$(CONTAINER_ENGINE) build \
$(QUIET_MODE) \
-t $(KPNG_IMAGE_TAG_NAME) \
-f $(CONTAINER_FILE) \
--build-arg RELEASE=$(RELEASE) \
--build-arg GIT_REPO_URL=$(GIT_REPO_URL) \
--build-arg GIT_COMMIT_HASH=$(GIT_COMMIT_HASH) \
.
## Create Kind cluster for Tilt. It requires backend(b) and ipfamily (i) as args. eg: make tilt-setup i=ipv4 b=nft m=split-process-per-node
tilt-setup:
./hack/tilt/setup.sh -i $(i) -b $(b) -m $(m)
## Start Tilt server.
tilt-up:
@tilt up -f ./hack/tilt/Tiltfile --host=0.0.0.0
## Stop TiltServer.
tilt-down:
@tilt down -f ./hack/tilt/Tiltfile