Browse Source

Fixing needs_update comparison. Added a small pause for race conditions. Fixed doc. Fix kind to storageclass

Kenny Woodson 7 years ago
parent
commit
f51e0082fe

+ 19 - 9
roles/lib_openshift/library/oc_storageclass.py

@@ -130,7 +130,7 @@ EXAMPLES = '''
       encrypted: 'true'
       kmsKeyId: '<full kms key arn>'
     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'],
                                     )
 

+ 12 - 5
roles/lib_openshift/src/class/oc_storageclass.py

@@ -4,7 +4,7 @@
 # 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
@@ -46,15 +46,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
+
+        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 True
+        return False
 
     @staticmethod
     # pylint: disable=too-many-return-statements,too-many-branches
@@ -67,7 +74,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'],
                                     )
 

+ 1 - 1
roles/lib_openshift/src/doc/storageclass

@@ -79,7 +79,7 @@ EXAMPLES = '''
       encrypted: 'true'
       kmsKeyId: '<full kms key arn>'
     provisioner: aws-ebs
-    default_sc: False
+    default_storage_class: False
   register: sc_out
   notify:
   - restart openshift master services

+ 6 - 3
roles/lib_openshift/src/lib/storageclass.py

@@ -11,7 +11,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 '''
@@ -20,7 +20,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 = {}
 
@@ -34,7 +34,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'