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

Add set instancegroup command #8531

Closed

Conversation

gabrieljackson
Copy link
Contributor

@gabrieljackson gabrieljackson commented Feb 11, 2020

This change adds a new command and functionality for updating
instance group configuration via command line arguments. This
behavior mimics the set cluster command.

Being able to update the instance group image via automation
would be very helpful to us: #7976

Regarding the implementation, I understand that the set cluster
command was done with hardcoded values with the intention of
updating it to "something better" in the long run. I believe I took
a step in that direction with the way I constructed this command.
By using a map of setting keys and config update logic (setters)
it's a little easier to do things like use the same setter function on
multiple instance groups in the future and to see what fields are
available to update via helper methods. If the reviewers like this
approach, I would be happy to do the same thing for the
set cluster command. It should be noted that I originally tried to
do reflect lookups on the actual config struct, but I found my
initial attempts to be brittle and the code to be confusing so
I opted for this instead. If this isn't a good initial implementation
then I am more than willing to swap it out.

Lastly, if the implementation is good enough, then I will go back
and add more instance group fields that can be set. I didn't want
to do that before I knew what initial reviewers thought.

Thanks!

@k8s-ci-robot
Copy link
Contributor

Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA.

It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.


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

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Feb 11, 2020
@k8s-ci-robot
Copy link
Contributor

Welcome @gabrieljackson!

It looks like this is your first PR to kubernetes/kops 🎉. 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/kops 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
Copy link
Contributor

Hi @gabrieljackson. 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 Feb 11, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: gabrieljackson
To complete the pull request process, please assign rdrgmnzs
You can assign the PR to them by writing /assign @rdrgmnzs in a comment when ready.

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

@gabrieljackson
Copy link
Contributor Author

I was pretty sure I had the CLA stuff all worked out, but I guess not. I will look into why the check failed.

@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 Feb 11, 2020
@gabrieljackson gabrieljackson force-pushed the set-instancegroups-cmd branch 3 times, most recently from 3deedab to d2efb62 Compare February 11, 2020 23:33
This change adds a new command and functionality for updating
instance group configuration via command line arguments. This
behavior mimics the `set cluster` command.
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Feb 12, 2020
@gabrieljackson
Copy link
Contributor Author

/assign @rdrgmnzs

cmd/kops/set_instancegroups.go Show resolved Hide resolved
cmd/kops/set_instancegroups.go Outdated Show resolved Hide resolved
cmd/kops/set_instancegroups.go Outdated Show resolved Hide resolved
pkg/commands/helpers_readwrite.go Outdated Show resolved Hide resolved
pkg/commands/helpers_readwrite.go Outdated Show resolved Hide resolved
pkg/commands/set_instancegroup.go Outdated Show resolved Hide resolved
pkg/commands/set_instancegroup.go Outdated Show resolved Hide resolved

ig.Spec.MaxSize = &i32
return nil
},
Copy link
Member

Choose a reason for hiding this comment

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

I'd think spec.machineType would be important. Zones? MaxPrice?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. As noted in my original PR description, I started with a small list of config fields with the intention to add more if the proposed implementation was acceptable as a first-pass for the command.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I hadn't processed the entire original description before making this review comment.


