Skip to content

Commit 6f70423

Browse files
zac-nixonniclask25
authored and
niclask25
committed
refactor validation
1 parent 7cba6b9 commit 6f70423

File tree

4 files changed

+26
-28
lines changed

4 files changed

+26
-28
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ require (
3232
github.com/spf13/pflag v1.0.5
3333
github.com/stretchr/testify v1.10.0
3434
go.uber.org/zap v1.27.0
35+
golang.org/x/net v0.37.0
3536
golang.org/x/time v0.7.0
3637
gomodules.xyz/jsonpatch/v2 v2.4.0
37-
helm.sh/helm/v3 v3.17.2
38+
helm.sh/helm/v3 v3.17.3
3839
k8s.io/api v0.32.2
3940
k8s.io/apimachinery v0.32.2
4041
k8s.io/cli-runtime v0.32.2
@@ -172,7 +173,6 @@ require (
172173
go.uber.org/multierr v1.11.0 // indirect
173174
golang.org/x/crypto v0.36.0 // indirect
174175
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
175-
golang.org/x/net v0.37.0 // indirect
176176
golang.org/x/oauth2 v0.23.0 // indirect
177177
golang.org/x/sync v0.12.0 // indirect
178178
golang.org/x/sys v0.31.0 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,8 +595,8 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
595595
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
596596
gotest.tools/v3 v3.4.0 h1:ZazjZUfuVeZGLAmlKKuyv3IKP5orXcwtOwDQH6YVr6o=
597597
gotest.tools/v3 v3.4.0/go.mod h1:CtbdzLSsqVhDgMtKsx03ird5YTGB3ar27v0u/yKBW5g=
598-
helm.sh/helm/v3 v3.17.2 h1:agYQ5ew2jq5vdx2K7q5W44KyKQrnSubUMCQsjkiv3/o=
599-
helm.sh/helm/v3 v3.17.2/go.mod h1:+uJKMH/UiMzZQOALR3XUf3BLIoczI2RKKD6bMhPh4G8=
598+
helm.sh/helm/v3 v3.17.3 h1:3n5rW3D0ArjFl0p4/oWO8IbY/HKaNNwJtOQFdH2AZHg=
599+
helm.sh/helm/v3 v3.17.3/go.mod h1:+uJKMH/UiMzZQOALR3XUf3BLIoczI2RKKD6bMhPh4G8=
600600
k8s.io/api v0.32.2 h1:bZrMLEkgizC24G9eViHGOPbW+aRo9duEISRIJKfdJuw=
601601
k8s.io/api v0.32.2/go.mod h1:hKlhk4x1sJyYnHENsrdCWw31FEmCijNGPJO5WzHiJ6Y=
602602
k8s.io/apiextensions-apiserver v0.32.2 h1:2YMk285jWMk2188V2AERy5yDwBYrjgWYggscghPCvV4=

pkg/gateway/model/model_build_subnet.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -105,28 +105,6 @@ func (subnetBuilder *subnetModelBuilderImpl) validateSubnetsInput(subnetConfigsP
105105
privateIPv4AllocationSpecified := subnetsConfig[0].PrivateIPv4Allocation != nil
106106
sourceNATSpecified := subnetsConfig[0].SourceNatIPv6Prefix != nil
107107

108-
for _, subnetConfig := range subnetsConfig {
109-
if (subnetConfig.Identifier != "") != identifierSpecified {
110-
return false, errors.Errorf("Either specify all subnet identifiers or none.")
111-
}
112-
113-
if (subnetConfig.EIPAllocation != nil) != eipAllocationSpecified {
114-
return false, errors.Errorf("Either specify all eip allocations or none.")
115-
}
116-
117-
if (subnetConfig.IPv6Allocation != nil) != ipv6AllocationSpecified {
118-
return false, errors.Errorf("Either specify all ipv6 allocations or none.")
119-
}
120-
121-
if (subnetConfig.PrivateIPv4Allocation != nil) != privateIPv4AllocationSpecified {
122-
return false, errors.Errorf("Either specify all private ipv4 allocations or none.")
123-
}
124-
125-
if (subnetConfig.SourceNatIPv6Prefix != nil) != sourceNATSpecified {
126-
return false, errors.Errorf("Either specify all source nat prefixes or none.")
127-
}
128-
}
129-
130108
if eipAllocationSpecified {
131109
if subnetBuilder.loadBalancerType != elbv2model.LoadBalancerTypeNetwork {
132110
return false, errors.Errorf("EIP Allocation is only allowed for Network LoadBalancers")
@@ -163,6 +141,28 @@ func (subnetBuilder *subnetModelBuilderImpl) validateSubnetsInput(subnetConfigsP
163141
}
164142
}
165143

144+
for _, subnetConfig := range subnetsConfig {
145+
if (subnetConfig.Identifier != "") != identifierSpecified {
146+
return false, errors.Errorf("Either specify all subnet identifiers or none.")
147+
}
148+
149+
if (subnetConfig.EIPAllocation != nil) != eipAllocationSpecified {
150+
return false, errors.Errorf("Either specify all eip allocations or none.")
151+
}
152+
153+
if (subnetConfig.IPv6Allocation != nil) != ipv6AllocationSpecified {
154+
return false, errors.Errorf("Either specify all ipv6 allocations or none.")
155+
}
156+
157+
if (subnetConfig.PrivateIPv4Allocation != nil) != privateIPv4AllocationSpecified {
158+
return false, errors.Errorf("Either specify all private ipv4 allocations or none.")
159+
}
160+
161+
if (subnetConfig.SourceNatIPv6Prefix != nil) != sourceNATSpecified {
162+
return false, errors.Errorf("Either specify all source nat prefixes or none.")
163+
}
164+
}
165+
166166
return sourceNATSpecified, nil
167167
}
168168

pkg/gateway/model/subnet/eip_mutator.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package subnet
22

33
import (
4-
"fmt"
54
ec2types "github.com/aws/aws-sdk-go-v2/service/ec2/types"
65
"github.com/pkg/errors"
76
elbv2gw "sigs.k8s.io/aws-load-balancer-controller/apis/gateway/v1beta1"
@@ -27,7 +26,6 @@ func (mutator *eipMutator) Mutate(elbSubnets []*elbv2model.SubnetMapping, _ []ec
2726
}
2827

2928
for i, elbSubnet := range elbSubnets {
30-
fmt.Println("HERE!")
3129
elbSubnet.AllocationID = subnetConfig[i].EIPAllocation
3230
}
3331
return nil

0 commit comments

Comments
 (0)