Add modify_only_with_source
Currently the modify_only_with_labels has to query the container registry to see what containers we should modify. We can use the source in from our service to container mapping to limit which containers we want to update. In the upstream CI, we only want to modify the kolla or tripleo containers as we want to prevent ceph and other related containers from being updated. Change-Id: I4bff2b96f7b13bde808f929c3567dcf167f1eacd Related-Bug: #1889122
This commit is contained in:
parent
fb0ec2ffd0
commit
f4d312f186
@ -0,0 +1,6 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Added `modify_only_with_source` to the ContainerImagePrepare set that can
|
||||
be used to limit modify container images to a specific image_source as
|
||||
defined in the services to container images mapping.
|
@ -180,6 +180,7 @@ def container_images_prepare_multi(environment, roles_data, dry_run=False,
|
||||
modify_role = cip_entry.get('modify_role')
|
||||
modify_vars = cip_entry.get('modify_vars')
|
||||
modify_only_with_labels = cip_entry.get('modify_only_with_labels')
|
||||
modify_only_with_source = cip_entry.get('modify_only_with_source')
|
||||
modify_append_tag = cip_entry.get('modify_append_tag',
|
||||
time.strftime(
|
||||
'-modified-%Y%m%d%H%M%S'))
|
||||
@ -208,6 +209,7 @@ def container_images_prepare_multi(environment, roles_data, dry_run=False,
|
||||
modify_role=modify_role,
|
||||
modify_vars=modify_vars,
|
||||
modify_only_with_labels=modify_only_with_labels,
|
||||
modify_only_with_source=modify_only_with_source,
|
||||
mirrors=mirrors,
|
||||
registry_credentials=creds,
|
||||
multi_arch=multi_arch,
|
||||
@ -249,6 +251,7 @@ def container_images_prepare(template_file=DEFAULT_TEMPLATE_FILE,
|
||||
output_images_file=None, tag_from_label=None,
|
||||
append_tag=None, modify_role=None,
|
||||
modify_vars=None, modify_only_with_labels=None,
|
||||
modify_only_with_source=None,
|
||||
mirrors=None, registry_credentials=None,
|
||||
multi_arch=False, lock=None):
|
||||
"""Perform container image preparation
|
||||
@ -276,6 +279,9 @@ def container_images_prepare(template_file=DEFAULT_TEMPLATE_FILE,
|
||||
:param modify_vars: dict of variables to pass to modify_role
|
||||
:param modify_only_with_labels: only modify the container images with the
|
||||
given labels
|
||||
:param modify_only_with_source: only modify the container images from a
|
||||
image_source in the tripleo-common service
|
||||
to container mapping (e.g. kolla/tripleo)
|
||||
:param mirrors: dict of registry netloc values to mirror urls
|
||||
:param registry_credentials: dict of registry netloc values to
|
||||
authentication credentials for that registry.
|
||||
@ -341,18 +347,27 @@ def container_images_prepare(template_file=DEFAULT_TEMPLATE_FILE,
|
||||
entry['imagename'] = '%s:%s' % (
|
||||
image_no_tag, image_version_tags[image_no_tag])
|
||||
|
||||
images_with_labels = []
|
||||
if modify_only_with_labels:
|
||||
images_with_labels = uploader.filter_images_with_labels(
|
||||
images, modify_only_with_labels)
|
||||
|
||||
images_with_source = []
|
||||
if modify_only_with_source:
|
||||
images_with_source = [i.get('imagename') for i in result
|
||||
if i.get('image_source', '')
|
||||
in modify_only_with_source]
|
||||
|
||||
params = {}
|
||||
modify_append_tag = append_tag
|
||||
for entry in result:
|
||||
imagename = entry.get('imagename', '')
|
||||
append_tag = ''
|
||||
if modify_role and (
|
||||
(not modify_only_with_labels) or
|
||||
imagename in images_with_labels):
|
||||
(not modify_only_with_labels
|
||||
and not modify_only_with_source) or
|
||||
(imagename in images_with_labels or
|
||||
imagename in images_with_source)):
|
||||
entry['modify_role'] = modify_role
|
||||
if modify_append_tag:
|
||||
entry['modify_append_tag'] = modify_append_tag
|
||||
|
@ -861,6 +861,15 @@ class TestPrepare(base.TestCase):
|
||||
'modify_role': 'add-foo-plugin',
|
||||
'modify_only_with_labels': ['kolla_version'],
|
||||
'modify_vars': {'foo_version': '1.0.1'}
|
||||
}, {
|
||||
'set': mapping_args,
|
||||
'tag_from_label': 'bar',
|
||||
'includes': ['nova', 'neutron'],
|
||||
'push_destination': True,
|
||||
'modify_role': 'add-foo-plugin',
|
||||
'modify_only_with_source': ['kolla', 'tripleo'],
|
||||
'modify_vars': {'foo_version': '1.0.1'}
|
||||
|
||||
}]
|
||||
}
|
||||
}
|
||||
@ -887,6 +896,19 @@ class TestPrepare(base.TestCase):
|
||||
'push_destination': '192.0.2.1:8787'
|
||||
}]
|
||||
},
|
||||
{
|
||||
'image_params': {
|
||||
'BarImage': 't/bar:1.0',
|
||||
'BazImage': 't/baz:1.0'
|
||||
},
|
||||
'upload_data': [{
|
||||
'imagename': 't/bar:1.0',
|
||||
'push_destination': '192.0.2.1:8787'
|
||||
}, {
|
||||
'imagename': 't/baz:1.0',
|
||||
'push_destination': '192.0.2.1:8787'
|
||||
}]
|
||||
},
|
||||
]
|
||||
|
||||
image_params = kb.container_images_prepare_multi(env, roles_data,
|
||||
@ -906,6 +928,7 @@ class TestPrepare(base.TestCase):
|
||||
append_tag=mock.ANY,
|
||||
modify_role=None,
|
||||
modify_only_with_labels=None,
|
||||
modify_only_with_source=None,
|
||||
modify_vars=None,
|
||||
mirrors={
|
||||
'docker.io': 'http://192.0.2.2/reg/'
|
||||
@ -929,6 +952,31 @@ class TestPrepare(base.TestCase):
|
||||
append_tag=mock.ANY,
|
||||
modify_role='add-foo-plugin',
|
||||
modify_only_with_labels=['kolla_version'],
|
||||
modify_only_with_source=None,
|
||||
modify_vars={'foo_version': '1.0.1'},
|
||||
mirrors={
|
||||
'docker.io': 'http://192.0.2.2/reg/'
|
||||
},
|
||||
registry_credentials={
|
||||
'docker.io': {'my_username': 'my_password'}
|
||||
},
|
||||
multi_arch=False,
|
||||
lock=mock_lock
|
||||
),
|
||||
mock.call(
|
||||
excludes=None,
|
||||
includes=['nova', 'neutron'],
|
||||
mapping_args=mapping_args,
|
||||
output_env_file='image_params',
|
||||
output_images_file='upload_data',
|
||||
pull_source=None,
|
||||
push_destination='192.0.2.1:8787',
|
||||
service_filter=None,
|
||||
tag_from_label='bar',
|
||||
append_tag=mock.ANY,
|
||||
modify_role='add-foo-plugin',
|
||||
modify_only_with_labels=None,
|
||||
modify_only_with_source=['kolla', 'tripleo'],
|
||||
modify_vars={'foo_version': '1.0.1'},
|
||||
mirrors={
|
||||
'docker.io': 'http://192.0.2.2/reg/'
|
||||
@ -941,7 +989,7 @@ class TestPrepare(base.TestCase):
|
||||
)
|
||||
])
|
||||
|
||||
mock_im.assert_called_once()
|
||||
self.assertEqual(mock_im.call_count, 2)
|
||||
|
||||
self.assertEqual(
|
||||
{
|
||||
@ -1020,6 +1068,7 @@ class TestPrepare(base.TestCase):
|
||||
append_tag=mock.ANY,
|
||||
modify_role=None,
|
||||
modify_only_with_labels=None,
|
||||
modify_only_with_source=None,
|
||||
modify_vars=None,
|
||||
mirrors={},
|
||||
registry_credentials=None,
|
||||
@ -1039,6 +1088,7 @@ class TestPrepare(base.TestCase):
|
||||
append_tag=mock.ANY,
|
||||
modify_role='add-foo-plugin',
|
||||
modify_only_with_labels=['kolla_version'],
|
||||
modify_only_with_source=None,
|
||||
modify_vars={'foo_version': '1.0.1'},
|
||||
mirrors={},
|
||||
registry_credentials=None,
|
||||
@ -1129,6 +1179,7 @@ class TestPrepare(base.TestCase):
|
||||
append_tag=mock.ANY,
|
||||
modify_role=None,
|
||||
modify_only_with_labels=None,
|
||||
modify_only_with_source=None,
|
||||
modify_vars=None,
|
||||
mirrors={},
|
||||
registry_credentials=None,
|
||||
@ -1148,6 +1199,7 @@ class TestPrepare(base.TestCase):
|
||||
append_tag=mock.ANY,
|
||||
modify_role='add-foo-plugin',
|
||||
modify_only_with_labels=['kolla_version'],
|
||||
modify_only_with_source=None,
|
||||
modify_vars={'foo_version': '1.0.1'},
|
||||
mirrors={},
|
||||
registry_credentials=None,
|
||||
|
Loading…
Reference in New Issue
Block a user