• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

kubeovn / kube-ovn / 30331632926

28 Jul 2026 05:25AM UTC coverage: 24.944% (+0.09%) from 24.855%
30331632926

Pull #7066

github

changluyi
ci: run metallb e2e with three nodes

Signed-off-by: clyi <clyi@alauda.io>
Pull Request #7066: [release-1.15] fix(metallb): preserve internal underlay VIP traffic

115 of 285 new or added lines in 6 files covered. (40.35%)

211 existing lines in 3 files now uncovered.

13866 of 55589 relevant lines covered (24.94%)

0.29 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

1.14
/pkg/controller/controller.go
1
package controller
2

3
import (
4
        "context"
5
        "fmt"
6
        "runtime"
7
        "strings"
8
        "sync"
9
        "sync/atomic"
10
        "time"
11

12
        netAttach "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/client/informers/externalversions"
13
        netAttachv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/client/listers/k8s.cni.cncf.io/v1"
14
        "github.com/puzpuzpuz/xsync/v4"
15
        "golang.org/x/time/rate"
16
        corev1 "k8s.io/api/core/v1"
17
        k8serrors "k8s.io/apimachinery/pkg/api/errors"
18
        metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
19
        "k8s.io/apimachinery/pkg/labels"
20
        utilruntime "k8s.io/apimachinery/pkg/util/runtime"
21
        "k8s.io/apimachinery/pkg/util/wait"
22
        "k8s.io/client-go/discovery"
23
        kubeinformers "k8s.io/client-go/informers"
24
        "k8s.io/client-go/kubernetes/scheme"
25
        typedcorev1 "k8s.io/client-go/kubernetes/typed/core/v1"
26
        appsv1 "k8s.io/client-go/listers/apps/v1"
27
        certListerv1 "k8s.io/client-go/listers/certificates/v1"
28
        v1 "k8s.io/client-go/listers/core/v1"
29
        discoveryv1 "k8s.io/client-go/listers/discovery/v1"
30
        netv1 "k8s.io/client-go/listers/networking/v1"
31
        "k8s.io/client-go/tools/cache"
32
        "k8s.io/client-go/tools/record"
33
        "k8s.io/client-go/util/workqueue"
34
        "k8s.io/klog/v2"
35
        "k8s.io/utils/keymutex"
36
        "k8s.io/utils/set"
37
        v1alpha1 "sigs.k8s.io/network-policy-api/apis/v1alpha1"
38
        netpolv1alpha2 "sigs.k8s.io/network-policy-api/apis/v1alpha2"
39
        anpinformer "sigs.k8s.io/network-policy-api/pkg/client/informers/externalversions"
40
        anplister "sigs.k8s.io/network-policy-api/pkg/client/listers/apis/v1alpha1"
41
        anplisterv1alpha2 "sigs.k8s.io/network-policy-api/pkg/client/listers/apis/v1alpha2"
42

43
        kubeovnv1 "github.com/kubeovn/kube-ovn/pkg/apis/kubeovn/v1"
44
        kubeovninformer "github.com/kubeovn/kube-ovn/pkg/client/informers/externalversions"
45
        kubeovnlister "github.com/kubeovn/kube-ovn/pkg/client/listers/kubeovn/v1"
46
        "github.com/kubeovn/kube-ovn/pkg/informer"
47
        ovnipam "github.com/kubeovn/kube-ovn/pkg/ipam"
48
        "github.com/kubeovn/kube-ovn/pkg/ovs"
49
        "github.com/kubeovn/kube-ovn/pkg/util"
50
)
51

52
const controllerAgentName = "kube-ovn-controller"
53

54
const (
55
        logicalSwitchKey              = "ls"
56
        logicalRouterKey              = "lr"
57
        portGroupKey                  = "pg"
58
        networkPolicyKey              = "np"
59
        sgKey                         = "sg"
60
        sgsKey                        = "security_groups"
61
        u2oKey                        = "u2o"
62
        adminNetworkPolicyKey         = "anp"
63
        baselineAdminNetworkPolicyKey = "banp"
64
        ippoolKey                     = "ippool"
65
        clusterNetworkPolicyKey       = "cnp"
66
)
67

68
// Controller is kube-ovn main controller that watch ns/pod/node/svc/ep and operate ovn
69
type Controller struct {
70
        config *Configuration
71

72
        ipam             *ovnipam.IPAM
73
        namedPort        *NamedPort
74
        anpPrioNameMap   map[int32]string
75
        anpNamePrioMap   map[string]int32
76
        bnpPrioNameMap   map[int32]string
77
        bnpNamePrioMap   map[string]int32
78
        priorityMapMutex sync.RWMutex
79

80
        OVNNbClient ovs.NbClient
81
        OVNSbClient ovs.SbClient
82

83
        // ExternalGatewayType define external gateway type, centralized
84
        ExternalGatewayType string
85

86
        podsLister             v1.PodLister
87
        podsSynced             cache.InformerSynced
88
        addOrUpdatePodQueue    workqueue.TypedRateLimitingInterface[string]
89
        deletePodQueue         workqueue.TypedRateLimitingInterface[string]
90
        deletingPodObjMap      *xsync.Map[string, *corev1.Pod]
91
        deletingNodeObjMap     *xsync.Map[string, *corev1.Node]
92
        updatePodSecurityQueue workqueue.TypedRateLimitingInterface[string]
93
        podKeyMutex            keymutex.KeyMutex
94

95
        vpcsLister           kubeovnlister.VpcLister
96
        vpcSynced            cache.InformerSynced
97
        addOrUpdateVpcQueue  workqueue.TypedRateLimitingInterface[string]
98
        vpcLastPoliciesMap   *xsync.Map[string, string]
99
        delVpcQueue          workqueue.TypedRateLimitingInterface[*kubeovnv1.Vpc]
100
        updateVpcStatusQueue workqueue.TypedRateLimitingInterface[string]
101
        vpcKeyMutex          keymutex.KeyMutex
102

103
        vpcNatGatewayLister           kubeovnlister.VpcNatGatewayLister
104
        vpcNatGatewaySynced           cache.InformerSynced
105
        addOrUpdateVpcNatGatewayQueue workqueue.TypedRateLimitingInterface[string]
106
        delVpcNatGatewayQueue         workqueue.TypedRateLimitingInterface[string]
107
        initVpcNatGatewayQueue        workqueue.TypedRateLimitingInterface[string]
108
        updateVpcEipQueue             workqueue.TypedRateLimitingInterface[string]
109
        updateVpcFloatingIPQueue      workqueue.TypedRateLimitingInterface[string]
110
        updateVpcDnatQueue            workqueue.TypedRateLimitingInterface[string]
111
        updateVpcSnatQueue            workqueue.TypedRateLimitingInterface[string]
112
        updateVpcSubnetQueue          workqueue.TypedRateLimitingInterface[string]
113
        vpcNatGwKeyMutex              keymutex.KeyMutex
114
        vpcNatGwExecKeyMutex          keymutex.KeyMutex
115

116
        vpcEgressGatewayLister           kubeovnlister.VpcEgressGatewayLister
117
        vpcEgressGatewaySynced           cache.InformerSynced
118
        addOrUpdateVpcEgressGatewayQueue workqueue.TypedRateLimitingInterface[string]
119
        delVpcEgressGatewayQueue         workqueue.TypedRateLimitingInterface[string]
120
        vpcEgressGatewayKeyMutex         keymutex.KeyMutex
121

122
        switchLBRuleLister      kubeovnlister.SwitchLBRuleLister
123
        switchLBRuleSynced      cache.InformerSynced
124
        addSwitchLBRuleQueue    workqueue.TypedRateLimitingInterface[string]
125
        updateSwitchLBRuleQueue workqueue.TypedRateLimitingInterface[*SlrInfo]
126
        delSwitchLBRuleQueue    workqueue.TypedRateLimitingInterface[*SlrInfo]
127

128
        vpcDNSLister           kubeovnlister.VpcDnsLister
129
        vpcDNSSynced           cache.InformerSynced
130
        addOrUpdateVpcDNSQueue workqueue.TypedRateLimitingInterface[string]
131
        delVpcDNSQueue         workqueue.TypedRateLimitingInterface[string]
132

133
        subnetsLister           kubeovnlister.SubnetLister
134
        subnetSynced            cache.InformerSynced
135
        addOrUpdateSubnetQueue  workqueue.TypedRateLimitingInterface[string]
136
        deleteSubnetQueue       workqueue.TypedRateLimitingInterface[*kubeovnv1.Subnet]
137
        updateSubnetStatusQueue workqueue.TypedRateLimitingInterface[string]
138
        syncVirtualPortsQueue   workqueue.TypedRateLimitingInterface[string]
139
        subnetKeyMutex          keymutex.KeyMutex
140

141
        ippoolLister            kubeovnlister.IPPoolLister
142
        ippoolSynced            cache.InformerSynced
143
        addOrUpdateIPPoolQueue  workqueue.TypedRateLimitingInterface[string]
144
        updateIPPoolStatusQueue workqueue.TypedRateLimitingInterface[string]
145
        deleteIPPoolQueue       workqueue.TypedRateLimitingInterface[*kubeovnv1.IPPool]
146
        ippoolKeyMutex          keymutex.KeyMutex
147

148
        ipsLister     kubeovnlister.IPLister
149
        ipSynced      cache.InformerSynced
150
        addIPQueue    workqueue.TypedRateLimitingInterface[string]
151
        updateIPQueue workqueue.TypedRateLimitingInterface[string]
152
        delIPQueue    workqueue.TypedRateLimitingInterface[*kubeovnv1.IP]
153

154
        virtualIpsLister          kubeovnlister.VipLister
155
        virtualIpsSynced          cache.InformerSynced
156
        addVirtualIPQueue         workqueue.TypedRateLimitingInterface[string]
157
        updateVirtualIPQueue      workqueue.TypedRateLimitingInterface[string]
158
        updateVirtualParentsQueue workqueue.TypedRateLimitingInterface[string]
159
        delVirtualIPQueue         workqueue.TypedRateLimitingInterface[*kubeovnv1.Vip]
160

161
        iptablesEipsLister     kubeovnlister.IptablesEIPLister
162
        iptablesEipSynced      cache.InformerSynced
163
        addIptablesEipQueue    workqueue.TypedRateLimitingInterface[string]
164
        updateIptablesEipQueue workqueue.TypedRateLimitingInterface[string]
165
        resetIptablesEipQueue  workqueue.TypedRateLimitingInterface[string]
166
        delIptablesEipQueue    workqueue.TypedRateLimitingInterface[*kubeovnv1.IptablesEIP]
167

168
        iptablesFipsLister     kubeovnlister.IptablesFIPRuleLister
169
        iptablesFipSynced      cache.InformerSynced
170
        addIptablesFipQueue    workqueue.TypedRateLimitingInterface[string]
171
        updateIptablesFipQueue workqueue.TypedRateLimitingInterface[string]
172
        delIptablesFipQueue    workqueue.TypedRateLimitingInterface[string]
173

174
        iptablesDnatRulesLister     kubeovnlister.IptablesDnatRuleLister
175
        iptablesDnatRuleSynced      cache.InformerSynced
176
        addIptablesDnatRuleQueue    workqueue.TypedRateLimitingInterface[string]
177
        updateIptablesDnatRuleQueue workqueue.TypedRateLimitingInterface[string]
178
        delIptablesDnatRuleQueue    workqueue.TypedRateLimitingInterface[string]
179

180
        iptablesSnatRulesLister     kubeovnlister.IptablesSnatRuleLister
181
        iptablesSnatRuleSynced      cache.InformerSynced
182
        addIptablesSnatRuleQueue    workqueue.TypedRateLimitingInterface[string]
183
        updateIptablesSnatRuleQueue workqueue.TypedRateLimitingInterface[string]
184
        delIptablesSnatRuleQueue    workqueue.TypedRateLimitingInterface[string]
185

186
        ovnEipsLister     kubeovnlister.OvnEipLister
187
        ovnEipSynced      cache.InformerSynced
188
        addOvnEipQueue    workqueue.TypedRateLimitingInterface[string]
189
        updateOvnEipQueue workqueue.TypedRateLimitingInterface[string]
190
        resetOvnEipQueue  workqueue.TypedRateLimitingInterface[string]
191
        delOvnEipQueue    workqueue.TypedRateLimitingInterface[*kubeovnv1.OvnEip]
192

193
        ovnFipsLister     kubeovnlister.OvnFipLister
194
        ovnFipSynced      cache.InformerSynced
195
        addOvnFipQueue    workqueue.TypedRateLimitingInterface[string]
196
        updateOvnFipQueue workqueue.TypedRateLimitingInterface[string]
197
        delOvnFipQueue    workqueue.TypedRateLimitingInterface[string]
198

199
        ovnSnatRulesLister     kubeovnlister.OvnSnatRuleLister
200
        ovnSnatRuleSynced      cache.InformerSynced
201
        addOvnSnatRuleQueue    workqueue.TypedRateLimitingInterface[string]
202
        updateOvnSnatRuleQueue workqueue.TypedRateLimitingInterface[string]
203
        delOvnSnatRuleQueue    workqueue.TypedRateLimitingInterface[string]
204

205
        ovnDnatRulesLister     kubeovnlister.OvnDnatRuleLister
206
        ovnDnatRuleSynced      cache.InformerSynced
207
        addOvnDnatRuleQueue    workqueue.TypedRateLimitingInterface[string]
208
        updateOvnDnatRuleQueue workqueue.TypedRateLimitingInterface[string]
209
        delOvnDnatRuleQueue    workqueue.TypedRateLimitingInterface[string]
210

211
        providerNetworksLister kubeovnlister.ProviderNetworkLister
212
        providerNetworkSynced  cache.InformerSynced
213

214
        vlansLister     kubeovnlister.VlanLister
215
        vlanSynced      cache.InformerSynced
216
        addVlanQueue    workqueue.TypedRateLimitingInterface[string]
217
        delVlanQueue    workqueue.TypedRateLimitingInterface[string]
218
        updateVlanQueue workqueue.TypedRateLimitingInterface[string]
219
        vlanKeyMutex    keymutex.KeyMutex
220

221
        namespacesLister  v1.NamespaceLister
222
        namespacesSynced  cache.InformerSynced
223
        addNamespaceQueue workqueue.TypedRateLimitingInterface[string]
224
        nsKeyMutex        keymutex.KeyMutex
225

226
        nodesLister     v1.NodeLister
227
        nodesSynced     cache.InformerSynced
228
        addNodeQueue    workqueue.TypedRateLimitingInterface[string]
229
        updateNodeQueue workqueue.TypedRateLimitingInterface[string]
230
        deleteNodeQueue workqueue.TypedRateLimitingInterface[string]
231
        nodeKeyMutex    keymutex.KeyMutex
232

233
        servicesLister     v1.ServiceLister
234
        serviceSynced      cache.InformerSynced
235
        addServiceQueue    workqueue.TypedRateLimitingInterface[string]
236
        deleteServiceQueue workqueue.TypedRateLimitingInterface[*vpcService]
237
        updateServiceQueue workqueue.TypedRateLimitingInterface[*updateSvcObject]
238
        svcKeyMutex        keymutex.KeyMutex
239

240
        endpointSlicesLister          discoveryv1.EndpointSliceLister
241
        endpointSlicesSynced          cache.InformerSynced
242
        addOrUpdateEndpointSliceQueue workqueue.TypedRateLimitingInterface[string]
243
        epKeyMutex                    keymutex.KeyMutex
244
        serviceL2StatusMutex          sync.RWMutex
245
        serviceL2StatusIndexer        cache.Indexer
246
        serviceL2StatusSynced         cache.InformerSynced
247
        serviceL2StatusStarted        bool
248

249
        deploymentsLister appsv1.DeploymentLister
250
        deploymentsSynced cache.InformerSynced
251

252
        npsLister     netv1.NetworkPolicyLister
253
        npsSynced     cache.InformerSynced
254
        updateNpQueue workqueue.TypedRateLimitingInterface[string]
255
        deleteNpQueue workqueue.TypedRateLimitingInterface[string]
256
        npKeyMutex    keymutex.KeyMutex
257

258
        sgsLister          kubeovnlister.SecurityGroupLister
259
        sgSynced           cache.InformerSynced
260
        addOrUpdateSgQueue workqueue.TypedRateLimitingInterface[string]
261
        delSgQueue         workqueue.TypedRateLimitingInterface[string]
262
        syncSgPortsQueue   workqueue.TypedRateLimitingInterface[string]
263
        sgKeyMutex         keymutex.KeyMutex
264

265
        qosPoliciesLister    kubeovnlister.QoSPolicyLister
266
        qosPolicySynced      cache.InformerSynced
267
        addQoSPolicyQueue    workqueue.TypedRateLimitingInterface[string]
268
        updateQoSPolicyQueue workqueue.TypedRateLimitingInterface[string]
269
        delQoSPolicyQueue    workqueue.TypedRateLimitingInterface[string]
270

271
        configMapsLister v1.ConfigMapLister
272
        configMapsSynced cache.InformerSynced
273

274
        anpsLister     anplister.AdminNetworkPolicyLister
275
        anpsSynced     cache.InformerSynced
276
        addAnpQueue    workqueue.TypedRateLimitingInterface[string]
277
        updateAnpQueue workqueue.TypedRateLimitingInterface[*AdminNetworkPolicyChangedDelta]
278
        deleteAnpQueue workqueue.TypedRateLimitingInterface[*v1alpha1.AdminNetworkPolicy]
279
        anpKeyMutex    keymutex.KeyMutex
280

281
        dnsNameResolversLister          kubeovnlister.DNSNameResolverLister
282
        dnsNameResolversSynced          cache.InformerSynced
283
        addOrUpdateDNSNameResolverQueue workqueue.TypedRateLimitingInterface[string]
284
        deleteDNSNameResolverQueue      workqueue.TypedRateLimitingInterface[*kubeovnv1.DNSNameResolver]
285

286
        banpsLister     anplister.BaselineAdminNetworkPolicyLister
287
        banpsSynced     cache.InformerSynced
288
        addBanpQueue    workqueue.TypedRateLimitingInterface[string]
289
        updateBanpQueue workqueue.TypedRateLimitingInterface[*AdminNetworkPolicyChangedDelta]
290
        deleteBanpQueue workqueue.TypedRateLimitingInterface[*v1alpha1.BaselineAdminNetworkPolicy]
291
        banpKeyMutex    keymutex.KeyMutex
292

293
        cnpsLister     anplisterv1alpha2.ClusterNetworkPolicyLister
294
        cnpsSynced     cache.InformerSynced
295
        addCnpQueue    workqueue.TypedRateLimitingInterface[string]
296
        updateCnpQueue workqueue.TypedRateLimitingInterface[*ClusterNetworkPolicyChangedDelta]
297
        deleteCnpQueue workqueue.TypedRateLimitingInterface[*netpolv1alpha2.ClusterNetworkPolicy]
298
        cnpKeyMutex    keymutex.KeyMutex
299

300
        csrLister           certListerv1.CertificateSigningRequestLister
301
        csrSynced           cache.InformerSynced
302
        addOrUpdateCsrQueue workqueue.TypedRateLimitingInterface[string]
303

304
        addOrUpdateVMIMigrationQueue workqueue.TypedRateLimitingInterface[string]
305
        deleteVMQueue                workqueue.TypedRateLimitingInterface[string]
306
        kubevirtInformerFactory      informer.KubeVirtInformerFactory
307

308
        netAttachLister          netAttachv1.NetworkAttachmentDefinitionLister
309
        netAttachSynced          cache.InformerSynced
310
        netAttachInformerFactory netAttach.SharedInformerFactory
311

312
        recorder               record.EventRecorder
313
        informerFactory        kubeinformers.SharedInformerFactory
314
        cmInformerFactory      kubeinformers.SharedInformerFactory
315
        deployInformerFactory  kubeinformers.SharedInformerFactory
316
        kubeovnInformerFactory kubeovninformer.SharedInformerFactory
317
        anpInformerFactory     anpinformer.SharedInformerFactory
318

319
        // Database health check
320
        dbFailureCount int
321

322
        distributedSubnetNeedSync atomic.Bool
323
}
324

