0006-Add-support-for-docker-registry.patch 17.1 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438
From 4b397d8117776f500b6933d3a72fb91dbc8b8611 Mon Sep 17 00:00:00 2001
From: Hua Wang <wanghua.humble@gmail.com>
Date: Thu, 31 Mar 2016 18:16:52 +0800
Subject: [PATCH 6/8] Add support for docker registry

After this patch is merged, docker registry will be available.
We can push docker images into local repo on a bay node.

Change-Id: I1245bde7ef3173226617e60e6436759f433eb464
Partially-Implements: blueprint registryv2-in-master
---
 magnum/conductor/template_definition.py            | 17 ++++++
 magnum/opts.py                                     |  2 +
 .../fragments/configure-docker-registry.sh         | 12 ++---
 .../kubernetes/fragments/write-heat-params.yaml    |  9 ++--
 magnum/templates/kubernetes/kubecluster.yaml       | 45 ++--------------
 magnum/templates/kubernetes/kubeminion.yaml        | 46 +++++-----------
 .../conductor/handlers/test_k8s_bay_conductor.py   | 62 +++++++++++++++++++++-
 .../unit/conductor/test_template_definition.py     |  2 +
 8 files changed, 108 insertions(+), 87 deletions(-)

diff --git a/magnum/conductor/template_definition.py b/magnum/conductor/template_definition.py
index 8832307..c1a799b 100644
--- a/magnum/conductor/template_definition.py
+++ b/magnum/conductor/template_definition.py
@@ -64,8 +64,18 @@ template_def_opts = [
                 help=_('Enabled bay definition entry points.')),
 ]
 
+docker_registry_opts = [
+    cfg.StrOpt('swift_region',
+               help=_('Region name of Swift')),
+    cfg.StrOpt('swift_registry_container',
+               default='docker_registry',
+               help=_('Name of the container in Swift which docker registry '
+                      'stores images in'))
+]
+
 CONF = cfg.CONF
 CONF.register_opts(template_def_opts, group='bay')
+CONF.register_opts(docker_registry_opts, group='docker_registry')
 CONF.import_opt('trustee_domain_id', 'magnum.common.keystone', group='trust')
 
 
@@ -445,6 +455,8 @@ class K8sTemplateDefinition(BaseTemplateDefinition):
         self.add_parameter('tls_disabled',
                            baymodel_attr='tls_disabled',
                            required=True)
+        self.add_parameter('registry_enabled',
+                           baymodel_attr='registry_enabled')
 
         self.add_output('api_address',
                         bay_attr='api_address',
@@ -473,6 +485,11 @@ class K8sTemplateDefinition(BaseTemplateDefinition):
         for label in label_list:
             extra_params[label] = baymodel.labels.get(label)
 
+        if baymodel.registry_enabled:
+            extra_params['swift_region'] = CONF.docker_registry.swift_region
+            extra_params['registry_container'] = (
+                CONF.docker_registry.swift_registry_container)
+
         return super(K8sTemplateDefinition,
                      self).get_params(context, baymodel, bay,
                                       extra_params=extra_params,
diff --git a/magnum/opts.py b/magnum/opts.py
index e07bf2b..b8dc60e 100644
--- a/magnum/opts.py
+++ b/magnum/opts.py
@@ -59,4 +59,6 @@ def list_opts():
                             local_cert_manager.local_cert_manager_opts,
                             )),
         ('baymodel', magnum.api.validation.baymodel_opts),
+        ('docker_registry',
+         magnum.conductor.template_definition.docker_registry_opts)
     ]
diff --git a/magnum/templates/kubernetes/fragments/configure-docker-registry.sh b/magnum/templates/kubernetes/fragments/configure-docker-registry.sh
index 0364b78..f3cfcfa 100644
--- a/magnum/templates/kubernetes/fragments/configure-docker-registry.sh
+++ b/magnum/templates/kubernetes/fragments/configure-docker-registry.sh
@@ -15,12 +15,12 @@ storage:
   cache:
     layerinfo: inmemory
   swift:
