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

kubeovn / kube-ovn / 13757275928

10 Mar 2025 05:06AM UTC coverage: 22.036% (-0.03%) from 22.065%
13757275928

push

github

web-flow
add copy of the kubevirt informer from upstream (#5065)

Signed-off-by: oilbeater <liumengxinfly@gmail.com>
Co-authored-by: Christoph Mewes <christoph@kubermatic.com>

0 of 72 new or added lines in 3 files covered. (0.0%)

10265 of 46582 relevant lines covered (22.04%)

0.26 hits per line

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

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

3
import (
4
        "context"
5
        "fmt"
6
        "runtime"
7
        "strings"
8
        "time"
9

10
        "github.com/puzpuzpuz/xsync/v3"
11
        "golang.org/x/time/rate"
12
        corev1 "k8s.io/api/core/v1"
13
        metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
14
        "k8s.io/apimachinery/pkg/labels"
15
        utilruntime "k8s.io/apimachinery/pkg/util/runtime"
16
        "k8s.io/apimachinery/pkg/util/wait"
17
        kubeinformers "k8s.io/client-go/informers"
18
        "k8s.io/client-go/kubernetes/scheme"
19
        typedcorev1 "k8s.io/client-go/kubernetes/typed/core/v1"
20
        appsv1 "k8s.io/client-go/listers/apps/v1"
21
        certListerv1 "k8s.io/client-go/listers/certificates/v1"
22
        v1 "k8s.io/client-go/listers/core/v1"
23
        netv1 "k8s.io/client-go/listers/networking/v1"
24
        "k8s.io/client-go/tools/cache"
25
        "k8s.io/client-go/tools/record"
26
        "k8s.io/client-go/util/workqueue"
27
        "k8s.io/klog/v2"
28
        "k8s.io/utils/keymutex"
29
        v1alpha1 "sigs.k8s.io/network-policy-api/apis/v1alpha1"
30
        anpinformer "sigs.k8s.io/network-policy-api/pkg/client/informers/externalversions"
31
        anplister "sigs.k8s.io/network-policy-api/pkg/client/listers/apis/v1alpha1"
32

33
        "github.com/kubeovn/kube-ovn/pkg/informer"
34

35
        kubeovnv1 "github.com/kubeovn/kube-ovn/pkg/apis/kubeovn/v1"
36
        kubeovninformer "github.com/kubeovn/kube-ovn/pkg/client/informers/externalversions"
37
        kubeovnlister "github.com/kubeovn/kube-ovn/pkg/client/listers/kubeovn/v1"
38
        ovnipam "github.com/kubeovn/kube-ovn/pkg/ipam"
39
        "github.com/kubeovn/kube-ovn/pkg/ovs"
40
        "github.com/kubeovn/kube-ovn/pkg/util"
41
)
42

43
const controllerAgentName = "kube-ovn-controller"
44

45
const (
46
        logicalSwitchKey              = "ls"
47
        logicalRouterKey              = "lr"
48
        portGroupKey                  = "pg"
49
        networkPolicyKey              = "np"
50
        sgKey                         = "sg"
51
        associatedSgKeyPrefix         = "associated_sg_"
52
        sgsKey                        = "security_groups"
53
        u2oKey                        = "u2o"
54
        adminNetworkPolicyKey         = "anp"
55
        baselineAdminNetworkPolicyKey = "banp"
56
)
57

58
// Controller is kube-ovn main controller that watch ns/pod/node/svc/ep and operate ovn
59
type Controller struct {
60
        config *Configuration
61

62
        ipam           *ovnipam.IPAM
63
        namedPort      *NamedPort
64
        anpPrioNameMap map[int32]string
65
        anpNamePrioMap map[string]int32
66

67
        OVNNbClient ovs.NbClient
68
        OVNSbClient ovs.SbClient
69

70
        // ExternalGatewayType define external gateway type, centralized
71
        ExternalGatewayType string
72

73
        podsLister             v1.PodLister
74
        podsSynced             cache.InformerSynced
75
        addOrUpdatePodQueue    workqueue.TypedRateLimitingInterface[string]
76
        deletePodQueue         workqueue.TypedRateLimitingInterface[string]
77
        deletingPodObjMap      *xsync.MapOf[string, *corev1.Pod]
78
        deletingNodeObjMap     *xsync.MapOf[string, *corev1.Node]
79
        updatePodSecurityQueue workqueue.TypedRateLimitingInterface[string]
80
        podKeyMutex            keymutex.KeyMutex
81

82
        vpcsLister           kubeovnlister.VpcLister
83
        vpcSynced            cache.InformerSynced
84
        addOrUpdateVpcQueue  workqueue.TypedRateLimitingInterface[string]
85
        delVpcQueue          workqueue.TypedRateLimitingInterface[*kubeovnv1.Vpc]
86
        updateVpcStatusQueue workqueue.TypedRateLimitingInterface[string]
87
        vpcKeyMutex          keymutex.KeyMutex
88

89
        vpcNatGatewayLister           kubeovnlister.VpcNatGatewayLister
90
        vpcNatGatewaySynced           cache.InformerSynced
91
        addOrUpdateVpcNatGatewayQueue workqueue.TypedRateLimitingInterface[string]
92
        delVpcNatGatewayQueue         workqueue.TypedRateLimitingInterface[string]
93
        initVpcNatGatewayQueue        workqueue.TypedRateLimitingInterface[string]
94
        updateVpcEipQueue             workqueue.TypedRateLimitingInterface[string]
95
        updateVpcFloatingIPQueue      workqueue.TypedRateLimitingInterface[string]
96
        updateVpcDnatQueue            workqueue.TypedRateLimitingInterface[string]
97
        updateVpcSnatQueue            workqueue.TypedRateLimitingInterface[string]
98
        updateVpcSubnetQueue          workqueue.TypedRateLimitingInterface[string]
99
        vpcNatGwKeyMutex              keymutex.KeyMutex
100

101
        vpcEgressGatewayLister           kubeovnlister.VpcEgressGatewayLister
102
        vpcEgressGatewaySynced           cache.InformerSynced
103
        addOrUpdateVpcEgressGatewayQueue workqueue.TypedRateLimitingInterface[string]
104
        delVpcEgressGatewayQueue         workqueue.TypedRateLimitingInterface[string]
105
        vpcEgressGatewayKeyMutex         keymutex.KeyMutex
106

107
        switchLBRuleLister      kubeovnlister.SwitchLBRuleLister
108
        switchLBRuleSynced      cache.InformerSynced
109
        addSwitchLBRuleQueue    workqueue.TypedRateLimitingInterface[string]
110
        updateSwitchLBRuleQueue workqueue.TypedRateLimitingInterface[*SlrInfo]
111
        delSwitchLBRuleQueue    workqueue.TypedRateLimitingInterface[*SlrInfo]
112

113
        vpcDNSLister           kubeovnlister.VpcDnsLister
114
        vpcDNSSynced           cache.InformerSynced
115
        addOrUpdateVpcDNSQueue workqueue.TypedRateLimitingInterface[string]
116
        delVpcDNSQueue         workqueue.TypedRateLimitingInterface[string]
117

118
        subnetsLister           kubeovnlister.SubnetLister
119
        subnetSynced            cache.InformerSynced
120
        addOrUpdateSubnetQueue  workqueue.TypedRateLimitingInterface[string]
121
        deleteSubnetQueue       workqueue.TypedRateLimitingInterface[*kubeovnv1.Subnet]
122
        updateSubnetStatusQueue workqueue.TypedRateLimitingInterface[string]
123
        syncVirtualPortsQueue   workqueue.TypedRateLimitingInterface[string]
124
        subnetKeyMutex          keymutex.KeyMutex
125

126
        ippoolLister            kubeovnlister.IPPoolLister
127
        ippoolSynced            cache.InformerSynced
128
        addOrUpdateIPPoolQueue  workqueue.TypedRateLimitingInterface[string]
129
        updateIPPoolStatusQueue workqueue.TypedRateLimitingInterface[string]
130
        deleteIPPoolQueue       workqueue.TypedRateLimitingInterface[*kubeovnv1.IPPool]
131
        ippoolKeyMutex          keymutex.KeyMutex
132

133
        ipsLister     kubeovnlister.IPLister
134
        ipSynced      cache.InformerSynced
135
        addIPQueue    workqueue.TypedRateLimitingInterface[string]
136
        updateIPQueue workqueue.TypedRateLimitingInterface[string]
137
        delIPQueue    workqueue.TypedRateLimitingInterface[*kubeovnv1.IP]
138

139
        virtualIpsLister          kubeovnlister.VipLister
140
        virtualIpsSynced          cache.InformerSynced
141
        addVirtualIPQueue         workqueue.TypedRateLimitingInterface[string]
142
        updateVirtualIPQueue      workqueue.TypedRateLimitingInterface[string]
143
        updateVirtualParentsQueue workqueue.TypedRateLimitingInterface[string]
144
        delVirtualIPQueue         workqueue.TypedRateLimitingInterface[*kubeovnv1.Vip]
145

146
        iptablesEipsLister     kubeovnlister.IptablesEIPLister
147
        iptablesEipSynced      cache.InformerSynced
148
        addIptablesEipQueue    workqueue.TypedRateLimitingInterface[string]
149
        updateIptablesEipQueue workqueue.TypedRateLimitingInterface[string]
150
        resetIptablesEipQueue  workqueue.TypedRateLimitingInterface[string]
151
        delIptablesEipQueue    workqueue.TypedRateLimitingInterface[string]
152

153
        iptablesFipsLister     kubeovnlister.IptablesFIPRuleLister
154
        iptablesFipSynced      cache.InformerSynced
155
        addIptablesFipQueue    workqueue.TypedRateLimitingInterface[string]
156
        updateIptablesFipQueue workqueue.TypedRateLimitingInterface[string]
157
        delIptablesFipQueue    workqueue.TypedRateLimitingInterface[string]
158

159
        iptablesDnatRulesLister     kubeovnlister.IptablesDnatRuleLister
160
        iptablesDnatRuleSynced      cache.InformerSynced
161
        addIptablesDnatRuleQueue    workqueue.TypedRateLimitingInterface[string]
162
        updateIptablesDnatRuleQueue workqueue.TypedRateLimitingInterface[string]
163
        delIptablesDnatRuleQueue    workqueue.TypedRateLimitingInterface[string]
164

165
        iptablesSnatRulesLister     kubeovnlister.IptablesSnatRuleLister
166
        iptablesSnatRuleSynced      cache.InformerSynced
167
        addIptablesSnatRuleQueue    workqueue.TypedRateLimitingInterface[string]
168
        updateIptablesSnatRuleQueue workqueue.TypedRateLimitingInterface[string]
169
        delIptablesSnatRuleQueue    workqueue.TypedRateLimitingInterface[string]
170

171
        ovnEipsLister     kubeovnlister.OvnEipLister
172
        ovnEipSynced      cache.InformerSynced
173
        addOvnEipQueue    workqueue.TypedRateLimitingInterface[string]
174
        updateOvnEipQueue workqueue.TypedRateLimitingInterface[string]
175
        resetOvnEipQueue  workqueue.TypedRateLimitingInterface[string]
176
        delOvnEipQueue    workqueue.TypedRateLimitingInterface[string]
177

178
        ovnFipsLister     kubeovnlister.OvnFipLister
179
        ovnFipSynced      cache.InformerSynced
180
        addOvnFipQueue    workqueue.TypedRateLimitingInterface[string]
181
        updateOvnFipQueue workqueue.TypedRateLimitingInterface[string]
182
        delOvnFipQueue    workqueue.TypedRateLimitingInterface[string]
183

184
        ovnSnatRulesLister     kubeovnlister.OvnSnatRuleLister
185
        ovnSnatRuleSynced      cache.InformerSynced
186
        addOvnSnatRuleQueue    workqueue.TypedRateLimitingInterface[string]
187
        updateOvnSnatRuleQueue workqueue.TypedRateLimitingInterface[string]
188
        delOvnSnatRuleQueue    workqueue.TypedRateLimitingInterface[string]
189

190
        ovnDnatRulesLister     kubeovnlister.OvnDnatRuleLister
191
        ovnDnatRuleSynced      cache.InformerSynced
192
        addOvnDnatRuleQueue    workqueue.TypedRateLimitingInterface[string]
193
        updateOvnDnatRuleQueue workqueue.TypedRateLimitingInterface[string]
194
        delOvnDnatRuleQueue    workqueue.TypedRateLimitingInterface[string]
195

196
        providerNetworksLister kubeovnlister.ProviderNetworkLister
197
        providerNetworkSynced  cache.InformerSynced
198

199
        vlansLister     kubeovnlister.VlanLister
200
        vlanSynced      cache.InformerSynced
201
        addVlanQueue    workqueue.TypedRateLimitingInterface[string]
202
        delVlanQueue    workqueue.TypedRateLimitingInterface[string]
203
        updateVlanQueue workqueue.TypedRateLimitingInterface[string]
204
        vlanKeyMutex    keymutex.KeyMutex
205

206
        namespacesLister  v1.NamespaceLister
207
        namespacesSynced  cache.InformerSynced
208
        addNamespaceQueue workqueue.TypedRateLimitingInterface[string]
209
        nsKeyMutex        keymutex.KeyMutex
210

211
        nodesLister     v1.NodeLister
212
        nodesSynced     cache.InformerSynced
213
        addNodeQueue    workqueue.TypedRateLimitingInterface[string]
214
        updateNodeQueue workqueue.TypedRateLimitingInterface[string]
215
        deleteNodeQueue workqueue.TypedRateLimitingInterface[string]
216
        nodeKeyMutex    keymutex.KeyMutex
217

218
        servicesLister     v1.ServiceLister
219
        serviceSynced      cache.InformerSynced
220
        addServiceQueue    workqueue.TypedRateLimitingInterface[string]
221
        deleteServiceQueue workqueue.TypedRateLimitingInterface[*vpcService]
222
        updateServiceQueue workqueue.TypedRateLimitingInterface[*updateSvcObject]
223
        svcKeyMutex        keymutex.KeyMutex
224

225
        endpointsLister          v1.EndpointsLister
226
        endpointsSynced          cache.InformerSynced
227
        addOrUpdateEndpointQueue workqueue.TypedRateLimitingInterface[string]
228
        epKeyMutex               keymutex.KeyMutex
229

230
        deploymentsLister appsv1.DeploymentLister
231
        deploymentsSynced cache.InformerSynced
232

233
        npsLister     netv1.NetworkPolicyLister
234
        npsSynced     cache.InformerSynced
235
        updateNpQueue workqueue.TypedRateLimitingInterface[string]
236
        deleteNpQueue workqueue.TypedRateLimitingInterface[string]
237
        npKeyMutex    keymutex.KeyMutex
238

239
        sgsLister          kubeovnlister.SecurityGroupLister
240
        sgSynced           cache.InformerSynced
241
        addOrUpdateSgQueue workqueue.TypedRateLimitingInterface[string]
242
        delSgQueue         workqueue.TypedRateLimitingInterface[string]
243
        syncSgPortsQueue   workqueue.TypedRateLimitingInterface[string]
244
        sgKeyMutex         keymutex.KeyMutex
245

246
        qosPoliciesLister    kubeovnlister.QoSPolicyLister
247
        qosPolicySynced      cache.InformerSynced
248
        addQoSPolicyQueue    workqueue.TypedRateLimitingInterface[string]
249
        updateQoSPolicyQueue workqueue.TypedRateLimitingInterface[string]
250
        delQoSPolicyQueue    workqueue.TypedRateLimitingInterface[string]
251

252
        configMapsLister v1.ConfigMapLister
253
        configMapsSynced cache.InformerSynced
254

255
        anpsLister     anplister.AdminNetworkPolicyLister
256
        anpsSynced     cache.InformerSynced
257
        addAnpQueue    workqueue.TypedRateLimitingInterface[string]
258
        updateAnpQueue workqueue.TypedRateLimitingInterface[*AdminNetworkPolicyChangedDelta]
259
        deleteAnpQueue workqueue.TypedRateLimitingInterface[*v1alpha1.AdminNetworkPolicy]
260
        anpKeyMutex    keymutex.KeyMutex
261

262
        banpsLister     anplister.BaselineAdminNetworkPolicyLister
263
        banpsSynced     cache.InformerSynced
264
        addBanpQueue    workqueue.TypedRateLimitingInterface[string]
265
        updateBanpQueue workqueue.TypedRateLimitingInterface[*AdminNetworkPolicyChangedDelta]
266
        deleteBanpQueue workqueue.TypedRateLimitingInterface[*v1alpha1.BaselineAdminNetworkPolicy]
267
        banpKeyMutex    keymutex.KeyMutex
268

269
        csrLister           certListerv1.CertificateSigningRequestLister
270
        csrSynced           cache.InformerSynced
271
        addOrUpdateCsrQueue workqueue.TypedRateLimitingInterface[string]
272

273
        vmiMigrationSynced           cache.InformerSynced
274
        addOrUpdateVMIMigrationQueue workqueue.TypedRateLimitingInterface[string]
275
        kubevirtInformerFactory      informer.KubeVirtInformerFactory
276

277
        recorder               record.EventRecorder
278
        informerFactory        kubeinformers.SharedInformerFactory
279
        cmInformerFactory      kubeinformers.SharedInformerFactory
280
        deployInformerFactory  kubeinformers.SharedInformerFactory
281
        kubeovnInformerFactory kubeovninformer.SharedInformerFactory
282
        anpInformerFactory     anpinformer.SharedInformerFactory
283
}
284

285
func newTypedRateLimitingQueue[T comparable](name string, rateLimiter workqueue.TypedRateLimiter[T]) workqueue.TypedRateLimitingInterface[T] {
1✔
286
        if rateLimiter == nil {
2✔
287
                rateLimiter = workqueue.DefaultTypedControllerRateLimiter[T]()
1✔
288
        }
1✔
289
        return workqueue.NewTypedRateLimitingQueueWithConfig(rateLimiter, workqueue.TypedRateLimitingQueueConfig[T]{Name: name})
1✔
290
}
291

292
// Run creates and runs a new ovn controller
293
func Run(ctx context.Context, config *Configuration) {
×
294
        klog.V(4).Info("Creating event broadcaster")
×
295
        eventBroadcaster := record.NewBroadcasterWithCorrelatorOptions(record.CorrelatorOptions{BurstSize: 100})
×
296
        eventBroadcaster.StartLogging(klog.Infof)
×
297
        eventBroadcaster.StartRecordingToSink(&typedcorev1.EventSinkImpl{Interface: config.KubeFactoryClient.CoreV1().Events("")})
×
298
        recorder := eventBroadcaster.NewRecorder(scheme.Scheme, corev1.EventSource{Component: controllerAgentName})
×
299
        custCrdRateLimiter := workqueue.NewTypedMaxOfRateLimiter(
×
300
                workqueue.NewTypedItemExponentialFailureRateLimiter[string](time.Duration(config.CustCrdRetryMinDelay)*time.Second, time.Duration(config.CustCrdRetryMaxDelay)*time.Second),
×
301
                &workqueue.TypedBucketRateLimiter[string]{Limiter: rate.NewLimiter(rate.Limit(10), 100)},
×
302
        )
×
303

×
304
        selector, err := labels.Parse(util.VpcEgressGatewayLabel)
×
305
        if err != nil {
×
306
                util.LogFatalAndExit(err, "failed to create label selector for vpc egress gateway workload")
×
307
        }
×
308

309
        informerFactory := kubeinformers.NewSharedInformerFactoryWithOptions(config.KubeFactoryClient, 0,
×
310
                kubeinformers.WithTweakListOptions(func(listOption *metav1.ListOptions) {
×
311
                        listOption.AllowWatchBookmarks = true
×
312
                }))
×
313
        cmInformerFactory := kubeinformers.NewSharedInformerFactoryWithOptions(config.KubeFactoryClient, 0,
×
314
                kubeinformers.WithTweakListOptions(func(listOption *metav1.ListOptions) {
×
315
                        listOption.AllowWatchBookmarks = true
×
316
                }), kubeinformers.WithNamespace(config.PodNamespace))
×
317
        // deployment informer used to list/watch vpc egress gateway workloads
318
        deployInformerFactory := kubeinformers.NewSharedInformerFactoryWithOptions(config.KubeFactoryClient, 0,
×
319
                kubeinformers.WithTweakListOptions(func(listOption *metav1.ListOptions) {
×
320
                        listOption.AllowWatchBookmarks = true
×
321
                        listOption.LabelSelector = selector.String()
×
322
                }))
×
323
        kubeovnInformerFactory := kubeovninformer.NewSharedInformerFactoryWithOptions(config.KubeOvnFactoryClient, 0,
×
324
                kubeovninformer.WithTweakListOptions(func(listOption *metav1.ListOptions) {
×
325
                        listOption.AllowWatchBookmarks = true
×
326
                }))
×
327
        anpInformerFactory := anpinformer.NewSharedInformerFactoryWithOptions(config.AnpClient, 0,
×
328
                anpinformer.WithTweakListOptions(func(listOption *metav1.ListOptions) {
×
329
                        listOption.AllowWatchBookmarks = true
×
330
                }))
×
331

NEW
332
        kubevirtInformerFactory := informer.NewKubeVirtInformerFactory(config.KubevirtClient.RestClient(), config.KubevirtClient, nil, util.KubevirtNamespace)
×
333

×
334
        vpcInformer := kubeovnInformerFactory.Kubeovn().V1().Vpcs()
×
335
        vpcNatGatewayInformer := kubeovnInformerFactory.Kubeovn().V1().VpcNatGateways()
×
336
        vpcEgressGatewayInformer := kubeovnInformerFactory.Kubeovn().V1().VpcEgressGateways()
×
337
        subnetInformer := kubeovnInformerFactory.Kubeovn().V1().Subnets()
×
338
        ippoolInformer := kubeovnInformerFactory.Kubeovn().V1().IPPools()
×
339
        ipInformer := kubeovnInformerFactory.Kubeovn().V1().IPs()
×
340
        virtualIPInformer := kubeovnInformerFactory.Kubeovn().V1().Vips()
×
341
        iptablesEipInformer := kubeovnInformerFactory.Kubeovn().V1().IptablesEIPs()
×
342
        iptablesFipInformer := kubeovnInformerFactory.Kubeovn().V1().IptablesFIPRules()
×
343
        iptablesDnatRuleInformer := kubeovnInformerFactory.Kubeovn().V1().IptablesDnatRules()
×
344
        iptablesSnatRuleInformer := kubeovnInformerFactory.Kubeovn().V1().IptablesSnatRules()
×
345
        vlanInformer := kubeovnInformerFactory.Kubeovn().V1().Vlans()
×
346
        providerNetworkInformer := kubeovnInformerFactory.Kubeovn().V1().ProviderNetworks()
×
347
        sgInformer := kubeovnInformerFactory.Kubeovn().V1().SecurityGroups()
×
348
        podInformer := informerFactory.Core().V1().Pods()
×
349
        namespaceInformer := informerFactory.Core().V1().Namespaces()
×
350
        nodeInformer := informerFactory.Core().V1().Nodes()
×
351
        serviceInformer := informerFactory.Core().V1().Services()
×
352
        endpointInformer := informerFactory.Core().V1().Endpoints()
×
353
        deploymentInformer := deployInformerFactory.Apps().V1().Deployments()
×
354
        qosPolicyInformer := kubeovnInformerFactory.Kubeovn().V1().QoSPolicies()
×
355
        configMapInformer := cmInformerFactory.Core().V1().ConfigMaps()
×
356
        npInformer := informerFactory.Networking().V1().NetworkPolicies()
×
357
        switchLBRuleInformer := kubeovnInformerFactory.Kubeovn().V1().SwitchLBRules()
×
358
        vpcDNSInformer := kubeovnInformerFactory.Kubeovn().V1().VpcDnses()
×
359
        ovnEipInformer := kubeovnInformerFactory.Kubeovn().V1().OvnEips()
×
360
        ovnFipInformer := kubeovnInformerFactory.Kubeovn().V1().OvnFips()
×
361
        ovnSnatRuleInformer := kubeovnInformerFactory.Kubeovn().V1().OvnSnatRules()
×
362
        ovnDnatRuleInformer := kubeovnInformerFactory.Kubeovn().V1().OvnDnatRules()
×
363
        anpInformer := anpInformerFactory.Policy().V1alpha1().AdminNetworkPolicies()
×
364
        banpInformer := anpInformerFactory.Policy().V1alpha1().BaselineAdminNetworkPolicies()
×
365
        csrInformer := informerFactory.Certificates().V1().CertificateSigningRequests()
×
366
        vmiMigrationInformer := kubevirtInformerFactory.VirtualMachineInstanceMigration()
×
367

×
368
        numKeyLocks := runtime.NumCPU() * 2
×
369
        if numKeyLocks < config.WorkerNum*2 {
×
370
                numKeyLocks = config.WorkerNum * 2
×
371
        }
×
372
        controller := &Controller{
×
373
                config:             config,
×
374
                deletingPodObjMap:  xsync.NewMapOf[string, *corev1.Pod](),
×
375
                deletingNodeObjMap: xsync.NewMapOf[string, *corev1.Node](),
×
376
                ipam:               ovnipam.NewIPAM(),
×
377
                namedPort:          NewNamedPort(),
×
378

×
379
                vpcsLister:           vpcInformer.Lister(),
×
380
                vpcSynced:            vpcInformer.Informer().HasSynced,
×
381
                addOrUpdateVpcQueue:  newTypedRateLimitingQueue[string]("AddOrUpdateVpc", nil),
×
382
                delVpcQueue:          newTypedRateLimitingQueue[*kubeovnv1.Vpc]("DeleteVpc", nil),
×
383
                updateVpcStatusQueue: newTypedRateLimitingQueue[string]("UpdateVpcStatus", nil),
×
384
                vpcKeyMutex:          keymutex.NewHashed(numKeyLocks),
×
385

×
386
                vpcNatGatewayLister:           vpcNatGatewayInformer.Lister(),
×
387
                vpcNatGatewaySynced:           vpcNatGatewayInformer.Informer().HasSynced,
×
388
                addOrUpdateVpcNatGatewayQueue: newTypedRateLimitingQueue("AddOrUpdateVpcNatGw", custCrdRateLimiter),
×
389
                initVpcNatGatewayQueue:        newTypedRateLimitingQueue("InitVpcNatGw", custCrdRateLimiter),
×
390
                delVpcNatGatewayQueue:         newTypedRateLimitingQueue("DeleteVpcNatGw", custCrdRateLimiter),
×
391
                updateVpcEipQueue:             newTypedRateLimitingQueue("UpdateVpcEip", custCrdRateLimiter),
×
392
                updateVpcFloatingIPQueue:      newTypedRateLimitingQueue("UpdateVpcFloatingIp", custCrdRateLimiter),
×
393
                updateVpcDnatQueue:            newTypedRateLimitingQueue("UpdateVpcDnat", custCrdRateLimiter),
×
394
                updateVpcSnatQueue:            newTypedRateLimitingQueue("UpdateVpcSnat", custCrdRateLimiter),
×
395
                updateVpcSubnetQueue:          newTypedRateLimitingQueue("UpdateVpcSubnet", custCrdRateLimiter),
×
396
                vpcNatGwKeyMutex:              keymutex.NewHashed(numKeyLocks),
×
397

×
398
                vpcEgressGatewayLister:           vpcEgressGatewayInformer.Lister(),
×
399
                vpcEgressGatewaySynced:           vpcEgressGatewayInformer.Informer().HasSynced,
×
400
                addOrUpdateVpcEgressGatewayQueue: newTypedRateLimitingQueue("AddOrUpdateVpcEgressGateway", custCrdRateLimiter),
×
401
                delVpcEgressGatewayQueue:         newTypedRateLimitingQueue("DeleteVpcEgressGateway", custCrdRateLimiter),
×
402
                vpcEgressGatewayKeyMutex:         keymutex.NewHashed(numKeyLocks),
×
403

×
404
                subnetsLister:           subnetInformer.Lister(),
×
405
                subnetSynced:            subnetInformer.Informer().HasSynced,
×
406
                addOrUpdateSubnetQueue:  newTypedRateLimitingQueue[string]("AddSubnet", nil),
×
407
                deleteSubnetQueue:       newTypedRateLimitingQueue[*kubeovnv1.Subnet]("DeleteSubnet", nil),
×
408
                updateSubnetStatusQueue: newTypedRateLimitingQueue[string]("UpdateSubnetStatus", nil),
×
409
                syncVirtualPortsQueue:   newTypedRateLimitingQueue[string]("SyncVirtualPort", nil),
×
410
                subnetKeyMutex:          keymutex.NewHashed(numKeyLocks),
×
411

×
412
                ippoolLister:            ippoolInformer.Lister(),
×
413
                ippoolSynced:            ippoolInformer.Informer().HasSynced,
×
414
                addOrUpdateIPPoolQueue:  newTypedRateLimitingQueue[string]("AddIPPool", nil),
×
415
                updateIPPoolStatusQueue: newTypedRateLimitingQueue[string]("UpdateIPPoolStatus", nil),
×
416
                deleteIPPoolQueue:       newTypedRateLimitingQueue[*kubeovnv1.IPPool]("DeleteIPPool", nil),
×
417
                ippoolKeyMutex:          keymutex.NewHashed(numKeyLocks),
×
418

×
419
                ipsLister:     ipInformer.Lister(),
×
420
                ipSynced:      ipInformer.Informer().HasSynced,
×
421
                addIPQueue:    newTypedRateLimitingQueue[string]("AddIP", nil),
×
422
                updateIPQueue: newTypedRateLimitingQueue[string]("UpdateIP", nil),
×
423
                delIPQueue:    newTypedRateLimitingQueue[*kubeovnv1.IP]("DeleteIP", nil),
×
424

×
425
                virtualIpsLister:          virtualIPInformer.Lister(),
×
426
                virtualIpsSynced:          virtualIPInformer.Informer().HasSynced,
×
427
                addVirtualIPQueue:         newTypedRateLimitingQueue[string]("AddVirtualIP", nil),
×
428
                updateVirtualIPQueue:      newTypedRateLimitingQueue[string]("UpdateVirtualIP", nil),
×
429
                updateVirtualParentsQueue: newTypedRateLimitingQueue[string]("UpdateVirtualParents", nil),
×
430
                delVirtualIPQueue:         newTypedRateLimitingQueue[*kubeovnv1.Vip]("DeleteVirtualIP", nil),
×
431

×
432
                iptablesEipsLister:     iptablesEipInformer.Lister(),
×
433
                iptablesEipSynced:      iptablesEipInformer.Informer().HasSynced,
×
434
                addIptablesEipQueue:    newTypedRateLimitingQueue("AddIptablesEip", custCrdRateLimiter),
×
435
                updateIptablesEipQueue: newTypedRateLimitingQueue("UpdateIptablesEip", custCrdRateLimiter),
×
436
                resetIptablesEipQueue:  newTypedRateLimitingQueue("ResetIptablesEip", custCrdRateLimiter),
×
437
                delIptablesEipQueue:    newTypedRateLimitingQueue("DeleteIptablesEip", custCrdRateLimiter),
×
438

×
439
                iptablesFipsLister:     iptablesFipInformer.Lister(),
×
440
                iptablesFipSynced:      iptablesFipInformer.Informer().HasSynced,
×
441
                addIptablesFipQueue:    newTypedRateLimitingQueue("AddIptablesFip", custCrdRateLimiter),
×
442
                updateIptablesFipQueue: newTypedRateLimitingQueue("UpdateIptablesFip", custCrdRateLimiter),
×
443
                delIptablesFipQueue:    newTypedRateLimitingQueue("DeleteIptablesFip", custCrdRateLimiter),
×
444

×
445
                iptablesDnatRulesLister:     iptablesDnatRuleInformer.Lister(),
×
446
                iptablesDnatRuleSynced:      iptablesDnatRuleInformer.Informer().HasSynced,
×
447
                addIptablesDnatRuleQueue:    newTypedRateLimitingQueue("AddIptablesDnatRule", custCrdRateLimiter),
×
448
                updateIptablesDnatRuleQueue: newTypedRateLimitingQueue("UpdateIptablesDnatRule", custCrdRateLimiter),
×
449
                delIptablesDnatRuleQueue:    newTypedRateLimitingQueue("DeleteIptablesDnatRule", custCrdRateLimiter),
×
450

×
451
                iptablesSnatRulesLister:     iptablesSnatRuleInformer.Lister(),
×
452
                iptablesSnatRuleSynced:      iptablesSnatRuleInformer.Informer().HasSynced,
×
453
                addIptablesSnatRuleQueue:    newTypedRateLimitingQueue("AddIptablesSnatRule", custCrdRateLimiter),
×
454
                updateIptablesSnatRuleQueue: newTypedRateLimitingQueue("UpdateIptablesSnatRule", custCrdRateLimiter),
×
455
                delIptablesSnatRuleQueue:    newTypedRateLimitingQueue("DeleteIptablesSnatRule", custCrdRateLimiter),
×
456

×
457
                vlansLister:     vlanInformer.Lister(),
×
458
                vlanSynced:      vlanInformer.Informer().HasSynced,
×
459
                addVlanQueue:    newTypedRateLimitingQueue[string]("AddVlan", nil),
×
460
                delVlanQueue:    newTypedRateLimitingQueue[string]("DeleteVlan", nil),
×
461
                updateVlanQueue: newTypedRateLimitingQueue[string]("UpdateVlan", nil),
×
462
                vlanKeyMutex:    keymutex.NewHashed(numKeyLocks),
×
463

×
464
                providerNetworksLister: providerNetworkInformer.Lister(),
×
465
                providerNetworkSynced:  providerNetworkInformer.Informer().HasSynced,
×
466

×
467
                podsLister:          podInformer.Lister(),
×
468
                podsSynced:          podInformer.Informer().HasSynced,
×
469
                addOrUpdatePodQueue: newTypedRateLimitingQueue[string]("AddOrUpdatePod", nil),
×
470
                deletePodQueue: workqueue.NewTypedRateLimitingQueueWithConfig(
×
471
                        workqueue.DefaultTypedControllerRateLimiter[string](),
×
472
                        workqueue.TypedRateLimitingQueueConfig[string]{
×
473
                                Name:          "DeletePod",
×
474
                                DelayingQueue: workqueue.NewTypedDelayingQueue[string](),
×
475
                        },
×
476
                ),
×
477
                updatePodSecurityQueue: newTypedRateLimitingQueue[string]("UpdatePodSecurity", nil),
×
478
                podKeyMutex:            keymutex.NewHashed(numKeyLocks),
×
479

×
480
                namespacesLister:  namespaceInformer.Lister(),
×
481
                namespacesSynced:  namespaceInformer.Informer().HasSynced,
×
482
                addNamespaceQueue: newTypedRateLimitingQueue[string]("AddNamespace", nil),
×
483
                nsKeyMutex:        keymutex.NewHashed(numKeyLocks),
×
484

×
485
                nodesLister:     nodeInformer.Lister(),
×
486
                nodesSynced:     nodeInformer.Informer().HasSynced,
×
487
                addNodeQueue:    newTypedRateLimitingQueue[string]("AddNode", nil),
×
488
                updateNodeQueue: newTypedRateLimitingQueue[string]("UpdateNode", nil),
×
489
                deleteNodeQueue: newTypedRateLimitingQueue[string]("DeleteNode", nil),
×
490
                nodeKeyMutex:    keymutex.NewHashed(numKeyLocks),
×
491

×
492
                servicesLister:     serviceInformer.Lister(),
×
493
                serviceSynced:      serviceInformer.Informer().HasSynced,
×
494
                addServiceQueue:    newTypedRateLimitingQueue[string]("AddService", nil),
×
495
                deleteServiceQueue: newTypedRateLimitingQueue[*vpcService]("DeleteService", nil),
×
496
                updateServiceQueue: newTypedRateLimitingQueue[*updateSvcObject]("UpdateService", nil),
×
497
                svcKeyMutex:        keymutex.NewHashed(numKeyLocks),
×
498

×
499
                endpointsLister:          endpointInformer.Lister(),
×
500
                endpointsSynced:          endpointInformer.Informer().HasSynced,
×
501
                addOrUpdateEndpointQueue: newTypedRateLimitingQueue[string]("UpdateEndpoint", nil),
×
502
                epKeyMutex:               keymutex.NewHashed(numKeyLocks),
×
503

×
504
                deploymentsLister: deploymentInformer.Lister(),
×
505
                deploymentsSynced: deploymentInformer.Informer().HasSynced,
×
506

×
507
                qosPoliciesLister:    qosPolicyInformer.Lister(),
×
508
                qosPolicySynced:      qosPolicyInformer.Informer().HasSynced,
×
509
                addQoSPolicyQueue:    newTypedRateLimitingQueue("AddQoSPolicy", custCrdRateLimiter),
×
510
                updateQoSPolicyQueue: newTypedRateLimitingQueue("UpdateQoSPolicy", custCrdRateLimiter),
×
511
                delQoSPolicyQueue:    newTypedRateLimitingQueue("DeleteQoSPolicy", custCrdRateLimiter),
×
512

×
513
                configMapsLister: configMapInformer.Lister(),
×
514
                configMapsSynced: configMapInformer.Informer().HasSynced,
×
515

×
516
                sgKeyMutex:         keymutex.NewHashed(numKeyLocks),
×
517
                sgsLister:          sgInformer.Lister(),
×
518
                sgSynced:           sgInformer.Informer().HasSynced,
×
519
                addOrUpdateSgQueue: newTypedRateLimitingQueue[string]("UpdateSecurityGroup", nil),
×
520
                delSgQueue:         newTypedRateLimitingQueue[string]("DeleteSecurityGroup", nil),
×
521
                syncSgPortsQueue:   newTypedRateLimitingQueue[string]("SyncSecurityGroupPorts", nil),
×
522

×
523
                ovnEipsLister:     ovnEipInformer.Lister(),
×
524
                ovnEipSynced:      ovnEipInformer.Informer().HasSynced,
×
525
                addOvnEipQueue:    newTypedRateLimitingQueue("AddOvnEip", custCrdRateLimiter),
×
526
                updateOvnEipQueue: newTypedRateLimitingQueue("UpdateOvnEip", custCrdRateLimiter),
×
527
                resetOvnEipQueue:  newTypedRateLimitingQueue("ResetOvnEip", custCrdRateLimiter),
×
528
                delOvnEipQueue:    newTypedRateLimitingQueue("DeleteOvnEip", custCrdRateLimiter),
×
529

×
530
                ovnFipsLister:     ovnFipInformer.Lister(),
×
531
                ovnFipSynced:      ovnFipInformer.Informer().HasSynced,
×
532
                addOvnFipQueue:    newTypedRateLimitingQueue("AddOvnFip", custCrdRateLimiter),
×
533
                updateOvnFipQueue: newTypedRateLimitingQueue("UpdateOvnFip", custCrdRateLimiter),
×
534
                delOvnFipQueue:    newTypedRateLimitingQueue("DeleteOvnFip", custCrdRateLimiter),
×
535

×
536
                ovnSnatRulesLister:     ovnSnatRuleInformer.Lister(),
×
537
                ovnSnatRuleSynced:      ovnSnatRuleInformer.Informer().HasSynced,
×
538
                addOvnSnatRuleQueue:    newTypedRateLimitingQueue("AddOvnSnatRule", custCrdRateLimiter),
×
539
                updateOvnSnatRuleQueue: newTypedRateLimitingQueue("UpdateOvnSnatRule", custCrdRateLimiter),
×
540
                delOvnSnatRuleQueue:    newTypedRateLimitingQueue("DeleteOvnSnatRule", custCrdRateLimiter),
×
541

×
542
                ovnDnatRulesLister:     ovnDnatRuleInformer.Lister(),
×
543
                ovnDnatRuleSynced:      ovnDnatRuleInformer.Informer().HasSynced,
×
544
                addOvnDnatRuleQueue:    newTypedRateLimitingQueue("AddOvnDnatRule", custCrdRateLimiter),
×
545
                updateOvnDnatRuleQueue: newTypedRateLimitingQueue("UpdateOvnDnatRule", custCrdRateLimiter),
×
546
                delOvnDnatRuleQueue:    newTypedRateLimitingQueue("DeleteOvnDnatRule", custCrdRateLimiter),
×
547

×
548
                csrLister:           csrInformer.Lister(),
×
549
                csrSynced:           csrInformer.Informer().HasSynced,
×
550
                addOrUpdateCsrQueue: newTypedRateLimitingQueue[string]("AddOrUpdateCSR", custCrdRateLimiter),
×
551

×
552
                vmiMigrationSynced:           vmiMigrationInformer.HasSynced,
×
553
                addOrUpdateVMIMigrationQueue: newTypedRateLimitingQueue[string]("AddOrUpdateVMIMigration", nil),
×
554
                kubevirtInformerFactory:      kubevirtInformerFactory,
×
555

×
556
                recorder:               recorder,
×
557
                informerFactory:        informerFactory,
×
558
                cmInformerFactory:      cmInformerFactory,
×
559
                deployInformerFactory:  deployInformerFactory,
×
560
                kubeovnInformerFactory: kubeovnInformerFactory,
×
561
                anpInformerFactory:     anpInformerFactory,
×
562
        }
×
563

×
564
        if controller.OVNNbClient, err = ovs.NewOvnNbClient(
×
565
                config.OvnNbAddr,
×
566
                config.OvnTimeout,
×
567
                config.OvsDbConnectTimeout,
×
568
                config.OvsDbInactivityTimeout,
×
569
                config.OvsDbConnectMaxRetry,
×
570
        ); err != nil {
×
571
                util.LogFatalAndExit(err, "failed to create ovn nb client")
×
572
        }
×
573
        if controller.OVNSbClient, err = ovs.NewOvnSbClient(
×
574
                config.OvnSbAddr,
×
575
                config.OvnTimeout,
×
576
                config.OvsDbConnectTimeout,
×
577
                config.OvsDbInactivityTimeout,
×
578
                config.OvsDbConnectMaxRetry,
×
579
        ); err != nil {
×
580
                util.LogFatalAndExit(err, "failed to create ovn sb client")
×
581
        }
×
582
        if config.EnableLb {
×
583
                controller.switchLBRuleLister = switchLBRuleInformer.Lister()
×
584
                controller.switchLBRuleSynced = switchLBRuleInformer.Informer().HasSynced
×
585
                controller.addSwitchLBRuleQueue = newTypedRateLimitingQueue("AddSwitchLBRule", custCrdRateLimiter)
×
586
                controller.delSwitchLBRuleQueue = newTypedRateLimitingQueue(
×
587
                        "DeleteSwitchLBRule",
×
588
                        workqueue.NewTypedMaxOfRateLimiter(
×
589
                                workqueue.NewTypedItemExponentialFailureRateLimiter[*SlrInfo](time.Duration(config.CustCrdRetryMinDelay)*time.Second, time.Duration(config.CustCrdRetryMaxDelay)*time.Second),
×
590
                                &workqueue.TypedBucketRateLimiter[*SlrInfo]{Limiter: rate.NewLimiter(rate.Limit(10), 100)},
×
591
                        ),
×
592
                )
×
593
                controller.updateSwitchLBRuleQueue = newTypedRateLimitingQueue(
×
594
                        "UpdateSwitchLBRule",
×
595
                        workqueue.NewTypedMaxOfRateLimiter(
×
596
                                workqueue.NewTypedItemExponentialFailureRateLimiter[*SlrInfo](time.Duration(config.CustCrdRetryMinDelay)*time.Second, time.Duration(config.CustCrdRetryMaxDelay)*time.Second),
×
597
                                &workqueue.TypedBucketRateLimiter[*SlrInfo]{Limiter: rate.NewLimiter(rate.Limit(10), 100)},
×
598
                        ),
×
599
                )
×
600

×
601
                controller.vpcDNSLister = vpcDNSInformer.Lister()
×
602
                controller.vpcDNSSynced = vpcDNSInformer.Informer().HasSynced
×
603
                controller.addOrUpdateVpcDNSQueue = newTypedRateLimitingQueue("AddOrUpdateVpcDns", custCrdRateLimiter)
×
604
                controller.delVpcDNSQueue = newTypedRateLimitingQueue("DeleteVpcDns", custCrdRateLimiter)
×
605
        }
×
606

607
        if config.EnableNP {
×
608
                controller.npsLister = npInformer.Lister()
×
609
                controller.npsSynced = npInformer.Informer().HasSynced
×
610
                controller.updateNpQueue = newTypedRateLimitingQueue[string]("UpdateNetworkPolicy", nil)
×
611
                controller.deleteNpQueue = newTypedRateLimitingQueue[string]("DeleteNetworkPolicy", nil)
×
612
                controller.npKeyMutex = keymutex.NewHashed(numKeyLocks)
×
613
        }
×
614

615
        if config.EnableANP {
×
616
                controller.anpsLister = anpInformer.Lister()
×
617
                controller.anpsSynced = anpInformer.Informer().HasSynced
×
618
                controller.addAnpQueue = newTypedRateLimitingQueue[string]("AddAdminNetworkPolicy", nil)
×
619
                controller.updateAnpQueue = newTypedRateLimitingQueue[*AdminNetworkPolicyChangedDelta]("UpdateAdminNetworkPolicy", nil)
×
620
                controller.deleteAnpQueue = newTypedRateLimitingQueue[*v1alpha1.AdminNetworkPolicy]("DeleteAdminNetworkPolicy", nil)
×
621
                controller.anpKeyMutex = keymutex.NewHashed(numKeyLocks)
×
622

×
623
                controller.banpsLister = banpInformer.Lister()
×
624
                controller.banpsSynced = banpInformer.Informer().HasSynced
×
625
                controller.addBanpQueue = newTypedRateLimitingQueue[string]("AddBaseAdminNetworkPolicy", nil)
×
626
                controller.updateBanpQueue = newTypedRateLimitingQueue[*AdminNetworkPolicyChangedDelta]("UpdateBaseAdminNetworkPolicy", nil)
×
627
                controller.deleteBanpQueue = newTypedRateLimitingQueue[*v1alpha1.BaselineAdminNetworkPolicy]("DeleteBaseAdminNetworkPolicy", nil)
×
628
                controller.banpKeyMutex = keymutex.NewHashed(numKeyLocks)
×
629
        }
×
630

631
        defer controller.shutdown()
×
632
        klog.Info("Starting OVN controller")
×
633

×
634
        // Wait for the caches to be synced before starting workers
×
635
        controller.informerFactory.Start(ctx.Done())
×
636
        controller.cmInformerFactory.Start(ctx.Done())
×
637
        controller.deployInformerFactory.Start(ctx.Done())
×
638
        controller.kubeovnInformerFactory.Start(ctx.Done())
×
639
        controller.anpInformerFactory.Start(ctx.Done())
×
640

×
641
        klog.Info("Waiting for informer caches to sync")
×
642
        cacheSyncs := []cache.InformerSynced{
×
643
                controller.vpcNatGatewaySynced, controller.vpcEgressGatewaySynced,
×
644
                controller.vpcSynced, controller.subnetSynced,
×
645
                controller.ipSynced, controller.virtualIpsSynced, controller.iptablesEipSynced,
×
646
                controller.iptablesFipSynced, controller.iptablesDnatRuleSynced, controller.iptablesSnatRuleSynced,
×
647
                controller.vlanSynced, controller.podsSynced, controller.namespacesSynced, controller.nodesSynced,
×
648
                controller.serviceSynced, controller.endpointsSynced, controller.deploymentsSynced, controller.configMapsSynced,
×
649
                controller.ovnEipSynced, controller.ovnFipSynced, controller.ovnSnatRuleSynced,
×
650
                controller.ovnDnatRuleSynced,
×
651
        }
×
652
        if controller.config.EnableLb {
×
653
                cacheSyncs = append(cacheSyncs, controller.switchLBRuleSynced, controller.vpcDNSSynced)
×
654
        }
×
655
        if controller.config.EnableNP {
×
656
                cacheSyncs = append(cacheSyncs, controller.npsSynced)
×
657
        }
×
658
        if controller.config.EnableANP {
×
659
                cacheSyncs = append(cacheSyncs, controller.anpsSynced, controller.banpsSynced)
×
660
        }
×
661

662
        if !cache.WaitForCacheSync(ctx.Done(), cacheSyncs...) {
×
663
                util.LogFatalAndExit(nil, "failed to wait for caches to sync")
×
664
        }
×
665

666
        if _, err = podInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
667
                AddFunc:    controller.enqueueAddPod,
×
668
                DeleteFunc: controller.enqueueDeletePod,
×
669
                UpdateFunc: controller.enqueueUpdatePod,
×
670
        }); err != nil {
×
671
                util.LogFatalAndExit(err, "failed to add pod event handler")
×
672
        }
