Skip to content

Commit 61a1c94

Browse files
committed
feat: bundle (some) CNI plugins with Talos core
Fixes siderolabs/extensions#448 Bundle some CNI standard plugins plus Flannel CNI plugin (as Flannel is the default CNI in Talos) in the Talos `initramfs`. With this change, no plugin install is required, so the `install-cni` step is dropped from the Flannel default manifest. The bundled plugins: ``` $ talosctl -n 172.20.0.2 ls -lH /opt/cni/bin/ NODE MODE UID GID SIZE(B) LASTMOD NAME 172.20.0.2 drwxr-xr-x 0 0 109 B 7 hours ago . 172.20.0.2 -rwxr-xr-x 0 0 3.2 MB 7 hours ago bridge 172.20.0.2 -rwxr-xr-x 0 0 3.3 MB 7 hours ago firewall 172.20.0.2 -rwxr-xr-x 0 0 2.4 MB 7 hours ago flannel 172.20.0.2 -rwxr-xr-x 0 0 2.4 MB 7 hours ago host-local 172.20.0.2 -rwxr-xr-x 0 0 2.4 MB 7 hours ago loopback 172.20.0.2 -rwxr-xr-x 0 0 2.8 MB 7 hours ago portmap ``` The `initramfs` for amd64 grows 67 -> 73 MiB with this change. The path `/opt/cni/bin` is still an overlay mount, so extra plugins can be dropped to this directory (no change here). Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
1 parent 091da16 commit 61a1c94

File tree

17 files changed

+402
-437
lines changed

17 files changed

+402
-437
lines changed

Dockerfile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ ARG PKG_APPARMOR
3434
ARG PKG_UTIL_LINUX
3535
ARG PKG_KMOD
3636
ARG PKG_KERNEL
37+
ARG PKG_CNI
38+
ARG PKG_FLANNEL_CNI
3739
ARG PKG_TALOSCTL_CNI_BUNDLE_INSTALL
3840

3941
# Resolve package images using ${PKGS} to be used later in COPY --from=.
@@ -112,10 +114,32 @@ FROM --platform=arm64 ${PKG_UTIL_LINUX} AS pkg-util-linux-arm64
112114
FROM --platform=amd64 ${PKG_KMOD} AS pkg-kmod-amd64
113115
FROM --platform=arm64 ${PKG_KMOD} AS pkg-kmod-arm64
114116

117+
FROM --platform=amd64 ${PKG_CNI} AS pkg-cni-amd64
118+
FROM --platform=arm64 ${PKG_CNI} AS pkg-cni-arm64
119+
120+
FROM --platform=amd64 ${PKG_FLANNEL_CNI} AS pkg-flannel-cni-amd64
121+
FROM --platform=arm64 ${PKG_FLANNEL_CNI} AS pkg-flannel-cni-arm64
122+
115123
FROM ${PKG_KERNEL} AS pkg-kernel
116124
FROM --platform=amd64 ${PKG_KERNEL} AS pkg-kernel-amd64
117125
FROM --platform=arm64 ${PKG_KERNEL} AS pkg-kernel-arm64
118126

127+
# Strip CNI package.
128+
129+
FROM scratch AS pkg-cni-stripped-amd64
130+
COPY --from=pkg-cni-amd64 /opt/cni/bin/bridge /opt/cni/bin/bridge
131+
COPY --from=pkg-cni-amd64 /opt/cni/bin/firewall /opt/cni/bin/firewall
132+
COPY --from=pkg-cni-amd64 /opt/cni/bin/host-local /opt/cni/bin/host-local
133+
COPY --from=pkg-cni-amd64 /opt/cni/bin/loopback /opt/cni/bin/loopback
134+
COPY --from=pkg-cni-amd64 /opt/cni/bin/portmap /opt/cni/bin/portmap
135+
136+
FROM scratch AS pkg-cni-stripped-arm64
137+
COPY --from=pkg-cni-arm64 /opt/cni/bin/bridge /opt/cni/bin/bridge
138+
COPY --from=pkg-cni-arm64 /opt/cni/bin/firewall /opt/cni/bin/firewall
139+
COPY --from=pkg-cni-arm64 /opt/cni/bin/host-local /opt/cni/bin/host-local
140+
COPY --from=pkg-cni-arm64 /opt/cni/bin/loopback /opt/cni/bin/loopback
141+
COPY --from=pkg-cni-arm64 /opt/cni/bin/portmap /opt/cni/bin/portmap
142+
119143
# Resolve package images using ${EXTRAS} to be used later in COPY --from=.
120144