// ValidInstanceGroupKeysToSetters returns the valid keys and config setting
// logic for instance groups.
func ValidInstanceGroupKeysToSetters() InstanceGroupKeySetters {
Copy link
Member

Choose a reason for hiding this comment

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

This really should be using reflection on api.InstanceGroup and its subfields. Open-coding all that is limiting and error prone.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As I mentioned in my description, I totally agree. Would it make sense to add a few more fields with the current PR description along with more tests and then do a follow-up PR to convert bot set instancegroup and set cluster to use reflection-based config setting, or would you like that to be in this PR?

Copy link
Member

Choose a reason for hiding this comment

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

If I were to do it I would first convert set cluster to reflection, then add set instancegroup. The reflection code should be a separate commit (or commits), if not PR.

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 totally makes sense. Does the following sound like a reasonable compromise?

  1. Merge this PR with current implementation, but more fields and tests.
  2. Add reflection code and move set cluster to use this, using original tests to help verify no regressions.
  3. Move set instancegroup to use reflection and use original tests to help verify no regressions.

If not, I can drop/change this PR to work on the reflection code again.

Copy link
Member

Choose a reason for hiding this comment

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

I wouldn't block that approach, not that I could anyway. The primary downside would be the cost of reviewing code that is likely to be ripped out shortly. The risk of step 2 not happening for a while means review standards on it can't be lowered.

@johngmyers
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 Feb 12, 2020
@johngmyers
Copy link
Member

I think it's fine to implement a subset of fields through reflection. If a leaf field has an unsupported type, emit an error.

@johngmyers
Copy link
Member

/retest

@gabrieljackson
Copy link
Contributor Author

I had some time to start writing code to handle running set commands that will use reflect to set config values. This would be a pretty big change so I wanted to check if it would be ideal to add this to this PR or to do a follow up.

Let me know how you would like me to proceed @rdrgmnzs or others. Thanks.

@johngmyers
Copy link
Member

My preference is for (4). That would be the most efficient use of my review time.

@gabrieljackson
Copy link
Contributor Author

Okay, assuming I don't get other input I will start working on a separate PR for reflect updates and will revisit this afterwards.

@@ -17,8 +17,7 @@ limitations under the License.
package commands

import (
"fmt"

"github.com/pkg/errors"
Copy link
Member

Choose a reason for hiding this comment

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

FYI I think we should use the functionality in xerrors which did make it into go 1.13, specifically fmt.Errorf("foo: %w", err)

@justinsb
Copy link
Member

I'd actually like to see us merge this as-is, though I agree that we shouldn't be printing the list of supported fields. I was testing out spot instance support (I think it is broken with launch templates), and this would have been handy.

A reflection-based approach is better, but it's also a harder in general which is why we haven't done it so far.

There's still an open question about what syntax we should use, but that was one of the goals of hand-coding these; it looks like I think we can support a subset of jmespath which is only the a.b and the a[*].b syntaxes (i.e. subfields and all-members-of-an-array).

Anyway, as it's not trivial to write the reflection code, I'd be in favor of merging this (minus the list of all fields), and then we can implement the reflection.

@johngmyers do you agree?

@gabrieljackson did you make any progress with the reflection code? And would you be able to update this to not print the list of fields?

@johngmyers
Copy link
Member

Aside from the risk of having to maintain quirks due to variance between reflection syntax and hand-coded syntax, I'm not a fan of stopgap code. There's nothing as permanent as temporary measures.

@justinsb justinsb added this to the v1.19 milestone Apr 10, 2020
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. area/documentation and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Apr 20, 2020
@gabrieljackson
Copy link
Contributor Author

Sorry for the delay in response @justinsb.

I have begun working on the reflect code and have it partially implemented, but am still working through the brittleness that comes along with reflect. As you mentioned above it's "harder in general" and I have been thinking about the method with which we decide to match a given set string with the underlying values. There are also follow-up questions like when dealing with a value that is a slice of something, does it append by default or replace the entire set? That's one of the temporary benefits of the current approach in this PR: we can address some useful settings while not opening up the command to some trickier configuration options.

All that said, I am still working on it, but it is becoming quite large and will take a good while longer before I can prioritize it again. In the meantime, I have pushed up some commits here to catch this PR up to master and to remove the field list functionality as requested.

If there is a change of heart and we decide this is worth merging as is I would be happy to work to get that done soon. I still think there is value to merging this as-is, but acknowledge that it would require reviewing some amount of temporary code.

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/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 Jul 19, 2020
@k8s-ci-robot
Copy link
Contributor

k8s-ci-robot commented Aug 18, 2020

@gabrieljackson: The following test failed, say /retest to rerun all failed tests:

Test name Commit Details Rerun command
pull-kops-e2e-k8s-containerd 5d88656 link /test pull-kops-e2e-k8s-containerd

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

@johngmyers
Copy link
Member

@gabrieljackson now that the reflection code has landed in #8896 could you recode this to be in terms of that?

@gabrieljackson
Copy link
Contributor Author

@johngmyers, I can absolutely do that. Thank you for letting me know that someone else had time to get the reflection logic in.

@fejta-bot
Copy link

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Sep 30, 2020
@fejta-bot
Copy link

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close

@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 27, 2020
@k8s-ci-robot
Copy link
Contributor

@gabrieljackson: 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/test-infra repository.

@k8s-ci-robot
Copy link
Contributor

@fejta-bot: Closed this PR.

In response to this:

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close

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.

@gabrieljackson
Copy link
Contributor Author

/reopen

@k8s-ci-robot
Copy link
Contributor

@gabrieljackson: Failed to re-open PR: state cannot be changed. The set-instancegroups-cmd branch was force-pushed or recreated.

In response to this:

/reopen

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/documentation cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants