Skip to content

Commit

Permalink
Merge pull request #15 from ocadotechnology/set-hostess-image
Browse files Browse the repository at this point in the history
fix: add in docker_registry environment variable
  • Loading branch information
blerko authored May 24, 2018
2 parents f06746c + 47d5b5b commit 891dce9
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 8 additions & 3 deletions mirroroperator/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
9 changes: 6 additions & 3 deletions mirroroperator/registrymirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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"},
Expand Down
4 changes: 3 additions & 1 deletion tests/test_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion tests/test_regmirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 891dce9

Please sign in to comment.