Skip to content

Commit

Permalink
Attempt to address remaining errors
Browse files Browse the repository at this point in the history
  • Loading branch information
lyda committed Nov 4, 2024
1 parent 597a4a2 commit 6d10560
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 36 deletions.
27 changes: 10 additions & 17 deletions pkg/service/model_build_target_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,8 @@ func (t *defaultModelBuildTask) buildTargetGroupBindingNetworking(_ context.Cont
Protocol: &protocolTCP,
Port: &tgPort,
})
case corev1.Protocol("TCP_UDP"):
fallthrough
case corev1.ProtocolUDP:
ports = append(ports, elbv2api.NetworkingPort{
Protocol: &protocolUDP,
Expand Down Expand Up @@ -567,18 +569,19 @@ func (t *defaultModelBuildTask) buildTargetGroupBindingNetworkingLegacy(ctx cont
trafficSource := loadBalancerSubnetCIDRs
defaultRangeUsed := false
var trafficPorts []elbv2api.NetworkingPort
switch networkingProtocol {
case elbv2api.NetworkingProtocolTCP_UDP:
tcpProtocol := elbv2api.NetworkingProtocolTCP
udpProtocol := elbv2api.NetworkingProtocolUDP
if networkingProtocol == elbv2api.NetworkingProtocolUDP || t.preserveClientIP {
trafficSource = t.getLoadBalancerSourceRanges(ctx)
if len(trafficSource) == 0 {
trafficSource, err = t.getDefaultIPSourceRanges(ctx, targetGroupIPAddressType, port.Protocol, scheme)
trafficSource, err = t.getDefaultIPSourceRanges(ctx, targetGroupIPAddressType, tgProtocol, scheme)
if err != nil {
return nil, err
}
defaultRangeUsed = true
}
}
if networkingProtocol == elbv2api.NetworkingProtocolTCP_UDP {
tcpProtocol := elbv2api.NetworkingProtocolTCP
udpProtocol := elbv2api.NetworkingProtocolUDP
trafficPorts = []elbv2api.NetworkingPort{
{
Port: &tgPort,
Expand All @@ -589,17 +592,7 @@ func (t *defaultModelBuildTask) buildTargetGroupBindingNetworkingLegacy(ctx cont
Protocol: &udpProtocol,
},
}
default:
if networkingProtocol == elbv2api.NetworkingProtocolUDP || t.preserveClientIP {
trafficSource = t.getLoadBalancerSourceRanges(ctx)
if len(trafficSource) == 0 {
trafficSource, err = t.getDefaultIPSourceRanges(ctx, targetGroupIPAddressType, port.Protocol, scheme)
if err != nil {
return nil, err
}
defaultRangeUsed = true
}
}
} else {
trafficPorts = []elbv2api.NetworkingPort{
{
Port: &tgPort,
Expand Down Expand Up @@ -640,7 +633,7 @@ func (t *defaultModelBuildTask) getDefaultIPSourceRanges(ctx context.Context, ta
if targetGroupIPAddressType == elbv2model.TargetGroupIPAddressTypeIPv6 {
defaultSourceRanges = t.defaultIPv6SourceRanges
}
if (protocol == corev1.ProtocolUDP || t.preserveClientIP) && scheme == elbv2model.LoadBalancerSchemeInternal {
if (protocol == corev1.Protocol("TCP_UDP") || protocol == corev1.ProtocolUDP || t.preserveClientIP) && scheme == elbv2model.LoadBalancerSchemeInternal {
vpcInfo, err := t.vpcInfoProvider.FetchVPCInfo(ctx, t.vpcID, networking.FetchVPCInfoWithoutCache())
if err != nil {
return nil, err
Expand Down
92 changes: 73 additions & 19 deletions pkg/service/model_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package service

import (
"context"
ec2types "github.com/aws/aws-sdk-go-v2/service/ec2/types"
elbv2types "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2/types"
"testing"
"time"

ec2types "github.com/aws/aws-sdk-go-v2/service/ec2/types"
elbv2types "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2/types"

awssdk "github.com/aws/aws-sdk-go-v2/aws"
"github.com/go-logr/logr"
"github.com/golang/mock/gomock"
Expand Down Expand Up @@ -2298,6 +2299,46 @@ func Test_defaultModelBuilderTask_Build(t *testing.T) {
{
"id":"app/tcpudp-protocol",
"resources":{
"AWS::EC2::SecurityGroup":{
"ManagedLBSecurityGroup":{
"spec":{
"description":"[k8s] Managed SecurityGroup for LoadBalancer",
"groupName":"k8s-app-tcpudppr-06a9156bf8",
"ingress":[
{
"fromPort":80,
"ipProtocol":"tcp",
"ipRanges":[
{
"cidrIP":"0.0.0.0/0"
}
],
"toPort":80
},
{
"fromPort":80,
"ipProtocol":"udp",
"ipRanges":[
{
"cidrIP":"0.0.0.0/0"
}
],
"toPort":80
},
{
"fromPort":83,
"ipProtocol":"tcp",
"ipRanges":[
{
"cidrIP":"0.0.0.0/0"
}
],
"toPort":83
}
]
}
}
},
"AWS::ElasticLoadBalancingV2::Listener":{
"80":{
"spec":{
Expand Down Expand Up @@ -2352,6 +2393,11 @@ func Test_defaultModelBuilderTask_Build(t *testing.T) {
"name":"k8s-app-tcpudppr-2af705447d",
"type":"network",
"scheme":"internet-facing",
"securityGroups":[
{
"$ref":"#/resources/AWS::EC2::SecurityGroup/ManagedLBSecurityGroup/status/groupID"
}
],
"ipAddressType":"ipv4",
"subnetMapping":[
{
Expand All @@ -2378,6 +2424,7 @@ func Test_defaultModelBuilderTask_Build(t *testing.T) {
"healthCheckConfig":{
"port":"traffic-port",
"protocol":"TCP",
"timeoutSeconds":10,
"unhealthyThresholdCount":3,
"healthyThresholdCount":3,
"intervalSeconds":10
Expand All @@ -2400,6 +2447,7 @@ func Test_defaultModelBuilderTask_Build(t *testing.T) {
"healthCheckConfig":{
"port":"traffic-port",
"protocol":"TCP",
"timeoutSeconds":10,
"unhealthyThresholdCount":3,
"healthyThresholdCount":3,
"intervalSeconds":10
Expand Down Expand Up @@ -2427,6 +2475,7 @@ func Test_defaultModelBuilderTask_Build(t *testing.T) {
"$ref":"#/resources/AWS::ElasticLoadBalancingV2::TargetGroup/app/tcpudp-protocol:80/status/targetGroupARN"
},
"targetType":"instance",
"vpcID":"vpc-xxx",
"serviceRef":{
"name":"tcpudp-protocol",
"port":80
Expand All @@ -2437,18 +2486,20 @@ func Test_defaultModelBuilderTask_Build(t *testing.T) {
{
"from":[
{
"ipBlock":{
"cidr":"0.0.0.0/0"
"securityGroup": {
"groupID": {
"$ref": "#/resources/AWS::EC2::SecurityGroup/ManagedLBSecurityGroup/status/groupID"
}
}
}
],
"ports":[
{
"protocol":"TCP",
"protocol":"UDP",
"port":31223
},
{
"protocol":"UDP",
"protocol":"TCP",
"port":31223
}
]
Expand All @@ -2472,6 +2523,7 @@ func Test_defaultModelBuilderTask_Build(t *testing.T) {
"$ref":"#/resources/AWS::ElasticLoadBalancingV2::TargetGroup/app/tcpudp-protocol:83/status/targetGroupARN"
},
"targetType":"instance",
"vpcID":"vpc-xxx",
"serviceRef":{
"name":"tcpudp-protocol",
"port":83
Expand All @@ -2482,8 +2534,10 @@ func Test_defaultModelBuilderTask_Build(t *testing.T) {
{
"from":[
{
"ipBlock":{
"cidr":"0.0.0.0/0"
"securityGroup": {
"groupID": {
"$ref": "#/resources/AWS::EC2::SecurityGroup/ManagedLBSecurityGroup/status/groupID"
}
}
}
],
Expand All @@ -2504,7 +2558,7 @@ func Test_defaultModelBuilderTask_Build(t *testing.T) {
}
}
`,
wantNumResources: 7,
wantNumResources: 8,
},
{
testName: "list load balancers error",
Expand Down Expand Up @@ -3643,7 +3697,7 @@ func Test_defaultModelBuilderTask_Build(t *testing.T) {
],
"ports":[
{
"port": 80,
"port": 80,
"protocol":"TCP"
}
]
Expand Down Expand Up @@ -3897,12 +3951,12 @@ func Test_defaultModelBuilderTask_Build(t *testing.T) {
}
],
"ports":[
{
"port": 80,
{
"port": 80,
"protocol":"TCP"
},
{
"port": 8888,
{
"port": 8888,
"protocol":"TCP"
}
]
Expand Down Expand Up @@ -4538,9 +4592,9 @@ func Test_defaultModelBuilderTask_Build(t *testing.T) {
"from":[
{
"securityGroup":{
"groupID": {
"$ref": "#/resources/AWS::EC2::SecurityGroup/ManagedLBSecurityGroup/status/groupID"
}
"groupID": {
"$ref": "#/resources/AWS::EC2::SecurityGroup/ManagedLBSecurityGroup/status/groupID"
}
}
}
],
Expand Down Expand Up @@ -4582,8 +4636,8 @@ func Test_defaultModelBuilderTask_Build(t *testing.T) {
{
"securityGroup":{
"groupID": {
"$ref": "#/resources/AWS::EC2::SecurityGroup/ManagedLBSecurityGroup/status/groupID"
}
"$ref": "#/resources/AWS::EC2::SecurityGroup/ManagedLBSecurityGroup/status/groupID"
}
}
}
],
Expand Down

0 comments on commit 6d10560

Please sign in to comment.