×
673

674
        if _, err = namespaceInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
675
                AddFunc:    controller.enqueueAddNamespace,
×
676
                UpdateFunc: controller.enqueueUpdateNamespace,
×
677
                DeleteFunc: controller.enqueueDeleteNamespace,
×
678
        }); err != nil {
×
679
                util.LogFatalAndExit(err, "failed to add namespace event handler")
×
680
        }
×
681

682
        if _, err = nodeInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
683
                AddFunc:    controller.enqueueAddNode,
×
684
                UpdateFunc: controller.enqueueUpdateNode,
×
685
                DeleteFunc: controller.enqueueDeleteNode,
×
686
        }); err != nil {
×
687
                util.LogFatalAndExit(err, "failed to add node event handler")
×
688
        }
×
689

690
        if _, err = serviceInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
691
                AddFunc:    controller.enqueueAddService,
×
692
                DeleteFunc: controller.enqueueDeleteService,
×
693
                UpdateFunc: controller.enqueueUpdateService,
×
694
        }); err != nil {
×
695
                util.LogFatalAndExit(err, "failed to add service event handler")
×
696
        }
×
697

698
        if _, err = endpointInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
699
                AddFunc:    controller.enqueueAddEndpoint,
×
700
                UpdateFunc: controller.enqueueUpdateEndpoint,