325
func newTypedRateLimitingQueue[T comparable](name string, rateLimiter workqueue.TypedRateLimiter[T]) workqueue.TypedRateLimitingInterface[T] {
1✔
326
        if rateLimiter == nil {
2✔
327
                rateLimiter = workqueue.DefaultTypedControllerRateLimiter[T]()
1✔
328
        }
1✔
329
        return workqueue.NewTypedRateLimitingQueueWithConfig(rateLimiter, workqueue.TypedRateLimitingQueueConfig[T]{Name: name})
1✔
330
}
331

332
// Run creates and runs a new ovn controller
333
func Run(ctx context.Context, config *Configuration) {
×
334
        klog.V(4).Info("Creating event broadcaster")
×
335
        eventBroadcaster := record.NewBroadcasterWithCorrelatorOptions(record.CorrelatorOptions{BurstSize: 100})
×
336
        eventBroadcaster.StartLogging(klog.Infof)
×
337
        eventBroadcaster.StartRecordingToSink(&typedcorev1.EventSinkImpl{Interface: config.KubeFactoryClient.CoreV1().Events("")})
×
338
        recorder := eventBroadcaster.NewRecorder(scheme.Scheme, corev1.EventSource{Component: controllerAgentName})
×
339
        custCrdRateLimiter := workqueue.NewTypedMaxOfRateLimiter(
×
340
                workqueue.NewTypedItemExponentialFailureRateLimiter[string](time.Duration(config.CustCrdRetryMinDelay)*time.Second, time.Duration(config.CustCrdRetryMaxDelay)*time.Second),
×
341
                &workqueue.TypedBucketRateLimiter[string]{Limiter: rate.NewLimiter(rate.Limit(10), 100)},
×
342
        )
×
343

×
344
        selector, err := labels.Parse(util.VpcEgressGatewayLabel)
×
345
        if err != nil {
×
346
                util.LogFatalAndExit(err, "failed to create label selector for vpc egress gateway workload")
×
347
        }
×
348

349
        informerFactory := kubeinformers.NewSharedInformerFactoryWithOptions(config.KubeFactoryClient, 0,
×
350
                kubeinformers.WithTweakListOptions(func(listOption *metav1.ListOptions) {
×
351
                        listOption.AllowWatchBookmarks = true
×
352
                }))
×
353
        cmInformerFactory := kubeinformers.NewSharedInformerFactoryWithOptions(config.KubeFactoryClient, 0,
×
354
                kubeinformers.WithTweakListOptions(func(listOption *metav1.ListOptions) {
×
355
                        listOption.AllowWatchBookmarks = true
×
356
                }), kubeinformers.WithNamespace(config.PodNamespace))
×
357
        // deployment informer used to list/watch vpc egress gateway workloads
358
        deployInformerFactory := kubeinformers.NewSharedInformerFactoryWithOptions(config.KubeFactoryClient, 0,
×
359
                kubeinformers.WithTweakListOptions(func(listOption *metav1.ListOptions) {
×
360
                        listOption.AllowWatchBookmarks = true
×
361
                        listOption.LabelSelector = selector.String()
×
362
                }))
×
363
        kubeovnInformerFactory := kubeovninformer.NewSharedInformerFactoryWithOptions(config.KubeOvnFactoryClient, 0,
×
364
                kubeovninformer.WithTweakListOptions(func(listOption *metav1.ListOptions) {
×
365
                        listOption.AllowWatchBookmarks = true
×
366
                }))
×
367
        anpInformerFactory := anpinformer.NewSharedInformerFactoryWithOptions(config.AnpClient, 0,
×
368
                anpinformer.WithTweakListOptions(func(listOption *metav1.ListOptions) {
×
369
                        listOption.AllowWatchBookmarks = true
×
370
                }))
×
371

372
        attachNetInformerFactory := netAttach.NewSharedInformerFactoryWithOptions(config.AttachNetClient, 0,
×
373
                netAttach.WithTweakListOptions(func(listOption *metav1.ListOptions) {
×
374
                        listOption.AllowWatchBookmarks = true
×
375
                }),
×
376
        )
377

378
        kubevirtInformerFactory := informer.NewKubeVirtInformerFactory(config.KubevirtClient.RestClient(), config.KubevirtClient, nil, util.KubevirtNamespace)
×
379

×
380
        vpcInformer := kubeovnInformerFactory.Kubeovn().V1().Vpcs()
×
381
        vpcNatGatewayInformer := kubeovnInformerFactory.Kubeovn().V1().VpcNatGateways()
×
382
        vpcEgressGatewayInformer := kubeovnInformerFactory.Kubeovn().V1().VpcEgressGateways()
×
383
        subnetInformer := kubeovnInformerFactory.Kubeovn().V1().Subnets()
×
384
        ippoolInformer := kubeovnInformerFactory.Kubeovn().V1().IPPools()
×
385
        ipInformer := kubeovnInformerFactory.Kubeovn().V1().IPs()
×
386
        virtualIPInformer := kubeovnInformerFactory.Kubeovn().V1().Vips()
×
387
        iptablesEipInformer := kubeovnInformerFactory.Kubeovn().V1().IptablesEIPs()
×
388
        iptablesFipInformer := kubeovnInformerFactory.Kubeovn().V1().IptablesFIPRules()
×
389
        iptablesDnatRuleInformer := kubeovnInformerFactory.Kubeovn().V1().IptablesDnatRules()
×
390
        iptablesSnatRuleInformer := kubeovnInformerFactory.Kubeovn().V1().IptablesSnatRules()
×
391
        vlanInformer := kubeovnInformerFactory.Kubeovn().V1().Vlans()
×
392
        providerNetworkInformer := kubeovnInformerFactory.Kubeovn().V1().ProviderNetworks()
×
393
        sgInformer := kubeovnInformerFactory.Kubeovn().V1().SecurityGroups()
×
394
        podInformer := informerFactory.Core().V1().Pods()
×
395
        namespaceInformer := informerFactory.Core().V1().Namespaces()
×
396
        nodeInformer := informerFactory.Core().V1().Nodes()
×
397
        serviceInformer := informerFactory.Core().V1().Services()
×
398
        endpointSliceInformer := informerFactory.Discovery().V1().EndpointSlices()
×
399
        deploymentInformer := deployInformerFactory.Apps().V1().Deployments()
×
400
        qosPolicyInformer := kubeovnInformerFactory.Kubeovn().V1().QoSPolicies()
×
401
        configMapInformer := cmInformerFactory.Core().V1().ConfigMaps()
×
402
        npInformer := informerFactory.Networking().V1().NetworkPolicies()
×
403
        switchLBRuleInformer := kubeovnInformerFactory.Kubeovn().V1().SwitchLBRules()
×
404
        vpcDNSInformer := kubeovnInformerFactory.Kubeovn().V1().VpcDnses()
×
405
        ovnEipInformer := kubeovnInformerFactory.Kubeovn().V1().OvnEips()
×
406
        ovnFipInformer := kubeovnInformerFactory.Kubeovn().V1().OvnFips()
×
407
        ovnSnatRuleInformer := kubeovnInformerFactory.Kubeovn().V1().OvnSnatRules()
×
408
        ovnDnatRuleInformer := kubeovnInformerFactory.Kubeovn().V1().OvnDnatRules()
×
409
        anpInformer := anpInformerFactory.Policy().V1alpha1().AdminNetworkPolicies()
×
410
        banpInformer := anpInformerFactory.Policy().V1alpha1().BaselineAdminNetworkPolicies()
×
411
        cnpInformer := anpInformerFactory.Policy().V1alpha2().ClusterNetworkPolicies()
×
412
        dnsNameResolverInformer := kubeovnInformerFactory.Kubeovn().V1().DNSNameResolvers()
×
413
        csrInformer := informerFactory.Certificates().V1().CertificateSigningRequests()
×
414
        netAttachInformer := attachNetInformerFactory.K8sCniCncfIo().V1().NetworkAttachmentDefinitions()
×
415

×
416
        numKeyLocks := max(runtime.NumCPU()*2, config.WorkerNum*2)
×
417
        controller := &Controller{
×
418
                config:             config,
×
419
                deletingPodObjMap:  xsync.NewMap[string, *corev1.Pod](),
×
420
                deletingNodeObjMap: xsync.NewMap[string, *corev1.Node](),
×
421
                ipam:               ovnipam.NewIPAM(),
×
422
                namedPort:          NewNamedPort(),
×
423

×
424
                vpcsLister:           vpcInformer.Lister(),
×
425
                vpcSynced:            vpcInformer.Informer().HasSynced,
×
426
                addOrUpdateVpcQueue:  newTypedRateLimitingQueue[string]("AddOrUpdateVpc", nil),
×
427
                vpcLastPoliciesMap:   xsync.NewMap[string, string](),
×
428
                delVpcQueue:          newTypedRateLimitingQueue[*kubeovnv1.Vpc]("DeleteVpc", nil),
×
429
                updateVpcStatusQueue: newTypedRateLimitingQueue[string]("UpdateVpcStatus", nil),
×
430
                vpcKeyMutex:          keymutex.NewHashed(numKeyLocks),
×
431

×
432
                vpcNatGatewayLister:              vpcNatGatewayInformer.Lister(),
×
433
                vpcNatGatewaySynced:              vpcNatGatewayInformer.Informer().HasSynced,
×
434
                addOrUpdateVpcNatGatewayQueue:    newTypedRateLimitingQueue("AddOrUpdateVpcNatGw", custCrdRateLimiter),
×
435
                initVpcNatGatewayQueue:           newTypedRateLimitingQueue("InitVpcNatGw", custCrdRateLimiter),
×
436
                delVpcNatGatewayQueue:            newTypedRateLimitingQueue("DeleteVpcNatGw", custCrdRateLimiter),
×
437
                updateVpcEipQueue:                newTypedRateLimitingQueue("UpdateVpcEip", custCrdRateLimiter),
×
438
                updateVpcFloatingIPQueue:         newTypedRateLimitingQueue("UpdateVpcFloatingIp", custCrdRateLimiter),
×
439
                updateVpcDnatQueue:               newTypedRateLimitingQueue("UpdateVpcDnat", custCrdRateLimiter),
×
440
                updateVpcSnatQueue:               newTypedRateLimitingQueue("UpdateVpcSnat", custCrdRateLimiter),
×
441
                updateVpcSubnetQueue:             newTypedRateLimitingQueue("UpdateVpcSubnet", custCrdRateLimiter),
×
442
                vpcNatGwKeyMutex:                 keymutex.NewHashed(numKeyLocks),
×
443
                vpcNatGwExecKeyMutex:             keymutex.NewHashed(numKeyLocks),
×
444
                vpcEgressGatewayLister:           vpcEgressGatewayInformer.Lister(),
×
445
                vpcEgressGatewaySynced:           vpcEgressGatewayInformer.Informer().HasSynced,
×
446
                addOrUpdateVpcEgressGatewayQueue: newTypedRateLimitingQueue("AddOrUpdateVpcEgressGateway", custCrdRateLimiter),
×
447
                delVpcEgressGatewayQueue:         newTypedRateLimitingQueue("DeleteVpcEgressGateway", custCrdRateLimiter),
×
448
                vpcEgressGatewayKeyMutex:         keymutex.NewHashed(numKeyLocks),
×
449

×
450
                subnetsLister:           subnetInformer.Lister(),
×
451
                subnetSynced:            subnetInformer.Informer().HasSynced,
×
452
                addOrUpdateSubnetQueue:  newTypedRateLimitingQueue[string]("AddSubnet", nil),
×
453
                deleteSubnetQueue:       newTypedRateLimitingQueue[*kubeovnv1.Subnet]("DeleteSubnet", nil),
×
454
                updateSubnetStatusQueue: newTypedRateLimitingQueue[string]("UpdateSubnetStatus", nil),
×
455
                syncVirtualPortsQueue:   newTypedRateLimitingQueue[string]("SyncVirtualPort", nil),
×
456
                subnetKeyMutex:          keymutex.NewHashed(numKeyLocks),
×
457

×
458
                ippoolLister:            ippoolInformer.Lister(),
×
459
                ippoolSynced:            ippoolInformer.Informer().HasSynced,
×
460
                addOrUpdateIPPoolQueue:  newTypedRateLimitingQueue[string]("AddIPPool", nil),
×
461
                updateIPPoolStatusQueue: newTypedRateLimitingQueue[string]("UpdateIPPoolStatus", nil),
×
462
                deleteIPPoolQueue:       newTypedRateLimitingQueue[*kubeovnv1.IPPool]("DeleteIPPool", nil),
×
463
                ippoolKeyMutex:          keymutex.NewHashed(numKeyLocks),
×
464

×
465
                ipsLister:     ipInformer.Lister(),
×
466
                ipSynced:      ipInformer.Informer().HasSynced,
×
467
                addIPQueue:    newTypedRateLimitingQueue[string]("AddIP", nil),
×
468
                updateIPQueue: newTypedRateLimitingQueue[string]("UpdateIP", nil),
×
469
                delIPQueue:    newTypedRateLimitingQueue[*kubeovnv1.IP]("DeleteIP", nil),
×
470

×
471
                virtualIpsLister:          virtualIPInformer.Lister(),
×
472
                virtualIpsSynced:          virtualIPInformer.Informer().HasSynced,
×
473
                addVirtualIPQueue:         newTypedRateLimitingQueue[string]("AddVirtualIP", nil),
×
474
                updateVirtualIPQueue:      newTypedRateLimitingQueue[string]("UpdateVirtualIP", nil),
×
475
                updateVirtualParentsQueue: newTypedRateLimitingQueue[string]("UpdateVirtualParents", nil),
×
476
                delVirtualIPQueue:         newTypedRateLimitingQueue[*kubeovnv1.Vip]("DeleteVirtualIP", nil),
×
477

×
478
                iptablesEipsLister:     iptablesEipInformer.Lister(),
×
479
                iptablesEipSynced:      iptablesEipInformer.Informer().HasSynced,
×
480
                addIptablesEipQueue:    newTypedRateLimitingQueue("AddIptablesEip", custCrdRateLimiter),
×
481
                updateIptablesEipQueue: newTypedRateLimitingQueue("UpdateIptablesEip", custCrdRateLimiter),
×
482
                resetIptablesEipQueue:  newTypedRateLimitingQueue("ResetIptablesEip", custCrdRateLimiter),
×
483
                delIptablesEipQueue:    newTypedRateLimitingQueue[*kubeovnv1.IptablesEIP]("DeleteIptablesEip", nil),
×
484

×
485
                iptablesFipsLister:     iptablesFipInformer.Lister(),
×
486
                iptablesFipSynced:      iptablesFipInformer.Informer().HasSynced,
×
487
                addIptablesFipQueue:    newTypedRateLimitingQueue("AddIptablesFip", custCrdRateLimiter),
×
488
                updateIptablesFipQueue: newTypedRateLimitingQueue("UpdateIptablesFip", custCrdRateLimiter),
×
489
                delIptablesFipQueue:    newTypedRateLimitingQueue("DeleteIptablesFip", custCrdRateLimiter),
×
490

×
491
                iptablesDnatRulesLister:     iptablesDnatRuleInformer.Lister(),
×
492
                iptablesDnatRuleSynced:      iptablesDnatRuleInformer.Informer().HasSynced,
×
493
                addIptablesDnatRuleQueue:    newTypedRateLimitingQueue("AddIptablesDnatRule", custCrdRateLimiter),
×
494
                updateIptablesDnatRuleQueue: newTypedRateLimitingQueue("UpdateIptablesDnatRule", custCrdRateLimiter),
×
495
                delIptablesDnatRuleQueue:    newTypedRateLimitingQueue("DeleteIptablesDnatRule", custCrdRateLimiter),
×
496

×
497
                iptablesSnatRulesLister:     iptablesSnatRuleInformer.Lister(),
×
498
                iptablesSnatRuleSynced:      iptablesSnatRuleInformer.Informer().HasSynced,
×
499
                addIptablesSnatRuleQueue:    newTypedRateLimitingQueue("AddIptablesSnatRule", custCrdRateLimiter),
×
500
                updateIptablesSnatRuleQueue: newTypedRateLimitingQueue("UpdateIptablesSnatRule", custCrdRateLimiter),
×
501
                delIptablesSnatRuleQueue:    newTypedRateLimitingQueue("DeleteIptablesSnatRule", custCrdRateLimiter),
×
502

×
503
                vlansLister:     vlanInformer.Lister(),
×
504
                vlanSynced:      vlanInformer.Informer().HasSynced,
×
505
                addVlanQueue:    newTypedRateLimitingQueue[string]("AddVlan", nil),
×
506
                delVlanQueue:    newTypedRateLimitingQueue[string]("DeleteVlan", nil),
×
507
                updateVlanQueue: newTypedRateLimitingQueue[string]("UpdateVlan", nil),
×
508
                vlanKeyMutex:    keymutex.NewHashed(numKeyLocks),
×
509

×
510
                providerNetworksLister: providerNetworkInformer.Lister(),
×
511
                providerNetworkSynced:  providerNetworkInformer.Informer().HasSynced,
×
512

×
513
                podsLister:          podInformer.Lister(),
×
514
                podsSynced:          podInformer.Informer().HasSynced,
×
515
                addOrUpdatePodQueue: newTypedRateLimitingQueue[string]("AddOrUpdatePod", nil),
×
516
                deletePodQueue: workqueue.NewTypedRateLimitingQueueWithConfig(
×
517
                        workqueue.DefaultTypedControllerRateLimiter[string](),
×
518
                        workqueue.TypedRateLimitingQueueConfig[string]{
×
519
                                Name:          "DeletePod",
×
520
                                DelayingQueue: workqueue.NewTypedDelayingQueue[string](),
×
521
                        },
×
522
                ),
×
523
                updatePodSecurityQueue: newTypedRateLimitingQueue[string]("UpdatePodSecurity", nil),
×
524
                podKeyMutex:            keymutex.NewHashed(numKeyLocks),
×
525

×
526
                namespacesLister:  namespaceInformer.Lister(),
×
527
                namespacesSynced:  namespaceInformer.Informer().HasSynced,
×
528
                addNamespaceQueue: newTypedRateLimitingQueue[string]("AddNamespace", nil),
×
529
                nsKeyMutex:        keymutex.NewHashed(numKeyLocks),
×
530

×
531
                nodesLister:     nodeInformer.Lister(),
×
532
                nodesSynced:     nodeInformer.Informer().HasSynced,
×
533
                addNodeQueue:    newTypedRateLimitingQueue[string]("AddNode", nil),
×
534
                updateNodeQueue: newTypedRateLimitingQueue[string]("UpdateNode", nil),
×
535
                deleteNodeQueue: newTypedRateLimitingQueue[string]("DeleteNode", nil),
×
536
                nodeKeyMutex:    keymutex.NewHashed(numKeyLocks),
×
537

×
538
                servicesLister:     serviceInformer.Lister(),
×
539
                serviceSynced:      serviceInformer.Informer().HasSynced,
×
540
                addServiceQueue:    newTypedRateLimitingQueue[string]("AddService", nil),
×
541
                deleteServiceQueue: newTypedRateLimitingQueue[*vpcService]("DeleteService", nil),
×
542
                updateServiceQueue: newTypedRateLimitingQueue[*updateSvcObject]("UpdateService", nil),
×
543
                svcKeyMutex:        keymutex.NewHashed(numKeyLocks),
×
544

×
545
                endpointSlicesLister:          endpointSliceInformer.Lister(),
×
546
                endpointSlicesSynced:          endpointSliceInformer.Informer().HasSynced,
×
547
                addOrUpdateEndpointSliceQueue: newTypedRateLimitingQueue[string]("UpdateEndpointSlice", nil),
×
548
                epKeyMutex:                    keymutex.NewHashed(numKeyLocks),
×
549

×
550
                deploymentsLister: deploymentInformer.Lister(),
×
551
                deploymentsSynced: deploymentInformer.Informer().HasSynced,
×
552

×
553
                qosPoliciesLister:    qosPolicyInformer.Lister(),
×
554
                qosPolicySynced:      qosPolicyInformer.Informer().HasSynced,
×
555
                addQoSPolicyQueue:    newTypedRateLimitingQueue("AddQoSPolicy", custCrdRateLimiter),
×
556
                updateQoSPolicyQueue: newTypedRateLimitingQueue("UpdateQoSPolicy", custCrdRateLimiter),
×
557
                delQoSPolicyQueue:    newTypedRateLimitingQueue("DeleteQoSPolicy", custCrdRateLimiter),
×
558

×
559
                configMapsLister: configMapInformer.Lister(),
×
560
                configMapsSynced: configMapInformer.Informer().HasSynced,
×
561

×
562
                sgKeyMutex:         keymutex.NewHashed(numKeyLocks),
×
563
                sgsLister:          sgInformer.Lister(),
×
564
                sgSynced:           sgInformer.Informer().HasSynced,
×
565
                addOrUpdateSgQueue: newTypedRateLimitingQueue[string]("UpdateSecurityGroup", nil),
×
566
                delSgQueue:         newTypedRateLimitingQueue[string]("DeleteSecurityGroup", nil),
×
567
                syncSgPortsQueue:   newTypedRateLimitingQueue[string]("SyncSecurityGroupPorts", nil),
×
568

×
569
                ovnEipsLister:     ovnEipInformer.Lister(),
×
570
                ovnEipSynced:      ovnEipInformer.Informer().HasSynced,
×
571
                addOvnEipQueue:    newTypedRateLimitingQueue("AddOvnEip", custCrdRateLimiter),
×
572
                updateOvnEipQueue: newTypedRateLimitingQueue("UpdateOvnEip", custCrdRateLimiter),
×
573
                resetOvnEipQueue:  newTypedRateLimitingQueue("ResetOvnEip", custCrdRateLimiter),
×
574
                delOvnEipQueue:    newTypedRateLimitingQueue[*kubeovnv1.OvnEip]("DeleteOvnEip", nil),
×
575

×
576
                ovnFipsLister:     ovnFipInformer.Lister(),
×
577
                ovnFipSynced:      ovnFipInformer.Informer().HasSynced,
×
578
                addOvnFipQueue:    newTypedRateLimitingQueue("AddOvnFip", custCrdRateLimiter),
×
579
                updateOvnFipQueue: newTypedRateLimitingQueue("UpdateOvnFip", custCrdRateLimiter),
×
580
                delOvnFipQueue:    newTypedRateLimitingQueue("DeleteOvnFip", custCrdRateLimiter),
×
581

×
582
                ovnSnatRulesLister:     ovnSnatRuleInformer.Lister(),
×
583
                ovnSnatRuleSynced:      ovnSnatRuleInformer.Informer().HasSynced,
×
584
                addOvnSnatRuleQueue:    newTypedRateLimitingQueue("AddOvnSnatRule", custCrdRateLimiter),
×
585
                updateOvnSnatRuleQueue: newTypedRateLimitingQueue("UpdateOvnSnatRule", custCrdRateLimiter),
×
586
                delOvnSnatRuleQueue:    newTypedRateLimitingQueue("DeleteOvnSnatRule", custCrdRateLimiter),
×
587

×
588
                ovnDnatRulesLister:     ovnDnatRuleInformer.Lister(),
×
589
                ovnDnatRuleSynced:      ovnDnatRuleInformer.Informer().HasSynced,
×
590
                addOvnDnatRuleQueue:    newTypedRateLimitingQueue("AddOvnDnatRule", custCrdRateLimiter),
×
591
                updateOvnDnatRuleQueue: newTypedRateLimitingQueue("UpdateOvnDnatRule", custCrdRateLimiter),
×
592
                delOvnDnatRuleQueue:    newTypedRateLimitingQueue("DeleteOvnDnatRule", custCrdRateLimiter),
×
593

×
594
                csrLister:           csrInformer.Lister(),
×
595
                csrSynced:           csrInformer.Informer().HasSynced,
×
596
                addOrUpdateCsrQueue: newTypedRateLimitingQueue("AddOrUpdateCSR", custCrdRateLimiter),
×
597

×
598
                addOrUpdateVMIMigrationQueue: newTypedRateLimitingQueue[string]("AddOrUpdateVMIMigration", nil),
×
599
                deleteVMQueue:                newTypedRateLimitingQueue[string]("DeleteVM", nil),
×
600
                kubevirtInformerFactory:      kubevirtInformerFactory,
×
601

×
602
                netAttachLister:          netAttachInformer.Lister(),
×
603
                netAttachSynced:          netAttachInformer.Informer().HasSynced,
×
604
                netAttachInformerFactory: attachNetInformerFactory,
×
605

×
606
                recorder:               recorder,
×
607
                informerFactory:        informerFactory,
×
608
                cmInformerFactory:      cmInformerFactory,
×
609
                deployInformerFactory:  deployInformerFactory,
×
610
                kubeovnInformerFactory: kubeovnInformerFactory,
×
611
                anpInformerFactory:     anpInformerFactory,
×
612
        }
×
613

×
614
        if controller.OVNNbClient, err = ovs.NewOvnNbClient(
×
615
                config.OvnNbAddr,
×
616
                config.OvnTimeout,
×
617
                config.OvsDbConnectTimeout,
×
618
                config.OvsDbInactivityTimeout,
×
619
                config.OvsDbConnectMaxRetry,
×
620
        ); err != nil {
×
621
                util.LogFatalAndExit(err, "failed to create ovn nb client")
×
622
        }
×
623
        if controller.OVNSbClient, err = ovs.NewOvnSbClient(
×
624
                config.OvnSbAddr,
×
625
                config.OvnTimeout,
×
626
                config.OvsDbConnectTimeout,
×
627
                config.OvsDbInactivityTimeout,
×
628
                config.OvsDbConnectMaxRetry,
×
629
        ); err != nil {
×
630
                util.LogFatalAndExit(err, "failed to create ovn sb client")
×
631
        }
×
632
        if config.EnableLb {
×
633
                controller.switchLBRuleLister = switchLBRuleInformer.Lister()
×
634
                controller.switchLBRuleSynced = switchLBRuleInformer.Informer().HasSynced
×
635
                controller.addSwitchLBRuleQueue = newTypedRateLimitingQueue("AddSwitchLBRule", custCrdRateLimiter)
×
636
                controller.delSwitchLBRuleQueue = newTypedRateLimitingQueue(
×
637
                        "DeleteSwitchLBRule",
×
638
                        workqueue.NewTypedMaxOfRateLimiter(
×
639
                                workqueue.NewTypedItemExponentialFailureRateLimiter[*SlrInfo](time.Duration(config.CustCrdRetryMinDelay)*time.Second, time.Duration(config.CustCrdRetryMaxDelay)*time.Second),
×
640
                                &workqueue.TypedBucketRateLimiter[*SlrInfo]{Limiter: rate.NewLimiter(rate.Limit(10), 100)},
×
641
                        ),
×
642
                )
×
643
                controller.updateSwitchLBRuleQueue = newTypedRateLimitingQueue(
×
644
                        "UpdateSwitchLBRule",
×
645
                        workqueue.NewTypedMaxOfRateLimiter(
×
646
                                workqueue.NewTypedItemExponentialFailureRateLimiter[*SlrInfo](time.Duration(config.CustCrdRetryMinDelay)*time.Second, time.Duration(config.CustCrdRetryMaxDelay)*time.Second),
×
647
                                &workqueue.TypedBucketRateLimiter[*SlrInfo]{Limiter: rate.NewLimiter(rate.Limit(10), 100)},
×
648
                        ),
×
649
                )
×
650

×
651
                controller.vpcDNSLister = vpcDNSInformer.Lister()
×
652
                controller.vpcDNSSynced = vpcDNSInformer.Informer().HasSynced
×
653
                controller.addOrUpdateVpcDNSQueue = newTypedRateLimitingQueue("AddOrUpdateVpcDns", custCrdRateLimiter)
×
654
                controller.delVpcDNSQueue = newTypedRateLimitingQueue("DeleteVpcDns", custCrdRateLimiter)
×
655
        }
×
656

657
        if config.EnableNP {
×
658
                controller.npsLister = npInformer.Lister()
×
659
                controller.npsSynced = npInformer.Informer().HasSynced
×
660
                controller.updateNpQueue = newTypedRateLimitingQueue[string]("UpdateNetworkPolicy", nil)
×
661
                controller.deleteNpQueue = newTypedRateLimitingQueue[string]("DeleteNetworkPolicy", nil)
×
662
                controller.npKeyMutex = keymutex.NewHashed(numKeyLocks)
×
663
        }
×
664

665
        if config.EnableANP {
×
666
                controller.anpsLister = anpInformer.Lister()
×
667
                controller.anpsSynced = anpInformer.Informer().HasSynced
×
668
                controller.addAnpQueue = newTypedRateLimitingQueue[string]("AddAdminNetworkPolicy", nil)
×
669
                controller.updateAnpQueue = newTypedRateLimitingQueue[*AdminNetworkPolicyChangedDelta]("UpdateAdminNetworkPolicy", nil)
×
670
                controller.deleteAnpQueue = newTypedRateLimitingQueue[*v1alpha1.AdminNetworkPolicy]("DeleteAdminNetworkPolicy", nil)
×
671
                controller.anpKeyMutex = keymutex.NewHashed(numKeyLocks)
×
672

×
673
                controller.banpsLister = banpInformer.Lister()
×
674
                controller.banpsSynced = banpInformer.Informer().HasSynced
×
675
                controller.addBanpQueue = newTypedRateLimitingQueue[string]("AddBaseAdminNetworkPolicy", nil)
×
676
                controller.updateBanpQueue = newTypedRateLimitingQueue[*AdminNetworkPolicyChangedDelta]("UpdateBaseAdminNetworkPolicy", nil)
×
677
                controller.deleteBanpQueue = newTypedRateLimitingQueue[*v1alpha1.BaselineAdminNetworkPolicy]("DeleteBaseAdminNetworkPolicy", nil)
×
678
                controller.banpKeyMutex = keymutex.NewHashed(numKeyLocks)
×
679

×
680
                controller.cnpsLister = cnpInformer.Lister()
×
681
                controller.cnpsSynced = cnpInformer.Informer().HasSynced
×
682
                controller.addCnpQueue = newTypedRateLimitingQueue[string]("AddClusterNetworkPolicy", nil)
×
683
                controller.updateCnpQueue = newTypedRateLimitingQueue[*ClusterNetworkPolicyChangedDelta]("UpdateClusterNetworkPolicy", nil)
×
684
                controller.deleteCnpQueue = newTypedRateLimitingQueue[*netpolv1alpha2.ClusterNetworkPolicy]("DeleteClusterNetworkPolicy", nil)
×
685
                controller.cnpKeyMutex = keymutex.NewHashed(numKeyLocks)
×
686
        }
×
687

688
        if config.EnableDNSNameResolver {
×
689
                if !config.EnableANP {
×
690
                        klog.Warning("DNS name resolver is enabled but ANP support is disabled, DNSNameResolver resources will not take effect")
×
691
                }
×
692
                controller.dnsNameResolversLister = dnsNameResolverInformer.Lister()
×
693
                controller.dnsNameResolversSynced = dnsNameResolverInformer.Informer().HasSynced
×
694
                controller.addOrUpdateDNSNameResolverQueue = newTypedRateLimitingQueue[string]("AddOrUpdateDNSNameResolver", nil)
×
695
                controller.deleteDNSNameResolverQueue = newTypedRateLimitingQueue[*kubeovnv1.DNSNameResolver]("DeleteDNSNameResolver", nil)
×
696
        }
697

698
        defer controller.shutdown()
×
699
        klog.Info("Starting OVN controller")
×
700

×
701
        // Start and sync NAD informer first, as many resources depend on NAD cache
×
702
        // NAD CRD is optional, so we check if it exists before starting the informer
×
703
        controller.StartNetAttachInformerFactory(ctx)
×
704

×
NEW
705
        // MetalLB is optional. When its ServiceL2Status API is available, use it to
×
NEW
706
        // identify the chassis announcing each underlay LoadBalancer VIP.
×
NEW
707
        controller.StartServiceL2StatusInformer(ctx)
×
NEW
708

×
709
        // Wait for the caches to be synced before starting workers
×
710
        controller.informerFactory.Start(ctx.Done())
×
711
        controller.cmInformerFactory.Start(ctx.Done())
×
712
        controller.deployInformerFactory.Start(ctx.Done())
×
713
        controller.kubeovnInformerFactory.Start(ctx.Done())
×
714
        controller.anpInformerFactory.Start(ctx.Done())
×
715
        controller.StartKubevirtInformerFactory(ctx, kubevirtInformerFactory)
×
716

×
717
        klog.Info("Waiting for informer caches to sync")
×
718
        cacheSyncs := []cache.InformerSynced{
×
719
                controller.vpcNatGatewaySynced, controller.vpcEgressGatewaySynced,
×
720
                controller.vpcSynced, controller.subnetSynced,
×
721
                controller.ipSynced, controller.virtualIpsSynced, controller.iptablesEipSynced,
×
722
                controller.iptablesFipSynced, controller.iptablesDnatRuleSynced, controller.iptablesSnatRuleSynced,
×
723
                controller.vlanSynced, controller.podsSynced, controller.namespacesSynced, controller.nodesSynced,
×
724
                controller.serviceSynced, controller.endpointSlicesSynced, controller.deploymentsSynced, controller.configMapsSynced,
×
725
                controller.ovnEipSynced, controller.ovnFipSynced, controller.ovnSnatRuleSynced,
×
726
                controller.ovnDnatRuleSynced,
×
727
        }
×
728
        if controller.config.EnableLb {
×
729
                cacheSyncs = append(cacheSyncs, controller.switchLBRuleSynced, controller.vpcDNSSynced)
×
730
        }
×
731
        if controller.config.EnableNP {
×
732
                cacheSyncs = append(cacheSyncs, controller.npsSynced)
×
733
        }
×
734
        if controller.config.EnableANP {
×
735
                cacheSyncs = append(cacheSyncs, controller.anpsSynced, controller.banpsSynced, controller.cnpsSynced)
×
736
        }
×
737
        if controller.config.EnableDNSNameResolver {
×
738
                cacheSyncs = append(cacheSyncs, controller.dnsNameResolversSynced)
×
739
        }
×
740

741
        if !cache.WaitForCacheSync(ctx.Done(), cacheSyncs...) {
×
742
                util.LogFatalAndExit(nil, "failed to wait for caches to sync")
×
743
        }
×
744

745
        if _, err = podInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
746
                AddFunc:    controller.enqueueAddPod,
×
747
                DeleteFunc: controller.enqueueDeletePod,
×
748
                UpdateFunc: controller.enqueueUpdatePod,
×
749
        }); err != nil {
×
750
                util.LogFatalAndExit(err, "failed to add pod event handler")
×
751
        }
