def test_handling_long_nested_image_name(): deploy = get_deployment() c = Component("service/test-service") c.image = "gcr.io/google-containers/etcd-amd64:3.3.10-1" c.image_pull_secrets = {"gcr.io": "secret"} c._patch_image_pull_secrets(deploy) spec = deploy["spec"]["template"]["spec"] assert spec["imagePullSecrets"][0]["name"] == "secret"
def test_patch_containers(): deploy = get_deployment() c = Component("service/test-service") c.image_prefix = "" c.image = "test-image" c.tag = "v6.6.6" c._patch_containers(deploy) container = deploy["spec"]["template"]["spec"]["containers"][0] assert container["image"] == "test-image:v6.6.6"
def test_patch_cronjob(): cronjob = get_cronjob() c = Component("service/test-cronjob") c.image_pull_secrets = {"imagined.registry.tld": "secret"} c.image_prefix = "" c.image = "imagined.registry.tld/test-image" c.tag = "v6.6.7" c._patch_cronjob(cronjob) # Assert image spec = cronjob["spec"]["jobTemplate"]["spec"]["template"]["spec"] cronjob_image = spec["containers"][0]["image"] assert cronjob_image == "imagined.registry.tld/test-image:v6.6.7" # Assert imagePullSecrets assert spec["imagePullSecrets"][0]["name"] == "secret"
def release( ctx, env, component=None, image=None, tag=None, replicas=None, dry_run=False, keep_configs=False, no_rollout_wait=False, ): tags: dict = {} images: dict = {} replica_counts: dict = {} components: List[str] = [] if image: for i in image: path, value = i.split("=") images[path] = value if tag: for t in tag: path, value = t.split("=") tags[path] = value if replicas: for r in replicas: path, value = r.split("=") replica_counts[path] = value rel_id = generate_release_id() big_label(logger.info, f"Release {rel_id} to {env} environment starting") settings = load_env_settings(env) if component: components = component else: components = settings.COMPONENTS # Override env settings for replicas if replica_counts: for path in replica_counts: settings.REPLICAS[path] = replica_counts[path] rel_path = RELEASE_TMP / rel_id logger.info("") logger.info("Releasing components:") for component in components: logger.info(f" - {component}") logger.info("") logger.info("Setting images and tags:") for path in components: tag = "(default)" image = "(default)" if path in tags: tag = tags[path] if path in images: image = images[path] logger.info(f" - {path} = {image}:{tag}") logger.info("") ensure_context(settings.KUBE_CONTEXT) ensure_namespace(settings.KUBE_NAMESPACE) release_env(ctx, env, dry_run) for path in components: logger.info("") label(logger.info, f"Releasing component {path}") component = Component(path) if path in images: component.image = images[path] images.pop(path) if path in tags: component.tag = tags[path] tags.pop(path) if path in settings.REPLICAS: component.replicas = settings.REPLICAS[path] replica_counts.pop(path, None) component.namespace = settings.KUBE_NAMESPACE component.context = settings.KUBE_CONTEXT component.image_pull_secrets = settings.IMAGE_PULL_SECRETS component.patch_from_env(env) component.validate(ctx) component.release(ctx, rel_path, dry_run, no_rollout_wait) if images: logger.error("Unprocessed image configurations:") for path in images: logger.error(f" - {path}={images[path]}") if tags: logger.error("Unprocessed tag configurations:") for path in tags: logger.error(f" - {path}={tags[path]}") if replica_counts: logger.error("Unprocessed replica configurations:") for path in replica_counts: logger.error(f" - {path}={replica_counts[path]}") if not keep_configs: logger.info(f"Removing temporary configurations from {rel_path}") if rel_path.exists(): rmtree(rel_path)