×
701
        }); err != nil {
×
702
                util.LogFatalAndExit(err, "failed to add endpoint event handler")
×
703
        }
×
704

705
        if _, err = deploymentInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
706
                AddFunc:    controller.enqueueAddDeployment,
×
707
                UpdateFunc: controller.enqueueUpdateDeployment,
×
708
        }); err != nil {
×
709
                util.LogFatalAndExit(err, "failed to add deployment event handler")
×
710
        }
×
711

712
        if _, err = vpcInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
713
                AddFunc:    controller.enqueueAddVpc,
×
714
                UpdateFunc: controller.enqueueUpdateVpc,
×
715
                DeleteFunc: controller.enqueueDelVpc,
×
716
        }); err != nil {
×
717
                util.LogFatalAndExit(err, "failed to add vpc event handler")
×
718
        }
×
719

720
        if _, err = vpcNatGatewayInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
721
                AddFunc:    controller.enqueueAddVpcNatGw,
×
722
                UpdateFunc: controller.enqueueUpdateVpcNatGw,
×
723
                DeleteFunc: controller.enqueueDeleteVpcNatGw,
×
724
        }); err != nil {
×
725
                util.LogFatalAndExit(err, "failed to add vpc nat gateway event handler")
×
726
        }
×
727

728
        if _, err = vpcEgressGatewayInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
