Skip to content
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

Improve findSubnet logic #3419

Closed
wants to merge 1 commit into from

Conversation

pydctw
Copy link
Contributor

@pydctw pydctw commented Apr 13, 2022

Make findSubnet to return an error when there is no matching subnet with ID

What type of PR is this?
/kind failing-test

What this PR does / why we need it:
Make findSubnet to return an error when there is no matching subnet with ID

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Part of #3399

Special notes for your reviewer:
Wrote a test case that catches the failing scenario described in the issue

Checklist:

  • squashed commits
  • includes documentation
  • adds unit tests
  • adds or updates e2e tests

@k8s-ci-robot k8s-ci-robot added kind/failing-test Categorizes issue or PR as related to a consistently or frequently failing test. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-priority labels Apr 13, 2022
@k8s-ci-robot
Copy link
Contributor

@pydctw: This issue is currently awaiting triage.

If CAPA/CAPI contributors determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Instructions 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/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Apr 13, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
To complete the pull request process, please assign fabriziopandini after the PR has been reviewed.
You can assign the PR to them by writing /assign @fabriziopandini in a comment when ready.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Apr 13, 2022
@Ankitasw
Copy link
Member

/test pull-cluster-api-provider-aws-e2e

@Ankitasw
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 18, 2022
@pydctw
Copy link
Contributor Author

pydctw commented Apr 18, 2022

e2e test failure - recently merged PR (#3425) is causing a failure. Not related to changes in this PR.

Failed to run clusterctl config cluster
Unexpected error:
    <*errors.withStack | 0xc000fd39e0>: {
        error: <*errors.withMessage | 0xc0015d2880>{
            cause: <*errors.fundamental | 0xc000fd39b0>{
                msg: "a lowercase RFC 1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character (e.g. 'example.com', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*')",
             ...
            msg: "invalid cluster name",
        },
        ...
    }
    invalid cluster name: a lowercase RFC 1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character (e.g. 'example.com', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*')
occurred
/home/prow/go/pkg/mod/sigs.k8s.io/cluster-api/test@v1.1.2/framework/clusterctl/client.go:216}

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 18, 2022
@pydctw pydctw force-pushed the subnetid-empty-case branch from 6e75a60 to c1c0f55 Compare April 18, 2022 19:36
@k8s-ci-robot
Copy link
Contributor

New changes are detected. LGTM label has been removed.

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 18, 2022
@pydctw
Copy link
Contributor Author

pydctw commented Apr 18, 2022

Will wait for #3429 to be merged.

@pydctw pydctw force-pushed the subnetid-empty-case branch from c1c0f55 to 3db45db Compare April 18, 2022 19:48
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 18, 2022
Make findSubnet to return an error when there is no matching subnet with ID
@pydctw pydctw force-pushed the subnetid-empty-case branch from 3db45db to b2cc995 Compare April 18, 2022 19:55
@pydctw
Copy link
Contributor Author

pydctw commented Apr 18, 2022

/test pull-cluster-api-provider-aws-e2e

subnets := s.scope.Subnets().FilterPrivate().FilterByZone(*failureDomain)
if len(subnets) == 0 {
errMessage := fmt.Sprintf("failed to run machine %q, no subnets available in availability zone %q",
errMessage := fmt.Sprintf("failed to run machine %q with public IP, no public subnets available in availability zone %q",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using same log for having no public subnets in the list vs having public subnets but missing their subnet IDs is misleading. Might worth keeping if len(subnets) == 0 check.

scope.Name(), *failureDomain)
record.Warnf(scope.AWSMachine, "FailedCreate", errMessage)
return "", awserrors.NewFailedDependency(errMessage)
if subnetID := getSubnetID(subnets); subnetID != "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of returning early when the ID is found, checking negative case first and returning early if fails is a more readable pattern to use and by this way calling getSubnetId() twice in the same case statement will not be needed.

errMessage := fmt.Sprintf("failed to run machine %q with public IP, no public subnets available", scope.Name())
record.Eventf(scope.AWSMachine, "FailedCreate", errMessage)
return "", awserrors.NewFailedDependency(errMessage)
if subnetID := getSubnetID(subnets); subnetID != "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above.

case scope.AWSMachine.Spec.PublicIP != nil && *scope.AWSMachine.Spec.PublicIP:
subnets := s.scope.Subnets().FilterPublic()
if len(subnets) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above.

@sedefsavas
Copy link
Contributor

What is the status with this PR?
If this PR is no longer required considering the fix coming up in cluster-api, let's close this one.

@pydctw pydctw closed this May 31, 2022
@pydctw pydctw deleted the subnetid-empty-case branch November 9, 2022 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/failing-test Categorizes issue or PR as related to a consistently or frequently failing test. needs-priority needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants