@@ -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 {
258261func (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