Skip to content

Fix: unexpected log when pod is shutting down #1383

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

Merged
merged 2 commits into from
May 9, 2025
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
7 changes: 3 additions & 4 deletions bpf/kmesh/probes/probe.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ static inline void observe_on_close(struct bpf_sock *sk)

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

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

// Use BPF_LOCAL_STORAGE_GET_F_CREATE in case a connection being established before kmesh start.
storage = bpf_sk_storage_get(&map_of_sock_storage, sk, 0, BPF_LOCAL_STORAGE_GET_F_CREATE);
storage = bpf_sk_storage_get(&map_of_sock_storage, sk, 0, 0);
if (!storage) {
BPF_LOG(ERR, PROBE, "on data: bpf_sk_storage_get failed dst %u \n", bpf_ntohs(sk->dst_port));
// maybe the connection is established before kmesh start
return;
}
__u64 now = bpf_ktime_get_ns();
Expand Down
13 changes: 3 additions & 10 deletions bpf/kmesh/probes/tcp_probe.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,9 @@ static inline void get_tcp_probe_info(struct bpf_tcp_sock *tcp_sock, struct tcp_

// construct_orig_dst_info try to read the dst_info from map_of_sock_storage first
// if not found, use the tuple info for orig_dst
static inline void construct_orig_dst_info(struct bpf_sock *sk, struct tcp_probe_info *info)
static inline void
construct_orig_dst_info(struct bpf_sock *sk, struct sock_storage_data *storage, struct tcp_probe_info *info)
{
struct sock_storage_data *storage = NULL;
storage = bpf_sk_storage_get(&map_of_sock_storage, sk, 0, 0);
if (!storage) {
BPF_LOG(ERR, PROBE, "on close: bpf_sk_storage_get failed\n");
return;
}

if (sk->family == AF_INET) {
info->orig_dst.ipv4.addr = storage->sk_tuple.ipv4.daddr;
info->orig_dst.ipv4.port = bpf_ntohs(storage->sk_tuple.ipv4.dport);
Expand All @@ -136,7 +130,6 @@ static inline void construct_orig_dst_info(struct bpf_sock *sk, struct tcp_probe
static inline void
tcp_report(struct bpf_sock *sk, struct bpf_tcp_sock *tcp_sock, struct sock_storage_data *storage, __u32 state)
{
// struct connect_info *info = NULL;
struct tcp_probe_info *info = NULL;

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

construct_orig_dst_info(sk, info);
construct_orig_dst_info(sk, storage, info);
info->last_report_ns = bpf_ktime_get_ns();
info->duration = info->last_report_ns - storage->connect_ns;
storage->last_report_ns = info->last_report_ns;
Expand Down
11 changes: 10 additions & 1 deletion pkg/controller/manage/manage_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,15 @@
}

func (c *KmeshManageController) handlePodUpdate(_, newObj interface{}) {
pod, ok := newObj.(*corev1.Pod)
if !ok {
log.Errorf("expected *corev1.Pod but got %T", newObj)
return
}

Check warning on line 167 in pkg/controller/manage/manage_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/manage/manage_controller.go#L165-L167

Added lines #L165 - L167 were not covered by tests
if pod.DeletionTimestamp != nil {
log.Debugf("pod %s/%s is being deleted, skip remanage", pod.Namespace, pod.Name)
return
}

Check warning on line 171 in pkg/controller/manage/manage_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/manage/manage_controller.go#L169-L171

Added lines #L169 - L171 were not covered by tests
c.handlePodAdd(newObj)
}

Expand Down Expand Up @@ -229,7 +238,7 @@
log.Debugf("Pod %s/%s is not ready, skipping Kmesh manage enable", pod.GetNamespace(), pod.GetName())
return
}
log.Infof("%s/%s: enable Kmesh manage", pod.GetNamespace(), pod.GetName())
log.Debugf("%s/%s: enable Kmesh manage", pod.GetNamespace(), pod.GetName())
nspath, _ := ns.GetPodNSpath(pod)
if err := utils.HandleKmeshManage(nspath, true); err != nil {
log.Errorf("failed to enable Kmesh manage")
Expand Down
Loading