729
                AddFunc:    controller.enqueueAddVpcEgressGateway,
×
730
                UpdateFunc: controller.enqueueUpdateVpcEgressGateway,
×
731
                DeleteFunc: controller.enqueueDeleteVpcEgressGateway,
×
732
        }); err != nil {
×
733
                util.LogFatalAndExit(err, "failed to add vpc egress gateway event handler")
×
734
        }
×
735

736
        if _, err = subnetInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
737
                AddFunc:    controller.enqueueAddSubnet,
×
738
                UpdateFunc: controller.enqueueUpdateSubnet,
×
739
                DeleteFunc: controller.enqueueDeleteSubnet,
×
740
        }); err != nil {
×
741
                util.LogFatalAndExit(err, "failed to add subnet event handler")
×
742
        }
×
743

744
        if _, err = ippoolInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
745
                AddFunc:    controller.enqueueAddIPPool,
×
746
                UpdateFunc: controller.enqueueUpdateIPPool,
×
747
                DeleteFunc: controller.enqueueDeleteIPPool,
×
748
        }); err != nil {
×
749
                util.LogFatalAndExit(err, "failed to add ippool event handler")
×
750
        }
×
751

752
        if _, err = ipInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
753
                AddFunc:    controller.enqueueAddIP,
×
754
                UpdateFunc: controller.enqueueUpdateIP,
