8000 Merge pull request #270 from lx1036/release/v1.91.0 · lx1036/code@f9fd58d · GitHub
[go: up one dir, main page]

Skip to content

Commit f9fd58d

Browse files
authored
Merge pull request #270 from lx1036/release/v1.91.0
Release/v1.91.0
2 parents 9c7a92e + 12fa83c commit f9fd58d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+5738
-43
lines changed

go/k8s-ui/frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"js-base64": "^2.5.0",
6060
"js-yaml": "3.13.1",
6161
"material-design-icons": "3.0.1",
62-
"moment": "^2.29.2",
62+
"moment": "^2.29.4",
6363
"mutationobserver-shim": "^0.3.2",
6464
"ng2-ace-editor": "^0.3.9",
6565
"ngx-cookie-service": "2.4.0",

go/k8s-ui/frontend/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10010,10 +10010,10 @@ moment-timezone@^0.5.25:
1001010010
dependencies:
1001110011
moment ">= 2.9.0"
1001210012

10013-
moment@*, "moment@>= 2.9.0", moment@^2.29.2:
10014-
version "2.29.2"
10015-
resolved "https://registry.yarnpkg.com/moment/-/moment-2.29.2.tgz#00910c60b20843bcba52d37d58c628b47b1f20e4"
10016-
integrity sha512-UgzG4rvxYpN15jgCmVJwac49h9ly9NurikMWGPdVxm8GZD6XjkKPxDTjQQ43gtGgnV3X0cAyWDdP2Wexoquifg==
10013+
moment@*, "moment@>= 2.9.0", moment@^2.29.4:
10014+
version "2.29.4"
10015+
resolved "https://registry.yarnpkg.com/moment/-/moment-2.29.4.tgz#3dbe052889fe7c1b2ed966fcb3a77328964ef108"
10016+
integrity sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w==
1001710017

1001810018
moment@2.24.0:
1001910019
version "2.24.0"