-    authurl: "$REGISTRY_AUTH_URL"
-    region: "$REGISTRY_REGION"
-    username: "$REGISTRY_USERNAME"
-    password: "$REGISTRY_PASSWORD"
-    domain: "$REGISTRY_DOMAIN"
-    trustid: "$REGISTRY_TRUST_ID"
+    authurl: "$AUTH_URL"
+    region: "$SWIFT_REGION"
+    username: "$TRUSTEE_USERNAME"
+    password: "$TRUSTEE_PASSWORD"
+    domainid: "$TRUSTEE_DOMAIN_ID"
+    trustid: "$TRUST_ID"
     container: "$REGISTRY_CONTAINER"
     insecureskipverify: $REGISTRY_INSECURE
     chunksize: $REGISTRY_CHUNKSIZE
diff --git a/magnum/templates/kubernetes/fragments/write-heat-params.yaml b/magnum/templates/kubernetes/fragments/write-heat-params.yaml
index d3430dd..9208d8e 100644
--- a/magnum/templates/kubernetes/fragments/write-heat-params.yaml
+++ b/magnum/templates/kubernetes/fragments/write-heat-params.yaml
@@ -14,12 +14,7 @@ write_files:
       NETWORK_DRIVER="$NETWORK_DRIVER"
       REGISTRY_ENABLED="$REGISTRY_ENABLED"
       REGISTRY_PORT="$REGISTRY_PORT"
-      REGISTRY_AUTH_URL="$REGISTRY_AUTH_URL"
-      REGISTRY_REGION="$REGISTRY_REGION"
-      REGISTRY_USERNAME="$REGISTRY_USERNAME"
-      REGISTRY_PASSWORD="$REGISTRY_PASSWORD"
-      REGISTRY_DOMAIN="$REGISTRY_DOMAIN"
-      REGISTRY_TRUST_ID="$REGISTRY_TRUST_ID"
+      SWIFT_REGION="$SWIFT_REGION"
       REGISTRY_CONTAINER="$REGISTRY_CONTAINER"
       REGISTRY_INSECURE="$REGISTRY_INSECURE"
       REGISTRY_CHUNKSIZE="$REGISTRY_CHUNKSIZE"
@@ -31,6 +26,8 @@ write_files:
       NO_PROXY="$NO_PROXY"
       WAIT_CURL="$WAIT_CURL"
       TRUSTEE_USER_ID="$TRUSTEE_USER_ID"
+      TRUSTEE_USERNAME="$TRUSTEE_USERNAME"
       TRUSTEE_PASSWORD="$TRUSTEE_PASSWORD"
+      TRUSTEE_DOMAIN_ID="$TRUSTEE_DOMAIN_ID"
       TRUST_ID="$TRUST_ID"
       AUTH_URL="$AUTH_URL"
diff --git a/magnum/templates/kubernetes/kubecluster.yaml b/magnum/templates/kubernetes/kubecluster.yaml
index 7817687..6c633fb 100644
--- a/magnum/templates/kubernetes/kubecluster.yaml
+++ b/magnum/templates/kubernetes/kubecluster.yaml
@@ -126,37 +126,10 @@ parameters:
     description: port of registry service
     default: 5000
 
-  registry_username:
-    type: string
-    description: username used by docker registry
-    default: "username"
-
-  registry_password:
-    type: string
-    description: password used by docker registry
-    default: "password"
-    hidden: true
-
-  registry_domain:
-    type: string
-    description: domain used by docker registry
-    default: "domain"
-
-  registry_trust_id:
-    type: string
-    description: trust_id used by docker registry
-    default: "trust_id"
-    hidden: true
-
-  registry_auth_url:
-    type: string
-    description: auth_url for keystone
-    default: "auth_url"
-
-  registry_region:
+  swift_region:
     type: string
     description: region of swift service
