Skip to content

Commit 23f92ba

Browse files
authored
Merge pull request #700 from l1b0k/feat/policy
add log for ct
2 parents 2d9c337 + 573884f commit 23f92ba

File tree

11 files changed

+96
-44
lines changed

11 files changed

+96
-44
lines changed

Diff for: .github/workflows/build-policy.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ jobs:
1717
build-policy:
1818
runs-on: ubuntu-latest
1919
steps:
20-
- uses: actions/checkout@v3
20+
- uses: actions/checkout@v4
2121
- name: Set up QEMU
22-
uses: docker/setup-qemu-action@v2
22+
uses: docker/setup-qemu-action@v3
2323

2424
- name: Set up Docker Buildx
25-
uses: docker/setup-buildx-action@v2
25+
uses: docker/setup-buildx-action@v3
2626

2727
- name: Cache Docker layers
2828
uses: actions/cache@v3
@@ -51,7 +51,7 @@ jobs:
5151
if: ${{ github.event_name != 'pull_request' && github.event.action != 'unassigned' }}
5252

5353
- name: Build and push
54-
uses: docker/build-push-action@v3
54+
uses: docker/build-push-action@v6
5555
with:
5656
context: .
5757
file: ./Dockerfile.policy

Diff for: .github/workflows/check.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- uses: actions/checkout@v4
1616
- uses: actions/setup-go@v5
1717
with:
18-
go-version: 1.21.3
18+
go-version: 1.23.2
1919
- name: Test
2020
run: |
2121
go=$(which go)
@@ -35,7 +35,7 @@ jobs:
3535
- uses: actions/checkout@v4
3636
- uses: actions/setup-go@v5
3737
with:
38-
go-version: 1.21.3
38+
go-version: 1.23.2
3939
- name: Check module vendoring
4040
run: |
4141
go mod tidy
@@ -49,12 +49,12 @@ jobs:
4949
- uses: actions/checkout@v4
5050
- uses: actions/setup-go@v5
5151
with:
52-
go-version: 1.21.3
52+
go-version: 1.23.2
5353
cache: false
5454
- name: Run golangci-lint
55-
uses: golangci/golangci-lint-action@v4
55+
uses: golangci/golangci-lint-action@v6
5656
with:
57-
version: v1.55
57+
version: v1.61
5858
args: --config=.golangci.yml
5959

6060
super-linter:

Diff for: .github/workflows/codeql-analysis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636

3737
steps:
3838
- name: Checkout repository
39-
uses: actions/checkout@v3
39+
uses: actions/checkout@v4
4040

4141
- name: Initialize CodeQL
4242
uses: github/codeql-action/init@v3

Diff for: .github/workflows/release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
release:
1414
runs-on: ubuntu-latest
1515
steps:
16-
- uses: actions/checkout@v3
16+
- uses: actions/checkout@v4
1717
- name: Build Changelog
1818
id: github_release
1919
uses: mikepenz/release-changelog-builder-action@v1

Diff for: Dockerfile

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
ARG TERWAY_POLICY_IMAGE=registry-cn-zhangjiakou.ack.aliyuncs.com/acs/terway:policy-75c98940@sha256:6dbdffee0cdc5c29239d487b4e567046d7dd23f61d67dbbbce1a2e5db9b210dc
1+
ARG TERWAY_POLICY_IMAGE=registry-cn-zhangjiakou.ack.aliyuncs.com/acs/terway:policy-927d6ab6@sha256:dbcc2cef1164b7ce0de7700cefbdece7ca0281d84e5db91ce96488f1a2c00ed7
22
ARG UBUNTU_IMAGE=registry.cn-hangzhou.aliyuncs.com/acs/ubuntu:22.04-update
33
ARG CILIUM_LLVM_IMAGE=quay.io/cilium/cilium-llvm:547db7ec9a750b8f888a506709adb41f135b952e@sha256:4d6fa0aede3556c5fb5a9c71bc6b9585475ac9b1064f516d4c45c8fb691c9d9e
44
ARG CILIUM_BPFTOOL_IMAGE=quay.io/cilium/cilium-bpftool:78448c1a37ff2b790d5e25c3d8b8ec3e96e6405f@sha256:99a9453a921a8de99899ef82e0822f0c03f65d97005c064e231c06247ad8597d
55
ARG CILIUM_IPROUTE2_IMAGE=quay.io/cilium/cilium-iproute2:3570d58349efb2d6b0342369a836998c93afd291@sha256:1abcd7a5d2117190ab2690a163ee9cd135bc9e4cf8a4df662a8f993044c79342
66
ARG CILIUM_IPTABLES_IMAGE=quay.io/cilium/iptables-20.04:e6f83206c57e606282056903ffd3aab0183bdaed@sha256:7ce0de449d356a5259021dc13f2b00a8bddfbea57a1c91ff8f146d455cace9e5
77