×
752

753
        if _, err = namespaceInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
754
                AddFunc:    controller.enqueueAddNamespace,
×
755
                UpdateFunc: controller.enqueueUpdateNamespace,
×
756
                DeleteFunc: controller.enqueueDeleteNamespace,
×
757
        }); err != nil {
×
758
                util.LogFatalAndExit(err, "failed to add namespace event handler")
×
759
        }
×
760

761
        if _, err = nodeInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
762
                AddFunc:    controller.enqueueAddNode,
×
763
                UpdateFunc: controller.enqueueUpdateNode,
×
764
                DeleteFunc: controller.enqueueDeleteNode,
×
765
        }); err != nil {
×
766
                util.LogFatalAndExit(err, "failed to add node event handler")
×
767
        }
×
768

769
        if _, err = serviceInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
770
                AddFunc:    controller.enqueueAddService,
×
771
                DeleteFunc: controller.enqueueDeleteService,
×
772
                UpdateFunc: controller.enqueueUpdateService,
×
773
        }); err != nil {
×
774
                util.LogFatalAndExit(err, "failed to add service event handler")
×
775
        }
×
776

777
        if _, err = endpointSliceInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
778
                AddFunc:    controller.enqueueAddEndpointSlice,
×
779
                UpdateFunc: controller.enqueueUpdateEndpointSlice,
