|
1 | | -import typing as t |
2 | | - |
3 | | -from pydantic import Field, conint, constr, field_validator, ValidationInfo |
4 | | - |
5 | | -from configomatic import Configuration as BaseConfiguration, Section, LoggingConfiguration |
| 1 | +from configomatic import ( |
| 2 | + Configuration as BaseConfiguration, |
| 3 | +) |
| 4 | +from configomatic import ( |
| 5 | + LoggingConfiguration, |
| 6 | + Section, |
| 7 | +) |
| 8 | +from pydantic import Field, ValidationInfo, conint, constr, field_validator |
6 | 9 |
|
7 | 10 |
|
8 | 11 | class HelmClientConfiguration(Section): |
9 | 12 | """ |
10 | 13 | Configuration for the Helm client. |
11 | 14 | """ |
| 15 | + |
12 | 16 | #: The default timeout to use with Helm releases |
13 | 17 | #: Can be an integer number of seconds or a duration string like 5m, 5h |
14 | | - default_timeout: t.Union[int, constr(min_length = 1)] = "1h" |
| 18 | + default_timeout: int | constr(min_length=1) = "1h" |
15 | 19 | #: The executable to use |
16 | 20 | #: By default, we assume Helm is on the PATH |
17 | | - executable: constr(min_length = 1) = "helm" |
| 21 | + executable: constr(min_length=1) = "helm" |
18 | 22 | #: The maximum number of revisions to retain in the history of releases |
19 | 23 | history_max_revisions: int = 10 |
20 | 24 | #: Indicates whether to verify TLS when pulling charts |
21 | 25 | insecure_skip_tls_verify: bool = False |
22 | 26 | #: The directory to use for unpacking charts |
23 | 27 | #: By default, the system temporary directory is used |
24 | | - unpack_directory: t.Optional[str] = None |
| 28 | + unpack_directory: str | None = None |
25 | 29 |
|
26 | 30 |
|
27 | 31 | class Configuration( |
28 | 32 | BaseConfiguration, |
29 | | - default_path = "/etc/capi-addon-provider/config.yaml", |
30 | | - path_env_var = "CAPI_ADDON_PROVIDER_CONFIG", |
31 | | - env_prefix = "CAPI_ADDON_PROVIDER" |
| 33 | + default_path="/etc/capi-addon-provider/config.yaml", |
| 34 | + path_env_var="CAPI_ADDON_PROVIDER_CONFIG", |
| 35 | + env_prefix="CAPI_ADDON_PROVIDER", |
32 | 36 | ): |
33 | 37 | """ |
34 | 38 | Top-level configuration model. |
35 | 39 | """ |
| 40 | + |
36 | 41 | #: The logging configuration |
37 | | - logging: LoggingConfiguration = Field(default_factory = LoggingConfiguration) |
| 42 | + logging: LoggingConfiguration = Field(default_factory=LoggingConfiguration) |
38 | 43 |
|
39 | 44 | #: The API group of the cluster CRDs |
40 | | - api_group: constr(min_length = 1) = "addons.stackhpc.com" |
| 45 | + api_group: constr(min_length=1) = "addons.stackhpc.com" |
41 | 46 | #: The prefix to use for operator annotations |
42 | | - annotation_prefix: constr(min_length = 1) = Field(None, validate_default = True) |
| 47 | + annotation_prefix: constr(min_length=1) = Field(None, validate_default=True) |
43 | 48 | #: A list of categories to place CRDs into |
44 | | - crd_categories: t.List[constr(min_length = 1)] = Field( |
45 | | - default_factory = lambda: ["cluster-api", "capi-addons"] |
| 49 | + crd_categories: list[constr(min_length=1)] = Field( |
| 50 | + default_factory=lambda: ["cluster-api", "capi-addons"] |
46 | 51 | ) |
47 | 52 |
|
48 | 53 | #: The field manager name to use for server-side apply |
49 | | - easykube_field_manager: constr(min_length = 1) = "cluster-api-addon-provider" |
| 54 | + easykube_field_manager: constr(min_length=1) = "cluster-api-addon-provider" |
50 | 55 |
|
51 | 56 | #: The amount of time (seconds) before a watch is forcefully restarted |
52 | | - watch_timeout: conint(gt = 0) = 600 |
| 57 | + watch_timeout: conint(gt=0) = 600 |
53 | 58 |
|
54 | 59 | #: The delay to use for temporary errors by default |
55 | | - temporary_error_delay: conint(gt = 0) = 15 |
| 60 | + temporary_error_delay: conint(gt=0) = 15 |
56 | 61 |
|
57 | 62 | #: The Helm client configuration |
58 | | - helm_client: HelmClientConfiguration = Field(default_factory = HelmClientConfiguration) |
| 63 | + helm_client: HelmClientConfiguration = Field( |
| 64 | + default_factory=HelmClientConfiguration |
| 65 | + ) |
59 | 66 |
|
60 | 67 | #: Label indicating that an addon belongs to a cluster |
61 | | - cluster_label: constr(min_length = 1) = Field(None, validate_default = True) |
| 68 | + cluster_label: constr(min_length=1) = Field(None, validate_default=True) |
62 | 69 | #: Label indicating the target namespace for the addon |
63 | | - release_namespace_label: constr(min_length = 1) = Field(None, validate_default = True) |
| 70 | + release_namespace_label: constr(min_length=1) = Field(None, validate_default=True) |
64 | 71 | #: Label indicating the name of the release for the addon |
65 | | - release_name_label: constr(min_length = 1) = Field(None, validate_default = True) |
| 72 | + release_name_label: constr(min_length=1) = Field(None, validate_default=True) |
66 | 73 | #: Label indicating that a configmap or secret should be watched for changes |
67 | | - watch_label: constr(min_length = 1) = Field(None, validate_default = True) |
| 74 | + watch_label: constr(min_length=1) = Field(None, validate_default=True) |
68 | 75 | #: Prefix to use for annotations containing a configmap checksum |
69 | | - configmap_annotation_prefix: constr(min_length = 1) = Field(None, validate_default = True) |
| 76 | + configmap_annotation_prefix: constr(min_length=1) = Field( |
| 77 | + None, validate_default=True |
| 78 | + ) |
70 | 79 | #: Prefix to use for annotations containing a secret checksum |
71 | | - secret_annotation_prefix: constr(min_length = 1) = Field(None, validate_default = True) |
| 80 | + secret_annotation_prefix: constr(min_length=1) = Field(None, validate_default=True) |
72 | 81 | #: Annotation to use to trigger restarts of workloads in lifecycle hooks |
73 | | - lifecycle_hook_restart_annotation: constr(min_length = 1) = Field(None, validate_default = True) |
| 82 | + lifecycle_hook_restart_annotation: constr(min_length=1) = Field( |
| 83 | + None, validate_default=True |
| 84 | + ) |
74 | 85 |
|
75 | | - @field_validator("annotation_prefix", mode = "before") |
| 86 | + @field_validator("annotation_prefix", mode="before") |
76 | 87 | @classmethod |
77 | 88 | def default_annotation_prefix(cls, v, info: ValidationInfo): |
78 | | - return v or info.data['api_group'] |
| 89 | + return v or info.data["api_group"] |
79 | 90 |
|
80 | | - @field_validator("cluster_label", mode = "before") |
| 91 | + @field_validator("cluster_label", mode="before") |
81 | 92 | @classmethod |
82 | 93 | def default_cluster_label(cls, v, info: ValidationInfo): |
83 | 94 | return v or f"{info.data['api_group']}/cluster" |
84 | 95 |
|
85 | | - @field_validator("release_namespace_label", mode = "before") |
| 96 | + @field_validator("release_namespace_label", mode="before") |
86 | 97 | @classmethod |
87 | 98 | def default_release_namespace_label(cls, v, info: ValidationInfo): |
88 | 99 | return v or f"{info.data['api_group']}/release-namespace" |
89 | 100 |
|
90 | | - @field_validator("release_name_label", mode = "before") |
| 101 | + @field_validator("release_name_label", mode="before") |
91 | 102 | @classmethod |
92 | 103 | def default_release_name_label(cls, v, info: ValidationInfo): |
93 | 104 | return v or f"{info.data['api_group']}/release-name" |
94 | 105 |
|
95 | | - @field_validator("watch_label", mode = "before") |
| 106 | + @field_validator("watch_label", mode="before") |
96 | 107 | @classmethod |
97 | 108 | def default_watch_label(cls, v, info: ValidationInfo): |
98 | 109 | return v or f"{info.data['api_group']}/watch" |
99 | 110 |
|
100 | | - @field_validator("configmap_annotation_prefix", mode = "before") |
| 111 | + @field_validator("configmap_annotation_prefix", mode="before") |
101 | 112 | @classmethod |
102 | 113 | def default_configmap_annotation_prefix(cls, v, info: ValidationInfo): |
103 | 114 | return v or f"configmap.{info.data['annotation_prefix']}" |
104 | 115 |
|
105 | | - @field_validator("secret_annotation_prefix", mode = "before") |
| 116 | + @field_validator("secret_annotation_prefix", mode="before") |
106 | 117 | @classmethod |
107 | 118 | def default_secret_annotation_prefix(cls, v, info: ValidationInfo): |
108 | 119 | return v or f"secret.{info.data['annotation_prefix']}" |
109 | 120 |
|
110 | | - @field_validator("lifecycle_hook_restart_annotation", mode = "before") |
| 121 | + @field_validator("lifecycle_hook_restart_annotation", mode="before") |
111 | 122 | @classmethod |
112 | 123 | def default_lifecycle_hook_restart_annotation(cls, v, info: ValidationInfo): |
113 | 124 | return v or f"{info.data['annotation_prefix']}/restarted-at" |
|
0 commit comments