-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
salt/volumes: Detach devices before (up|down)grade
Since the management of loop devices changed between 2.6 and 2.7 (introduction of systemd units for this purpose), we want to ensure there will not be duplicated devices pointing to the same sparse file. To do this, we introduce a "cleanup" formula, which can operate in two modes, 'upgrade' and 'downgrade' (controlled via pillar). For upgrade, we manage this cleanup in the `deploy_node` orchestrate, during the drain. For downgrade, we cannot change the `deploy_node` orchestrate, so we manually drain and cleanup from the `downgrade` orchestrate. See: #2982
- Loading branch information
Showing
5 changed files
with
136 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Clean already attached loop devices before applying highstate, to avoid | ||
# creating duplicates for a same sparse file. | ||
# This state can cleanup either "manually", for upgrade, or by disabling the | ||
# systemd units, for downgrade. | ||
{%- set mode = pillar.get('cleanup_mode', 'upgrade') %} | ||
|
||
include: | ||
- .installed | ||
|
||
{%- set sparse_volumes = [] %} | ||
{%- for volume in pillar.metalk8s.volumes %} | ||
{%- if 'sparseLoopDevice' in volume.spec %} | ||
{%- do sparse_volumes.append(volume) %} | ||
{%- endif %} | ||
{%- endfor %} | ||
|
||
{%- if not sparse_volumes %} | ||
|
||
Nothing to cleanup: | ||
test.succeed_without_changes: [] | ||
|
||
{%- else %} | ||
{%- for volume in sparse_volumes %} | ||
{%- set volume_name = volume.metadata.name %} | ||
{%- set volume_id = volume.metadata.uid %} | ||
{%- if mode == 'upgrade' %} | ||
|
||
Cleanup loop device for Volume {{ volume_name }}: | ||
cmd.run: | ||
- cmd: /usr/local/libexec/metalk8s-sparse-volume-cleanup "{{ volume_id }}" | ||
# Only cleanup if the systemd unit doesn't exist yet (this command exits | ||
# with retcode 3 if the service is dead, 4 if the template does not exist) | ||
- unless: systemctl status metalk8s-sparse-volume@{{ volume_id }} | ||
- require: | ||
- test: Ensure Python 3 is available | ||
- file: Install clean-up script | ||
{%- else %} {# mode == 'downgrade' #} | ||
Disable systemd unit for Volume {{ volume_name }}: | ||
service.dead: | ||
- name: metalk8s-sparse-volume@{{ volume_id }} | ||
- enable: false | ||
- require: | ||
- test: Ensure Python 3 is available | ||
- file: Set up systemd template unit for sparse loop device provisioning | ||
- file: Install clean-up script | ||
{%- endif %} | ||
{%- endfor %} | ||
{%- endif %} |