'install' hook does not get executed on CAAS models

Bug #1854635 reported by Dmitrii Shcherbakov
18
This bug affects 3 people
Affects Status Importance Assigned to Milestone
Canonical Juju
Fix Released
High
Heather Lanigan
2.7
Fix Released
High
Heather Lanigan

Bug Description

For IAAS charms 'install' hook runs before any other hook except storage hooks. For CAAS charms this is not the case.

Tested on 2.7.0 but I believe the same behavior is there for other versions.

There is a clear distinction for handling IAAS and CAAS models in the code - on CAAS models 'start' event runs first instead of 'install':
https://github.com/juju/juju/blob/juju-2.7.0/worker/uniter/uniter.go#L622-L638

I found one vague reference to that here:
https://discourse.jujucharms.com/t/writing-a-kubernetes-charm/159 "unlike traditional charms there’s no expectation that the install hook be implemented"

but not in the install event documentation https://discourse.jujucharms.com/t/charm-hooks/1040#heading--install

Likewise, the "start" event is documented as the one that runs after the first config-changed but currently it doesn't (this documentation issue is probably due to the removal of config-changed execution on every agent restart). This is probably a good thing considering that a charm author needs an event that runs before config-changed.

juju debug-log --replay | grep -P 'test11.*?running op: run '
application-test11: 17:33:33 TRACE juju.worker.uniter.resolver running op: run start hook
application-test11: 17:33:33 TRACE juju.worker.uniter.resolver running op: run leader-elected hook
application-test11: 17:33:33 TRACE juju.worker.uniter.resolver running op: run config-changed hook
application-test11: 17:33:35 TRACE juju.worker.uniter.resolver running op: run config-changed hook
application-test11: 17:41:02 TRACE juju.worker.uniter.resolver running op: run update-status hook

It makes sense that any work done in the charm code that modifies the local pod environment will be lost if the operator pod gets restarted unless persisted to the operator-storage. There are two things that a charm author might want to do in the install hook though:

1) initialize any persistent charm state (a one-time operation for things like .unit-state.db);
1) install any additional dependencies persisted to the operator-storage (e.g. into a python virtual environment).

Based on that, it might be worth having the 'install' hook for k8s charms as well.

Revision history for this message
Ian Booth (wallyworld) wrote :

FWIW, this is already a roadmap item for the current cycle

Changed in juju:
status: New → Triaged
importance: Undecided → High
milestone: none → 2.8-beta1
Changed in juju:
assignee: nobody → Heather Lanigan (hmlanigan)
status: Triaged → In Progress
Revision history for this message
Heather Lanigan (hmlanigan) wrote :
Changed in juju:
milestone: 2.8-beta1 → 2.7.2
Changed in juju:
milestone: 2.7.2 → 2.8-beta1
Revision history for this message
Heather Lanigan (hmlanigan) wrote :

Important note with this change!

There is an impact to k8s charms with storage. Any storage-attached hooks will not be triggered until after the start hook has been run, which differs from non k78s units. The initial hook sequence is install -> leader-elected -> config-changed -> started. This means that any charm logic that needs storage cannot be in install or start and if in config-changed, needs to be deferred until storage is available.

Adding to discourse as well.

Changed in juju:
status: In Progress → Fix Committed
Revision history for this message
John A Meinel (jameinel) wrote :

Is this also being targeted for 2.7.*?

Revision history for this message
Heather Lanigan (hmlanigan) wrote :

I wanted to let this bake in develop for a little bit and target to 2.7.3 once that milestone is available.

Revision history for this message
Heather Lanigan (hmlanigan) wrote :
Harry Pidcock (hpidcock)
Changed in juju:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.