Skip to content

Commit e8d3d0d

Browse files
Update to latests usernetes
1 parent 22edbaf commit e8d3d0d

File tree

4 files changed

+163
-107
lines changed

4 files changed

+163
-107
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use at your own risk.
1111

1212
## Install
1313

14-
- On a fedora-30 system, install the pre-built package:
14+
- On a fedora-33 system, install the pre-built package:
1515

1616
```shell
1717
sudo dnf install -y $SILVERKUBE_RPM_RELEASE_URL

build.py

Lines changed: 70 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/python3
2-
# Copyright 2019 Red Hat
2+
# Copyright 2020 Red Hat
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License"); you may
55
# not use this file except in compliance with the License. You may obtain
@@ -32,28 +32,19 @@
3232

3333
environ["GOPATH"] = str(BASE_DIR)
3434

35-
# 2019-09-02T05:32:23Z
36-
ROOTLESSKIT_COMMIT = "182be5f88e62f3568b86331356d237910909b24e"
37-
# 2019-08-30T11:19:53Z
38-
SLIRP4NETNS_COMMIT = "f9503feb2adcd33ad817f954d294f2076de80f45"
39-
# 2019-09-18T18:53:36Z
40-
RUNC_COMMIT = "2186cfa3cd52b8e00b1de76db7859cacdf7b1f94"
41-
# Sat Jan 4 12:13:38 2020
42-
CRIO_COMMIT = "a82ac66f0b89f6caaa1d1a127c0fd7992522a396"
43-
# 2019-09-18T15:12:43Z
44-
CNI_PLUGINS_COMMIT = "497560f35f2cef2695f1690137b0bba98adf849b"
45-
# 2019-09-24T20:37:53Z
46-
KUBERNETES_COMMIT = "948870b5840add1ba4068e3d27d54ea353839992"
47-
CONMON_RELEASE = "v2.0.1"
48-
# Wed Dec 11 19:16:53 2019 tag: v1.6.6
49-
COREDNS_COMMIT = "6a7a75e0cc14159177e604d0157836cc32add343"
50-
# Kube's build script requires KUBE_GIT_VERSION to be set to a semver string
51-
KUBE_GIT_VERSION = "v1.17.0-usernetes"
52-
# 01/23/2017 (v.1.7.3.2)
53-
SOCAT_COMMIT = "cef0e039a89fe3b38e36090d9fe4be000973e0be"
54-
55-
ETCD_RELEASE = "v3.4.1"
56-
BAZEL_RELEASE = "0.29.1"
35+
USERNETES_COMMIT = "534df949509da0bfbb9e036688bded3e03533ec2"
36+
ROOTLESSKIT_COMMIT = "7d4b61b7e0939e63d2d550139ee0ee0a96081b07"
37+
CRIO_COMMIT = "4dff9dd17d3d27046b3261bd5688581c421334a9"
38+
KUBERNETES_COMMIT = "v1.21.0-alpha.0"
39+
SLIRP4NETNS_COMMIT = "v1.1.8"
40+
CRUN_COMMIT = "0.16"
41+
CNI_PLUGINS_COMMIT = "v0.8.7"
42+
CONMON_RELEASE = "v2.0.21"
43+
COREDNS_COMMIT = "v1.8.0"
44+
KUBE_GIT_VERSION = "v1.21.0-usernetes"
45+
46+
ETCD_RELEASE = "v3.4.14"
47+
BAZEL_RELEASE = "3.7.1"
5748

5849

5950
def execute(args: List[str], cwd: Path = Path(".")) -> None:
@@ -124,13 +115,15 @@ def build_slirp() -> List[Path]:
124115
return [slirp]
125116

126117

127-
def build_runc() -> List[Path]:
128-
print("Building runc")
129-
git = clone("https://github.com/opencontainers/runc", RUNC_COMMIT)
130-
runc = git / "runc"
131-
if not runc.exists():
132-
execute(["make", "BUILDTAGS=seccomp selinux"], git)
133-
return [runc]
118+
def build_crun() -> List[Path]:
119+
print("Building crun")
120+
git = clone("https://github.com/containers/crun", CRUN_COMMIT)
121+
crun = git / "crun"
122+
if not crun.exists():
123+
execute(["./autogen.sh"], git)
124+
execute(["./configure"], git)
125+
execute(["make"], git)
126+
return [crun]
134127

135128

136129
def build_crio() -> List[Path]:
@@ -194,14 +187,45 @@ def build_kube() -> List[Path]:
194187
)
195188
execute(["sudo", "chmod", "+x", str(bazel)])
196189
git = clone("https://github.com/kubernetes/kubernetes", KUBERNETES_COMMIT)
197-
kube = git / "bazel-bin" / "cmd" / "hyperkube" / "hyperkube"
198-
if not kube.exists():
190+
cmds = ["kubelet"] + list(
191+
map(
192+
lambda n: "kube-" + n,
193+
["apiserver", "controller-manager", "scheduler", "proxy"],
194+
)
195+
)
196+
197+
def get_kubes():
198+
try:
199+
return list(
200+
map(
201+
lambda cmd: Path(
202+
glob(
203+
str(
204+
git
205+
/ "bazel-out"
206+
/ "k8-fastbuild*"
207+
/ "bin"
208+
/ "cmd"
209+
/ cmd
210+
/ (cmd + "_")
211+
/ cmd
212+
)
213+
)[0]
214+
),
215+
cmds,
216+
)
217+
)
218+
except IndexError:
219+
return []
220+
221+
kubes = get_kubes()
222+
if not kubes or not all(map(lambda kube: kube.exists(), kubes)):
199223
execute(["git", "config", "user.email", "[email protected]"], git)
200224
execute(["git", "config", "user.name", "Silverkube Build Script"], git)
201225
patches = (
202226
clone(
203227
"https://github.com/rootless-containers/usernetes",
204-
"d58792bd5d4c56c4dda844ea119ee05a6b0d1808",
228+
USERNETES_COMMIT,
205229
)
206230
/ "src"
207231
/ "patches"
@@ -215,11 +239,14 @@ def build_kube() -> List[Path]:
215239
"KUBE_GIT_VERSION=" + KUBE_GIT_VERSION,
216240
"bazel",
217241
"build",
218-
"cmd/hyperkube",
219-
],
242+
]
243+
+ list(map(lambda cmd: "cmd/" + cmd, cmds)),
220244
git,
221245
)
222-
return [kube]
246+
kubes = get_kubes()
247+
if not kubes:
248+
raise RuntimeError("Couldn't find:" + cmds)
249+
return kubes
223250

224251

225252
def build_etcd() -> List[Path]:
@@ -251,6 +278,8 @@ def build_etcd() -> List[Path]:
251278
"automake",
252279
"libtool",
253280
"libcap-devel",
281+
"libslirp-devel",
282+
"yajl-devel",
254283
"glibc-static",
255284
"gcc",
256285
"gcc-c++",
@@ -280,7 +309,7 @@ def main():
280309
bins = (
281310
build_rootless()
282311
+ build_slirp()
283-
+ build_runc()
312+
+ build_crun()
284313
+ build_crio()
285314
+ build_conmon()
286315
+ build_coredns()
@@ -291,11 +320,11 @@ def main():
291320

292321
specfile = [
293322
"Name: silverkube",
294-
"Version: 0.0.4",
323+
"Version: 0.1.0",
295324
"Release: 1%{?dist}",
296325
"Summary: A kubernetes service for desktop",
297326
"",
298-
"Requires: iptables, ipset, conntrack-tools, containers-common",
327+
"Requires: iptables, ipset, conntrack-tools, containers-common, kubernetes-client",
299328
"Requires(post): udica",
300329
"Requires(post): coreutils",
301330
"",
@@ -306,7 +335,7 @@ def main():
306335
"Source2: silverkube.cil",
307336
]
308337
for idx, source in zip(range(100, 1000), bins + cnis):
309-
src_name = str(source).replace("/root/.cache/silverkube/", "")
338+
src_name = str(source).split(".cache/silverkube/")[1]
310339
specfile.append(f"Source{idx}: {src_name}")
311340

312341
specfile.extend(
@@ -354,7 +383,7 @@ def sd(mode: str, path: str, srcs: List[Path]) -> List[Tuple[str, str]]:
354383
"/usr/share/silverkube",
355384
"",
356385
"%changelog",
357-
"* Sat Sep 21 2019 Tristan Cacqueray <[email protected]>",
386+
"* Mon Dec 14 2020 Tristan Cacqueray <[email protected]>",
358387
"- Initial packaging",
359388
]
360389
)

silverkube.py

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,18 @@
1818

1919
from base64 import b64encode, b64decode
2020
from json import dumps as json_dumps
21-
from os import environ, getuid, chown
21+
from os import environ, getuid, getgid, chown
2222
from subprocess import Popen, PIPE
2323
from time import sleep
2424
from typing import List, Tuple, Optional
2525
from sys import argv
2626
from pathlib import Path
2727
from textwrap import dedent
2828

29-
USERNETES = getuid() > 0
29+
UID = getuid()
30+
GID = getgid()
31+
NEXT_UID = UID + 1
32+
USERNETES = UID > 0
3033
RKJOIN = Path("~/.local/bin/rootless-join").expanduser()
3134

3235
if USERNETES:
@@ -39,7 +42,9 @@
3942
SYSTEMD = Path("~/.config/systemd/user").expanduser()
4043
SYSTEMCTL = ["systemctl", "--user"]
4144
NSJOIN = [str(RKJOIN)]
42-
UIDMAPPING = ",".join(["1000:0:1", "0:1:1000", "1001:1001:%s" % (2 ** 16 - 1001)])
45+
UIDMAPPING = ",".join(
46+
[f"{UID}:0:1", f"0:1:{UID}", f"{NEXT_UID}:{NEXT_UID}:%s" % (2 ** 16 - NEXT_UID)]
47+
)
4348
else:
4449
# Admin Paths
4550
CONF = Path("/etc/silverkube")
@@ -93,7 +98,7 @@
9398
"--port-driver=builtin",
9499
"--copy-up=/etc --copy-up=/run --copy-up=/var/lib",
95100
"--copy-up=/opt", # --copy-up=/sys",
96-
"--pidns",
101+
"--pidns --cgroupns --ipcns --utsns --propagation=rslave",
97102
str(RKINIT),
98103
],
99104
[
@@ -129,6 +134,8 @@
129134
# This is not actually working...
130135
# umount -l /sys
131136
137+
mount -t tmpfs none /sys/fs/cgroup
138+
mount -t cgroup2 none /sys/fs/cgroup
132139
mount --bind /usr/libexec/silverkube/cni /opt/cni/bin
133140
mount --bind {CONF}/net.d/ /etc/cni/net.d/
134141
for dst in /var/lib/kubelet /var/lib/cni /var/log /var/lib/crio; do
@@ -174,7 +181,7 @@
174181
grpc_max_recv_msg_size = 16777216
175182
176183
[crio.runtime]
177-
default_runtime = "runc"
184+
default_runtime = "crun"
178185
no_pivot = false
179186
conmon = "/usr/libexec/silverkube/conmon"
180187
conmon_cgroup = "pod"
@@ -211,10 +218,10 @@
211218
ctr_stop_timeout = 0
212219
pinns_path = "/usr/libexec/silverkube/pinns"
213220
214-
[crio.runtime.runtimes.runc]
215-
runtime_path = ""
221+
[crio.runtime.runtimes.crun]
222+
runtime_path = "/usr/libexec/silverkube/crun"
216223
runtime_type = "oci"
217-
runtime_root = "{RUN}/runc"
224+
runtime_root = "{RUN}/crun"
218225
219226
[crio.image]
220227
default_transport = "docker://"
@@ -314,6 +321,10 @@
314321
str(PKI / "api-key.pem"),
315322
"--bind-address 0.0.0.0",
316323
"--secure-port 8043",
324+
"--service-account-issuer",
325+
"test",
326+
"--service-account-signing-key-file",
327+
str(PKI / "sa-key.pem"),
317328
"--service-account-key-file",
318329
str(PKI / "sa-cert.pem"),
319330
"--anonymous-auth=False",
@@ -454,8 +465,7 @@
454465
+ (
455466
[
456467
"--feature-gates",
457-
"DevicePlugins=false,SupportNoneCgroupDriver=true",
458-
"--cgroup-driver=none --cgroups-per-qos=false",
468+
"DevicePlugins=false",
459469
"--enforce-node-allocatable=''",
460470
"--register-node=true",
461471
]
@@ -483,7 +493,14 @@
483493
clusterDomain: "cluster.local"
484494
clusterDNS:
485495
- "%s"
496+
featureGates:
497+
DevicePlugins: false
498+
LocalStorageCapacityIsolation: false
499+
evictionHard:
500+
nodefs.available: "3%%"
486501
podCIDR: "%s"
502+
cgroupDriver: "none"
503+
cgroupsPerQOS: false
487504
ImageMinimumGCAge: 100000m
488505
HighThresholdPercent: 100
489506
LowThresholdPercent: 0
@@ -903,11 +920,7 @@ def setup_service(name: str, args: List[Command]) -> None:
903920
if name == "rootlesskit" and not USERNETES:
904921
# No need for that service
905922
return
906-
if name.startswith("kube"):
907-
command_name = f"hyperkube {name}"
908-
else:
909-
command_name = name
910-
command_name = "/usr/libexec/silverkube/" + command_name
923+
command_name = "/usr/libexec/silverkube/" + name
911924
if name != "rootlesskit" and USERNETES:
912925
# Usernetes needs to share the namespace
913926
command_name = str(RKJOIN) + " " + command_name
@@ -922,6 +935,7 @@ def setup_service(name: str, args: List[Command]) -> None:
922935
923936
[Service]
924937
Environment="PATH=/usr/libexec/silverkube/:/bin:/sbin"
938+
Environment="_CRIO_ROOTLESS=1"
925939
SyslogIdentifier=silverkube-{name}
926940
ExecStart={command}
927941
@@ -1000,13 +1014,14 @@ def generate_pvs():
10001014
base = RUN / "pvs"
10011015
base.mkdir(exist_ok=True)
10021016
base.chmod(0o700)
1003-
chown(str(base), 1000, 1000)
1017+
chown(str(base), UID, GID)
10041018
pvs = []
10051019
for pv in range(10):
10061020
path = base / f"pv{pv}"
10071021
path.mkdir(parents=True, exist_ok=True)
1008-
chown(str(path), 1000, 1000)
1009-
execute(["chcon", "system_u:object_r:container_file_t:s0", str(path)])
1022+
chown(str(path), UID, GID)
1023+
if not USERNETES:
1024+
execute(["chcon", "system_u:object_r:container_file_t:s0", str(path)])
10101025
pvs.append(
10111026
dict(
10121027
apiVersion="v1",
@@ -1102,8 +1117,7 @@ def down() -> int:
11021117
if not USERNETES:
11031118
execute(
11041119
[
1105-
"/usr/libexec/silverkube/hyperkube",
1106-
"kube-proxy",
1120+
"/usr/libexec/silverkube/kube-proxy",
11071121
"--cleanup",
11081122
"--cleanup-ipvs",
11091123
"--config",

0 commit comments

Comments
 (0)