Skip to content

Commit f073927

Browse files
Merge pull request #7 from killianmuldoon/pr-add-utils
These components are mirrored from their original place at github.com/nvidia/doca-platform: ipallocator: https://github.com/NVIDIA/doca-platform/tree/public-release-v25.7/cmd/ipallocator cniprovisioner: https://github.com/NVIDIA/doca-platform/tree/public-release-v25.7/cmd/dpucniprovisioner ovnkuberneteswebhookinjector: https://github.com/NVIDIA/doca-platform/tree/public-release-v25.7/cmd/ovnkubernetesresourceinjector
2 parents 6ba9df2 + 304685b commit f073927

File tree

23 files changed

+4734
-6
lines changed

23 files changed

+4734
-6
lines changed

.github/workflows/build-images.yaml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ env:
1515
REGISTRY: ghcr.io
1616
IMAGE_NAME_UBUNTU: ghcr.io/mellanox/ovn-kubernetes-dpf
1717
IMAGE_NAME_FEDORA: ghcr.io/mellanox/ovn-kubernetes-dpf-fedora
18+
IMAGE_NAME_DPF_UTILS: ghcr.io/mellanox/ovn-kubernetes-dpf-utils
1819

1920
jobs:
2021
build-ubuntu:
@@ -135,3 +136,61 @@ jobs:
135136
cache-to: type=gha,mode=max
136137
provenance: false
137138