×
780
        }); err != nil {
×
781
                util.LogFatalAndExit(err, "failed to add endpoint slice event handler")
×
782
        }
×
783

784
        if _, err = deploymentInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
785
                AddFunc:    controller.enqueueAddDeployment,
×
786
                UpdateFunc: controller.enqueueUpdateDeployment,
×
787
        }); err != nil {
×
788
                util.LogFatalAndExit(err, "failed to add deployment event handler")
×
789
        }
×
790

791
        if _, err = vpcInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
792
                AddFunc:    controller.enqueueAddVpc,
×
793
                UpdateFunc: controller.enqueueUpdateVpc,
×
794
                DeleteFunc: controller.enqueueDelVpc,
×
795
        }); err != nil {
×
796
                util.LogFatalAndExit(err, "failed to add vpc event handler")
×
797
        }
×
798

799
        if _, err = vpcNatGatewayInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
800
                AddFunc:    controller.enqueueAddVpcNatGw,
×
801
                UpdateFunc: controller.enqueueUpdateVpcNatGw,
×
802
                DeleteFunc: controller.enqueueDeleteVpcNatGw,
×
803
        }); err != nil {
×
804
                util.LogFatalAndExit(err, "failed to add vpc nat gateway event handler")
×
805
        }
×
806

