Skip to content
This repository was archived by the owner on Jun 23, 2025. It is now read-only.

Commit 56abbfc

Browse files
authored
Make CNI DEL idempotent (#74)
* new Pod containerId attribute * add container_id to status subresource * add containerid handler * add containerID to cmdAdd and cmdDel * typo squashing * log text clarification * fix error message
1 parent beb2bbb commit 56abbfc

File tree

7 files changed

+263
-210
lines changed

7 files changed

+263
-210
lines changed

api/types/v1beta1/topology.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ type TopologySpec struct {
2424
}
2525

2626
type TopologyStatus struct {
27-
Skipped []string `json:"skipped"`
28-
SrcIP string `json:"src_ip"`
29-
NetNS string `json:"net_ns"`
27+
Skipped []string `json:"skipped"`
28+
SrcIP string `json:"src_ip"`
29+
NetNS string `json:"net_ns"`
30+
ContainerID string `json:"container_id"`
3031
}
3132

3233
type Link struct {

daemon/meshnet/handler.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ func (m *Meshnet) Get(ctx context.Context, pod *mpb.PodQuery) (*mpb.Pod, error)
6363

6464
srcIP, _, _ := unstructured.NestedString(result.Object, "status", "src_ip")
6565
netNs, _, _ := unstructured.NestedString(result.Object, "status", "net_ns")
66+
containerId, _, _ := unstructured.NestedString(result.Object, "status", "container_id")
6667
nodeIP := os.Getenv("HOST_IP")
6768
nodeIntf := os.Getenv("HOST_INTF")
6869

@@ -74,6 +75,7 @@ func (m *Meshnet) Get(ctx context.Context, pod *mpb.PodQuery) (*mpb.Pod, error)
7475
Links: links,
7576
NodeIp: nodeIP,
7677
NodeIntf: nodeIntf,
78+
ContainerId: containerId,
7779
}, nil
7880
}
7981

@@ -95,6 +97,10 @@ func (m *Meshnet) SetAlive(ctx context.Context, pod *mpb.Pod) (*mpb.BoolResponse
9597
mnetdLogger.Errorf("Failed to update pod's net_ns")
9698
}
9799

100+
if err = unstructured.SetNestedField(result.Object, pod.ContainerId, "status", "container_id"); err != nil {
101+
mnetdLogger.Errorf("Failed to update pod's container_id")
102+
}
103+
98104
return m.updateStatus(ctx, result, pod.KubeNs)
99105
})
100106

daemon/proto/meshnet/v1beta1/meshnet.pb.go

Lines changed: 163 additions & 153 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

daemon/proto/meshnet/v1beta1/meshnet.proto

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ message Pod {
1313
repeated Link links = 5;
1414
string node_ip = 6;
1515
string node_intf = 7;
16+
string container_id = 8;
1617
}
1718

1819
message Link {
@@ -54,8 +55,8 @@ message RemotePod {
5455
message WireDef {
5556
// The remote machine interface id, to which this wire is connected to.
5657
// When local machine sends a packet to remote mahcine over grpc-wire,
57-
// then along with the packet data, local machine also sends the interface id
58-
// to whihc this packet needs to delivered in remote machine. It avoids any
58+
// then along with the packet data, local machine also sends the interface id
59+
// to whihc this packet needs to delivered in remote machine. It avoids any
5960
// per packet interface lookup at the remote end. Packet delivery becomes
6061
// an O(1) operation at remote end.
6162
int64 peer_intf_id = 1;
@@ -66,12 +67,12 @@ message WireDef {
6667
// Interface name, which comes from topology definition and to be put
6768
// inside container.
6869
// This filed is used when grpc-wire to be created.
69-
string intf_name_in_pod = 3;
70+
string intf_name_in_pod = 3;
7071

7172
// Network name space of the local pod which is connected to this
7273
// grpc-wire
73-
string local_pod_net_ns = 4;
74-
74+
string local_pod_net_ns = 4;
75+
7576
// Each meshnet link has a uid.
7677
int64 link_uid = 5;
7778

@@ -87,7 +88,7 @@ message WireDef {
8788
string kube_ns = 8;
8889

8990
string local_pod_ip = 9;
90-
91+
9192
}
9293

9394
message WireCreateResponse {
@@ -101,8 +102,8 @@ message WireDownResponse {
101102
}
102103

103104
message Packet {
104-
// the remote machine interface id, to which this packet should be delivered.
105-
int64 remot_intf_id = 1;
105+
// the remote machine interface id, to which this packet should be delivered.
106+
int64 remot_intf_id = 1;
106107
bytes frame = 2;
107108
}
108109

@@ -114,7 +115,7 @@ message GenerateNodeInterfaceNameRequest {
114115

115116
message GenerateNodeInterfaceNameResponse {
116117
bool ok = 1;
117-
string node_intf_name = 2;
118+
string node_intf_name = 2;
118119
}
119120

120121
service Local {
@@ -124,12 +125,12 @@ service Local {
124125
rpc Skip (SkipQuery) returns (BoolResponse);
125126
rpc IsSkipped (SkipQuery) returns (BoolResponse);
126127

127-
rpc GRPCWireExists(WireDef) returns (WireCreateResponse);
128+
rpc GRPCWireExists(WireDef) returns (WireCreateResponse);
128129
rpc AddGRPCWireLocal(WireDef) returns (BoolResponse);
129130
rpc RemGRPCWire(WireDef) returns (BoolResponse);
130131

131-
// A node is going to hold multiple veth to connect to multiple containers.
132-
// Each veth name must be unique with in a node. Daemon generates an ID that
132+
// A node is going to hold multiple veth to connect to multiple containers.
133+
// Each veth name must be unique with in a node. Daemon generates an ID that
133134
// is unique in this node.
134135
rpc GenerateNodeInterfaceName(GenerateNodeInterfaceNameRequest) returns (GenerateNodeInterfaceNameResponse);
135136
}

0 commit comments

Comments
 (0)