Skip to content

Commit

Permalink
fix ip6tnl suffix to use two last bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinWeindel committed Jan 13, 2025
1 parent a223fd9 commit 6634462
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions pkg/shoot_client/tunnel/tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ 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, err := d.linkName()
if err != nil {
d._setFailed(err)
return
}

if err := network.DeleteLinkByName(name); err != nil {
d._setFailed(fmt.Errorf("failed to delete link %s: %w", name, err))
Expand Down Expand Up @@ -116,14 +120,27 @@ 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, err := d.linkName()
if err != nil {
d._setFailed(err)
return
}

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, error) {
s := fmt.Sprintf("%sip6tnl%02x%02x", constants.BondDevice, d.remoteAddr[len(d.remoteAddr)-2], d.remoteAddr[len(d.remoteAddr)-1])
if len(s) > 15 {
return "", fmt.Errorf("link name too long: %s", s)
}
return s, nil
}

func (d *kubeApiserverData) _setFailed(err error) {
d.lastCreationFailed = ptr.To(time.Now())
d.creationFailedCount++
Expand Down

0 comments on commit 6634462

Please sign in to comment.