-    default: "region"
+    default: ""
 
   registry_container:
     type: string
@@ -242,28 +215,23 @@ parameters:
   trustee_domain_id:
     type: string
     description: domain id of the trustee
-    default: ""
 
   trustee_user_id:
     type: string
     description: user id of the trustee
-    default: ""
 
   trustee_username:
     type: string
     description: username of the trustee
-    default: ""
 
   trustee_password:
     type: string
     description: password of the trustee
-    default: ""
     hidden: true
 
   trust_id:
     type: string
     description: id of the trust which is used by the trustee
-    default: ""
     hidden: true
 
   auth_url:
@@ -351,12 +319,7 @@ resources:
           wait_condition_timeout: {get_param: wait_condition_timeout}
           registry_enabled: {get_param: registry_enabled}
           registry_port: {get_param: registry_port}
-          registry_username: {get_param: registry_username}
-          registry_password: {get_param: registry_password}
-          registry_domain: {get_param: registry_domain}
-          registry_trust_id: {get_param: registry_trust_id}
-          registry_auth_url: {get_param: registry_auth_url}
-          registry_region: {get_param: registry_region}
+          swift_region: {get_param: swift_region}
           registry_container: {get_param: registry_container}
           registry_insecure: {get_param: registry_insecure}
           registry_chunksize: {get_param: registry_chunksize}
@@ -369,7 +332,9 @@ resources:
           https_proxy: {get_param: https_proxy}
           no_proxy: {get_param: no_proxy}
           trustee_user_id: {get_param: trustee_user_id}
+          trustee_username: {get_param: trustee_username}
           trustee_password: {get_param: trustee_password}
+          trustee_domain_id: {get_param: trustee_domain_id}
           trust_id: {get_param: trust_id}
           auth_url: {get_param: auth_url}
 
diff --git a/magnum/templates/kubernetes/kubeminion.yaml b/magnum/templates/kubernetes/kubeminion.yaml
index 3322142..544fc3a 100644
--- a/magnum/templates/kubernetes/kubeminion.yaml
+++ b/magnum/templates/kubernetes/kubeminion.yaml
@@ -93,34 +93,7 @@ parameters:
     description: port of registry service
     default: 5000
 
-  registry_username:
-    type: string
-    description: username used by docker registry
-    default: "username"
-
-  registry_password:
-    type: string
-    description: password used by docker registry
-    default: "password"
-    hidden: true
-
-  registry_domain:
-    type: string
-    description: domain used by docker registry
-    default: "domain"
-
-  registry_trust_id:
-    type: string
-    description: trust_id used by docker registry
-    default: "trust_id"
-    hidden: true
-
-  registry_auth_url:
-    type: string
-    description: auth_url for keystone
-    default: "auth_url"
-
-  registry_region:
+  swift_region:
     type: string
     description: region of swift service
     default: "region"
@@ -162,11 +135,19 @@ parameters:
     description: no proxies for docker
     default: ""
 
+  trustee_domain_id:
+    type: string
+    description: domain id of the trustee
+
   trustee_user_id:
     type: string
     description: user id of the trustee
     default: ""
 
+  trustee_username:
+    type: string
+    description: username of the trustee
+
   trustee_password:
     type: string
     description: password of the trustee
@@ -218,12 +199,7 @@ resources:
             $NETWORK_DRIVER: {get_param: network_driver}
             $REGISTRY_ENABLED: {get_param: registry_enabled}
             $REGISTRY_PORT: {get_param: registry_port}
-            $REGISTRY_AUTH_URL: {get_param: registry_auth_url}
-            $REGISTRY_REGION: {get_param: registry_region}
-            $REGISTRY_USERNAME: {get_param: registry_username}
-            $REGISTRY_PASSWORD: {get_param: registry_password}
-            $REGISTRY_DOMAIN: {get_param: registry_domain}
-            $REGISTRY_TRUST_ID: {get_param: registry_trust_id}
+            $SWIFT_REGION: {get_param: swift_region}
             $REGISTRY_CONTAINER: {get_param: registry_container}
             $REGISTRY_INSECURE: {get_param: registry_insecure}
             $REGISTRY_CHUNKSIZE: {get_param: registry_chunksize}
