...
1
16
17 package options
18
19 import (
20 "fmt"
21 "strings"
22
23 "github.com/spf13/pflag"
24
25 nodeipamconfig "k8s.io/kubernetes/pkg/controller/nodeipam/config"
26 )
27
28
29 type NodeIPAMControllerOptions struct {
30 *nodeipamconfig.NodeIPAMControllerConfiguration
31 }
32
33
34 func (o *NodeIPAMControllerOptions) AddFlags(fs *pflag.FlagSet) {
35 if o == nil {
36 return
37 }
38 fs.StringVar(&o.ServiceCIDR, "service-cluster-ip-range", o.ServiceCIDR, "CIDR Range for Services in cluster. Requires --allocate-node-cidrs to be true")
39 fs.Int32Var(&o.NodeCIDRMaskSize, "node-cidr-mask-size", o.NodeCIDRMaskSize, "Mask size for node cidr in cluster. Default is 24 for IPv4 and 64 for IPv6.")
40 fs.Int32Var(&o.NodeCIDRMaskSizeIPv4, "node-cidr-mask-size-ipv4", o.NodeCIDRMaskSizeIPv4, "Mask size for IPv4 node cidr in dual-stack cluster. Default is 24.")
41 fs.Int32Var(&o.NodeCIDRMaskSizeIPv6, "node-cidr-mask-size-ipv6", o.NodeCIDRMaskSizeIPv6, "Mask size for IPv6 node cidr in dual-stack cluster. Default is 64.")
42 }
43
44
45 func (o *NodeIPAMControllerOptions) ApplyTo(cfg *nodeipamconfig.NodeIPAMControllerConfiguration) error {
46 if o == nil {
47 return nil
48 }
49
50
51 serviceCIDRList := strings.Split(o.ServiceCIDR, ",")
52 if len(serviceCIDRList) > 0 {
53 cfg.ServiceCIDR = serviceCIDRList[0]
54 }
55 if len(serviceCIDRList) > 1 {
56 cfg.SecondaryServiceCIDR = serviceCIDRList[1]
57 }
58
59 cfg.NodeCIDRMaskSize = o.NodeCIDRMaskSize
60 cfg.NodeCIDRMaskSizeIPv4 = o.NodeCIDRMaskSizeIPv4
61 cfg.NodeCIDRMaskSizeIPv6 = o.NodeCIDRMaskSizeIPv6
62
63 return nil
64 }
65
66
67 func (o *NodeIPAMControllerOptions) Validate() []error {
68 if o == nil {
69 return nil
70 }
71 errs := make([]error, 0)
72
73 serviceCIDRList := strings.Split(o.ServiceCIDR, ",")
74 if len(serviceCIDRList) > 2 {
75 errs = append(errs, fmt.Errorf("--service-cluster-ip-range can not contain more than two entries"))
76 }
77
78 return errs
79 }
80
View as plain text