×
755
                DeleteFunc: controller.enqueueDelIP,
×
756
        }); err != nil {
×
757
                util.LogFatalAndExit(err, "failed to add ips event handler")
×
758
        }
×
759

760
        if _, err = vlanInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
761
                AddFunc:    controller.enqueueAddVlan,
×
762
                DeleteFunc: controller.enqueueDelVlan,
×
763
                UpdateFunc: controller.enqueueUpdateVlan,
×
764
        }); err != nil {
×
765
                util.LogFatalAndExit(err, "failed to add vlan event handler")
×
766
        }
×
767

768
        if _, err = sgInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
769
                AddFunc:    controller.enqueueAddSg,
×
770
                DeleteFunc: controller.enqueueDeleteSg,
×
771
                UpdateFunc: controller.enqueueUpdateSg,
×
772
        }); err != nil {
×
773
                util.LogFatalAndExit(err, "failed to add security group event handler")
×
774
        }
×
775

776
        if _, err = virtualIPInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
777
                AddFunc:    controller.enqueueAddVirtualIP,
×
778
                UpdateFunc: controller.enqueueUpdateVirtualIP,
×
779
                DeleteFunc: controller.enqueueDelVirtualIP,
×
780
        }); err != nil {
×
781
                util.LogFatalAndExit(err, "failed to add virtual ip event handler")
×
782
        }
×
783

784
        if _, err = iptablesEipInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
785
                AddFunc:    controller.enqueueAddIptablesEip,
×
786
                UpdateFunc: controller.enqueueUpdateIptablesEip,
×
787
                DeleteFunc: controller.enqueueDelIptablesEip,
×
788
        }); err != nil {
×
789
                util.LogFatalAndExit(err, "failed to add iptables eip event handler")
×
790
        }
×
791

792
        if _, err = iptablesFipInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
793
                AddFunc:    controller.enqueueAddIptablesFip,
×
794
                UpdateFunc: controller.enqueueUpdateIptablesFip,
×
795
                DeleteFunc: controller.enqueueDelIptablesFip,
×
796
        }); err != nil {
×
797
                util.LogFatalAndExit(err, "failed to add iptables fip event handler")
×
798
        }
×
799

800
        if _, err = iptablesDnatRuleInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
801
                AddFunc:    controller.enqueueAddIptablesDnatRule,
×
802
                UpdateFunc: controller.enqueueUpdateIptablesDnatRule,
×
803
                DeleteFunc: controller.enqueueDelIptablesDnatRule,
×
804
        }); err != nil {
×
805
                util.LogFatalAndExit(err, "failed to add iptables dnat event handler")
×
806
        }
×
807

808
        if _, err = iptablesSnatRuleInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
809
                AddFunc:    controller.enqueueAddIptablesSnatRule,
×
810
                UpdateFunc: controller.enqueueUpdateIptablesSnatRule,
×
811
                DeleteFunc: controller.enqueueDelIptablesSnatRule,
×
812
        }); err != nil {
×
813
                util.LogFatalAndExit(err, "failed to add iptables snat rule event handler")
×
814
        }
×
815

816
        if _, err = ovnEipInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
817
                AddFunc:    controller.enqueueAddOvnEip,
×
818
                UpdateFunc: controller.enqueueUpdateOvnEip,
×
819
                DeleteFunc: controller.enqueueDelOvnEip,
×
820
        }); err != nil {
×
821
                util.LogFatalAndExit(err, "failed to add ovn eip event handler")
×
822
        }
×
823

824
        if _, err = ovnFipInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
825
                AddFunc:    controller.enqueueAddOvnFip,
×
826
                UpdateFunc: controller.enqueueUpdateOvnFip,
×
827
                DeleteFunc: controller.enqueueDelOvnFip,
×
828
        }); err != nil {
×
829
                util.LogFatalAndExit(err, "failed to add ovn fip event handler")
×
830
        }
×
831

832
        if _, err = ovnSnatRuleInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
833
                AddFunc:    controller.enqueueAddOvnSnatRule,
×
834
                UpdateFunc: controller.enqueueUpdateOvnSnatRule,
×
835
                DeleteFunc: controller.enqueueDelOvnSnatRule,
×
836
        }); err != nil {
×
837
                util.LogFatalAndExit(err, "failed to add ovn snat rule event handler")
×
838
        }
×
839

840
        if _, err = ovnDnatRuleInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
841
                AddFunc:    controller.enqueueAddOvnDnatRule,
×
842
                UpdateFunc: controller.enqueueUpdateOvnDnatRule,
×
843
                DeleteFunc: controller.enqueueDelOvnDnatRule,
×
844
        }); err != nil {
×
845
                util.LogFatalAndExit(err, "failed to add ovn dnat rule event handler")
×
846
        }
×
847

848
        if _, err = qosPolicyInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
849
                AddFunc:    controller.enqueueAddQoSPolicy,
×
850
                UpdateFunc: controller.enqueueUpdateQoSPolicy,
×
851
                DeleteFunc: controller.enqueueDelQoSPolicy,
×
852
        }); err != nil {
×
853
                util.LogFatalAndExit(err, "failed to add qos policy event handler")
×
854
        }
×
855

856
        if config.EnableLb {
×
857
                if _, err = switchLBRuleInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
858
                        AddFunc:    controller.enqueueAddSwitchLBRule,
×
859
                        UpdateFunc: controller.enqueueUpdateSwitchLBRule,
×
860
                        DeleteFunc: controller.enqueueDeleteSwitchLBRule,
×
861
                }); err != nil {
×
862
                        util.LogFatalAndExit(err, "failed to add switch lb rule event handler")
×
863
                }