121145
FROM ${PKG_TALOSCTL_CNI_BUNDLE_INSTALL} AS extras-talosctl-cni-bundle-install
@@ -578,6 +602,8 @@ COPY --from=depmod-arm64 /build/lib/modules /lib/modules
578602
FROM build AS rootfs-base-amd64
579603
COPY --link --from=pkg-fhs / /rootfs
580604
COPY --link --from=pkg-apparmor-amd64 / /rootfs
605+
COPY --link --from=pkg-cni-stripped-amd64 / /rootfs
606+
COPY --link --from=pkg-flannel-cni-amd64 / /rootfs
581607
COPY --link --from=pkg-cryptsetup-amd64 / /rootfs
582608
COPY --link --from=pkg-containerd-amd64 / /rootfs
583609
COPY --link --from=pkg-dosfstools-amd64 / /rootfs
@@ -642,6 +668,8 @@ END
642668
FROM build AS rootfs-base-arm64
643669
COPY --link --from=pkg-fhs / /rootfs
644670
COPY --link --from=pkg-apparmor-arm64 / /rootfs
671+
COPY --link --from=pkg-cni-stripped-arm64 / /rootfs
672+
COPY --link --from=pkg-flannel-cni-arm64 / /rootfs
645673
COPY --link --from=pkg-cryptsetup-arm64 / /rootfs
646674
COPY --link --from=pkg-containerd-arm64 / /rootfs
647675
COPY --link --from=pkg-dosfstools-arm64 / /rootfs

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ ARTIFACTS := _out
2020
TOOLS ?= ghcr.io/siderolabs/tools:v1.8.0-alpha.0-8-ga764e8d
2121

2222
PKGS_PREFIX ?= ghcr.io/siderolabs
23-
PKGS ?= v1.8.0-alpha.0-46-g124d35b
23+
PKGS ?= v1.8.0-alpha.0-49-g5f919c5
2424
EXTRAS ?= v1.8.0-alpha.0-5-g6f4a373
2525

2626
KRES_IMAGE ?= ghcr.io/siderolabs/kres:latest
@@ -51,6 +51,8 @@ PKG_RUNC ?= $(PKGS_PREFIX)/runc:$(PKGS)
5151
PKG_XFSPROGS ?= $(PKGS_PREFIX)/xfsprogs:$(PKGS)
5252
PKG_UTIL_LINUX ?= $(PKGS_PREFIX)/util-linux:$(PKGS)
5353
PKG_KMOD ?= $(PKGS_PREFIX)/kmod:$(PKGS)
54+
PKG_CNI ?= $(PKGS_PREFIX)/cni:$(PKGS)
55+
PKG_FLANNEL_CNI ?= $(PKGS_PREFIX)/flannel-cni:$(PKGS)
5456
PKG_KERNEL ?= $(PKGS_PREFIX)/kernel:$(PKGS)
5557
PKG_TALOSCTL_CNI_BUNDLE_INSTALL ?= $(PKGS_PREFIX)/talosctl-cni-bundle-install:$(EXTRAS)
5658

@@ -208,6 +210,8 @@ COMMON_ARGS += --build-arg=PKG_UTIL_LINUX=$(PKG_UTIL_LINUX)
208210
COMMON_ARGS += --build-arg=PKG_KMOD=$(PKG_KMOD)
209211
COMMON_ARGS += --build-arg=PKG_U_BOOT=$(PKG_U_BOOT)
210212
COMMON_ARGS += --build-arg=PKG_RASPBERYPI_FIRMWARE=$(PKG_RASPBERYPI_FIRMWARE)
213+
COMMON_ARGS += --build-arg=PKG_CNI=$(PKG_CNI)
214+
COMMON_ARGS += --build-arg=PKG_FLANNEL_CNI=$(PKG_FLANNEL_CNI)
211215
COMMON_ARGS += --build-arg=PKG_KERNEL=$(PKG_KERNEL)
212216
COMMON_ARGS += --build-arg=PKG_TALOSCTL_CNI_BUNDLE_INSTALL=$(PKG_TALOSCTL_CNI_BUNDLE_INSTALL)
213217
COMMON_ARGS += --build-arg=ABBREV_TAG=$(ABBREV_TAG)

api/api.descriptors

22 Bytes
Binary file not shown.

api/resource/definitions/k8s/k8s.proto

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ message BootstrapManifestsConfigSpec {
5454
string dns_service_i_pv6 = 10;
5555
bool flannel_enabled = 11;
5656
string flannel_image = 12;
57-
string flannel_cni_image = 13;
5857
bool pod_security_policy_enabled = 14;
5958
bool talos_api_service_enabled = 15;
6059
repeated string flannel_extra_args = 16;

cmd/talosctl/cmd/talos/image.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ var imageDefaultCmd = &cobra.Command{
135135
}))
136136

