Skip to content

Commit 6cfbaf0

Browse files
zac-nixonshraddhabang
authored andcommitted
refactor validation
1 parent 112c72e commit 6cfbaf0

File tree

2 files changed

+22
-24
lines changed

2 files changed

+22
-24
lines changed

pkg/gateway/model/model_build_subnet.go

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

116-
for _, subnetConfig := range subnetsConfig {
117-
if (subnetConfig.Identifier != "") != identifierSpecified {
118-
return false, errors.Errorf("Either specify all subnet identifiers or none.")
119-
}
120-
121-
if (subnetConfig.EIPAllocation != nil) != eipAllocationSpecified {
122-
return false, errors.Errorf("Either specify all eip allocations or none.")
123-
}
124-
125-
if (subnetConfig.IPv6Allocation != nil) != ipv6AllocationSpecified {
126-
return false, errors.Errorf("Either specify all ipv6 allocations or none.")
127-
}
128-
129-
if (subnetConfig.PrivateIPv4Allocation != nil) != privateIPv4AllocationSpecified {
130-
return false, errors.Errorf("Either specify all private ipv4 allocations or none.")
131-
}
132-
133-
if (subnetConfig.SourceNatIPv6Prefix != nil) != sourceNATSpecified {
134-
return false, errors.Errorf("Either specify all source nat prefixes or none.")
135-
}
136-
}
137-
138116
if eipAllocationSpecified {
139117
if subnetBuilder.loadBalancerType != elbv2model.LoadBalancerTypeNetwork {
140118
return false, errors.Errorf("EIP Allocation is only allowed for Network LoadBalancers")
@@ -171,6 +149,28 @@ func (subnetBuilder *subnetModelBuilderImpl) validateSubnetsInput(subnetConfigsP
171149
}
172150
}
173151

152+
for _, subnetConfig := range subnetsConfig {
153+
if (subnetConfig.Identifier != "") != identifierSpecified {
154+
return false, errors.Errorf("Either specify all subnet identifiers or none.")
155+
}
156+
157+
if (subnetConfig.EIPAllocation != nil) != eipAllocationSpecified {
158+
return false, errors.Errorf("Either specify all eip allocations or none.")
159+
}
160+
161+
if (subnetConfig.IPv6Allocation != nil) != ipv6AllocationSpecified {
162+
return false, errors.Errorf("Either specify all ipv6 allocations or none.")
163+
}
164+
165+
if (subnetConfig.PrivateIPv4Allocation != nil) != privateIPv4AllocationSpecified {
166+
return false, errors.Errorf("Either specify all private ipv4 allocations or none.")
167+
}
168+
169+
if (subnetConfig.SourceNatIPv6Prefix != nil) != sourceNATSpecified {
170+
return false, errors.Errorf("Either specify all source nat prefixes or none.")
171+
}
172+
}
173+
174174
return sourceNATSpecified, nil
175175
}
176176

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)