diff --git a/doc/source/admin/image-building.rst b/doc/source/admin/image-building.rst index aa100f4a3d..9e87fbf1b6 100644 --- a/doc/source/admin/image-building.rst +++ b/doc/source/admin/image-building.rst @@ -130,10 +130,11 @@ installed from upstream sources. The default method of the OpenStack install is ones. The locations of OpenStack source code are written in ``kolla-build.conf``. -The source type supports ``url``, ``git``, and ``local``. The location of -the ``local`` source type can point to either a directory containing the source -code or to a tarball of the source. The ``local`` source type permits to make -the best use of the Docker cache. +The source's ``type`` supports ``url``, ``git`` and ``local``. The +``location`` of the ``local`` source type can point to either a directory +containing the source code or to a tarball of the source. The ``local`` source +type permits to make the best use of the Docker cache. A source may be +disabled by setting ``enabled`` to ``False``. The ``kolla-build.conf`` file could look like this: @@ -156,6 +157,7 @@ The ``kolla-build.conf`` file could look like this: [ironic-base] type = local location = /tmp/ironic.tar.gz + enabled = False .. note:: @@ -369,8 +371,11 @@ The template now becomes: python3 -m pip --no-cache-dir install /plugins/* {% endblock %} -Many of the Dockerfiles already copy the ``plugins-archive`` to the image and -install available plugins at build time. +Some plugins are installed by default. For images with default plugins, the +Dockerfiles already copy the ``plugins-archive`` to the image and install +available plugins at build time. These default plugins may be disabled by +setting ``enabled`` to ``False`` in the relevant plugin source configuration +section in ``kolla-build.conf``. Neutron plugins ^^^^^^^^^^^^^^^ diff --git a/kolla/common/config.py b/kolla/common/config.py index 25e5821329..aff96fbf05 100755 --- a/kolla/common/config.py +++ b/kolla/common/config.py @@ -955,7 +955,7 @@ USERS = { } -def get_source_opts(type_=None, location=None, reference=None): +def get_source_opts(type_=None, location=None, reference=None, enabled=True): return [cfg.StrOpt('type', choices=['local', 'git', 'url'], default=type_, help='Source location type'), @@ -963,7 +963,9 @@ def get_source_opts(type_=None, location=None, reference=None): help='The location for source install'), cfg.StrOpt('reference', default=reference, help=('Git reference to pull, commit sha, tag ' - 'or branch name'))] + 'or branch name')), + cfg.BoolOpt('enabled', default=enabled, + help=('Whether the source is enabled'))] def get_user_opts(uid, gid, group): @@ -990,7 +992,8 @@ def gen_all_source_opts(): type_ = params['type'] location = params['location'] reference = params.get('reference') - yield name, get_source_opts(type_, location, reference) + enabled = params.get('enabled', True) + yield name, get_source_opts(type_, location, reference, enabled) def list_opts(): diff --git a/kolla/image/build.py b/kolla/image/build.py index b137059fa6..0ed8cb903d 100755 --- a/kolla/image/build.py +++ b/kolla/image/build.py @@ -361,6 +361,10 @@ class BuildTask(DockerTask): return followups def process_source(self, image, source): + if not source['enabled']: + self.logger.debug("Skipping disabled source %s", source['name']) + return + dest_archive = os.path.join(image.path, source['name'] + '-archive') if source.get('type') == 'url': @@ -458,7 +462,8 @@ class BuildTask(DockerTask): archive_path = self.process_source(image, item) if image.status in STATUS_ERRORS: raise ArchivingError - archives.append(archive_path) + if archive_path: + archives.append(archive_path) if archives: for archive in archives: with tarfile.open(archive, 'r') as archive_tar: @@ -1206,6 +1211,7 @@ class KollaWorker(object): installation['name'] = section if installation['type'] == 'git': installation['reference'] = self.conf[section]['reference'] + installation['enabled'] = self.conf[section]['enabled'] return installation all_sections = (set(self.conf._groups.keys()) | diff --git a/kolla/tests/test_build.py b/kolla/tests/test_build.py index 0200fadd72..6174d5dd8a 100644 --- a/kolla/tests/test_build.py +++ b/kolla/tests/test_build.py @@ -254,7 +254,8 @@ class TasksTest(base.TestCase): self.image.source = { 'source': 'http://fake/source', 'type': 'url', - 'name': 'fake-image-base' + 'name': 'fake-image-base', + 'enabled': True } push_queue = mock.Mock() builder = build.BuildTask(self.conf, self.image, push_queue) @@ -276,17 +277,21 @@ class TasksTest(base.TestCase): def test_process_source(self, mock_get, mock_client, mock_rmtree, mock_copyfile, mock_utime): for source in [{'source': 'http://fake/source1', 'type': 'url', - 'name': 'fake-image-base1', - 'reference': 'http://fake/reference1'}, + 'name': 'fake-image-base1', + 'reference': 'http://fake/reference1', + 'enabled': True}, {'source': 'http://fake/source2', 'type': 'git', - 'name': 'fake-image-base2', - 'reference': 'http://fake/reference2'}, + 'name': 'fake-image-base2', + 'reference': 'http://fake/reference2', + 'enabled': True}, {'source': 'http://fake/source3', 'type': 'local', - 'name': 'fake-image-base3', - 'reference': 'http://fake/reference3'}, + 'name': 'fake-image-base3', + 'reference': 'http://fake/reference3', + 'enabled': True}, {'source': 'http://fake/source4', 'type': None, - 'name': 'fake-image-base4', - 'reference': 'http://fake/reference4'}]: + 'name': 'fake-image-base4', + 'reference': 'http://fake/reference4', + 'enabled': True}]: self.image.source = source push_queue = mock.Mock() builder = build.BuildTask(self.conf, self.image, push_queue) @@ -305,7 +310,8 @@ class TasksTest(base.TestCase): mock_path_exists): source = {'source': 'http://fake/source1', 'type': 'git', 'name': 'fake-image1', - 'reference': 'fake/reference1'} + 'reference': 'fake/reference1', + 'enabled': True} self.image.source = source self.image.path = "fake_image_path" @@ -385,7 +391,8 @@ class KollaWorkerTest(base.TestCase): 'name': 'neutron-server-plugin-networking-arista', 'reference': 'master', 'source': 'https://opendev.org/x/networking-arista', - 'type': 'git' + 'type': 'git', + 'enabled': True } found = False @@ -399,6 +406,30 @@ class KollaWorkerTest(base.TestCase): if not found: self.fail('Can not find the expected neutron arista plugin') + def test_build_image_list_skips_disabled_plugins(self): + + self.conf.set_override('install_type', 'source') + self.conf.set_override('enabled', False, + 'neutron-base-plugin-networking-baremetal') + + kolla = build.KollaWorker(self.conf) + kolla.setup_working_dir() + kolla.find_dockerfiles() + kolla.create_dockerfiles() + kolla.build_image_list() + disabled_plugin = 'neutron-base-plugin-networking-baremetal' + + found = False + for image in kolla.images: + if image.name == 'neutron-server': + for plugin in image.plugins: + if plugin == disabled_plugin: + found = True + break + break + if found: + self.fail('Found disabled neutron networking-baremetal plugin') + def test_build_image_list_plugin_parsing(self): """Ensure regex used to parse plugins adds them to the correct image""" self.conf.set_override('install_type', 'source') diff --git a/releasenotes/notes/source-enable-flag-9ce10be097739214.yaml b/releasenotes/notes/source-enable-flag-9ce10be097739214.yaml new file mode 100644 index 0000000000..bbbc8c5f9c --- /dev/null +++ b/releasenotes/notes/source-enable-flag-9ce10be097739214.yaml @@ -0,0 +1,7 @@ +--- +features: + - | + Adds a new ``enabled`` option to each source definition. This allows + sources, plugins or additions for each source image to be disabled + individually. This may be used to reduce image sizes, or restrict the + dependencies necessary to build images.