Skip to content

Commit

Permalink
feat(disk_setup) add timeout
Browse files Browse the repository at this point in the history
In a cloud environment, sometimes disks will attach while cloud-init is
running and get missed. This adds a configurable timeout to wait for
those disks.

Signed-off-by: Florian Klink <flokli@flokli.de>
  • Loading branch information
nibalizer authored and flokli committed Dec 8, 2023
1 parent dac62ec commit eadf16e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cloudinit/config/cc_disk_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@ def alias_to_device(cand):
LOG.warning("Invalid disk definition for %s", disk)
continue

if definition.get("timeout"):
tmout = int(definition.get("timeout"))
missing = util.wait_for_files([disk],
maxwait=tmout,
naplen=0.1)
if len(missing) > 0:
LOG.warning("Timeout expired waiting for %s" % disk)
try:
LOG.debug("Creating new partition table/disk")
util.log_time(
Expand Down
5 changes: 5 additions & 0 deletions cloudinit/config/schemas/schema-cloud-config-v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -1261,6 +1261,11 @@
"type": "boolean",
"default": false,
"description": "Controls whether this module tries to be safe about writing partition tables or not. If ``overwrite: false`` is set, the device will be checked for a partition table and for a file system and if either is found, the operation will be skipped. If ``overwrite: true`` is set, no checks will be performed. Using ``overwrite: true`` is **dangerous** and can lead to data loss, so double check that the correct device has been specified if using this option. Default: ``false``"
},
"timeout": {
"type": "integer",
"default": 0,
"description": "Seconds to wait for a disk to appear. If omitted, no wait is performed. This is useful if a cloud provider has late or inconsistent disk attachments and you need a delay."
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions doc/examples/cloud-config-disk-setup.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ disk_setup:
# table_type: 'mbr'
# layout: <LAYOUT|BOOL>
# overwrite: <BOOL>
# timeout: <INT>
#
# Where:
# <DEVICE>: The name of the device. 'ephemeralX' and 'swap' are special
Expand Down Expand Up @@ -160,6 +161,11 @@ disk_setup:
# done blindly. USE with caution, you can do things you
# really, really don't want to do.
#
# timeout=<INT>: Seconds to wait for a disk to appear. If omitted, no wait
# is performed. This is useful if a cloud provider has late or
# inconsistent disk attachments and you need a delay.
#
#
#
# fs_setup: Setup the filesystem
# ------------------------------
Expand Down

0 comments on commit eadf16e

Please sign in to comment.