Coverage for ocp_resources/task.py: 0%
36 statements
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-30 10:48 +0200
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-30 10:48 +0200
1from typing import Any, Dict, List, Optional
2from ocp_resources.resource import NamespacedResource, MissingRequiredArgumentError
5class Task(NamespacedResource):
6 """
7 A collection of Steps for continuous integration flow, executed as a Pod on a Kubernetes cluster.
8 API Reference: https://tekton.dev/docs/pipelines/tasks/#configuring-a-task
9 """
11 api_group: str = NamespacedResource.ApiGroup.TEKTON_DEV
13 def __init__(
14 self,
15 steps: Optional[List[Dict[str, Any]]] = None,
16 description: Optional[str] = None,
17 params: Optional[List[Dict[str, str]]] = None,
18 workspaces: Optional[List[Dict[str, Any]]] = None,
19 results: Optional[List[Dict[str, Any]]] = None,
20 volumes: Optional[List[Dict[str, Dict[str, Any]]]] = None,
21 step_template: Optional[Dict[str, Any]] = None,
22 sidecars: Optional[List[Dict[str, Any]]] = None,
23 **kwargs: Any,
24 ):
25 """
26 Create and manage Task which specifies a sequence of steps to be executed.
28 Args:
29 steps (List[Dict[str, Any]]): Specifies one or more container images to run in the Task.
30 description (Optional[str]): An informative description of the Task.
31 params (Optional[List[Dict[str, str]]]): Specifies execution parameters for the Task.
32 workspaces (Optional[List[Dict[str, Any]]]): Specifies paths to volumes required by the Task.
33 results (Optional[List[Dict[str, Any]]]): Specifies the names under which Tasks write execution results.
34 volumes (Optional[List[Dict[str, Dict[str, Any]]]]): Specifies one or more volumes that will be available to the Steps in the Task.
35 step_template (Optional[Dict[str, Any]]): Specifies a Container step definition to use as the basis for all Steps in the Task.
36 sidecars (Optional[List[Dict[str, Any]]]): Specifies Sidecar containers to run alongside the Steps in the Task.
37 """
38 super().__init__(**kwargs)
39 self.steps = steps
40 self.description = description
41 self.params = params
42 self.workspaces = workspaces
43 self.results = results
44 self.volumes = volumes
45 self.step_template = step_template
46 self.sidecars = sidecars
48 def to_dict(self) -> None:
49 super().to_dict()
50 if not self.kind_dict and not self.yaml_file:
51 if not self.steps:
52 raise MissingRequiredArgumentError(argument="steps")
53 self.res["spec"] = {}
54 _spec = self.res["spec"]
55 _spec = {"steps": self.steps}
57 if self.description:
58 _spec["description"] = self.description
60 if self.params:
61 _spec["params"] = self.params
63 if self.workspaces:
64 _spec["workspaces"] = self.workspaces
66 if self.results:
67 _spec["results"] = self.results
69 if self.volumes:
70 _spec["volumes"] = self.volumes
72 if self.step_template:
73 _spec["stepTemplate"] = self.step_template
75 if self.sidecars:
76 _spec["sidecars"] = self.sidecars