Skip to content

Commit

Permalink
resync provider network status periodically
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangzujian committed Feb 24, 2022
1 parent 172c173 commit 85c15cb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,7 @@ func (c *Controller) startWorkers(stopCh <-chan struct{}) {
}, 5*time.Second, stopCh)
}

go wait.Until(c.resyncProviderNetworkStatus, 30*time.Second, stopCh)
go wait.Until(c.resyncSubnetMetrics, 30*time.Second, stopCh)
go wait.Until(c.CheckGatewayReady, 5*time.Second, stopCh)

Expand Down
35 changes: 35 additions & 0 deletions pkg/controller/exporter.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package controller

import (
"context"
"math"
"sync"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/klog/v2"

kubeovnv1 "github.com/kubeovn/kube-ovn/pkg/apis/kubeovn/v1"
"github.com/kubeovn/kube-ovn/pkg/util"
)

var registerMetricsOnce sync.Once
Expand All @@ -19,6 +22,38 @@ func (c *Controller) registerSubnetMetrics() {
})
}

func (c *Controller) resyncProviderNetworkStatus() {
nodeList, err := c.nodesLister.List(labels.Everything())
if err != nil {
klog.Errorf("failed to get nodes %v", err)
return
}
pnList, err := c.providerNetworksLister.List(labels.Everything())
if err != nil {
klog.Errorf("failed to get provider networks %v", err)
return
}

for _, pn := range pnList {
ready := true
for _, node := range nodeList {
if !util.ContainsString(pn.Spec.ExcludeNodes, node.Name) &&
!util.ContainsString(pn.Status.ReadyNodes, node.Name) {
ready = false
break
}
}
if ready != pn.Status.Ready {
newPn := pn.DeepCopy()
newPn.Status.Ready = ready
_, err = c.config.KubeOvnClient.KubeovnV1().ProviderNetworks().Update(context.Background(), newPn, metav1.UpdateOptions{})
if err != nil {
klog.Errorf("failed to update provider network %s: %v", pn.Name, err)
}
}
}
}

// resyncSubnetMetrics start to update subnet metrics
func (c *Controller) resyncSubnetMetrics() {
c.exportSubnetMetrics()
Expand Down

0 comments on commit 85c15cb

Please sign in to comment.