diff --git a/.python-version b/.python-version new file mode 100644 index 0000000000..bd28b9c5c2 --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +3.9 diff --git a/pkg/deploy/elbv2/target_group_binding_manager.go b/pkg/deploy/elbv2/target_group_binding_manager.go index 7081fbb2ed..b8db710f28 100644 --- a/pkg/deploy/elbv2/target_group_binding_manager.go +++ b/pkg/deploy/elbv2/target_group_binding_manager.go @@ -187,6 +187,7 @@ func buildK8sTargetGroupBindingSpec(ctx context.Context, resTGB *elbv2model.Targ } k8sTGBSpec.NodeSelector = resTGB.Spec.Template.Spec.NodeSelector k8sTGBSpec.IPAddressType = resTGB.Spec.Template.Spec.IPAddressType + k8sTGBSpec.VpcId = resTGB.Spec.Template.Spec.VpcId return k8sTGBSpec, nil } diff --git a/pkg/ingress/model_build_target_group.go b/pkg/ingress/model_build_target_group.go index b855efb291..87b8b7ca92 100644 --- a/pkg/ingress/model_build_target_group.go +++ b/pkg/ingress/model_build_target_group.go @@ -77,6 +77,7 @@ func (t *defaultModelBuildTask) buildTargetGroupBindingSpec(ctx context.Context, Networking: tgbNetworking, NodeSelector: nodeSelector, IPAddressType: (*elbv2api.TargetGroupIPAddressType)(tg.Spec.IPAddressType), + VpcId: t.vpcID, }, }, } diff --git a/pkg/ingress/model_builder_test.go b/pkg/ingress/model_builder_test.go index f82ceac325..80db2120da 100644 --- a/pkg/ingress/model_builder_test.go +++ b/pkg/ingress/model_builder_test.go @@ -308,6 +308,7 @@ const baseStackJSON = ` "$ref":"#/resources/AWS::ElasticLoadBalancingV2::TargetGroup/ns-1/ing-1-svc-1:http/status/targetGroupARN" }, "targetType":"instance", + "vpcId": "vpc-dummy", "ipAddressType":"ipv4", "serviceRef":{ "name":"svc-1", @@ -350,6 +351,7 @@ const baseStackJSON = ` }, "targetType":"instance", "ipAddressType":"ipv4", + "vpcId": "vpc-dummy", "serviceRef":{ "name":"svc-2", "port":"http" @@ -390,6 +392,7 @@ const baseStackJSON = ` "$ref":"#/resources/AWS::ElasticLoadBalancingV2::TargetGroup/ns-1/ing-1-svc-3:https/status/targetGroupARN" }, "targetType":"ip", + "vpcId": "vpc-dummy", "ipAddressType":"ipv4", "serviceRef":{ "name":"svc-3", @@ -1131,7 +1134,7 @@ func Test_defaultModelBuilder_Build(t *testing.T) { "port": 443, "protocol": "HTTPS", "sslPolicy": "ELBSecurityPolicy-2016-08", - "mutualAuthentication" : { + "mutualAuthentication" : { "mode" : "off" } } @@ -1442,6 +1445,7 @@ func Test_defaultModelBuilder_Build(t *testing.T) { }, "spec": { "ipAddressType": "ipv4", + "vpcId": "vpc-dummy", "networking": { "ingress": [ { @@ -2429,6 +2433,7 @@ func Test_defaultModelBuilder_Build(t *testing.T) { }, "spec": { "ipAddressType": "ipv6", + "vpcId": "vpc-dummy", "networking": { "ingress": [ { @@ -2695,6 +2700,7 @@ func Test_defaultModelBuilder_Build(t *testing.T) { }, "spec": { "ipAddressType": "ipv4", + "vpcId": "vpc-dummy", "networking": { "ingress": [ { @@ -2854,6 +2860,7 @@ func Test_defaultModelBuilder_Build(t *testing.T) { }, "spec": { "ipAddressType": "ipv4", + "vpcId": "vpc-dummy", "networking": { "ingress": [ { diff --git a/pkg/model/elbv2/target_group_binding.go b/pkg/model/elbv2/target_group_binding.go index 9399476143..4641cf6bad 100644 --- a/pkg/model/elbv2/target_group_binding.go +++ b/pkg/model/elbv2/target_group_binding.go @@ -103,6 +103,10 @@ type TargetGroupBindingSpec struct { // ipAddressType specifies whether the target group is of type IPv4 or IPv6. If unspecified, it will be automatically inferred. // +optional IPAddressType *elbv2api.TargetGroupIPAddressType `json:"ipAddressType,omitempty"` + + // VpcId is the VPC of the TargetGroup. If unspecified, it will be automatically inferred. + // +optional + VpcId string `json:"vpcId,omitempty"` } // Template for TargetGroupBinding Custom Resource. diff --git a/pkg/service/model_build_target_group.go b/pkg/service/model_build_target_group.go index f03991cb0b..5575e210fe 100644 --- a/pkg/service/model_build_target_group.go +++ b/pkg/service/model_build_target_group.go @@ -444,6 +444,7 @@ func (t *defaultModelBuildTask) buildTargetGroupBindingSpec(ctx context.Context, Networking: tgbNetworking, NodeSelector: nodeSelector, IPAddressType: (*elbv2api.TargetGroupIPAddressType)(targetGroup.Spec.IPAddressType), + VpcId: t.vpcID, }, }, }, nil diff --git a/pkg/service/model_builder_test.go b/pkg/service/model_builder_test.go index 3bbe57fcf0..39eefa0942 100644 --- a/pkg/service/model_builder_test.go +++ b/pkg/service/model_builder_test.go @@ -233,6 +233,7 @@ func Test_defaultModelBuilderTask_Build(t *testing.T) { }, "targetType":"ip", "ipAddressType":"ipv4", + "vpcId": "vpc-xxx", "serviceRef":{ "name":"nlb-ip-svc-tls", "port":80 @@ -380,6 +381,7 @@ func Test_defaultModelBuilderTask_Build(t *testing.T) { }, "targetType":"ip", "ipAddressType":"ipv4", + "vpcId": "vpc-xxx", "serviceRef":{ "name":"nlb-ip-svc-tls", "port":80 @@ -598,6 +600,7 @@ func Test_defaultModelBuilderTask_Build(t *testing.T) { }, "targetType":"ip", "ipAddressType":"ipv4", + "vpcId": "vpc-xxx", "serviceRef":{ "name":"nlb-ip-svc", "port":80 @@ -664,6 +667,7 @@ func Test_defaultModelBuilderTask_Build(t *testing.T) { }, "targetType":"ip", "ipAddressType":"ipv4", + "vpcId": "vpc-xxx", "serviceRef":{ "name":"nlb-ip-svc", "port":83 @@ -942,6 +946,7 @@ func Test_defaultModelBuilderTask_Build(t *testing.T) { "$ref":"#/resources/AWS::ElasticLoadBalancingV2::TargetGroup/default/nlb-ip-svc-tls:80/status/targetGroupARN" }, "targetType":"ip", + "vpcId": "vpc-xxx", "ipAddressType":"ipv4", "serviceRef":{ "name":"nlb-ip-svc-tls", @@ -994,6 +999,7 @@ func Test_defaultModelBuilderTask_Build(t *testing.T) { }, "targetType":"ip", "ipAddressType":"ipv4", + "vpcId": "vpc-xxx", "serviceRef":{ "name":"nlb-ip-svc-tls", "port":83 @@ -1276,6 +1282,7 @@ func Test_defaultModelBuilderTask_Build(t *testing.T) { }, "targetType":"instance", "ipAddressType":"ipv4", + "vpcId": "vpc-xxx", "serviceRef":{ "name":"instance-mode", "port":80 @@ -1317,6 +1324,7 @@ func Test_defaultModelBuilderTask_Build(t *testing.T) { }, "targetType":"instance", "ipAddressType":"ipv4", + "vpcId": "vpc-xxx", "serviceRef":{ "name":"instance-mode", "port":83 @@ -1554,6 +1562,7 @@ func Test_defaultModelBuilderTask_Build(t *testing.T) { "$ref":"#/resources/AWS::ElasticLoadBalancingV2::TargetGroup/app/traffic-local:80/status/targetGroupARN" }, "targetType":"instance", + "vpcId": "vpc-xxx", "ipAddressType":"ipv4", "serviceRef":{ "name":"traffic-local", @@ -1626,6 +1635,7 @@ func Test_defaultModelBuilderTask_Build(t *testing.T) { }, "targetType":"instance", "ipAddressType":"ipv4", + "vpcId": "vpc-xxx", "serviceRef":{ "name":"traffic-local", "port":83 @@ -1815,6 +1825,7 @@ func Test_defaultModelBuilderTask_Build(t *testing.T) { }, "targetType":"ip", "ipAddressType":"ipv4", + "vpcId": "vpc-xxx", "serviceRef":{ "name":"nlb-ip-svc-tls", "port":80 @@ -1935,6 +1946,7 @@ func Test_defaultModelBuilderTask_Build(t *testing.T) { "spec": { "targetType": "ip", "ipAddressType":"ipv4", + "vpcId": "vpc-xxx", "targetGroupARN": { "$ref": "#/resources/AWS::ElasticLoadBalancingV2::TargetGroup/default/ip-target:80/status/targetGroupARN" }, @@ -2108,6 +2120,7 @@ func Test_defaultModelBuilderTask_Build(t *testing.T) { "spec": { "targetType": "ip", "ipAddressType":"ipv4", + "vpcId": "vpc-xxx", "targetGroupARN": { "$ref": "#/resources/AWS::ElasticLoadBalancingV2::TargetGroup/default/default-ip-target:80/status/targetGroupARN" }, @@ -2473,6 +2486,7 @@ func Test_defaultModelBuilderTask_Build(t *testing.T) { "$ref": "#/resources/AWS::ElasticLoadBalancingV2::TargetGroup/default/traffic-local:80/status/targetGroupARN" }, "targetType": "instance", + "vpcId": "vpc-xxx", "serviceRef": { "name": "traffic-local", "port": 80 @@ -2622,6 +2636,8 @@ func Test_defaultModelBuilderTask_Build(t *testing.T) { "$ref": "#/resources/AWS::ElasticLoadBalancingV2::TargetGroup/default/traffic-local:80/status/targetGroupARN" }, "targetType": "instance", + "vpcId": "vpc-xxx", + "vpcId": "vpc-xxx", "serviceRef": { "name": "traffic-local", "port": 80 @@ -2824,6 +2840,7 @@ func Test_defaultModelBuilderTask_Build(t *testing.T) { "$ref": "#/resources/AWS::ElasticLoadBalancingV2::TargetGroup/awesome/lb-with-class:80/status/targetGroupARN" }, "targetType": "instance", + "vpcId": "vpc-xxx", "serviceRef": { "name": "lb-with-class", "port": 80 @@ -2992,6 +3009,7 @@ func Test_defaultModelBuilderTask_Build(t *testing.T) { }, "targetType":"ip", "ipAddressType":"ipv4", + "vpcId": "vpc-xxx", "serviceRef":{ "name":"manual-sg-rule", "port":80 @@ -3145,6 +3163,7 @@ func Test_defaultModelBuilderTask_Build(t *testing.T) { }, "targetType":"ip", "ipAddressType":"ipv4", + "vpcId": "vpc-xxx", "serviceRef":{ "name":"nlb-ip-svc-tls", "port":80 @@ -3326,6 +3345,7 @@ func Test_defaultModelBuilderTask_Build(t *testing.T) { "$ref":"#/resources/AWS::ElasticLoadBalancingV2::TargetGroup/default/nlb-ip-svc-tls:80/status/targetGroupARN" }, "targetType":"ip", + "vpcId": "vpc-xxx", "ipAddressType":"ipv4", "serviceRef":{ "name":"nlb-ip-svc-tls", @@ -3580,6 +3600,7 @@ func Test_defaultModelBuilderTask_Build(t *testing.T) { }, "targetType":"ip", "ipAddressType":"ipv4", + "vpcId": "vpc-xxx", "serviceRef":{ "name":"nlb-ip-svc", "port":80 @@ -3624,6 +3645,7 @@ func Test_defaultModelBuilderTask_Build(t *testing.T) { "$ref":"#/resources/AWS::ElasticLoadBalancingV2::TargetGroup/default/nlb-ip-svc:83/status/targetGroupARN" }, "targetType":"ip", + "vpcId": "vpc-xxx", "ipAddressType":"ipv4", "serviceRef":{ "name":"nlb-ip-svc", @@ -3917,6 +3939,7 @@ func Test_defaultModelBuilderTask_Build(t *testing.T) { "$ref":"#/resources/AWS::ElasticLoadBalancingV2::TargetGroup/default/nlb-ip-svc-tls:80/status/targetGroupARN" }, "targetType":"ip", + "vpcId": "vpc-xxx", "ipAddressType":"ipv4", "serviceRef":{ "name":"nlb-ip-svc-tls", @@ -3958,6 +3981,7 @@ func Test_defaultModelBuilderTask_Build(t *testing.T) { "$ref":"#/resources/AWS::ElasticLoadBalancingV2::TargetGroup/default/nlb-ip-svc-tls:83/status/targetGroupARN" }, "targetType":"ip", + "vpcId": "vpc-xxx", "ipAddressType":"ipv4", "serviceRef":{ "name":"nlb-ip-svc-tls", @@ -4220,6 +4244,7 @@ func Test_defaultModelBuilderTask_Build(t *testing.T) { }, "targetType":"instance", "ipAddressType":"ipv4", + "vpcId": "vpc-xxx", "serviceRef":{ "name":"instance-mode", "port":80 @@ -4262,6 +4287,7 @@ func Test_defaultModelBuilderTask_Build(t *testing.T) { }, "targetType":"instance", "ipAddressType":"ipv4", + "vpcId": "vpc-xxx", "serviceRef":{ "name":"instance-mode", "port":83 @@ -4557,6 +4583,7 @@ func Test_defaultModelBuilderTask_Build(t *testing.T) { "$ref":"#/resources/AWS::ElasticLoadBalancingV2::TargetGroup/app/traffic-local:80/status/targetGroupARN" }, "targetType":"instance", + "vpcId": "vpc-xxx", "ipAddressType":"ipv4", "serviceRef":{ "name":"traffic-local", @@ -4605,6 +4632,7 @@ func Test_defaultModelBuilderTask_Build(t *testing.T) { }, "targetType":"instance", "ipAddressType":"ipv4", + "vpcId": "vpc-xxx", "serviceRef":{ "name":"traffic-local", "port":83 @@ -4906,6 +4934,7 @@ func Test_defaultModelBuilderTask_Build(t *testing.T) { }, "targetType":"instance", "ipAddressType":"ipv4", + "vpcId": "vpc-xxx", "serviceRef":{ "name":"traffic-local", "port":80 @@ -4953,6 +4982,7 @@ func Test_defaultModelBuilderTask_Build(t *testing.T) { }, "targetType":"instance", "ipAddressType":"ipv4", + "vpcId": "vpc-xxx", "serviceRef":{ "name":"traffic-local", "port":83 @@ -5135,6 +5165,7 @@ func Test_defaultModelBuilderTask_Build(t *testing.T) { "$ref":"#/resources/AWS::ElasticLoadBalancingV2::TargetGroup/default/nlb-ip-svc-tls:80/status/targetGroupARN" }, "targetType":"ip", + "vpcId": "vpc-xxx", "ipAddressType":"ipv4", "serviceRef":{ "name":"nlb-ip-svc-tls", @@ -5275,6 +5306,7 @@ func Test_defaultModelBuilderTask_Build(t *testing.T) { "spec": { "targetType": "ip", "ipAddressType":"ipv4", + "vpcId": "vpc-xxx", "targetGroupARN": { "$ref": "#/resources/AWS::ElasticLoadBalancingV2::TargetGroup/default/ip-target:80/status/targetGroupARN" }, @@ -5526,6 +5558,7 @@ func Test_defaultModelBuilderTask_Build(t *testing.T) { "$ref": "#/resources/AWS::ElasticLoadBalancingV2::TargetGroup/default/traffic-local:80/status/targetGroupARN" }, "targetType": "instance", + "vpcId": "vpc-xxx", "serviceRef": { "name": "traffic-local", "port": 80 @@ -5709,6 +5742,7 @@ func Test_defaultModelBuilderTask_Build(t *testing.T) { "$ref": "#/resources/AWS::ElasticLoadBalancingV2::TargetGroup/default/traffic-local:80/status/targetGroupARN" }, "targetType": "instance", + "vpcId": "vpc-xxx", "serviceRef": { "name": "traffic-local", "port": 80 @@ -5891,6 +5925,7 @@ func Test_defaultModelBuilderTask_Build(t *testing.T) { "$ref": "#/resources/AWS::ElasticLoadBalancingV2::TargetGroup/awesome/lb-with-class:80/status/targetGroupARN" }, "targetType": "instance", + "vpcId": "vpc-xxx", "serviceRef": { "name": "lb-with-class", "port": 80 @@ -6085,6 +6120,7 @@ func Test_defaultModelBuilderTask_Build(t *testing.T) { "$ref": "#/resources/AWS::ElasticLoadBalancingV2::TargetGroup/default/manual-security-groups:80/status/targetGroupARN" }, "targetType": "ip", + "vpcId": "vpc-xxx", "serviceRef": { "name": "manual-security-groups", "port": 80 @@ -6224,6 +6260,7 @@ func Test_defaultModelBuilderTask_Build(t *testing.T) { "$ref": "#/resources/AWS::ElasticLoadBalancingV2::TargetGroup/default/manual-security-groups:80/status/targetGroupARN" }, "targetType": "ip", + "vpcId": "vpc-xxx", "serviceRef": { "name": "manual-security-groups", "port": 80 @@ -6252,7 +6289,7 @@ func Test_defaultModelBuilderTask_Build(t *testing.T) { } } } - } + } } } `,