28
28
29
29
type ContainerID string
30
30
31
+ type ContainerNetwork struct {
32
+ NetworkID string
33
+ }
34
+
31
35
type ContainerMetadata struct {
32
36
name string
33
37
labels map [string ]string
@@ -36,6 +40,7 @@ type ContainerMetadata struct {
36
40
image string
37
41
logDecoder logparser.Decoder
38
42
hostListens map [string ][]netaddr.IPPort
43
+ networks map [string ]ContainerNetwork
39
44
}
40
45
41
46
type Delays struct {
@@ -111,6 +116,7 @@ type Container struct {
111
116
isHostNs bool
112
117
hostConntrack * Conntrack
113
118
nsConntrack * Conntrack
119
+ lbConntracks []* Conntrack
114
120
115
121
lock sync.RWMutex
116
122
@@ -151,6 +157,17 @@ func NewContainer(id ContainerID, cg *cgroup.Cgroup, md *ContainerMetadata, host
151
157
done : make (chan struct {}),
152
158
}
153
159
160
+ for _ , n := range md .networks {
161
+ if nsHandle := FindNetworkLoadBalancerNs (n .NetworkID ); nsHandle .IsOpen () {
162
+ if ct , err := NewConntrack (nsHandle ); err != nil {
163
+ klog .Warningln (err )
164
+ } else {
165
+ c .lbConntracks = append (c .lbConntracks , ct )
166
+ }
167
+ _ = nsHandle .Close ()
168
+ }
169
+ }
170
+
154
171
c .runLogParser ("" )
155
172
156
173
go func () {
@@ -173,6 +190,9 @@ func (c *Container) Close() {
173
190
for _ , p := range c .logParsers {
174
191
p .Stop ()
175
192
}
193
+ for _ , ct := range c .lbConntracks {
194
+ _ = ct .Close ()
195
+ }
176
196
if c .nsConntrack != nil {
177
197
_ = c .nsConntrack .Close ()
178
198
}
@@ -477,6 +497,11 @@ func (c *Container) getActualDestination(pid uint32, src, dst netaddr.IPPort) (*
477
497
if actualDst := lookupCiliumConntrackTable (src , dst ); actualDst != nil {
478
498
return actualDst , nil
479
499
}
500
+ for _ , lb := range c .lbConntracks {
501
+ if actualDst := lb .GetActualDestination (src , dst ); actualDst != nil {
502
+ return actualDst , nil
503
+ }
504
+ }
480
505
actualDst := c .hostConntrack .GetActualDestination (src , dst )
481
506
if actualDst != nil {
482
507
return actualDst , nil
0 commit comments