807
        if _, err = vpcEgressGatewayInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
808
                AddFunc:    controller.enqueueAddVpcEgressGateway,
×
809
                UpdateFunc: controller.enqueueUpdateVpcEgressGateway,
×
810
                DeleteFunc: controller.enqueueDeleteVpcEgressGateway,
×
811
        }); err != nil {
×
812
                util.LogFatalAndExit(err, "failed to add vpc egress gateway event handler")
×
813
        }
×
814

815
        if _, err = subnetInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
816
                AddFunc:    controller.enqueueAddSubnet,
×
817
                UpdateFunc: controller.enqueueUpdateSubnet,
×
818
                DeleteFunc: controller.enqueueDeleteSubnet,
×
819
        }); err != nil {
×
820
                util.LogFatalAndExit(err, "failed to add subnet event handler")
×
821
        }
×
822

823
        if _, err = ippoolInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
824
                AddFunc:    controller.enqueueAddIPPool,
×
825
                UpdateFunc: controller.enqueueUpdateIPPool,
×
826
                DeleteFunc: controller.enqueueDeleteIPPool,
×
827
        }); err != nil {
×
828
                util.LogFatalAndExit(err, "failed to add ippool event handler")
×
829
        }
×
830

831
        if _, err = ipInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
832
                AddFunc:    controller.enqueueAddIP,
×
833
                UpdateFunc: controller.enqueueUpdateIP,
×
834
                DeleteFunc: controller.enqueueDelIP,
×
835
        }); err != nil {
×
836
                util.LogFatalAndExit(err, "failed to add ips event handler")
×
837
        }
×
838

839
        if _, err = vlanInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
840
                AddFunc:    controller.enqueueAddVlan,
×
841
                DeleteFunc: controller.enqueueDelVlan,
×
842
                UpdateFunc: controller.enqueueUpdateVlan,
×
843
        }); err != nil {
×
844
                util.LogFatalAndExit(err, "failed to add vlan event handler")
×
845
        }
×
846

847
        if _, err = sgInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
848
                AddFunc:    controller.enqueueAddSg,
×
849
                DeleteFunc: controller.enqueueDeleteSg,
×
850
                UpdateFunc: controller.enqueueUpdateSg,
×
851
        }); err != nil {
×
852
                util.LogFatalAndExit(err, "failed to add security group event handler")
×
853
        }
×
854

855
        if _, err = virtualIPInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
856
                AddFunc:    controller.enqueueAddVirtualIP,
×
857
                UpdateFunc: controller.enqueueUpdateVirtualIP,
×
858
                DeleteFunc: controller.enqueueDelVirtualIP,
×
859
        }); err != nil {
×
860
                util.LogFatalAndExit(err, "failed to add virtual ip event handler")
×
861
        }
×
862

863
        if _, err = iptablesEipInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
864
                AddFunc:    controller.enqueueAddIptablesEip,
×
865
                UpdateFunc: controller.enqueueUpdateIptablesEip,
×
866
                DeleteFunc: controller.enqueueDelIptablesEip,
×
867
        }); err != nil {
×
868
                util.LogFatalAndExit(err, "failed to add iptables eip event handler")
×
869
        }
×
870

871
        if _, err = iptablesFipInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
872
                AddFunc:    controller.enqueueAddIptablesFip,
×
873
                UpdateFunc: controller.enqueueUpdateIptablesFip,
×
874
                DeleteFunc: controller.enqueueDelIptablesFip,
×
875
        }); err != nil {
×
876
                util.LogFatalAndExit(err, "failed to add iptables fip event handler")
×
877
        }
×
878

879
        if _, err = iptablesDnatRuleInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
880
                AddFunc:    controller.enqueueAddIptablesDnatRule,
×
881
                UpdateFunc: controller.enqueueUpdateIptablesDnatRule,
×
882
                DeleteFunc: controller.enqueueDelIptablesDnatRule,
×
883
        }); err != nil {
×
884
                util.LogFatalAndExit(err, "failed to add iptables dnat event handler")
×
885
        }
×
886

887
        if _, err = iptablesSnatRuleInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
888
                AddFunc:    controller.enqueueAddIptablesSnatRule,
×
889
                UpdateFunc: controller.enqueueUpdateIptablesSnatRule,
×
890
                DeleteFunc: controller.enqueueDelIptablesSnatRule,
×
891
        }); err != nil {
×
892
                util.LogFatalAndExit(err, "failed to add iptables snat rule event handler")
×
893
        }
×
894

895
        if _, err = ovnEipInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
896
                AddFunc:    controller.enqueueAddOvnEip,
×
897
                UpdateFunc: controller.enqueueUpdateOvnEip,
×
898
                DeleteFunc: controller.enqueueDelOvnEip,
×
899
        }); err != nil {
×
900
                util.LogFatalAndExit(err, "failed to add ovn eip event handler")
×
901
        }
×
902

903
        if _, err = ovnFipInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
904
                AddFunc:    controller.enqueueAddOvnFip,
×
905
                UpdateFunc: controller.enqueueUpdateOvnFip,
×
906
                DeleteFunc: controller.enqueueDelOvnFip,
×
907
        }); err != nil {
×
908
                util.LogFatalAndExit(err, "failed to add ovn fip event handler")
×
909
        }
×
910

911
        if _, err = ovnSnatRuleInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
912
                AddFunc:    controller.enqueueAddOvnSnatRule,
×
913
                UpdateFunc: controller.enqueueUpdateOvnSnatRule,
×
914
                DeleteFunc: controller.enqueueDelOvnSnatRule,
×
915
        }); err != nil {
×
916
                util.LogFatalAndExit(err, "failed to add ovn snat rule event handler")
×
917
        }
×
918

919
        if _, err = ovnDnatRuleInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
920
                AddFunc:    controller.enqueueAddOvnDnatRule,
×
921
                UpdateFunc: controller.enqueueUpdateOvnDnatRule,
×
922
                DeleteFunc: controller.enqueueDelOvnDnatRule,
×
923
        }); err != nil {
×
924
                util.LogFatalAndExit(err, "failed to add ovn dnat rule event handler")
×
925
        }
×
926

927
        if _, err = qosPolicyInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
928
                AddFunc:    controller.enqueueAddQoSPolicy,
×
929
                UpdateFunc: controller.enqueueUpdateQoSPolicy,
×
930
                DeleteFunc: controller.enqueueDelQoSPolicy,
×
931
        }); err != nil {
×
932
                util.LogFatalAndExit(err, "failed to add qos policy event handler")
×
933
        }
×
934

935
        if config.EnableLb {
×
936
                if _, err = switchLBRuleInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
937
                        AddFunc:    controller.enqueueAddSwitchLBRule,
×
938
                        UpdateFunc: controller.enqueueUpdateSwitchLBRule,
×
939
                        DeleteFunc: controller.enqueueDeleteSwitchLBRule,
×
940
                }); err != nil {
×
941
                        util.LogFatalAndExit(err, "failed to add switch lb rule event handler")
×
942
                }
×
943

944
                if _, err = vpcDNSInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
945
                        AddFunc:    controller.enqueueAddVpcDNS,
×
946
                        UpdateFunc: controller.enqueueUpdateVpcDNS,
×
947
                        DeleteFunc: controller.enqueueDeleteVPCDNS,
×
948
                }); err != nil {
×
949
                        util.LogFatalAndExit(err, "failed to add vpc dns event handler")
×
950
                }
×
951
        }
952

953
        if config.EnableNP {
×
954
                if _, err = npInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
955
                        AddFunc:    controller.enqueueAddNp,
×
956
                        UpdateFunc: controller.enqueueUpdateNp,
×
957
                        DeleteFunc: controller.enqueueDeleteNp,
×
958
                }); err != nil {
×
959
                        util.LogFatalAndExit(err, "failed to add network policy event handler")
×
960
                }
×
961
        }
962

963
        if config.EnableANP {
×
964
                if _, err = anpInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
965
                        AddFunc:    controller.enqueueAddAnp,
×
966
                        UpdateFunc: controller.enqueueUpdateAnp,
×
967
                        DeleteFunc: controller.enqueueDeleteAnp,
×
968
                }); err != nil {
×
969
                        util.LogFatalAndExit(err, "failed to add admin network policy event handler")
×
970
                }
×
971

972
                if _, err = banpInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
973
                        AddFunc:    controller.enqueueAddBanp,
×
974
                        UpdateFunc: controller.enqueueUpdateBanp,
×
975
                        DeleteFunc: controller.enqueueDeleteBanp,
×
976
                }); err != nil {
×
977
                        util.LogFatalAndExit(err, "failed to add baseline admin network policy event handler")
×
978
                }
×
979

980
                if _, err = cnpInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
981
                        AddFunc:    controller.enqueueAddCnp,
×
982
                        UpdateFunc: controller.enqueueUpdateCnp,
×
983
                        DeleteFunc: controller.enqueueDeleteCnp,
×
984
                }); err != nil {
×
985
                        util.LogFatalAndExit(err, "failed to add cluster network policy event handler")
×
986
                }
×
987

988
                maxPriorityPerMap := util.CnpMaxPriority + 1
