Skip to content

Commit 470bfa5

Browse files
authored
Merge pull request juju#10325 from manadart/2.6-ha-partial-placement
juju#10325 ## Description of change Backport of juju#10185 from the develop branch.
2 parents d7d9e50 + fe7921e commit 470bfa5

File tree

4 files changed

+98
-54
lines changed

4 files changed

+98
-54
lines changed

apiserver/facades/client/highavailability/highavailability.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,11 @@ func getReferenceController(st *state.State, machineIds []string) (*state.Machin
170170
controllerId := controllerIds[0]
171171

172172
// Load the controller machine and get its constraints.
173-
controller, err := st.Machine(strconv.Itoa(controllerId))
173+
cm, err := st.Machine(strconv.Itoa(controllerId))
174174
if err != nil {
175175
return nil, errors.Annotatef(err, "reading controller id %v", controllerId)
176176
}
177-
return controller, nil
177+
return cm, nil
178178
}
179179

180180
// validateCurrentControllers checks for a scenario where there is no HA space
@@ -189,11 +189,11 @@ func validateCurrentControllers(st *state.State, cfg controller.Config, machineI
189189

190190
var badIds []string
191191
for _, id := range machineIds {
192-
controller, err := st.Machine(id)
192+
cm, err := st.Machine(id)
193193
if err != nil {
194194
return errors.Annotatef(err, "reading controller id %v", id)
195195
}
196-
addresses := controller.Addresses()
196+
addresses := cm.Addresses()
197197
if len(addresses) == 0 {
198198
// machines without any address are essentially not started yet
199199
continue

cmd/juju/commands/enableha.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ func (c *enableHACommand) Run(ctx *cmd.Context) error {
227227
return err
228228
}
229229

230-
defer haClient.Close()
230+
defer func() { _ = haClient.Close() }()
231231
enableHAResult, err := haClient.EnableHA(
232232
c.NumControllers,
233233
c.Constraints,

state/enableha.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -184,18 +184,20 @@ func (st *State) enableHAIntentionOps(
184184
) ([]txn.Op, ControllersChanges, error) {
185185
var ops []txn.Op
186186
var change ControllersChanges
187+
187188
for _, m := range intent.promote {
188189
ops = append(ops, promoteControllerOps(m)...)
189190
change.Promoted = append(change.Promoted, m.doc.Id)
190191
}
192+
191193
for _, m := range intent.convert {
192194
ops = append(ops, convertControllerOps(m)...)
193195
change.Converted = append(change.Converted, m.doc.Id)
194196
}
195-
// Use any placement directives that have been provided
196-
// when adding new machines, until the directives have
197-
// been all used up. Ignore constraints for provided machines.
198-
// Set up a helper function to do the work required.
197+
198+
// Use any placement directives that have been provided when adding new
199+
// machines, until the directives have been all used up.
200+
// Ignore constraints for provided machines.
199201
placementCount := 0
200202
getPlacementConstraints := func() (string, constraints.Value) {
201203
if placementCount >= len(intent.placement) {
@@ -205,6 +207,7 @@ func (st *State) enableHAIntentionOps(
205207
placementCount++
206208
return result, constraints.Value{}
207209
}
210+
208211
mdocs := make([]*machineDoc, intent.newCount)
209212
for i := range mdocs {
210213
placement, cons := getPlacementConstraints()
@@ -224,8 +227,8 @@ func (st *State) enableHAIntentionOps(
224227
mdocs[i] = mdoc
225228
ops = append(ops, addOps...)
226229
change.Added = append(change.Added, mdoc.Id)
227-
228230
}
231+
229232
for _, m := range intent.maintain {
230233
tag, err := names.ParseTag(m.Tag().String())
231234
if err != nil {
@@ -258,15 +261,21 @@ type enableHAIntent struct {
258261
func (st *State) enableHAIntentions(info *ControllerInfo, placement []string) (*enableHAIntent, error) {
259262
var intent enableHAIntent
260263
for _, s := range placement {
261-
// TODO(natefinch): unscoped placements shouldn't ever get here (though
262-
// they do currently). We should fix up the CLI to always add a scope
263-
// to placements and then we can remove the need to deal with unscoped
264-
// placements.
264+
// TODO(natefinch): Unscoped placements can end up here, though they
265+
// should not. We should fix up the CLI to always add a scope,
266+
// then we can remove the need to deal with unscoped placements.
267+
268+
// Append unscoped placements to the intentions.
269+
// These will be used if/when adding new controllers is required.
270+
// These placements will be interpreted as availability zones.
265271
p, err := instance.ParsePlacement(s)
266272
if err == instance.ErrPlacementScopeMissing {
267273
intent.placement = append(intent.placement, s)
268274
continue
269275
}
276+
277+
// Placements for machines are "consumed" by appending such machines as
278+
// candidates for promotion to controllers.
270279
if err == nil && p.Scope == instance.MachineScope {
271280
if names.IsContainerMachine(p.Directive) {
272281
return nil, errors.New("container placement directives not supported")
@@ -280,7 +289,6 @@ func (st *State) enableHAIntentions(info *ControllerInfo, placement []string) (*
280289
return nil, errors.Errorf("machine for placement directive %q is already a controller", s)
281290
}
282291
intent.convert = append(intent.convert, m)
283-
intent.placement = append(intent.placement, s)
284292
continue
285293
}
286294
return nil, errors.Errorf("unsupported placement directive %q", s)

0 commit comments

Comments
 (0)