Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid race condition when deleting HNS networks #5336

Merged
merged 1 commit into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/windows/calico.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ func (c *Calico) Start(ctx context.Context) error {
// generateCalicoNetworks creates the overlay networks for internode networking
func (c *Calico) generateCalicoNetworks() error {
if err := deleteAllNetworks(); err != nil {
return err
return errors.Wrapf(err, "failed to delete all networks before bootstrapping calico")
}

// There are four ways to select the vxlan interface. In order of priority:
Expand Down
22 changes: 22 additions & 0 deletions pkg/windows/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
opv1 "github.com/tigera/operator/api/v1"
"k8s.io/apimachinery/pkg/util/wait"
)

// createHnsNetwork creates the network that will connect nodes and returns its managementIP
Expand Down Expand Up @@ -101,15 +102,36 @@ func deleteAllNetworks() error {
return err
}

var ips []string

for _, network := range networks {
if network.Name != "nat" {
logrus.Debugf("Deleting network: %s before starting calico", network.Name)
ips = append(ips, network.ManagementIP)
_, err = network.Delete()
if err != nil {
return err
}
}
}

// HNS overlay networks restart the physical interface when they are deleted. Wait until it comes back before returning
// TODO: Replace with non-deprecated PollUntilContextTimeout when our and Kubernetes code migrate to it
waitErr := wait.Poll(2*time.Second, 20*time.Second, func() (bool, error) {
for _, ip := range ips {
logrus.Debugf("Calico is waiting for the interface with ip: %s to come back", ip)
_, err := findInterface(ip)
if err != nil {
return false, nil
}
}
return true, nil
})

if waitErr == wait.ErrWaitTimeout {
return fmt.Errorf("timed out waiting for the network interfaces to come back")
}

return nil
}

Expand Down
Loading