Skip to content

Commit 8a06b9a

Browse files
naiming-zededarene
authored andcommitted
Fix: cluster-ip should not be part of the source ip for SendOnIntf
- fix an issue where in eve-k cluster mode, the cluster-intf can also be the management port, and the cluster-ip is in part of the AddrInfoList list on the interface to be used as the source ip address for communicating to the controller or northbound servers. - this patch introduces a separate ClusterIPAddr for zedkube to use for kubernetes cluster purpose Signed-off-by: naiming-zededa <naiming@zededa.com>
1 parent e9f4587 commit 8a06b9a

File tree

5 files changed

+22
-9
lines changed

5 files changed

+22
-9
lines changed

pkg/pillar/cmd/zedagent/reportinfo.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,9 @@ func encodeNetworkPortStatus(ctx *zedagentContext,
917917
for _, ipAddr := range port.AddrInfoList {
918918
devicePort.IPAddrs = append(devicePort.IPAddrs, ipAddr.Addr.String())
919919
}
920+
if port.ClusterIPAddr != nil {
921+
devicePort.IPAddrs = append(devicePort.IPAddrs, port.ClusterIPAddr.String())
922+
}
920923
// devicePort.Gateway is deprecated - replaced by DefaultRouters
921924
devicePort.DefaultRouters = utils.ToStrings(port.DefaultRouters)
922925
// devicePort.DNSServers is deprecated - replaced by Dns

pkg/pillar/cmd/zedkube/clusterstatus.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -211,13 +211,9 @@ func (z *zedkube) updateClusterIPReadiness() (changed bool) {
211211
if port.Logicallabel != z.clusterConfig.ClusterInterface {
212212
continue
213213
}
214-
for _, addr := range port.AddrInfoList {
215-
if addr.Addr.Equal(z.clusterConfig.ClusterIPPrefix.IP) {
216-
ready = true
217-
break
218-
}
219-
}
220-
if ready {
214+
if port.ClusterIPAddr != nil &&
215+
port.ClusterIPAddr.Equal(z.clusterConfig.ClusterIPPrefix.IP) {
216+
ready = true
221217
break
222218
}
223219
}
@@ -251,7 +247,6 @@ func (z *zedkube) startClusterStatusServer() {
251247
mux.HandleFunc("/cluster-app/", func(w http.ResponseWriter, r *http.Request) {
252248
z.clusterAppIDHandler(w, r)
253249
})
254-
255250
serverAddr := net.JoinHostPort(
256251
z.clusterConfig.ClusterIPPrefix.IP.String(), types.ClusterStatusPort)
257252
z.statusServer = &http.Server{

pkg/pillar/cmd/zedkube/kubeservice.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ func (z *zedkube) isDeviceInterfaceIP(ipStr string) bool {
333333

334334
// Check each port in deviceNetworkStatus
335335
for _, port := range z.deviceNetworkStatus.Ports {
336-
// Check each address in the port's AddrInfoList
336+
// Check regular addresses, and not include the ClusterIPAddr
337337
for _, addrInfo := range port.AddrInfoList {
338338
if addrInfo.Addr.Equal(ip) {
339339
log.Functionf("Found matching interface IP %s on port %s", ipStr, port.IfName)

pkg/pillar/dpcmanager/dns.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,12 @@ func (m *DpcManager) updateDNS() {
138138
// Below this point we collect L3-specific info for the port.
139139
if !port.IsL3Port {
140140
m.deviceNetStatus.Ports[ix].AddrInfoList = nil
141+
m.deviceNetStatus.Ports[ix].ClusterIPAddr = nil
141142
continue
142143
}
143144

144145
addrInfoList := make([]types.AddrInfo, 0, len(ipAddrs))
146+
var clusterIPAddr net.IP
145147
if len(ipAddrs) == 0 {
146148
m.Log.Functionf("updateDNS: interface %s has NO IP addresses", port.IfName)
147149
}
@@ -151,9 +153,18 @@ func (m *DpcManager) updateDNS() {
151153
// IP address received over DHCP is ignored.
152154
continue
153155
}
156+
// Cluster IP is kept separate from AddrInfoList — it is only
157+
// for inter-node communication and must not be used as a source
158+
// IP for controller-bound traffic.
159+
if m.clusterStatus.ClusterIPPrefix != nil &&
160+
m.clusterStatus.ClusterIPPrefix.Contains(addr.IP) {
161+
clusterIPAddr = addr.IP
162+
continue
163+
}
154164
addrInfoList = append(addrInfoList, types.AddrInfo{Addr: addr.IP})
155165
}
156166
m.deviceNetStatus.Ports[ix].AddrInfoList = addrInfoList
167+
m.deviceNetStatus.Ports[ix].ClusterIPAddr = clusterIPAddr
157168

158169
// Get DNS etc info from dhcpcd. Updates DomainName and DNSServers.
159170
err = m.getDHCPInfo(&m.deviceNetStatus.Ports[ix], port)

pkg/pillar/types/dns.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ type NetworkPortStatus struct {
5959
DNSServers []net.IP // from DHCP + static combined (with Gateway as fallback)
6060
NtpServers []netutils.HostnameOrIP // from DHCP + static combined
6161
AddrInfoList []AddrInfo // from DHCP + static combined
62+
ClusterIPAddr net.IP // ClusterIPAddr is the cluster IP address assigned to this port
6263
DefaultRouters []net.IP // from DHCP + static combined
6364
Up bool
6465
MacAddr net.HardwareAddr
@@ -262,6 +263,9 @@ func (status DeviceNetworkStatus) MostlyEqual(status2 DeviceNetworkStatus) bool
262263
}) {
263264
return false
264265
}
266+
if !p1.ClusterIPAddr.Equal(p2.ClusterIPAddr) {
267+
return false
268+
}
265269
if p1.Up != p2.Up ||
266270
!bytes.Equal(p1.MacAddr, p2.MacAddr) {
267271
return false

0 commit comments

Comments
 (0)