Skip to content

Commit

Permalink
Fixed update verification
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
srgothi92 committed May 19, 2021
1 parent 422293c commit 3817f66
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
29 changes: 17 additions & 12 deletions updater/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const (
type instance struct {
instanceID string
containerInstanceID string
bottlerocketVersion string
}

type checkOutput struct {
Expand Down Expand Up @@ -112,6 +113,7 @@ func (u *updater) filterAvailableUpdates(bottlerocketInstances []instance) ([]in
continue
}
if output.UpdateState == "Available" {
inst.bottlerocketVersion = output.ActivePartition.Image.Version
candidates = append(candidates, inst)
}
}
Expand Down Expand Up @@ -237,33 +239,36 @@ func (u *updater) updateInstance(inst instance) error {
}

// verifyUpdate verifies if instance was properly updated
func (u *updater) verifyUpdate(inst instance) error {
func (u *updater) verifyUpdate(inst instance) (bool, error) {
log.Println("Verifying update by checking there is no new version available to update" +
" and validate the active version")
ec2IDs := []string{inst.instanceID}
updateStatus, err := u.sendCommand(ec2IDs, "apiclient update check")
if err != nil {
return fmt.Errorf("failed to send update check command : %v", err)
return false, fmt.Errorf("failed to send update check command: %v", err)
}

updateResult, err := u.getCommandResult(updateStatus, inst.instanceID)
if err != nil {
return fmt.Errorf("failed to get check command output: %w", err)
return false, fmt.Errorf("failed to get check command output: %w", err)
}
output, err := parseCommandOutput(updateResult)
if err != nil {
return fmt.Errorf("failed to parse command output %s, manual verification required: %w", string(updateResult), err)
return false, fmt.Errorf("failed to parse command output %s, manual verification required: %w", string(updateResult), err)
}
if output.UpdateState == "Available" {
return fmt.Errorf(" instance did not update, manual update advised")
}
log.Printf("Instance %#q updated successfully", inst)
if output.ActivePartition.Image.Version != "" {
log.Printf("Instance %#q running Bottlerocket: %s", inst, output.ActivePartition.Image.Version)
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)
return false, nil
} else if output.UpdateState == "Available" {
log.Printf("Container instance %q was updated to version %q successfully, however another newer version was recently released;"+
" Instance will be updated to newer version in next iteration.", inst.containerInstanceID, updatedVersion)
return true, nil
} else {
log.Printf("Unable to verify active version. Manual verification of %#q required.", inst)
log.Printf("Container instance %q updated to version %q", inst.containerInstanceID, updatedVersion)
}
return nil
return true, nil
}

func (u *updater) sendCommand(instanceIDs []string, ssmCommand string) (string, error) {
Expand Down
7 changes: 6 additions & 1 deletion updater/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,15 @@ func _main() error {
return fmt.Errorf("instance %#q failed to re-activate after update: %w", i, activateErr)
}

err = u.verifyUpdate(i)
ok, err := u.verifyUpdate(i)
if err != nil {
log.Printf("Failed to verify update for instance %#q: %v", i, err)
}
if !ok {
log.Printf("Update failed for instance %#q", i)
} else {
log.Printf("Instance %#q updated successfully!", i)
}
}
return nil
}

0 comments on commit 3817f66

Please sign in to comment.