×
989
                controller.anpPrioNameMap = make(map[int32]string, maxPriorityPerMap)
×
990
                controller.anpNamePrioMap = make(map[string]int32, maxPriorityPerMap)
×
991
                controller.bnpPrioNameMap = make(map[int32]string, maxPriorityPerMap)
×
992
                controller.bnpNamePrioMap = make(map[string]int32, maxPriorityPerMap)
×
993
        }
994

995
        if config.EnableDNSNameResolver {
×
996
                if _, err = dnsNameResolverInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
997
                        AddFunc:    controller.enqueueAddDNSNameResolver,
×
998
                        UpdateFunc: controller.enqueueUpdateDNSNameResolver,
×
999
                        DeleteFunc: controller.enqueueDeleteDNSNameResolver,
×
1000
                }); err != nil {
×
1001
                        util.LogFatalAndExit(err, "failed to add dns name resolver event handler")
×
1002
                }
×
1003
        }
1004

1005
        if config.EnableOVNIPSec {
×
1006
                if _, err = csrInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
1007
                        AddFunc:    controller.enqueueAddCsr,
×
1008
                        UpdateFunc: controller.enqueueUpdateCsr,
×
1009
                        // no need to add delete func for csr
×
1010
                }); err != nil {
×
1011
                        util.LogFatalAndExit(err, "failed to add csr event handler")
×
1012
                }
×
1013
        }
1014

1015
        controller.Run(ctx)
×
1016
}
1017

1018
// Run will set up the event handlers for types we are interested in, as well
1019
// as syncing informer caches and starting workers. It will block until stopCh
1020
// is closed, at which point it will shutdown the workqueue and wait for
1021
// workers to finish processing their current work items.
1022
func (c *Controller) Run(ctx context.Context) {
×
1023
        // The init process can only be placed here if the init process do really affect the normal process of controller, such as Nodes/Pods/Subnets...
×
1024
        // Otherwise, the init process should be placed after all workers have already started working
×
1025
        if err := c.OVNNbClient.SetLsDnatModDlDst(c.config.LsDnatModDlDst); err != nil {
×
1026
                util.LogFatalAndExit(err, "failed to set NB_Global option ls_dnat_mod_dl_dst")
×
1027
        }
×
1028

1029
        if err := c.OVNNbClient.SetUseCtInvMatch(); err != nil {
×
1030
                util.LogFatalAndExit(err, "failed to set NB_Global option use_ct_inv_match to false")
×
1031
        }
×
1032

1033
        if err := c.OVNNbClient.SetLsCtSkipDstLportIPs(c.config.LsCtSkipDstLportIPs); err != nil {
×
1034
                util.LogFatalAndExit(err, "failed to set NB_Global option ls_ct_skip_dst_lport_ips")
×
1035
        }
×
1036

1037
        if err := c.OVNNbClient.SetNodeLocalDNSIP(strings.Join(c.config.NodeLocalDNSIPs, ",")); err != nil {
×
1038
                util.LogFatalAndExit(err, "failed to set NB_Global option node_local_dns_ip")
×
1039
        }
×
1040

1041
        if err := c.OVNNbClient.SetSkipConntrackCidrs(c.config.SkipConntrackDstCidrs); err != nil {
×
1042
                util.LogFatalAndExit(err, "failed to set NB_Global option skip_conntrack_ipcidrs")
×
1043
        }
×
1044

1045
        if err := c.OVNNbClient.SetOVNIPSec(c.config.EnableOVNIPSec); err != nil {
×
1046
                util.LogFatalAndExit(err, "failed to set NB_Global ipsec")
×
1047
        }
×
1048

1049
        if err := c.InitOVN(); err != nil {
×
1050
                util.LogFatalAndExit(err, "failed to initialize ovn resources")
×
1051
        }
×
1052

1053
        // sync ip crd before initIPAM since ip crd will be used to restore vm and statefulset pod in initIPAM
1054
        if err := c.syncIPCR(); err != nil {
×
1055
                util.LogFatalAndExit(err, "failed to sync crd ips")
×
1056
        }
×
1057

1058
        if err := c.syncFinalizers(); err != nil {
×
1059
                util.LogFatalAndExit(err, "failed to initialize crd finalizers")
×
1060
        }
×
1061

1062
        if err := c.InitIPAM(); err != nil {
×
1063
                util.LogFatalAndExit(err, "failed to initialize ipam")
×
1064
        }
×
1065

1066
        if err := c.syncNodeRoutes(); err != nil {
×
1067
                util.LogFatalAndExit(err, "failed to initialize node routes")
×
1068
        }
×
1069

1070
        if err := c.syncSubnetCR(); err != nil {
×
1071
                util.LogFatalAndExit(err, "failed to sync crd subnets")
×
1072
        }
×
1073

1074
        if err := c.syncVlanCR(); err != nil {
×
1075
                util.LogFatalAndExit(err, "failed to sync crd vlans")
×
1076
        }
×
1077

1078
        if c.config.EnableOVNIPSec && !c.config.CertManagerIPSecCert {
×
1079
                if err := c.InitDefaultOVNIPsecCA(); err != nil {
×
1080
                        util.LogFatalAndExit(err, "failed to init ovn ipsec CA")
×
1081
                }
×
1082
        }
1083

1084
        c.startKubeOVNTLSManager(ctx)
×
1085

×
1086
        // start workers to do all the network operations
×
1087
        c.startWorkers(ctx)
×
1088

×
1089
        c.initResourceOnce()
×
1090
        <-ctx.Done()
×
1091
        klog.Info("Shutting down workers")
×
1092

×
1093
        c.OVNNbClient.Close()
×
1094
        c.OVNSbClient.Close()
×
1095
}
1096

1097
func (c *Controller) dbStatus() {
×
1098
        const maxFailures = 5
×
1099

×
1100
        done := make(chan error, 2)
×
1101
        go func() {
×
1102
                done <- c.OVNNbClient.Echo(context.Background())
×
1103
        }()
×
1104
        go func() {
×
1105
                done <- c.OVNSbClient.Echo(context.Background())
×
1106
        }()
×
1107

1108
        resultsReceived := 0
×
1109
        timeout := time.After(time.Duration(c.config.OvnTimeout) * time.Second)
×
1110

×
1111
        for resultsReceived < 2 {
×
1112
                select {
×
1113
                case err := <-done:
×
1114
                        resultsReceived++
×
1115
                        if err != nil {
×
1116
                                c.dbFailureCount++
×
1117
                                klog.Errorf("OVN database echo failed (%d/%d): %v", c.dbFailureCount, maxFailures, err)
×
1118
                                if c.dbFailureCount >= maxFailures {
×
1119
                                        util.LogFatalAndExit(err, "OVN database connection failed after %d attempts", maxFailures)
×
1120
                                }
×
1121
                                return
×
1122
                        }
1123
                case <-timeout:
×
1124
                        c.dbFailureCount++
×
1125
                        klog.Errorf("OVN database echo timeout (%d/%d) after %ds", c.dbFailureCount, maxFailures, c.config.OvnTimeout)
×
1126
                        if c.dbFailureCount >= maxFailures {
×
1127
                                util.LogFatalAndExit(nil, "OVN database connection timeout after %d attempts", maxFailures)
×
1128
                        }
×
1129
                        return
×
1130
                }
1131
        }
1132

1133
        if c.dbFailureCount > 0 {
×
1134
                klog.Infof("OVN database connection recovered after %d failures", c.dbFailureCount)
×
1135
                c.dbFailureCount = 0
×
1136
        }
×
1137
}
1138

1139
func (c *Controller) shutdown() {
×
1140
        utilruntime.HandleCrash()
×
1141

×
1142
        c.addOrUpdatePodQueue.ShutDown()
×
1143
        c.deletePodQueue.ShutDown()
×
1144
        c.updatePodSecurityQueue.ShutDown()
×
1145

×
1146
        c.addNamespaceQueue.ShutDown()
×
1147

×
1148
        c.addOrUpdateSubnetQueue.ShutDown()
×
1149
        c.deleteSubnetQueue.ShutDown()
×
1150
        c.updateSubnetStatusQueue.ShutDown()
×
1151
        c.syncVirtualPortsQueue.ShutDown()
×
1152

×
1153
        c.addOrUpdateIPPoolQueue.ShutDown()
×
1154
        c.updateIPPoolStatusQueue.ShutDown()
×
1155
        c.deleteIPPoolQueue.ShutDown()
×
1156

×
1157
        c.addNodeQueue.ShutDown()
×
1158
        c.updateNodeQueue.ShutDown()
×
1159
        c.deleteNodeQueue.ShutDown()
×
1160

×
1161
        c.addServiceQueue.ShutDown()
×
1162
        c.deleteServiceQueue.ShutDown()
×
1163
        c.updateServiceQueue.ShutDown()
×
1164
        c.addOrUpdateEndpointSliceQueue.ShutDown()
×
1165

×
1166
        c.addVlanQueue.ShutDown()
×
1167
        c.delVlanQueue.ShutDown()
×
1168
        c.updateVlanQueue.ShutDown()
×
1169

×
1170
        c.addOrUpdateVpcQueue.ShutDown()
×
1171
        c.updateVpcStatusQueue.ShutDown()
×
1172
        c.delVpcQueue.ShutDown()
×
1173

×
1174
        c.addOrUpdateVpcNatGatewayQueue.ShutDown()
×
1175
        c.initVpcNatGatewayQueue.ShutDown()
×
1176
        c.delVpcNatGatewayQueue.ShutDown()
×
1177
        c.updateVpcEipQueue.ShutDown()
×
1178
        c.updateVpcFloatingIPQueue.ShutDown()
×
1179
        c.updateVpcDnatQueue.ShutDown()
×
1180
        c.updateVpcSnatQueue.ShutDown()
×
1181
        c.updateVpcSubnetQueue.ShutDown()
×
1182

×
1183
        c.addOrUpdateVpcEgressGatewayQueue.ShutDown()
×
1184
        c.delVpcEgressGatewayQueue.ShutDown()
×
1185

×
1186
        if c.config.EnableLb {
×
1187
                c.addSwitchLBRuleQueue.ShutDown()
×
1188
                c.delSwitchLBRuleQueue.ShutDown()
×
1189
                c.updateSwitchLBRuleQueue.ShutDown()
×
1190

×
1191
                c.addOrUpdateVpcDNSQueue.ShutDown()
×
1192
                c.delVpcDNSQueue.ShutDown()
×
1193
        }
×
1194

1195
        c.addIPQueue.ShutDown()
×
1196
        c.updateIPQueue.ShutDown()
×
1197
        c.delIPQueue.ShutDown()
×
1198

×
1199
        c.addVirtualIPQueue.ShutDown()
×
1200
        c.updateVirtualIPQueue.ShutDown()
×
1201
        c.updateVirtualParentsQueue.ShutDown()
×
1202
        c.delVirtualIPQueue.ShutDown()
×
1203

×
1204
        c.addIptablesEipQueue.ShutDown()
×
1205
        c.updateIptablesEipQueue.ShutDown()
×
1206
        c.resetIptablesEipQueue.ShutDown()
×
1207
        c.delIptablesEipQueue.ShutDown()
×
1208

×
1209
        c.addIptablesFipQueue.ShutDown()
×
1210
        c.updateIptablesFipQueue.ShutDown()
×
1211
        c.delIptablesFipQueue.ShutDown()
×
1212

×
1213
        c.addIptablesDnatRuleQueue.ShutDown()
×
1214
        c.updateIptablesDnatRuleQueue.ShutDown()
×
1215
        c.delIptablesDnatRuleQueue.ShutDown()
×
1216

×
1217
        c.addIptablesSnatRuleQueue.ShutDown()
×
1218
        c.updateIptablesSnatRuleQueue.ShutDown()
×
1219
        c.delIptablesSnatRuleQueue.ShutDown()
×
1220

×
1221
        c.addQoSPolicyQueue.ShutDown()
×
1222
        c.updateQoSPolicyQueue.ShutDown()
×
1223
        c.delQoSPolicyQueue.ShutDown()
×
1224

×
1225
        c.addOvnEipQueue.ShutDown()
×
1226
        c.updateOvnEipQueue.ShutDown()
×
1227
        c.resetOvnEipQueue.ShutDown()
×
1228
        c.delOvnEipQueue.ShutDown()
×
1229

×
1230
        c.addOvnFipQueue.ShutDown()
×
1231
        c.updateOvnFipQueue.ShutDown()
×
1232
        c.delOvnFipQueue.ShutDown()
×
1233

×
1234
        c.addOvnSnatRuleQueue.ShutDown()
×
1235
        c.updateOvnSnatRuleQueue.ShutDown()
×
1236
        c.delOvnSnatRuleQueue.ShutDown()
×
1237

×
1238
        c.addOvnDnatRuleQueue.ShutDown()
×
1239
        c.updateOvnDnatRuleQueue.ShutDown()
×
1240
        c.delOvnDnatRuleQueue.ShutDown()
×
1241

×
1242
        if c.config.EnableNP {
×
1243
                c.updateNpQueue.ShutDown()
×
1244
                c.deleteNpQueue.ShutDown()
×
1245
        }
×
1246
        if c.config.EnableANP {
×
1247
                c.addAnpQueue.ShutDown()
×
1248
                c.updateAnpQueue.ShutDown()
×
1249
                c.deleteAnpQueue.ShutDown()
×
1250

×
1251
                c.addBanpQueue.ShutDown()
×
1252
                c.updateBanpQueue.ShutDown()
×
1253
                c.deleteBanpQueue.ShutDown()
×
1254

×
1255
                c.addCnpQueue.ShutDown()
×
1256
                c.updateCnpQueue.ShutDown()
×
1257
                c.deleteCnpQueue.ShutDown()
×
1258
        }
×
1259

1260
        if c.config.EnableDNSNameResolver {
×
1261
                c.addOrUpdateDNSNameResolverQueue.ShutDown()
×
1262
                c.deleteDNSNameResolverQueue.ShutDown()
×
1263
        }
×
1264

1265
        c.addOrUpdateSgQueue.ShutDown()
×
1266
        c.delSgQueue.ShutDown()
×
1267
        c.syncSgPortsQueue.ShutDown()
×
1268

×
1269
        c.addOrUpdateCsrQueue.ShutDown()
×
1270

×
1271
        if c.config.EnableLiveMigrationOptimize {
×
1272
                c.addOrUpdateVMIMigrationQueue.ShutDown()
×
1273
        }
×
1274
}
1275

