Skip to content

Commit

Permalink
Use WaitForLocalNodeReady in route agent main
Browse files Browse the repository at this point in the history
Signed-off-by: Tom Pantelis <[email protected]>
  • Loading branch information
tpantelis committed Nov 22, 2024
1 parent 1d2678b commit 6c046bc
Showing 1 changed file with 4 additions and 24 deletions.
28 changes: 4 additions & 24 deletions pkg/routeagent_driver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ import (
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/tools/clientcmd"
nodeutil "k8s.io/component-helpers/node/util"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
)
Expand Down Expand Up @@ -82,7 +81,7 @@ func main() {

logger.Info("Starting submariner-route-agent using the event framework")
// set up signals so we handle the first shutdown signal gracefully
stopCh := signals.SetupSignalHandler().Done()
ctx := signals.SetupSignalHandler()

// Clean up "sockets" created as directories by previous versions
removeInvalidSockets()
Expand Down Expand Up @@ -111,7 +110,7 @@ func main() {
logger.FatalOnError(err, "Error building the REST mapper")

if env.WaitForNode {
waitForNodeReady(k8sClientSet)
node.WaitForLocalNodeReady(ctx, k8sClientSet)

return
}
Expand Down Expand Up @@ -163,6 +162,8 @@ func main() {
})
logger.FatalOnError(err, "Error creating controller for event handling")

stopCh := ctx.Done()

err = ctl.Start(stopCh)
logger.FatalOnError(err, "Error starting controller")

Expand Down Expand Up @@ -211,27 +212,6 @@ func uninstall(registry *event.Registry) {
}
}

func waitForNodeReady(k8sClientSet *kubernetes.Clientset) {
// In most cases the node will already be ready; otherwise, wait for ever
for {
localNode, err := node.GetLocalNode(k8sClientSet)

if err != nil {
logger.Error(err, "Error retrieving local node")
} else if localNode != nil {
_, condition := nodeutil.GetNodeCondition(&localNode.Status, corev1.NodeReady)
if condition != nil && condition.Status == corev1.ConditionTrue {
logger.Info("Node ready")
return
}

logger.Infof("Node not ready, waiting: %v", localNode.Status)
}

time.Sleep(1 * time.Second)
}
}

func removeInvalidSockets() {
// This can be removed once we stop supporting upgrades from 0.16.0 or older
for _, dir := range []string{"/run/openvswitch/db.sock", "/var/run/openvswitch/ovnnb_db.sock", "/var/run/ovn-ic/ovnnb_db.sock"} {
Expand Down

0 comments on commit 6c046bc

Please sign in to comment.