-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding support for fenceAgentRemediationTemplate
Signed-off-by: Geetika Kapoor <gkapoor@redhat.com>
- Loading branch information
1 parent
9dba2e3
commit d6150b3
Showing
2 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# API Reference: https://github.com/medik8s/fence-agents-remediation | ||
from typing import Any, Dict | ||
|
||
from ocp_resources.resource import NamespacedResource, MissingRequiredArgumentError | ||
|
||
|
||
class FenceAgentsRemediationTemplate(NamespacedResource): | ||
""" | ||
FenceAgentsRemediationTemplate CRD for managing fencing agents in a Kubernetes cluster. | ||
""" | ||
|
||
api_group = NamespacedResource.ApiGroup.FENCE_AGENTS_REMEDIATION_MEDIK8S_IO | ||
|
||
def __init__( | ||
self, | ||
agent: str, | ||
remediation_strategy: str = "", | ||
retry_count: int | None = None, | ||
retry_interval: str = "", | ||
timeout: str = "", | ||
shared_parameters: Dict[str, str] | None = None, | ||
node_parameters: Dict[str, Any] | None = None, | ||
**kwargs: Any, | ||
) -> None: | ||
""" | ||
Initialize a FenceAgentsRemediationTemplate object. | ||
Args: | ||
agent (str): The name of the fence agent to use, must start with "fence_". | ||
remediation_strategy (str, optional): The strategy to use for remediation. | ||
retry_count (int, optional): The number of retry attempts for the fencing operation. | ||
retry_interval (str, optional): The interval between retry attempts. | ||
timeout (str, optional): The timeout for each fencing attempt. | ||
shared_parameters (dict, optional): Parameters common to all nodes for the fencing agent. | ||
node_parameters (dict, optional): Node-specific parameters for the fencing agent. | ||
""" | ||
super().__init__(**kwargs) | ||
self.agent = agent | ||
self.remediation_strategy = remediation_strategy | ||
self.retry_count = retry_count | ||
self.retry_interval = retry_interval | ||
self.timeout = timeout | ||
self.shared_parameters = shared_parameters or {} | ||
self.node_parameters = node_parameters or {} | ||
|
||
def to_dict(self) -> None: | ||
super().to_dict() | ||
if not self.yaml_file: | ||
if not self.agent: | ||
raise MissingRequiredArgumentError(argument="agent") | ||
if not self.agent.startswith("fence_"): | ||
raise ValueError("agent must start with 'fence_'") | ||
_spec = self.res["spec"] = {"template": {"spec": {}}} | ||
_spec["template"]["spec"]["agent"] = self.agent | ||
if self.remediation_strategy: | ||
_spec["template"]["spec"]["remediationStrategy"] = self.remediation_strategy | ||
if self.retry_count: | ||
_spec["template"]["spec"]["retrycount"] = self.retry_count | ||
if self.retry_interval: | ||
_spec["template"]["spec"]["retryinterval"] = self.retry_interval | ||
if self.timeout: | ||
_spec["template"]["spec"]["timeout"] = self.timeout | ||
if self.shared_parameters: | ||
_spec["template"]["spec"]["sharedparameters"] = self.shared_parameters | ||
if self.node_parameters: | ||
_spec["template"]["spec"]["nodeparameters"] = self.node_parameters |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters