Split off Ceph related container images

This commit updates the default tripleo_containers jinja template
splitting off the Ceph related container images.
With this new approach pulling the ceph containers is optional,
and can be avoided by setting the 'ceph_images' boolean to False.
To make this possible, a new jinja template processing approach
has been introduced, and a template basedir parameter (required
by the jinja loader) has been added to the BaseImageManager.

In particular:

- the 'template_dir' parameter represents the location path to the
  j2 templates that can be included in the main tripleo containers
  template; a default location (which matches with the default j2
  path) has been added, but if nothing is passed the old behavior
  is maintained;

- Two more 'ceph_' prefixed containers, required to deploy the Ceph
  Ingress daemon are added, and they are supposed to match with the
  tripleo-heat-templates 'OS::TripleO::Services::CephIngress' service.
  The Ingress daemon won’t be baked into the Ceph daemon container,
  hence `tripleo container image prepare` should be executed to pull
  the new container images/tags in the undercloud as made for the
  Ceph Dashboard and the regular Ceph image.

Change-Id: I7e337596b653cf635f07a36606e9f673044402a3
This commit is contained in:
Francesco Pantano 2022-01-12 13:24:13 +01:00
parent 3eae6a0ec0
commit 08a8118f1b
No known key found for this signature in database
GPG Key ID: 0458D4D1F41BD75C
9 changed files with 174 additions and 64 deletions

55
container-images/ceph.j2 Normal file
View File

@ -0,0 +1,55 @@
- imagename: "{{ceph_namespace}}/{{ceph_image}}:{{ceph_tag}}"
image_source: ceph
params:
- ContainerCephDaemonImage
services:
- OS::TripleO::Services::CephClient
- OS::TripleO::Services::CephExternal
- OS::TripleO::Services::CephMds
- OS::TripleO::Services::CephMgr
- OS::TripleO::Services::CephMon
- OS::TripleO::Services::CephOSD
- OS::TripleO::Services::CephRgw
- OS::TripleO::Services::CephRbdMirror
- imagename: "{{ceph_prometheus_namespace}}/{{ceph_prometheus_image}}:{{ceph_prometheus_tag}}"
image_source: prom
params:
- PrometheusContainerImage
services:
- OS::TripleO::Services::CephGrafana
- imagename: "{{ceph_alertmanager_namespace}}/{{ceph_alertmanager_image}}:{{ceph_alertmanager_tag}}"
image_source: prom
params:
- AlertManagerContainerImage
services:
- OS::TripleO::Services::CephGrafana
- imagename: "{{ceph_node_exporter_namespace}}/{{ceph_node_exporter_image}}:{{ceph_node_exporter_tag}}"
image_source: prom
params:
- NodeExporterContainerImage
services:
- OS::TripleO::Services::CephGrafana
- imagename: "{{ceph_grafana_namespace}}/{{ceph_grafana_image}}:{{ceph_grafana_tag}}"
image_source: grafana
params:
- GrafanaContainerImage
services:
- OS::TripleO::Services::CephGrafana
- imagename: "{{ceph_keepalived_namespace}}/{{ceph_keepalived_image}}:{{ceph_keepalived_tag}}"
image_source: keepalived
params:
- KeepalivedContainerImage
services:
- OS::TripleO::Services::CephIngress
- imagename: "{{ceph_haproxy_namespace}}/{{ceph_haproxy_image}}:{{ceph_haproxy_tag}}"
image_source: haproxy
params:
- HaproxyContainerImage
services:
- OS::TripleO::Services::CephIngress

View File