139+
build-dpf-utils:
140+
runs-on: ubuntu-latest
141+
permissions:
142+
contents: read
143+
packages: write
144+
145+
steps:
146+
- name: Checkout repository
147+
uses: actions/checkout@v4
148+
with:
149+
submodules: recursive
150+
fetch-depth: 0
151+
152+
- name: Determine tag
153+
id: tag
154+
run: |
155+
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
156+
TAG=${GITHUB_REF#refs/tags/}
157+
else
158+
TAG=v25.7.1-${GITHUB_SHA::7}
159+
fi
160+
echo "tag=${TAG}" >> $GITHUB_OUTPUT
161+
162+
- name: Set up QEMU
163+
uses: docker/setup-qemu-action@v3
164+
165+
- name: Set up Docker Buildx
166+
uses: docker/setup-buildx-action@v3
167+
168+
- name: Log in to Container Registry
169+
if: github.event_name != 'pull_request'
170+
uses: docker/login-action@v3
171+
with:
172+
registry: ${{ env.REGISTRY }}
173+
username: ${{ github.actor }}
174+
password: ${{ secrets.GITHUB_TOKEN }}
175+
176+
- name: Extract metadata (labels only)
177+
id: meta
178+
uses: docker/metadata-action@v5
179+
with:
180+
images: ${{ env.IMAGE_NAME_DPF_UTILS }}
181+
182+
- name: Build and push DPF Utils image
183+
uses: docker/build-push-action@v5
184+
with:
185+
context: ./dpf-utils
186+
file: ./dpf-utils/Dockerfile
187+
platforms: linux/amd64,linux/arm64
188+
push: ${{ github.event_name != 'pull_request' }}
189+
tags: ${{ env.IMAGE_NAME_DPF_UTILS }}:${{ steps.tag.outputs.tag }}
190+
labels: ${{ steps.meta.outputs.labels }}
191+
build-args: |
192+
builder_image=quay.io/projectquay/golang:1.24
193+
cache-from: type=gha
194+
cache-to: type=gha,mode=max
195+
provenance: false
196+
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Test and Lint DPF Utils
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'dpf-utils/**'
9+
- '.github/workflows/test-dpf-utils.yaml'
10+
pull_request:
11+
branches:
12+
- main
13+
paths:
14+
- 'dpf-utils/**'
15+
- '.github/workflows/test-dpf-utils.yaml'
16+
17+
jobs:
18+
test:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v4
23+
24+
- name: Set up Go
25+
uses: actions/setup-go@v5
26+
with:
27+
go-version: '1.24'
28+
29+
- name: Run tests
30+
run: make test
31+
32+
lint:
33+
runs-on: ubuntu-latest
34+
steps:
35+
- name: Checkout repository
36+
uses: actions/checkout@v4
37+
38+
- name: Set up Go
39+
uses: actions/setup-go@v5
40+
with:
41+
go-version: '1.24'
42+
43+
- name: Run linter
44+
run: make lint
45+

Makefile

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ help: ## Display this help.
3636

3737
REGISTRY ?= example.com
3838
OVNKUBERNETES_IMAGE ?= $(REGISTRY)/ovn-kubernetes-dpf
39+
DPF_UTILS_IMAGE ?= $(REGISTRY)/ovn-kubernetes-dpf-utils
3940

4041
.PHONY: docker-build-ubuntu
4142
docker-build-ubuntu:
@@ -55,6 +56,15 @@ docker-build-fedora:
5556
--load \
5657
-f Dockerfile.ovn-kubernetes.fedora .
5758

59+
.PHONY: docker-build-dpf-utils
60+
docker-build-dpf-utils: ## Build DPF utilities image
61+
docker buildx build \
62+
--build-arg builder_image=${GO_IMAGE} \
63+
-t $(DPF_UTILS_IMAGE):$(TAG) \
64+
--load \
65+
-f dpf-utils/Dockerfile \
66+
dpf-utils/
67+
5868
.PHONY: docker-push-ubuntu
5969
docker-push-ubuntu: ## Push Ubuntu image to registry
6070
docker push $(OVNKUBERNETES_IMAGE):$(TAG)
@@ -63,6 +73,22 @@ docker-push-ubuntu: ## Push Ubuntu image to registry
6373
docker-push-fedora: ## Push Fedora image to registry
6474
docker push $(OVNKUBERNETES_IMAGE):$(TAG)-fedora
6575

76+
.PHONY: docker-push-dpf-utils
77+
docker-push-dpf-utils: ## Push DPF utilities image to registry
78+
docker push $(DPF_UTILS_IMAGE):$(TAG)
79+
80+
##@ DPF Utils Targets
81+
82+
DPF_UTILS_DIR = dpf-utils
83+
84+
.PHONY: lint
85+
lint: golangci-lint ## Run linter for DPF utilities
86+
cd $(DPF_UTILS_DIR) && $(GOLANGCI_LINT) run --timeout=5m ./...
87+
88+
.PHONY: test
89+
test: ## Run tests for DPF utilities
90+
cd $(DPF_UTILS_DIR) && go test -v -coverprofile=coverage.out -covermode=atomic ./...
91+
6692
##@ Helm Chart Targets
6793

6894
HELM_CHART_DIR ?= helm/ovn-kubernetes-dpf
@@ -72,15 +98,15 @@ HELM_OUTPUT_DIR ?= _output/helm
7298
helm-build: yq
7399
@mkdir -p $(HELM_OUTPUT_DIR)
74100
@cp $(HELM_CHART_DIR)/values.yaml.tmpl $(HELM_CHART_DIR)/values.yaml
75-
@$(YQ) eval -i '.ovn-kubernetes-resource-injector.controllerManager.webhook.image.repository = "$(OVNKUBERNETES_IMAGE)"' $(HELM_CHART_DIR)/values.yaml
101+
@$(YQ) eval -i '.ovn-kubernetes-resource-injector.controllerManager.webhook.image.repository = "$(DPF_UTILS_IMAGE)"' $(HELM_CHART_DIR)/values.yaml
76102
@$(YQ) eval -i '.ovn-kubernetes-resource-injector.controllerManager.webhook.image.tag = "$(TAG)"' $(HELM_CHART_DIR)/values.yaml
77103
@$(YQ) eval -i '.nodeWithDPUManifests.image.repository = "$(OVNKUBERNETES_IMAGE)"' $(HELM_CHART_DIR)/values.yaml
78104
@$(YQ) eval -i '.nodeWithDPUManifests.image.tag = "$(TAG)"' $(HELM_CHART_DIR)/values.yaml
79105
@$(YQ) eval -i '.nodeWithoutDPUManifests.image.repository = "$(OVNKUBERNETES_IMAGE)"' $(HELM_CHART_DIR)/values.yaml
80106
@$(YQ) eval -i '.nodeWithoutDPUManifests.image.tag = "$(TAG)"' $(HELM_CHART_DIR)/values.yaml
81107
@$(YQ) eval -i '.dpuManifests.image.repository = "$(OVNKUBERNETES_IMAGE)"' $(HELM_CHART_DIR)/values.yaml
82108
@$(YQ) eval -i '.dpuManifests.image.tag = "$(TAG)"' $(HELM_CHART_DIR)/values.yaml
83-
@$(YQ) eval -i '.dpuManifests.imagedpf.repository = "$(OVNKUBERNETES_IMAGE)"' $(HELM_CHART_DIR)/values.yaml
109+
@$(YQ) eval -i '.dpuManifests.imagedpf.repository = "$(DPF_UTILS_IMAGE)"' $(HELM_CHART_DIR)/values.yaml
84110
@$(YQ) eval -i '.dpuManifests.imagedpf.tag = "$(TAG)"' $(HELM_CHART_DIR)/values.yaml
85111
@$(YQ) eval -i '.controlPlaneManifests.image.repository = "$(OVNKUBERNETES_IMAGE)"' $(HELM_CHART_DIR)/values.yaml
86112
@$(YQ) eval -i '.controlPlaneManifests.image.tag = "$(TAG)"' $(HELM_CHART_DIR)/values.yaml
@@ -103,6 +129,8 @@ helm-clean:
103129
TOOLSDIR ?= $(CURDIR)/hack/tools/bin
104130
YQ_VERSION ?= v4.45.1
105131
export YQ ?= $(TOOLSDIR)/yq-$(YQ_VERSION)
132+
GOLANGCI_LINT_VERSION ?= v1.62.2
133+
export GOLANGCI_LINT ?= $(TOOLSDIR)/golangci-lint-$(GOLANGCI_LINT_VERSION)
106134

107135
define go-install-tool
108136
@[ -f $(1) ] || { \
@@ -120,4 +148,9 @@ $(TOOLSDIR):
120148
.PHONY: yq
121149
yq: $(YQ) ## Download yq locally if necessary
122150
$(YQ): | $(TOOLSDIR)
123-
$(call go-install-tool,$(YQ),github.com/mikefarah/yq/v4,$(YQ_VERSION))
151+
$(call go-install-tool,$(YQ),github.com/mikefarah/yq/v4,$(YQ_VERSION))
152+
153+
.PHONY: golangci-lint
154+
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary
155+
$(GOLANGCI_LINT): | $(TOOLSDIR)
156+
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))

