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

kubeovn / kube-ovn / 21623048013

03 Feb 2026 08:37AM UTC coverage: 23.043%. Remained the same
21623048013

push

github

web-flow
fix typo (#6253)

Signed-off-by: Mengxin Liu <liumengxinfly@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>

12 of 152 new or added lines in 51 files covered. (7.89%)

1 existing line in 1 file now uncovered.

12411 of 53860 relevant lines covered (23.04%)

0.27 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 config
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
        EnableDNSNameResolver       bool
100
        EnableOVNIPSec              bool
101
        CertManagerIPSecCert        bool
102
        EnableLiveMigrationOptimize bool
103

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

109
        GCInterval      int
110
        InspectInterval int
111

112
        BfdMinTx      int
113
        BfdMinRx      int
114
        BfdDetectMult int
115

116
        NodeLocalDNSIPs []string
117

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

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

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

129
        // Non Primary CNI flag
130
        EnableNonPrimaryCNI bool
131

132
        // Enforcement level of network policies (standard, lax)
133
        NetworkPolicyEnforcement string
134

135
        // Skip conntrack for specific destination IP CIDRs
136
        SkipConntrackDstCidrs string
137
}
138

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

×
153
                argDefaultLogicalSwitch  = pflag.String("default-ls", util.DefaultSubnet, "The default logical switch name")
×
154
                argDefaultCIDR           = pflag.String("default-cidr", "10.16.0.0/16", "Default CIDR for namespace with no logical switch annotation")
×
155
                argDefaultGateway        = pflag.String("default-gateway", "", "Default gateway for default-cidr (default the first ip in default-cidr)")
×
156
                argDefaultGatewayCheck   = pflag.Bool("default-gateway-check", true, "Check switch for the default subnet's gateway")
×
157
                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)")
×
158
                argDefaultExcludeIps     = pflag.String("default-exclude-ips", "", "Exclude ips in default switch (default gateway address)")
×
159

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

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

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

×
169
                argClusterTCPLoadBalancer         = pflag.String("cluster-tcp-loadbalancer", "cluster-tcp-loadbalancer", "The name for cluster tcp loadbalancer")
×
170
                argClusterUDPLoadBalancer         = pflag.String("cluster-udp-loadbalancer", "cluster-udp-loadbalancer", "The name for cluster udp loadbalancer")
×
171
                argClusterSctpLoadBalancer        = pflag.String("cluster-sctp-loadbalancer", "cluster-sctp-loadbalancer", "The name for cluster sctp loadbalancer")
×
172
                argClusterTCPSessionLoadBalancer  = pflag.String("cluster-tcp-session-loadbalancer", "cluster-tcp-session-loadbalancer", "The name for cluster tcp session loadbalancer")
×
173
                argClusterUDPSessionLoadBalancer  = pflag.String("cluster-udp-session-loadbalancer", "cluster-udp-session-loadbalancer", "The name for cluster udp session loadbalancer")
×
174
                argClusterSctpSessionLoadBalancer = pflag.String("cluster-sctp-session-loadbalancer", "cluster-sctp-session-loadbalancer", "The name for cluster sctp session loadbalancer")
×
175

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

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

×
207
                argExternalGatewayConfigNS = pflag.String("external-gateway-config-ns", "kube-system", "The namespace of configmap external-gateway-config, default: kube-system")
×
208
                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")
×
209
                argExternalGatewayNet      = pflag.String("external-gateway-net", "external", "The name of the external network which mappings with an ovs bridge, default: external")
×
210
                argExternalGatewayVlanID   = pflag.Int("external-gateway-vlanid", 0, "The vlanId of port ln-ovn-external, default: 0")
×
211
                argNodeLocalDNSIP          = pflag.String("node-local-dns-ip", "", "Comma-separated string of nodelocal DNS ip addresses")
×
212

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

×
216
                argBfdMinTx      = pflag.Int("bfd-min-tx", 100, "This is the minimum interval, in milliseconds, ovn would like to use when transmitting BFD Control packets")
×
217
                argBfdMinRx      = pflag.Int("bfd-min-rx", 100, "This is the minimum interval, in milliseconds, between received BFD Control packets")
×
218
                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.")
×
219

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

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

×
224
                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.")
×
225
                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.")
×
226
                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.")
×
227

×
228
                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")
×
229

×
230
                argSkipConntrackDstCidrs = pflag.String("skip-conntrack-dst-cidrs", "", "Comma-separated list of destination IP CIDRs that should skip conntrack processing")
×
231
        )
×
232

×
233
        klogFlags := flag.NewFlagSet("klog", flag.ExitOnError)
×
234
        klog.InitFlags(klogFlags)
×
235

×
236
        // sync the glog and klog flags.
×
237
        pflag.CommandLine.VisitAll(func(f1 *pflag.Flag) {
×
238
                f2 := klogFlags.Lookup(f1.Name)
×
239
                if f2 != nil {
×
240
                        value := f1.Value.String()
×
241
                        if err := f2.Value.Set(value); err != nil {
×
242
                                util.LogFatalAndExit(err, "failed to set pflag")
×
243
                        }
×
244
                }
245
        })
246

247
        pflag.CommandLine.AddGoFlagSet(klogFlags)
×
248
        pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
×
249
        pflag.Parse()
×
250

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

331
        if config.NetworkType == util.NetworkTypeVlan && config.DefaultHostInterface == "" {
×
332
                return nil, errors.New("no host nic for vlan")
×
333
        }
×
334

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

344
        if config.DefaultExcludeIps == "" {
×
345
                config.DefaultExcludeIps = config.DefaultGateway
×
346
        }
×
347

348
        if config.NodeSwitchGateway == "" {
×
349
                gw, err := util.GetGwByCidr(config.NodeSwitchCIDR)
×
350
                if err != nil {
×
351
                        klog.Error(err)
×
352
                        return nil, err
×
353
                }
×
354
                config.NodeSwitchGateway = gw
×
355
        }
356

357
        if err := config.initKubeClient(); err != nil {
×
358
                klog.Error(err)
×
359
                return nil, err
×
360
        }
×
361

362
        if err := config.initKubeFactoryClient(); err != nil {
×
363
                klog.Error(err)
×
364
                return nil, err
×
365
        }
×
366

367
        if err := util.CheckSystemCIDR([]string{config.NodeSwitchCIDR, config.DefaultCIDR, config.ServiceClusterIPRange}); err != nil {
×
368
                klog.Error(err)
×
369
                return nil, fmt.Errorf("check system cidr failed, %w", err)
×
370
        }
×
371

372
        for ip := range strings.SplitSeq(*argNodeLocalDNSIP, ",") {
×
373
                if err := util.CheckNodeDNSIP(ip); err != nil {
×
374
                        klog.Error(err)
×
375
                        return nil, err
×
376
                }
×
377
                config.NodeLocalDNSIPs = append(config.NodeLocalDNSIPs, ip)
×
378
        }
379

380
        klog.Infof("config is %+v", config)
×
381
        return config, nil
×
382
}
383

384
func (config *Configuration) initKubeClient() error {
×
385
        var cfg *rest.Config
×
386
        var err error
×
387
        if config.KubeConfigFile == "" {
×
388
                klog.Infof("no --kubeconfig, use in-cluster kubernetes config")
×
389
                cfg, err = rest.InClusterConfig()
×
390
        } else {
×
391
                cfg, err = clientcmd.BuildConfigFromFlags("", config.KubeConfigFile)
×
392
        }
×
393
        if err != nil {
×
394
                klog.Errorf("failed to build kubeconfig %v", err)
×
395
                return err
×
396
        }
×
397

398
        // try to connect to apiserver's tcp port
399
        if err = util.DialAPIServer(cfg.Host, 3*time.Second, 10); err != nil {
×
400
                klog.Errorf("failed to dial apiserver: %v", err)
×
401
                return err
×
402
        }
×
403

404
        cfg.QPS = 1000
×
405
        cfg.Burst = 2000
×
406
        // use cmd arg to modify timeout later
×
407
        cfg.Timeout = 30 * time.Second
×
408

×
409
        AttachNetClient, err := attachnetclientset.NewForConfig(cfg)
×
410
        if err != nil {
×
411
                klog.Errorf("init attach network client failed %v", err)
×
412
                return err
×
413
        }
×
414
        config.AttachNetClient = AttachNetClient
×
415

×
416
        // get the kubevirt client, using which kubevirt resources can be managed.
×
417
        virtClient, err := kubecli.GetKubevirtClientFromRESTConfig(cfg)
×
418
        if err != nil {
×
419
                klog.Errorf("init kubevirt client failed %v", err)
×
420
                return err
×
421
        }
×
422
        config.KubevirtClient = virtClient
×
423

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

×
431
        kubeOvnClient, err := clientset.NewForConfig(cfg)
×
432
        if err != nil {
×
433
                klog.Errorf("init kubeovn client failed %v", err)
×
434
                return err
×
435
        }
×
436
        config.KubeOvnClient = kubeOvnClient
×
437

×
438
        ExtClient, err := extClientSet.NewForConfig(cfg)
×
439
        if err != nil {
×
NEW
440
                klog.Errorf("init extension client failed %v", err)
×
441
                return err
×
442
        }
×
443
        config.ExtClient = ExtClient
×
444

×
445
        cfg.ContentType = util.ContentTypeProtobuf
×
446
        cfg.AcceptContentTypes = util.AcceptContentTypes
×
447
        kubeClient, err := kubernetes.NewForConfig(cfg)
×
448
        if err != nil {
×
449
                klog.Errorf("init kubernetes client failed %v", err)
×
450
                return err
×
451
        }
×
452
        config.KubeClient = kubeClient
×
453
        return nil
×
454
}
455

456
func (config *Configuration) initKubeFactoryClient() error {
×
457
        var cfg *rest.Config
×
458
        var err error
×
459
        if config.KubeConfigFile == "" {
×
460
                klog.Infof("no --kubeconfig, use in-cluster kubernetes config")
×
461
                cfg, err = rest.InClusterConfig()
×
462
        } else {
×
463
                cfg, err = clientcmd.BuildConfigFromFlags("", config.KubeConfigFile)
×
464
        }
×
465
        if err != nil {
×
466
                klog.Errorf("failed to build kubeconfig %v", err)
×
467
                return err
×
468
        }
×
469
        cfg.QPS = 1000
×
470
        cfg.Burst = 2000
×
471

×
472
        config.KubeRestConfig = cfg
×
473

×
474
        kubeOvnClient, err := clientset.NewForConfig(cfg)
×
475
        if err != nil {
×
476
                klog.Errorf("init kubeovn client failed %v", err)
×
477
                return err
×
478
        }
×
479
        config.KubeOvnFactoryClient = kubeOvnClient
×
480

×
481
        cfg.ContentType = util.ContentTypeProtobuf
×
482
        cfg.AcceptContentTypes = util.AcceptContentTypes
×
483
        kubeClient, err := kubernetes.NewForConfig(cfg)
×
484
        if err != nil {
×
485
                klog.Errorf("init kubernetes client failed %v", err)
×
486
                return err
×
487
        }
×
488
        config.KubeFactoryClient = kubeClient
×
489
        return nil
×
490
}
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