Repository navigation
CNTRLPLANE-3371: Fix AllowedCIDRs e2e test for Route-based KAS #8469
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,9 +7,129 @@ import ( | |
|
|
||
| . "github.com/onsi/gomega" | ||
|
|
||
| hyperv1 "github.com/openshift/hypershift/api/hypershift/v1beta1" | ||
| "github.com/openshift/hypershift/support/azureutil" | ||
| "github.com/openshift/hypershift/support/certs" | ||
|
|
||
| "k8s.io/utils/ptr" | ||
| ) | ||
|
|
||
| func TestAllowedCIDRsTargetService(t *testing.T) { | ||
| const ns = "test-hcp" | ||
|
|
||
| publicHC := func(platform hyperv1.PlatformType, svcType hyperv1.PublishingStrategyType) *hyperv1.HostedCluster { | ||
| hc := &hyperv1.HostedCluster{ | ||
| Spec: hyperv1.HostedClusterSpec{ | ||
| Platform: hyperv1.PlatformSpec{Type: platform}, | ||
| Services: []hyperv1.ServicePublishingStrategyMapping{{ | ||
| Service: hyperv1.APIServer, | ||
| ServicePublishingStrategy: hyperv1.ServicePublishingStrategy{Type: svcType}, | ||
| }}, | ||
| }, | ||
| } | ||
| switch platform { | ||
| case hyperv1.AWSPlatform: | ||
| hc.Spec.Platform.AWS = ptr.To(hyperv1.AWSPlatformSpec{EndpointAccess: hyperv1.Public}) | ||
| case hyperv1.AzurePlatform: | ||
| hc.Spec.Platform.Azure = ptr.To(hyperv1.AzurePlatformSpec{Topology: hyperv1.AzureTopologyPublic}) | ||
| } | ||
| return hc | ||
| } | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| hc *hyperv1.HostedCluster | ||
| aroHCP bool | ||
| wantName string | ||
| wantNil bool | ||
| }{ | ||
| { | ||
| name: "When Route strategy on AWS it should return the router service", | ||
| hc: publicHC(hyperv1.AWSPlatform, hyperv1.Route), | ||
| wantName: "router", | ||
| }, | ||
| { | ||
| name: "When Route strategy on Azure self-managed it should return the router service", | ||
| hc: publicHC(hyperv1.AzurePlatform, hyperv1.Route), | ||
| wantName: "router", | ||
| }, | ||
| { | ||
| name: "When Route strategy on ARO HCP it should return nil", | ||
| hc: publicHC(hyperv1.AzurePlatform, hyperv1.Route), | ||
| aroHCP: true, | ||
| wantNil: true, | ||
| }, | ||
| { | ||
| name: "When LoadBalancer strategy on Azure it should return the Azure LB service", | ||
| hc: publicHC(hyperv1.AzurePlatform, hyperv1.LoadBalancer), | ||
| wantName: "kube-apiserverlb", | ||
| }, | ||
| { | ||
| name: "When LoadBalancer strategy with Azure management annotation it should return the Azure LB service", | ||
| hc: func() *hyperv1.HostedCluster { | ||
| hc := publicHC(hyperv1.NonePlatform, hyperv1.LoadBalancer) | ||
| hc.Annotations = map[string]string{ | ||
| hyperv1.ManagementPlatformAnnotation: string(hyperv1.AzurePlatform), | ||
| } | ||
| return hc | ||
| }(), | ||
| wantName: "kube-apiserverlb", | ||
| }, | ||
| { | ||
| name: "When LoadBalancer strategy on AWS it should return the KAS service", | ||
| hc: publicHC(hyperv1.AWSPlatform, hyperv1.LoadBalancer), | ||
| wantName: "kube-apiserver", | ||
| }, | ||
| { | ||
| name: "When private Azure cluster it should return nil", | ||
| hc: &hyperv1.HostedCluster{ | ||
| Spec: hyperv1.HostedClusterSpec{ | ||
| Platform: hyperv1.PlatformSpec{ | ||
| Type: hyperv1.AzurePlatform, | ||
| Azure: ptr.To(hyperv1.AzurePlatformSpec{Topology: hyperv1.AzureTopologyPrivate}), | ||
| }, | ||
| Services: []hyperv1.ServicePublishingStrategyMapping{{ | ||
| Service: hyperv1.APIServer, | ||
| ServicePublishingStrategy: hyperv1.ServicePublishingStrategy{Type: hyperv1.Route}, | ||
| }}, | ||
| }, | ||
| }, | ||
| wantNil: true, | ||
| }, | ||
|
Member
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. These two test cases (NodePort and no-strategy) don't actually reach the branch they claim to test. Both create an Using the {
name: "When NodePort strategy it should return nil",
hc: publicHC(hyperv1.AWSPlatform, hyperv1.NodePort),
wantNil: true,
},
{
name: "When no APIServer strategy it should return nil",
hc: func() *hyperv1.HostedCluster {
hc := publicHC(hyperv1.AWSPlatform, hyperv1.Route)
hc.Spec.Services = nil
return hc
}(),
wantNil: true,
},The tests still return
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. Done. NodePort now uses AI-assisted response via Claude Code |
||
| { | ||
| name: "When NodePort strategy it should return nil", | ||
| hc: publicHC(hyperv1.AWSPlatform, hyperv1.NodePort), | ||
| wantNil: true, | ||
| }, | ||
| { | ||
| name: "When no APIServer strategy it should return nil", | ||
| hc: func() *hyperv1.HostedCluster { | ||
| hc := publicHC(hyperv1.AWSPlatform, hyperv1.Route) | ||
| hc.Spec.Services = nil | ||
| return hc | ||
| }(), | ||
| wantNil: true, | ||
| }, | ||
| } | ||
|
|
||
| for _, tc := range tests { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| g := NewWithT(t) | ||
|
Member
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:
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. Done. Switched to AI-assisted response via Claude Code |
||
| if tc.aroHCP { | ||
| azureutil.SetAsAroHCPTest(t) | ||
| } | ||
| svc := allowedCIDRsTargetService(tc.hc, ns) | ||
| if tc.wantNil { | ||
| g.Expect(svc).To(BeNil()) | ||
| } else { | ||
| g.Expect(svc).ToNot(BeNil()) | ||
| g.Expect(svc.Name).To(Equal(tc.wantName)) | ||
| g.Expect(svc.Namespace).To(Equal(ns)) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
bryan-cox marked this conversation as resolved.
Resolved
|
||
|
|
||
| // TestGenerateCustomCertificate verifies that our certificate generation works correctly | ||
| func TestGenerateCustomCertificate(t *testing.T) { | ||
| testsCases := []struct { | ||
|
|
||
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.
why this change?
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.
After AllowedCIDRs blocks all KAS traffic (
0.0.0.0/32) and then restores it, the KAS pod's WI webhook sidecar may still be recovering. Since the webhook hasFailurePolicy: Ignore, pods created during recovery are silently admitted without WI mutation, causing the WI test to time out waiting for projected token volumes. Running WI first avoids this window.AI-assisted response via Claude Code
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.
please add a comment explaining the order, so contributors know not to change it later.
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.
Done. Added a comment explaining that WI must run first because AllowedCIDRs blocks/restores KAS traffic and the webhook sidecar (FailurePolicy: Ignore) may not be ready during recovery.
AI-assisted response via Claude Code