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

kubeovn / kube-ovn / 18554291225

16 Oct 2025 07:53AM UTC coverage: 21.145% (+0.06%) from 21.087%
18554291225

push

github

web-flow
feat(netpol): authorize l3 protocols (#5745)

* feat(netpol): authorize l3 protocols

Signed-off-by: SkalaNetworks <contact@skala.network>

* feat(netpol): add annotation for different policy enforcements

Signed-off-by: SkalaNetworks <contact@skala.network>

* feat(netpols): add enforcement configuration and deployment config

Signed-off-by: SkalaNetworks <contact@skala.network>

* chore(netpol): add unit tests

Signed-off-by: SkalaNetworks <contact@skala.network>

* feat(netpol): only block tcp/udp/sctp in lax enforcement

Signed-off-by: SkalaNetworks <contact@skala.network>

---------

Signed-off-by: SkalaNetworks <contact@skala.network>

57 of 94 new or added lines in 3 files covered. (60.64%)

2 existing lines in 1 file now uncovered.

10729 of 50740 relevant lines covered (21.15%)

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
        // Enforcement level of network policies (standard, lax)
133
        NetworkPolicyEnforcement string
134
}
135

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

×
228
        klogFlags := flag.NewFlagSet("klog", flag.ExitOnError)
×
229
        klog.InitFlags(klogFlags)
×
230

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

242
        pflag.CommandLine.AddGoFlagSet(klogFlags)
×
243
        pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
×
244
        pflag.Parse()
×
245

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

325
        if config.NetworkType == util.NetworkTypeVlan && config.DefaultHostInterface == "" {
×
326
                return nil, errors.New("no host nic for vlan")
×
327
        }
×
328

329
        if config.DefaultGateway == "" {
×
330
                gw, err := util.GetGwByCidr(config.DefaultCIDR)
×
331
                if err != nil {
×
332
                        klog.Error(err)
×
333
                        return nil, err
×
334
                }
×
335
                config.DefaultGateway = gw
×
336
        }
337

338
        if config.DefaultExcludeIps == "" {
×
339
                config.DefaultExcludeIps = config.DefaultGateway
×
340
        }
×
341

342
        if config.NodeSwitchGateway == "" {
×
343
                gw, err := util.GetGwByCidr(config.NodeSwitchCIDR)
×
344
                if err != nil {
×
345
                        klog.Error(err)
×
346
                        return nil, err
×
347
                }
×
348
                config.NodeSwitchGateway = gw
×
349
        }
350

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

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

361
        if err := util.CheckSystemCIDR([]string{config.NodeSwitchCIDR, config.DefaultCIDR, config.ServiceClusterIPRange}); err != nil {
×
362
                klog.Error(err)
×
363
                return nil, fmt.Errorf("check system cidr failed, %w", err)
×
364
        }
×
365

366
        for ip := range strings.SplitSeq(*argNodeLocalDNSIP, ",") {
×
367
                if err := util.CheckNodeDNSIP(ip); err != nil {
×
368
                        klog.Error(err)
×
369
                        return nil, err
×
370
                }
×
371
                config.NodeLocalDNSIPs = append(config.NodeLocalDNSIPs, ip)
×
372
        }
373

374
        klog.Infof("config is %+v", config)
×
375
        return config, nil
×
376
}
377

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

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

398
        cfg.QPS = 1000
×
399
        cfg.Burst = 2000
×
400
        // use cmd arg to modify timeout later
×
401
        cfg.Timeout = 30 * time.Second
×
402

×
403
        AttachNetClient, err := attachnetclientset.NewForConfig(cfg)
×
404
        if err != nil {
×
405
                klog.Errorf("init attach network client failed %v", err)
×
406
                return err
×
407
        }
×
408
        config.AttachNetClient = AttachNetClient
×
409

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

×
418
        AnpClient, err := anpclientset.NewForConfig(cfg)
×
419
        if err != nil {
×
420
                klog.Errorf("init admin network policy client failed %v", err)
×
421
                return err
×
422
        }
×
423
        config.AnpClient = AnpClient
×
424

×
425
        kubeOvnClient, err := clientset.NewForConfig(cfg)
×
426
        if err != nil {
×
427
                klog.Errorf("init kubeovn client failed %v", err)
×
428
                return err
×
429
        }
×
430
        config.KubeOvnClient = kubeOvnClient
×
431

×
432
        ExtClient, err := extClientSet.NewForConfig(cfg)
×
433
        if err != nil {
×
434
                klog.Errorf("init extentsion client failed %v", err)
×
435
                return err
×
436
        }
×
437
        config.ExtClient = ExtClient
×
438

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

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

×
466
        config.KubeRestConfig = cfg
×
467

×
468
        kubeOvnClient, err := clientset.NewForConfig(cfg)
×
469
        if err != nil {
×
470
                klog.Errorf("init kubeovn client failed %v", err)
×
471
                return err
×
472
        }
×
473
        config.KubeOvnFactoryClient = kubeOvnClient
×
474

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

© 2025 Coveralls, Inc