Skip to content

Commit a69f8fb

Browse files
committed
Ensure num_units is adjusted correctly for subordinate charms
Subordinate charms are by definition don't require additional units. So num-units should be 0 at deploy. Normally in libjuju num_units defaults to 1, this change lets libjuju to check the metadata from charmhub to see if we're deploying a subordinate charm. If that's the case then we adjust the num-units to 0 to be able to deploy it without any problems from Juju's side. fixes #639
1 parent 4f1944c commit a69f8fb

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

juju/model.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1622,6 +1622,16 @@ async def deploy(
16221622
resources = await self._add_charmhub_resources(res.app_name,
16231623
identifier,
16241624
add_charm_res.charm_origin)
1625+
charm_info = await self.charmhub.info(res.app_name)
1626+
is_subordinate = False
1627+
try:
1628+
is_subordinate = charm_info.result.charm.subordinate
1629+
except AttributeError:
1630+
log.warning('CharmHub.Info : unable to retrieve the subordinate information')
1631+
if is_subordinate:
1632+
if num_units > 1:
1633+
raise JujuError("cannot use num_units with subordinate application")
1634+
num_units = 0
16251635

16261636
if Schema.CHARM_STORE.matches(url.schema):
16271637
resources = await self._add_store_resources(res.app_name,

0 commit comments

Comments
 (0)