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

[Digital Ocean] Handle logic for kops edit/update cluster #9116

Merged
merged 6 commits into from
May 22, 2020

Conversation

srikiz
Copy link
Contributor

@srikiz srikiz commented May 11, 2020

  • Added logic for FindCluster Status

  • Also fixed load balancer logic to only create LB if it doesn't exist.

  • Tested with kops edit cluster by adding new Instance group and was able to see the cluster updated as expected.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels May 11, 2020
@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 the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label May 11, 2020
@k8s-ci-robot k8s-ci-robot added the area/provider/digitalocean Issues or PRs related to digitalocean provider label May 11, 2020
@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 May 11, 2020
Copy link

@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 from the DO end. I mostly left comments around improving error reporting and a few minor refactoring suggestions.

Thanks for doing this Sri. 👏

volumes, err := getAllVolumesByRegion(c, c.RegionName)

if err != nil {
return nil, fmt.Errorf("error describing volumes: %v", err)

Choose a reason for hiding this comment

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

Maybe use a error message closer to the function name we called and include the region name, e.g.:

return nil, fmt.Errorf("failed to get all volumes by region from %s: %v", c.RegionName, err)

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.

var etcdClusterSpec *etcd.EtcdClusterSpec

for _, myTag := range volume.Tags {
klog.V(2).Infof("findEtcdStatus status (from cloud): %v", myTag)

Choose a reason for hiding this comment

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

Perhaps the message should be more about the tag, for instance:

"findEtcdStatus status (from cloud): checking if volume with tag %q belongs to cluster", myTag"

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.

var etcdClusterSpec *etcd.EtcdClusterSpec

for _, myTag := range volume.Tags {
klog.V(2).Infof("findEtcdStatus status (from cloud): %v", myTag)

Choose a reason for hiding this comment

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

Should this be at a higher log level to decrease verbosity, especially because other log statements in this function is a verbosity of 10?

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, changed to verbosity of 10.

// check if volume belongs to this cluster.
// tag will be in the format "KubernetesCluster:dev5-k8s-local" (where clusterName is dev5.k8s.local)
clusterName := strings.Replace(cluster.Name, ".", "-", -1)
if strings.Contains(myTag, fmt.Sprintf("%s, %s", TagKubernetesClusterNamePrefix, ":", clusterName)) {

Choose a reason for hiding this comment

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

Am I misreading this one, or does the call to fmt.Sprintf use 3 variables but only 2 placeholders?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was a miss - I updated it as part of the future commit.

for _, volumeTag := range volume.Tags {
if strings.Contains(volumeTag, TagKubernetesClusterIndex) {
if len(strings.Split(volumeTag, ":")) < 2 {
return nil, fmt.Errorf("error splitting the volume tag %q on volume %q", volumeTag, volume)

Choose a reason for hiding this comment

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

Can we make the message more specific about the fact that we have too few components in the tag?

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.

if len(strings.Split(volumeTag, ":")) < 2 {
return nil, fmt.Errorf("error splitting the volume tag %q on volume %q", volumeTag, volume)
}
dropletIndex := strings.Split(volumeTag, ":")[1]

Choose a reason for hiding this comment

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

nit: if we call strings.Split() first and check the length on the outcome, we only need a single call to strings.Split(). That is,

volumeTagParts := strings.Split(volumeTag, ":")
if len(volumeTagParts) < 2 {
  <error handling>
}
dropletIndex := volumeTagParts[1]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch - thanks, updated.

// tag will be in the format "KubernetesCluster:dev5-k8s-local" (where clusterName is dev5.k8s.local)
clusterName := strings.Replace(cluster.Name, ".", "-", -1)
if strings.Contains(myTag, fmt.Sprintf("%s:%s", TagKubernetesClusterNamePrefix, clusterName)) {
klog.V(10).Infof("findEtcdStatus cluster comparison matched for tag: %v", myTag)
Copy link

@timoreimann timoreimann May 12, 2020

Choose a reason for hiding this comment

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

Wondering if 10 could be too high. AFAIK, level 8 is where Kubernetes tends to log very specific details at the HTTP request level. I'm not too familiar with how kops handles log levels in general, so not a super strong opinion here.

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 will keep it with 10 for now. There are lot places I had seen 10 before, and that's how I continued to use that. I'll keep a note to change this to 8 for all DO work as a separate PR at a later point.

dropletIndex := strings.Split(volumeTag, ":")[1]
etcdClusterSpec, err = c.getEtcdClusterSpec(volume.Name, dropletIndex)
klog.V(10).Infof("findEtcdStatus etcdClusterSpec: %v", fi.DebugAsJsonString(etcdClusterSpec))
if err != nil {

Choose a reason for hiding this comment

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

The error should be handled before we log the spec in the line right above.

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.

}
}

var status []kops.EtcdClusterStatus

Choose a reason for hiding this comment

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

This can be improved slightly performance-wise since we know the target size of the slice:

status := make([]kops.EtcdClusterStatus, 0, len(statusMap))

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.

Copy link

@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. 👍

@rdrgmnzs
Copy link
Contributor

Thanks @srikiz!

/lgtm
/approve

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: rdrgmnzs, srikiz

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 May 22, 2020
@k8s-ci-robot k8s-ci-robot merged commit ee504ac into kubernetes:master May 22, 2020
@k8s-ci-robot k8s-ci-robot added this to the v1.18 milestone May 22, 2020
@srikiz srikiz deleted the DO-LB-HandleUpdates branch May 22, 2020 08:42
k8s-ci-robot added a commit that referenced this pull request May 28, 2020
…9116-upstream-release-1.17

Automated cherry pick of #8180: Refactor: Add Region() method to fi.Cloud #9116: Changes for handling kops update
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/provider/digitalocean Issues or PRs related to digitalocean provider 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.

5 participants