@@ -234,7 +210,9 @@ resources:
             $HTTPS_PROXY: {get_param: https_proxy}
             $NO_PROXY: {get_param: no_proxy}
             $WAIT_CURL: {get_attr: [minion_wait_handle, curl_cli]}
+            $TRUSTEE_DOMAIN_ID: {get_param: trustee_domain_id}
             $TRUSTEE_USER_ID: {get_param: trustee_user_id}
+            $TRUSTEE_USERNAME: {get_param: trustee_username}
             $TRUSTEE_PASSWORD: {get_param: trustee_password}
             $TRUST_ID: {get_param: trust_id}
             $AUTH_URL: {get_param: auth_url}
diff --git a/magnum/tests/unit/conductor/handlers/test_k8s_bay_conductor.py b/magnum/tests/unit/conductor/handlers/test_k8s_bay_conductor.py
index 7f2e2c3..37665b7 100644
--- a/magnum/tests/unit/conductor/handlers/test_k8s_bay_conductor.py
+++ b/magnum/tests/unit/conductor/handlers/test_k8s_bay_conductor.py
@@ -43,7 +43,8 @@ class TestBayConductorWithK8s(base.TestCase):
                        'flannel_network_subnetlen': '26',
                        'flannel_use_vxlan': 'yes'},
             'tls_disabled': False,
-            'server_type': 'vm'
+            'server_type': 'vm',
+            'registry_enabled': False
         }
         self.bay_dict = {
             'uuid': 'bay-xx-xx-xx-xx',
@@ -143,6 +144,7 @@ class TestBayConductorWithK8s(base.TestCase):
             'bay_uuid': self.bay_dict['uuid'],
             'magnum_url': self.mock_osc.magnum_url.return_value,
             'tls_disabled': False,
+            'registry_enabled': False,
             'trustee_domain_id': '3527620c-b220-4f37-9ebc-6e63a81a9b2f',
             'trustee_username': 'fake_trustee',
             'trustee_password': 'fake_trustee_password',
@@ -156,6 +158,61 @@ class TestBayConductorWithK8s(base.TestCase):
         self.assertEqual(expected, definition)
 
     @patch('magnum.objects.BayModel.get_by_uuid')
+    def test_extract_template_definition_with_registry(
+            self,
+            mock_objects_baymodel_get_by_uuid):
+        self.baymodel_dict['registry_enabled'] = True
+        baymodel = objects.BayModel(self.context, **self.baymodel_dict)
+        mock_objects_baymodel_get_by_uuid.return_value = baymodel
+        bay = objects.Bay(self.context, **self.bay_dict)
+
+        cfg.CONF.set_override('swift_region',
+                              'RegionOne',
+                              group='docker_registry')
+
+        (template_path,
+         definition) = bay_conductor._extract_template_definition(self.context,
+                                                                  bay)
+
+        expected = {
+            'auth_url': 'http://192.168.10.10:5000/v3',
+            'bay_uuid': '5d12f6fd-a196-4bf0-ae4c-1f639a523a52',
+            'discovery_url': 'https://discovery.etcd.io/test',
+            'dns_nameserver': 'dns_nameserver',
+            'docker_volume_size': 20,
+            'external_network': 'external_network_id',
+            'flannel_backend': 'vxlan',
+            'flannel_network_cidr': '10.101.0.0/16',
+            'flannel_network_subnetlen': '26',
+            'http_proxy': 'http_proxy',
+            'https_proxy': 'https_proxy',
+            'magnum_url': 'http://127.0.0.1:9511/v1',
+            'master_flavor': 'master_flavor_id',
+            'minion_flavor': 'flavor_id',
+            'network_driver': 'network_driver',
+            'no_proxy': 'no_proxy',
+            'number_of_masters': 1,
+            'number_of_minions': 1,
+            'region_name': 'RegionOne',
+            'registry_container': 'docker_registry',
+            'registry_enabled': True,
+            'server_image': 'image_id',
+            'ssh_key_name': 'keypair_id',
+            'swift_region': 'RegionOne',
+            'tenant_name': 'fake_tenant',
+            'tls_disabled': False,
+            'trust_id': 'bd11efc5-d4e2-4dac-bbce-25e348ddf7de',
+            'trustee_domain_id': '3527620c-b220-4f37-9ebc-6e63a81a9b2f',
+            'trustee_password': 'fake_trustee_password',
+            'trustee_user_id': '7b489f04-b458-4541-8179-6a48a553e656',
+            'trustee_username': 'fake_trustee',
+            'username': 'fake_user',
+            'volume_driver': 'volume_driver'
+        }
+
+        self.assertEqual(expected, definition)
+
+    @patch('magnum.objects.BayModel.get_by_uuid')
     def test_extract_template_definition_coreos_with_disovery(
             self,
             mock_objects_baymodel_get_by_uuid):
@@ -186,6 +243,7 @@ class TestBayConductorWithK8s(base.TestCase):
             'flannel_network_subnetlen': '26',
             'flannel_use_vxlan': 'yes',
             'tls_disabled': False,
+            'registry_enabled': False,
             'trustee_domain_id': '3527620c-b220-4f37-9ebc-6e63a81a9b2f',
             'trustee_username': 'fake_trustee',
             'trustee_password': 'fake_trustee_password',
@@ -231,6 +289,7 @@ class TestBayConductorWithK8s(base.TestCase):
             'flannel_network_subnetlen': '26',
             'flannel_use_vxlan': 'yes',
             'tls_disabled': False,
+            'registry_enabled': False,
             'trustee_domain_id': '3527620c-b220-4f37-9ebc-6e63a81a9b2f',
             'trustee_username': 'fake_trustee',
             'trustee_password': 'fake_trustee_password',
@@ -349,6 +408,7 @@ class TestBayConductorWithK8s(base.TestCase):
             'bay_uuid': self.bay_dict['uuid'],
             'magnum_url': self.mock_osc.magnum_url.return_value,
             'tls_disabled': False,
+            'registry_enabled': False,
             'trustee_domain_id': '3527620c-b220-4f37-9ebc-6e63a81a9b2f',
             'trustee_username': 'fake_trustee',
             'trustee_password': 'fake_trustee_password',
diff --git a/magnum/tests/unit/conductor/test_template_definition.py b/magnum/tests/unit/conductor/test_template_definition.py
index add6756..4ee75ae 100644
--- a/magnum/tests/unit/conductor/test_template_definition.py
+++ b/magnum/tests/unit/conductor/test_template_definition.py
@@ -175,6 +175,7 @@ class AtomicK8sTemplateDefinitionTestCase(base.TestCase):
         mock_context.auth_token = 'AUTH_TOKEN'
         mock_baymodel = mock.MagicMock()
         mock_baymodel.tls_disabled = False
+        mock_baymodel.registry_enabled = False
         mock_bay = mock.MagicMock()
         mock_bay.uuid = 'bay-xx-xx-xx-xx'
         del mock_bay.stack_id
@@ -225,6 +226,7 @@ class AtomicK8sTemplateDefinitionTestCase(base.TestCase):
         mock_context.auth_token = 'AUTH_TOKEN'
         mock_baymodel = mock.MagicMock()
         mock_baymodel.tls_disabled = True
+        mock_baymodel.registry_enabled = False
         mock_bay = mock.MagicMock()
         mock_bay.uuid = 'bay-xx-xx-xx-xx'
         del mock_bay.stack_id
-- 
2.5.5