1
// Copyright 2014 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
7
jujuversion "github.com/juju/juju/version"
8
"github.com/juju/version"
11
// stateUpgradeOperations returns an ordered slice of sets of
12
// state-based operations needed to upgrade Juju to particular
13
// version. The slice is ordered by target version, so that the sets
14
// of operations are executed in order from oldest version to most
17
// All state-based operations are run before API-based operations
19
var stateUpgradeOperations = func() []Operation {
21
// Replace when we have upgrades to do
23
version.MustParse("1.26-placeholder1"),
30
// upgradeOperations returns an ordered slice of sets of API-based
31
// operations needed to upgrade Juju to particular version. As per the
32
// state-based operations above, ordering is important.
33
var upgradeOperations = func() []Operation {
35
// Replace when we have upgrades to do
37
version.MustParse("1.26-placeholder1"),
44
type opsIterator struct {
51
func newStateUpgradeOpsIterator(from version.Number) *opsIterator {
52
return newOpsIterator(from, jujuversion.Current, stateUpgradeOperations())
55
func newUpgradeOpsIterator(from version.Number) *opsIterator {
56
return newOpsIterator(from, jujuversion.Current, upgradeOperations())
59
func newOpsIterator(from, to version.Number, ops []Operation) *opsIterator {
60
// If from is not known, it is 1.16.
61
if from == version.Zero {
62
from = version.MustParse("1.16.0")
65
// Clear the version tag of the target release to ensure that all
66
// upgrade steps for the release are run for alpha and beta
68
// ...but only do this if the agent version has actually changed,
69
// lest we trigger upgrade mode unnecessarily for non-final
71
if from.Compare(to) != 0 {
83
func (it *opsIterator) Next() bool {
86
if it.current >= len(it.allOps) {
89
targetVersion := it.allOps[it.current].TargetVersion()
91
// Do not run steps for versions of Juju earlier or same as we are upgrading from.
92
if targetVersion.Compare(it.from) <= 0 {
95
// Do not run steps for versions of Juju later than we are upgrading to.
96
if targetVersion.Compare(it.to) > 0 {
103
func (it *opsIterator) Get() Operation {
104
return it.allOps[it.current]