@ -26,22 +26,32 @@ parameter_defaults:
# Container image name components for Ceph images.
# Only used if Ceph is deployed.
# Pass ceph_images: false to avoid pulling the Ceph related images
ceph_namespace: quay.io/ceph
ceph_image: daemon
ceph_tag: v6.0.6-stable-6.0-pacific-centos-8-x86_64
ceph_prometheus_namespace: quay.ceph.io/prometheus
ceph_prometheus_namespace: quay.io/prometheus
ceph_prometheus_image: prometheus
ceph_prometheus_tag: v2.7.2
ceph_prometheus_tag: v2.18.1
ceph_alertmanager_namespace: quay.ceph.io/prometheus
ceph_alertmanager_namespace: quay.io/prometheus
ceph_alertmanager_image: alertmanager
ceph_alertmanager_tag: v0.16.2
ceph_alertmanager_tag: v0.20.0
ceph_node_exporter_namespace: quay.ceph.io/prometheus
ceph_node_exporter_namespace: quay.io/prometheus
ceph_node_exporter_image: node-exporter
ceph_node_exporter_tag: v0.17.0
ceph_node_exporter_tag: v0.18.1
ceph_grafana_namespace: quay.ceph.io/app-sre
ceph_grafana_image: grafana
ceph_grafana_namespace: quay.io/ceph
ceph_grafana_image: ceph-grafana
ceph_grafana_tag: 6.7.4
ceph_haproxy_namespace: quay.io/ceph
ceph_haproxy_image: haproxy
ceph_haproxy_tag: 2.3
ceph_keepalived_namespace: quay.io/ceph
ceph_keepalived_image: keepalived
ceph_keepalived_tag: 2.1.5

View File

@ -167,14 +167,18 @@ container_images:
image_source: tripleo
- imagename: quay.io/ceph/daemon:v6.0.6-stable-6.0-pacific-centos-8-x86_64
image_source: ceph
- imagename: quay.ceph.io/prometheus/prometheus:v2.7.2
- imagename: quay.io/prometheus/prometheus:v2.18.1
image_source: prom
- imagename: quay.ceph.io/prometheus/alertmanager:v0.16.2
- imagename: quay.io/prometheus/alertmanager:v0.20.0
image_source: prom
- imagename: quay.ceph.io/prometheus/node-exporter:v0.17.0
- imagename: quay.io/prometheus/node-exporter:v0.18.1
image_source: prom
- imagename: quay.ceph.io/app-sre/grafana:6.7.4
- imagename: quay.io/ceph/ceph-grafana:6.7.4
image_source: grafana
- imagename: quay.io/ceph/keepalived:2.1.5
image_source: keepalived
- imagename: quay.io/ceph/haproxy:2.3
image_source: haproxy
- imagename: quay.io/tripleomaster/openstack-rsyslog:current-tripleo
image_source: tripleo
- imagename: quay.io/tripleomaster/openstack-unbound:current-tripleo

View File

@ -720,47 +720,9 @@ container_images_template:
- OS::TripleO::Services::SwiftRingBuilder
- OS::TripleO::Services::SwiftStorage
- imagename: "{{ceph_namespace}}/{{ceph_image}}:{{ceph_tag}}"
image_source: ceph
params:
- ContainerCephDaemonImage
services:
- OS::TripleO::Services::CephClient
- OS::TripleO::Services::CephExternal
- OS::TripleO::Services::CephMds
- OS::TripleO::Services::CephMgr
- OS::TripleO::Services::CephMon
- OS::TripleO::Services::CephOSD
- OS::TripleO::Services::CephRgw
- OS::TripleO::Services::CephRbdMirror
- imagename: "{{ceph_prometheus_namespace}}/{{ceph_prometheus_image}}:{{ceph_prometheus_tag}}"
image_source: prom
params:
- PrometheusContainerImage
services:
- OS::TripleO::Services::CephGrafana
- imagename: "{{ceph_alertmanager_namespace}}/{{ceph_alertmanager_image}}:{{ceph_alertmanager_tag}}"
image_source: prom
params:
- AlertManagerContainerImage
services:
- OS::TripleO::Services::CephGrafana
- imagename: "{{ceph_node_exporter_namespace}}/{{ceph_node_exporter_image}}:{{ceph_node_exporter_tag}}"
image_source: prom
params:
- NodeExporterContainerImage
services:
- OS::TripleO::Services::CephGrafana
- imagename: "{{ceph_grafana_namespace}}/{{ceph_grafana_image}}:{{ceph_grafana_tag}}"
image_source: grafana
params:
- GrafanaContainerImage
services:
- OS::TripleO::Services::CephGrafana
{% if ceph_images | default(true) %}
{% include 'ceph.j2' %}
{% endif %}
- imagename: "{{namespace}}/{{name_prefix}}rsyslog{{name_suffix}}:{{tag}}"
image_source: tripleo
@ -798,3 +760,4 @@ container_images_template:
- ContainerTripleoClientImage
services:
- OS::TripleO::Services::TripleoClient