1276
func (c *Controller) startWorkers(ctx context.Context) {
×
1277
        klog.Info("Starting workers")
×
1278

×
1279
        go wait.Until(runWorker("add/update vpc", c.addOrUpdateVpcQueue, c.handleAddOrUpdateVpc), time.Second, ctx.Done())
×
1280
        go wait.Until(runWorker("delete vpc", c.delVpcQueue, c.handleDelVpc), time.Second, ctx.Done())
×
1281
        go wait.Until(runWorker("update status of vpc", c.updateVpcStatusQueue, c.handleUpdateVpcStatus), time.Second, ctx.Done())
×
1282

×
1283
        go wait.Until(runWorker("add/update vpc nat gateway", c.addOrUpdateVpcNatGatewayQueue, c.handleAddOrUpdateVpcNatGw), time.Second, ctx.Done())
×
1284
        go wait.Until(runWorker("init vpc nat gateway", c.initVpcNatGatewayQueue, c.handleInitVpcNatGw), time.Second, ctx.Done())
×
1285
        go wait.Until(runWorker("delete vpc nat gateway", c.delVpcNatGatewayQueue, c.handleDelVpcNatGw), time.Second, ctx.Done())
×
1286
        go wait.Until(runWorker("add/update vpc egress gateway", c.addOrUpdateVpcEgressGatewayQueue, c.handleAddOrUpdateVpcEgressGateway), time.Second, ctx.Done())
×
1287
        go wait.Until(runWorker("delete vpc egress gateway", c.delVpcEgressGatewayQueue, c.handleDelVpcEgressGateway), time.Second, ctx.Done())
×
1288
        go wait.Until(runWorker("update fip for vpc nat gateway", c.updateVpcFloatingIPQueue, c.handleUpdateVpcFloatingIP), time.Second, ctx.Done())
×
1289
        go wait.Until(runWorker("update eip for vpc nat gateway", c.updateVpcEipQueue, c.handleUpdateVpcEip), time.Second, ctx.Done())
×
1290
        go wait.Until(runWorker("update dnat for vpc nat gateway", c.updateVpcDnatQueue, c.handleUpdateVpcDnat), time.Second, ctx.Done())
×
1291
        go wait.Until(runWorker("update snat for vpc nat gateway", c.updateVpcSnatQueue, c.handleUpdateVpcSnat), time.Second, ctx.Done())
×
1292
        go wait.Until(runWorker("update subnet route for vpc nat gateway", c.updateVpcSubnetQueue, c.handleUpdateNatGwSubnetRoute), time.Second, ctx.Done())
×
1293
        go wait.Until(runWorker("add/update csr", c.addOrUpdateCsrQueue, c.handleAddOrUpdateCsr), time.Second, ctx.Done())
×
1294
        // add default and join subnet and wait them ready
×
1295
        for range c.config.WorkerNum {
×
1296
                go wait.Until(runWorker("add/update subnet", c.addOrUpdateSubnetQueue, c.handleAddOrUpdateSubnet), time.Second, ctx.Done())
×
1297
        }
×
1298
        go wait.Until(runWorker("add/update ippool", c.addOrUpdateIPPoolQueue, c.handleAddOrUpdateIPPool), time.Second, ctx.Done())
×
1299
        go wait.Until(runWorker("add vlan", c.addVlanQueue, c.handleAddVlan), time.Second, ctx.Done())
×
1300
        go wait.Until(runWorker("add namespace", c.addNamespaceQueue, c.handleAddNamespace), time.Second, ctx.Done())
×
1301
        err := wait.PollUntilContextCancel(ctx, 3*time.Second, true, func(_ context.Context) (done bool, err error) {
×
1302
                subnets := []string{c.config.DefaultLogicalSwitch, c.config.NodeSwitch}
×
1303
                klog.Infof("wait for subnets %v ready", subnets)
×
1304

×
1305
                return c.allSubnetReady(subnets...)
×
1306
        })
×
1307
        if err != nil {
×
1308
                klog.Fatalf("wait default and join subnet ready, error: %v", err)
×
1309
        }
×
1310

1311
        go wait.Until(runWorker("add/update security group", c.addOrUpdateSgQueue, func(key string) error { return c.handleAddOrUpdateSg(key, false) }), time.Second, ctx.Done())
×
1312
        go wait.Until(runWorker("delete security group", c.delSgQueue, c.handleDeleteSg), time.Second, ctx.Done())
×
1313
        go wait.Until(runWorker("ports for security group", c.syncSgPortsQueue, c.syncSgLogicalPort), time.Second, ctx.Done())
×
1314

×
1315
        // run node worker before handle any pods
×
1316
        for range c.config.WorkerNum {
×
1317
                go wait.Until(runWorker("add node", c.addNodeQueue, c.handleAddNode), time.Second, ctx.Done())
×
1318
                go wait.Until(runWorker("update node", c.updateNodeQueue, c.handleUpdateNode), time.Second, ctx.Done())
×
1319
                go wait.Until(runWorker("delete node", c.deleteNodeQueue, c.handleDeleteNode), time.Second, ctx.Done())
×
1320
        }
×
1321
        for {
×
1322
                ready := true
×
1323
                time.Sleep(3 * time.Second)
×
1324
                nodes, err := c.nodesLister.List(labels.Everything())
×
1325
                if err != nil {
×
1326
                        util.LogFatalAndExit(err, "failed to list nodes")
×
1327
                }
×
1328
                for _, node := range nodes {
×
1329
                        if node.Annotations[util.AllocatedAnnotation] != "true" {
×
1330
                                klog.Infof("wait node %s annotation ready", node.Name)
×
1331
                                ready = false
×
1332
                                break
×
1333
                        }
1334
                }
1335
                if ready {
×
1336
                        break
×
1337
                }
1338
        }
1339

1340
        if c.config.EnableLb {
×
1341
                go wait.Until(runWorker("add service", c.addServiceQueue, c.handleAddService), time.Second, ctx.Done())
×
1342
                // run in a single worker to avoid delete the last vip, which will lead ovn to delete the loadbalancer
×
1343
                go wait.Until(runWorker("delete service", c.deleteServiceQueue, c.handleDeleteService), time.Second, ctx.Done())
×
1344

×
1345
                go wait.Until(runWorker("add/update switch lb rule", c.addSwitchLBRuleQueue, c.handleAddOrUpdateSwitchLBRule), time.Second, ctx.Done())
×
1346
                go wait.Until(runWorker("delete switch lb rule", c.delSwitchLBRuleQueue, c.handleDelSwitchLBRule), time.Second, ctx.Done())
×
1347
                go wait.Until(runWorker("delete switch lb rule", c.updateSwitchLBRuleQueue, c.handleUpdateSwitchLBRule), time.Second, ctx.Done())
×
1348

×
1349
                go wait.Until(runWorker("add/update vpc dns", c.addOrUpdateVpcDNSQueue, c.handleAddOrUpdateVPCDNS), time.Second, ctx.Done())
×
1350
                go wait.Until(runWorker("delete vpc dns", c.delVpcDNSQueue, c.handleDelVpcDNS), time.Second, ctx.Done())
×
1351
                go wait.Until(func() {
×
1352
                        c.resyncVpcDNSConfig()
×
1353
                }, 5*time.Second, ctx.Done())
×
1354
        }
1355

1356
        for range c.config.WorkerNum {
×
1357
                go wait.Until(runWorker("delete pod", c.deletePodQueue, c.handleDeletePod), time.Second, ctx.Done())
×
1358
                go wait.Until(runWorker("add/update pod", c.addOrUpdatePodQueue, c.handleAddOrUpdatePod), time.Second, ctx.Done())
×
1359
                go wait.Until(runWorker("update pod security", c.updatePodSecurityQueue, c.handleUpdatePodSecurity), time.Second, ctx.Done())
×
1360

×
1361
                go wait.Until(runWorker("delete subnet", c.deleteSubnetQueue, c.handleDeleteSubnet), time.Second, ctx.Done())
×
1362
                go wait.Until(runWorker("delete ippool", c.deleteIPPoolQueue, c.handleDeleteIPPool), time.Second, ctx.Done())
×
1363
                go wait.Until(runWorker("update status of subnet", c.updateSubnetStatusQueue, c.handleUpdateSubnetStatus), time.Second, ctx.Done())
×
1364
                go wait.Until(runWorker("update status of ippool", c.updateIPPoolStatusQueue, c.handleUpdateIPPoolStatus), time.Second, ctx.Done())
×
1365
                go wait.Until(runWorker("virtual port for subnet", c.syncVirtualPortsQueue, c.syncVirtualPort), time.Second, ctx.Done())
×
1366

×
1367
                if c.config.EnableLb {
×
1368
                        go wait.Until(runWorker("update service", c.updateServiceQueue, c.handleUpdateService), time.Second, ctx.Done())
×
1369
                        go wait.Until(runWorker("add/update endpoint slice", c.addOrUpdateEndpointSliceQueue, c.handleUpdateEndpointSlice), time.Second, ctx.Done())
×
1370
                }
×
1371

1372
                if c.config.EnableNP {
×
1373
                        go wait.Until(runWorker("update network policy", c.updateNpQueue, c.handleUpdateNp), time.Second, ctx.Done())
×
1374
                        go wait.Until(runWorker("delete network policy", c.deleteNpQueue, c.handleDeleteNp), time.Second, ctx.Done())
×
1375
                }
×
1376

1377
                go wait.Until(runWorker("delete vlan", c.delVlanQueue, c.handleDelVlan), time.Second, ctx.Done())
×
1378
                go wait.Until(runWorker("update vlan", c.updateVlanQueue, c.handleUpdateVlan), time.Second, ctx.Done())
×
1379
        }
1380

1381
        if c.config.EnableEipSnat {
×
1382
                go wait.Until(func() {
×
1383
                        // init l3 about the default vpc external lrp binding to the gw chassis
×
1384
                        c.resyncExternalGateway()
×
1385
                }, time.Second, ctx.Done())
×
1386

1387
                // maintain l3 ha about the vpc external lrp binding to the gw chassis
1388
                c.OVNNbClient.MonitorBFD()
×
1389
        }
1390
        // TODO: we should merge these two vpc nat config into one config and resync them together
1391
        go wait.Until(func() {
×
1392
                c.resyncVpcNatGwConfig()
×
1393
        }, time.Second, ctx.Done())
×
1394

1395
        go wait.Until(func() {
×
1396
                c.resyncVpcNatConfig()
×
1397
        }, time.Second, ctx.Done())
×
1398

1399
        if c.config.GCInterval != 0 {
×
1400
                go wait.Until(func() {
×
1401
                        if err := c.markAndCleanLSP(); err != nil {
×
1402
                                klog.Errorf("gc lsp error: %v", err)
×
1403
                        }
×
1404
                }, time.Duration(c.config.GCInterval)*time.Second, ctx.Done())
1405
        }
1406

1407
        go wait.Until(func() {
×
1408
                if err := c.inspectPod(); err != nil {
×
1409
                        klog.Errorf("inspection error: %v", err)
×
1410
                }
×
1411
        }, time.Duration(c.config.InspectInterval)*time.Second, ctx.Done())
1412

1413
        if c.config.EnableExternalVpc {
×
1414
                go wait.Until(func() {
×
1415
                        c.syncExternalVpc()
×
1416
                }, 5*time.Second, ctx.Done())
×
1417
        }
1418

1419
        go wait.Until(c.resyncProviderNetworkStatus, 30*time.Second, ctx.Done())
×
1420
        go wait.Until(c.exportSubnetMetrics, 30*time.Second, ctx.Done())
×
1421
        go wait.Until(c.checkSubnetGateway, 5*time.Second, ctx.Done())
×
1422
        go wait.Until(c.syncDistributedSubnetRoutes, 5*time.Second, ctx.Done())
×
1423

×
1424
        go wait.Until(runWorker("add ovn eip", c.addOvnEipQueue, c.handleAddOvnEip), time.Second, ctx.Done())
×
1425
        go wait.Until(runWorker("update ovn eip", c.updateOvnEipQueue, c.handleUpdateOvnEip), time.Second, ctx.Done())
×
1426
        go wait.Until(runWorker("reset ovn eip", c.resetOvnEipQueue, c.handleResetOvnEip), time.Second, ctx.Done())
×
1427
        go wait.Until(runWorker("delete ovn eip", c.delOvnEipQueue, c.handleDelOvnEip), time.Second, ctx.Done())
×
1428

×
1429
        go wait.Until(runWorker("add ovn fip", c.addOvnFipQueue, c.handleAddOvnFip), time.Second, ctx.Done())
×
1430
        go wait.Until(runWorker("update ovn fip", c.updateOvnFipQueue, c.handleUpdateOvnFip), time.Second, ctx.Done())
×
1431
        go wait.Until(runWorker("delete ovn fip", c.delOvnFipQueue, c.handleDelOvnFip), time.Second, ctx.Done())
×
1432

×
1433
        go wait.Until(runWorker("add ovn snat rule", c.addOvnSnatRuleQueue, c.handleAddOvnSnatRule), time.Second, ctx.Done())
×
1434
        go wait.Until(runWorker("update ovn snat rule", c.updateOvnSnatRuleQueue, c.handleUpdateOvnSnatRule), time.Second, ctx.Done())
×
1435
        go wait.Until(runWorker("delete ovn snat rule", c.delOvnSnatRuleQueue, c.handleDelOvnSnatRule), time.Second, ctx.Done())
×
1436

×
1437
        go wait.Until(runWorker("add ovn dnat", c.addOvnDnatRuleQueue, c.handleAddOvnDnatRule), time.Second, ctx.Done())
×
1438
        go wait.Until(runWorker("update ovn dnat", c.updateOvnDnatRuleQueue, c.handleUpdateOvnDnatRule), time.Second, ctx.Done())
×
1439
        go wait.Until(runWorker("delete ovn dnat", c.delOvnDnatRuleQueue, c.handleDelOvnDnatRule), time.Second, ctx.Done())
×
1440

×
1441
        go wait.Until(c.CheckNodePortGroup, time.Duration(c.config.NodePgProbeTime)*time.Minute, ctx.Done())
×
1442

×
1443
        go wait.Until(runWorker("add ip", c.addIPQueue, c.handleAddReservedIP), time.Second, ctx.Done())
×
1444
        go wait.Until(runWorker("update ip", c.updateIPQueue, c.handleUpdateIP), time.Second, ctx.Done())
×
1445
        go wait.Until(runWorker("delete ip", c.delIPQueue, c.handleDelIP), time.Second, ctx.Done())
×
1446

×
1447
        go wait.Until(runWorker("add vip", c.addVirtualIPQueue, c.handleAddVirtualIP), time.Second, ctx.Done())
×
1448
        go wait.Until(runWorker("update vip", c.updateVirtualIPQueue, c.handleUpdateVirtualIP), time.Second, ctx.Done())
×
1449
        go wait.Until(runWorker("update virtual parent for vip", c.updateVirtualParentsQueue, c.handleUpdateVirtualParents), time.Second, ctx.Done())
×
1450
        go wait.Until(runWorker("delete vip", c.delVirtualIPQueue, c.handleDelVirtualIP), time.Second, ctx.Done())
×
1451

×
1452
        go wait.Until(runWorker("add iptables eip", c.addIptablesEipQueue, c.handleAddIptablesEip), time.Second, ctx.Done())
×
1453
        go wait.Until(runWorker("update iptables eip", c.updateIptablesEipQueue, c.handleUpdateIptablesEip), time.Second, ctx.Done())
×
1454
        go wait.Until(runWorker("reset iptables eip", c.resetIptablesEipQueue, c.handleResetIptablesEip), time.Second, ctx.Done())
×
1455
        go wait.Until(runWorker("delete iptables eip", c.delIptablesEipQueue, c.handleDelIptablesEip), time.Second, ctx.Done())
×
1456

×
1457
        go wait.Until(runWorker("add iptables fip", c.addIptablesFipQueue, c.handleAddIptablesFip), time.Second, ctx.Done())
×
1458
        go wait.Until(runWorker("update iptables fip", c.updateIptablesFipQueue, c.handleUpdateIptablesFip), time.Second, ctx.Done())
×
1459
        go wait.Until(runWorker("delete iptables fip", c.delIptablesFipQueue, c.handleDelIptablesFip), time.Second, ctx.Done())
×
1460

×
1461
        go wait.Until(runWorker("add iptables dnat rule", c.addIptablesDnatRuleQueue, c.handleAddIptablesDnatRule), time.Second, ctx.Done())
×
1462
        go wait.Until(runWorker("update iptables dnat rule", c.updateIptablesDnatRuleQueue, c.handleUpdateIptablesDnatRule), time.Second, ctx.Done())
×
1463
        go wait.Until(runWorker("delete iptables dnat rule", c.delIptablesDnatRuleQueue, c.handleDelIptablesDnatRule), time.Second, ctx.Done())
×
1464

×
1465
        go wait.Until(runWorker("add iptables snat rule", c.addIptablesSnatRuleQueue, c.handleAddIptablesSnatRule), time.Second, ctx.Done())
×
1466
        go wait.Until(runWorker("update iptables snat rule", c.updateIptablesSnatRuleQueue, c.handleUpdateIptablesSnatRule), time.Second, ctx.Done())
×
1467
        go wait.Until(runWorker("delete iptables snat rule", c.delIptablesSnatRuleQueue, c.handleDelIptablesSnatRule), time.Second, ctx.Done())
×
1468

×
1469
        go wait.Until(runWorker("add qos policy", c.addQoSPolicyQueue, c.handleAddQoSPolicy), time.Second, ctx.Done())
×
1470
        go wait.Until(runWorker("update qos policy", c.updateQoSPolicyQueue, c.handleUpdateQoSPolicy), time.Second, ctx.Done())
×
1471
        go wait.Until(runWorker("delete qos policy", c.delQoSPolicyQueue, c.handleDelQoSPolicy), time.Second, ctx.Done())
×
1472

×
1473
        if c.config.EnableANP {
×
1474
                go wait.Until(runWorker("add admin network policy", c.addAnpQueue, c.handleAddAnp), time.Second, ctx.Done())
×
1475
                go wait.Until(runWorker("update admin network policy", c.updateAnpQueue, c.handleUpdateAnp), time.Second, ctx.Done())
×
1476
                go wait.Until(runWorker("delete admin network policy", c.deleteAnpQueue, c.handleDeleteAnp), time.Second, ctx.Done())
×
1477

×
1478
                go wait.Until(runWorker("add base admin network policy", c.addBanpQueue, c.handleAddBanp), time.Second, ctx.Done())
×
1479
                go wait.Until(runWorker("update base admin network policy", c.updateBanpQueue, c.handleUpdateBanp), time.Second, ctx.Done())
×
1480
                go wait.Until(runWorker("delete base admin network policy", c.deleteBanpQueue, c.handleDeleteBanp), time.Second, ctx.Done())
×
1481

×
1482
                go wait.Until(runWorker("add cluster network policy", c.addCnpQueue, c.handleAddCnp), time.Second, ctx.Done())
×
1483
                go wait.Until(runWorker("update cluster network policy", c.updateCnpQueue, c.handleUpdateCnp), time.Second, ctx.Done())
×
1484
                go wait.Until(runWorker("delete cluster network policy", c.deleteCnpQueue, c.handleDeleteCnp), time.Second, ctx.Done())
×
1485
        }
×
1486

1487
        if c.config.EnableDNSNameResolver {
×
1488
                go wait.Until(runWorker("add or update dns name resolver", c.addOrUpdateDNSNameResolverQueue, c.handleAddOrUpdateDNSNameResolver), time.Second, ctx.Done())
×
1489
                go wait.Until(runWorker("delete dns name resolver", c.deleteDNSNameResolverQueue, c.handleDeleteDNSNameResolver), time.Second, ctx.Done())
×
1490
        }
×
1491

1492
        if c.config.EnableLiveMigrationOptimize {
×
1493
                go wait.Until(runWorker("add/update vmiMigration ", c.addOrUpdateVMIMigrationQueue, c.handleAddOrUpdateVMIMigration), 50*time.Millisecond, ctx.Done())
×
1494
        }
×
1495

1496
        go wait.Until(runWorker("delete vm", c.deleteVMQueue, c.handleDeleteVM), time.Second, ctx.Done())
×
1497

×
1498
        go wait.Until(c.dbStatus, 15*time.Second, ctx.Done())
×
1499
}
1500

