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

Update refactor and Compare versions for validating update #56

Merged
merged 3 commits into from
May 21, 2021

Conversation

srgothi92
Copy link
Contributor

Issue number:
#48 , Partial #40

Description of changes:
This PR includes 3 commits:

  1. Refactor logs for do update and verify update step

  2. Refactor parsing check command output

Previously, there were separate methods for getting active version
and update state. However in all the cases, we need both the fields together.
So, this change adds a method to parse the raw bytes of command output and
extract all the fields required in a struct
  1. Fixed update verification
Previously version before update was not stored, so it was hard to verify
if update happened or not. This change stores the version and compares it with
updated version to report appropriate logs.

Testing done:

  1. Added an instance to the cluster and saw it updated completely with proper logs.
  2. Ran make test

Terms of contribution:

By submitting this pull request, I agree that this contribution is dual-licensed under the terms of both the Apache License, version 2.0, and the MIT license.

@srgothi92
Copy link
Contributor Author

Keeping It draft until dependent PR in cron-updater branch is merged.

@srgothi92 srgothi92 force-pushed the cron-updater branch 5 times, most recently from 06f240d to f920185 Compare May 17, 2021 16:42
@srgothi92 srgothi92 changed the base branch from cron-updater to develop May 19, 2021 00:04
@srgothi92 srgothi92 marked this pull request as ready for review May 19, 2021 00:22
@srgothi92 srgothi92 requested review from WilboMo and samuelkarp May 19, 2021 00:22
updater/aws.go Outdated
Comment on lines 225 to 226
// updateInstance starts an update process on an instance, and changes instance
// state from DRAINING to ACTIVE in case of success or failure.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it'd be a bit easier to reason about if we pulled the activateInstance bits out of this function and back into the loop in main.go. In all cases we want to reactivate the instance; we don't want to leave it in DRAINING indefinitely. What we can do in main.go is, after reactivating, decide whether or not to continue in the loop based on whether instances are updating successfully or not. And that way we can distinguish between an error in doing the update and an error in reactivating.

Something like this:

err = u.updateInstance(i)
activateErr := u.activateInstance(i)
if err != nil {
	// return? continue?
}
if activateErr != nil {
	// probably return here
}

An alternative would be to have the reactivation happen in a defer inside updateInstance (now that it's extracted to a function this becomes a reasonable option, but that would mean that the caller of updateInstance would lose the ability to determine the difference between an update failure and a reactivation failure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

defer would have been nice, but it was hard to defer something that can result in an error and making sure all the errors are properly logged. I followed your first suggestion with slight change in handling error. Let me know if it looks okay.

Copy link
Contributor

@WilboMo WilboMo left a comment

Choose a reason for hiding this comment

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

nits aside, looks good to me!

updater/aws.go Show resolved Hide resolved
updater/aws.go Outdated
updatedVersion := output.ActivePartition.Image.Version
if updatedVersion == inst.bottlerocketVersion {
log.Printf("Container instance %q did not update, its current "+
"version %s and updated version %s are same", inst.containerInstanceID, inst.bottlerocketVersion, updatedVersion)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: missing "the" in the print statement: "version %s and updated version %s are the same"

updater/main.go Show resolved Hide resolved
Copy link
Contributor Author

@srgothi92 srgothi92 left a comment

Choose a reason for hiding this comment

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

srgothi92 force-pushed the update-refactor branch from 3817f66 to ece94f7 23 seconds ago

Addressed Will's comment.

updater/aws.go Show resolved Hide resolved
updater/main.go Show resolved Hide resolved
updater/main.go Outdated
Comment on lines 108 to 109
}
updateState, err := isUpdateAvailable(updateResult)
if err != nil {
log.Printf("Unable to determine update result. Manual verification of %#q required", i)
if updateErr != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I'd either do these three as a series of if/else if statements or as cases in a switch. Each conditional ends up being mutually exclusive with all the others.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed to if/else if blocks

srgothi92 added 3 commits May 21, 2021 10:00
Previously, there were separate methods for getting active version
and UpdateState. However in all the cases, we need both the fields together.
So, this change adds a method to parse the raw bytes of command output and
extract all the fields required in a struct
Previously version before update was not stored, so it was hard to verify
if update happened or not. This change stores the version and compares it with
updated version to report approiate logs.
@srgothi92 srgothi92 merged commit ea87fc4 into develop May 21, 2021
@srgothi92 srgothi92 deleted the update-refactor branch May 24, 2021 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants