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

kubeovn / kube-ovn / 17723172333

15 Sep 2025 05:35AM UTC coverage: 21.04% (-0.2%) from 21.229%
17723172333

push

github

web-flow
fix(deps): update module github.com/puzpuzpuz/xsync/v4 to v4.2.0 (#5722)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

10661 of 50669 relevant lines covered (21.04%)

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
        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

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

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

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

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

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

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

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

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

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

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

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

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

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

×
217
                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.")
×
218
                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.")
×
219
                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.")
×
220

×
221
                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")
×
222
        )
×
223

×
224
        klogFlags := flag.NewFlagSet("klog", flag.ExitOnError)
×
225
        klog.InitFlags(klogFlags)
×
226

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

238
        pflag.CommandLine.AddGoFlagSet(klogFlags)
×
239
        pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
×
240
        pflag.Parse()
×
241

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

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

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

333
        if config.DefaultExcludeIps == "" {
×
334
                config.DefaultExcludeIps = config.DefaultGateway
×
335
        }
×
336

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

346
        if err := config.initKubeClient(); err != nil {
×
347
                klog.Error(err)
×
348
                return nil, err
×
349
        }
×
350

351
        if err := config.initKubeFactoryClient(); err != nil {
×
352
                klog.Error(err)
×
353
                return nil, err
×
354
        }
×
355

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

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

369
        klog.Infof("config is %+v", config)
×
370
        return config, nil
×
371
}
372

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

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

393
        cfg.QPS = 1000
×
394
        cfg.Burst = 2000
×
395
        // use cmd arg to modify timeout later
×
396
        cfg.Timeout = 30 * time.Second
×
397

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

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

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

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

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

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

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

×
461
        config.KubeRestConfig = cfg
×
462

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

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