×
864

865
                if _, err = vpcDNSInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
866
                        AddFunc:    controller.enqueueAddVpcDNS,
×
867
                        UpdateFunc: controller.enqueueUpdateVpcDNS,
×
868
                        DeleteFunc: controller.enqueueDeleteVPCDNS,
×
869
                }); err != nil {
×
870
                        util.LogFatalAndExit(err, "failed to add vpc dns event handler")
×
871
                }
×
872
        }
873

874
        if config.EnableNP {
×
875
                if _, err = npInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
876
                        AddFunc:    controller.enqueueAddNp,
×
877
                        UpdateFunc: controller.enqueueUpdateNp,
×
878
                        DeleteFunc: controller.enqueueDeleteNp,
×
879
                }); err != nil {
×
880
                        util.LogFatalAndExit(err, "failed to add network policy event handler")
×
881
                }
×
882
        }
883

884
        if config.EnableANP {
×
885
                if _, err = anpInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
886
                        AddFunc:    controller.enqueueAddAnp,
×
887
                        UpdateFunc: controller.enqueueUpdateAnp,
×
888
                        DeleteFunc: controller.enqueueDeleteAnp,
×
889
                }); err != nil {
×
890
                        util.LogFatalAndExit(err, "failed to add admin network policy event handler")
×
891
                }
×
892

893
                if _, err = banpInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
894
                        AddFunc:    controller.enqueueAddBanp,
×
895
                        UpdateFunc: controller.enqueueUpdateBanp,
×
896
                        DeleteFunc: controller.enqueueDeleteBanp,
×
897
                }); err != nil {
×
898
                        util.LogFatalAndExit(err, "failed to add baseline admin network policy event handler")
×
899
                }
×
900

901
                controller.anpPrioNameMap = make(map[int32]string, 100)
×
902
                controller.anpNamePrioMap = make(map[string]int32, 100)
×
903
        }
904

905
        if config.EnableOVNIPSec {
×
906
                if _, err = csrInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
×
907
                        AddFunc:    controller.enqueueAddCsr,
×
908
                        UpdateFunc: controller.enqueueUpdateCsr,
×
909
                        // no need to add delete func for csr
×
910
                }); err != nil {
×
911
                        util.LogFatalAndExit(err, "failed to add csr event handler")
×
912
                }
×
913
        }
914

915
        if config.EnableLiveMigrationOptimize {
×
916
                if _, err = vmiMigrationInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{
×
917
                        AddFunc:    controller.enqueueAddVMIMigration,
×
918
                        UpdateFunc: controller.enqueueUpdateVMIMigration,
×
919
                }); err != nil {
×
920
                        util.LogFatalAndExit(err, "failed to add VMI Migration event handler")
×
921
                }
×
922
                controller.StartMigrationInformerFactory(ctx, kubevirtInformerFactory)
×
923
        }
924

925
        controller.Run(ctx)
×
926
}
927

928
// Run will set up the event handlers for types we are interested in, as well
929
// as syncing informer caches and starting workers. It will block until stopCh
930
// is closed, at which point it will shutdown the workqueue and wait for
931
// workers to finish processing their current work items.
932
func (c *Controller) Run(ctx context.Context) {
×
933
        // 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...
×
934
        // Otherwise, the init process should be placed after all workers have already started working
×
935
        if err := c.OVNNbClient.SetLsDnatModDlDst(c.config.LsDnatModDlDst); err != nil {
×
936
                util.LogFatalAndExit(err, "failed to set NB_Global option ls_dnat_mod_dl_dst")
×
937
        }
×
938

939
        if err := c.OVNNbClient.SetUseCtInvMatch(); err != nil {
×
940
                util.LogFatalAndExit(err, "failed to set NB_Global option use_ct_inv_match to false")
×
941
        }
×
942

943
        if err := c.OVNNbClient.SetLsCtSkipDstLportIPs(c.config.LsCtSkipDstLportIPs); err != nil {
×
944
                util.LogFatalAndExit(err, "failed to set NB_Global option ls_ct_skip_dst_lport_ips")
×
945
        }
×
946

947
        if err := c.OVNNbClient.SetNodeLocalDNSIP(strings.Join(c.config.NodeLocalDNSIPs, ",")); err != nil {
×
948
                util.LogFatalAndExit(err, "failed to set NB_Global option node_local_dns_ip")
×
949
        }
×
950

951
        if err := c.OVNNbClient.SetOVNIPSec(c.config.EnableOVNIPSec); err != nil {
×
952
                util.LogFatalAndExit(err, "failed to set NB_Global ipsec")
×
953
        }
×
954

955
        if err := c.InitOVN(); err != nil {
×
956
                util.LogFatalAndExit(err, "failed to initialize ovn resources")
×
957
        }
×
958

959
        // sync ip crd before initIPAM since ip crd will be used to restore vm and statefulset pod in initIPAM
960
        if err := c.syncIPCR(); err != nil {
×
961
                util.LogFatalAndExit(err, "failed to sync crd ips")
×
962
        }
×
963

964
        if err := c.syncFinalizers(); err != nil {
×
965
                util.LogFatalAndExit(err, "failed to initialize crd finalizers")
×
966
        }
×
967

968
        if err := c.InitIPAM(); err != nil {
×
969
                util.LogFatalAndExit(err, "failed to initialize ipam")
×
970
        }
×
971

972
        if err := c.syncNodeRoutes(); err != nil {
×
973
                util.LogFatalAndExit(err, "failed to initialize node routes")
×
974
        }
×
975

976
        if err := c.syncSubnetCR(); err != nil {
×
977
                util.LogFatalAndExit(err, "failed to sync crd subnets")
×
978
        }
×
979

980
        if err := c.syncVlanCR(); err != nil {
×
981
                util.LogFatalAndExit(err, "failed to sync crd vlans")
×
982
        }
×
983

984
        if c.config.EnableOVNIPSec {
×
985
                if err := c.InitDefaultOVNIPsecCA(); err != nil {
×
986
                        util.LogFatalAndExit(err, "failed to init ovn ipsec CA")
×
987
                }
×
988
        }
989

990
        // start workers to do all the network operations
991
        c.startWorkers(ctx)
×
992

×
993
        c.initResourceOnce()
×
994
        <-ctx.Done()
×
995
        klog.Info("Shutting down workers")
×
996
}
997

998
func (c *Controller) shutdown() {
×
999
        utilruntime.HandleCrash()
×
1000

×
1001
        c.addOrUpdatePodQueue.ShutDown()
×
1002
        c.deletePodQueue.ShutDown()
×
1003
        c.updatePodSecurityQueue.ShutDown()
×
1004

×
1005
        c.addNamespaceQueue.ShutDown()
×
1006

×
1007
        c.addOrUpdateSubnetQueue.ShutDown()
×
1008
        c.deleteSubnetQueue.ShutDown()
×
1009
        c.updateSubnetStatusQueue.ShutDown()
×
1010
        c.syncVirtualPortsQueue.ShutDown()
×
1011

×
1012
        c.addOrUpdateIPPoolQueue.ShutDown()
×
1013
        c.updateIPPoolStatusQueue.ShutDown()
×
1014
        c.deleteIPPoolQueue.ShutDown()
×
1015

×
1016
        c.addNodeQueue.ShutDown()
×
1017
        c.updateNodeQueue.ShutDown()
×
1018
        c.deleteNodeQueue.ShutDown()
×
1019

×
1020
        c.addServiceQueue.ShutDown()
×
1021
        c.deleteServiceQueue.ShutDown()
×
1022
        c.updateServiceQueue.ShutDown()
×
1023
        c.addOrUpdateEndpointQueue.ShutDown()
×
1024

×
1025
        c.addVlanQueue.ShutDown()
×
1026
        c.delVlanQueue.ShutDown()
×
1027
        c.updateVlanQueue.ShutDown()
×
1028

×
1029
        c.addOrUpdateVpcQueue.ShutDown()
×
1030
        c.updateVpcStatusQueue.ShutDown()
×
1031
        c.delVpcQueue.ShutDown()
×
1032

×
1033
        c.addOrUpdateVpcNatGatewayQueue.ShutDown()
×
1034
        c.initVpcNatGatewayQueue.ShutDown()
×
1035
        c.delVpcNatGatewayQueue.ShutDown()
×
1036
        c.updateVpcEipQueue.ShutDown()
×
1037
        c.updateVpcFloatingIPQueue.ShutDown()
×
1038
        c.updateVpcDnatQueue.ShutDown()
×
1039
        c.updateVpcSnatQueue.ShutDown()
×
1040
        c.updateVpcSubnetQueue.ShutDown()
×
1041

×
1042
        c.addOrUpdateVpcEgressGatewayQueue.ShutDown()
×
1043
        c.delVpcEgressGatewayQueue.ShutDown()
×
1044

×
1045
        if c.config.EnableLb {
×
1046
                c.addSwitchLBRuleQueue.ShutDown()
×
1047
                c.delSwitchLBRuleQueue.ShutDown()
×
1048
                c.updateSwitchLBRuleQueue.ShutDown()
×
1049

×
1050
                c.addOrUpdateVpcDNSQueue.ShutDown()
×
1051
                c.delVpcDNSQueue.ShutDown()
×
1052
        }
×
1053

1054
        c.addIPQueue.ShutDown()
×
1055
        c.updateIPQueue.ShutDown()
×
1056
        c.delIPQueue.ShutDown()
×
1057

×
1058
        c.addVirtualIPQueue.ShutDown()
×
1059
        c.updateVirtualIPQueue.ShutDown()
×
1060
        c.updateVirtualParentsQueue.ShutDown()
×
1061
        c.delVirtualIPQueue.ShutDown()
×
1062

×
1063
        c.addIptablesEipQueue.ShutDown()
×
1064
        c.updateIptablesEipQueue.ShutDown()
×
1065
        c.resetIptablesEipQueue.ShutDown()
×
1066
        c.delIptablesEipQueue.ShutDown()
×
1067

×
1068
        c.addIptablesFipQueue.ShutDown()
×
1069
        c.updateIptablesFipQueue.ShutDown()
×
1070
        c.delIptablesFipQueue.ShutDown()
×
1071

×
1072
        c.addIptablesDnatRuleQueue.ShutDown()
×
1073
        c.updateIptablesDnatRuleQueue.ShutDown()
×
1074
        c.delIptablesDnatRuleQueue.ShutDown()
×
1075

×
1076
        c.addIptablesSnatRuleQueue.ShutDown()
×
1077
        c.updateIptablesSnatRuleQueue.ShutDown()
×
1078
        c.delIptablesSnatRuleQueue.ShutDown()
×
1079

×
1080
        c.addQoSPolicyQueue.ShutDown()
×
1081
        c.updateQoSPolicyQueue.ShutDown()
×
1082
        c.delQoSPolicyQueue.ShutDown()
×
1083

×
1084
        c.addOvnEipQueue.ShutDown()
×
1085
        c.updateOvnEipQueue.ShutDown()
×
1086
        c.resetOvnEipQueue.ShutDown()
×
1087
        c.delOvnEipQueue.ShutDown()
×
1088

×
1089
        c.addOvnFipQueue.ShutDown()
×
1090
        c.updateOvnFipQueue.ShutDown()
×
1091
        c.delOvnFipQueue.ShutDown()
×
1092

×
1093
        c.addOvnSnatRuleQueue.ShutDown()
×
1094
        c.updateOvnSnatRuleQueue.ShutDown()
×
1095
        c.delOvnSnatRuleQueue.ShutDown()
×
1096

×
1097
        c.addOvnDnatRuleQueue.ShutDown()
×
1098
        c.updateOvnDnatRuleQueue.ShutDown()
×
1099
        c.delOvnDnatRuleQueue.ShutDown()
×
1100

×
1101
        if c.config.EnableNP {
×
1102
                c.updateNpQueue.ShutDown()
×
1103
                c.deleteNpQueue.ShutDown()
×
1104
        }
×
1105
        if c.config.EnableANP {
×
1106
                c.addAnpQueue.ShutDown()
×
1107
                c.updateAnpQueue.ShutDown()
×
1108
                c.deleteAnpQueue.ShutDown()
×
1109

×
1110
                c.addBanpQueue.ShutDown()
×
1111
                c.updateBanpQueue.ShutDown()
×
1112
                c.deleteBanpQueue.ShutDown()
×
1113
        }
×
1114

1115
        c.addOrUpdateSgQueue.ShutDown()
×
1116
        c.delSgQueue.ShutDown()
×
1117
        c.syncSgPortsQueue.ShutDown()
×
1118

×
1119
        c.addOrUpdateCsrQueue.ShutDown()
×
1120

×
1121
        if c.config.EnableLiveMigrationOptimize {
×
1122
                c.addOrUpdateVMIMigrationQueue.ShutDown()
×
1123
        }
×
1124
}
1125

