-
Notifications
You must be signed in to change notification settings - Fork 495
OCPBUGS-85243: Set aws-load-balancer-scheme on public HCP router service #8458
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,8 @@ package ingress | |
| import ( | ||
| "testing" | ||
|
|
||
| . "github.com/onsi/gomega" | ||
|
|
||
| hyperv1 "github.com/openshift/hypershift/api/hypershift/v1beta1" | ||
| "github.com/openshift/hypershift/support/netutil" | ||
|
|
||
|
|
@@ -56,6 +58,69 @@ func TestReconcileRouterServiceAnnotations(t *testing.T) { | |
| } | ||
| } | ||
|
|
||
| // When reconciling an external (non-internal) AWS router service | ||
| // it should set aws-load-balancer-scheme to internet-facing. | ||
| func TestReconcileRouterService_WhenExternalAWS_ItShouldSetInternetFacingScheme(t *testing.T) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Good test -- gomega + Gherkin naming, positive and negative assertions. Consider adding a complementary subtest that pre-populates the conflicting annotation to verify cleanup: t.Run("When switching from internal to external it should remove the internal annotation", func(t *testing.T) {
g := NewGomegaWithT(t)
svc := &corev1.Service{}
svc.Annotations = map[string]string{
"service.beta.kubernetes.io/aws-load-balancer-internal": "true",
}
err := ReconcileRouterService(svc, false, true, hcp)
g.Expect(err).ToNot(HaveOccurred())
g.Expect(svc.Annotations).To(HaveKeyWithValue(
"service.beta.kubernetes.io/aws-load-balancer-scheme", "internet-facing"))
g.Expect(svc.Annotations).ToNot(HaveKey(
"service.beta.kubernetes.io/aws-load-balancer-internal"))
})This would pair with the defensive
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a test case for the switching back and forth. |
||
| g := NewGomegaWithT(t) | ||
|
|
||
| hcp := &hyperv1.HostedControlPlane{} | ||
| hcp.Spec.Platform.Type = hyperv1.AWSPlatform | ||
|
|
||
| svc := &corev1.Service{} | ||
|
|
||
| err := ReconcileRouterService(svc, false /* internal */, true /* cross-zone */, hcp) | ||
| g.Expect(err).ToNot(HaveOccurred()) | ||
|
|
||
| g.Expect(svc.Annotations).To(HaveKeyWithValue( | ||
| "service.beta.kubernetes.io/aws-load-balancer-scheme", "internet-facing")) | ||
| g.Expect(svc.Annotations).ToNot(HaveKey( | ||
| "service.beta.kubernetes.io/aws-load-balancer-internal")) | ||
| } | ||
|
|
||
| func TestReconcileRouterService_WhenSwitchingMode_ItShouldRemoveConflictingAnnotation(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| internal bool | ||
| preExisting map[string]string | ||
| expectKey string | ||
| expectValue string | ||
| expectAbsent string | ||
| }{ | ||
| { | ||
| name: "When switching from internal to external it should remove the internal annotation", | ||
| internal: false, | ||
| preExisting: map[string]string{"service.beta.kubernetes.io/aws-load-balancer-internal": "true"}, | ||
| expectKey: "service.beta.kubernetes.io/aws-load-balancer-scheme", | ||
| expectValue: "internet-facing", | ||
| expectAbsent: "service.beta.kubernetes.io/aws-load-balancer-internal", | ||
| }, | ||
| { | ||
| name: "When switching from external to internal it should remove the scheme annotation", | ||
| internal: true, | ||
| preExisting: map[string]string{"service.beta.kubernetes.io/aws-load-balancer-scheme": "internet-facing"}, | ||
| expectKey: "service.beta.kubernetes.io/aws-load-balancer-internal", | ||
| expectValue: "true", | ||
| expectAbsent: "service.beta.kubernetes.io/aws-load-balancer-scheme", | ||
| }, | ||
| } | ||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| g := NewGomegaWithT(t) | ||
|
|
||
| hcp := &hyperv1.HostedControlPlane{} | ||
| hcp.Spec.Platform.Type = hyperv1.AWSPlatform | ||
|
|
||
| svc := &corev1.Service{} | ||
| svc.Annotations = tt.preExisting | ||
|
|
||
| err := ReconcileRouterService(svc, tt.internal, true /* cross-zone */, hcp) | ||
| g.Expect(err).ToNot(HaveOccurred()) | ||
| g.Expect(svc.Annotations).To(HaveKeyWithValue(tt.expectKey, tt.expectValue)) | ||
| g.Expect(svc.Annotations).ToNot(HaveKey(tt.expectAbsent)) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| // Test that LoadBalancerSourceRanges is applied for external router services with allowedCIDRBlocks | ||
| func TestReconcileRouterService_AppliesLoadBalancerSourceRanges(t *testing.T) { | ||
| // Test case 1: External router service should have LoadBalancerSourceRanges set | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (non-blocking): The PR description mentions "clean up mutually exclusive annotations" but the production code only adds -- it never deletes the conflicting annotation. While the current architecture uses separate Service objects for public/private (so the transition scenario can't happen today), defensive cleanup costs nothing and follows the pattern already used in
oauth/service.go:77:This would also make the code match what the
infra_test.gofixture helper already expects (theprivateServicehelper doesdelete(s.Annotations, "...scheme")).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, thanks! Updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 thanks both