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

Implements InstancesV2 interface #845

Merged
merged 1 commit into from Feb 18, 2024

Conversation

mmerkes
Copy link
Contributor

@mmerkes mmerkes commented Feb 10, 2024

What type of PR is this?

/kind cleanup
/kind feature

What this PR does / why we need it:

The InstancesV2 interface is the path forward for cloud providers. To enable new changes, like providing custom labels, we need to migrate to InstancesV2 as they won't be implemented in the original Instances interface.

This change is needed to prepare to support #300

Which issue(s) this PR fixes:
N/A

Special notes for your reviewer:

I've added unit tests here and the automation should run. I'll do some manual testing with an EKS cluster, but if you have suggestions on things I should test specifically, let me know.

Does this PR introduce a user-facing change?:

Migrate to InstancesV2 interface

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. kind/feature Categorizes issue or PR as related to a new feature. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Feb 10, 2024
@k8s-ci-robot
Copy link
Contributor

This issue is currently awaiting triage.

If cloud-provider-aws contributors determine 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 size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Feb 10, 2024
@mmerkes
Copy link
Contributor Author

mmerkes commented Feb 10, 2024

/assign @cartermckinnon @dims

func (c *Cloud) InstanceMetadata(ctx context.Context, node *v1.Node) (*cloudprovider.InstanceMetadata, error) {
providerID, err := c.getProviderID(ctx, node)
if err != nil {
return &cloudprovider.InstanceMetadata{}, err
Copy link
Member

Choose a reason for hiding this comment

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

is return nil, err enough?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe I'm wrong, but I thought you needed to return an empty object with Go... I might also be conflating with another language.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sometimes folks use signatures that return (struct, error) instead of (*struct, error). The former forces you to return an empty struct in this case, while the latter lets you return nil, err.

The caller should be paying attention to your err, so I think nil is some nice encouragement :) (they'll panic if they don't have error handling)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tx for being big brained @cartermckinnon

pkg/providers/v1/instances_v2.go Show resolved Hide resolved
if err != nil {
return "", err
}
return c.ProviderName() + "://" + instanceID, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

There should already be an impl for this in aws.go, and the provider ID should be suffixed by the AZ

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One would think that... But it's not.

the provider ID should be suffixed by the AZ

Ya, I knew I needed to update this, but ran out of time. I just copied the code from k8s/k8s to get the provider ID, so I was a little confused by it. I'll dig in further and make sure it returns the right output with some unit tests.

Copy link
Contributor Author

@mmerkes mmerkes Feb 10, 2024

Choose a reason for hiding this comment

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

Ok, I was a little confused by this because I copied the logic upstream and didn't totally close the loop on it. However, looks like this is actually the right behavior. In totally obvious fashion, instanceID, in this case, is actually NOT the instance ID. It's the instance ID plus the zone we tack on the provider ID...

func (c *Cloud) InstanceID(ctx context.Context, nodeName types.NodeName) (string, error) {
// In the future it is possible to also return an endpoint as:
// <endpoint>/<zone>/<instanceid>
if c.selfAWSInstance.nodeName == nodeName {
return "/" + c.selfAWSInstance.availabilityZone + "/" + c.selfAWSInstance.awsID, nil
}
inst, err := c.getInstanceByNodeName(nodeName)
if err != nil {
if err == cloudprovider.InstanceNotFound {
// The Instances interface requires that we return InstanceNotFound (without wrapping)
return "", err
}
return "", fmt.Errorf("getInstanceByNodeName failed for %q with %q", nodeName, err)
}
return "/" + aws.StringValue(inst.Placement.AvailabilityZone) + "/" + aws.StringValue(inst.InstanceId), nil
}

Copy link
Member

Choose a reason for hiding this comment

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

Am I missing something, or does this function ignore the provider ID already set on the node resource?
At least some installers set the provider ID through the kubelet flag, which in turn sets it on the node resource as it is created.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hm looks like the provider ID returned here won't overwrite an existing one: https://github.com/kubernetes/kubernetes/blob/5031ae11590748f247c15c81f9f35390a786104b/staging/src/k8s.io/cloud-provider/controllers/node/node_controller.go#L524-L530

But we could save some EC2 calls if we use the existing provider ID.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably won't save any calls to EC2 because we use cached values and will need the describe values for the other fields, but getting it directly, if it's set, makes sense.

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Feb 17, 2024
@mmerkes mmerkes changed the title [WIP] Implements InstancesV2 interface Implements InstancesV2 interface Feb 17, 2024
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 17, 2024
@mmerkes mmerkes force-pushed the instancesv2 branch 2 times, most recently from bcfed89 to 152c50e Compare February 17, 2024 15:35
Signed-off-by: Matt Merkes <merkes@amazon.com>
@mmerkes
Copy link
Contributor Author

mmerkes commented Feb 17, 2024

/retest

@dims
Copy link
Member

dims commented Feb 17, 2024

/approve

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 17, 2024
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 18, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dims, olemarkus

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

The pull request process is described 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

@olemarkus
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot merged commit d6048ef into kubernetes:master Feb 18, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. release-note Denotes a PR that will be considered when it comes time to generate release notes. 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.

None yet

5 participants