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

refactor: allow variants to implement their own k8s providerID parsing logic #938

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sanjams2
Copy link

@sanjams2 sanjams2 commented Jun 3, 2024

== Motivation ==

Allow further variant specific customization

== Details ==

This change adds the ability for variants to implement their own logic to parse a k8s providerID into an identifier specific to that variant. This is done by adding a new method 'NodeId' on each variant that takes the providerID (in pre-parsed url format) and returns a respective NodeId. That said, the behavior of the existing Fargate variant and EC2 node are left unchanged.

NodeId is a refactor of the previous InstanceId which was inadequately named for variants other than EC2 instances (e.g. fargate). I have also taken this opportunity to add a bit more strong typing to the variant methods to make these methods a bit easier to grok and safer to implement. I have also renamed the KubernetesInstanceId to KubernetesProviderId which felt a more adequate name as well. Finally, in order to prevent circular depedencies and to maintain (what I felt) was a more logical concept of a NodeId, we have created a new submodule in the v1 package named 'awsnode' which contains the NodeId type. This allows both the base v1 module and the variant submodule to use this NodeId type withou circular dependencies.

I have opted not to change variables named instanceId or similar for the time being given the bloat that would cause on this CR size.

Im pushing this change now to get feedback quickly. Can work on adding the necessary testing steps/release notes as required. Based on #917, it seems this may not be required for this change.

@k8s-ci-robot
Copy link
Contributor

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.

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-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added the do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. label Jun 3, 2024
Copy link

linux-foundation-easycla bot commented Jun 3, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign nckturner for approval. For more information see the Kubernetes Code Review Process.

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 cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. labels Jun 3, 2024
@k8s-ci-robot
Copy link
Contributor

Welcome @sanjams2!

It looks like this is your first PR to kubernetes/cloud-provider-aws 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/cloud-provider-aws has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jun 3, 2024
@k8s-ci-robot
Copy link
Contributor

Hi @sanjams2. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jun 3, 2024
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Jun 4, 2024
@dims
Copy link
Member

dims commented Jun 5, 2024

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jun 5, 2024
@sanjams2
Copy link
Author

sanjams2 commented Jun 5, 2024

@cartermckinnon any way you could give this a quick glance and see if there is anything glaring? thanks in advance!

Copy link
Contributor

@cartermckinnon cartermckinnon left a comment

Choose a reason for hiding this comment

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

I like where this is headed, and I think we can do a bit more compaction of the various types involved

import "github.com/aws/aws-sdk-go/aws"

// NodeID is the ID of a node used to uniquely identify that node within an AWS service
type NodeID string
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this could be more useful as an interface, we have too many string alias types in here already 😛

Something like:

type AWSProviderID interface {
    ComputeID() string
}

Then we can implement an EC2ProviderID, FargateProviderID, etc.

The func-s in the Variant interface can accept an AWSProviderID and cast to the relevant type as necessary, providerID.(EC2ProviderID)

Copy link
Author

Choose a reason for hiding this comment

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

hmm I actually am not quite following the need for an interface here. While the NodeID might have different formats, I dont see why there would be different implementations required for those different formats. Along that same line, while it sounds potentially useful to have strongly typed NodeID's, there is currently not a need for it — the casting you mention wouldnt actually be necessary anywhere. That to me signals that an interface may be overkill, but perhaps Im not thinking about a future use-case where having an interface would be ideal.

So as it stands now, I actually think the ergonomics of the string alias type is fits the needs quite well. Let me know your thoughts.

Copy link
Author

Choose a reason for hiding this comment

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

also, much less of a concern, but moving to an interface would substantially increase the size of the changes in this commit.

// the following form
// - aws:///<zone>/<awsInstanceId>
// - aws:////<awsInstanceId>
// - aws:///<zone>/fargate-<eni-ip-address>
// - <awsInstanceId>
type KubernetesInstanceID string
type KubernetesProviderID string
Copy link
Contributor

Choose a reason for hiding this comment

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

This type doesn't seem very useful to me, can we get rid of it in favor of something like:

func ParseProviderID(providerID string) (AWSProviderID, error)

?

Copy link
Author

Choose a reason for hiding this comment

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

Agree and makes sense. Will fix

…g logic

== Motivation ==

Allow further variant specific customization

== Details ==

This change adds the ability for variants to implement their own logic
to parse a k8s providerID into an identifier specific to that variant.
This is done by adding a new method 'NodeId' on each variant that takes
the providerID (in pre-parsed url format) and returns a respective NodeId.

NodeId is a refactor of the previous InstanceId which was inadequately named
for variants other than EC2 instances (e.g. fargate). I have also taken this
opportunity to add a bit more strong typing to the variant methods to make
these methods a bit easier to grok and safer to implement. I have also renamed
the KubernetesInstanceId to KubernetesProviderId which felt a more adequate name
as well. Finally, in order to prevent circular depedencies and to maintain
(what I felt) was a more logical concept of a NodeId, we have created a new
submodule in the v1 package named 'awsnode' which contains the NodeId type.
This allows both the base v1 module and the variant submodule to use this
NodeId type withou circular dependencies.

== Testing ==

make
@sanjams2
Copy link
Author

sanjams2 commented Jun 7, 2024

The test errors seem unrelated to my change. I also cannot find an existing issue noting a similar symptom to these failures.

@sanjams2
Copy link
Author

/retest

@k8s-ci-robot
Copy link
Contributor

@sanjams2: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-cloud-provider-aws-e2e-kubetest2-quick ae2dd17 link false /test pull-cloud-provider-aws-e2e-kubetest2-quick
pull-cloud-provider-aws-e2e-kubetest2 ae2dd17 link false /test pull-cloud-provider-aws-e2e-kubetest2

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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-sigs/prow repository. I understand the commands that are listed here.

@@ -20,6 +20,7 @@ import (
"context"
"fmt"
"io"
"k8s.io/cloud-provider-aws/pkg/providers/v1/awsnode"
Copy link
Member

Choose a reason for hiding this comment

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

nit: can we group the import correctly ?

func (name KubernetesInstanceID) MapToAWSInstanceID() (InstanceID, error) {
s := string(name)

func ParseProviderID(providerID string) (awsnode.NodeID, error) {
Copy link
Member

Choose a reason for hiding this comment

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

i observed that we are making call to get variant followed by this method in most places. Can we return the variant also such that the caller can get both at the same time ?

@kmala
Copy link
Member

kmala commented Jun 17, 2024

/kind feature
/triage accepted

@k8s-ci-robot k8s-ci-robot added the kind/feature Categorizes issue or PR as related to a new feature. label Jun 17, 2024
@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-kind Indicates a PR lacks a `kind/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Jun 17, 2024
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 21, 2024
@k8s-ci-robot
Copy link
Contributor

PR needs rebase.

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-sigs/prow repository.

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle stale
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Nov 19, 2024
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. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. kind/feature Categorizes issue or PR as related to a new feature. lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants