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

Rework workload update order #1431

Merged
merged 3 commits into from
Oct 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
46 changes: 29 additions & 17 deletions pkg/gridtypes/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ func (d *Deployment) ByType(typ WorkloadType) []*WorkloadWithID {
// Upgrade validates n as an updated version of d, and return an Upgrade description
// for the steps that the node needs to take to move from d to n. unchanged workloads results
// will be set on n as is
func (d *Deployment) Upgrade(n *Deployment) (*Upgrade, error) {
func (d *Deployment) Upgrade(n *Deployment) ([]UpgradeOp, error) {
if err := n.Valid(); err != nil {
return nil, errors.Wrap(err, "new deployment is invalid")
}
Expand All @@ -420,10 +420,7 @@ func (d *Deployment) Upgrade(n *Deployment) (*Upgrade, error) {
current[wl.Name] = wl
}

update := make([]*WorkloadWithID, 0)
add := make([]*WorkloadWithID, 0)
remove := make([]*WorkloadWithID, 0)

ops := make([]UpgradeOp, 0)
for i := range n.Workloads {
l := &n.Workloads[i]
id, err := NewWorkloadID(n.TwinID, n.ContractID, l.Name)
Expand All @@ -439,7 +436,10 @@ func (d *Deployment) Upgrade(n *Deployment) (*Upgrade, error) {
if !ok {
if wl.Version == expected {
// newly added workload
add = append(add, wl)
ops = append(ops, UpgradeOp{
wl,
OpAdd,
})
} else {
return nil, fmt.Errorf("invalid version number for workload '%s' expected '%d'", wl.Name, expected)
}
Expand All @@ -454,7 +454,11 @@ func (d *Deployment) Upgrade(n *Deployment) (*Upgrade, error) {
// so
if wl.Version == expected {
// should added to 'update' pile
update = append(update, wl)
ops = append(ops, UpgradeOp{
wl,
OpUpdate,
})

}
// other wise. we leave it untouched
}
Expand All @@ -466,18 +470,26 @@ func (d *Deployment) Upgrade(n *Deployment) (*Upgrade, error) {
for _, wl := range current {
id, _ := NewWorkloadID(d.TwinID, d.ContractID, wl.Name)

remove = append(remove, &WorkloadWithID{
Workload: wl,
ID: id,
ops = append(ops, UpgradeOp{
&WorkloadWithID{
Workload: wl,
ID: id,
},
OpRemove,
})
}

return &Upgrade{ToAdd: add, ToUpdate: update, ToRemove: remove}, nil
return ops, nil
}

// Upgrade procedure structure
type Upgrade struct {
ToAdd []*WorkloadWithID
ToUpdate []*WorkloadWithID
ToRemove []*WorkloadWithID
type UpgradeOp struct {
WlID *WorkloadWithID
Op jobOperation
}

type jobOperation int

const (
OpRemove jobOperation = iota
OpAdd
OpUpdate
)
Loading