Skip to content

Commit ed69807

Browse files
authored
Merge pull request #1383 from hzxuzhonghu/fix-graceful-shutdown
Fix: unexpected log when pod is shutting down
2 parents 8af0ce4 + 3dc6d64 commit ed69807

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

bpf/kmesh/probes/probe.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ static inline void observe_on_close(struct bpf_sock *sk)
7777

7878
storage = bpf_sk_storage_get(&map_of_sock_storage, sk, 0, 0);
7979
if (!storage) {
80-
BPF_LOG(ERR, PROBE, "on close: bpf_sk_storage_get failed\n");
80+
// maybe the connection is established before kmesh start
8181
return;
8282
}
8383

@@ -95,10 +95,9 @@ static inline void observe_on_data(struct bpf_sock *sk)
9595
if (!tcp_sock)
9696
return;
9797

98-
// Use BPF_LOCAL_STORAGE_GET_F_CREATE in case a connection being established before kmesh start.
99-
storage = bpf_sk_storage_get(&map_of_sock_storage, sk, 0, BPF_LOCAL_STORAGE_GET_F_CREATE);
98+
storage = bpf_sk_storage_get(&map_of_sock_storage, sk, 0, 0);
10099
if (!storage) {
101-
BPF_LOG(ERR, PROBE, "on data: bpf_sk_storage_get failed dst %u \n", bpf_ntohs(sk->dst_port));
100+
// maybe the connection is established before kmesh start
102101
return;
103102
}
104103
__u64 now = bpf_ktime_get_ns();

bpf/kmesh/probes/tcp_probe.h

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,9 @@ static inline void get_tcp_probe_info(struct bpf_tcp_sock *tcp_sock, struct tcp_
110110

111111
// construct_orig_dst_info try to read the dst_info from map_of_sock_storage first
112112
// if not found, use the tuple info for orig_dst
113-
static inline void construct_orig_dst_info(struct bpf_sock *sk, struct tcp_probe_info *info)
113+
static inline void
114+
construct_orig_dst_info(struct bpf_sock *sk, struct sock_storage_data *storage, struct tcp_probe_info *info)
114115
{
115-
struct sock_storage_data *storage = NULL;
116-
storage = bpf_sk_storage_get(&map_of_sock_storage, sk, 0, 0);
117-
if (!storage) {
118-
BPF_LOG(ERR, PROBE, "on close: bpf_sk_storage_get failed\n");
119-
return;
120-
}
121-
122116
if (sk->family == AF_INET) {
123117
info->orig_dst.ipv4.addr = storage->sk_tuple.ipv4.daddr;
124118
info->orig_dst.ipv4.port = bpf_ntohs(storage->sk_tuple.ipv4.dport);
@@ -136,7 +130,6 @@ static inline void construct_orig_dst_info(struct bpf_sock *sk, struct tcp_probe
136130
static inline void
137131
tcp_report(struct bpf_sock *sk, struct bpf_tcp_sock *tcp_sock, struct sock_storage_data *storage, __u32 state)
138132
{
139-
// struct connect_info *info = NULL;
140133
struct tcp_probe_info *info = NULL;
141134

142135
// store tuple
@@ -157,7 +150,7 @@ tcp_report(struct bpf_sock *sk, struct bpf_tcp_sock *tcp_sock, struct sock_stora
157150
(*info).type = IPV4;
158151
}
159152

160-
construct_orig_dst_info(sk, info);
153+
construct_orig_dst_info(sk, storage, info);
161154
info->last_report_ns = bpf_ktime_get_ns();
162155
info->duration = info->last_report_ns - storage->connect_ns;
163156
storage->last_report_ns = info->last_report_ns;

pkg/controller/manage/manage_controller.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,15 @@ func (c *KmeshManageController) handlePodAdd(obj interface{}) {
160160
}
161161

162162
func (c *KmeshManageController) handlePodUpdate(_, newObj interface{}) {
163+
pod, ok := newObj.(*corev1.Pod)
164+
if !ok {
165+
log.Errorf("expected *corev1.Pod but got %T", newObj)
166+
return
167+
}
168+
if pod.DeletionTimestamp != nil {
169+
log.Debugf("pod %s/%s is being deleted, skip remanage", pod.Namespace, pod.Name)
170+
return
171+
}
163172
c.handlePodAdd(newObj)
164173
}
165174

@@ -229,7 +238,7 @@ func (c *KmeshManageController) enableKmeshManage(pod *corev1.Pod) {
229238
log.Debugf("Pod %s/%s is not ready, skipping Kmesh manage enable", pod.GetNamespace(), pod.GetName())
230239
return
231240
}
232-
log.Infof("%s/%s: enable Kmesh manage", pod.GetNamespace(), pod.GetName())
241+
log.Debugf("%s/%s: enable Kmesh manage", pod.GetNamespace(), pod.GetName())
233242
nspath, _ := ns.GetPodNSpath(pod)
234243
if err := utils.HandleKmeshManage(nspath, true); err != nil {
235244
log.Errorf("failed to enable Kmesh manage")

0 commit comments

Comments
 (0)