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

[Issue-7870] kops controller support for digital ocean #7961

Merged
merged 5 commits into from Nov 25, 2019

Conversation

srikiz
Copy link
Contributor

@srikiz srikiz commented Nov 19, 2019

This PR addresses the issue mentioned in #7870
for digital ocean cloud provider.

Added a kops-controller that updates the node labels. Tested it and it seems to be working as expected.
Please see the attached image.

image

image

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Nov 19, 2019
@k8s-ci-robot
Copy link
Contributor

Hi @srikiz. 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. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 19, 2019
@rifelpet
Copy link
Member

/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 Nov 19, 2019
Copy link
Member

@zetaab zetaab left a comment

Choose a reason for hiding this comment

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

seems good for me, please fix those comments that I mentioned

also check verify-packages output, its missing something from hack

return string(bodyBytes), nil
}

// IdentifyNode queries OpenStack for the node identity information
Copy link
Member

Choose a reason for hiding this comment

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

openstack :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks, updated.

return token, nil
}

// New creates and returns a nodeidentity.Identifier for Nodes running on OpenStack
Copy link
Member

Choose a reason for hiding this comment

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

openstack?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated.

"k8s.io/kops/pkg/nodeidentity"
)

// nodeIdentifier identifies a node from EC2
Copy link
Member

Choose a reason for hiding this comment

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

ec2?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated.

Copy link
Contributor

@timoreimann timoreimann left a comment

Choose a reason for hiding this comment

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

Looking good in general; left a few comments.

func getMetadata(url string) (string, error) {
resp, err := http.Get(url)
if err != nil {
return "", err
Copy link
Contributor

Choose a reason for hiding this comment

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

We may want to annotate this error and the one one in line 112 to be able to distinguish the two; i.e., do something like

return "", fmt.Errorf("failed to get metadata URL %s: %v", url, err)

here and similarly below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, updated.


instanceID := strings.TrimPrefix(providerID, "digitalocean://")
if strings.HasPrefix(instanceID, "/") {
instanceID = strings.TrimPrefix(instanceID, "/")
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the reason we check for a leading slash here?

Copy link
Member

Choose a reason for hiding this comment

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

i think this is copied from openstack. In openstack the instanceid is in format openstack:///[id] basically this supports both two and three slashes. No idea what is the format for do

Copy link
Contributor

Choose a reason for hiding this comment

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

ah, interesting, thanks for sharing that bit of info @zetaab.

The provider ID is a parameter passed in by kubelet, so I think it depends on how it's configured in kops. In the managed Kubernetes product at DigitalOcean, we use the digitalocean://<id> format -- hoping that's an established convention for Kubernetes clusters running on DO infrastructure.

@srikiz you have much more familiar with the DO integration in kops than me -- could you tell (or look at an existing kops-managed cluster on DO)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I looked into it a little more and it looks like we use the digitalocean:// format.
This is not set in the KOPS code though - looks like this is set in the cloud-provider repo - https://github.com/kubernetes/cloud-provider/blob/master/cloud.go#L103.
The associated changes to cloud-controller-manager for DO is done here -https://github.com/digitalocean/digitalocean-cloud-controller-manager/pull/36/files
I have updated the code to use the same pattern.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for digging, Sri.


func (i *nodeIdentifier) getInstanceGroup(instanceID string) (string, error) {

dropletID, err := strconv.Atoi(instanceID)
Copy link
Contributor

Choose a reason for hiding this comment

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

To me, this piece still belongs to the provider ID parsing functionality, so I'd move it into IdentifyNode. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.


func (i *nodeIdentifier) getInstanceGroup(instanceID string) (string, error) {

dropletID, err := strconv.Atoi(instanceID)
Copy link
Contributor

Choose a reason for hiding this comment

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

The error still needs to be handled.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated and moved this to IdentifyNode.

dropletID, err := strconv.Atoi(instanceID)
ctx := context.TODO()
droplet, _, err := i.doClient.Droplets.Get(ctx, dropletID)

Copy link
Contributor

Choose a reason for hiding this comment

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

Remove blank?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

func (i *nodeIdentifier) getInstanceGroup(instanceID string) (string, error) {

dropletID, err := strconv.Atoi(instanceID)
ctx := context.TODO()
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it make sense to use a timeout-based context here to make sure we do not hang too long trying to fetch the droplet?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are lot of places where context.TODO is used. I'll create an issue to address that as a separate PR. Please suggest if that's Ok for you.

Copy link
Contributor

Choose a reason for hiding this comment

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

Totally okay with that 👍

if strings.Contains(dropletTag, dropletTagInstanceGroupName) {
instancegrouptag := strings.SplitN(dropletTag, ":", 2)
if len(instancegrouptag) < 2 {
return "", fmt.Errorf("failed to retrieve droplet instance group tag = %s properly", dropletTag)
Copy link
Contributor

Choose a reason for hiding this comment

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

How about rephrasing this to something like

return "", fmt.Errorf("failed to parse droplet tag %q: expected colon-separated key/value pair", dropletTag)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, done.

}
}

return "", fmt.Errorf("Could not find tag 'kops-instancegroup' from instance metadata")
Copy link
Contributor

Choose a reason for hiding this comment

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

Should use errors.New here since the error message does not have any place holders.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, updated.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 24, 2019
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 24, 2019
@srikiz
Copy link
Contributor Author

srikiz commented Nov 24, 2019

@timoreimann @zetaab - I have incorporated all the comments. Please have a look and approve if you are Ok. Thanks !

Copy link
Contributor

@timoreimann timoreimann left a comment

Choose a reason for hiding this comment

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

LGTM. 👍

Copy link
Member

@zetaab zetaab left a comment

Choose a reason for hiding this comment

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

thanks @srikiz

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Nov 24, 2019
@rifelpet
Copy link
Member

not sure why tide is still waiting on approved and lgtm...

/lgtm
/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: rifelpet, srikiz, zetaab

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

@droslean
Copy link
Member

/refresh

1 similar comment
@srikiz
Copy link
Contributor Author

srikiz commented Nov 25, 2019

/refresh

@k8s-ci-robot k8s-ci-robot merged commit 5f4a731 into kubernetes:master Nov 25, 2019
@srikiz srikiz deleted the DO-KOPS-Controller-Support branch November 25, 2019 18:36
k8s-ci-robot added a commit that referenced this pull request Dec 23, 2019
…pstream-release-1.16

Automated cherry pick of #7961: Initial work
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. lgtm "Looks good to me", indicates that a PR is ready to be merged. 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants