WIP/test/e2e: export load balancer helpers#1381
Conversation
|
Skipping CI for Draft Pull Request. |
|
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
This issue is currently awaiting triage. If cloud-provider-aws contributors determine this is a relevant issue, they will accept it by applying the The DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
/test pull-cloud-provider-aws-test |
|
/test ? |
|
/test pull-cloud-provider-aws-e2e |
|
Covnerting to reguar PR just to trigger e2e |
|
/uncc dmis olemarkus |
|
/hold |
|
/test pull-cloud-provider-aws-e2e |
|
/test pull-cloud-provider-aws-e2e |
|
Node discovery for hairpinning traffic was failing: /test pull-cloud-provider-aws-e2e |
|
/test pull-cloud-provider-aws-e2e |
|
Updated the worker node lookup function to get compatibility with existing logic: /test pull-cloud-provider-aws-e2e |
|
/test pull-cloud-provider-aws-e2e |
|
local tests passing /test pull-cloud-provider-aws-e2e |
|
/test ? |
|
/test pull-cloud-provider-aws-e2e-kubetest2 |
| func (e *E2ETestHelper) cleanup(ctx context.Context) { | ||
| framework.Logf("Cleaning up e2e resources") | ||
| // TODO cleanup resources created by the test helper | ||
| } |
There was a problem hiding this comment.
Do we need this or does it need to be implemented?
| } | ||
| lbDNS := cfg.svc.Status.LoadBalancer.Ingress[0].Hostname | ||
| framework.ExpectNoError(getLBTargetCount(cfg.ctx, lbDNS, cfg.nodeCount), "AWS LB target count validation failed") | ||
| // TODO expected lbDNS not empty |
There was a problem hiding this comment.
nit: remove comment or add validation of lbDNS
| // Use AWS SDK paginator to search through all load balancers | ||
| foundLB, err := getAWSLoadBalancerFromDNSName(e2e.ctx, elbClient, hostAddr) | ||
| framework.ExpectNoError(err, "failed to find load balancer with DNS name %s", hostAddr) | ||
| foundLB, err := e2e.GetAWSHelper().GetLoadBalancerFromDNSNameWithRetry(ctx, hostAddr) |
There was a problem hiding this comment.
GetLoadBalancerFromDNSNameWithRetry is marked as deprecated (see comment to the function), if so we should not use it in new code.
| Capabilities: &v1.Capabilities{ | ||
| Drop: []v1.Capability{"ALL"}, | ||
| }, | ||
| ReadOnlyRootFilesystem: aws.Bool(true), |
There was a problem hiding this comment.
nit: I don't particularly like using the AWS SDK helpers (aws.Bool in this case) outside AWS-related blocks of code, it adds unnecessary coupling.
| @@ -0,0 +1,883 @@ | |||
| /* | |||
| Copyright 2025 The Kubernetes Authors. | |||
| func (h *E2ETestHelperAWS) GetLBTargets(ctx context.Context, lbDNSName string, listenerPort, targetPort int32) ([]string, error) { | ||
| foundLB, err := h.GetLoadBalancerFromDNSNameDefaultTimeout(ctx, lbDNSName) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to get load balancer from DNS name: %v", err) |
There was a problem hiding this comment.
nit (was already present before): it is good practice to error wrap with %w instead of %v, consider fixing.
| LoadBalancerArn: aws.String(lbARN), | ||
| }) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to describe listeners: %v", err) |
There was a problem hiding this comment.
nit (was already present before): it is good practice to error wrap with %w instead of %v, consider fixing.
| // MaxAttempts: 5, | ||
| // MaxBackoff: 10 * time.Second, | ||
| // }) | ||
| func NewAWSHelperWithOptions(ctx context.Context, opts E2ETestHelperAWSOptions) (*E2ETestHelperAWS, error) { |
There was a problem hiding this comment.
nit, just an alternative approach to E2ETestHelperAWSOptions:
It is quite common in go to use the "Functional Options" pattern to pass optional configurations, and it might work well here as well. For example instead of having a NewAWSHelperWithOptions and a E2ETestHelperAWS struct, we could have:
type E2ETestHelperAWSOpt func(*E2ETestHelperAWS)
func NewAWSHelper(ctx context.Context, opts ...E2ETestHelperAWSOpt) (*E2ETestHelperAWS, error) {
h := &E2ETestHelperAWS {}
for _, optFn := range opts {
optFn(h)
}
// rest of code down here
}
func WithMaxAttempts(attempts int) func(*E2ETestHelperAWS) {
return func(h *E2ETestHelperAWS) {
h.MaxAttempts = attempts
}
}
func WithMaxBackoff(maxBackoff time.Duration) func(*E2ETestHelperAWS) {
return func(h *E2ETestHelperAWS) {
h.MaxBackoff = maxBackoff
}
}
With this pattern you have only 1 constructor and the user can pass only the configurations he wants to edit.
For example to get the default one would do:
h, err := NewAWSHelper(ctx)
And instead to customize only one of the settings would do:
h, err := NewAWSHelper(ctx, WithMaxAttempts(5))
I think this approach is less code and more flexible.
| framework.Logf("error getting LB targets (will retry): %v", err) | ||
| lastErr = err |
There was a problem hiding this comment.
we could consider isolating and treating differently retryable vs non-retryable errors here too.
| opts.ApplyDefaults() | ||
|
|
||
| cfg, err := config.LoadDefaultConfig(ctx) | ||
| framework.ExpectNoError(err, "unable to load AWS config") |
There was a problem hiding this comment.
nit: Should we do test assertions inside the helpers (here and in other parts of the PR)? Not a strong opinion, just generally I'd do assertions inside the test function.
What type of PR is this?
/kind cleanup
/kind design
/kind failing-test
What this PR does / why we need it:
This PR introduces exports for e2e library to be extended in test frameworks of layered controllers.
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?: