Skip to content

Commit d044fca

Browse files
authored
feat: add azure ip masq merger (#3737)
* add azure ip masq merger merges ip masq agent configs into one configmap and outputs to a directory adds the non masquerade ips list together and ORs the other flags together if no configmap that starts with ip-masq exists, no merged configmap is output and any previously created merged configmap in the merged-config directory is deleted this binary is separate from the rest of the repo similar to azure-ipam * add azure ip masq merger make targets ip masq merger is only meant to work on linux since ip masq agent only runs on linux * add ip masq merger tests rename ip masq merger to be consistent with other files add golangci yml for linting fix shadowing issues with err and use newer method to check file not found error fix linter issues use require for tests * add make test for azure ip masq merger tested * add input output configuration * update images to mariner 3.0 * update temp base to 3.0 and fix formatting
1 parent 9df7534 commit d044fca

File tree

7 files changed

+927
-17
lines changed

7 files changed

+927
-17
lines changed

Makefile

Lines changed: 86 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,20 @@ EXE_EXT = .exe
3030
endif
3131

3232
# Interrogate the git repo and set some variables
33-
REPO_ROOT ?= $(shell git rev-parse --show-toplevel)
34-
REVISION ?= $(shell git rev-parse --short HEAD)
35-
ACN_VERSION ?= $(shell git describe --exclude "azure-ipam*" --exclude "dropgz*" --exclude "zapai*" --exclude "ipv6-hp-bpf*" --tags --always)
36-
IPV6_HP_BPF_VERSION ?= $(notdir $(shell git describe --match "ipv6-hp-bpf*" --tags --always))
37-
AZURE_IPAM_VERSION ?= $(notdir $(shell git describe --match "azure-ipam*" --tags --always))
38-
CNI_VERSION ?= $(ACN_VERSION)
39-
CNS_VERSION ?= $(ACN_VERSION)
40-
NPM_VERSION ?= $(ACN_VERSION)
41-
ZAPAI_VERSION ?= $(notdir $(shell git describe --match "zapai*" --tags --always))
33+
REPO_ROOT ?= $(shell git rev-parse --show-toplevel)
34+
REVISION ?= $(shell git rev-parse --short HEAD)
35+
ACN_VERSION ?= $(shell git describe --exclude "azure-ipam*" --exclude "dropgz*" --exclude "zapai*" --exclude "ipv6-hp-bpf*" --tags --always)
36+
IPV6_HP_BPF_VERSION ?= $(notdir $(shell git describe --match "ipv6-hp-bpf*" --tags --always))
37+
AZURE_IPAM_VERSION ?= $(notdir $(shell git describe --match "azure-ipam*" --tags --always))
38+
AZURE_IP_MASQ_MERGER_VERSION ?= $(notdir $(shell git describe --match "azure-ip-masq-merger*" --tags --always))
39+
CNI_VERSION ?= $(ACN_VERSION)
40+
CNS_VERSION ?= $(ACN_VERSION)
41+
NPM_VERSION ?= $(ACN_VERSION)
42+
ZAPAI_VERSION ?= $(notdir $(shell git describe --match "zapai*" --tags --always))
4243

4344
# Build directories.
4445
AZURE_IPAM_DIR = $(REPO_ROOT)/azure-ipam
46+
AZURE_IP_MASQ_MERGER_DIR = $(REPO_ROOT)/azure-ip-masq-merger
4547
IPV6_HP_BPF_DIR = $(REPO_ROOT)/bpf-prog/ipv6-hp-bpf
4648

4749
CNI_NET_DIR = $(REPO_ROOT)/cni/network/plugin
@@ -55,6 +57,7 @@ NPM_DIR = $(REPO_ROOT)/npm/cmd
5557
OUTPUT_DIR = $(REPO_ROOT)/output
5658
BUILD_DIR = $(OUTPUT_DIR)/$(GOOS)_$(GOARCH)
5759
AZURE_IPAM_BUILD_DIR = $(BUILD_DIR)/azure-ipam
60+
AZURE_IP_MASQ_MERGER_BUILD_DIR = $(BUILD_DIR)/azure-ip-masq-merger
5861
IPV6_HP_BPF_BUILD_DIR = $(BUILD_DIR)/bpf-prog/ipv6-hp-bpf
5962
IMAGE_DIR = $(OUTPUT_DIR)/images
6063

@@ -102,6 +105,7 @@ CNI_DUALSTACK_ARCHIVE_NAME = azure-vnet-cni-overlay-dualstack-$(GOOS)-$(GOARCH)-
102105
CNS_ARCHIVE_NAME = azure-cns-$(GOOS)-$(GOARCH)-$(CNS_VERSION).$(ARCHIVE_EXT)
103106
NPM_ARCHIVE_NAME = azure-npm-$(GOOS)-$(GOARCH)-$(NPM_VERSION).$(ARCHIVE_EXT)
104107
AZURE_IPAM_ARCHIVE_NAME = azure-ipam-$(GOOS)-$(GOARCH)-$(AZURE_IPAM_VERSION).$(ARCHIVE_EXT)
108+
AZURE_IP_MASQ_MERGER_ARCHIVE_NAME = azure-ip-masq-merger-$(GOOS)-$(GOARCH)-$(AZURE_IP_MASQ_MERGER_VERSION).$(ARCHIVE_EXT)
105109
IPV6_HP_BPF_ARCHIVE_NAME = ipv6-hp-bpf-$(GOOS)-$(GOARCH)-$(IPV6_HP_BPF_VERSION).$(ARCHIVE_EXT)
106110

107111
# Image info file names.
@@ -119,8 +123,8 @@ all-binaries-platforms: ## Make all platform binaries
119123

120124
# OS specific binaries/images
121125
ifeq ($(GOOS),linux)
122-
all-binaries: acncli azure-cni-plugin azure-cns azure-npm azure-ipam ipv6-hp-bpf
123-
all-images: npm-image cns-image cni-manager-image ipv6-hp-bpf-image
126+
all-binaries: acncli azure-cni-plugin azure-cns azure-npm azure-ipam azure-ip-masq-merger ipv6-hp-bpf
127+
all-images: npm-image cns-image cni-manager-image azure-ip-masq-merger-image ipv6-hp-bpf-image
124128
else
125129
all-binaries: azure-cni-plugin azure-cns azure-npm
126130
all-images:
@@ -134,6 +138,7 @@ acncli: acncli-binary acncli-archive
134138
azure-npm: azure-npm-binary npm-archive
135139
azure-ipam: azure-ipam-binary azure-ipam-archive
136140
ipv6-hp-bpf: ipv6-hp-bpf-binary ipv6-hp-bpf-archive
141+
azure-ip-masq-merger: azure-ip-masq-merger-binary azure-ip-masq-merger-archive
137142

138143

139144
##@ Versioning
@@ -149,6 +154,9 @@ acncli-version: version
149154
azure-ipam-version: ## prints the azure-ipam version
150155
@echo $(AZURE_IPAM_VERSION)
151156

157+
azure-ip-masq-merger-version: ## prints the azure-ip-masq-merger version
158+
@echo $(AZURE_IP_MASQ_MERGER_VERSION)
159+
152160
ipv6-hp-bpf-version: ## prints the ipv6-hp-bpf version
153161
@echo $(IPV6_HP_BPF_VERSION)
154162

@@ -218,6 +226,10 @@ azure-npm-binary:
218226
cd $(CNI_TELEMETRY_DIR) && CGO_ENABLED=0 go build -v -o $(NPM_BUILD_DIR)/azure-vnet-telemetry$(EXE_EXT) -ldflags "-X main.version=$(NPM_VERSION)" -gcflags="-dwarflocationlists=true"
219227
cd $(NPM_DIR) && CGO_ENABLED=0 go build -v -o $(NPM_BUILD_DIR)/azure-npm$(EXE_EXT) -ldflags "-X main.version=$(NPM_VERSION) -X $(NPM_AI_PATH)=$(NPM_AI_ID)" -gcflags="-dwarflocationlists=true"
220228

229+
# Build the azure-ip-masq-merger binary.
230+
azure-ip-masq-merger-binary:
231+
cd $(AZURE_IP_MASQ_MERGER_DIR) && CGO_ENABLED=0 go build -v -o $(AZURE_IP_MASQ_MERGER_BUILD_DIR)/azure-ip-masq-merger$(EXE_EXT) -ldflags "-X main.version=$(AZURE_IP_MASQ_MERGER_VERSION)" -gcflags="-dwarflocationlists=true"
232+
221233
##@ Containers
222234

223235
## Common variables for all containers.
@@ -256,12 +268,13 @@ CONTAINER_TRANSPORT = docker
256268
endif
257269

258270
## Image name definitions.
259-
ACNCLI_IMAGE = acncli
260-
AZURE_IPAM_IMAGE = azure-ipam
261-
IPV6_HP_BPF_IMAGE = ipv6-hp-bpf
262-
CNI_IMAGE = azure-cni
263-
CNS_IMAGE = azure-cns
264-
NPM_IMAGE = azure-npm
271+
ACNCLI_IMAGE = acncli
272+
AZURE_IPAM_IMAGE = azure-ipam
273+
IPV6_HP_BPF_IMAGE = ipv6-hp-bpf
274+
CNI_IMAGE = azure-cni
275+
CNS_IMAGE = azure-cns
276+
NPM_IMAGE = azure-npm
277+
AZURE_IP_MASQ_MERGER_IMAGE = azure-ip-masq-merger
265278

266279
## Image platform tags.
267280
ACNCLI_PLATFORM_TAG ?= $(subst /,-,$(PLATFORM))-$(ACN_VERSION)
@@ -273,6 +286,7 @@ CNI_WINDOWS_PLATFORM_TAG ?= $(subst /,-,$(PLATFORM))-$(CNI_VERSION)-$(OS_SKU_WI
273286
CNS_PLATFORM_TAG ?= $(subst /,-,$(PLATFORM))-$(CNS_VERSION)
274287
CNS_WINDOWS_PLATFORM_TAG ?= $(subst /,-,$(PLATFORM))-$(CNS_VERSION)-$(OS_SKU_WIN)
275288
NPM_PLATFORM_TAG ?= $(subst /,-,$(PLATFORM))-$(NPM_VERSION)
289+
AZURE_IP_MASQ_MERGER_PLATFORM_TAG ?= $(subst /,-,$(PLATFORM))-$(AZURE_IP_MASQ_MERGER_VERSION)
276290

277291

278292
qemu-user-static: ## Set up the host to run qemu multiplatform container builds.
@@ -383,6 +397,34 @@ azure-ipam-image-pull: ## pull azure-ipam container image.
383397
IMAGE=$(AZURE_IPAM_IMAGE) \
384398
TAG=$(AZURE_IPAM_PLATFORM_TAG)
385399

400+
# azure-ip-masq-merger
401+
azure-ip-masq-merger-image-name: # util target to print the azure-ip-masq-merger image name.
402+
@echo $(AZURE_IP_MASQ_MERGER_IMAGE)
403+
404+
azure-ip-masq-merger-image-name-and-tag: # util target to print the azure-ip-masq-merger image name and tag.
405+
@echo $(IMAGE_REGISTRY)/$(AZURE_IP_MASQ_MERGER_IMAGE):$(AZURE_IP_MASQ_MERGER_PLATFORM_TAG)
406+
407+
azure-ip-masq-merger-image: ## build azure-ip-masq-merger container image.
408+
$(MAKE) container \
409+
DOCKERFILE=azure-ip-masq-merger/Dockerfile \
410+
IMAGE=$(AZURE_IP_MASQ_MERGER_IMAGE) \
411+
PLATFORM=$(PLATFORM) \
412+
TAG=$(AZURE_IP_MASQ_MERGER_PLATFORM_TAG) \
413+
TARGET=$(OS) \
414+
OS=$(OS) \
415+
ARCH=$(ARCH)
416+
417+
azure-ip-masq-merger-image-push: ## push azure-ip-masq-merger container image.
418+
$(MAKE) container-push \
419+
IMAGE=$(AZURE_IP_MASQ_MERGER_IMAGE) \
420+
TAG=$(AZURE_IP_MASQ_MERGER_PLATFORM_TAG)
421+
422+
azure-ip-masq-merger-image-pull: ## pull azure-ip-masq-merger container image.
423+
$(MAKE) container-pull \
424+
IMAGE=$(AZURE_IP_MASQ_MERGER_IMAGE) \
425+
TAG=$(AZURE_IP_MASQ_MERGER_PLATFORM_TAG)
426+
427+
386428
# ipv6-hp-bpf
387429

388430
ipv6-hp-bpf-image-name: # util target to print the ipv6-hp-bpf image name.
@@ -559,6 +601,22 @@ azure-ipam-skopeo-archive: ## export tar archive of azure-ipam multiplat contain
559601
IMAGE=$(AZURE_IPAM_IMAGE) \
560602
TAG=$(AZURE_IPAM_VERSION)
561603

604+
azure-ip-masq-merger-manifest-build: ## build azure-ip-masq-merger multiplat container manifest.
605+
$(MAKE) manifest-build \
606+
PLATFORMS="$(PLATFORMS)" \
607+
IMAGE=$(AZURE_IP_MASQ_MERGER_IMAGE) \
608+
TAG=$(AZURE_IP_MASQ_MERGER_VERSION)
609+
610+
azure-ip-masq-merger-manifest-push: ## push azure-ip-masq-merger multiplat container manifest
611+
$(MAKE) manifest-push \
612+
IMAGE=$(AZURE_IP_MASQ_MERGER_IMAGE) \
613+
TAG=$(AZURE_IP_MASQ_MERGER_VERSION)
614+
615+
azure-ip-masq-merger-skopeo-archive: ## export tar archive of azure-ip-masq-merger multiplat container manifest.
616+
$(MAKE) manifest-skopeo-archive \
617+
IMAGE=$(AZURE_IP_MASQ_MERGER_IMAGE) \
618+
TAG=$(AZURE_IP_MASQ_MERGER_VERSION)
619+
562620
ipv6-hp-bpf-manifest-build: ## build ipv6-hp-bpf multiplat container manifest.
563621
$(MAKE) manifest-build \
564622
PLATFORMS="$(PLATFORMS)" \
@@ -709,6 +767,14 @@ ifeq ($(GOOS),linux)
709767
cd $(AZURE_IPAM_BUILD_DIR) && $(ARCHIVE_CMD) $(AZURE_IPAM_ARCHIVE_NAME) azure-ipam$(EXE_EXT)
710768
endif
711769

770+
# Create a azure-ip-masq-merger archive for the target platform.
771+
.PHONY: azure-ip-masq-merger-archive
772+
azure-ip-masq-merger-archive: azure-ip-masq-merger-binary
773+
ifeq ($(GOOS),linux)
774+
$(MKDIR) $(AZURE_IP_MASQ_MERGER_BUILD_DIR)
775+
cd $(AZURE_IP_MASQ_MERGER_BUILD_DIR) && $(ARCHIVE_CMD) $(AZURE_IP_MASQ_MERGER_ARCHIVE_NAME) azure-ip-masq-merger$(EXE_EXT)
776+
endif
777+
712778
# Create a ipv6-hp-bpf archive for the target platform.
713779
.PHONY: ipv6-hp-bpf-archive
714780
ipv6-hp-bpf-archive: ipv6-hp-bpf-binary
@@ -791,6 +857,9 @@ test-extended-cyclonus: ## run the cyclonus test for npm.
791857
test-azure-ipam: ## run the unit test for azure-ipam
792858
cd $(AZURE_IPAM_DIR) && go test
793859

860+
test-azure-ip-masq-merger: ## run the unit test for azure-ip-masq-merger
861+
cd $(AZURE_IP_MASQ_MERGER_DIR) && go test
862+
794863
kind:
795864
kind create cluster --config ./test/kind/kind.yaml
796865

azure-ip-masq-merger/.golangci.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
issues:
2+
max-same-issues: 0
3+
max-issues-per-linter: 0
4+
new-from-rev: origin/master
5+
linters:
6+
presets:
7+
- bugs
8+
- error
9+
- format
10+
- performance
11+
- unused
12+
disable:
13+
- maligned
14+
- scopelint
15+
enable:
16+
- exportloopref
17+
- goconst
18+
- gocritic
19+
- gocyclo
20+
- gofmt
21+
- goprintffuncname
22+
- gosimple
23+
- lll
24+
- misspell
25+
- nakedret
26+
- promlinter
27+
- revive
28+
linters-settings:
29+
gocritic:
30+
enabled-tags:
31+
- "diagnostic"
32+
- "style"
33+
- "performance"
34+
disabled-checks:
35+
- "hugeParam"
36+
govet:
37+
enable:
38+
- shadow
39+
lll:
40+
line-length: 200

azure-ip-masq-merger/Dockerfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
ARG ARCH
2+
ARG OS_VERSION
3+
ARG OS
4+
5+
# skopeo inspect docker://mcr.microsoft.com/oss/go/microsoft/golang:1.23.2-azurelinux3.0 --format "{{.Name}}@{{.Digest}}"
6+
FROM --platform=linux/${ARCH} mcr.microsoft.com/oss/go/microsoft/golang@sha256:f1f0cbd464ae4cd9d41176d47f1f9fe16a6965425871f817587314e3a04576ec AS go
7+
8+
# skopeo inspect docker://mcr.microsoft.com/azurelinux/base/core:3.0 --format "{{.Name}}@{{.Digest}}"
9+
FROM --platform=linux/${ARCH} mcr.microsoft.com/azurelinux/base/core@sha256:b46476be0b5c9691ad20f78871819950c01433bdfad81d72c61618f4a6202b25 AS mariner-core
10+
11+
FROM go AS azure-ip-masq-merger
12+
ARG OS
13+
ARG VERSION
14+
WORKDIR /azure-ip-masq-merger
15+
COPY ./azure-ip-masq-merger .
16+
RUN GOOS=$OS CGO_ENABLED=0 go build -a -o /go/bin/ip-masq-merger -trimpath -ldflags "-X main.version="$VERSION"" -gcflags="-dwarflocationlists=true" .
17+
18+
# TODO: Replace with scratch later
19+
FROM --platform=linux/${ARCH} mcr.microsoft.com/azurelinux/base/core@sha256:b46476be0b5c9691ad20f78871819950c01433bdfad81d72c61618f4a6202b25 AS linux
20+
COPY --from=azure-ip-masq-merger /go/bin/ip-masq-merger ip-masq-merger
21+
ENTRYPOINT [ "/ip-masq-merger" ]
22+
23+
# skopeo inspect docker://mcr.microsoft.com/oss/kubernetes/windows-host-process-containers-base-image:v1.0.0 --format "{{.Name}}@{{.Digest}}"
24+
FROM mcr.microsoft.com/oss/kubernetes/windows-host-process-containers-base-image@sha256:b4c9637e032f667c52d1eccfa31ad8c63f1b035e8639f3f48a510536bf34032b as windows
25+
COPY --from=azure-ip-masq-merger /go/bin/ip-masq-merger ip-masq-merger.exe
26+
ENTRYPOINT [ "/ip-masq-merger.exe" ]

azure-ip-masq-merger/go.mod

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
module github.com/Azure/azure-container-networking/azure-ip-masq-merger
2+
3+
go 1.23.0
4+
5+
require (
6+
github.com/stretchr/testify v1.9.0
7+
gopkg.in/yaml.v2 v2.4.0
8+
k8s.io/apimachinery v0.31.3
9+
k8s.io/component-base v0.31.3
10+
k8s.io/klog/v2 v2.130.1
11+
)
12+
13+
require (
14+
github.com/beorn7/perks v1.0.1 // indirect
15+
github.com/blang/semver/v4 v4.0.0 // indirect
16+
github.com/cespare/xxhash/v2 v2.3.0 // indirect
17+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
18+
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
19+
github.com/go-logr/logr v1.4.2 // indirect
20+
github.com/gogo/protobuf v1.3.2 // indirect
21+
github.com/google/go-cmp v0.6.0 // indirect
22+
github.com/google/gofuzz v1.2.0 // indirect
23+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
24+
github.com/json-iterator/go v1.1.12 // indirect
25+
github.com/kr/text v0.2.0 // indirect
26+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
27+
github.com/modern-go/reflect2 v1.0.2 // indirect
28+
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
29+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
30+
github.com/prometheus/client_golang v1.19.1 // indirect
31+
github.com/prometheus/client_model v0.6.1 // indirect
32+
github.com/prometheus/common v0.55.0 // indirect
33+
github.com/prometheus/procfs v0.15.1 // indirect
34+
github.com/spf13/cobra v1.8.1 // indirect
35+
github.com/spf13/pflag v1.0.5 // indirect
36+
github.com/x448/float16 v0.8.4 // indirect
37+
golang.org/x/net v0.36.0 // indirect
38+
golang.org/x/sys v0.30.0 // indirect
39+
golang.org/x/text v0.22.0 // indirect
40+
google.golang.org/protobuf v1.34.2 // indirect
41+
gopkg.in/inf.v0 v0.9.1 // indirect
42+
gopkg.in/yaml.v3 v3.0.1 // indirect
43+
k8s.io/utils v0.0.0-20240921022957-49e7df575cb6 // indirect
44+
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
45+
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
46+
sigs.k8s.io/yaml v1.4.0 // indirect
47+
)

0 commit comments

Comments
 (0)