Revert "kubevirt_pvc: default to wait; detect WaitForFirstConsumer (#53858)" (#53864)

This reverts commit 6567e05cbc.
pull/54029/head
Mariusz Mazur 6 years ago committed by ansibot
parent 968bedd8c2
commit 3398ce278c

@ -130,9 +130,10 @@ 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)."
default: true - "Unless used in conjuction with I(cdi_source), this might result in a timeout, as clusters may be configured
to not bind PVCs until first usage."
default: false
type: bool type: bool
wait_timeout: wait_timeout:
description: description:
@ -294,7 +295,7 @@ PVC_ARG_SPEC = {
'cdi_source': {'type': 'dict'}, 'cdi_source': {'type': 'dict'},
'wait': { 'wait': {
'type': 'bool', 'type': 'bool',
'default': True 'default': False
}, },
'wait_timeout': { 'wait_timeout': {
'type': 'int', 'type': 'int',
@ -372,26 +373,18 @@ 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, result): def _wait_for_creation(self, resource, uid):
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:
v1_events = self.client.resources.get(api_version='v1', kind='Event') for event in resource.watch(namespace=self.namespace, timeout=self.params.get('wait_timeout')):
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')
@ -449,7 +442,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']) result['result'] = self._wait_for_creation(resource, result['result']['metadata']['uid'])
self.exit_json(**result) self.exit_json(**result)

Loading…
Cancel
Save