go/k8s/network/calico/calico.yaml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4082,7 +4082,7 @@ spec:
40824082
# It can be deleted if this is a fresh installation, or if you have already
40834083
# upgraded to use calico-ipam.
40844084
- name: upgrade-ipam
4085-
image: calico/cni:v3.21.2
4085+
image: calico/cni:v3.22.2
40864086
command: ["/opt/cni/bin/calico-ipam", "-upgrade"]
40874087
envFrom:
40884088
- configMapRef:
@@ -4109,7 +4109,7 @@ spec:
41094109
# This container installs the CNI binaries
41104110
# and CNI network config file on each node.
41114111
- name: install-cni
4112-
image: calico/cni:v3.21.2
4112+
image: calico/cni:v3.22.2
41134113
command: ["/opt/cni/bin/install"]
41144114
envFrom:
41154115
- configMapRef:
@@ -4150,7 +4150,7 @@ spec:
41504150
# Adds a Flex Volume Driver that creates a per-pod Unix Domain Socket to allow Dikastes
41514151
# to communicate with Felix over the Policy Sync API.
41524152
- name: flexvol-driver
4153-
image: calico/pod2daemon-flexvol:v3.21.2
4153+
image: calico/pod2daemon-flexvol:v3.22.2
41544154
volumeMounts:
41554155
- name: flexvol-driver-host
41564156
mountPath: /host/driver
@@ -4161,13 +4161,15 @@ spec:
41614161
# container programs network policy and routes on each
41624162
# host.
41634163
- name: calico-node
4164-
image: calico/node:v3.21.2
4164+
image: calico/node:v3.22.2
41654165
envFrom:
41664166
- configMapRef:
41674167
# Allow KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT to be overridden for eBPF mode.
41684168
name: kubernetes-services-endpoint
41694169
optional: true
41704170
env:
4171+
- name: FELIX_LOGSEVERITYSCREEN # debug log for felix
4172+
value: debug
41714173
# Use Kubernetes API as the backing datastore.
41724174
- name: DATASTORE_TYPE
41734175
value: "kubernetes"
@@ -4380,7 +4382,7 @@ spec:
43804382
priorityClassName: system-cluster-critical
43814383
containers:
43824384
- name: calico-kube-controllers
4383-
image: calico/kube-controllers:v3.21.2
4385+
image: calico/kube-controllers:v3.22.2
43844386
env:
43854387
# Choose which controllers to run.
43864388
- name: ENABLED_CONTROLLERS
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
3+
# BPF
4+
calico felix 组件负责下发 eBPF 规则,并实现 service 四层负载均衡。
5+
开启 eBPF https://projectcalico.docs.tigera.io/maintenance/ebpf/enabling-ebpf :
6+
7+
```yaml
8+
apiVersion: crd.projectcalico.org/v1
9+
kind: FelixConfiguration
10+
metadata:
11+
name: default
12+
spec:
13+
bpfEnabled: true # 设置为 true 则开启
14+
bpfExternalServiceMode: DSR # 负载均衡 DSR mode
15+
bpfLogLevel: ''
16+
logSeverityScreen: Info
17+
reportingInterval: 0s
18+
```
19+
20+
开启后的 ebpf maps 对象为:
21+
22+
```shell
23+
ls /sys/fs/bpf/tc/globals
24+
# cali_v4_arp2 cali_v4_ct2 cali_v4_ct_nats cali_v4_fsafes2
25+
# cali_v4_ip_sets cali_v4_nat_aff cali_v4_nat_be
26+
# cali_v4_nat_fe3 cali_v4_routes cali_v4_srmsg cali_v4_state3
27+
```
28+
Lines changed: 285 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,285 @@
1+
package bpf
2+
3+
import (
4+
"fmt"
5+
"golang.org/x/sys/unix"
6+
"io"
7+
"os"
8+
"runtime"
9+
"unsafe"
10+
)
11+
12+
func GetMapFDByPin(filename string) (MapFD, error) {
13+
fd, err := ObjGet(filename)
14+
return MapFD(fd), err
15+
}
16+
17+
type MapInfo struct {
18+
Type int
19+
KeySize int
20+
ValueSize int
21+
MaxEntries int
22+
}
23+
type bpfAttrObjInfo struct {
24+
Fd uint32
25+
InfoLen uint32
26+
Info uint64
27+
}
28+
type bpfMapInfo struct {
29+
MapType uint32
30+
MapID uint32
31+
SizeKey uint32
32+
SizeValue uint32
33+
MaxEntries uint32
34+
Flags uint32
35+
}
36+
37+
// GetMapInfo INFO: https://github.com/cilium/cilium/blob/1.8.1/pkg/datapath/connector/ipvlan.go#L117-L136 根据 napID 获取 MapInfo
38+
func GetMapInfo(fd MapFD) (*MapInfo, error) {
39+
info := bpfMapInfo{}
40+
bpfAttrInfo := bpfAttrObjInfo{
41+
Fd: uint32(fd),
42+
InfoLen: uint32(unsafe.Sizeof(info)),
43+
Info: uint64(uintptr(unsafe.Pointer(&info))),
44+
}
45+
bpfAttr2 := struct {
46+
info bpfAttrObjInfo
47+
}{
48+
info: bpfAttrInfo,
49+
}
50+
_, _, errno := unix.Syscall(
51+
unix.SYS_BPF,
52+
unix.BPF_OBJ_GET_INFO_BY_FD,
53+
uintptr(unsafe.Pointer(&bpfAttr2)),
54+
unsafe.Sizeof(bpfAttr2),
55+
)
56+
if errno != 0 {
57+
return nil, errno
58+
}
59+
60+
return &MapInfo{
61+
Type: int(info.MapType),
62+
KeySize: int(info.SizeKey),
63+
ValueSize: int(info.SizeValue),
64+
MaxEntries: int(info.MaxEntries),
65+
}, nil
66+
}
67+
68+
func UpdateMapEntry(fd MapFD, k, v []byte) error {
69+
return UpdateElement(int(fd), unsafe.Pointer(&k), unsafe.Pointer(&v), unix.BPF_ANY)
70+
}
71+
72+
// This struct must be in sync with union bpf_attr's anonymous struct used by
73+
// BPF_OBJ_*_ commands
74+
type bpfAttrObjOp struct {
75+
pathname uint64
76+
fd uint32
77+
pad0 [4]byte
78+
}
79+
80+
// ObjGet INFO: 根据 map filename 获取 bpf 虚拟文件系统 fd
81+
// @see https://github.com/cilium/cilium/blob/v1.11.6/pkg/bpf/bpf_linux.go#L320-L355
82+
func ObjGet(pathname string) (int, error) {
83+
pathStr, err := unix.BytePtrFromString(pathname)
84+
if err != nil {
85+
return 0, fmt.Errorf("unable to convert pathname %q to byte pointer: %w", pathname, err)
86+
}
87+
bpfAttr := bpfAttrObjOp{
88+
pathname: uint64(uintptr(unsafe.Pointer(pathStr))),
89+
}
90+
91+
fd, _, errno := unix.Syscall(
92+
unix.SYS_BPF,
93+
unix.BPF_OBJ_GET,
94+
uintptr(unsafe.Pointer(&bpfAttr)),
95+
unsafe.Sizeof(bpfAttr),
96+
)
97+
runtime.KeepAlive(pathStr)
98+
runtime.KeepAlive(&bpfAttr)
99+
100+
if fd == 0 || errno != 0 {
101+
return 0, &os.PathError{
102+
Op: "Unable to get object",
103+
Err: errno,
104+
Path: pathname,
105+
}
106+
}
107+
108+
return int(fd), nil
109+
}
110+
111+
type bpfAttrFdFromId struct {
112+
ID uint32
113+
NextID uint32
114+
Flags uint32
115+
}
116+
117+
// MapFdFromID INFO: 根据 mapID 获取 bpf 虚拟文件系统 fd
118+
// @see https://github.com/cilium/cilium/blob/v1.11.6/pkg/bpf/bpf_linux.go#L363-L389
119+
func MapFdFromID(id int) (int, error) {
120+
bpfAttr := bpfAttrFdFromId{
121+
ID: uint32(id),
122+
}
123+
fd, _, err := unix.Syscall(
124+
unix.SYS_BPF,
125+
unix.BPF_MAP_GET_FD_BY_ID,
126+
uintptr(unsafe.Pointer(&bpfAttr)),
127+
unsafe.Sizeof(bpfAttr),
128+
)
129+
runtime.KeepAlive(&bpfAttr)
130+
131+
if fd == 0 || err != 0 {
132+
return 0, fmt.Errorf("Unable to get object fd from id %d: %s", id, err)
133+
}
134+
135+
return int(fd), nil
136+
}
137+
138+
// This struct must be in sync with union bpf_attr's anonymous struct used by
139+
// BPF_MAP_*_ELEM commands
140+
type bpfAttrMapOpElem struct {
141+
mapFd uint32
142+
pad0 [4]byte
143+
key uint64
144+
value uint64 // union: value or next_key
145+
flags uint64
146+
}
147+
148+
// UpdateElement INFO: https://github.com/cilium/cilium/blob/v1.11.6/pkg/bpf/bpf_linux.go#L121-L139
149+
func UpdateElement(fd int, key, value unsafe.Pointer, flags uint64) error {
150+
bpfAttr := bpfAttrMapOpElem{
151+
mapFd: uint32(fd),
152+
key: uint64(uintptr(key)),
153+
value: uint64(uintptr(value)),
154+
flags: uint64(flags),
155+
}
156+
157+
ret := UpdateElementFromPointers(fd, unsafe.Pointer(&bpfAttr), unsafe.Sizeof(bpfAttr))
158+
runtime.KeepAlive(key)
159+
runtime.KeepAlive(value)
160+
return ret
161+
}
162+
163+
// UpdateElementFromPointers updates the map in fd with the given value in the given key.
164+
func UpdateElementFromPointers(fd int, structPtr unsafe.Pointer, sizeOfStruct uintptr) error {
165+
ret, _, err := unix.Syscall(
166+
unix.SYS_BPF,
167+
unix.BPF_MAP_UPDATE_ELEM,
168+
uintptr(structPtr),
169+
sizeOfStruct,
170+
)
171+
runtime.KeepAlive(structPtr)
172+
if ret != 0 || err != 0 {
173+
return fmt.Errorf("Unable to update element for map with file descriptor %d: %s", fd, err)
174+
}
175+
176+
return nil
177+
}
178+
179+
func GetMapEntry(fd MapFD, key []byte, valueSize int) ([]byte, error) {
180+
value := make([]byte, valueSize)
181+
err := LookupElement(int(fd), unsafe.Pointer(&key), unsafe.Pointer(&value))
182+
if err != nil {
183+
return nil, err
184+
}
185+
186+
return value, nil
187+
}
188+
189+
// LookupElement INFO: 从 map fd 中查找 key 对应的 value
190+
func LookupElement(fd int, key, value unsafe.Pointer) error {
191+
uba := bpfAttrMapOpElem{
192+
mapFd: uint32(fd),
193+
key: uint64(uintptr(key)),
194+
value: uint64(uintptr(value)),
195+
}
196+
197+
ret := LookupElementFromPointers(fd, unsafe.Pointer(&uba), unsafe.Sizeof(uba))
198+
runtime.KeepAlive(key)
199+
runtime.KeepAlive(value)
200+
return ret
201+
}
202+
func LookupElementFromPointers(fd int, structPtr unsafe.Pointer, sizeOfStruct uintptr) error {
203+
ret, _, err := unix.Syscall(
204+
unix.SYS_BPF,
205+
unix.BPF_MAP_LOOKUP_ELEM,
206+
uintptr(structPtr),
207+
sizeOfStruct,
208+
)
209+
runtime.KeepAlive(structPtr)
210+
211+
if ret != 0 || err != 0 {
212+
return fmt.Errorf("Unable to lookup element in map with file descriptor %d: %s", fd, err)
213+
}
214+
215+
return nil
216+
}
217+
218+
func DeleteMapEntry(mapFD MapFD, k []byte, valueSize int) error {
219+
return DeleteElement(int(mapFD), unsafe.Pointer(&k))
220+
}
221+
222+
// DeleteElement deletes the map element with the given key.
223+
func DeleteElement(fd int, key unsafe.Pointer) error {
224+
ret, err := deleteElement(fd, key)
225+
226+
if ret != 0 || err != 0 {
227+
return fmt.Errorf("unable to delete element from map with file descriptor %d: %s", fd, err)
228+
}
229+
230+
return nil
231+
}
232+
func deleteElement(fd int, key unsafe.Pointer) (uintptr, unix.Errno) {
233+
bpfAttr := bpfAttrMapOpElem{
234+
mapFd: uint32(fd),
235+
key: uint64(uintptr(key)),
236+
}
237+
ret, _, err := unix.Syscall(
238+
unix.SYS_BPF,
239+
unix.BPF_MAP_DELETE_ELEM,
240+
uintptr(unsafe.Pointer(&bpfAttr)),
241+
unsafe.Sizeof(bpfAttr),
242+
)
243+
runtime.KeepAlive(key)
244+
runtime.KeepAlive(&bpfAttr)
245+
246+
return ret, err
247+
}
248+
249+
// GetNextKeyFromPointers stores, in nextKey, the next key after the key of the
250+
// map in fd. When there are no more keys, io.EOF is returned.
251+
func GetNextKeyFromPointers(fd int, structPtr unsafe.Pointer, sizeOfStruct uintptr) error {
252+
ret, _, err := unix.Syscall(
253+
unix.SYS_BPF,
254+
unix.BPF_MAP_GET_NEXT_KEY,
255+
uintptr(structPtr),
256+
sizeOfStruct,
257+
)
258+
runtime.KeepAlive(structPtr)
259+
260+
// BPF_MAP_GET_NEXT_KEY returns ENOENT when all keys have been iterated
261+
// translate that to io.EOF to signify there are no next keys
262+
if err == unix.ENOENT {
263+
return io.EOF
264+
}
265+
266+
if ret != 0 || err != 0 {
267+
return fmt.Errorf("unable to get next key from map with file descriptor %d: %s", fd, err)
268+
}
269+
270+
return nil
271+
}
272+
273+
// GetFirstKey fetches the first key in the map. If there are no keys in the
274+
// map, io.EOF is returned.
275+
func GetFirstKey(fd int, nextKey unsafe.Pointer) error {
276+
bpfAttr := bpfAttrMapOpElem{
277+
mapFd: uint32(fd),
278+
key: 0, // NULL -> Get first element
279+
value: uint64(uintptr(nextKey)),
280+
}
281+
282+
ret := GetNextKeyFromPointers(fd, unsafe.Pointer(&bpfAttr), unsafe.Sizeof(bpfAttr))
283+
runtime.KeepAlive(nextKey)
284+
return ret
285+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package bpf
2+
3+
func MaybeMountBPFfs() (string, error) {
4+
5+
}

0 commit comments

Comments
 (0)
0