1126
func (c *Controller) startWorkers(ctx context.Context) {
×
1127
        klog.Info("Starting workers")
×
1128

×
1129
        go wait.Until(runWorker("add/update vpc", c.addOrUpdateVpcQueue, c.handleAddOrUpdateVpc), time.Second, ctx.Done())
×
1130
        go wait.Until(runWorker("delete vpc", c.delVpcQueue, c.handleDelVpc), time.Second, ctx.Done())
×
1131
        go wait.Until(runWorker("update status of vpc", c.updateVpcStatusQueue, c.handleUpdateVpcStatus), time.Second, ctx.Done())
×
1132

×
1133
        go wait.Until(runWorker("add/update vpc nat gateway", c.addOrUpdateVpcNatGatewayQueue, c.handleAddOrUpdateVpcNatGw), time.Second, ctx.Done())
×
1134
        go wait.Until(runWorker("init vpc nat gateway", c.initVpcNatGatewayQueue, c.handleInitVpcNatGw), time.Second, ctx.Done())
×
1135
        go wait.Until(runWorker("delete vpc nat gateway", c.delVpcNatGatewayQueue, c.handleDelVpcNatGw), time.Second, ctx.Done())
×
1136
        go wait.Until(runWorker("add/update vpc egress gateway", c.addOrUpdateVpcEgressGatewayQueue, c.handleAddOrUpdateVpcEgressGateway), time.Second, ctx.Done())
×
1137
        go wait.Until(runWorker("delete vpc egress gateway", c.delVpcEgressGatewayQueue, c.handleDelVpcEgressGateway), time.Second, ctx.Done())
×
1138
        go wait.Until(runWorker("update fip for vpc nat gateway", c.updateVpcFloatingIPQueue, c.handleUpdateVpcFloatingIP), time.Second, ctx.Done())
×
1139
        go wait.Until(runWorker("update eip for vpc nat gateway", c.updateVpcEipQueue, c.handleUpdateVpcEip), time.Second, ctx.Done())
×
1140
        go wait.Until(runWorker("update dnat for vpc nat gateway", c.updateVpcDnatQueue, c.handleUpdateVpcDnat), time.Second, ctx.Done())
×
1141
        go wait.Until(runWorker("update snat for vpc nat gateway", c.updateVpcSnatQueue, c.handleUpdateVpcSnat), time.Second, ctx.Done())
×
1142
        go wait.Until(runWorker("update subnet route for vpc nat gateway", c.updateVpcSubnetQueue, c.handleUpdateNatGwSubnetRoute), time.Second, ctx.Done())
×
1143
        go wait.Until(runWorker("add/update csr", c.addOrUpdateCsrQueue, c.handleAddOrUpdateCsr), time.Second, ctx.Done())
×
1144
        // add default and join subnet and wait them ready
×
1145
        go wait.Until(runWorker("add/update subnet", c.addOrUpdateSubnetQueue, c.handleAddOrUpdateSubnet), time.Second, ctx.Done())
×
1146
        go wait.Until(runWorker("add/update ippool", c.addOrUpdateIPPoolQueue, c.handleAddOrUpdateIPPool), time.Second, ctx.Done())
×
1147
        go wait.Until(runWorker("add vlan", c.addVlanQueue, c.handleAddVlan), time.Second, ctx.Done())
×
1148
        go wait.Until(runWorker("add namespace", c.addNamespaceQueue, c.handleAddNamespace), time.Second, ctx.Done())
×
1149
        err := wait.PollUntilContextCancel(ctx, 3*time.Second, true, func(_ context.Context) (done bool, err error) {
×
1150
                subnets := []string{c.config.DefaultLogicalSwitch, c.config.NodeSwitch}
×
1151
                klog.Infof("wait for subnets %v ready", subnets)
×
1152

×
1153
                return c.allSubnetReady(subnets...)
×
1154
        })
×
1155
        if err != nil {
×
1156
                klog.Fatalf("wait default and join subnet ready, error: %v", err)
×
1157
        }
×
1158

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

×
1163
        // run node worker before handle any pods
×
1164
        for i := 0; i < c.config.WorkerNum; i++ {
×
1165
                go wait.Until(runWorker("add node", c.addNodeQueue, c.handleAddNode), time.Second, ctx.Done())
×
1166
                go wait.Until(runWorker("update node", c.updateNodeQueue, c.handleUpdateNode), time.Second, ctx.Done())
×
1167
                go wait.Until(runWorker("delete node", c.deleteNodeQueue, c.handleDeleteNode), time.Second, ctx.Done())
×
1168
        }
×
1169
        for {
×
1170
                ready := true
×
1171
                time.Sleep(3 * time.Second)
×
1172
                nodes, err := c.nodesLister.List(labels.Everything())
×
1173
                if err != nil {
×
1174
                        util.LogFatalAndExit(err, "failed to list nodes")
×
1175
                }
×
1176
                for _, node := range nodes {
×
1177
                        if node.Annotations[util.AllocatedAnnotation] != "true" {
×
1178
                                klog.Infof("wait node %s annotation ready", node.Name)
×
1179
                                ready = false
×
1180
                                break
×
1181
                        }
1182
                }
1183
                if ready {
×
1184
                        break
×
1185
                }
1186
        }
1187

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

×
1193
                go wait.Until(runWorker("add/update switch lb rule", c.addSwitchLBRuleQueue, c.handleAddOrUpdateSwitchLBRule), time.Second, ctx.Done())
×
1194
                go wait.Until(runWorker("delete switch lb rule", c.delSwitchLBRuleQueue, c.handleDelSwitchLBRule), time.Second, ctx.Done())
×
1195
                go wait.Until(runWorker("delete switch lb rule", c.updateSwitchLBRuleQueue, c.handleUpdateSwitchLBRule), time.Second, ctx.Done())
×
1196

×
1197
                go wait.Until(runWorker("add/update vpc dns", c.addOrUpdateVpcDNSQueue, c.handleAddOrUpdateVPCDNS), time.Second, ctx.Done())
×
1198
                go wait.Until(runWorker("delete vpc dns", c.delVpcDNSQueue, c.handleDelVpcDNS), time.Second, ctx.Done())
×
1199
                go wait.Until(func() {
×
1200
                        c.resyncVpcDNSConfig()
×
1201
                }, 5*time.Second, ctx.Done())
×
1202
        }
1203

1204
        for i := 0; i < c.config.WorkerNum; i++ {
×
1205
                go wait.Until(runWorker("delete pod", c.deletePodQueue, c.handleDeletePod), time.Second, ctx.Done())
×
1206
                go wait.Until(runWorker("add/update pod", c.addOrUpdatePodQueue, c.handleAddOrUpdatePod), time.Second, ctx.Done())
×
1207
                go wait.Until(runWorker("update pod security", c.updatePodSecurityQueue, c.handleUpdatePodSecurity), time.Second, ctx.Done())
×
1208

×
1209
                go wait.Until(runWorker("delete subnet", c.deleteSubnetQueue, c.handleDeleteSubnet), time.Second, ctx.Done())
×
1210
                go wait.Until(runWorker("delete ippool", c.deleteIPPoolQueue, c.handleDeleteIPPool), time.Second, ctx.Done())
×
1211
                go wait.Until(runWorker("update status of subnet", c.updateSubnetStatusQueue, c.handleUpdateSubnetStatus), time.Second, ctx.Done())
×
1212
                go wait.Until(runWorker("update status of ippool", c.updateIPPoolStatusQueue, c.handleUpdateIPPoolStatus), time.Second, ctx.Done())
×
1213
                go wait.Until(runWorker("virtual port for subnet", c.syncVirtualPortsQueue, c.syncVirtualPort), time.Second, ctx.Done())
×
1214

×
1215
                if c.config.EnableLb {
×
1216
                        go wait.Until(runWorker("update service", c.updateServiceQueue, c.handleUpdateService), time.Second, ctx.Done())
×
1217
                        go wait.Until(runWorker("add/update endpoint", c.addOrUpdateEndpointQueue, c.handleUpdateEndpoint), time.Second, ctx.Done())
×
1218
                }
×
1219

1220
                if c.config.EnableNP {
×
1221
                        go wait.Until(runWorker("update network policy", c.updateNpQueue, c.handleUpdateNp), time.Second, ctx.Done())
×
1222
                        go wait.Until(runWorker("delete network policy", c.deleteNpQueue, c.handleDeleteNp), time.Second, ctx.Done())
×
1223
                }
×
1224

1225
                go wait.Until(runWorker("delete vlan", c.delVlanQueue, c.handleDelVlan), time.Second, ctx.Done())
×
1226
                go wait.Until(runWorker("update vlan", c.updateVlanQueue, c.handleUpdateVlan), time.Second, ctx.Done())
×
1227
        }
1228

1229
        if c.config.EnableEipSnat {
×
1230
                go wait.Until(func() {
×
1231
                        // init l3 about the default vpc external lrp binding to the gw chassis
×
1232
                        c.resyncExternalGateway()
×
1233
                }, time.Second, ctx.Done())
×
1234

1235
                // maintain l3 ha about the vpc external lrp binding to the gw chassis
1236
                c.OVNNbClient.MonitorBFD()
×
1237
        }
1238
        // TODO: we should merge these two vpc nat config into one config and resync them together
1239
        go wait.Until(func() {
×
1240
                c.resyncVpcNatGwConfig()
×
1241
        }, time.Second, ctx.Done())
×
1242

1243
        go wait.Until(func() {
×
1244
                c.resyncVpcNatConfig()
×
1245
        }, time.Second, ctx.Done())
×
1246

1247
        if c.config.GCInterval != 0 {
×
1248
                go wait.Until(func() {
×
1249
                        if err := c.markAndCleanLSP(); err != nil {
×
1250
                                klog.Errorf("gc lsp error: %v", err)
×
1251
                        }
×
1252
                }, time.Duration(c.config.GCInterval)*time.Second, ctx.Done())
1253
        }
1254

1255
        go wait.Until(func() {
×
1256
                if err := c.inspectPod(); err != nil {
×
1257
                        klog.Errorf("inspection error: %v", err)
×
1258
                }
×
1259
        }, time.Duration(c.config.InspectInterval)*time.Second, ctx.Done())
1260

1261
        if c.config.EnableExternalVpc {
×
1262
                go wait.Until(func() {
×
1263
                        c.syncExternalVpc()
×
1264
                }, 5*time.Second, ctx.Done())
×
1265
        }
1266

1267
        go wait.Until(c.resyncProviderNetworkStatus, 30*time.Second, ctx.Done())
×
1268
        go wait.Until(c.exportSubnetMetrics, 30*time.Second, ctx.Done())