View File

@ -0,0 +1,38 @@
---
features:
- |
Split off Ceph related container images
This change releases an update on the default tripleo_containers jinja
template, splitting off the Ceph related container images.
With this new approach pulling the ceph containers is optional, and can
be avoided by setting the `ceph_images` boolean to False.
e.g., passing something like the following::
parameter_defaults:
ContainerImagePrepare:
- push_destination: true
set:
name_prefix: openstack-
name_suffix: ''
namespace: quay.io/tripleomaster
neutron_driver: ovn
rhel_containers: false
tag: current-tripleo
ceph_images: false
ContainerImagePrepareDebug: true
ContainerImageRegistryCredentials: {}
avoid the ceph containers being pulled in the undercloud.
To make this possible, a new jinja template processing approach
has been introduced, and a template basedir parameter (required
by the jinja loader) has been added to the BaseImageManager.
Finallym, two more `ceph_` prefixed containers, required to deploy
the Ceph Ingress daemon are added, and they are supposed to match
the tripleo-heat-templates `OS::TripleO::Services::CephIngress`
service.
The Ingress daemon doesn't use the Ceph daemon container, hence
`tripleo container image prepare` should be executed to pull the
new container images/tags in the undercloud as made for the Ceph
Dashboard and the regular Ceph image.

View File

@ -33,9 +33,10 @@ class BaseImageManager(object):
'container_images_template'
)
def __init__(self, config_files, images=None):
def __init__(self, config_files, template_dir=None, images=None):
self.config_files = config_files
self.images = images
self.template_dir = template_dir
def _extend_or_set_attribute(self, existing_image, image, attribute_name):
attribute = image.get(attribute_name)

View File

