|
| 1 | +diff --git a/mocks/pkg/ovs/interface.go b/mocks/pkg/ovs/interface.go |
| 2 | +index e9c472bee..59076f9ed 100644 |
| 3 | +--- a/mocks/pkg/ovs/interface.go |
| 4 | ++++ b/mocks/pkg/ovs/interface.go |
| 5 | +@@ -10,6 +10,7 @@ |
| 6 | + package ovs |
| 7 | + |
| 8 | + import ( |
| 9 | ++ context "context" |
| 10 | + reflect "reflect" |
| 11 | + |
| 12 | + v1 "github.com/kubeovn/kube-ovn/pkg/apis/kubeovn/v1" |
| 13 | +@@ -3322,6 +3323,20 @@ func (mr *MockNbClientMockRecorder) DeleteSecurityGroup(sgName any) *gomock.Call |
| 14 | + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteSecurityGroup", reflect.TypeOf((*MockNbClient)(nil).DeleteSecurityGroup), sgName) |
| 15 | + } |
| 16 | + |
| 17 | ++// Echo mocks base method. |
| 18 | ++func (m *MockNbClient) Echo(arg0 context.Context) error { |
| 19 | ++ m.ctrl.T.Helper() |
| 20 | ++ ret := m.ctrl.Call(m, "Echo", arg0) |
| 21 | ++ ret0, _ := ret[0].(error) |
| 22 | ++ return ret0 |
| 23 | ++} |
| 24 | ++ |
| 25 | ++// Echo indicates an expected call of Echo. |
| 26 | ++func (mr *MockNbClientMockRecorder) Echo(arg0 any) *gomock.Call { |
| 27 | ++ mr.mock.ctrl.T.Helper() |
| 28 | ++ return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Echo", reflect.TypeOf((*MockNbClient)(nil).Echo), arg0) |
| 29 | ++} |
| 30 | ++ |
| 31 | + // EnablePortLayer2forward mocks base method. |
| 32 | + func (m *MockNbClient) EnablePortLayer2forward(lspName string) error { |
| 33 | + m.ctrl.T.Helper() |
| 34 | +@@ -4770,6 +4785,20 @@ func (mr *MockSbClientMockRecorder) GetAllChassisByHost(nodeName any) *gomock.Ca |
| 35 | + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAllChassisByHost", reflect.TypeOf((*MockSbClient)(nil).GetAllChassisByHost), nodeName) |
| 36 | + } |
| 37 | + |
| 38 | ++// Echo mocks base method. |
| 39 | ++func (m *MockSbClient) Echo(arg0 context.Context) error { |
| 40 | ++ m.ctrl.T.Helper() |
| 41 | ++ ret := m.ctrl.Call(m, "Echo", arg0) |
| 42 | ++ ret0, _ := ret[0].(error) |
| 43 | ++ return ret0 |
| 44 | ++} |
| 45 | ++ |
| 46 | ++// Echo indicates an expected call of Echo. |
| 47 | ++func (mr *MockSbClientMockRecorder) Echo(arg0 any) *gomock.Call { |
| 48 | ++ mr.mock.ctrl.T.Helper() |
| 49 | ++ return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Echo", reflect.TypeOf((*MockSbClient)(nil).Echo), arg0) |
| 50 | ++} |
| 51 | ++ |
| 52 | + // GetChassis mocks base method. |
| 53 | + func (m *MockSbClient) GetChassis(chassisName string, ignoreNotFound bool) (*ovnsb.Chassis, error) { |
| 54 | + m.ctrl.T.Helper() |
| 55 | +@@ -4915,6 +4944,20 @@ func (m *MockCommon) EXPECT() *MockCommonMockRecorder { |
| 56 | + return m.recorder |
| 57 | + } |
| 58 | + |
| 59 | ++// Echo mocks base method. |
| 60 | ++func (m *MockCommon) Echo(arg0 context.Context) error { |
| 61 | ++ m.ctrl.T.Helper() |
| 62 | ++ ret := m.ctrl.Call(m, "Echo", arg0) |
| 63 | ++ ret0, _ := ret[0].(error) |
| 64 | ++ return ret0 |
| 65 | ++} |
| 66 | ++ |
| 67 | ++// Echo indicates an expected call of Echo. |
| 68 | ++func (mr *MockCommonMockRecorder) Echo(arg0 any) *gomock.Call { |
| 69 | ++ mr.mock.ctrl.T.Helper() |
| 70 | ++ return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Echo", reflect.TypeOf((*MockCommon)(nil).Echo), arg0) |
| 71 | ++} |
| 72 | ++ |
| 73 | + // GetEntityInfo mocks base method. |
| 74 | + func (m *MockCommon) GetEntityInfo(entity any) error { |
| 75 | + m.ctrl.T.Helper() |
| 76 | +diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go |
| 77 | +index cb594a4c8..a2a88eb06 100644 |
| 78 | +--- a/pkg/controller/controller.go |
| 79 | ++++ b/pkg/controller/controller.go |
| 80 | +@@ -268,6 +268,9 @@ type Controller struct { |
| 81 | + cmInformerFactory kubeinformers.SharedInformerFactory |
| 82 | + kubeovnInformerFactory kubeovninformer.SharedInformerFactory |
| 83 | + anpInformerFactory anpinformer.SharedInformerFactory |
| 84 | ++ |
| 85 | ++ // Database health check |
| 86 | ++ dbFailureCount int |
| 87 | + } |
| 88 | + |
| 89 | + func newTypedRateLimitingQueue[T comparable](name string, rateLimiter workqueue.TypedRateLimiter[T]) workqueue.TypedRateLimitingInterface[T] { |
| 90 | +@@ -944,6 +947,48 @@ func (c *Controller) Run(ctx context.Context) { |
| 91 | + klog.Info("Shutting down workers") |
| 92 | + } |
| 93 | + |
| 94 | ++func (c *Controller) dbStatus() { |
| 95 | ++ const maxFailures = 5 |
| 96 | ++ |
| 97 | ++ done := make(chan error, 2) |
| 98 | ++ go func() { |
| 99 | ++ done <- c.OVNNbClient.Echo(context.Background()) |
| 100 | ++ }() |
| 101 | ++ go func() { |
| 102 | ++ done <- c.OVNSbClient.Echo(context.Background()) |
| 103 | ++ }() |
| 104 | ++ |
| 105 | ++ resultsReceived := 0 |
| 106 | ++ timeout := time.After(time.Duration(c.config.OvnTimeout) * time.Second) |
| 107 | ++ |
| 108 | ++ for resultsReceived < 2 { |
| 109 | ++ select { |
| 110 | ++ case err := <-done: |
| 111 | ++ resultsReceived++ |
| 112 | ++ if err != nil { |
| 113 | ++ c.dbFailureCount++ |
| 114 | ++ klog.Errorf("OVN database echo failed (%d/%d): %v", c.dbFailureCount, maxFailures, err) |
| 115 | ++ if c.dbFailureCount >= maxFailures { |
| 116 | ++ util.LogFatalAndExit(err, "OVN database connection failed after %d attempts", maxFailures) |
| 117 | ++ } |
| 118 | ++ return |
| 119 | ++ } |
| 120 | ++ case <-timeout: |
| 121 | ++ c.dbFailureCount++ |
| 122 | ++ klog.Errorf("OVN database echo timeout (%d/%d) after %ds", c.dbFailureCount, maxFailures, c.config.OvnTimeout) |
| 123 | ++ if c.dbFailureCount >= maxFailures { |
| 124 | ++ util.LogFatalAndExit(nil, "OVN database connection timeout after %d attempts", maxFailures) |
| 125 | ++ } |
| 126 | ++ return |
| 127 | ++ } |
| 128 | ++ } |
| 129 | ++ |
| 130 | ++ if c.dbFailureCount > 0 { |
| 131 | ++ klog.Infof("OVN database connection recovered after %d failures", c.dbFailureCount) |
| 132 | ++ c.dbFailureCount = 0 |
| 133 | ++ } |
| 134 | ++} |
| 135 | ++ |
| 136 | + func (c *Controller) shutdown() { |
| 137 | + utilruntime.HandleCrash() |
| 138 | + |
| 139 | +@@ -1277,6 +1322,8 @@ func (c *Controller) startWorkers(ctx context.Context) { |
| 140 | + if c.config.EnableLiveMigrationOptimize { |
| 141 | + go wait.Until(runWorker("add/update vmiMigration ", c.addOrUpdateVMIMigrationQueue, c.handleAddOrUpdateVMIMigration), 50*time.Millisecond, ctx.Done()) |
| 142 | + } |
| 143 | ++ |
| 144 | ++ go wait.Until(c.dbStatus, 15*time.Second, ctx.Done()) |
| 145 | + } |
| 146 | + |
| 147 | + func (c *Controller) allSubnetReady(subnets ...string) (bool, error) { |
| 148 | +diff --git a/pkg/ovs/interface.go b/pkg/ovs/interface.go |
| 149 | +index df6907c4d..5e70dd6c7 100644 |
| 150 | +--- a/pkg/ovs/interface.go |
| 151 | ++++ b/pkg/ovs/interface.go |
| 152 | +@@ -1,6 +1,8 @@ |
| 153 | + package ovs |
| 154 | + |
| 155 | + import ( |
| 156 | ++ "context" |
| 157 | ++ |
| 158 | + netv1 "k8s.io/api/networking/v1" |
| 159 | + |
| 160 | + "github.com/ovn-org/libovsdb/ovsdb" |
| 161 | +@@ -235,6 +237,7 @@ type SbClient interface { |
| 162 | + } |
| 163 | + |
| 164 | + type Common interface { |
| 165 | ++ Echo(context.Context) error |
| 166 | + Transact(method string, operations []ovsdb.Operation) error |
| 167 | + GetEntityInfo(entity interface{}) error |
| 168 | + } |
0 commit comments