From f51e0082fe17f14aec5e14facc143986f47cf260 Mon Sep 17 00:00:00 2001 From: Kenny Woodson Date: Fri, 14 Jul 2017 08:59:02 -0400 Subject: Fixing needs_update comparison. Added a small pause for race conditions. Fixed doc. Fix kind to storageclass --- roles/lib_openshift/library/oc_storageclass.py | 28 +++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'roles/lib_openshift/library') diff --git a/roles/lib_openshift/library/oc_storageclass.py b/roles/lib_openshift/library/oc_storageclass.py index fa5a1ab15..5ca2e23a7 100644 --- a/roles/lib_openshift/library/oc_storageclass.py +++ b/roles/lib_openshift/library/oc_storageclass.py @@ -130,7 +130,7 @@ EXAMPLES = ''' encrypted: 'true' kmsKeyId: '' provisioner: aws-ebs - default_sc: False + default_storage_class: False register: sc_out notify: - restart openshift master services @@ -1430,7 +1430,7 @@ class StorageClassConfig(object): provisioner=None, parameters=None, annotations=None, - default_sc="false", + default_storage_class="false", api_version='v1', kubeconfig='/etc/origin/master/admin.kubeconfig'): ''' constructor for handling storageclass options ''' @@ -1439,7 +1439,7 @@ class StorageClassConfig(object): self.annotations = annotations self.provisioner = provisioner self.api_version = api_version - self.default_sc = default_sc + self.default_storage_class = str(default_storage_class).lower() self.kubeconfig = kubeconfig self.data = {} @@ -1453,7 +1453,10 @@ class StorageClassConfig(object): self.data['metadata']['name'] = self.name self.data['metadata']['annotations'] = {} - self.data['metadata']['annotations']['storageclass.beta.kubernetes.io/is-default-class'] = self.default_sc + if self.annotations is not None: + self.data['metadata']['annotations'] = self.annotations + + self.data['metadata']['annotations']['storageclass.beta.kubernetes.io/is-default-class'] = self.default_storage_class if self.provisioner is None: self.data['provisioner'] = 'kubernetes.io/aws-ebs' @@ -1497,7 +1500,7 @@ class StorageClass(Yedit): # pylint: disable=too-many-instance-attributes class OCStorageClass(OpenShiftCLI): ''' Class to wrap the oc command line tools ''' - kind = 'sc' + kind = 'storageclass' # pylint allows 5 # pylint: disable=too-many-arguments @@ -1539,15 +1542,22 @@ class OCStorageClass(OpenShiftCLI): '''update the object''' # parameters are currently unable to be updated. need to delete and recreate self.delete() + # pause here and attempt to wait for delete. + # Better option would be to poll + time.sleep(5) return self.create() def needs_update(self): ''' verify an update is needed ''' # check if params have updated - if self.storage_class.get_parameters() == self.config.parameters: - return False + if self.storage_class.get_parameters() != self.config.parameters: + return True - return True + for anno_key, anno_value in self.storage_class.get_annotations().items(): + if 'is-default-class' in anno_key and anno_value != self.config.default_storage_class: + return True + + return False @staticmethod # pylint: disable=too-many-return-statements,too-many-branches @@ -1560,7 +1570,7 @@ class OCStorageClass(OpenShiftCLI): parameters=params['parameters'], annotations=params['annotations'], api_version="storage.k8s.io/{}".format(params['api_version']), - default_sc=params['default_storage_class'], + default_storage_class=params.get('default_storage_class', 'false'), kubeconfig=params['kubeconfig'], ) -- cgit v1.2.3