Skip to content

Commit 9aa8eb4

Browse files
author
Rahul Sharma
committed
handle default value for subnet-names, add docs
1 parent f640b63 commit 9aa8eb4

File tree

5 files changed

+44
-16
lines changed

5 files changed

+44
-16
lines changed

cloud/linode/vpc.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ func getNodeBalancerBackendIPv4SubnetID(client client.Client) (int, error) {
170170

171171
func validateVPCSubnetFlags() error {
172172
switch {
173+
case len(Options.VPCIDs) > 0 && len(Options.VPCNames) > 0:
174+
return fmt.Errorf("cannot have both vpc-ids and vpc-names set")
173175
case len(Options.VPCIDs) > 0 && len(Options.SubnetIDs) == 0:
174176
return fmt.Errorf("vpc-ids cannot be set without subnet-ids")
175177
case len(Options.SubnetIDs) > 0 && len(Options.VPCIDs) == 0:
@@ -178,10 +180,6 @@ func validateVPCSubnetFlags() error {
178180
// and if so, we require vpc-names to be set
179181
case len(Options.SubnetNames) > 0 && len(Options.VPCNames) == 0 && Options.EnableRouteController:
180182
return fmt.Errorf("subnet-names cannot be set without vpc-names")
181-
case len(Options.VPCIDs) > 0 && len(Options.VPCNames) > 0:
182-
return fmt.Errorf("cannot have both vpc-ids and vpc-names set")
183-
case len(Options.SubnetIDs) > 0 && len(Options.SubnetNames) > 0:
184-
return fmt.Errorf("cannot have both subnet-ids and subnet-names set")
185183
case len(Options.VPCIDs) == 0:
186184
return nil
187185
}
@@ -204,6 +202,11 @@ func resolveSubnetNames(client client.Client, vpcID int) ([]string, error) {
204202
}
205203

206204
func validateAndSetVPCSubnetFlags(client client.Client) error {
205+
// ignore default subnet-names if subnet-ids are set
206+
if len(Options.SubnetIDs) > 0 {
207+
Options.SubnetNames = []string{}
208+
}
209+
207210
if err := validateVPCSubnetFlags(); err != nil {
208211
return err
209212
}
@@ -231,5 +234,7 @@ func validateAndSetVPCSubnetFlags(client client.Client) error {
231234
}
232235

233236
Options.VPCNames = append(Options.VPCNames, vpcNames...)
237+
klog.V(3).Infof("VPC IDs: %v, VPC Names: %v, Subnet IDs: %v, Subnet Names: %v",
238+
Options.VPCIDs, Options.VPCNames, Options.SubnetIDs, Options.SubnetNames)
234239
return nil
235240
}

cloud/linode/vpc_test.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -306,14 +306,6 @@ func Test_validateVPCSubnetFlags(t *testing.T) {
306306
subnetNames: []string{},
307307
wantErr: true,
308308
},
309-
{
310-
name: "invalid flags with subnet-names and subnet-ids set",
311-
vpcIDs: []int{},
312-
vpcNames: []string{"vpc1", "vpc2"},
313-
subnetIDs: []int{1, 2},
314-
subnetNames: []string{"subnet1", "subnet2"},
315-
wantErr: true,
316-
},
317309
{
318310
name: "invalid flags with subnet-names and no vpc-names",
319311
vpcIDs: []int{},

deploy/chart/templates/daemonset.yaml

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,20 @@ spec:
8383
{{- if and .Values.routeController .Values.routeController.subnetNames }}
8484
{{- $subnetNames = .Values.routeController.subnetNames }}
8585
{{- end }}
86+
{{- $vpcIDs := .Values.vpcIDs }}
87+
{{- if and .Values.routeController .Values.routeController.vpcIDs }}
88+
{{- $vpcIDs = .Values.routeController.vpcIDs }}
89+
{{- end }}
90+
{{- $subnetIDs := .Values.subnetIDs }}
91+
{{- if and .Values.routeController .Values.routeController.subnetIDs }}
92+
{{- $subnetIDs = .Values.routeController.subnetIDs }}
93+
{{- end }}
94+
{{- if and $vpcIDs $vpcNames }}
95+
{{- fail "Both vpcIDs and vpcNames are set. Please use only one." }}
96+
{{- end }}
97+
{{- if and $subnetIDs $subnetNames }}
98+
{{- fail "Both subnetIDs and subnetNames are set. Please use only one." }}
99+
{{- end }}
86100
{{- if .Values.disableNodeBalancerVPCBackends }}
87101
- --disable-nodebalancer-vpc-backends={{ .Values.disableNodeBalancerVPCBackends }}
88102
{{- end }}
@@ -99,8 +113,11 @@ spec:
99113
{{- end }}
100114
{{- if .Values.routeController }}
101115
- --enable-route-controller=true
102-
{{- if not $vpcNames }}
103-
{{- fail "vpcNames not set. Please set it when enabling route_controller for VPCs." }}
116+
{{- if not (or $vpcNames $vpcIDs) }}
117+
{{- fail "vpcNames or vpcIDs not set. Please set it when enabling route_controller for VPCs." }}
118+
{{- end }}
119+
{{- if and $vpcIDs (not $subnetIDs) }}
120+
{{- fail "subnetIDs must be set when vpcIDs are set for route-controller" }}
104121
{{- end }}
105122
{{- if not $clusterCIDR }}
106123
{{- fail "clusterCIDR is required if route-controller is enabled" }}
@@ -116,6 +133,12 @@ spec:
116133
{{- with $subnetNames }}
117134
- --subnet-names={{ . }}
118135
{{- end }}
136+
{{- with $vpcIDs }}
137+
- --vpc-ids={{ . }}
138+
{{- end }}
139+
{{- with $subnetIDs }}
140+
- --subnet-ids={{ . }}
141+
{{- end }}
119142
{{- with $clusterCIDR }}
120143
- --cluster-cidr={{ . }}
121144
{{- end }}

deploy/chart/values.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,11 @@ tolerations:
7575

7676
# This section adds ability to enable route-controller for ccm
7777
# routeController:
78+
# Use one of the two: either [vpcNames and subnetNames] or [vpcIDs and subnetIDs]
7879
# vpcNames: <comma separated list of vpc names>
7980
# subnetNames: <comma separated list of subnet names>
81+
# vpcIDs: <comma separated list of vpc ids>
82+
# subnetIDs: <comma separated list of subnet ids>
8083
# clusterCIDR: 10.192.0.0/10
8184
# configureCloudRoutes: true
8285

@@ -87,8 +90,11 @@ tolerations:
8790
# nodeCIDRMaskSizeIPv6: 64
8891

8992
# vpcs and subnets that node internal IPs will be assigned from (not required if already specified in routeController)
93+
# Use one of the two: either [vpcNames and subnetNames] or [vpcIDs and subnetIDs]
9094
# vpcNames: <comma separated list of vpc names>
9195
# subnetNames: <comma separated list of subnet names>
96+
# vpcIDs: <comma separated list of vpc ids>
97+
# subnetIDs: <comma separated list of subnet ids>
9298

9399
# Enable Linode token health checker
94100
# tokenHealthChecker: true

docs/configuration/environment.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ The CCM supports the following flags:
3939
| `--linodego-debug` | `false` | Enables debug output for the LinodeAPI wrapper |
4040
| `--enable-route-controller` | `false` | Enables route_controller for CCM |
4141
| `--enable-token-health-checker` | `false` | Enables Linode API token health checker |
42-
| `--vpc-names` | `""` | Comma separated VPC names whose routes will be managed by route-controller |
43-
| `--subnet-names` | `""` | Comma separated subnet names whose routes will be managed by route-controller (requires vpc-names flag) |
42+
| `--vpc-names` | `[]` | Comma separated VPC names whose routes will be managed by route-controller |
43+
| `--subnet-names` | `["default"]` | Comma separated subnet names whose routes will be managed by route-controller (requires vpc-names flag) |
44+
| `--vpc-ids` | `[]` | Comma separated VPC ids whose routes will be managed by route-controller |
45+
| `--subnet-ids` | `[]` | Comma separated subnet ids whose routes will be managed by route-controller (requires vpc-ids flag) |
4446
| `--load-balancer-type` | `nodebalancer` | Configures which type of load-balancing to use (options: nodebalancer, cilium-bgp) |
4547
| `--bgp-node-selector` | `""` | Node selector to use to perform shared IP fail-over with BGP |
4648
| `--ip-holder-suffix` | `""` | Suffix to append to the IP holder name when using shared IP fail-over with BGP |

0 commit comments

Comments
 (0)