Преглед изворни кода

Merge pull request #4003 from lhuard1A/fix_registry_ose_3.2

Merged by openshift-bot
OpenShift Bot пре 8 година
родитељ
комит
468531c30e

+ 25 - 16
roles/lib_openshift/library/oc_adm_registry.py

@@ -2538,25 +2538,34 @@ class Registry(OpenShiftCLI):
     def run_ansible(params, check_mode):
         '''run idempotent ansible code'''
 
+        registry_options = {'images': {'value': params['images'], 'include': True},
+                            'latest_images': {'value': params['latest_images'], 'include': True},
+                            'labels': {'value': params['labels'], 'include': True},
+                            'ports': {'value': ','.join(params['ports']), 'include': True},
+                            'replicas': {'value': params['replicas'], 'include': True},
+                            'selector': {'value': params['selector'], 'include': True},
+                            'service_account': {'value': params['service_account'], 'include': True},
+                            'mount_host': {'value': params['mount_host'], 'include': True},
+                            'env_vars': {'value': params['env_vars'], 'include': False},
+                            'volume_mounts': {'value': params['volume_mounts'], 'include': False},
+                            'edits': {'value': params['edits'], 'include': False},
+                            'tls_key': {'value': params['tls_key'], 'include': True},
+                            'tls_certificate': {'value': params['tls_certificate'], 'include': True},
+                           }
+
+        # Do not always pass the daemonset and enforce-quota parameters because they are not understood
+        # by old versions of oc.
+        # Default value is false. So, it's safe to not pass an explicit false value to oc versions which
+        # understand these parameters.
+        if params['daemonset']:
+            registry_options['daemonset'] = {'value': params['daemonset'], 'include': True}
+        if params['enforce_quota']:
+            registry_options['enforce_quota'] = {'value': params['enforce_quota'], 'include': True}
+
         rconfig = RegistryConfig(params['name'],
                                  params['namespace'],
                                  params['kubeconfig'],
-                                 {'images': {'value': params['images'], 'include': True},
-                                  'latest_images': {'value': params['latest_images'], 'include': True},
-                                  'labels': {'value': params['labels'], 'include': True},
-                                  'ports': {'value': ','.join(params['ports']), 'include': True},
-                                  'replicas': {'value': params['replicas'], 'include': True},
-                                  'selector': {'value': params['selector'], 'include': True},
-                                  'service_account': {'value': params['service_account'], 'include': True},
-                                  'mount_host': {'value': params['mount_host'], 'include': True},
-                                  'env_vars': {'value': params['env_vars'], 'include': False},
-                                  'volume_mounts': {'value': params['volume_mounts'], 'include': False},
-                                  'edits': {'value': params['edits'], 'include': False},
-                                  'enforce_quota': {'value': params['enforce_quota'], 'include': True},
-                                  'daemonset': {'value': params['daemonset'], 'include': True},
-                                  'tls_key': {'value': params['tls_key'], 'include': True},
-                                  'tls_certificate': {'value': params['tls_certificate'], 'include': True},
-                                 })
+                                 registry_options)
 
 
         ocregistry = Registry(rconfig, params['debug'])

+ 25 - 16
roles/lib_openshift/src/class/oc_adm_registry.py

@@ -331,25 +331,34 @@ class Registry(OpenShiftCLI):
     def run_ansible(params, check_mode):
         '''run idempotent ansible code'''
 
+        registry_options = {'images': {'value': params['images'], 'include': True},
+                            'latest_images': {'value': params['latest_images'], 'include': True},
+                            'labels': {'value': params['labels'], 'include': True},
+                            'ports': {'value': ','.join(params['ports']), 'include': True},
+                            'replicas': {'value': params['replicas'], 'include': True},
+                            'selector': {'value': params['selector'], 'include': True},
+                            'service_account': {'value': params['service_account'], 'include': True},
+                            'mount_host': {'value': params['mount_host'], 'include': True},
+                            'env_vars': {'value': params['env_vars'], 'include': False},
+                            'volume_mounts': {'value': params['volume_mounts'], 'include': False},
+                            'edits': {'value': params['edits'], 'include': False},
+                            'tls_key': {'value': params['tls_key'], 'include': True},
+                            'tls_certificate': {'value': params['tls_certificate'], 'include': True},
+                           }
+
+        # Do not always pass the daemonset and enforce-quota parameters because they are not understood
+        # by old versions of oc.
+        # Default value is false. So, it's safe to not pass an explicit false value to oc versions which
+        # understand these parameters.
+        if params['daemonset']:
+            registry_options['daemonset'] = {'value': params['daemonset'], 'include': True}
+        if params['enforce_quota']:
+            registry_options['enforce_quota'] = {'value': params['enforce_quota'], 'include': True}
+
         rconfig = RegistryConfig(params['name'],
                                  params['namespace'],
                                  params['kubeconfig'],
-                                 {'images': {'value': params['images'], 'include': True},
-                                  'latest_images': {'value': params['latest_images'], 'include': True},
-                                  'labels': {'value': params['labels'], 'include': True},
-                                  'ports': {'value': ','.join(params['ports']), 'include': True},
-                                  'replicas': {'value': params['replicas'], 'include': True},
-                                  'selector': {'value': params['selector'], 'include': True},
-                                  'service_account': {'value': params['service_account'], 'include': True},
-                                  'mount_host': {'value': params['mount_host'], 'include': True},
-                                  'env_vars': {'value': params['env_vars'], 'include': False},
-                                  'volume_mounts': {'value': params['volume_mounts'], 'include': False},
-                                  'edits': {'value': params['edits'], 'include': False},
-                                  'enforce_quota': {'value': params['enforce_quota'], 'include': True},
-                                  'daemonset': {'value': params['daemonset'], 'include': True},
-                                  'tls_key': {'value': params['tls_key'], 'include': True},
-                                  'tls_certificate': {'value': params['tls_certificate'], 'include': True},
-                                 })
+                                 registry_options)
 
 
         ocregistry = Registry(rconfig, params['debug'])

+ 1 - 1
roles/lib_openshift/src/test/unit/test_oc_adm_registry.py

@@ -254,7 +254,7 @@ class RegistryTest(unittest.TestCase):
         mock_cmd.assert_has_calls([
             mock.call(['oc', 'get', 'dc', 'docker-registry', '-o', 'json', '-n', 'default'], None),
             mock.call(['oc', 'get', 'svc', 'docker-registry', '-o', 'json', '-n', 'default'], None),
-            mock.call(['oc', 'adm', 'registry', '--daemonset=False', '--enforce-quota=False',
+            mock.call(['oc', 'adm', 'registry',
                        '--ports=5000', '--replicas=1', '--selector=type=infra',
                        '--service-account=registry', '--dry-run=True', '-o', 'json', '-n', 'default'], None),
             mock.call(['oc', 'create', '-f', mock.ANY, '-n', 'default'], None),