|
|
@ -130,10 +130,9 @@ options:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- "If set, this module will wait for the PVC to become bound and CDI (if enabled) to finish its operation
|
|
|
|
- "If set, this module will wait for the PVC to become bound and CDI (if enabled) to finish its operation
|
|
|
|
before returning."
|
|
|
|
before returning."
|
|
|
|
|
|
|
|
- Module is aware of WaitForFirstConsumer and will not erroneously time out in such cases.
|
|
|
|
- "Used only if I(state) set to C(present)."
|
|
|
|
- "Used only if I(state) set to C(present)."
|
|
|
|
- "Unless used in conjuction with I(cdi_source), this might result in a timeout, as clusters may be configured
|
|
|
|
default: true
|
|
|
|
to not bind PVCs until first usage."
|
|
|
|
|
|
|
|
default: false
|
|
|
|
|
|
|
|
type: bool
|
|
|
|
type: bool
|
|
|
|
wait_timeout:
|
|
|
|
wait_timeout:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
@ -295,7 +294,7 @@ PVC_ARG_SPEC = {
|
|
|
|
'cdi_source': {'type': 'dict'},
|
|
|
|
'cdi_source': {'type': 'dict'},
|
|
|
|
'wait': {
|
|
|
|
'wait': {
|
|
|
|
'type': 'bool',
|
|
|
|
'type': 'bool',
|
|
|
|
'default': False
|
|
|
|
'default': True
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'wait_timeout': {
|
|
|
|
'wait_timeout': {
|
|
|
|
'type': 'int',
|
|
|
|
'type': 'int',
|
|
|
@ -373,18 +372,26 @@ class KubevirtPVC(KubernetesRawModule):
|
|
|
|
if 'certConfigMap' in src_spec:
|
|
|
|
if 'certConfigMap' in src_spec:
|
|
|
|
annotations['cdi.kubevirt.io/storage.import.certConfigMap'] = src_spec['certConfigMap']
|
|
|
|
annotations['cdi.kubevirt.io/storage.import.certConfigMap'] = src_spec['certConfigMap']
|
|
|
|
|
|
|
|
|
|
|
|
def _wait_for_creation(self, resource, uid):
|
|
|
|
def _wait_for_creation(self, resource, result):
|
|
|
|
return_obj = None
|
|
|
|
return_obj = None
|
|
|
|
desired_cdi_status = 'Succeeded'
|
|
|
|
desired_cdi_status = 'Succeeded'
|
|
|
|
|
|
|
|
uid = result['metadata']['uid']
|
|
|
|
use_cdi = True if self.params.get('cdi_source') else False
|
|
|
|
use_cdi = True if self.params.get('cdi_source') else False
|
|
|
|
|
|
|
|
|
|
|
|
if use_cdi and 'upload' in self.params['cdi_source']:
|
|
|
|
if use_cdi and 'upload' in self.params['cdi_source']:
|
|
|
|
desired_cdi_status = 'Running'
|
|
|
|
desired_cdi_status = 'Running'
|
|
|
|
|
|
|
|
if not use_cdi:
|
|
|
|
for event in resource.watch(namespace=self.namespace, timeout=self.params.get('wait_timeout')):
|
|
|
|
v1_events = self.client.resources.get(api_version='v1', kind='Event')
|
|
|
|
|
|
|
|
pvc_events = v1_events.get(namespace=self.namespace, field_selector='involvedObject.uid={0}'.format(uid))
|
|
|
|
|
|
|
|
reasons = [item.reason for item in pvc_events.items if hasattr(item, 'reason')]
|
|
|
|
|
|
|
|
if 'WaitForFirstConsumer' in reasons:
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for event in resource.watch(namespace=self.namespace,
|
|
|
|
|
|
|
|
field_selector='involvedObject.uid={0}'.format(uid),
|
|
|
|
|
|
|
|
timeout=self.params.get('wait_timeout')):
|
|
|
|
entity = event['object']
|
|
|
|
entity = event['object']
|
|
|
|
metadata = entity.metadata
|
|
|
|
metadata = entity.metadata
|
|
|
|
if not hasattr(metadata, 'uid') or metadata.uid != uid:
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
if entity.status.phase == 'Bound':
|
|
|
|
if entity.status.phase == 'Bound':
|
|
|
|
if use_cdi and hasattr(metadata, 'annotations'):
|
|
|
|
if use_cdi and hasattr(metadata, 'annotations'):
|
|
|
|
import_status = metadata.annotations.get('cdi.kubevirt.io/storage.pod.phase')
|
|
|
|
import_status = metadata.annotations.get('cdi.kubevirt.io/storage.pod.phase')
|
|
|
@ -442,7 +449,7 @@ class KubevirtPVC(KubernetesRawModule):
|
|
|
|
definition = self.set_defaults(resource, definition)
|
|
|
|
definition = self.set_defaults(resource, definition)
|
|
|
|
result = self.perform_action(resource, definition)
|
|
|
|
result = self.perform_action(resource, definition)
|
|
|
|
if self.params.get('wait') and self.params.get('state') == 'present':
|
|
|
|
if self.params.get('wait') and self.params.get('state') == 'present':
|
|
|
|
result['result'] = self._wait_for_creation(resource, result['result']['metadata']['uid'])
|
|
|
|
result['result'] = self._wait_for_creation(resource, result['result'])
|
|
|
|
|
|
|
|
|
|
|
|
self.exit_json(**result)
|
|
|
|
self.exit_json(**result)
|
|
|
|
|
|
|
|
|
|
|
|