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

cloud provider: fix the fake cloud provider #95499

Merged
merged 1 commit into from Oct 20, 2020

Conversation

nicolehanjing
Copy link
Member

fix the fake cloud provider and update the unit tests for cloud node controller

What type of PR is this?
/kind bug

What this PR does / why we need it:
Fix the fake cloud provider and update the unit tests for cloud node controller
After this merge, back port it into v1.19

To implement instancesV2 interface (kubernetes/cloud-provider-aws#131), we need to handle empty InstancesV2 providerID from getProviderID. A bug was found and fixed: #95342

The test case we're now missing in our unit tests for cloud node controller is when existingNode does not have spec.providerID already set, the updated node should set providerID based on the providerID returned from InstanceMetadata.
Testing that would require the fake cloud provider to return a generated provider ID not derived from what's already set on the node

After this fix, the fake cloud provider will return ProviderID in InstanceMetadata from the node spec if it exists, otherwise it returns a generated providerID like fake:// where ext-id is fetched from the ExtID map

Which issue(s) this PR fixes:

Part of #125

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:

NONE

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/bug Categorizes issue or PR as related to a bug. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Oct 12, 2020
@k8s-ci-robot
Copy link
Contributor

Hi @nicolehanjing. 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/test-infra repository.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Oct 12, 2020
@k8s-ci-robot k8s-ci-robot added area/cloudprovider sig/cloud-provider Categorizes an issue or PR as relevant to SIG Cloud Provider. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Oct 12, 2020
Copy link
Member

@andrewsykim andrewsykim left a comment

Choose a reason for hiding this comment

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

/ok-to-test

@@ -321,8 +321,15 @@ func (f *Cloud) InstanceMetadata(ctx context.Context, node *v1.Node) (*cloudprov
f.addCall("instance-metadata-by-provider-id")
f.addressesMux.Lock()
defer f.addressesMux.Unlock()

providerID := node.Spec.ProviderID
_, ok := f.ExtIDErr[types.NodeName(node.Name)]
Copy link
Member

Choose a reason for hiding this comment

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

This should probably check ExtID instead of ExtIDErr, and fake cloud provider could likely use a new field like MetadataErr to mock errors when calling InstanceMetadata

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought if there is ExtIDErr associated with the nodeName, that means ExtID is an empty map, but if ExtIDErr doesn't exist, we have ExtID available.
But you are right, maybe checking ExtID is more straightforward
will update!

@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 Oct 13, 2020
@andrewsykim
Copy link
Member

/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Oct 13, 2020
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Oct 13, 2020
@nicolehanjing
Copy link
Member Author

/retest

providerID := node.Spec.ProviderID
id, ok := f.ExtID[types.NodeName(node.Name)]
if providerID == "" && ok {
providerID = "fake://" + id
Copy link
Member

Choose a reason for hiding this comment

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

On second thought, I think we want Cloud to have a field ProviderID that holds the value that would be returned here. This way you can define the fake provider ID from the test instead of it being opaque. What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah I agree, that could be much clearer, will update!

@nicolehanjing
Copy link
Member Author

/retest

@@ -702,6 +702,7 @@ func Test_syncNode(t *testing.T) {
Effect: v1.TaintEffectNoSchedule,
},
},
ProviderID: "fake://12345",
Copy link
Member

Choose a reason for hiding this comment

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

For reference, this was originally removed here https://github.com/kubernetes/kubernetes/pull/95342/files#r501940685 since the fake cloud provider did not support pre-existing provider IDs

@@ -436,14 +436,14 @@ func Test_syncNode(t *testing.T) {
CreationTimestamp: metav1.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC),
},
Spec: v1.NodeSpec{
ProviderID: "fake://12345",
Copy link
Member

Choose a reason for hiding this comment

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

This change here seems not related, can we undo this just to keep the git history clean?

Copy link
Member

Choose a reason for hiding this comment

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

(move line 446 back here)

Copy link
Member Author

Choose a reason for hiding this comment

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

ah sure, good catch!

@@ -321,13 +323,20 @@ func (f *Cloud) InstanceMetadata(ctx context.Context, node *v1.Node) (*cloudprov
f.addCall("instance-metadata-by-provider-id")
f.addressesMux.Lock()
defer f.addressesMux.Unlock()

providerID := node.Spec.ProviderID
_, ok := f.ExtID[types.NodeName(node.Name)]
Copy link
Member

Choose a reason for hiding this comment

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

Realiziing now that similar to ExtID, ProviderID should probably be of type map[types.NodeName]string. And here we should check f.ProviderID instead of f.ExtdID.

Copy link
Member Author

Choose a reason for hiding this comment

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

gotcha! Will update

Copy link
Member

@andrewsykim andrewsykim left a comment

Choose a reason for hiding this comment

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

One more minor comment, lgtm otherwise

@@ -702,6 +702,7 @@ func Test_syncNode(t *testing.T) {
Effect: v1.TaintEffectNoSchedule,
},
},
ProviderID: "fake://12345",
Copy link
Member

Choose a reason for hiding this comment

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

This test case name is "provider ID not implemented", so I think the existing node is not supposed to have a provider ID and the updated node is not supposed to have it either.

@nicolehanjing nicolehanjing force-pushed the nicoleh-fix-fake branch 2 times, most recently from 6efeb6b to bbc0364 Compare October 20, 2020 00:01
@@ -321,13 +323,20 @@ func (f *Cloud) InstanceMetadata(ctx context.Context, node *v1.Node) (*cloudprov
f.addCall("instance-metadata-by-provider-id")
f.addressesMux.Lock()
defer f.addressesMux.Unlock()

providerID := ""
Copy link
Member Author

Choose a reason for hiding this comment

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

@andrewsykim so I make this default empty providerID instead of inheriting from node.spec.providerID
PTAL :)

Copy link
Member

@andrewsykim andrewsykim left a comment

Choose a reason for hiding this comment

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

/approve
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 20, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: andrewsykim, nicolehanjing

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 20, 2020
@k8s-ci-robot k8s-ci-robot merged commit 4b59044 into kubernetes:master Oct 20, 2020
@k8s-ci-robot k8s-ci-robot added this to the v1.20 milestone Oct 20, 2020
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. area/cloudprovider cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note-none Denotes a PR that doesn't merit a release note. sig/cloud-provider Categorizes an issue or PR as relevant to SIG Cloud Provider. size/M Denotes a PR that changes 30-99 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.

None yet

3 participants