Skip to content

Commit

Permalink
Merge pull request #40 from ocadotechnology/added-tolerations-for-ds-…
Browse files Browse the repository at this point in the history
…and-ss

feat: added tolerations for DS and SS
  • Loading branch information
YuraBeznos authored Mar 26, 2019
2 parents b608800 + 885fccd commit 5294403
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ HOSTESS_DOCKER_IMAGE | The name of the docker image for mirror-hostess. | ocadot
HOSTESS_DOCKER_TAG | The tag for the mirror-hostess docker image. | 1.1.0
SS_DS_LABELS | (Optional) StatefulSet and DaemonSet labels | None
SS_DS_TEMPLATE_LABELS | (Optional) StatefulSet and DaemonSet pod labels | None
SS_DS_TOLERATIONS | (Optional) StatefulSet and DaemonSet pod tolerations | None
IMAGE_PULL_SECRETS | (Optional) Secret to pull images from the upstream registry | None
CA_CERTIFICATE_BUNDLE | (Optional) Certificate bundle for the registry host | None

Expand Down
11 changes: 9 additions & 2 deletions mirroroperator/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def __init__(self, env_vars):
hostess_docker_registry (used in RegistryMirror),
ss_ds_labels (used in RegistryMirror, optional),
ss_ds_template_lables (used in RegistryMirror, optional)
ss_ds_tolerations (used in RegistryMirror, optional)
hostess_docker_image (used in RegistryMirror),
hostess_docker_tag (used in RegistryMirror),
image_pull_secrets(used in RegistryMirror, optional),
Expand Down Expand Up @@ -55,6 +56,10 @@ def watch_registry_mirrors(self):
LOGGER.exception("Error watching custom object events", exc_info=True)


def safely_eval_env(env_var):
return ast.literal_eval(os.environ.get(env_var)) if env_var is not None else None


if __name__ == '__main__':
logging.basicConfig(level=logging.INFO)

Expand All @@ -67,8 +72,10 @@ def watch_registry_mirrors(self):
"ocadotechnology/mirror-hostess"),
hostess_docker_tag=os.environ.get("HOSTESS_DOCKER_TAG", "1.1.0"),
# optional labels to be added to daemonsets and statefulsets
ss_ds_labels=ast.literal_eval(os.environ.get("SS_DS_LABELS")),
ss_ds_template_labels=ast.literal_eval(os.environ.get("SS_DS_TEMPLATE_LABELS")),
ss_ds_labels=safely_eval_env("SS_DS_LABELS"),
ss_ds_template_labels=safely_eval_env("SS_DS_TEMPLATE_LABELS"),
# optional tolerations to be added to daemonsets and statefulsets
ss_ds_tolerations=safely_eval_env("SS_DS_TOLERATIONS"),
# optional in V1PodSpec secrets split with comma
image_pull_secrets=os.environ.get("IMAGE_PULL_SECRETS"),
# get the docker certificate:
Expand Down
3 changes: 3 additions & 0 deletions mirroroperator/registrymirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def __init__(self, event_type, namespace, hostess_docker_registry,

self.ss_ds_labels = kwargs["ss_ds_labels"] or ""
self.ss_ds_template_labels = kwargs["ss_ds_template_labels"] or ""
self.ss_ds_tolerations = kwargs["ss_ds_tolerations"] or ""
self.image_pull_secrets = kwargs["image_pull_secrets"] or ""
self.ca_certificate_bundle = kwargs["ca_certificate_bundle"]

Expand Down Expand Up @@ -304,6 +305,7 @@ def generate_daemon_set(self, daemon_set):
],
)
],
tolerations=self.ss_ds_tolerations,
image_pull_secrets=[{"name": name} for name in
self.image_pull_secrets.split(",")],
service_account_name="mirror-hostess",
Expand Down Expand Up @@ -550,6 +552,7 @@ def generate_stateful_set(self):
volume_mounts=volumes_to_mount,
),
],
tolerations=self.ss_ds_tolerations,
termination_grace_period_seconds=10,
volumes=volumes,
)
Expand Down
1 change: 1 addition & 0 deletions tests/test_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def setUp(self):
"hostess_docker_tag": None,
"ss_ds_labels": {"test":"test_labels"},
"ss_ds_template_labels": {"test":"test_pod_labels"},
"ss_ds_tolerations": {"test": "test_taints"},
"image_pull_secrets": None,
"docker_certificate_secret": 'aaa',
"ca_certificate_bundle": 'bbb',
Expand Down
1 change: 1 addition & 0 deletions tests/test_regmirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def setUp(self):
"hostess_docker_tag": 2,
"ss_ds_labels":{"test":"test_labels"},
"ss_ds_template_labels":{"test": "test_pod_labels"},
"ss_ds_tolerations": {"test": "test_taints"},
"image_pull_secrets": None,
"docker_certificate_secret": VALID_SECRET,
"ca_certificate_bundle": None,
Expand Down

0 comments on commit 5294403

Please sign in to comment.