@ -50,12 +50,13 @@ def init_prepare_defaults(defaults_file):
CONTAINER_IMAGES_DEFAULTS = CONTAINER_IMAGE_PREPARE_PARAM[0]['set']
DEFAULT_TEMPLATE_FILE = os.path.join(sys.prefix, 'share', 'tripleo-common',
'container-images',
DEFAULT_TEMPLATE_DIR = os.path.join(sys.prefix, 'share', 'tripleo-common',
'container-images')
DEFAULT_TEMPLATE_FILE = os.path.join(DEFAULT_TEMPLATE_DIR,
'tripleo_containers.yaml.j2')
DEFAULT_PREPARE_FILE = os.path.join(sys.prefix, 'share', 'tripleo-common',
'container-images',
DEFAULT_PREPARE_FILE = os.path.join(DEFAULT_TEMPLATE_DIR,
'container_image_prepare_defaults.yaml')
if os.path.isfile(DEFAULT_PREPARE_FILE):
@ -269,6 +270,7 @@ def container_images_prepare_defaults():
def container_images_prepare(template_file=DEFAULT_TEMPLATE_FILE,
template_dir=DEFAULT_TEMPLATE_DIR,
excludes=None, includes=None, service_filter=None,
pull_source=None, push_destination=None,
mapping_args=None, output_env_file=None,
@ -281,6 +283,7 @@ def container_images_prepare(template_file=DEFAULT_TEMPLATE_FILE,
"""Perform container image preparation
:param template_file: path to Jinja2 file containing all image entries
:param template_dir: path to Jinja2 files included in the main template
:param excludes: list of image name substrings to use for exclude filter
:param includes: list of image name substrings, at least one must match.
All excludes are ignored if includes is specified.
@ -344,7 +347,7 @@ def container_images_prepare(template_file=DEFAULT_TEMPLATE_FILE,
return None
return entry
builder = KollaImageBuilder([template_file])
builder = KollaImageBuilder([template_file], template_dir)
result = builder.container_images_from_template(
filter=ffunc, **mapping_args)
@ -513,8 +516,14 @@ class KollaImageBuilder(base.BaseImageManager):
if len(self.config_files) != 1:
raise ValueError('A single config file must be specified')
config_file = self.config_files[0]
template_dir = self.template_dir
with open(config_file) as cf:
template = jinja2.Template(cf.read())
if template_dir is not None:
template = jinja2.Environment(loader=jinja2.FileSystemLoader(
template_dir)).from_string(cf.read())
else:
template = jinja2.Template(cf.read())
rendered = template.render(mapping)
rendered_dict = yaml.safe_load(rendered)
@ -537,6 +546,7 @@ class KollaImageBuilder(base.BaseImageManager):
if len(self.config_files) == 0:
self.config_files = [DEFAULT_TEMPLATE_FILE]
self.template_dir = DEFAULT_TEMPLATE_DIR
container_images = self.container_images_from_template()
else:
container_images = self.load_config_files(self.CONTAINER_IMAGES) \

View File

@ -33,6 +33,10 @@ TEMPLATE_PATH = os.path.join(os.path.dirname(__file__),
DEFAULTS_PATH = os.path.join(os.path.dirname(__file__),
'..', '..', '..', 'container-images',
'container_image_prepare_defaults.yaml')
TEMPLATE_DIR_PATH = os.path.join(os.path.dirname(__file__),
'..', '..', '..', 'container-images')
kb.init_prepare_defaults(DEFAULTS_PATH)
KB_DEFAULT_TAG = kb.CONTAINER_IMAGES_DEFAULTS['tag']
KB_DEFAULT_PREFIX = kb.CONTAINER_IMAGES_DEFAULTS['name_prefix']
@ -260,6 +264,12 @@ class TestKollaImageBuilderTemplate(base.TestCase):
'ceph_node_exporter_namespace',
'ceph_node_exporter_image',
'ceph_node_exporter_tag',
'ceph_haproxy_namespace',
'ceph_haproxy_image',
'ceph_haproxy_tag',
'ceph_keepalived_namespace',
'ceph_keepalived_image',
'ceph_keepalived_tag',
):
if key in kb.CONTAINER_IMAGES_DEFAULTS:
expected[key] = kb.CONTAINER_IMAGES_DEFAULTS[key]
@ -293,6 +303,12 @@ class TestKollaImageBuilderTemplate(base.TestCase):
'ceph_node_exporter_namespace',
'ceph_node_exporter_image',
'ceph_node_exporter_tag',
'ceph_haproxy_namespace',
'ceph_haproxy_image',
'ceph_haproxy_tag',
'ceph_keepalived_namespace',
'ceph_keepalived_image',
'ceph_keepalived_tag',
):
if key in kb.CONTAINER_IMAGES_DEFAULTS:
expected[key] = kb.CONTAINER_IMAGES_DEFAULTS[key]
@ -364,7 +380,7 @@ class TestKollaImageBuilderTemplate(base.TestCase):
files_dir = os.path.join(project_dir, 'container-images')
oc_tmpl_file = os.path.join(files_dir, 'tripleo_containers.yaml.j2')
tmpl_builder = kb.KollaImageBuilder([oc_tmpl_file])
tmpl_builder = kb.KollaImageBuilder([oc_tmpl_file], files_dir)
def ffunc(entry):
if 'params' in entry:
@ -378,7 +394,7 @@ class TestKollaImageBuilderTemplate(base.TestCase):
rhel_containers=rhel_containers)
oc_yaml_file = os.path.join(files_dir, 'tripleo_containers.yaml')
yaml_builder = kb.KollaImageBuilder([oc_yaml_file])
yaml_builder = kb.KollaImageBuilder([oc_yaml_file], files_dir)
container_images = yaml_builder.load_config_files(
yaml_builder.CONTAINER_IMAGES)
@ -461,7 +477,8 @@ class TestPrepare(base.TestCase):
def test_prepare_noargs(self, mock_insecure):
self.assertEqual(
{},
kb.container_images_prepare(template_file=TEMPLATE_PATH)
kb.container_images_prepare(template_file=TEMPLATE_PATH,
template_dir=TEMPLATE_DIR_PATH)
)
@mock.patch('tripleo_common.image.kolla_builder.'
@ -480,6 +497,7 @@ class TestPrepare(base.TestCase):
}},
kb.container_images_prepare(
template_file=TEMPLATE_PATH,
template_dir=TEMPLATE_DIR_PATH,
output_env_file=CONTAINER_DEFAULTS_ENVIRONMENT,
output_images_file='container_images.yaml',
service_filter=['OS::TripleO::Services::NovaLibvirt'],
@ -507,6 +525,7 @@ class TestPrepare(base.TestCase):
}},
kb.container_images_prepare(
template_file=TEMPLATE_PATH,
template_dir=TEMPLATE_DIR_PATH,
output_env_file=CONTAINER_DEFAULTS_ENVIRONMENT,
output_images_file='container_images.yaml',
includes=['libvirt'],
@ -534,6 +553,7 @@ class TestPrepare(base.TestCase):
}},
kb.container_images_prepare(
template_file=TEMPLATE_PATH,
template_dir=TEMPLATE_DIR_PATH,
output_env_file=CONTAINER_DEFAULTS_ENVIRONMENT,
output_images_file='container_images.yaml',
includes=['libvirt'],
@ -568,6 +588,7 @@ class TestPrepare(base.TestCase):
}},
kb.container_images_prepare(
template_file=TEMPLATE_PATH,
template_dir=TEMPLATE_DIR_PATH,
output_env_file=CONTAINER_DEFAULTS_ENVIRONMENT,
output_images_file='container_images.yaml',
service_filter=['OS::TripleO::Services::NovaApi'],
@ -604,6 +625,7 @@ class TestPrepare(base.TestCase):
}},
kb.container_images_prepare(
template_file=TEMPLATE_PATH,
template_dir=TEMPLATE_DIR_PATH,
output_env_file=CONTAINER_DEFAULTS_ENVIRONMENT,
output_images_file='container_images.yaml',
service_filter=['OS::TripleO::Services::NovaApi'],
@ -630,6 +652,7 @@ class TestPrepare(base.TestCase):
}},
kb.container_images_prepare(
template_file=TEMPLATE_PATH,
template_dir=TEMPLATE_DIR_PATH,
output_env_file=CONTAINER_DEFAULTS_ENVIRONMENT,
output_images_file='container_images.yaml',
service_filter=['OS::TripleO::Services::CephMon'],
@ -655,6 +678,7 @@ class TestPrepare(base.TestCase):
}},
kb.container_images_prepare(
template_file=TEMPLATE_PATH,
template_dir=TEMPLATE_DIR_PATH,
output_env_file=CONTAINER_DEFAULTS_ENVIRONMENT,
output_images_file='container_images.yaml',
service_filter=[
@ -688,6 +712,7 @@ class TestPrepare(base.TestCase):
}},
kb.container_images_prepare(
template_file=TEMPLATE_PATH,
template_dir=TEMPLATE_DIR_PATH,
output_env_file=CONTAINER_DEFAULTS_ENVIRONMENT,
output_images_file='container_images.yaml',
service_filter=[
@ -716,6 +741,7 @@ class TestPrepare(base.TestCase):
kb.container_images_prepare(
template_file=TEMPLATE_PATH,
template_dir=TEMPLATE_DIR_PATH,
output_env_file=CONTAINER_DEFAULTS_ENVIRONMENT,
output_images_file='container_images.yaml',
mapping_args={},
@ -726,6 +752,7 @@ class TestPrepare(base.TestCase):
kb.container_images_prepare(
template_file=TEMPLATE_PATH,
template_dir=TEMPLATE_DIR_PATH,
output_env_file=CONTAINER_DEFAULTS_ENVIRONMENT,
output_images_file='container_images.yaml',
mapping_args={"tag": "master"},

View File

@ -35,7 +35,9 @@ def default_image_params():
template_file = os.path.join(sys.prefix, 'share', 'tripleo-common',
'container-images',
'tripleo_containers.yaml.j2')
builder = kolla_builder.KollaImageBuilder([template_file])
template_dir = os.path.join(sys.prefix, 'share', 'tripleo-common',
'container-images')
builder = kolla_builder.KollaImageBuilder([template_file], template_dir)
result = builder.container_images_from_template(filter=ffunc)
params = {}