Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mount cgroupv2 for cilium at a custom location #12431

Merged
merged 1 commit into from
Sep 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 53 additions & 1 deletion nodeup/pkg/model/networking/cilium.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ limitations under the License.
package networking

import (
"errors"
"fmt"
"os"
"path/filepath"

"golang.org/x/sys/unix"
Expand Down Expand Up @@ -50,7 +52,11 @@ func (b *CiliumBuilder) Build(c *fi.ModelBuilderContext) error {
}

if err := b.buildBPFMount(c); err != nil {
return err
return fmt.Errorf("failed to create bpf mount unit: %w", err)
}

if err := b.buildCgroup2Mount(c); err != nil {
return fmt.Errorf("failed to create cgroupv2 mount unit: %w", err)
}

return nil
Expand Down Expand Up @@ -93,6 +99,52 @@ WantedBy=multi-user.target
Name: "sys-fs-bpf.mount",
Definition: fi.String(unit),
}
service.InitDefaults()
c.AddTask(service)
}

return nil
}

func (b *CiliumBuilder) buildCgroup2Mount(c *fi.ModelBuilderContext) error {

cgroupPath := "/run/cilium/cgroupv2"

var fsdata unix.Statfs_t
err := unix.Statfs(cgroupPath, &fsdata)

// If the path does not exist, systemd will create it
if !errors.Is(err, os.ErrNotExist) {
return fmt.Errorf("error checking for /run/cilium/cgroupv2: %v", err)
}

CGROUP_FS_MAGIC := uint32(0x63677270)

alreadyMounted := uint32(fsdata.Type) == CGROUP_FS_MAGIC

if !alreadyMounted {
unit := `
[Unit]
Description=Cilium Cgroup2 mounts
Documentation=http://docs.cilium.io/
DefaultDependencies=no
Before=local-fs.target umount.target kubelet.service

[Mount]
What=cgroup2
Where=/run/cilium/cgroupv2
Type=cgroup2

[Install]
WantedBy=multi-user.target
`

service := &nodetasks.Service{
Name: "run-cilium-cgroupv2.mount",
Definition: fi.String(unit),
SmartRestart: fi.Bool(false),
}
service.InitDefaults()
c.AddTask(service)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ spec:
k8s-addon: storage-aws.addons.k8s.io
- id: k8s-1.16
manifest: networking.cilium.io/k8s-1.16-v1.10.yaml
manifestHash: 79105657d58e949d8612de05cf98900e30b0e7fb5c6e2c06a7c35692c91f302e
manifestHash: 1703cd96b5c8d24e70cc30e81b011e9f6392a2df4e3a714bccb03b0a9a824f0e
name: networking.cilium.io
needsRollingUpdate: all
selector:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ data:
bpf-nat-global-max: "524288"
bpf-neigh-global-max: "524288"
bpf-policy-map-max: "16384"
cgroup-root: /sys/fs/cgroup/unified
cgroup-root: /run/cilium/cgroupv2
cluster-name: default
container-runtime: none
debug: "false"
Expand Down Expand Up @@ -494,7 +494,7 @@ spec:
volumeMounts:
- mountPath: /sys/fs/bpf
name: bpf-maps
- mountPath: /sys/fs/cgroup/unified
- mountPath: /run/cilium/cgroupv2
mountPropagation: HostToContainer
name: cilium-cgroup
- mountPath: /var/run/cilium
Expand All @@ -520,8 +520,8 @@ spec:
type: DirectoryOrCreate
name: cni-path
- hostPath:
path: /sys/fs/cgroup/unified
type: DirectoryOrCreate
path: /run/cilium/cgroupv2
type: Directory
name: cilium-cgroup
- hostPath:
path: /etc/cni/net.d
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ spec:
k8s-addon: storage-aws.addons.k8s.io
- id: k8s-1.16
manifest: networking.cilium.io/k8s-1.16-v1.10.yaml
manifestHash: 39ec0f473a3c9479e15718e23b965dd5670502132723c7d2d9377f6b800be453
manifestHash: 96198c21b885265a89a7374b685d06154fe36741c890b38f932a759073bdc82f
name: networking.cilium.io
needsRollingUpdate: all
selector:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ data:
bpf-nat-global-max: "524288"
bpf-neigh-global-max: "524288"
bpf-policy-map-max: "16384"
cgroup-root: /sys/fs/cgroup/unified
cgroup-root: /run/cilium/cgroupv2
cluster-name: default
container-runtime: none
debug: "false"
Expand Down Expand Up @@ -494,7 +494,7 @@ spec:
volumeMounts:
- mountPath: /sys/fs/bpf
name: bpf-maps
- mountPath: /sys/fs/cgroup/unified
- mountPath: /run/cilium/cgroupv2
mountPropagation: HostToContainer
name: cilium-cgroup
- mountPath: /var/run/cilium
Expand All @@ -520,8 +520,8 @@ spec:
type: DirectoryOrCreate
name: cni-path
- hostPath:
path: /sys/fs/cgroup/unified
type: DirectoryOrCreate
path: /run/cilium/cgroupv2
type: Directory
name: cilium-cgroup
- hostPath:
path: /etc/cni/net.d
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ spec:
k8s-addon: storage-aws.addons.k8s.io
- id: k8s-1.16
manifest: networking.cilium.io/k8s-1.16-v1.10.yaml
manifestHash: 6fb92a78a0b2be6a6a21dd312e41be98245f64ad104add14d900de041e41ce41
manifestHash: b0d700920b53b105c93ca2d6bd1c9ca5fcdab045f8e5b4d88f4893be71752c55
name: networking.cilium.io
needsRollingUpdate: all
selector:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ data:
bpf-nat-global-max: "524288"
bpf-neigh-global-max: "524288"
bpf-policy-map-max: "16384"
cgroup-root: /sys/fs/cgroup/unified
cgroup-root: /run/cilium/cgroupv2
cluster-name: default
container-runtime: none
debug: "false"
Expand Down Expand Up @@ -514,7 +514,7 @@ spec:
volumeMounts:
- mountPath: /sys/fs/bpf
name: bpf-maps
- mountPath: /sys/fs/cgroup/unified
- mountPath: /run/cilium/cgroupv2
mountPropagation: HostToContainer
name: cilium-cgroup
- mountPath: /var/run/cilium
Expand All @@ -540,8 +540,8 @@ spec:
type: DirectoryOrCreate
name: cni-path
- hostPath:
path: /sys/fs/cgroup/unified
type: DirectoryOrCreate
path: /run/cilium/cgroupv2
type: Directory
name: cilium-cgroup
- hostPath:
path: /etc/cni/net.d
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ data:
# enable-l7-proxy enables L7 proxy for L7 policy enforcement. (default true)
enable-l7-proxy: "{{ .EnableL7Proxy }}"

cgroup-root: /sys/fs/cgroup/unified
cgroup-root: /run/cilium/cgroupv2

{{ if WithDefaultBool .Hubble.Enabled false }}
# Enable Hubble gRPC service.
Expand Down Expand Up @@ -761,7 +761,7 @@ spec:
name: bpf-maps
mountPropagation: HostToContainer
# Required to mount cgroup filesystem from the host to cilium agent pod
- mountPath: /sys/fs/cgroup/unified
- mountPath: /run/cilium/cgroupv2
name: cilium-cgroup
mountPropagation: HostToContainer
- mountPath: /var/run/cilium
Expand Down Expand Up @@ -797,8 +797,8 @@ spec:
name: cni-path
# To keep state between restarts / upgrades for cgroup2 filesystem
- hostPath:
path: /sys/fs/cgroup/unified
type: DirectoryOrCreate
path: /run/cilium/cgroupv2
type: Directory
name: cilium-cgroup
# To install cilium cni configuration in the host
- hostPath:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ data:
# enable-l7-proxy enables L7 proxy for L7 policy enforcement. (default true)
enable-l7-proxy: "{{ .EnableL7Proxy }}"

cgroup-root: /sys/fs/cgroup/unified
cgroup-root: /run/cilium/cgroupv2

{{ if WithDefaultBool .Hubble.Enabled false }}
# Enable Hubble gRPC service.
Expand Down Expand Up @@ -798,7 +798,7 @@ spec:
mountPropagation: HostToContainer
{{- end }}
# Required to mount cgroup filesystem from the host to cilium agent pod
- mountPath: /sys/fs/cgroup/unified
- mountPath: /run/cilium/cgroupv2
name: cilium-cgroup
mountPropagation: HostToContainer
- mountPath: /var/run/cilium
Expand Down Expand Up @@ -834,8 +834,8 @@ spec:
name: cni-path
# To keep state between restarts / upgrades for cgroup2 filesystem
- hostPath:
path: /sys/fs/cgroup/unified
type: DirectoryOrCreate
path: /run/cilium/cgroupv2
type: Directory
name: cilium-cgroup
# To install cilium cni configuration in the host
- hostPath:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ spec:
k8s-addon: storage-aws.addons.k8s.io
- id: k8s-1.16
manifest: networking.cilium.io/k8s-1.16-v1.10.yaml
manifestHash: 2aa3ec34168ba0988b888912ecfe9fdc653b3caef70ea5a504aa77f662006a7e
manifestHash: a8676c7ed851ffa9059350f44530cc6a89e79abf6e2395a0655c9ec950e543e2
name: networking.cilium.io
needsRollingUpdate: all
selector:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ spec:
k8s-addon: storage-aws.addons.k8s.io
- id: k8s-1.16
manifest: networking.cilium.io/k8s-1.16-v1.10.yaml
manifestHash: 2aa3ec34168ba0988b888912ecfe9fdc653b3caef70ea5a504aa77f662006a7e
manifestHash: a8676c7ed851ffa9059350f44530cc6a89e79abf6e2395a0655c9ec950e543e2
name: networking.cilium.io
needsRollingUpdate: all
selector:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ spec:
k8s-addon: storage-aws.addons.k8s.io
- id: k8s-1.16
manifest: networking.cilium.io/k8s-1.16-v1.10.yaml
manifestHash: 2aa3ec34168ba0988b888912ecfe9fdc653b3caef70ea5a504aa77f662006a7e
manifestHash: a8676c7ed851ffa9059350f44530cc6a89e79abf6e2395a0655c9ec950e543e2
name: networking.cilium.io
needsRollingUpdate: all
selector:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ spec:
k8s-addon: storage-aws.addons.k8s.io
- id: k8s-1.16
manifest: networking.cilium.io/k8s-1.16-v1.10.yaml
manifestHash: 2aa3ec34168ba0988b888912ecfe9fdc653b3caef70ea5a504aa77f662006a7e
manifestHash: a8676c7ed851ffa9059350f44530cc6a89e79abf6e2395a0655c9ec950e543e2
name: networking.cilium.io
needsRollingUpdate: all
selector:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ spec:
k8s-addon: storage-aws.addons.k8s.io
- id: k8s-1.16
manifest: networking.cilium.io/k8s-1.16-v1.10.yaml
manifestHash: 2aa3ec34168ba0988b888912ecfe9fdc653b3caef70ea5a504aa77f662006a7e
manifestHash: a8676c7ed851ffa9059350f44530cc6a89e79abf6e2395a0655c9ec950e543e2
name: networking.cilium.io
needsRollingUpdate: all
selector:
Expand Down