1501
func (c *Controller) allSubnetReady(subnets ...string) (bool, error) {
1✔
1502
        for _, lsName := range subnets {
2✔
1503
                exist, err := c.OVNNbClient.LogicalSwitchExists(lsName)
1✔
1504
                if err != nil {
1✔
1505
                        klog.Error(err)
×
1506
                        return false, fmt.Errorf("check logical switch %s exist: %w", lsName, err)
×
1507
                }
×
1508

1509
                if !exist {
2✔
1510
                        return false, nil
1✔
1511
                }
1✔
1512
        }
1513

1514
        return true, nil
1✔
1515
}
1516

1517
func (c *Controller) initResourceOnce() {
×
1518
        c.registerSubnetMetrics()
×
1519

×
1520
        if err := c.initNodeChassis(); err != nil {
×
1521
                util.LogFatalAndExit(err, "failed to initialize node chassis")
×
1522
        }
×
1523

1524
        if err := c.initDefaultDenyAllSecurityGroup(); err != nil {
×
1525
                util.LogFatalAndExit(err, "failed to initialize 'deny_all' security group")
×
1526
        }
×
1527
        if err := c.syncSecurityGroup(); err != nil {
×
1528
                util.LogFatalAndExit(err, "failed to sync security group")
×
1529
        }
×
1530

1531
        if err := c.syncVpcNatGatewayCR(); err != nil {
×
1532
                util.LogFatalAndExit(err, "failed to sync crd vpc nat gateways")
×
1533
        }
×
1534

1535
        if err := c.initVpcNatGw(); err != nil {
×
1536
                util.LogFatalAndExit(err, "failed to initialize vpc nat gateways")
×
1537
        }
×
1538
        if c.config.EnableLb {
×
1539
                if err := c.initVpcDNSConfig(); err != nil {
×
1540
                        util.LogFatalAndExit(err, "failed to initialize vpc-dns")
×
1541
                }
×
1542
        }
1543

1544
        // remove resources in ovndb that not exist any more in kubernetes resources
1545
        // process gc at last in case of affecting other init process
1546
        if err := c.gc(); err != nil {
×
1547
                util.LogFatalAndExit(err, "failed to run gc")
×
1548
        }
×
1549
}
1550

1551
func processNextWorkItem[T comparable](action string, queue workqueue.TypedRateLimitingInterface[T], handler func(T) error, getItemKey func(any) string) bool {
×
1552
        item, shutdown := queue.Get()
×
1553
        if shutdown {
×
1554
                return false
×
1555
        }
×
1556

1557
        err := func(item T) error {
×
1558
                defer queue.Done(item)
×
1559
                if err := handler(item); err != nil {
×
1560
                        queue.AddRateLimited(item)
×
1561
                        return fmt.Errorf("error syncing %s %q: %w, requeuing", action, getItemKey(item), err)
×
1562
                }
×
1563
                queue.Forget(item)
×
1564
                return nil
×
1565
        }(item)
1566
        if err != nil {
×
1567
                utilruntime.HandleError(err)
×
1568
                return true
×
1569
        }
×
1570
        return true
×
1571
}
1572

1573
func getWorkItemKey(obj any) string {
×
1574
        switch v := obj.(type) {
×
1575
        case string:
×
1576
                return v
×
1577
        case *vpcService:
×
1578
                return cache.MetaObjectToName(obj.(*vpcService).Svc).String()
×
1579
        case *AdminNetworkPolicyChangedDelta:
×
1580
                return v.key
×
1581
        case *SlrInfo:
×
1582
                return v.Name
×
1583
        default:
×
1584
                key, err := cache.MetaNamespaceKeyFunc(obj)
×
1585
                if err != nil {
×
1586
                        utilruntime.HandleError(err)
×
1587
                        return ""
×
1588
                }
×
1589
                return key
×
1590
        }
1591
}
1592

1593
func runWorker[T comparable](action string, queue workqueue.TypedRateLimitingInterface[T], handler func(T) error) func() {
×
1594
        return func() {
×
1595
                for processNextWorkItem(action, queue, handler, getWorkItemKey) {
×
1596
                }
×
1597
        }
1598
}
1599

1600
// apiResourceExists checks if all specified kinds exist in the given group version.
1601
// It returns true if all kinds are found, false otherwise.
1602
// Parameters:
1603
// - discoveryClient: The discovery client to use for querying API resources.
1604
// - gv: The group version string (e.g., "apps/v1").
1605
// - kinds: A variadic list of kind names to check for existence (e.g., "Deployment", "StatefulSet").
1606
func apiResourceExists(discoveryClient discovery.DiscoveryInterface, gv string, kinds ...string) (bool, error) {
×
1607
        apiResourceLists, err := discoveryClient.ServerResourcesForGroupVersion(gv)
×
1608
        if err != nil {
×
1609
                if k8serrors.IsNotFound(err) {
×
1610
                        return false, nil
×
1611
                }
×
1612
                return false, fmt.Errorf("failed to discover api resources for %s: %w", gv, err)
×
1613
        }
1614

1615
        existingKinds := set.New[string]()
×
1616
        for _, apiResource := range apiResourceLists.APIResources {
×
1617
                existingKinds.Insert(apiResource.Kind)
×
1618
        }
×
1619

1620
        return existingKinds.HasAll(kinds...), nil
×
1621
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc