Skip to content

Commit 8050e6e

Browse files
committed
fix(aws): set aws-load-balancer-scheme on public HCP router service
The AWS Load Balancer Controller (used on EKS) defaults to scheme=internal when the aws-load-balancer-scheme annotation is not set, while the in-tree AWS cloud provider (used on OpenShift) defaults to internet-facing. This causes the public HCP router NLB to be created as internal on EKS, making KAS and OAuth unreachable from outside the VPC for PublicAndPrivate clusters. Set the annotation explicitly on the public router service so it works on both OpenShift and EKS management clusters. Also clean up mutually exclusive annotations (aws-load-balancer-internal vs aws-load-balancer-scheme) when switching between internal and external. Signed-off-by: Claudio Busse <cbusse@redhat.com> Commit-Message-Assisted-by: Claude (via Claude Code)
1 parent 2fc8a13 commit 8050e6e

5 files changed

Lines changed: 31 additions & 1 deletion

File tree

control-plane-operator/controllers/hostedcontrolplane/infra/infra_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1471,7 +1471,8 @@ func TestReconcileHCPRouterServices(t *testing.T) {
14711471
Name: "router",
14721472
Namespace: namespace,
14731473
Annotations: map[string]string{
1474-
"service.beta.kubernetes.io/aws-load-balancer-type": "nlb",
1474+
"service.beta.kubernetes.io/aws-load-balancer-type": "nlb",
1475+
"service.beta.kubernetes.io/aws-load-balancer-scheme": "internet-facing",
14751476
},
14761477
Labels: map[string]string{"app": "private-router"},
14771478
},
@@ -1493,6 +1494,7 @@ func TestReconcileHCPRouterServices(t *testing.T) {
14931494
return publicService(append(m, func(s *corev1.Service) {
14941495
s.Name = "private-router"
14951496
s.Annotations["service.beta.kubernetes.io/aws-load-balancer-internal"] = "true"
1497+
delete(s.Annotations, "service.beta.kubernetes.io/aws-load-balancer-scheme")
14961498
})...)
14971499
}
14981500
withCrossZoneAnnotation := func(svc *corev1.Service) {

control-plane-operator/controllers/hostedcontrolplane/infra/testdata/zz_fixture_TestReconcileInfrastructure_AWS_PublicAndPrivate_Route.yaml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

control-plane-operator/controllers/hostedcontrolplane/infra/testdata/zz_fixture_TestReconcileInfrastructure_AWS_Public_Route.yaml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

control-plane-operator/controllers/hostedcontrolplane/ingress/router.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ func ReconcileRouterService(svc *corev1.Service, internal, crossZoneLoadBalancin
2929
svc.Annotations["service.beta.kubernetes.io/aws-load-balancer-type"] = "nlb"
3030
if internal {
3131
svc.Annotations["service.beta.kubernetes.io/aws-load-balancer-internal"] = "true"
32+
} else {
33+
// The AWS Load Balancer Controller (used on EKS) defaults to scheme=internal.
34+
// The in-tree AWS cloud provider (used on OpenShift) defaults to internet-facing.
35+
// Set the annotation explicitly so the public router works on both.
36+
svc.Annotations["service.beta.kubernetes.io/aws-load-balancer-scheme"] = "internet-facing"
3237
}
3338
if crossZoneLoadBalancingEnabled {
3439
// In-tree AWS cloud provider annotation for cross-zone load balancing (OpenShift management clusters).

control-plane-operator/controllers/hostedcontrolplane/ingress/router_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package ingress
33
import (
44
"testing"
55

6+
. "github.com/onsi/gomega"
7+
68
hyperv1 "github.com/openshift/hypershift/api/hypershift/v1beta1"
79
"github.com/openshift/hypershift/support/netutil"
810

@@ -56,6 +58,25 @@ func TestReconcileRouterServiceAnnotations(t *testing.T) {
5658
}
5759
}
5860

61+
// When reconciling an external (non-internal) AWS router service
62+
// it should set aws-load-balancer-scheme to internet-facing.
63+
func TestReconcileRouterService_WhenExternalAWS_ItShouldSetInternetFacingScheme(t *testing.T) {
64+
g := NewGomegaWithT(t)
65+
66+
hcp := &hyperv1.HostedControlPlane{}
67+
hcp.Spec.Platform.Type = hyperv1.AWSPlatform
68+
69+
svc := &corev1.Service{}
70+
71+
err := ReconcileRouterService(svc, false /* internal */, true /* cross-zone */, hcp)
72+
g.Expect(err).ToNot(HaveOccurred())
73+
74+
g.Expect(svc.Annotations).To(HaveKeyWithValue(
75+
"service.beta.kubernetes.io/aws-load-balancer-scheme", "internet-facing"))
76+
g.Expect(svc.Annotations).ToNot(HaveKey(
77+
"service.beta.kubernetes.io/aws-load-balancer-internal"))
78+
}
79+
5980
// Test that LoadBalancerSourceRanges is applied for external router services with allowedCIDRBlocks
6081
func TestReconcileRouterService_AppliesLoadBalancerSourceRanges(t *testing.T) {
6182
// Test case 1: External router service should have LoadBalancerSourceRanges set

0 commit comments

Comments
 (0)