Skip to content

Commit

Permalink
Merge pull request #189 from ripienaar/188
Browse files Browse the repository at this point in the history
(#188) adds a skip indicator for version upgrade skips
  • Loading branch information
ploubser authored Feb 23, 2023
2 parents 7c408c7 + a1351bd commit 0cf791d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
20 changes: 13 additions & 7 deletions host/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,13 @@ func (h *Host) Provision(ctx context.Context, fw *choria.Framework) (bool, error
}

if h.cfg.Features.VersionUpgrades && h.upgradeTargetVersion != "" {
err := h.handleHostUpgrade(ctx)
skipped, err := h.handleHostUpgrade(ctx)
switch {
case err == nil:
if skipped {
break
}

// no delay so we reprov asap
return false, nil
case h.cfg.UpgradesOptional:
Expand All @@ -208,19 +212,19 @@ func (h *Host) Provision(ctx context.Context, fw *choria.Framework) (bool, error
return true, nil
}

func (h *Host) handleHostUpgrade(ctx context.Context) error {
func (h *Host) handleHostUpgrade(ctx context.Context) (bool, error) {
if h.cfg.Features.VersionUpgrades {
if h.cfg.UpgradesRepo == "" && !h.cfg.UpgradesOptional {
return fmt.Errorf("updates_repository not configured for upgrades feature")
return false, fmt.Errorf("updates_repository not configured for upgrades feature")
}
}

if h.version == "" {
return fmt.Errorf("did not receive a version in inventory")
return false, fmt.Errorf("did not receive a version in inventory")
}

if !h.upgradable {
return fmt.Errorf("does not support upgrades")
return false, fmt.Errorf("does not support upgrades")
}

cv := NewVersion(h.version)
Expand All @@ -231,11 +235,13 @@ func (h *Host) handleHostUpgrade(ctx context.Context) error {

err := h.upgrade(ctx)
if err != nil {
return fmt.Errorf("upgrading to %v failed: %v", h.upgradeTargetVersion, err)
return false, fmt.Errorf("upgrading to %v failed: %v", h.upgradeTargetVersion, err)
}

return false, nil
}

return nil
return true, nil
}

func (h *Host) generateServerJWT(c *ConfigResponse) error {
Expand Down
13 changes: 7 additions & 6 deletions hosts/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ func provisioner(ctx context.Context, wg *sync.WaitGroup, i int) {
provErrCtr.WithLabelValues(conf.Site).Inc()
log.Errorf("Could not provision %s: %s", host.Identity, err)
done <- host
continue
}

log.Infof("Provisioned %s", host.Identity)
if delay {
time.AfterFunc(60*time.Second, func() { done <- host })
} else {
log.Infof("Provisioned %s", host.Identity)
if delay {
time.AfterFunc(60*time.Second, func() { done <- host })
} else {
done <- host
}
done <- host
}

case <-ctx.Done():
Expand Down

0 comments on commit 0cf791d

Please sign in to comment.