Skip to content

Commit 8f46a4d

Browse files
committed
Allow to specify cidr block for default node nodeport ingress rule
1 parent d6337fc commit 8f46a4d

14 files changed

+180
-1
lines changed

api/v1beta1/awscluster_conversion.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ func (src *AWSCluster) ConvertTo(dstRaw conversion.Hub) error {
8585
}
8686

8787
dst.Spec.NetworkSpec.AdditionalControlPlaneIngressRules = restored.Spec.NetworkSpec.AdditionalControlPlaneIngressRules
88+
dst.Spec.NetworkSpec.NodePortIngressRuleCidrBlocks = restored.Spec.NetworkSpec.NodePortIngressRuleCidrBlocks
8889

8990
if restored.Spec.NetworkSpec.VPC.IPAMPool != nil {
9091
if dst.Spec.NetworkSpec.VPC.IPAMPool == nil {

api/v1beta1/zz_generated.conversion.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1beta2/awscluster_webhook.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package v1beta2
1818

1919
import (
2020
"fmt"
21+
"net"
2122
"strings"
2223

2324
"github.com/google/go-cmp/cmp"
@@ -267,6 +268,12 @@ func (r *AWSCluster) validateNetwork() field.ErrorList {
267268
allErrs = append(allErrs, r.validateIngressRule(rule)...)
268269
}
269270

271+
for cidrBlockIndex, cidrBlock := range r.Spec.NetworkSpec.NodePortIngressRuleCidrBlocks {
272+
if _, _, err := net.ParseCIDR(cidrBlock); err != nil {
273+
allErrs = append(allErrs, field.Invalid(field.NewPath("spec", "network", fmt.Sprintf("nodePortIngressRuleCidrBlocks[%d]", cidrBlockIndex)), r.Spec.NetworkSpec.NodePortIngressRuleCidrBlocks, "CIDR block is invalid"))
274+
}
275+
}
276+
270277
if r.Spec.NetworkSpec.VPC.ElasticIPPool != nil {
271278
eipp := r.Spec.NetworkSpec.VPC.ElasticIPPool
272279
if eipp.PublicIpv4Pool != nil {

api/v1beta2/awscluster_webhook_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,28 @@ func TestAWSClusterValidateCreate(t *testing.T) {
638638
},
639639
wantErr: false,
640640
},
641+
{
642+
name: "accepts cidrBlock for default node port ingress rule",
643+
cluster: &AWSCluster{
644+
Spec: AWSClusterSpec{
645+
NetworkSpec: NetworkSpec{
646+
NodePortIngressRuleCidrBlocks: []string{"10.0.0.0/16"},
647+
},
648+
},
649+
},
650+
wantErr: false,
651+
},
652+
{
653+
name: "reject invalid cidrBlock for default node port ingress rule",
654+
cluster: &AWSCluster{
655+
Spec: AWSClusterSpec{
656+
NetworkSpec: NetworkSpec{
657+
NodePortIngressRuleCidrBlocks: []string{"10.0.0.0"},
658+
},
659+
},
660+
},
661+
wantErr: true,
662+
},
641663
}
642664
for _, tt := range tests {
643665
t.Run(tt.name, func(t *testing.T) {

api/v1beta2/network_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,11 @@ type NetworkSpec struct {
351351
// AdditionalControlPlaneIngressRules is an optional set of ingress rules to add to the control plane
352352
// +optional
353353
AdditionalControlPlaneIngressRules []IngressRule `json:"additionalControlPlaneIngressRules,omitempty"`
354+
355+
// NodePortIngressRuleCidrBlocks is an optional set of CIDR blocks to allow traffic to nodes' NodePort services.
356+
// If none are specified here, all IPs are allowed to connect.
357+
// +optional
358+
NodePortIngressRuleCidrBlocks []string `json:"nodePortIngressRuleCidrBlocks,omitempty"`
354359
}
355360

356361
// IPv6 contains ipv6 specific settings for the network.

api/v1beta2/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/controlplane.cluster.x-k8s.io_awsmanagedcontrolplanes.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,13 @@ spec:
474474
type: object
475475
type: array
476476
type: object
477+
nodePortIngressRuleCidrBlocks:
478+
description: |-
479+
NodePortIngressRuleCidrBlocks is an optional set of CIDR blocks to allow traffic to nodes' NodePort services.
480+
If none are specified here, all IPs are allowed to connect.
481+
items:
482+
type: string
483+
type: array
477484
securityGroupOverrides:
478485
additionalProperties:
479486
type: string
@@ -2500,6 +2507,13 @@ spec:
25002507
type: object
25012508
type: array
25022509
type: object
2510+
nodePortIngressRuleCidrBlocks:
2511+
description: |-
2512+
NodePortIngressRuleCidrBlocks is an optional set of CIDR blocks to allow traffic to nodes' NodePort services.
2513+
If none are specified here, all IPs are allowed to connect.
2514+
items:
2515+
type: string
2516+
type: array
25032517
securityGroupOverrides:
25042518
additionalProperties:
25052519
type: string

config/crd/bases/infrastructure.cluster.x-k8s.io_awsclusters.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,6 +1414,13 @@ spec:
14141414
type: object
14151415
type: array
14161416
type: object
1417+
nodePortIngressRuleCidrBlocks:
1418+
description: |-
1419+
NodePortIngressRuleCidrBlocks is an optional set of CIDR blocks to allow traffic to nodes' NodePort services.
1420+
If none are specified here, all IPs are allowed to connect.
1421+
items:
1422+
type: string
1423+
type: array
14171424
securityGroupOverrides:
14181425
additionalProperties:
14191426
type: string

config/crd/bases/infrastructure.cluster.x-k8s.io_awsclustertemplates.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,13 @@ spec:
10111011
type: object
10121012
type: array
10131013
type: object
1014+
nodePortIngressRuleCidrBlocks:
1015+
description: |-
1016+
NodePortIngressRuleCidrBlocks is an optional set of CIDR blocks to allow traffic to nodes' NodePort services.
1017+
If none are specified here, all IPs are allowed to connect.
1018+
items:
1019+
type: string
1020+
type: array
10141021
securityGroupOverrides:
10151022
additionalProperties:
10161023
type: string

pkg/cloud/scope/cluster.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,3 +418,8 @@ func (s *ClusterScope) AdditionalControlPlaneIngressRules() []infrav1.IngressRul
418418
func (s *ClusterScope) UnstructuredControlPlane() (*unstructured.Unstructured, error) {
419419
return getUnstructuredControlPlane(context.TODO(), s.client, s.Cluster)
420420
}
421+
422+
// NodePortIngressRuleCidrBlocks returns the CIDR blocks for the node NodePort ingress rules.
423+
func (s *ClusterScope) NodePortIngressRuleCidrBlocks() []string {
424+
return s.AWSCluster.Spec.NetworkSpec.DeepCopy().NodePortIngressRuleCidrBlocks
425+
}

0 commit comments

Comments
 (0)