feat: implement the TAG action to re-tag untagged instances - #62
Conversation
tagInstances() was a stub (built a name list, then hit a TODO + exit()), and 'TAG' was also missing from the $actions whitelist -- so `-a TAG` printed help and was never reachable. Now: - Register 'TAG' in $actions so the action is actually accepted. - Require -m and -c so the expected Name set can be rebuilt (mirrors addNewInstance naming, incl. the scoreboard T0 case). - List VPC instances (excluding terminated), split into named vs untagged (reading the Name tag robustly), assign the still-missing names to the untagged instances, and re-apply Name + TrainingEndDate. - Safety: if untagged count > missing names (e.g. multiple machine types), abort rather than risk mis-tagging. Validated live (us-west-2): re-tag of one untagged instance, the safety guard abort, and a full two-instance re-tag all behaved correctly. Closes percona#53 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
eaab027 to
5fc20ad
Compare
|
Live-tested in us-west-2 — now passing. ✅ Testing first surfaced a second bug: End-to-end validation (2×
|
Closes #53
Problem
tagInstances()(theTAGaction) was never finished — it built a name list, then hit// TODO: finish thisandexit()before doing anything. The dead code beneath it was also buggy (unset($instanceNames)cleared the entire array on the first match, and it assumed theNametag was always at index 0). So-a TAGwas a no-op.What it does now
Re-tags instances that failed to get a
Nametag at creation (the scenario the original comment describes):-mand-cso the expectedNameset can be rebuilt — mirrors the exact naming inaddNewInstance()(Percona-Training-<suffix>-<machine>-T<team>, including thescoreboard→T0special case).Nametag robustly.expected − taken) and assigns them to the untagged instances, re-applyingName+TrainingEndDate.ADDinstead.Limitation (documented in code)
An untagged instance gives no hint of its intended machine type, so this is only reliable for a single machine type per run. Noted in the function comment.
Verification
php -lpasses.describeInstances/createTagspath needs a validation run (ideally by reproducing the original "instance failed to tag" case, or by manually untagging an instance and running-a TAG -m <type> -c <n>).