137137
fmt.Printf("%s\n", images.Flannel)
138-
fmt.Printf("%s\n", images.FlannelCNI)
139138
fmt.Printf("%s\n", images.CoreDNS)
140139
fmt.Printf("%s\n", images.Etcd)
141140
fmt.Printf("%s\n", images.KubeAPIServer)

hack/release.toml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ preface = """\
1919
title = "Component Updates"
2020
description = """\
2121
Kubernetes: 1.31.0-rc.1
22-
Linux: 6.6.44
22+
Linux: 6.6.45
2323
containerd: 2.0.0-rc.3
2424
runc: 1.2.0-rc.2
2525
etcd: 3.5.15
@@ -157,6 +157,21 @@ default tag would point to slim image:
157157
158158
* `v1.x.y` (default, slim)
159159
* `v1.x.y-fat` (fat)
160+
"""
161+
162+
[notes.cni]
163+
title = "CNI Plugins"
164+
description = """\
165+
Talos Linux now bundles by default the following standard CNI plugins:
166+
167+
* `bridge`
168+
* `firewall`
169+
* `flannel`
170+
* `host-local`
171+
* `loopback`
172+
* `portmap`
173+
174+
The Talos bundled Flannel manifest was simplified to remove the `install-cni` step.
160175
"""
161176

162177
[make_deps]

internal/app/machined/pkg/controllers/k8s/control_plane.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,6 @@ func NewControlPlaneBootstrapManifestsController() *ControlPlaneBootstrapManifes
292292

293293
FlannelEnabled: cfgProvider.Cluster().Network().CNI().Name() == constants.FlannelCNI,
294294
FlannelImage: images.Flannel,
295-
FlannelCNIImage: images.FlannelCNI,
296295
FlannelExtraArgs: cfgProvider.Cluster().Network().CNI().Flannel().ExtraArgs(),
297296
FlannelKubeServiceHost: flannelKubeServiceHost,
298297
FlannelKubeServicePort: flannelKubeServicePort,

internal/app/machined/pkg/controllers/k8s/manifest_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,8 @@ var defaultManifestSpec = k8s.BootstrapManifestsConfigSpec{
108108

109109
DNSServiceIP: "192.168.0.1",
110110

111-
FlannelEnabled: true,
112-
FlannelImage: "foo/bar",
113-
FlannelCNIImage: "foo/bar",
111+
FlannelEnabled: true,
112+
FlannelImage: "foo/bar",
114113

115114
PodSecurityPolicyEnabled: true,
116115
}

pkg/flannel/gen.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -221,17 +221,6 @@ var Template = []byte(`+"`", url)
221221
},
222222
},
223223
},
224-
{
225-
Name: "install-cni",
226-
Image: "{{ .FlannelCNIImage }}",
227-
Command: []string{"/install-cni.sh"},
228-
VolumeMounts: []corev1.VolumeMount{
229-
{
230-
Name: "cni-plugin",
231-
MountPath: "/host/opt/cni/bin/",
232-
},
233-
},
234-
},
235224
}
236225

237226
marshal(out, obj)

pkg/flannel/template.go

Lines changed: 0 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/images/list.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@ import (
99

1010
"github.com/siderolabs/talos/pkg/machinery/config"
1111
"github.com/siderolabs/talos/pkg/machinery/constants"
12-
"github.com/siderolabs/talos/pkg/machinery/version"
1312
)
1413

1514
// Versions holds all the images (and their versions) that are used in Talos.
1615
type Versions struct {
17-
Etcd string
18-
Flannel string
19-
FlannelCNI string
20-
CoreDNS string
16+
Etcd string
17+
Flannel string
18+
CoreDNS string
2119

2220
Kubelet string
2321
KubeAPIServer string
@@ -42,7 +40,6 @@ func List(config config.Config) Versions {
4240
images.Etcd = config.Cluster().Etcd().Image()
4341
images.CoreDNS = config.Cluster().CoreDNS().Image()
4442
images.Flannel = fmt.Sprintf("ghcr.io/siderolabs/flannel:%s", constants.FlannelVersion) // mirrored from docker.io/flannelcni/flannel
45-
images.FlannelCNI = fmt.Sprintf("ghcr.io/siderolabs/install-cni:%s", version.ExtrasVersion)
4643
images.Kubelet = config.Machine().Kubelet().Image()
4744
images.KubeAPIServer = config.Cluster().APIServer().Image()
4845
images.KubeControllerManager = config.Cluster().ControllerManager().Image()

0 commit comments

Comments
 (0)