Skip to content

Commit

Permalink
Merge pull request #125 from gardener/fix/ip6tnl-name
Browse files Browse the repository at this point in the history
Tunnelcontroller for HA: Fix ip6tnl suffix to use two last bytes
  • Loading branch information
DockToFuture authored Jan 14, 2025
2 parents a223fd9 + c2d2d7c commit 6d13a40
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions pkg/shoot_client/tunnel/tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ func (d *kubeApiserverData) update() {
d.lock.Lock()
defer d.lock.Unlock()

name := fmt.Sprintf("%s-ip6tnl-%02x", constants.BondDevice, d.remoteAddr[len(d.remoteAddr)-1])

name := d.linkName()
if err := network.DeleteLinkByName(name); err != nil {
d._setFailed(fmt.Errorf("failed to delete link %s: %w", name, err))
return
Expand Down Expand Up @@ -116,14 +115,20 @@ func (d *kubeApiserverData) delete() {
d.lock.Lock()
defer d.lock.Unlock()

name := fmt.Sprintf("%s-ip6tnl-%02x", constants.BondDevice, d.remoteAddr[len(d.remoteAddr)-1])
name := d.linkName()
if err := network.DeleteLinkByName(name); err != nil {
d.log.Error(err, "failed to delete old tunnel device", "name", name)
} else {
d.log.Info("tunnel device deleted", "name", name)
}
}

func (d *kubeApiserverData) linkName() string {
// link name must be unique, so we use the last two bytes of the remote address as it is chosen from a /112 range.
// The link name must be 15 characters or less in Linux.
return fmt.Sprintf("%sip6tnl%02x%02x", constants.BondDevice, d.remoteAddr[len(d.remoteAddr)-2], d.remoteAddr[len(d.remoteAddr)-1])
}

func (d *kubeApiserverData) _setFailed(err error) {
d.lastCreationFailed = ptr.To(time.Now())
d.creationFailedCount++
Expand Down Expand Up @@ -198,6 +203,12 @@ func (c *Controller) Run(log logr.Logger) error {
podIP: podIP,
}
c.kubeApiservers[key] = data
// edge case: if the remoteAddr was used by another kube-apiserver before and cleanup has not run yet, the entry must be removed
for k, d := range c.kubeApiservers {
if k != key && data.remoteAddr.Equal(d.remoteAddr) {
delete(c.kubeApiservers, k)
}
}
}
c.lock.Unlock()

Expand Down

0 comments on commit 6d13a40

Please sign in to comment.