dpf-utils/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/ovnkubernetesresourceinjector
2+
/ipallocator
3+
/dpucniprovisioner

dpf-utils/Dockerfile

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
ARG builder_image
2+
3+
FROM --platform=${BUILDPLATFORM} ${builder_image} AS builder
4+
5+
ARG TARGETARCH
6+
ARG gcflags
7+
ARG ldflags
8+
9+
WORKDIR /workspace
10+
11+
ARG ipallocator_dir
12+
COPY ./ ./
13+
COPY go.mod go.mod
14+
COPY go.sum go.sum
15+
16+
RUN --mount=type=cache,target=/go/pkg/mod \
17+
go mod download
18+
19+
RUN --mount=type=cache,target=/root/.cache/go-build \
20+
--mount=type=cache,target=/go/pkg/mod \
21+
CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
22+
go build -trimpath \
23+
-ldflags="${ldflags}" \
24+
-gcflags="${gcflags}" \
25+
-o ipallocator ./cmd/ipallocator
26+
27+
RUN --mount=type=cache,target=/root/.cache/go-build \
28+
--mount=type=cache,target=/go/pkg/mod \
29+
CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
30+
go build -trimpath \
31+
-ldflags="${ldflags}" \
32+
-gcflags="${gcflags}" \
33+
-o dpucniprovisioner ./cmd/dpucniprovisioner
34+
35+
RUN --mount=type=cache,target=/root/.cache/go-build \
36+
--mount=type=cache,target=/go/pkg/mod \
37+
CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
38+
go build -trimpath \
39+
-ldflags="${ldflags}" \
40+
-gcflags="${gcflags}" \
41+
-o ovnkubernetesresourceinjector ./cmd/ovnkubernetesresourceinjector
42+
43+
# Create source code archive excluding .gocache, and test files.
44+
# Skipping `.gocache` since it contains pre-compiled versions of packages and other build artifacts for speeding up subsequent builds
45+
RUN mkdir src && \
46+
find . -name '*.go' \
47+
-not -path "./hack/*" \
48+
-not -path "./.gocache/*" \
49+
-not -name "*_test.go" \
50+
-exec cp --parents {} src/ \; && \
51+
tar -czf source-code.tar.gz src
52+
53+
# Build the final image
54+
FROM nvcr.io/nvidia/doca/canonical:ubuntu24.04
55+
56+
ARG TARGETARCH
57+
58+
USER root
59+
60+
ARG ubuntu_mirror=http://archive.ubuntu.com/ubuntu/
61+
62+
# Dependencies for installing OVN (Netplan, systemd and udev required by dpucniprovisioner).
63+
ARG PACKAGES="openvswitch-switch netplan.io udev systemd dnsmasq"
64+
65+
RUN dpkg -l | awk '/^ii/{print $2"="$3}' | sort > /initial-dpkg-list.txt
66+
67+
RUN find /etc/apt/sources.list* -type f -exec sed -i \
68+
-e "s|http://archive.ubuntu.com/ubuntu/|${ubuntu_mirror}|g" \
69+
-e "s|http://security.ubuntu.com/ubuntu/|${ubuntu_mirror}|g" '{}' \;
70+
71+
RUN apt-get update && \
72+
apt-get install -y --no-install-recommends ${PACKAGES} && \
73+
apt-get clean && \
74+
rm -rf /var/lib/apt/lists/*
75+
76+
RUN dpkg -l | awk '/^ii/{print $2"="$3}' | sort > /after-ovn-dpkg-list.txt
77+
78+
RUN mkdir -p /var/run/openvswitch
79+
80+
RUN mkdir -p /usr/libexec/cni/
81+
COPY --from=builder /workspace/ipallocator /ipallocator
82+
COPY --from=builder /workspace/dpucniprovisioner /cniprovisioner
83+
COPY --from=builder /workspace/ovnkubernetesresourceinjector /ovnkubernetesresourceinjector
84+
85+
# Get all the source code
86+
RUN mkdir -p /src
87+
WORKDIR /src
88+
89+
# Copy source code from builder stage
90+
COPY --from=builder /workspace/source-code.tar.gz ovn-kubernetes-source-code.tar.gz
91+
92+
# Download source code for apt packages.
93+
# Starting from Ubuntu 24.04 shifted to the new deb822 format for source management.
94+
# Enable `deb-src` to be able to fetch sources using `apt-get source`
95+
ARG PACKAGE_SOURCES
96+
RUN test "${PACKAGE_SOURCES}" = "false" || ( \
97+
sed -i 's/^# deb-src/deb-src/g' /etc/apt/sources.list /etc/apt/sources.list.d/* && \
98+
sed -i 's/^Types: deb$/Types: deb deb-src/g' /etc/apt/sources.list.d/*.sources && \
99+
apt-get update && \
100+
apt-get source --download-only ${PACKAGES} && \
101+
comm -23 /after-ovn-dpkg-list.txt /initial-dpkg-list.txt | xargs -r apt-get source --download-only && \
102+
apt-get clean && \
103+
rm -f /initial-dpkg-list.txt /after-ovn-dpkg-list.txt && \
104+
rm -rf /var/lib/apt/lists/* && \
105+
cd / && \
106+
tar -cf source-code.tar /src && \
107+
rm -rf /src \
108+
)
109+
110+
LABEL io.k8s.display-name="ovn-kubernetes dpf utilities" \
111+
io.k8s.description="ovn-kubernetes dpf utilities ubuntu image"
112+
113+
WORKDIR /root

0 commit comments

Comments
 (0)