From b2377c5d19958e9b65fded1ae4abe33f5b6fbeae Mon Sep 17 00:00:00 2001 From: Ian MacDougall Date: Wed, 23 May 2018 16:49:55 +0100 Subject: [PATCH 1/2] fix: add in docker_registry environment variable This is to replace the mirror_image variable --- mirroroperator/operator.py | 11 ++++++++--- mirroroperator/registrymirror.py | 9 ++++++--- tests/test_operator.py | 4 +++- tests/test_regmirror.py | 4 +++- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/mirroroperator/operator.py b/mirroroperator/operator.py index dce1f38..d7d8019 100644 --- a/mirroroperator/operator.py +++ b/mirroroperator/operator.py @@ -20,7 +20,9 @@ class MirrorOperator(object): def __init__(self, env_vars): """ :param env_vars: dictionary includes namespace, - mirror_hostess_image(used in RegistryMirror), + hostess_docker_registry (used in RegistryMirror), + hostess_docker_image (used in RegistryMirror), + hostess_docker_tag (used in RegistryMirror), image_pull_secrets(used in RegistryMirror, optional), secret_name(optional), cert_name(optional) @@ -53,8 +55,11 @@ def watch_registry_mirrors(self): # Get organization specific variables from env env_vars = dict( namespace=os.environ.get("NAMESPACE", "default"), - # needed - mirror_hostess_image=os.environ.get("MIRROR_HOSTESS_IMAGE"), + # optional to allow for image to be pulled from elsewhere + hostess_docker_registry=os.environ.get("HOSTESS_DOCKER_REGISTRY", "docker.io"), + hostess_docker_image=os.environ.get("HOSTESS_DOCKER_IMAGE", + "ocadotechnology/mirror-hostess"), + hostess_docker_tag=os.environ.get("HOSTESS_DOCKER_TAG", "1.1.0"), # optional in V1PodSpec secrets split with comma image_pull_secrets=os.environ.get("IMAGE_PULL_SECRETS"), # get secret name: diff --git a/mirroroperator/registrymirror.py b/mirroroperator/registrymirror.py index 0013d9c..a37b938 100644 --- a/mirroroperator/registrymirror.py +++ b/mirroroperator/registrymirror.py @@ -11,10 +11,13 @@ class RegistryMirror(object): - def __init__(self, event_type, namespace, mirror_hostess_image, **kwargs): + def __init__(self, event_type, namespace, hostess_docker_registry, + hostess_docker_image, hostess_docker_tag, **kwargs): self.event_type = event_type self.namespace = namespace - self.mirror_hostess_image = mirror_hostess_image + self.hostess_docker_registry = hostess_docker_registry + self.hostess_docker_image = hostess_docker_image + self.hostess_docker_tag = hostess_docker_tag self.kind = kwargs.get("kind") self.name = kwargs.get("metadata", {}).get("name") self.uid = kwargs.get("metadata", {}).get("uid") @@ -134,7 +137,7 @@ def generate_daemon_set(self, daemon_set): client.V1EnvVar(name="HOSTS_FILE_BACKUP", value="/etc/hosts.backup/hosts") ], - image=self.mirror_hostess_image, + image="{}/{}:{}".format(self.hostess_docker_registry, self.hostess_docker_image, self.hostess_docker_tag), image_pull_policy="Always", resources=client.V1ResourceRequirements( requests={"memory": "32Mi", "cpu": "0.001"}, diff --git a/tests/test_operator.py b/tests/test_operator.py index 6da1c2c..d9ebfa9 100644 --- a/tests/test_operator.py +++ b/tests/test_operator.py @@ -26,7 +26,9 @@ def setUp(self): super().setUp() env_var_dict = { "namespace": "default", - "mirror_hostess_image": "some-public-mirror-hostess-image", + "hostess_docker_registry": "docker.io", + "hostess_docker_image": "ocadotechnology/mirror-hostess", + "hostess_docker_tag": None, "image_pull_secrets": None, "secret_name": None, "cert_name": None, diff --git a/tests/test_regmirror.py b/tests/test_regmirror.py index 180314b..ae53ca1 100644 --- a/tests/test_regmirror.py +++ b/tests/test_regmirror.py @@ -13,7 +13,9 @@ def setUp(self): super().setUp() self.env_var_dict = { "namespace": "default", - "mirror_hostess_image": "some-public-mirror-hostess-image", + "hostess_docker_registry": "docker.io", + "hostess_docker_image": "ocadotechnology/mirror-hostess", + "hostess_docker_tag": 2, "image_pull_secrets": None, "secret_name": None, "cert_name": None, From 47d5b5bc64f00c1985150e87b4b3f2492e51d0d0 Mon Sep 17 00:00:00 2001 From: Ian MacDougall Date: Thu, 24 May 2018 14:46:45 +0100 Subject: [PATCH 2/2] docs: Add in new environment variables in the README --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 6edef31..75b5077 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,9 @@ Name | description | default --- | --- | --- NAMESPACE | The namespace in which the resources should be created. This should be the same namespace as where the container is running | default SECONDS_BETWEEN_STREAMS | Time to sleep between calls to the API. The operator will occasionally lose connection or else fail to run if the Custom Resource Definition does not exist. | 30 +HOSTESS_DOCKER_REGISTRY | The docker registry where mirror-hostess is to be pulled from. | docker.io +HOSTESS_DOCKER_IMAGE | The name of the docker image for mirror-hostess. | ocadotechnology/mirror-hostess +HOSTESS_DOCKER_TAG | The tag for the mirror-hostess docker image. | 1.1.0 ## Usage In order to have the operator deploy a new mirror, the cluster needs to have the custom resource defined: