Parameters: name – the name of the op. It does not have to be unique within a pipeline because the pipeline will generates a unique new name in case of conflicts. init_containers – the listof UserContainer objects describing the InitContainer to deploy before the main container. sidecars – the listof Sidecar objects describing the sidecar containers to deploy together with the main container. is_exit_handler – Deprecated.
Each constraint is a key-value pair label. For the container to be eligible to run on a node, the node must have each of the constraints appeared as labels.
Parameters:
label_name (Union[str, PipelineParam]) – The name of the constraint label.
value (Union[str, PipelineParam]) – The value of the constraint label.
Sets the number of times the task is retried until it’s declared failed.
Parameters:
num_retries – Number of times to retry on failures.
policy – Retry policy name.
backoff_duration – The time interval between retries. Defaults to an immediate retry. In case you specify a simple number, the unit defaults to seconds. You can also specify a different unit, for instance, 2m (2 minutes), 1h (1 hour).
backoff_factor – The exponential backoff factor applied to backoff_duration. For example, if backoff_duration=”60” (60 seconds) and backoff_factor=2, the first retry will happen after 60 seconds, then after 120, 240, and so on.
backoff_max_duration – The maximum interval that can be reached with the backoff strategy.
class ContainerOp(BaseOp): def __init__(...) self._container = Container( image=image, args=arguments, command=command, **container_kwargs) # decorator func to proxy a method in `Container` into `ContainerOp` def _proxy(proxy_attr): """Decorator func to proxy to ContainerOp.container."""
def _decorated(*args, **kwargs): # execute method ret = getattr(self._container, proxy_attr)(*args, **kwargs) if ret == self._container: return self return ret
# iter thru container and attach a proxy func to the container method for attr_to_proxy in dir(self._container): func = getattr(self._container, attr_to_proxy) # ignore private methods, and bypass method overrided by subclasses. if (not hasattr(self, attr_to_proxy) and hasattr(func, '__call__') and (attr_to_proxy[0] != '_') and (attr_to_proxy notin ignore_set)): # only proxy public callables setattr(self, attr_to_proxy, _proxy(attr_to_proxy))
Represents an op implemented by a container image.
Parameters: name – the name of the op. It does not have to be unique within a pipeline because the pipeline will generates a unique new name in case of conflicts. image – the container image name, such as ‘python:3.5-jessie’ command – the command to run in the container. If None, uses default CMD in defined in container. arguments – the arguments of the command. The command can include “%s” and supply a PipelineParam as the string replacement. For example, (‘echo %s’ % input_param). At container run time the argument will be ‘echo param_value’. init_containers – the list of UserContainer objects describing the InitContainer to deploy before the main container. sidecars – the list of Sidecar objects describing the sidecar containers to deploy together with the main container. container_kwargs – the dict of additional keyword arguments to pass to the op’s Container definition. artifact_argument_paths – Optional. Maps input artifact arguments (values or references) to the local file paths where they’ll be placed. At pipeline run time, the value of the artifact argument is saved to a local file with specified path. This parameter is only needed when the input file paths are hard-coded in the program. Otherwise it’s better to pass input artifact placement paths by including artifact arguments in the command-line using the InputArgumentPath class instances. file_outputs – Maps output names to container local output file paths. 将输出名称映射到容器本地输出文件路径。 The system will take the data from those files and will make it available for passing to downstream tasks. 系统将从这些文件中获取数据,并将其传递给下游任务。 For each output in the file_outputs map there will be a corresponding output reference available in the task.outputs dictionary. 对于file_outputs map中的每个输出,输出引用对应于task.outputs字典。 These output references can be passed to the other tasks as arguments. The following output names are handled specially by the frontend and 这些输出引用可以作为参数传递给其他任务。 backend: “mlpipeline-ui-metadata” and “mlpipeline-metrics”. output_artifact_paths – Deprecated. Maps output artifact labels to local artifact file paths. Deprecated: Use file_outputs instead. It now supports big data outputs. is_exit_handler – Deprecated. This is no longer needed. pvolumes – Dictionary for the user to match a path on the op’s fs with a V1Volume or it inherited type. E.g {“/my/path”: vol, “/mnt”: other_op.pvolumes[“/output”]}.
from kfp import dsl from kubernetes.client.models import V1EnvVar, V1SecretKeySelector @dsl.pipeline( name='foo', description='hello world') def foo_pipeline(tag: str, pull_image_policy: str): # any attributes can be parameterized (both serialized string or actual PipelineParam) op = dsl.ContainerOp(name='foo', image='busybox:%s' % tag, # pass in init_container list init_containers=[dsl.UserContainer('print', 'busybox:latest', command='echo "hello"')], # pass in sidecars list sidecars=[dsl.Sidecar('print', 'busybox:latest', command='echo "hello"')], # pass in k8s container kwargs container_kwargs={'env': [V1EnvVar('foo', 'bar')]}, ) # set `imagePullPolicy` property for `container` with `PipelineParam` op.container.set_image_pull_policy(pull_image_policy) # add sidecar with parameterized image tag # sidecar follows the argo sidecar swagger spec op.add_sidecar(dsl.Sidecar('redis', 'redis:%s' % tag).set_image_pull_policy('Always'))
add_init_container(init_container: kfp.dsl._container_op.UserContainer) Add a init containerto the Op. Parameters:init_container – UserContainer object.
add_node_selector_constraint(label_name: Union[str, kfp.dsl._pipeline_param.PipelineParam], value: Union[str, kfp.dsl._pipeline_param.PipelineParam]) → kfp.dsl._container_op.ContainerOp Sets accelerator type requirement for this task. When compiling for v2, this function can be optionally used with set_gpu_limit toset the numberof accelerator required. Otherwise, bydefault the number requested will be 1. Parameters: label_name – The nameof the constraint label. For v2, only ‘cloud.google.com/gke-accelerator’ is supported now. value – The nameof the accelerator. For v2, available valuesinclude ‘nvidia-tesla-k80’, ‘tpu-v3’. Returns: selfreturntoallow chained callwith other resource specification.
add_pod_annotation(name: str, value: str) Adds a pod’s metadata annotation. Parameters: name – The nameof the annotation. value – The valueof the annotation.
add_pod_label(name: str, value: str) # 为 pod 添加标签 Adds a pod’s metadata label. Parameters: name – The nameof the label. value – The valueof the label.
add_pvolumes(pvolumes: Dict[str, kubernetes.client.models.v1_volume.V1Volume] = None) Updates the existing pvolumes dict, extends volumes and volume_mounts and redefines the pvolume attribute. Parameters:pvolumes – Dictionary. Keysaremount paths, valuesare Kubernetes volumes or inherited types (e.g. PipelineVolumes).
add_sidecar(sidecar: kfp.dsl._container_op.Sidecar) Add a sidecar to the Op. Parameters:sidecar – SideCar object.
add_volume(volume) Add K8s volume to the container. Parameters: volume – Kubernetes volumes For detailed spec, check volume definition https – //github.com/kubernetes-client/python/blob/master/kubernetes/client/models/v1_volume.py
after(*ops) Specify explicit dependency on other ops.
apply(mod_func) Applies a modifier functionto self. The function should return the passed object. This is needed tochain “extention methods” to this class. Example: from kfp.gcp import use_gcp_secret task = ( train_op(...) .set_memory_request('1G') .apply(use_gcp_secret('user-gcp-sa')) .set_memory_limit('2G') )
container Containerobject that represents the container property in io.argoproj.workflow.v1alpha1.Template. Can be used toupdate the container configurations. Example: import kfp.dsl as dsl from kubernetes.client.models import V1EnvVar
inputs Listof PipelineParams that will be converted intoinputparameters (io.argoproj.workflow.v1alpha1.Inputs) for the argo workflow.
is_v2
set_caching_options(enable_caching: bool) → kfp.dsl._container_op.BaseOp Setscaching options for the Op. Parameters:enable_caching – Whether ornottoenablecachingfor this task. Returns:Selfreturntoallow chained setting calls.
set_display_name(name: str)
set_retry(num_retries: int, policy: Optional[str] = None, backoff_duration: Optional[str] = None, backoff_factor: Optional[float] = None, backoff_max_duration: Optional[str] = None) Sets the numberof times the task is retried until it’s declared failed. Parameters: num_retries – Numberof times to retry on failures. policy – Retry policy name. backoff_duration – The timeintervalbetween retries. Defaultsto an immediate retry. Incase you specify a simple number, the unit defaultsto seconds. You can also specify a different unit, forinstance, 2m (2minutes), 1h (1hour). backoff_factor – The exponential backoff factor applied to backoff_duration. For example, if backoff_duration=”60” (60seconds) and backoff_factor=2, the first retry will happen after60seconds, thenafter120, 240, and so on. backoff_max_duration – The maximum interval that can be reached with the backoff strategy.
set_timeout(seconds: int) Sets the timeoutfor the task in seconds. Parameters: seconds – Numberof seconds.
PodDisruptionBudget holds the number of concurrent disruptions that you allow for pipeline Pods.
Parameters:
min_available (Union[int, str]) – An eviction is allowed if at least “minAvailable” pods selected by “selector” will still be available after the eviction, i.e. even in the absence of the evicted pod. So for example you can prevent all voluntary evictions by specifying “100%”. “minAvailable” can be either an absolute number or a percentage.
Representing a future value that is passed between pipeline components.
A PipelineParam object can be used as a pipeline function argument so that it will be a pipeline parameter that shows up in ML Pipelines system UI. It can also represent an intermediate value passed between components.
Parameters:
name – name of the pipeline parameter.
op_name – the name of the operation that produces the PipelineParam. None means it is not produced by any operator, so if None, either user constructs it directly (for providing an immediate value), or it is a pipeline function argument.
value – The actual value of the PipelineParam. If provided, the PipelineParam is “resolved” immediately. For now, we support string only.
param_type – the type of the PipelineParam.
pattern – the serialized string regex pattern this pipeline parameter created from.
Raises: ValueError in name or op_name contains invalid characters, or both
op_name and value are set.
full_name
Unique name in the argo yaml for the PipelineParam.
Representing a volume that is passed between pipeline operators and is.
to be mounted by a ContainerOp or its inherited type.
A PipelineVolume object can be used as an extention of the pipeline function’s filesystem. It may then be passed between ContainerOps, exposing dependencies.
Each constraint is a key-value pair label. For the container to be eligible to run on a node, the node must have each of the constraints appeared as labels.
Parameters:
label_name (Union[str, PipelineParam]) – The name of the constraint label.
value (Union[str, PipelineParam]) – The value of the constraint label.
Sets the number of times the task is retried until it’s declared failed.
Parameters:
num_retries – Number of times to retry on failures.
policy – Retry policy name.
backoff_duration – The time interval between retries. Defaults to an immediate retry. In case you specify a simple number, the unit defaults to seconds. You can also specify a different unit, for instance, 2m (2 minutes), 1h (1 hour).
backoff_factor – The exponential backoff factor applied to backoff_duration. For example, if backoff_duration=”60” (60 seconds) and backoff_factor=2, the first retry will happen after 60 seconds, then after 120, 240, and so on.
backoff_max_duration – The maximum interval that can be reached with the backoff strategy.
Parameters: name – unique name for the sidecar container image – image to use for the sidecar container, e.g. redis:alpine command – entrypoint array. Not executed within a shell. args – arguments to the entrypoint. mirror_volume_mounts – MirrorVolumeMounts will mount the same volumes specified in the main container to the sidecar (including artifacts), at the same mountPaths. This enables dind daemon to partially see the same filesystem as the main container in order to use features such as docker volume binding **kwargs – keyword arguments available for Container
add_port(container_port) → kfp.dsl._container_op.Container Add a container port to the container.
Parameters: container_port – Kubernetes container port For detailed spec, checkcontainer port definition https – //github.com/kubernetes-client/python/blob/master/kubernetes/client/models/v1_container_port.py
add_resource_limit(resource_name, value) → kfp.dsl._container_op.Container Add the resourcelimitof the container.
Parameters: resource_name – The nameof the resource. It can be cpu, memory, etc. value – The stringvalueof the limit.
add_resource_request(resource_name, value) → kfp.dsl._container_op.Container Add the resource request of the container.
Parameters: resource_name – The nameof the resource. It can be cpu, memory, etc. value – The stringvalueof the request.
add_volume_devices(volume_device) → kfp.dsl._container_op.Container Add a block device to be used by the container.
args E501 Arguments to the entrypoint. The docker image’s CMD is used if this isnot provided. Variablereferences $(VAR_NAME) are expanded using the container’s environment. If a variable cannot be resolved, the referencein the inputstring will be unchanged. The $(VAR_NAME) syntax can be escapedwith a double $$, ie: $$(VAR_NAME). Escapedreferences will never be expanded, regardless of whether the variableexistsor not. Cannot be updated. More info: https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell # noqa: E501
command E501 Entrypoint array. Not executed within a shell. The docker image’s ENTRYPOINT is used if this isnot provided. Variablereferences $(VAR_NAME) are expanded using the container’s environment. If a variable cannot be resolved, the referencein the inputstring will be unchanged. The $(VAR_NAME) syntax can be escapedwith a double $$, ie: $$(VAR_NAME). Escapedreferences will never be expanded, regardless of whether the variableexistsor not. Cannot be updated. More info: https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell # noqa: E501
Returns:The command of this V1Container. # noqa: E501 Returntype:list[str] Type:Gets the command of this V1Container. # noqa
env E501 Listof environment variablestosetin the container. Cannot be updated. # noqa: E501
Returns:The env of this V1Container. # noqa: E501 Returntype:list[V1EnvVar] Type:Gets the env of this V1Container. # noqa
env_from E501 Listof sources to populate environment variablesin the container. The keys defined within a source must be a C_IDENTIFIER. All invalid keys will be reported as an eventwhen the containeris starting. When a keyexistsin multiple sources, the value associated with the lastsource will take precedence. Values defined by an Env with a duplicatekey will take precedence. Cannot be updated. # noqa: E501
Returns:The env_from of this V1Container. # noqa: E501 Returntype:list[V1EnvFromSource] Type:Gets the env_from of this V1Container. # noqa
get_resource_limit(resource_name: str) → Optional[str] Get the resourcelimitof the container. Parameters:resource_name – The nameof the resource. It can be cpu, memory, etc.
get_resource_request(resource_name: str) → Optional[str] Get the resource request of the container. Parameters: resource_name – The nameof the resource. It can be cpu, memory, etc.
image E501 Docker image name. More info: https://kubernetes.io/docs/concepts/containers/images This fieldis optional toallow higher level config managementtodefaultor override container images in workload controllers like Deployments and StatefulSets. # noqa: E501
Returns:The image of this V1Container. # noqa: E501 Returntype:str Type:Gets the image of this V1Container. # noqa
image_pull_policy E501 Image pull policy. One ofAlways, Never, IfNotPresent. DefaultstoAlwaysif :latest tag is specified, or IfNotPresent otherwise. Cannot be updated. More info: https://kubernetes.io/docs/concepts/containers/images#updating-images # noqa: E501
Returns:The image_pull_policy of this V1Container. # noqa: E501 Returntype:str Type: Gets the image_pull_policy of this V1Container. # noqa
inputs A listof PipelineParam foundin the UserContainer object.
lifecycle E501 Returns:The lifecycle of this V1Container. # noqa: E501 Returntype:V1Lifecycle Type:Gets the lifecycle of this V1Container. # noqa
liveness_probe E501 Returns:The liveness_probe of this V1Container. # noqa: E501 Returntype:V1Probe Type:Gets the liveness_probe of this V1Container. # noqa
name E501 Nameof the container specified as a DNS_LABEL. Eachcontainerin a pod must have a uniquename (DNS_LABEL). Cannot be updated. # noqa: E501 Returns:The nameof this V1Container. # noqa: E501 Returntype:str Type:Gets the nameof this V1Container. # noqa openapi_types= {'args': 'list[str]', 'command': 'list[str]', 'env': 'list[V1EnvVar]', 'env_from': 'list[V1EnvFromSource]', 'image': 'str', 'image_pull_policy': 'str', 'lifecycle': 'V1Lifecycle', 'liveness_probe': 'V1Probe', 'mirror_volume_mounts': 'bool', 'name': 'str', 'ports': 'list[V1ContainerPort]', 'readiness_probe': 'V1Probe', 'resources': 'V1ResourceRequirements', 'security_context': 'V1SecurityContext', 'startup_probe': 'V1Probe', 'stdin': 'bool', 'stdin_once': 'bool', 'termination_message_path': 'str', 'termination_message_policy': 'str', 'tty': 'bool', 'volume_devices': 'list[V1VolumeDevice]', 'volume_mounts': 'list[V1VolumeMount]', 'working_dir': 'str'}
ports E501 Listof ports to expose from the container. Exposing a port here gives the system additional information about the network connections a container uses, but is primarily informational. Not specifying a port here DOES NOT prevent that port from being exposed. Any port which is listening on the default “0.0.0.0” address inside a container will be accessiblefrom the network. Cannot be updated. # noqa: E501 Returns:The ports of this V1Container. # noqa: E501 Returntype:list[V1ContainerPort] Type:Gets the ports of this V1Container. # noqa
readiness_probe E501 Returns:The readiness_probe of this V1Container. # noqa: E501 Returntype:V1Probe Type:Gets the readiness_probe of this V1Container. # noqa
resources E501 Returns:The resources of this V1Container. # noqa: E501 Returntype:V1ResourceRequirements Type:Gets the resources of this V1Container. # noqa
security_context E501 Returns:The security_context of this V1Container. # noqa: E501 Returntype:V1SecurityContext Type:Gets the security_context of this V1Container. # noqa
set_cpu_limit(cpu: Union[str, kfp.dsl._pipeline_param.PipelineParam]) → kfp.dsl._container_op.Container Set cpu limit (maximum) for this operator. Parameters:cpu (Union[str, PipelineParam]) – A string which can be a numberor a number followed by “m”, which means 1/1000.
set_cpu_request(cpu: Union[str, kfp.dsl._pipeline_param.PipelineParam]) → kfp.dsl._container_op.Container Set cpu request (minimum) for this operator. Parameters:cpu (Union[str, PipelineParam]) – A string which can be a numberor a number followed by “m”, which means 1/1000.
Parameters: name – The nameof the environment variable. value – The valueof the environment variable.
set_ephemeral_storage_limit(size) → kfp.dsl._container_op.Container Set ephemeral-storage request (maximum) for this operator.
Parameters:size – a string which can be a numberor a number followed by one of “E”, “P”, “T”, “G”, “M”, “K”.
set_ephemeral_storage_request(size) → kfp.dsl._container_op.Container Set ephemeral-storage request (minimum) for this operator.
Parameters:size – a string which can be a numberor a number followed by one of “E”, “P”, “T”, “G”, “M”, “K”.
set_gpu_limit(gpu: Union[str, kfp.dsl._pipeline_param.PipelineParam], vendor: Union[str, kfp.dsl._pipeline_param.PipelineParam] = 'nvidia') → kfp.dsl._container_op.Container Set gpu limitfor the operator. This functionadd ‘<vendor>.com/gpu’ intoresource limit. Note that there isno need toadd GPU request. GPUs areonly supposed to be specified in the limits section. See https://kubernetes.io/docs/tasks/manage-gpus/scheduling-gpus/.
Parameters: gpu (Union[str, PipelineParam]) – A string which must be a positive number. vendor (Union[str, PipelineParam]) – Optional. A string which is the vendor of the requested gpu. The supported valuesare: ‘nvidia’ (default), and ‘amd’. The valueis ignored in v2.
set_image_pull_policy(image_pull_policy) → kfp.dsl._container_op.Container Set image pull policyfor the container. Parameters:image_pull_policy – One ofAlways, Never, IfNotPresent.
set_lifecycle(lifecycle) → kfp.dsl._container_op.Container Setup a lifecycle config for the container.
set_memory_limit(memory: Union[str, kfp.dsl._pipeline_param.PipelineParam]) → kfp.dsl._container_op.Container Setmemorylimit (maximum) for this operator.
Parameters: memory (Union[str, PipelineParam]) – a string which can be a numberor a number followed by one of “E”, “P”, “T”, “G”, “M”, “K”.
set_memory_request(memory: Union[str, kfp.dsl._pipeline_param.PipelineParam]) → kfp.dsl._container_op.Container Setmemory request (minimum) for this operator.
Parameters: memory (Union[str, PipelineParam]) – a string which can be a numberor a number followed by one of “E”, “P”, “T”, “G”, “M”, “K”.
set_mirror_volume_mounts(mirror_volume_mounts=True) Setting mirrorVolumeMounts totrue will mount the same volumes specified in the maincontainerto the container (including artifacts), at the same mountPaths. This enables dind daemon to partially see the same filesystem as the maincontainerinordertouse features such as docker volume binding.
Parameters: mirror_volume_mounts – boolean flag
set_readiness_probe(readiness_probe) → kfp.dsl._container_op.Container Set a readiness probe for the container.
set_stdin(stdin=True) → kfp.dsl._container_op.Container Whether this container should allocate a buffer for stdin in the container runtime. If this isnotset, readsfrom stdin in the container will alwaysresultin EOF.
Parameters: stdin – boolean flag
set_stdin_once(stdin_once=True) → kfp.dsl._container_op.Container Whether the container runtime should close the stdin channel after it has been opened by a single attach. When stdin istrue the stdin stream will remain open across multiple attach sessions. If stdinOnce issettotrue, stdin is opened oncontainerstart, isemptyuntil the firstclient attaches to stdin, andthen remains openand accepts datauntil the client disconnects, at which time stdin is closed and remains closed until the containeris restarted. If this flag isfalse, a container processes that readsfrom stdin will never receive an EOF.
Parameters: stdin_once – boolean flag
set_termination_message_path(termination_message_path) → kfp.dsl._container_op.Container Pathat which the fileto which the container’s termination message will be written is mounted into the container’s filesystem. Message written is intended to be brief finalstatus, such as an assertionfailure message. Will be truncated by the node if greater than4096 bytes. The total message length across all containers will be limited to12kb.
Parameters: termination_message_path – pathfor the termination message
set_termination_message_policy(termination_message_policy) → kfp.dsl._container_op.Container Indicate how the termination message should be populated. File will use the contentsof terminationMessagePath to populate the containerstatus message onbothsuccessand failure. FallbackToLogsOnError will use the lastchunkofcontainerlogoutputif the termination message fileisemptyand the container exited with an error. The logoutputis limited to2048bytesor80lines, whichever is smaller.
set_tty(tty: bool = True) → kfp.dsl._container_op.Container Whether this container should allocate a TTY for itself, also requires ‘stdin’ to be true.
Parameters: tty – boolean flag
startup_probe E501 Returns: The startup_probe of this V1Container. # noqa: E501 Returntype: V1Probe Type: Gets the startup_probe of this V1Container. # noqa
stdin E501 Whether this container should allocate a buffer for stdin in the container runtime. If this isnotset, readsfrom stdin in the container will alwaysresultin EOF. Defaultis false. # noqa: E501 Returns: The stdin of this V1Container. # noqa: E501 Returntype: bool Type: Gets the stdin of this V1Container. # noqa
stdin_once E501 Whether the container runtime should close the stdin channel after it has been opened by a single attach. When stdin istrue the stdin stream will remain open across multiple attach sessions. If stdinOnce issettotrue, stdin is opened oncontainerstart, isemptyuntil the firstclient attaches to stdin, andthen remains openand accepts datauntil the client disconnects, at which time stdin is closed and remains closed until the containeris restarted. If this flag isfalse, a container processes that readsfrom stdin will never receive an EOF. Defaultisfalse# noqa: E501
Returns: The stdin_once of this V1Container. # noqa: E501 Returntype: bool Type: Gets the stdin_once of this V1Container. # noqa
termination_message_path E501 Optional: Pathat which the fileto which the container’s termination message will be written is mounted into the container’s filesystem. Message written is intended to be brief finalstatus, such as an assertionfailure message. Will be truncated by the node if greater than4096 bytes. The total message length across all containers will be limited to12kb. Defaultsto /dev/termination-log. Cannot be updated. # noqa: E501
Returns: The termination_message_path of this V1Container. # noqa: E501 Returntype: str Type: Gets the termination_message_path of this V1Container. # noqa
termination_message_policy E501 Indicate how the termination message should be populated. File will use the contentsof terminationMessagePath to populate the containerstatus message onbothsuccessand failure. FallbackToLogsOnError will use the lastchunkofcontainerlogoutputif the termination message fileisemptyand the container exited with an error. The logoutputis limited to2048bytesor80lines, whichever is smaller. Defaultsto File. Cannot be updated. # noqa: E501 Returns: The termination_message_policy of this V1Container. # noqa: E501 Returntype: str Type: Gets the termination_message_policy of this V1Container. # noqa
to_dict() Returns the model properties as a dict
to_str() Returns the string representation of the model
tty E501 Whether this container should allocate a TTY for itself, also requires ‘stdin’ to be true. Defaultis false. # noqa: E501 Returns: The tty of this V1Container. # noqa: E501 Returntype: bool Type: Gets the tty of this V1Container. # noqa
volume_devices E501 volumeDevices is the listofblock devices to be used by the container. # noqa: E501 Returns: The volume_devices of this V1Container. # noqa: E501 Returntype: list[V1VolumeDevice] Type: Gets the volume_devices of this V1Container. # noqa
volume_mounts E501 Pod volumes tomountinto the container’s filesystem. Cannot be updated. # noqa: E501 Returns: The volume_mounts of this V1Container. # noqa: E501 Returntype: list[V1VolumeMount] Type: Gets the volume_mounts of this V1Container. # noqa
working_dir E501 Container’s working directory. Ifnot specified, the container runtime’s default will be used, which might be configured in the container image. Cannot be updated. # noqa: E501 Returns: The working_dir of this V1Container. # noqa: E501 Returntype: str Type: Gets the working_dir of this V1Container. # noqa
Represents an argo workflow UserContainer (io.argoproj.workflow.v1alpha1.UserContainer) to be used in UserContainer property in argo’s workflow template (io.argoproj.workflow.v1alpha1.Template).
UserContainer inherits from Container class with an addition of mirror_volume_mounts attribute (mirrorVolumeMounts property).
image – image to use for the user container, e.g. redis:alpine
command – entrypoint array. Not executed within a shell.
args – arguments to the entrypoint.
mirror_volume_mounts – MirrorVolumeMounts will mount the same volumes specified in the main container to the container (including artifacts), at the same mountPaths. This enables dind daemon to partially see the same filesystem as the main container in order to use features such as docker volume binding
**kwargs – keyword arguments available for Container
swagger_types
The key is attribute name and the value is attribute type.
Type:
dict
Example
1 2 3 4
from kfp.dsl import ContainerOp, UserContainer # creates a `ContainerOp` and adds a redis init container op = (ContainerOp(name='foo-op', image='busybox:latest') .add_initContainer(UserContainer(name='redis', image='redis:alpine')))
Arguments to the entrypoint. The docker image’s CMD is used if this is not provided. Variable references $(VAR_NAME) are expanded using the container’s environment. If a variable cannot be resolved, the reference in the input string will be unchanged. The $(VAR_NAME) syntax can be escaped with a double $$, ie: $$(VAR_NAME). Escaped references will never be expanded, regardless of whether the variable exists or not. Cannot be updated. More info: https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell # noqa: E501
Entrypoint array. Not executed within a shell. The docker image’s ENTRYPOINT is used if this is not provided. Variable references $(VAR_NAME) are expanded using the container’s environment. If a variable cannot be resolved, the reference in the input string will be unchanged. The $(VAR_NAME) syntax can be escaped with a double $$, ie: $$(VAR_NAME). Escaped references will never be expanded, regardless of whether the variable exists or not. Cannot be updated. More info: https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell # noqa: E501
Returns:
The command of this V1Container. # noqa: E501
Return type:
list[str]
Type:
Gets the command of this V1Container. # noqa
env
E501
List of environment variables to set in the container. Cannot be updated. # noqa: E501
Returns:
The env of this V1Container. # noqa: E501
Return type:
list[V1EnvVar]
Type:
Gets the env of this V1Container. # noqa
env_from
E501
List of sources to populate environment variables in the container. The keys defined within a source must be a C_IDENTIFIER. All invalid keys will be reported as an event when the container is starting. When a key exists in multiple sources, the value associated with the last source will take precedence. Values defined by an Env with a duplicate key will take precedence. Cannot be updated. # noqa: E501
resource_name – The name of the resource. It can be cpu, memory, etc.
image
E501
Docker image name. More info: https://kubernetes.io/docs/concepts/containers/images This field is optional to allow higher level config management to default or override container images in workload controllers like Deployments and StatefulSets. # noqa: E501
List of ports to expose from the container. Exposing a port here gives the system additional information about the network connections a container uses, but is primarily informational. Not specifying a port here DOES NOT prevent that port from being exposed. Any port which is listening on the default “0.0.0.0” address inside a container will be accessible from the network. Cannot be updated. # noqa: E501
Returns:
The ports of this V1Container. # noqa: E501
Return type:
list[V1ContainerPort]
Type:
Gets the ports of this V1Container. # noqa
readiness_probe
E501
Returns:
The readiness_probe of this V1Container. # noqa: E501
Return type:
V1Probe
Type:
Gets the readiness_probe of this V1Container. # noqa
resources
E501
Returns:
The resources of this V1Container. # noqa: E501
Return type:
V1ResourceRequirements
Type:
Gets the resources of this V1Container. # noqa
security_context
E501
Returns:
The security_context of this V1Container. # noqa: E501
Return type:
V1SecurityContext
Type:
Gets the security_context of this V1Container. # noqa
gpu (Union[str, PipelineParam]) – A string which must be a positive number.
vendor (Union[str, PipelineParam]) – Optional. A string which is the vendor of the requested gpu. The supported values are: ‘nvidia’ (default), and ‘amd’. The value is ignored in v2.
Setting mirrorVolumeMounts to true will mount the same volumes specified in the main container to the container (including artifacts), at the same mountPaths. This enables dind daemon to partially see the same filesystem as the main container in order to use features such as docker volume binding.
Whether this container should allocate a buffer for stdin in the container runtime. If this is not set, reads from stdin in the container will always result in EOF.
Whether the container runtime should close the stdin channel after it has been opened by a single attach. When stdin is true the stdin stream will remain open across multiple attach sessions. If stdinOnce is set to true, stdin is opened on container start, is empty until the first client attaches to stdin, and then remains open and accepts data until the client disconnects, at which time stdin is closed and remains closed until the container is restarted. If this flag is false, a container processes that reads from stdin will never receive an EOF.
Path at which the file to which the container’s termination message will be written is mounted into the container’s filesystem. Message written is intended to be brief final status, such as an assertion failure message. Will be truncated by the node if greater than 4096 bytes. The total message length across all containers will be limited to 12kb.
Parameters:
termination_message_path – path for the termination message
Indicate how the termination message should be populated. File will use the contents of terminationMessagePath to populate the container status message on both success and failure. FallbackToLogsOnError will use the last chunk of container log output if the termination message file is empty and the container exited with an error. The log output is limited to 2048 bytes or 80 lines, whichever is smaller.
Parameters:
termination_message_policy – File or FallbackToLogsOnError
Whether this container should allocate a TTY for itself, also requires ‘stdin’ to be true.
Parameters:
tty – boolean flag
startup_probe
E501
Returns:
The startup_probe of this V1Container. # noqa: E501
Return type:
V1Probe
Type:
Gets the startup_probe of this V1Container. # noqa
stdin
E501
Whether this container should allocate a buffer for stdin in the container runtime. If this is not set, reads from stdin in the container will always result in EOF. Default is false. # noqa: E501
Returns:
The stdin of this V1Container. # noqa: E501
Return type:
bool
Type:
Gets the stdin of this V1Container. # noqa
stdin_once
E501
Whether the container runtime should close the stdin channel after it has been opened by a single attach. When stdin is true the stdin stream will remain open across multiple attach sessions. If stdinOnce is set to true, stdin is opened on container start, is empty until the first client attaches to stdin, and then remains open and accepts data until the client disconnects, at which time stdin is closed and remains closed until the container is restarted. If this flag is false, a container processes that reads from stdin will never receive an EOF. Default is false # noqa: E501
Returns:
The stdin_once of this V1Container. # noqa: E501
Return type:
bool
Type:
Gets the stdin_once of this V1Container. # noqa
termination_message_path
E501
Optional: Path at which the file to which the container’s termination message will be written is mounted into the container’s filesystem. Message written is intended to be brief final status, such as an assertion failure message. Will be truncated by the node if greater than 4096 bytes. The total message length across all containers will be limited to 12kb. Defaults to /dev/termination-log. Cannot be updated. # noqa: E501
Returns:
The termination_message_path of this V1Container. # noqa: E501
Return type:
str
Type:
Gets the termination_message_path of this V1Container. # noqa
termination_message_policy
E501
Indicate how the termination message should be populated. File will use the contents of terminationMessagePath to populate the container status message on both success and failure. FallbackToLogsOnError will use the last chunk of container log output if the termination message file is empty and the container exited with an error. The log output is limited to 2048 bytes or 80 lines, whichever is smaller. Defaults to File. Cannot be updated. # noqa: E501
Returns:
The termination_message_policy of this V1Container. # noqa: E501
Return type:
str
Type:
Gets the termination_message_policy of this V1Container. # noqa
to_dict()
Returns the model properties as a dict
to_str()
Returns the string representation of the model
tty
E501
Whether this container should allocate a TTY for itself, also requires ‘stdin’ to be true. Default is false. # noqa: E501
Returns:
The tty of this V1Container. # noqa: E501
Return type:
bool
Type:
Gets the tty of this V1Container. # noqa
volume_devices
E501
volumeDevices is the list of block devices to be used by the container. # noqa: E501
Returns:
The volume_devices of this V1Container. # noqa: E501
Return type:
list[V1VolumeDevice]
Type:
Gets the volume_devices of this V1Container. # noqa
volume_mounts
E501
Pod volumes to mount into the container’s filesystem. Cannot be updated. # noqa: E501
Returns:
The volume_mounts of this V1Container. # noqa: E501
Return type:
list[V1VolumeMount]
Type:
Gets the volume_mounts of this V1Container. # noqa
working_dir
E501
Container’s working directory. If not specified, the container runtime’s default will be used, which might be configured in the container image. Cannot be updated. # noqa: E501
resource_name – A desired name for the PVC which will be created
size – The size of the PVC which will be created
storage_class – The storage class to use for the dynamically created PVC
modes – The access modes for the PVC
annotations – Annotations to be patched in the PVC
data_source – May be a V1TypedLocalObjectReference, and then it is used in the data_source field of the PVC as is. Can also be a string/PipelineParam, and in that case it will be used as a VolumeSnapshot name (Alpha feature)
volume_name – VolumeName is the binding reference to the PersistentVolume backing this claim.
generate_unique_name – Generate unique name for the PVC
ValueError – if k8s_resource is provided along with other arguments if k8s_resource is not a V1PersistentVolumeClaim if size is None if size is an invalid memory string (when not a
Each constraint is a key-value pair label. For the container to be eligible to run on a node, the node must have each of the constraints appeared as labels.
Parameters:
label_name (Union[str, PipelineParam]) – The name of the constraint label.
value (Union[str, PipelineParam]) – The value of the constraint label.
Sets the number of times the task is retried until it’s declared failed.
Parameters:
num_retries – Number of times to retry on failures.
policy – Retry policy name.
backoff_duration – The time interval between retries. Defaults to an immediate retry. In case you specify a simple number, the unit defaults to seconds. You can also specify a different unit, for instance, 2m (2 minutes), 1h (1 hour).
backoff_factor – The exponential backoff factor applied to backoff_duration. For example, if backoff_duration=”60” (60 seconds) and backoff_factor=2, the first retry will happen after 60 seconds, then after 120, 240, and so on.
backoff_max_duration – The maximum interval that can be reached with the backoff strategy.
ValueError – if k8s_resource is provided along with other arguments if k8s_resource is not a VolumeSnapshot if pvc and volume are None if pvc and volume are not None if volume does not reference a PVC
Each constraint is a key-value pair label. For the container to be eligible to run on a node, the node must have each of the constraints appeared as labels.
Parameters:
label_name (Union[str, PipelineParam]) – The name of the constraint label.
value (Union[str, PipelineParam]) – The value of the constraint label.
Sets the number of times the task is retried until it’s declared failed.
Parameters:
num_retries – Number of times to retry on failures.
policy – Retry policy name.
backoff_duration – The time interval between retries. Defaults to an immediate retry. In case you specify a simple number, the unit defaults to seconds. You can also specify a different unit, for instance, 2m (2 minutes), 1h (1 hour).
backoff_factor – The exponential backoff factor applied to backoff_duration. For example, if backoff_duration=”60” (60 seconds) and backoff_factor=2, the first retry will happen after 60 seconds, then after 120, 240, and so on.
backoff_max_duration – The maximum interval that can be reached with the backoff strategy.
# Warning: caching is tricky when recursion is involved. Please be careful # and set proper max_cache_staleness in case of infinite loop. import kfp.dsl as dsl @dsl.graph_component def flip_component(flip_result): print_flip = PrintOp(flip_result) flipA = FlipCoinOp().after(print_flip) flipA.execution_options.caching_strategy.max_cache_staleness = "P0D" with dsl.Condition(flipA.output == 'heads'): flip_component(flipA.output) return {'flip_result': flipA.output}
name – The pipeline name. Default to a sanitized version of the function name.
description – Optionally, a human-readable description of the pipeline.
pipeline_root – The root directory to generate input/output URI under this pipeline. This is required if input/output URI placeholder is used in this pipeline.
This decorator adds the metadata to the function object itself.
Args:
name: Human-readable name of the component description: Optional. Description of the component base_image: Optional. Docker container image to use as the base of the
component. Needs to have Python 3.5+ installed.
target_component_file: Optional. Local file to store the component
definition. The file can then be used for sharing.
Returns:
The same function (with some metadata fields set).
Deprecated since version 0.2.6: This decorator does not seem to be used, so we deprecate it. If you need this decorator, please create an issue at https://github.com/kubeflow/pipelines/issues