Skip to content

Commit 27e10e8

Browse files
Yongli Chentamilmani1989
authored andcommitted
handle empty string (#213)
1 parent 59ae2cd commit 27e10e8

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

network/endpoint_windows.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,23 @@ func (endpoint *EndpointInfo) HotAttachEndpoint(containerID string) error {
2222

2323
// ConstructEndpointID constructs endpoint name from netNsPath.
2424
func ConstructEndpointID(containerID string, netNsPath string, ifName string) (string, string) {
25-
infraEpName, workloadEpName := "", ""
26-
2725
if len(containerID) > 8 {
2826
containerID = containerID[:8]
2927
}
3028

31-
if netNsPath != "" {
32-
splits := strings.Split(netNsPath, ":")
29+
infraEpName, workloadEpName := "", ""
30+
31+
splits := strings.Split(netNsPath, ":")
32+
if len(splits) == 2 {
3333
// For workload containers, we extract its linking infrastructure container ID.
34-
if len(splits) == 2 {
35-
if len(splits[1]) > 8 {
36-
splits[1] = splits[1][:8]
37-
}
38-
infraEpName = splits[1] + "-" + ifName
39-
workloadEpName = containerID + "-" + ifName
40-
} else {
41-
// For infrastructure containers, we just use its container ID.
42-
infraEpName = containerID + "-" + ifName
34+
if len(splits[1]) > 8 {
35+
splits[1] = splits[1][:8]
4336
}
37+
infraEpName = splits[1] + "-" + ifName
38+
workloadEpName = containerID + "-" + ifName
39+
} else {
40+
// For infrastructure containers, we use its container ID directly.
41+
infraEpName = containerID + "-" + ifName
4442
}
4543

4644
return infraEpName, workloadEpName

0 commit comments

Comments
 (0)