-@wrap_error_handling_start
-@monkeypatch_loggers
-@operation
-def create_and_start_container_for_platforms(**kwargs):
- """Initiate Kubernetes deployment for platform components
-
- This operation method is to be used with the ContainerizedPlatformComponent
- node type.
- """
- # Capture node properties
- image = ctx.node.properties["image"]
- docker_config = ctx.node.properties.get("docker_config", {})
- resource_config = ctx.node.properties.get("resource_config", {})
- kwargs["resource_config"] = resource_config
- if "healthcheck" in docker_config:
- kwargs["readiness"] = docker_config["healthcheck"]
- if "livehealthcheck" in docker_config:
- kwargs["liveness"] = docker_config["livehealthcheck"]
- if "dns_name" in ctx.node.properties:
- service_component_name = ctx.node.properties["dns_name"]
- else:
- service_component_name = ctx.node.properties["name"]
-
- # Set some labels for the Kubernetes pods
- # The name segment is required and must be 63 characters or less
- kwargs["labels"] = {
- "cfydeployment" : ctx.deployment.id,
- "cfynode": ctx.node.name[:63],
- "cfynodeinstance": ctx.instance.id[:63]
- }
-
- host_port = ctx.node.properties["host_port"]
- container_port = ctx.node.properties["container_port"]
-
- # Cloudify properties are all required and Cloudify complains that None
- # is not a valid type for integer. Defaulting to 0 to indicate to not
- # use this and not to set a specific port mapping in cases like service
- # change handler.
- if container_port != 0:
- # Doing this because other nodes might want to use this property
- port_mapping = "{cp}:{hp}".format(cp=container_port, hp=host_port)
- ports = kwargs.get("ports", []) + [ port_mapping ]
- kwargs["ports"] = ports
- if "ports" not in kwargs:
- ctx.logger.warn("No port mappings defined. Will randomly assign port.")
-
- # All of the new node properties could be handled more DRYly!
- # If a registration to MSB is required, then set up the registration info
- if "msb_registration" in ctx.node.properties and "port" in ctx.node.properties["msb_registration"]:
- kwargs["msb_list"] = [_setup_msb_registration(service_component_name, ctx.node.properties["msb_registration"])]
-
- # If centralized logging via ELK is desired, then set up the logging info
- if "log_info" in ctx.node.properties and "log_directory" in ctx.node.properties["log_info"]:
- kwargs["log_info"] = ctx.node.properties["log_info"]
-
- # Pick up TLS info if present
- if "tls_info" in ctx.node.properties:
- kwargs["tls_info"] = ctx.node.properties["tls_info"]
-
- # Pick up replica count and always_pull_image flag
- if "replicas" in ctx.node.properties:
- kwargs["replicas"] = ctx.node.properties["replicas"]
- if "always_pull_image" in ctx.node.properties:
- kwargs["always_pull_image"] = ctx.node.properties["always_pull_image"]
-
- # Pick up location
- kwargs["k8s_location"] = _get_location()
-
- returned_args = _create_and_start_container(service_component_name, image, **kwargs)
-
- # Verify that the k8s deployment is ready
- # - Set service component name into kwargs
- # - max_wait is already in kwargs if it was set
- returned_args[SERVICE_COMPONENT_NAME] = service_component_name
- _verify_component(**returned_args)
-