8-
FROM --platform=$TARGETPLATFORM ${TERWAY_POLICY_IMAGE} as policy-dist
9-
FROM --platform=$TARGETPLATFORM ${CILIUM_LLVM_IMAGE} as llvm-dist
10-
FROM --platform=$TARGETPLATFORM ${CILIUM_BPFTOOL_IMAGE} as bpftool-dist
11-
FROM --platform=$TARGETPLATFORM ${CILIUM_IPROUTE2_IMAGE} as iproute2-dist
12-
FROM --platform=$TARGETPLATFORM ${CILIUM_IPTABLES_IMAGE} as iptables-dist
8+
FROM --platform=$TARGETPLATFORM ${TERWAY_POLICY_IMAGE} AS policy-dist
9+
FROM --platform=$TARGETPLATFORM ${CILIUM_LLVM_IMAGE} AS llvm-dist
10+
FROM --platform=$TARGETPLATFORM ${CILIUM_BPFTOOL_IMAGE} AS bpftool-dist
11+
FROM --platform=$TARGETPLATFORM ${CILIUM_IPROUTE2_IMAGE} AS iproute2-dist
12+
FROM --platform=$TARGETPLATFORM ${CILIUM_IPTABLES_IMAGE} AS iptables-dist
1313

14-
FROM --platform=$BUILDPLATFORM golang:1.21.3 as builder
14+
FROM --platform=$BUILDPLATFORM golang:1.23.2 AS builder
1515
ARG GOPROXY
1616
ARG TARGETOS
1717
ARG TARGETARCH
18-
ENV GOPROXY $GOPROXY
18+
ENV GOPROXY=$GOPROXY
1919
WORKDIR /go/src/github.com/AliyunContainerService/terway/
2020
COPY go.sum go.mod ./
2121
RUN go mod download

Diff for: Dockerfile.controlplane

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
FROM --platform=$BUILDPLATFORM golang:1.21.3 as builder
1+
FROM --platform=$BUILDPLATFORM golang:1.23.2 AS builder
22
ARG GOPROXY
33
ARG TARGETOS
44
ARG TARGETARCH
5-
ENV GOPROXY $GOPROXY
5+
ENV GOPROXY=$GOPROXY
66
WORKDIR /go/src/github.com/AliyunContainerService/terway/
77
COPY go.sum go.mod ./
88
RUN go mod download
@@ -15,7 +15,7 @@ RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -tags default_build
1515
-X \"github.com/AliyunContainerService/terway/pkg/aliyun/credential.kubernetesAlicloudIdentity=terway-controlplane/`git rev-parse --short HEAD 2>/dev/null`\"" \
1616
-o terway-controlplane cmd/terway-controlplane/terway-controlplane.go
1717

18-
FROM --platform=$TARGETPLATFORM debian:stable-slim as cert
18+
FROM --platform=$TARGETPLATFORM debian:stable-slim AS cert
1919
RUN apt-get update && apt-get -uy upgrade
2020
RUN apt-get -y install ca-certificates && update-ca-certificates
2121

Diff for: Dockerfile.policy

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM --platform=$TARGETPLATFORM calico/go-build:v0.90 as felix-builder
1+
FROM --platform=$TARGETPLATFORM calico/go-build:v0.90 AS felix-builder
22
ARG GOPROXY
33
ARG GIT_VERSION
44
ENV GOPROXY $GOPROXY
@@ -21,7 +21,7 @@ RUN cd /go/src/github.com/projectcalico/calico && \
2121

2222
FROM --platform=$TARGETPLATFORM quay.io/cilium/cilium-builder:1d3ec0f0b74a32048a9716c7a8ce1eee851ca0ec@sha256:9fab9eb021456705d99b014d2f9e59aff9f50aa1a296aa55e984f3e947a62120 as cilium-builder
2323
ARG GOPROXY
24-
ENV GOPROXY $GOPROXY
24+
ENV GOPROXY=$GOPROXY
2525
ARG CILIUM_SHA=""
2626
ARG GIT_VERSION=""
2727
LABEL cilium-sha=${CILIUM_SHA}

Diff for: Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ GOLANGCI_LINT = $(LOCALBIN)/golangci-lint-$(GOLANGCI_LINT_VERSION)
113113
## Tool Versions
114114
CONTROLLER_TOOLS_VERSION ?= v0.14.0
115115
ENVTEST_VERSION ?= latest
116-
GOLANGCI_LINT_VERSION ?= v1.54.2
116+
GOLANGCI_LINT_VERSION ?= v1.61.0
117117

118118
.PHONY: controller-gen
119119
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.

Diff for: pkg/controller/webhook/mutating.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package webhook
1818

1919
import (
2020
"context"
21+
"errors"
2122
"fmt"
2223
"net/http"
2324
"strconv"
@@ -35,7 +36,7 @@ import (
3536

3637
"gomodules.xyz/jsonpatch/v2"
3738
corev1 "k8s.io/api/core/v1"
38-
"k8s.io/apimachinery/pkg/api/errors"
39+
k8sErr "k8s.io/apimachinery/pkg/api/errors"
3940
"k8s.io/apimachinery/pkg/api/resource"
4041
k8stypes "k8s.io/apimachinery/pkg/types"
4142
"k8s.io/apimachinery/pkg/util/json"
@@ -101,7 +102,7 @@ func podWebhook(ctx context.Context, req *webhook.AdmissionRequest, client clien
101102
if err != nil {
102103
msg := fmt.Sprintf("error get previous podENI conf, %s", err)
103104
l.Error(err, msg)
104-
return webhook.Errored(1, fmt.Errorf(msg))
105+
return webhook.Errored(1, errors.New(msg))
105106
}
106107

107108
// 1. check pod annotation config first
@@ -348,7 +349,7 @@ func getPreviousZone(ctx context.Context, client client.Client, pod *corev1.Pod)
348349
Name: pod.Name,
349350
}, podENI)
350351
if err != nil {
351-
if errors.IsNotFound(err) {
352+
if k8sErr.IsNotFound(err) {
352353
return "", nil
353354
}
354355
return "", err

Diff for: plugin/driver/utils/netlink_linux.go

+16-16
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func NetlinkFamily(ip net.IP) int {
3333

3434
func LinkSetName(link netlink.Link, name string) error {
3535
cmd := fmt.Sprintf("ip link set %s name %s", link.Attrs().Name, name)
36-
Log.Infof(cmd)
36+
Log.Info(cmd)
3737
err := netlink.LinkSetName(link, name)
3838
if err != nil {
3939
return fmt.Errorf("error %s, %w", cmd, err)
@@ -43,7 +43,7 @@ func LinkSetName(link netlink.Link, name string) error {
4343

4444
func LinkAdd(link netlink.Link) error {
4545
cmd := fmt.Sprintf("ip link add %s type %s", link.Attrs().Name, link.Type())
46-
Log.Infof(cmd)
46+
Log.Info(cmd)
4747
err := netlink.LinkAdd(link)
4848
if err != nil {
4949
return fmt.Errorf("error %s, %w", cmd, err)
@@ -53,7 +53,7 @@ func LinkAdd(link netlink.Link) error {
5353

5454
func LinkSetUp(link netlink.Link) error {
5555
cmd := fmt.Sprintf("ip link set %s up", link.Attrs().Name)
56-
Log.Infof(cmd)
56+
Log.Info(cmd)
5757
err := netlink.LinkSetUp(link)
5858
if err != nil {
5959
return fmt.Errorf("error %s, %w", cmd, err)
@@ -63,7 +63,7 @@ func LinkSetUp(link netlink.Link) error {
6363

6464
func LinkSetDown(link netlink.Link) error {
6565
cmd := fmt.Sprintf("ip link set %s down", link.Attrs().Name)
66-
Log.Infof(cmd)
66+
Log.Info(cmd)
6767
err := netlink.LinkSetDown(link)
6868
if err != nil {
6969
return fmt.Errorf("error %s, %w", cmd, err)
@@ -73,7 +73,7 @@ func LinkSetDown(link netlink.Link) error {
7373

7474
func LinkDel(link netlink.Link) error {
7575
cmd := fmt.Sprintf("ip link del %s", link.Attrs().Name)
76-
Log.Infof(cmd)
76+
Log.Info(cmd)
7777
err := netlink.LinkDel(link)
7878
if err != nil {
7979
if _, ok := err.(netlink.LinkNotFoundError); ok {
@@ -86,7 +86,7 @@ func LinkDel(link netlink.Link) error {
8686

8787
func LinkSetMTU(link netlink.Link, mtu int) error {
8888
cmd := fmt.Sprintf("ip link set %s mtu %d", link.Attrs().Name, mtu)
89-
Log.Infof(cmd)
89+
Log.Info(cmd)
9090
err := netlink.LinkSetMTU(link, mtu)
9191
if err != nil {
9292
return fmt.Errorf("error %s, %w", cmd, err)
@@ -96,7 +96,7 @@ func LinkSetMTU(link netlink.Link, mtu int) error {
9696

9797
func AddrDel(link netlink.Link, addr *netlink.Addr) error {
9898
cmd := fmt.Sprintf("ip addr del %s dev %s", addr.IPNet.String(), link.Attrs().Name)
99-
Log.Infof(cmd)
99+
Log.Info(cmd)
100100
err := netlink.AddrDel(link, addr)
101101
if err != nil {
102102
return fmt.Errorf("error %s, %w", cmd, err)
@@ -106,7 +106,7 @@ func AddrDel(link netlink.Link, addr *netlink.Addr) error {
106106

107107
func AddrReplace(link netlink.Link, addr *netlink.Addr) error {
108108
cmd := fmt.Sprintf("ip addr replace %s dev %s", addr.IPNet.String(), link.Attrs().Name)
109-
Log.Infof(cmd)
109+
Log.Info(cmd)
110110
err := netlink.AddrReplace(link, addr)
111111
if err != nil {
112112
return fmt.Errorf("error %s, %w", cmd, err)
@@ -116,7 +116,7 @@ func AddrReplace(link netlink.Link, addr *netlink.Addr) error {
116116

117117
func RouteReplace(route *netlink.Route) error {
118118
cmd := fmt.Sprintf("ip route replace %s", route.String())
119-
Log.Infof(cmd)
119+
Log.Info(cmd)
120120
err := netlink.RouteReplace(route)
121121
if err != nil {
122122
return fmt.Errorf("error %s, %w", cmd, err)
@@ -126,7 +126,7 @@ func RouteReplace(route *netlink.Route) error {
126126

127127
func RouteDel(route *netlink.Route) error {
128128
cmd := fmt.Sprintf("ip route del %s", route.String())
129-
Log.Infof(cmd)
129+
Log.Info(cmd)
130130
err := netlink.RouteDel(route)
131131
if err != nil {
132132
return fmt.Errorf("error %s, %w", cmd, err)
@@ -136,7 +136,7 @@ func RouteDel(route *netlink.Route) error {
136136

137137
func NeighSet(neigh *netlink.Neigh) error {
138138
cmd := fmt.Sprintf("ip neigh replace %s", neigh.String())
139-
Log.Infof(cmd)
139+
Log.Info(cmd)
140140
err := netlink.NeighSet(neigh)
141141
if err != nil {
142142
return fmt.Errorf("error %s, %w", cmd, err)
@@ -146,7 +146,7 @@ func NeighSet(neigh *netlink.Neigh) error {
146146

147147
func RuleAdd(rule *netlink.Rule) error {
148148
cmd := fmt.Sprintf("ip rule add %s", rule.String())
149-
Log.Infof(cmd)
149+
Log.Info(cmd)
150150
err := netlink.RuleAdd(rule)
151151
if err != nil {
152152
return fmt.Errorf("error %s, %w", cmd, err)
@@ -156,7 +156,7 @@ func RuleAdd(rule *netlink.Rule) error {
156156

157157
func RuleDel(rule *netlink.Rule) error {
158158
cmd := fmt.Sprintf("ip rule del %s", rule.String())
159-
Log.Infof(cmd)
159+
Log.Info(cmd)
160160
err := netlink.RuleDel(rule)
161161
if err != nil {
162162
rule.IifName = ""
@@ -172,7 +172,7 @@ func RuleDel(rule *netlink.Rule) error {
172172

173173
func LinkSetNsFd(link netlink.Link, netNS ns.NetNS) error {
174174
cmd := fmt.Sprintf("ip link set %s netns %s", link.Attrs().Name, netNS.Path())
175-
Log.Infof(cmd)
175+
Log.Info(cmd)
176176
err := netlink.LinkSetNsFd(link, int(netNS.Fd()))
177177
if err != nil {
178178
return fmt.Errorf("error %s, %w", cmd, err)
@@ -182,7 +182,7 @@ func LinkSetNsFd(link netlink.Link, netNS ns.NetNS) error {
182182

183183
func QdiscReplace(qdisc netlink.Qdisc) error {
184184
cmd := fmt.Sprintf("tc qdisc replace %s", qdisc.Attrs().String())
185-
Log.Infof(cmd)
185+
Log.Info(cmd)
186186
err := netlink.QdiscReplace(qdisc)
187187
if err != nil {
188188
return fmt.Errorf("error %s, %w", cmd, err)
@@ -191,7 +191,7 @@ func QdiscReplace(qdisc netlink.Qdisc) error {
191191
}
192192
func QdiscDel(qdisc netlink.Qdisc) error {
193193
cmd := fmt.Sprintf("tc qdisc del %s", qdisc.Attrs().String())
194-
Log.Infof(cmd)
194+
Log.Info(cmd)
195195
err := netlink.QdiscDel(qdisc)
196196
if err != nil {
197197
return fmt.Errorf("error %s, %w", cmd, err)

Diff for: policy/cilium/0033-logging.patch

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: l1b0k <[email protected]>
3+
Date: Mon, 14 Oct 2024 16:33:42 +0800
4+
Subject: logging
5+
6+
Signed-off-by: l1b0k <[email protected]>
7+
---
8+
pkg/maps/ctmap/ctmap.go | 19 +++++++++++++------
9+
1 file changed, 13 insertions(+), 6 deletions(-)
10+
11+
diff --git a/pkg/maps/ctmap/ctmap.go b/pkg/maps/ctmap/ctmap.go
12+
index 868871811b..052cab28e9 100644
13+
--- a/pkg/maps/ctmap/ctmap.go
14+
+++ b/pkg/maps/ctmap/ctmap.go
15+
@@ -496,6 +496,13 @@ func doGC4(m *Map, filter *GCFilter) gcStats {
16+
globalDeleteLock[m.mapType].Lock()
17+
stats.dumpError = m.DumpReliablyWithCallback(filterCallback, stats.DumpStats)
18+
globalDeleteLock[m.mapType].Unlock()
19+
+
20+
+ log.Infof("gc map %s id %d max %d deleted %d alived %d", m.Name(), m.InnerID, m.MaxEntries, stats.deleted, stats.aliveEntries)
21+
+ cur := stats.aliveEntries + stats.deleted
22+
+ if float64(cur)/float64(m.MaxEntries) >= 0.9 {
23+
+ log.Infof("ConntrackFull table %s current %d maxEntries %d", m.Name(), cur, m.MaxEntries)
24+
+ }
25+
+
26+
return stats
27+
}
28+
29+
@@ -566,13 +573,13 @@ func GC(m *Map, filter *GCFilter) int {
30+
// The consumer of the buffer invokes the function.
31+
//
32+
// The SNAT is being used for the following cases:
33+
-// 1. By NodePort BPF on an intermediate node before fwd'ing request from outside
34+
+// 1. By NodePort BPF on an intermediate node before fwd'ing request from outside
35+
// to a destination node.
36+
-// 2. A packet from local endpoint sent to outside (BPF-masq).
37+
-// 3. A packet from a host local application (i.e. running in the host netns)
38+
-// This is needed to prevent SNAT from hijacking such connections.
39+
-// 4. By DSR on a backend node to SNAT responses with service IP+port before
40+
-// sending to a client.
41+
+// 2. A packet from local endpoint sent to outside (BPF-masq).
42+
+// 3. A packet from a host local application (i.e. running in the host netns)
43+
+// This is needed to prevent SNAT from hijacking such connections.
44+
+// 4. By DSR on a backend node to SNAT responses with service IP+port before
45+
+// sending to a client.
46+
//
47+
// In the case of 1-3, we always create a CT_EGRESS CT entry. This allows the
48+
// CT GC to remove corresponding SNAT entries. In the case of 4, will create
49+
--
50+
2.47.0
51+

0 commit comments

Comments
 (0)