×
1269
        go wait.Until(c.checkSubnetGateway, 5*time.Second, ctx.Done())
×
1270

×
1271
        go wait.Until(runWorker("add ovn eip", c.addOvnEipQueue, c.handleAddOvnEip), time.Second, ctx.Done())
×
1272
        go wait.Until(runWorker("update ovn eip", c.updateOvnEipQueue, c.handleUpdateOvnEip), time.Second, ctx.Done())
×
1273
        go wait.Until(runWorker("reset ovn eip", c.resetOvnEipQueue, c.handleResetOvnEip), time.Second, ctx.Done())
×
1274
        go wait.Until(runWorker("delete ovn eip", c.delOvnEipQueue, c.handleDelOvnEip), time.Second, ctx.Done())
×
1275

×
1276
        go wait.Until(runWorker("add ovn fip", c.addOvnFipQueue, c.handleAddOvnFip), time.Second, ctx.Done())
×
1277
        go wait.Until(runWorker("update ovn fip", c.updateOvnFipQueue, c.handleUpdateOvnFip), time.Second, ctx.Done())
×
1278
        go wait.Until(runWorker("delete ovn fip", c.delOvnFipQueue, c.handleDelOvnFip), time.Second, ctx.Done())
×
1279

×
1280
        go wait.Until(runWorker("add ovn snat rule", c.addOvnSnatRuleQueue, c.handleAddOvnSnatRule), time.Second, ctx.Done())
×
1281
        go wait.Until(runWorker("update ovn snat rule", c.updateOvnSnatRuleQueue, c.handleUpdateOvnSnatRule), time.Second, ctx.Done())
×
1282
        go wait.Until(runWorker("delete ovn snat rule", c.delOvnSnatRuleQueue, c.handleDelOvnSnatRule), time.Second, ctx.Done())
×
1283

×
1284
        go wait.Until(runWorker("add ovn dnat", c.addOvnDnatRuleQueue, c.handleAddOvnDnatRule), time.Second, ctx.Done())
×
1285
        go wait.Until(runWorker("update ovn dnat", c.updateOvnDnatRuleQueue, c.handleUpdateOvnDnatRule), time.Second, ctx.Done())
×
1286
        go wait.Until(runWorker("delete ovn dnat", c.delOvnDnatRuleQueue, c.handleDelOvnDnatRule), time.Second, ctx.Done())
×
1287

×
1288
        if c.config.EnableNP {
×
1289
                go wait.Until(c.CheckNodePortGroup, time.Duration(c.config.NodePgProbeTime)*time.Minute, ctx.Done())
×
1290
        }
×
1291

1292
        go wait.Until(runWorker("add ip", c.addIPQueue, c.handleAddReservedIP), time.Second, ctx.Done())
×
1293
        go wait.Until(runWorker("update ip", c.updateIPQueue, c.handleUpdateIP), time.Second, ctx.Done())
×
1294
        go wait.Until(runWorker("delete ip", c.delIPQueue, c.handleDelIP), time.Second, ctx.Done())
×
1295

×
1296
        go wait.Until(runWorker("add vip", c.addVirtualIPQueue, c.handleAddVirtualIP), time.Second, ctx.Done())
×
1297
        go wait.Until(runWorker("update vip", c.updateVirtualIPQueue, c.handleUpdateVirtualIP), time.Second, ctx.Done())
×
1298
        go wait.Until(runWorker("update virtual parent for vip", c.updateVirtualParentsQueue, c.handleUpdateVirtualParents), time.Second, ctx.Done())
×
1299
        go wait.Until(runWorker("delete vip", c.delVirtualIPQueue, c.handleDelVirtualIP), time.Second, ctx.Done())
×
1300

×
1301
        go wait.Until(runWorker("add iptables eip", c.addIptablesEipQueue, c.handleAddIptablesEip), time.Second, ctx.Done())
×
1302
        go wait.Until(runWorker("update iptables eip", c.updateIptablesEipQueue, c.handleUpdateIptablesEip), time.Second, ctx.Done())
×
1303
        go wait.Until(runWorker("reset iptables eip", c.resetIptablesEipQueue, c.handleResetIptablesEip), time.Second, ctx.Done())
×
1304
        go wait.Until(runWorker("delete iptables eip", c.delIptablesEipQueue, c.handleDelIptablesEip), time.Second, ctx.Done())
×
1305

×
1306
        go wait.Until(runWorker("add iptables fip", c.addIptablesFipQueue, c.handleAddIptablesFip), time.Second, ctx.Done())
×
1307
        go wait.Until(runWorker("update iptables fip", c.updateIptablesFipQueue, c.handleUpdateIptablesFip), time.Second, ctx.Done())
×
1308
        go wait.Until(runWorker("delete iptables fip", c.delIptablesFipQueue, c.handleDelIptablesFip), time.Second, ctx.Done())
×
1309

×
1310
        go wait.Until(runWorker("add iptables dnat rule", c.addIptablesDnatRuleQueue, c.handleAddIptablesDnatRule), time.Second, ctx.Done())
×
1311
        go wait.Until(runWorker("update iptables dnat rule", c.updateIptablesDnatRuleQueue, c.handleUpdateIptablesDnatRule), time.Second, ctx.Done())
×
1312
        go wait.Until(runWorker("delete iptables dnat rule", c.delIptablesDnatRuleQueue, c.handleDelIptablesDnatRule), time.Second, ctx.Done())
×
1313

×
1314
        go wait.Until(runWorker("add iptables snat rule", c.addIptablesSnatRuleQueue, c.handleAddIptablesSnatRule), time.Second, ctx.Done())
×
1315
        go wait.Until(runWorker("update iptables snat rule", c.updateIptablesSnatRuleQueue, c.handleUpdateIptablesSnatRule), time.Second, ctx.Done())
×
1316
        go wait.Until(runWorker("delete iptables snat rule", c.delIptablesSnatRuleQueue, c.handleDelIptablesSnatRule), time.Second, ctx.Done())
×
1317

×
1318
        go wait.Until(runWorker("add qos policy", c.addQoSPolicyQueue, c.handleAddQoSPolicy), time.Second, ctx.Done())
×
1319
        go wait.Until(runWorker("update qos policy", c.updateQoSPolicyQueue, c.handleUpdateQoSPolicy), time.Second, ctx.Done())
×
1320
        go wait.Until(runWorker("delete qos policy", c.delQoSPolicyQueue, c.handleDelQoSPolicy), time.Second, ctx.Done())
×
1321

×
1322
        if c.config.EnableANP {
×
1323
                go wait.Until(runWorker("add admin network policy", c.addAnpQueue, c.handleAddAnp), time.Second, ctx.Done())
×
1324
                go wait.Until(runWorker("update admin network policy", c.updateAnpQueue, c.handleUpdateAnp), time.Second, ctx.Done())
×
1325
                go wait.Until(runWorker("delete admin network policy", c.deleteAnpQueue, c.handleDeleteAnp), time.Second, ctx.Done())
×
1326

×
1327
                go wait.Until(runWorker("add base admin network policy", c.addBanpQueue, c.handleAddBanp), time.Second, ctx.Done())
×
1328
                go wait.Until(runWorker("update base admin network policy", c.updateBanpQueue, c.handleUpdateBanp), time.Second, ctx.Done())
×
1329
                go wait.Until(runWorker("delete base admin network policy", c.deleteBanpQueue, c.handleDeleteBanp), time.Second, ctx.Done())
×
1330
        }
×
1331

1332
        if c.config.EnableLiveMigrationOptimize {
×
1333
                go wait.Until(runWorker("add/update vmiMigration ", c.addOrUpdateVMIMigrationQueue, c.handleAddOrUpdateVMIMigration), 50*time.Millisecond, ctx.Done())
×
1334
        }
×
1335
}
1336

1337
func (c *Controller) allSubnetReady(subnets ...string) (bool, error) {
1✔
1338
        for _, lsName := range subnets {
2✔
1339
                exist, err := c.OVNNbClient.LogicalSwitchExists(lsName)
1✔
1340
                if err != nil {
1✔
1341
                        klog.Error(err)
×
1342
                        return false, fmt.Errorf("check logical switch %s exist: %w", lsName, err)
×
1343
                }
×
1344

1345
                if !exist {
2✔
1346
                        return false, nil
1✔
1347
                }
1✔
1348
        }
1349

1350
        return true, nil
1✔
1351
}
1352

1353
func (c *Controller) initResourceOnce() {
×
1354
        c.registerSubnetMetrics()
×
1355

×
1356
        if err := c.initNodeChassis(); err != nil {
×
1357
                util.LogFatalAndExit(err, "failed to initialize node chassis")
×
1358
        }
×
1359

1360
        if err := c.initDefaultDenyAllSecurityGroup(); err != nil {
×
1361
                util.LogFatalAndExit(err, "failed to initialize 'deny_all' security group")
×
1362
        }
×
1363
        if err := c.syncSecurityGroup(); err != nil {
×
1364
                util.LogFatalAndExit(err, "failed to sync security group")
×
1365
        }
×
1366

1367
        if err := c.syncVpcNatGatewayCR(); err != nil {
×
1368
                util.LogFatalAndExit(err, "failed to sync crd vpc nat gateways")
×
1369
        }
×
1370

1371
        if err := c.initVpcNatGw(); err != nil {
×
1372
                util.LogFatalAndExit(err, "failed to initialize vpc nat gateways")
×
1373
        }
×
1374
        if c.config.EnableLb {
×
1375
                if err := c.initVpcDNSConfig(); err != nil {
×
1376
                        util.LogFatalAndExit(err, "failed to initialize vpc-dns")
×
1377
                }
×
1378
        }
1379

1380
        // remove resources in ovndb that not exist any more in kubernetes resources
1381
        // process gc at last in case of affecting other init process
1382
        if err := c.gc(); err != nil {
×
1383
                util.LogFatalAndExit(err, "failed to run gc")
×
1384
        }
×
1385
}
1386

1387
func processNextWorkItem[T comparable](action string, queue workqueue.TypedRateLimitingInterface[T], handler func(T) error, getItemKey func(any) string) bool {
×
1388
        item, shutdown := queue.Get()
×
1389
        if shutdown {
×
1390
                return false
×
1391
        }
×
1392

1393
        err := func(item T) error {
×
1394
                defer queue.Done(item)
×
1395
                if err := handler(item); err != nil {
×
1396
                        queue.AddRateLimited(item)
×
1397
                        return fmt.Errorf("error syncing %s %q: %w, requeuing", action, getItemKey(item), err)
×
1398
                }
×
1399
                queue.Forget(item)
×
1400
                return nil
×
1401
        }(item)
1402
        if err != nil {
×
1403
                utilruntime.HandleError(err)
×
1404
                return true
×
1405
        }
×
1406
        return true
×
1407
}
1408

1409
func getWorkItemKey(obj any) string {
×
1410
        switch v := obj.(type) {
×
1411
        case string:
×
1412
                return v
×
1413
        case *vpcService:
×
1414
                return cache.MetaObjectToName(obj.(*vpcService).Svc).String()
×
1415
        case *AdminNetworkPolicyChangedDelta:
×
1416
                return v.key
×
1417
        case *SlrInfo:
×
1418
                return v.Name
×
1419
        default:
×
1420
                key, err := cache.MetaNamespaceKeyFunc(obj)
×
1421
                if err != nil {
×
1422
                        utilruntime.HandleError(err)
×
1423
                        return ""
×
1424
                }
×
1425
                return key
×
1426
        }
1427
}
1428

1429
func runWorker[T comparable](action string, queue workqueue.TypedRateLimitingInterface[T], handler func(T) error) func() {
×
1430
        return func() {
×
1431
                for processNextWorkItem(action, queue, handler, getWorkItemKey) {
×
1432
                }
×
1433
        }
1434
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc