Skip to content

Commit

Permalink
Add unit tests to verify update of Infra CR with Ingress LB IPs
Browse files Browse the repository at this point in the history
Add tests for the AWS Platform where the Ingress LB's Hostname is
available but the Infra CR needs to be updated with its IP.
  • Loading branch information
sadasu committed Nov 21, 2024
1 parent f35a247 commit 90693b7
Showing 1 changed file with 60 additions and 5 deletions.
65 changes: 60 additions & 5 deletions pkg/operator/controller/ingress/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1617,9 +1617,34 @@ func Test_IsProxyProtocolNeeded(t *testing.T) {

func Test_computeUpdatedInfraFromService(t *testing.T) {
var (
IngressLBIP = configv1.IP("196.78.125.4")
awsPlatform = configv1.PlatformStatus{
Type: configv1.AWSPlatformType,
}
awsPlatformWithDNSType = configv1.PlatformStatus{
Type: configv1.AWSPlatformType,
AWS: &configv1.AWSPlatformStatus{
CloudLoadBalancerConfig: &configv1.CloudLoadBalancerConfig{
DNSType: configv1.ClusterHostedDNSType,
},
},
}
awsPlatformWithLBIP = configv1.PlatformStatus{
Type: configv1.AWSPlatformType,
AWS: &configv1.AWSPlatformStatus{
CloudLoadBalancerConfig: &configv1.CloudLoadBalancerConfig{
DNSType: configv1.ClusterHostedDNSType,
ClusterHosted: &configv1.CloudLoadBalancerIPs{
IngressLoadBalancerIPs: []configv1.IP{
IngressLBIP,
},
},
},
},
}
azurePlatform = configv1.PlatformStatus{
Type: configv1.AzurePlatformType,
}
gcpPlatform = configv1.PlatformStatus{
Type: configv1.GCPPlatformType,
}
Expand All @@ -1631,10 +1656,6 @@ func Test_computeUpdatedInfraFromService(t *testing.T) {
},
},
}
ingresses = []corev1.LoadBalancerIngress{
{IP: "196.78.125.4"},
}
IngressLBIP = configv1.IP("196.78.125.4")
gcpPlatformWithLBIP = configv1.PlatformStatus{
Type: configv1.GCPPlatformType,
GCP: &configv1.GCPPlatformStatus{
Expand All @@ -1648,10 +1669,16 @@ func Test_computeUpdatedInfraFromService(t *testing.T) {
},
},
}
ingresses = []corev1.LoadBalancerIngress{
{IP: "196.78.125.4"},
}
ingressesWithMultipleIPs = []corev1.LoadBalancerIngress{
{IP: "196.78.125.4"},
{IP: "10.10.10.4"},
}
awsIngresses = []corev1.LoadBalancerIngress{
{Hostname: "196.78.125.4"},
}
)
testCases := []struct {
description string
Expand All @@ -1670,7 +1697,7 @@ func Test_computeUpdatedInfraFromService(t *testing.T) {
},
{
description: "unsupported platform should not cause an error",
platform: &awsPlatform,
platform: &azurePlatform,
ingresses: []corev1.LoadBalancerIngress{},
expectUpdated: false,
expectError: false,
Expand Down Expand Up @@ -1710,6 +1737,34 @@ func Test_computeUpdatedInfraFromService(t *testing.T) {
expectUpdated: true,
expectError: false,
},
{
description: "aws platform without DNSType set",
platform: &awsPlatform,
ingresses: []corev1.LoadBalancerIngress{},
expectUpdated: false,
expectError: false,
},
{
description: "aws platform with DNSType and no LB IP",
platform: &awsPlatformWithDNSType,
ingresses: []corev1.LoadBalancerIngress{},
expectUpdated: false,
expectError: false,
},
{
description: "aws platform with DNSType and no LB IP in infra config, service has 1 IP",
platform: &awsPlatformWithDNSType,
ingresses: awsIngresses,
expectUpdated: true,
expectError: false,
},
{
description: "aws platform with no change to LB IPs",
platform: &awsPlatformWithLBIP,
ingresses: awsIngresses,
expectUpdated: false,
expectError: false,
},
}
for _, tc := range testCases {
t.Run(tc.description, func(t *testing.T) {
Expand Down

0 comments on commit 90693b7

Please sign in to comment.