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

[JUJU-299] Store unit CharmURL as a string reference #13546

Merged
merged 2 commits into from
Dec 10, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Replaces the only usage of untiDoc in upgrades with the document as it
was at the time (version 2.8) that stored *charm.URL instead of *string.
  • Loading branch information
manadart committed Dec 10, 2021
commit 2d136b950c0a4bd09c720510ccc7c84896d6c83a
2 changes: 1 addition & 1 deletion state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -1588,7 +1588,7 @@ func (st *State) AssignStagedUnits(ids []string) ([]UnitAssignmentResult, error)
return results, nil
}

// UnitAssignments returns all staged unit assignments in the model.
// AllUnitAssignments returns all staged unit assignments in the model.
func (st *State) AllUnitAssignments() ([]UnitAssignment, error) {
return st.unitAssignments(nil)
}
Expand Down
2 changes: 1 addition & 1 deletion state/upgrade/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ type OldPortsDoc28 struct {
TxnRevno int64 `bson:"txn-revno"`
}

// OldPortsDoc28 represents a port range entry document prior to the 2.9 schema changes.
// OldPortRangeDoc28 represents a port range entry document prior to the 2.9 schema changes.
type OldPortRangeDoc28 struct {
UnitName string `bson:"unitname"`
FromPort int `bson:"fromport"`
Expand Down
30 changes: 26 additions & 4 deletions state/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"github.com/juju/juju/mongo/utils"
"github.com/juju/juju/state/upgrade"
"github.com/juju/juju/storage/provider"
"github.com/juju/juju/tools"
)

var upgradesLogger = loggo.GetLogger("juju.state.upgrade")
Expand Down Expand Up @@ -1327,7 +1328,7 @@ func collectRelationInfo(coll *mgo.Collection) (map[string]*relationUnitCountInf
return relations, nil
}

// unitAppName returns the name of the Application, given a Units name.
// unitAppName returns the name of the Application, given a Unit's name.
func unitAppName(unitName string) string {
unitParts := strings.Split(unitName, "/")
return unitParts[0]
Expand Down Expand Up @@ -2897,13 +2898,34 @@ func AddMachineIDToSubordinates(pool *StatePool) error {
coll, closer := st.db().GetRawCollection(unitsC)
defer closer()

// unitDoc28 represents the unit document as at Juju version 2.8,
// to which this upgrade step applies.
// Later, in version 2.9.23, CharmURL was stored as *string
// instead of *charm.URL.
type unitDoc28 struct {
DocID string `bson:"_id"`
Name string `bson:"name"`
ModelUUID string `bson:"model-uuid"`
Application string
Series string
CharmURL *charm.URL
Principal string
Subordinates []string
StorageAttachmentCount int `bson:"storageattachmentcount"`
MachineId string
Resolved ResolvedMode
Tools *tools.Tools `bson:",omitempty"`
Life Life
PasswordHash string
}

// Load all the units into a map by full ID.
units := make(map[string]*unitDoc)
units := make(map[string]*unitDoc28)

var doc unitDoc
var doc unitDoc28
iter := coll.Find(nil).Iter()
for iter.Next(&doc) {
// Make a copy of the unitDoc and put the copy
// Make a copy of the doc and put the copy
// into the map.
unit := doc
units[unit.DocID] = &unit
Expand Down