Skip to content

Commit e1084a5

Browse files
committed
Auto switch to scale from add_unit on container based models
Fixes #651
1 parent fc93ad5 commit e1084a5

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

examples/charmhub_deploy_k8s.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@ async def main():
2424
)
2525

2626
print('Waiting for active')
27-
await model.block_until(
28-
lambda: all(unit.workload_status == 'active'
29-
for unit in application.units))
27+
await model.wait_for_idle(status="active")
28+
29+
# when run on a container based model it should auto-switch to
30+
# scale instead of failing with JujuError
31+
await application.add_unit(count=2)
32+
await application.destroy()
3033

3134
finally:
3235
print('Disconnecting from model')

juju/application.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ async def add_unit(self, count=1, to=None):
131131
If None, a new machine is provisioned.
132132
133133
"""
134+
135+
if self.model.info.type_ == 'caas':
136+
log.warning('adding units to a container-based model not supported, auto-switching to scale')
137+
return await self.scale(scale_change=count)
138+
134139
app_facade = self._facade()
135140

136141
log.debug(

0 commit comments

Comments
 (0)