Skip to content

Commit 191d3c5

Browse files
authored
ci: add azure ip masq merger to pipeline (#3739)
* add ip masq merger to pipeline yaml * add azure ip masq merger to signed binaries (acn official build) pipeline todo: add azureIpMasqMergerVersion pipeline version somewhere * add script and changes to signed pipeline * add README to azure ip masq merger * modify dockerfile to be consistent with binary naming tested merged config live cluster with tcpdump * update dockerfiles * remove unused dockerfile components
1 parent 3253093 commit 191d3c5

File tree

7 files changed

+138
-14
lines changed

7 files changed

+138
-14
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
ARG ARCH
2+
3+
FROM scratch AS linux
4+
ARG ARTIFACT_DIR
5+
6+
COPY ${ARTIFACT_DIR}/bin/azure-ip-masq-merger /azure-ip-masq-merger
7+
ENTRYPOINT ["/azure-ip-masq-merger"]

.pipelines/build/ob-prepare.steps.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
steps:
32
- template: utils/rename-dockerfile-references.steps.yaml
43
parameters:
@@ -59,6 +58,10 @@ steps:
5958
echo "##vso[task.setvariable variable=azureIpamVersion;isOutput=true]$AZUREIPAMVERSION"
6059
echo "azureIpamVersion: $AZUREIPAMVERSION"
6160
61+
AZUREIPMASQMERGERVERSION=$(make azure-ip-masq-merger-version)
62+
echo "##vso[task.setvariable variable=azureIpMasqMergerVersion;isOutput=true]$AZUREIPMASQMERGERVERSION"
63+
echo "azureIpMasqMergerVersion: $AZUREIPMASQMERGERVERSION"
64+
6265
CNIVERSION=$(make cni-version)
6366
echo "##vso[task.setvariable variable=cniVersion;isOutput=true]$CNIVERSION"
6467
echo "cniVersion: $CNIVERSION"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
set -eux
3+
4+
[[ $OS =~ windows ]] && { echo "azure-ip-masq-merger is not supported on Windows"; exit 1; }
5+
FILE_EXT=''
6+
7+
export CGO_ENABLED=0
8+
9+
mkdir -p "$OUT_DIR"/bin
10+
mkdir -p "$OUT_DIR"/files
11+
12+
pushd "$REPO_ROOT"/azure-ip-masq-merger
13+
GOOS="$OS" go build -v -a -trimpath \
14+
-o "$OUT_DIR"/bin/azure-ip-masq-merger"$FILE_EXT" \
15+
-ldflags "-X github.com/Azure/azure-container-networking/azure-ip-masq-merger/internal/buildinfo.Version=$AZURE_IP_MASQ_MERGER_VERSION -X main.version=$AZURE_IP_MASQ_MERGER_VERSION" \
16+
-gcflags="-dwarflocationlists=true" \
17+
.
18+
popd

.pipelines/pipeline.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ stages:
121121
arch: amd64
122122
name: azure-ipam
123123
os: windows
124+
azure_ip_masq_merger_linux_amd64:
125+
arch: amd64
126+
name: azure-ip-masq-merger
127+
os: linux
124128
cni_linux_amd64:
125129
arch: amd64
126130
name: cni
@@ -166,6 +170,10 @@ stages:
166170
arch: arm64
167171
name: azure-ipam
168172
os: linux
173+
azure_ip_masq_merger_linux_arm64:
174+
arch: arm64
175+
name: azure-ip-masq-merger
176+
os: linux
169177
cni_linux_arm64:
170178
arch: arm64
171179
name: cni
@@ -217,6 +225,9 @@ stages:
217225
npm:
218226
name: npm
219227
platforms: linux/amd64 linux/arm64 windows/amd64
228+
azure_ip_masq_merger:
229+
name: azure-ip-masq-merger
230+
platforms: linux/amd64 linux/arm64
220231
steps:
221232
- template: containers/manifest-template.yaml
222233
parameters:

.pipelines/run-pipeline.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ stages:
3939

4040
IMAGE_REPO_PATH: $[ stageDependencies.setup.env.outputs['EnvironmentalVariables.imageRepositoryPath'] ]
4141
AZURE_IPAM_VERSION: $[ stageDependencies.setup.env.outputs['EnvironmentalVariables.azureIpamVersion'] ]
42+
AZURE_IP_MASQ_MERGER_VERSION: $[ stageDependencies.setup.env.outputs['EnvironmentalVariables.azureIpMasqMergerVersion'] ]
4243
CNI_VERSION: $[ stageDependencies.setup.env.outputs['EnvironmentalVariables.cniVersion'] ]
4344
CNS_VERSION: $[ stageDependencies.setup.env.outputs['EnvironmentalVariables.cnsVersion'] ]
4445
IPV6_HP_BPF_VERSION: $[ stageDependencies.setup.env.outputs['EnvironmentalVariables.ipv6HpBpfVersion'] ]
@@ -63,6 +64,12 @@ stages:
6364
archiveVersion: $(AZURE_IPAM_VERSION)
6465
imageTag: $(Build.BuildNumber)
6566
packageWithDropGZ: True
67+
azure_ip_masq_merger:
68+
name: azure-ip-masq-merger
69+
extraArgs: ''
70+
archiveName: azure-ip-masq-merger
71+
archiveVersion: $(AZURE_IP_MASQ_MERGER_VERSION)
72+
imageTag: $(Build.BuildNumber)
6673
cni:
6774
name: cni
6875
extraArgs: '--build-arg CNI_AI_PATH=$(CNI_AI_PATH) --build-arg CNI_AI_ID=$(CNI_AI_ID)'
@@ -141,6 +148,12 @@ stages:
141148
extraArgs: ''
142149
imageTag: $(Build.BuildNumber)
143150
packageWithDropGZ: True
151+
azure_ip_masq_merger:
152+
name: azure-ip-masq-merger
153+
extraArgs: ''
154+
archiveName: azure-ip-masq-merger
155+
archiveVersion: $(AZURE_IP_MASQ_MERGER_VERSION)
156+
imageTag: $(Build.BuildNumber)
144157
cni:
145158
name: cni
146159
extraArgs: '--build-arg CNI_AI_PATH=$(CNI_AI_PATH) --build-arg CNI_AI_ID=$(CNI_AI_ID)'
@@ -177,6 +190,7 @@ stages:
177190
IMAGE_REPO_PATH: $[ stageDependencies.setup.env.outputs['EnvironmentalVariables.imageRepositoryPath'] ]
178191

179192
AZURE_IPAM_VERSION: $[ stageDependencies.setup.env.outputs['EnvironmentalVariables.azureIpamVersion'] ]
193+
AZURE_IP_MASQ_MERGER_VERSION: $[ stageDependencies.setup.env.outputs['EnvironmentalVariables.azureIpMasqMergerVersion'] ]
180194
CNI_VERSION: $[ stageDependencies.setup.env.outputs['EnvironmentalVariables.cniVersion'] ]
181195
CNS_VERSION: $[ stageDependencies.setup.env.outputs['EnvironmentalVariables.cnsVersion'] ]
182196
IPV6_HP_BPF_VERSION: $[ stageDependencies.setup.env.outputs['EnvironmentalVariables.ipv6HpBpfVersion'] ]
@@ -186,6 +200,9 @@ stages:
186200
IPAM_LINUX_ARM64_REF: $(IMAGE_REPO_PATH)/linux-arm64/azure-ipam:$(Build.BuildNumber)
187201
IPAM_WINDOWS_AMD64_REF: $(IMAGE_REPO_PATH)/windows-amd64/azure-ipam:$(Build.BuildNumber)
188202

203+
IP_MASQ_MERGER_LINUX_AMD64_REF: $(IMAGE_REPO_PATH)/linux-amd64/azure-ip-masq-merger:$(Build.BuildNumber)
204+
IP_MASQ_MERGER_LINUX_ARM64_REF: $(IMAGE_REPO_PATH)/linux-arm64/azure-ip-masq-merger:$(Build.BuildNumber)
205+
189206
CNI_LINUX_AMD64_REF: $(IMAGE_REPO_PATH)/linux-amd64/cni:$(Build.BuildNumber)
190207
CNI_LINUX_ARM64_REF: $(IMAGE_REPO_PATH)/linux-arm64/cni:$(Build.BuildNumber)
191208
CNI_WINDOWS_AMD64_REF: $(IMAGE_REPO_PATH)/windows-amd64/cni:$(Build.BuildNumber)
@@ -216,6 +233,15 @@ stages:
216233
imageReference: $(IPAM_LINUX_ARM64_REF)
217234
- platform: windows/amd64
218235
imageReference: $(IPAM_WINDOWS_AMD64_REF)
236+
- job: azure_ip_masq_merger
237+
templateContext:
238+
name: azure-ip-masq-merger
239+
image_tag: $(AZURE_IP_MASQ_MERGER_VERSION)
240+
platforms:
241+
- platform: linux/amd64
242+
imageReference: $(IP_MASQ_MERGER_LINUX_AMD64_REF)
243+
- platform: linux/arm64
244+
imageReference: $(IP_MASQ_MERGER_LINUX_ARM64_REF)
219245
- job: cni
220246
templateContext:
221247
name: cni

azure-ip-masq-merger/Dockerfile

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,16 @@
11
ARG ARCH
2-
ARG OS_VERSION
32
ARG OS
43

54
# skopeo inspect docker://mcr.microsoft.com/oss/go/microsoft/golang:1.23.2-azurelinux3.0 --format "{{.Name}}@{{.Digest}}"
65
FROM --platform=linux/${ARCH} mcr.microsoft.com/oss/go/microsoft/golang@sha256:f1f0cbd464ae4cd9d41176d47f1f9fe16a6965425871f817587314e3a04576ec AS go
76

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-
117
FROM go AS azure-ip-masq-merger
128
ARG OS
139
ARG VERSION
1410
WORKDIR /azure-ip-masq-merger
1511
COPY ./azure-ip-masq-merger .
1612
RUN GOOS=$OS CGO_ENABLED=0 go build -a -o /go/bin/ip-masq-merger -trimpath -ldflags "-X main.version="$VERSION"" -gcflags="-dwarflocationlists=true" .
1713

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" ]
14+
FROM scratch AS linux
15+
COPY --from=azure-ip-masq-merger /go/bin/ip-masq-merger azure-ip-masq-merger
16+
ENTRYPOINT [ "/azure-ip-masq-merger" ]

azure-ip-masq-merger/README.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# azure-ip-masq-merger
2+
3+
`azure-ip-masq-merger` is a utility for merging multiple ip-masq-agent configuration files into a single, valid configuration for use in Kubernetes clusters.
4+
5+
## Description
6+
7+
The goal of this program is to periodically scan a directory for configuration fragments (YAML or JSON files starting with `ip-masq`), validate and merge them, and write the resulting configuration to a target directory for consumption. This allows us to combine non-masquerade CIDRs and related options between multiple files, for example if we had one ip masq config managed by the cloud provider and another supplied by the user.
8+
9+
## Usage
10+
11+
Follow the steps below to build and run the program:
12+
13+
1. Build the binary using `make`:
14+
```bash
15+
make azure-ip-masq-merger
16+
```
17+
or make an image:
18+
```bash
19+
make azure-ip-masq-merger-image
20+
```
21+
22+
2. Deploy or copy the binary to your node(s).
23+
24+
3. Prepare your configuration fragments in the input directory (see below for defaults). Each file should be named with the prefix `ip-masq` and contain valid YAML or JSON for the ip-masq-agent config.
25+
26+
4. Start the program with:
27+
```bash
28+
./azure-ip-masq-merger --input=/etc/config/ --output=/etc/merged-config/
29+
```
30+
- The `--input` flag specifies the directory to scan for config fragments. Default: `/etc/config/`
31+
- The `--output` flag specifies where to write the merged config. Default: `/etc/merged-config/`
32+
33+
5. The merged configuration will be written to the output directory as `ip-masq-agent`. If no valid configs are found, any existing merged config will be removed.
34+
35+
## Manual Testing
36+
37+
You can test the merger locally by creating sample config files in your input directory and running the merger.
38+
39+
## Configuration File Format
40+
41+
Each config fragment should be a YAML or JSON file that may have the following fields:
42+
```yaml
43+
nonMasqueradeCIDRs:
44+
- 10.0.0.0/8
45+
- 192.168.0.0/16
46+
masqLinkLocal: true
47+
masqLinkLocalIPv6: false
48+
```
49+
- `nonMasqueradeCIDRs`: List of CIDRs that should not be masqueraded. Appended between configs.
50+
- `masqLinkLocal`: Boolean to enable/disable masquerading of link-local addresses. OR'd between configs.
51+
- `masqLinkLocalIPv6`: Boolean to enable/disable masquerading of IPv6 link-local addresses. OR'd between configs.
52+
53+
## Debugging
54+
55+
Logs are output to standard error. Increase verbosity with the `-v` flag:
56+
```bash
57+
./azure-ip-masq-merger -v 2
58+
```
59+
60+
## Development
61+
62+
To run tests:
63+
```bash
64+
go test ./...
65+
```
66+
or at the repository level:
67+
```bash
68+
make test-azure-ip-masq-merger
69+
```

0 commit comments

Comments
 (0)