Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wait for taint to be gone in the node before starting the netpol cont…
Browse files Browse the repository at this point in the history
…roller

Signed-off-by: Manuel Buil <mbuil@suse.com>
manuelbuil committed Jan 3, 2024
1 parent 9411196 commit f5075b7
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions pkg/agent/netpol/netpol.go
Original file line number Diff line number Diff line change
@@ -11,6 +11,11 @@ import (
"runtime"
"strings"
"sync"
"time"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
cloudproviderapi "k8s.io/cloud-provider/api"

"github.com/cloudnativelabs/kube-router/v2/pkg/version"

@@ -55,6 +60,26 @@ func Run(ctx context.Context, nodeConfig *config.Node) error {
return err
}

// As kube-router netpol requires addresses to be available in the node object
// Wait until the node has ready addresses to avoid race conditions (max 1 minute).
// TODO: Replace with non-deprecated PollUntilContextTimeout when our and Kubernetes code migrate to it
wait.PollImmediateWithContext(ctx, 2*time.Second, 60*time.Second, func(ctx context.Context) (bool, error) {
// Get the node object
node, err := client.CoreV1().Nodes().Get(ctx, nodeConfig.AgentConfig.NodeName, metav1.GetOptions{})
if err != nil {
logrus.Errorf("Error getting the node object: %v", err)
return false, err
}
// Check for the uninitialized taint that should be removed by cloud-provider
// If there is no cloud-provider, the taint will not be there
for _, taint := range node.Spec.Taints {
if taint.Key == cloudproviderapi.TaintExternalCloudProvider {
return false, nil
}
}
return true, nil
})

krConfig := options.NewKubeRouterConfig()
var serviceIPs []string
for _, elem := range nodeConfig.AgentConfig.ServiceCIDRs {

0 comments on commit f5075b7

Please sign in to comment.