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

kubeovn / kube-ovn / 17601237263

10 Sep 2025 02:25AM UTC coverage: 21.232% (-0.1%) from 21.329%
17601237263

push

github

web-flow
Feat: Added non primary cni mode support for Kube-OVN (#5618)

* Add support for secondary CNI configuration

Signed-off-by: Vishal Mohan <vishalmohan@microsoft.com>

* Enhanced VPC NAT gateway to work with secondary interface

Signed-off-by: Vishal Mohan <vishalmohan@microsoft.com>

* Enhance NAT gateway and pod handling for non-primary CNI support

Signed-off-by: Vishal Mohan <vishalmohan@microsoft.com>

* Fixed compile

Signed-off-by: Vishal Mohan <vishalmohan@microsoft.com>

* Fix typo in TODO comment and improve error handling in getNadInterfaceFromNetworkStatusAnnotation

Signed-off-by: Vishal Mohan <vishalmohan@microsoft.com>

* Refactor getNadInterfaceFromNetworkStatusAnnotation to util package and update references in VPC NAT gateway

Signed-off-by: Vishal Mohan <vishalmohan@microsoft.com>

* Add support for non-primary CNI mode and improve VPC NAT gateway handling

- Introduced non-primary CNI configuration in values.yaml.
- Updated controller deployment to include non-primary CNI flag.
- Refactored NAT gateway script to use correct environment file path.
- Enhanced endpoint slice handling to utilize secondary IPs.
- Simplified pod provider extraction logic for VPC NAT gateway.
- Improved annotation management for VPC CIDRs in NAT gateway.

Signed-off-by: Vishal Mohan <vishalmohan@microsoft.com>

* Apply suggestions from code review

Signed-off-by: Vishal Mohan <vishalmohan@microsoft.com>

* Fixed lint
- Refactor variable type from 'interface{}' to 'any' in GetNadInterfaceFromNetworkStatusAnnotation for clarity
- Fixed pod routes annotation to use subnetProvider variable in vpc nat gw genNatGwStatefulSet

Signed-off-by: Vishal Mohan <vishalmohan@microsoft.com>

* fix lint issues

Signed-off-by: Mengxin Liu <liumengxinfly@gmail.com>

* Refactor endpoint slice handling to improve secondary IP address updates and add conditional provider retrieval for VPC NAT gateway support

Signed-off-by: Vishal Mohan <vishalmohan@microsoft.com>

* Updated He... (continued)

0 of 250 new or added lines in 5 files covered. (0.0%)

4 existing lines in 3 files now uncovered.

10659 of 50202 relevant lines covered (21.23%)

0.25 hits per line

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

0.0
/pkg/controller/config.go
1
package controller
2

3
import (
4
        "errors"
5
        "flag"
6
        "fmt"
7
        "os"
8
        "strings"
9
        "time"
10

11
        attachnetclientset "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/client/clientset/versioned"
12
        "github.com/spf13/pflag"
13
        extClientSet "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
14
        "k8s.io/client-go/kubernetes"
15
        "k8s.io/client-go/rest"
16
        "k8s.io/client-go/tools/clientcmd"
17
        "k8s.io/klog/v2"
18
        "kubevirt.io/client-go/kubecli"
19
        anpclientset "sigs.k8s.io/network-policy-api/pkg/client/clientset/versioned"
20

21
        clientset "github.com/kubeovn/kube-ovn/pkg/client/clientset/versioned"
22
        "github.com/kubeovn/kube-ovn/pkg/util"
23
)
24

25
// Configuration is the controller conf
26
type Configuration struct {
27
        OvnNbAddr              string
28
        OvnSbAddr              string
29
        OvnTimeout             int
30
        OvsDbConnectTimeout    int
31
        OvsDbConnectMaxRetry   int
32
        OvsDbInactivityTimeout int
33
        CustCrdRetryMaxDelay   int
34
        CustCrdRetryMinDelay   int
35
        KubeConfigFile         string
36
        KubeRestConfig         *rest.Config
37

38
        KubeClient      kubernetes.Interface
39
        KubeOvnClient   clientset.Interface
40
        AnpClient       anpclientset.Interface
41
        AttachNetClient attachnetclientset.Interface
42
        KubevirtClient  kubecli.KubevirtClient
43
        ExtClient       extClientSet.Interface
44

45
        KubeFactoryClient    kubernetes.Interface
46
        KubeOvnFactoryClient clientset.Interface
47

48
        DefaultLogicalSwitch      string
49
        DefaultCIDR               string
50
        DefaultGateway            string
51
        DefaultExcludeIps         string
52
        DefaultGatewayCheck       bool
53
        DefaultLogicalGateway     bool
54
        DefaultU2OInterconnection bool
55

56
        ClusterRouter     string
57
        NodeSwitch        string
58
        NodeSwitchCIDR    string
59
        NodeSwitchGateway string
60

61
        ServiceClusterIPRange string
62

63
        ClusterTCPLoadBalancer         string
64
        ClusterUDPLoadBalancer         string
65
        ClusterSctpLoadBalancer        string
66
        ClusterTCPSessionLoadBalancer  string
67
        ClusterUDPSessionLoadBalancer  string
68
        ClusterSctpSessionLoadBalancer string
69

70
        PodName      string
71
        PodNamespace string
72
        PodNicType   string
73

74
        WorkerNum       int
75
        PprofPort       int32
76
        EnablePprof     bool
77
        SecureServing   bool
78
        NodePgProbeTime int
79

80
        NetworkType             string
81
        DefaultProviderName     string
82
        DefaultHostInterface    string
83
        DefaultExchangeLinkName bool
84
        DefaultVlanName         string
85
        DefaultVlanID           int
86
        LsDnatModDlDst          bool
87
        LsCtSkipDstLportIPs     bool
88

89
        EnableLb                    bool
90
        EnableNP                    bool
91
        EnableEipSnat               bool
92
        EnableExternalVpc           bool
93
        EnableEcmp                  bool
94
        EnableKeepVMIP              bool
95
        EnableLbSvc                 bool
96
        EnableOVNLBPreferLocal      bool
97
        EnableMetrics               bool
98
        EnableANP                   bool
99
        EnableOVNIPSec              bool
100
        CertManagerIPSecCert        bool
101
        EnableLiveMigrationOptimize bool
102

103
        ExternalGatewaySwitch   string
104
        ExternalGatewayConfigNS string
105
        ExternalGatewayNet      string
106
        ExternalGatewayVlanID   int
107

108
        GCInterval      int
109
        InspectInterval int
110

111
        BfdMinTx      int
112
        BfdMinRx      int
113
        BfdDetectMult int
114

115
        NodeLocalDNSIPs []string
116

117
        // used to set vpc-egress-gateway image
118
        Image string
119

120
        // used to set log file permission
121
        LogPerm string
122

123
        // TLS configuration for secure serving
124
        TLSMinVersion   string
125
        TLSMaxVersion   string
126
        TLSCipherSuites []string
127

128
        // Non Primary CNI flag
129
        EnableNonPrimaryCNI bool
130
}
131

132
// ParseFlags parses cmd args then init kubeclient and conf
133
// TODO: validate configuration
134
func ParseFlags() (*Configuration, error) {
×
135
        var (
×
136
                argOvnNbAddr              = pflag.String("ovn-nb-addr", "", "ovn-nb address")
×
137
                argOvnSbAddr              = pflag.String("ovn-sb-addr", "", "ovn-sb address")
×
138
                argOvnTimeout             = pflag.Int("ovn-timeout", 60, "The seconds to wait ovn command timeout")
×
139
                argOvsDbConTimeout        = pflag.Int("ovsdb-con-timeout", 3, "The seconds to wait ovsdb connect timeout")
×
140
                argOvsDbConnectMaxRetry   = pflag.Int("ovsdb-con-maxretry", 60, "The maximum number of retries for connecting to ovsdb")
×
141
                argOvsDbInactivityTimeout = pflag.Int("ovsdb-inactivity-timeout", 10, "The seconds to wait ovsdb inactivity check timeout")
×
142
                argCustCrdRetryMinDelay   = pflag.Int("cust-crd-retry-min-delay", 1, "The min delay seconds between custom crd two retries")
×
143
                argCustCrdRetryMaxDelay   = pflag.Int("cust-crd-retry-max-delay", 20, "The max delay seconds between custom crd two retries")
×
144
                argKubeConfigFile         = pflag.String("kubeconfig", "", "Path to kubeconfig file with authorization and master location information. If not set use the inCluster token.")
×
145

×
146
                argDefaultLogicalSwitch  = pflag.String("default-ls", util.DefaultSubnet, "The default logical switch name")
×
147
                argDefaultCIDR           = pflag.String("default-cidr", "10.16.0.0/16", "Default CIDR for namespace with no logical switch annotation")
×
148
                argDefaultGateway        = pflag.String("default-gateway", "", "Default gateway for default-cidr (default the first ip in default-cidr)")
×
149
                argDefaultGatewayCheck   = pflag.Bool("default-gateway-check", true, "Check switch for the default subnet's gateway")
×
150
                argDefaultLogicalGateway = pflag.Bool("default-logical-gateway", false, "Create a logical gateway for the default subnet instead of using underlay gateway. Take effect only when the default subnet is in underlay mode. (default false)")
×
151
                argDefaultExcludeIps     = pflag.String("default-exclude-ips", "", "Exclude ips in default switch (default gateway address)")
×
152

×
153
                argDefaultU2OInterconnection = pflag.Bool("default-u2o-interconnection", false, "usage for underlay to overlay interconnection")
×
154

×
155
                argClusterRouter     = pflag.String("cluster-router", util.DefaultVpc, "The router name for cluster router")
×
156
                argNodeSwitch        = pflag.String("node-switch", "join", "The name of node gateway switch which help node to access pod network")
×
157
                argNodeSwitchCIDR    = pflag.String("node-switch-cidr", "100.64.0.0/16", "The cidr for node switch")
×
158
                argNodeSwitchGateway = pflag.String("node-switch-gateway", "", "The gateway for node switch (default the first ip in node-switch-cidr)")
×
159

×
160
                argServiceClusterIPRange = pflag.String("service-cluster-ip-range", "10.96.0.0/12", "The kubernetes service cluster ip range")
×
161

×
162
                argClusterTCPLoadBalancer         = pflag.String("cluster-tcp-loadbalancer", "cluster-tcp-loadbalancer", "The name for cluster tcp loadbalancer")
×
163
                argClusterUDPLoadBalancer         = pflag.String("cluster-udp-loadbalancer", "cluster-udp-loadbalancer", "The name for cluster udp loadbalancer")
×
164
                argClusterSctpLoadBalancer        = pflag.String("cluster-sctp-loadbalancer", "cluster-sctp-loadbalancer", "The name for cluster sctp loadbalancer")
×
165
                argClusterTCPSessionLoadBalancer  = pflag.String("cluster-tcp-session-loadbalancer", "cluster-tcp-session-loadbalancer", "The name for cluster tcp session loadbalancer")
×
166
                argClusterUDPSessionLoadBalancer  = pflag.String("cluster-udp-session-loadbalancer", "cluster-udp-session-loadbalancer", "The name for cluster udp session loadbalancer")
×
167
                argClusterSctpSessionLoadBalancer = pflag.String("cluster-sctp-session-loadbalancer", "cluster-sctp-session-loadbalancer", "The name for cluster sctp session loadbalancer")
×
168

×
169
                argWorkerNum       = pflag.Int("worker-num", 3, "The parallelism of each worker")
×
170
                argEnablePprof     = pflag.Bool("enable-pprof", false, "Enable pprof")
×
171
                argPprofPort       = pflag.Int32("pprof-port", 10660, "The port to get profiling data")
×
172
                argSecureServing   = pflag.Bool("secure-serving", false, "Enable secure serving")
×
173
                argNodePgProbeTime = pflag.Int("nodepg-probe-time", 1, "The probe interval for node port-group, the unit is minute")
×
174

×
175
                argNetworkType                 = pflag.String("network-type", util.NetworkTypeGeneve, "The ovn network type")
×
176
                argDefaultProviderName         = pflag.String("default-provider-name", "provider", "The vlan or vxlan type default provider interface name")
×
177
                argDefaultInterfaceName        = pflag.String("default-interface-name", "", "The default host interface name in the vlan/vxlan type")
×
178
                argDefaultExchangeLinkName     = pflag.Bool("default-exchange-link-name", false, "exchange link names of OVS bridge and the provider nic in the default provider-network")
×
179
                argDefaultVlanName             = pflag.String("default-vlan-name", "ovn-vlan", "The default vlan name")
×
180
                argDefaultVlanID               = pflag.Int("default-vlan-id", 1, "The default vlan id")
×
181
                argLsDnatModDlDst              = pflag.Bool("ls-dnat-mod-dl-dst", true, "Set ethernet destination address for DNAT on logical switch")
×
182
                argLsCtSkipDstLportIPs         = pflag.Bool("ls-ct-skip-dst-lport-ips", true, "Skip conntrack for direct traffic between lports")
×
183
                argPodNicType                  = pflag.String("pod-nic-type", "veth-pair", "The default pod network nic implementation type")
×
184
                argEnableLb                    = pflag.Bool("enable-lb", true, "Enable load balancer")
×
185
                argEnableNP                    = pflag.Bool("enable-np", true, "Enable network policy support")
×
186
                argEnableEipSnat               = pflag.Bool("enable-eip-snat", true, "Enable EIP and SNAT")
×
187
                argEnableExternalVpc           = pflag.Bool("enable-external-vpc", false, "Enable external vpc support")
×
188
                argEnableEcmp                  = pflag.Bool("enable-ecmp", false, "Enable ecmp route for centralized subnet")
×
189
                argKeepVMIP                    = pflag.Bool("keep-vm-ip", true, "Whether to keep ip for kubevirt pod when pod is rebuild")
×
190
                argEnableLbSvc                 = pflag.Bool("enable-lb-svc", false, "Whether to support loadbalancer service")
×
191
                argEnableOVNLBPreferLocal      = pflag.Bool("enable-ovn-lb-prefer-local", false, "Whether to support ovn loadbalancer prefer local")
×
192
                argEnableMetrics               = pflag.Bool("enable-metrics", true, "Whether to support metrics query")
×
193
                argEnableANP                   = pflag.Bool("enable-anp", false, "Enable support for admin network policy and baseline admin network policy")
×
194
                argEnableOVNIPSec              = pflag.Bool("enable-ovn-ipsec", false, "Whether to enable ovn ipsec")
×
195
                argCertManagerIPSecCert        = pflag.Bool("cert-manager-ipsec-cert", false, "Whether to use cert-manager for signing IPSec certificates")
×
196
                argEnableLiveMigrationOptimize = pflag.Bool("enable-live-migration-optimize", true, "Whether to enable kubevirt live migration optimize")
×
197

×
198
                argExternalGatewayConfigNS = pflag.String("external-gateway-config-ns", "kube-system", "The namespace of configmap external-gateway-config, default: kube-system")
×
199
                argExternalGatewaySwitch   = pflag.String("external-gateway-switch", "external", "The name of the external gateway switch which is a ovs bridge to provide external network, default: external")
×
200
                argExternalGatewayNet      = pflag.String("external-gateway-net", "external", "The name of the external network which mappings with an ovs bridge, default: external")
×
201
                argExternalGatewayVlanID   = pflag.Int("external-gateway-vlanid", 0, "The vlanId of port ln-ovn-external, default: 0")
×
202
                argNodeLocalDNSIP          = pflag.String("node-local-dns-ip", "", "Comma-separated string of nodelocal DNS ip addresses")
×
203

×
204
                argGCInterval      = pflag.Int("gc-interval", 360, "The interval between GC processes, default 360 seconds. If set to 0, GC will be disabled")
×
205
                argInspectInterval = pflag.Int("inspect-interval", 20, "The interval between inspect processes, default 20 seconds")
×
206

×
207
                argBfdMinTx      = pflag.Int("bfd-min-tx", 100, "This is the minimum interval, in milliseconds, ovn would like to use when transmitting BFD Control packets")
×
208
                argBfdMinRx      = pflag.Int("bfd-min-rx", 100, "This is the minimum interval, in milliseconds, between received BFD Control packets")
×
209
                argBfdDetectMult = pflag.Int("detect-mult", 3, "The negotiated transmit interval, multiplied by this value, provides the Detection Time for the receiving system in Asynchronous mode.")
×
210

×
211
                argImage = pflag.String("image", "", "The image for vpc-egress-gateway")
×
212

×
213
                argLogPerm = pflag.String("log-perm", "640", "The permission for the log file")
×
214

×
215
                argTLSMinVersion   = pflag.String("tls-min-version", "", "The minimum TLS version to use for secure serving. Supported values: TLS10, TLS11, TLS12, TLS13. If not set, the default is used based on the Go version.")
×
216
                argTLSMaxVersion   = pflag.String("tls-max-version", "", "The maximum TLS version to use for secure serving. Supported values: TLS10, TLS11, TLS12, TLS13. If not set, the default is used based on the Go version.")
×
217
                argTLSCipherSuites = pflag.StringSlice("tls-cipher-suites", nil, "Comma-separated list of TLS cipher suite names to use for secure serving (e.g., 'TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384'). Names must match Go's crypto/tls package. See Go documentation for available suites. If not set, defaults are used. Users are responsible for selecting secure cipher suites.")
×
NEW
218

×
NEW
219
                argNonPrimaryCNI = pflag.Bool("non-primary-cni-mode", false, "Use Kube-OVN in non primary cni mode. When true, Kube-OVN will only manage the network for network attachment definitions")
×
220
        )
×
221

×
222
        klogFlags := flag.NewFlagSet("klog", flag.ExitOnError)
×
223
        klog.InitFlags(klogFlags)
×
224

×
225
        // sync the glog and klog flags.
×
226
        pflag.CommandLine.VisitAll(func(f1 *pflag.Flag) {
×
227
                f2 := klogFlags.Lookup(f1.Name)
×
228
                if f2 != nil {
×
229
                        value := f1.Value.String()
×
230
                        if err := f2.Value.Set(value); err != nil {
×
231
                                util.LogFatalAndExit(err, "failed to set pflag")
×
232
                        }
×
233
                }
234
        })
235

236
        pflag.CommandLine.AddGoFlagSet(klogFlags)
×
237
        pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
×
238
        pflag.Parse()
×
239

×
240
        config := &Configuration{
×
241
                OvnNbAddr:                      *argOvnNbAddr,
×
242
                OvnSbAddr:                      *argOvnSbAddr,
×
243
                OvnTimeout:                     *argOvnTimeout,
×
244
                OvsDbConnectTimeout:            *argOvsDbConTimeout,
×
245
                OvsDbConnectMaxRetry:           *argOvsDbConnectMaxRetry,
×
246
                OvsDbInactivityTimeout:         *argOvsDbInactivityTimeout,
×
247
                CustCrdRetryMinDelay:           *argCustCrdRetryMinDelay,
×
248
                CustCrdRetryMaxDelay:           *argCustCrdRetryMaxDelay,
×
249
                KubeConfigFile:                 *argKubeConfigFile,
×
250
                DefaultLogicalSwitch:           *argDefaultLogicalSwitch,
×
251
                DefaultCIDR:                    *argDefaultCIDR,
×
252
                DefaultGateway:                 *argDefaultGateway,
×
253
                DefaultGatewayCheck:            *argDefaultGatewayCheck,
×
254
                DefaultLogicalGateway:          *argDefaultLogicalGateway,
×
255
                DefaultU2OInterconnection:      *argDefaultU2OInterconnection,
×
256
                DefaultExcludeIps:              *argDefaultExcludeIps,
×
257
                ClusterRouter:                  *argClusterRouter,
×
258
                NodeSwitch:                     *argNodeSwitch,
×
259
                NodeSwitchCIDR:                 *argNodeSwitchCIDR,
×
260
                NodeSwitchGateway:              *argNodeSwitchGateway,
×
261
                ServiceClusterIPRange:          *argServiceClusterIPRange,
×
262
                ClusterTCPLoadBalancer:         *argClusterTCPLoadBalancer,
×
263
                ClusterUDPLoadBalancer:         *argClusterUDPLoadBalancer,
×
264
                ClusterSctpLoadBalancer:        *argClusterSctpLoadBalancer,
×
265
                ClusterTCPSessionLoadBalancer:  *argClusterTCPSessionLoadBalancer,
×
266
                ClusterUDPSessionLoadBalancer:  *argClusterUDPSessionLoadBalancer,
×
267
                ClusterSctpSessionLoadBalancer: *argClusterSctpSessionLoadBalancer,
×
268
                WorkerNum:                      *argWorkerNum,
×
269
                EnablePprof:                    *argEnablePprof,
×
270
                PprofPort:                      *argPprofPort,
×
271
                SecureServing:                  *argSecureServing,
×
272
                NetworkType:                    *argNetworkType,
×
273
                DefaultVlanID:                  *argDefaultVlanID,
×
274
                LsDnatModDlDst:                 *argLsDnatModDlDst,
×
275
                LsCtSkipDstLportIPs:            *argLsCtSkipDstLportIPs,
×
276
                DefaultProviderName:            *argDefaultProviderName,
×
277
                DefaultHostInterface:           *argDefaultInterfaceName,
×
278
                DefaultExchangeLinkName:        *argDefaultExchangeLinkName,
×
279
                DefaultVlanName:                *argDefaultVlanName,
×
280
                PodName:                        os.Getenv("POD_NAME"),
×
281
                PodNamespace:                   os.Getenv("KUBE_NAMESPACE"),
×
282
                PodNicType:                     *argPodNicType,
×
283
                EnableLb:                       *argEnableLb,
×
284
                EnableNP:                       *argEnableNP,
×
285
                EnableEipSnat:                  *argEnableEipSnat,
×
286
                EnableExternalVpc:              *argEnableExternalVpc,
×
287
                ExternalGatewayConfigNS:        *argExternalGatewayConfigNS,
×
288
                ExternalGatewaySwitch:          *argExternalGatewaySwitch,
×
289
                ExternalGatewayNet:             *argExternalGatewayNet,
×
290
                ExternalGatewayVlanID:          *argExternalGatewayVlanID,
×
291
                EnableEcmp:                     *argEnableEcmp,
×
292
                EnableKeepVMIP:                 *argKeepVMIP,
×
293
                NodePgProbeTime:                *argNodePgProbeTime,
×
294
                GCInterval:                     *argGCInterval,
×
295
                InspectInterval:                *argInspectInterval,
×
296
                EnableLbSvc:                    *argEnableLbSvc,
×
297
                EnableOVNLBPreferLocal:         *argEnableOVNLBPreferLocal,
×
298
                EnableMetrics:                  *argEnableMetrics,
×
299
                EnableOVNIPSec:                 *argEnableOVNIPSec,
×
300
                CertManagerIPSecCert:           *argCertManagerIPSecCert,
×
301
                EnableLiveMigrationOptimize:    *argEnableLiveMigrationOptimize,
×
302
                BfdMinTx:                       *argBfdMinTx,
×
303
                BfdMinRx:                       *argBfdMinRx,
×
304
                BfdDetectMult:                  *argBfdDetectMult,
×
305
                EnableANP:                      *argEnableANP,
×
306
                Image:                          *argImage,
×
307
                LogPerm:                        *argLogPerm,
×
308
                TLSMinVersion:                  *argTLSMinVersion,
×
309
                TLSMaxVersion:                  *argTLSMaxVersion,
×
310
                TLSCipherSuites:                *argTLSCipherSuites,
×
NEW
311
                EnableNonPrimaryCNI:            *argNonPrimaryCNI,
×
312
        }
×
313
        if config.OvsDbConnectTimeout >= config.OvsDbInactivityTimeout {
×
314
                return nil, errors.New("OVS DB inactivity timeout value should be greater than reconnect timeout value")
×
315
        }
×
316

317
        if config.NetworkType == util.NetworkTypeVlan && config.DefaultHostInterface == "" {
×
318
                return nil, errors.New("no host nic for vlan")
×
319
        }
×
320

321
        if config.DefaultGateway == "" {
×
322
                gw, err := util.GetGwByCidr(config.DefaultCIDR)
×
323
                if err != nil {
×
324
                        klog.Error(err)
×
325
                        return nil, err
×
326
                }
×
327
                config.DefaultGateway = gw
×
328
        }
329

330
        if config.DefaultExcludeIps == "" {
×
331
                config.DefaultExcludeIps = config.DefaultGateway
×
332
        }
×
333

334
        if config.NodeSwitchGateway == "" {
×
335
                gw, err := util.GetGwByCidr(config.NodeSwitchCIDR)
×
336
                if err != nil {
×
337
                        klog.Error(err)
×
338
                        return nil, err
×
339
                }
×
340
                config.NodeSwitchGateway = gw
×
341
        }
342

343
        if err := config.initKubeClient(); err != nil {
×
344
                klog.Error(err)
×
345
                return nil, err
×
346
        }
×
347

348
        if err := config.initKubeFactoryClient(); err != nil {
×
349
                klog.Error(err)
×
350
                return nil, err
×
351
        }
×
352

353
        if err := util.CheckSystemCIDR([]string{config.NodeSwitchCIDR, config.DefaultCIDR, config.ServiceClusterIPRange}); err != nil {
×
354
                klog.Error(err)
×
355
                return nil, fmt.Errorf("check system cidr failed, %w", err)
×
356
        }
×
357

358
        for ip := range strings.SplitSeq(*argNodeLocalDNSIP, ",") {
×
359
                if err := util.CheckNodeDNSIP(ip); err != nil {
×
360
                        klog.Error(err)
×
361
                        return nil, err
×
362
                }
×
363
                config.NodeLocalDNSIPs = append(config.NodeLocalDNSIPs, ip)
×
364
        }
365

366
        klog.Infof("config is %+v", config)
×
367
        return config, nil
×
368
}
369

370
func (config *Configuration) initKubeClient() error {
×
371
        var cfg *rest.Config
×
372
        var err error
×
373
        if config.KubeConfigFile == "" {
×
374
                klog.Infof("no --kubeconfig, use in-cluster kubernetes config")
×
375
                cfg, err = rest.InClusterConfig()
×
376
        } else {
×
377
                cfg, err = clientcmd.BuildConfigFromFlags("", config.KubeConfigFile)
×
378
        }
×
379
        if err != nil {
×
380
                klog.Errorf("failed to build kubeconfig %v", err)
×
381
                return err
×
382
        }
×
383

384
        // try to connect to apiserver's tcp port
385
        if err = util.DialAPIServer(cfg.Host, 3*time.Second, 10); err != nil {
×
386
                klog.Errorf("failed to dial apiserver: %v", err)
×
387
                return err
×
388
        }
×
389

390
        cfg.QPS = 1000
×
391
        cfg.Burst = 2000
×
392
        // use cmd arg to modify timeout later
×
393
        cfg.Timeout = 30 * time.Second
×
394

×
395
        AttachNetClient, err := attachnetclientset.NewForConfig(cfg)
×
396
        if err != nil {
×
397
                klog.Errorf("init attach network client failed %v", err)
×
398
                return err
×
399
        }
×
400
        config.AttachNetClient = AttachNetClient
×
401

×
402
        // get the kubevirt client, using which kubevirt resources can be managed.
×
403
        virtClient, err := kubecli.GetKubevirtClientFromRESTConfig(cfg)
×
404
        if err != nil {
×
405
                klog.Errorf("init kubevirt client failed %v", err)
×
406
                return err
×
407
        }
×
408
        config.KubevirtClient = virtClient
×
409

×
410
        AnpClient, err := anpclientset.NewForConfig(cfg)
×
411
        if err != nil {
×
412
                klog.Errorf("init admin network policy client failed %v", err)
×
413
                return err
×
414
        }
×
415
        config.AnpClient = AnpClient
×
416

×
417
        kubeOvnClient, err := clientset.NewForConfig(cfg)
×
418
        if err != nil {
×
419
                klog.Errorf("init kubeovn client failed %v", err)
×
420
                return err
×
421
        }
×
422
        config.KubeOvnClient = kubeOvnClient
×
423

×
424
        ExtClient, err := extClientSet.NewForConfig(cfg)
×
425
        if err != nil {
×
426
                klog.Errorf("init extentsion client failed %v", err)
×
427
                return err
×
428
        }
×
429
        config.ExtClient = ExtClient
×
430

×
431
        cfg.ContentType = "application/vnd.kubernetes.protobuf"
×
432
        cfg.AcceptContentTypes = "application/vnd.kubernetes.protobuf,application/json"
×
433
        kubeClient, err := kubernetes.NewForConfig(cfg)
×
434
        if err != nil {
×
435
                klog.Errorf("init kubernetes client failed %v", err)
×
436
                return err
×
437
        }
×
438
        config.KubeClient = kubeClient
×
439
        return nil
×
440
}
441

442
func (config *Configuration) initKubeFactoryClient() error {
×
443
        var cfg *rest.Config
×
444
        var err error
×
445
        if config.KubeConfigFile == "" {
×
446
                klog.Infof("no --kubeconfig, use in-cluster kubernetes config")
×
447
                cfg, err = rest.InClusterConfig()
×
448
        } else {
×
449
                cfg, err = clientcmd.BuildConfigFromFlags("", config.KubeConfigFile)
×
450
        }
×
451
        if err != nil {
×
452
                klog.Errorf("failed to build kubeconfig %v", err)
×
453
                return err
×
454
        }
×
455
        cfg.QPS = 1000
×
456
        cfg.Burst = 2000
×
457

×
458
        config.KubeRestConfig = cfg
×
459

×
460
        kubeOvnClient, err := clientset.NewForConfig(cfg)
×
461
        if err != nil {
×
462
                klog.Errorf("init kubeovn client failed %v", err)
×
463
                return err
×
464
        }
×
465
        config.KubeOvnFactoryClient = kubeOvnClient
×
466

×
467
        cfg.ContentType = "application/vnd.kubernetes.protobuf"
×
468
        cfg.AcceptContentTypes = "application/vnd.kubernetes.protobuf,application/json"
×
469
        kubeClient, err := kubernetes.NewForConfig(cfg)
×
470
        if err != nil {
×
471
                klog.Errorf("init kubernetes client failed %v", err)
×
472
                return err
×
473
        }
×
474
        config.KubeFactoryClient = kubeClient
×
475
        return nil
×
476
}
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