From 8844c0d493e47bfa1dd069d8f26984babeb46cb0 Mon Sep 17 00:00:00 2001 From: Geetika Kapoor Date: Thu, 30 May 2024 01:37:21 +0100 Subject: [PATCH] Support for SelfNodeRemediationTemplate Signed-off-by: Geetika Kapoor --- ocp_resources/resource.py | 1 + .../self_node_remediation_templates.py | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 ocp_resources/self_node_remediation_templates.py diff --git a/ocp_resources/resource.py b/ocp_resources/resource.py index e935d8b4c5..2eb9a17023 100644 --- a/ocp_resources/resource.py +++ b/ocp_resources/resource.py @@ -325,6 +325,7 @@ class ApiGroup: SCHEDULING_K8S_IO = "scheduling.k8s.io" SECURITY_ISTIO_IO = "security.istio.io" SECURITY_OPENSHIFT_IO = "security.openshift.io" + SELF_NODE_REMEDIATION_MEDIK8S_IO = "self-node-remediation.medik8s.io" SNAPSHOT_STORAGE_K8S_IO = "snapshot.storage.k8s.io" SNAPSHOT_KUBEVIRT_IO = "snapshot.kubevirt.io" SRIOVNETWORK_OPENSHIFT_IO = "sriovnetwork.openshift.io" diff --git a/ocp_resources/self_node_remediation_templates.py b/ocp_resources/self_node_remediation_templates.py new file mode 100644 index 0000000000..61986af76a --- /dev/null +++ b/ocp_resources/self_node_remediation_templates.py @@ -0,0 +1,36 @@ +# API reference: https://github.com/medik8s/self-node-remediation +from typing import Any + +from ocp_resources.resource import NamespacedResource + + +class SelfNodeRemediationTemplate(NamespacedResource): + """ + SelfNodeRemediationTemplate CRD + """ + + api_group = NamespacedResource.ApiGroup.SELF_NODE_REMEDIATION_MEDIK8S_IO + + def __init__( + self, + remediation_strategy: str = "", + **kwargs: Any, + ) -> None: + """ + Create SelfNodeRemediationTemplate object. + + Args: + remediation_strategy (str, optional): The remediation method for unhealthy nodes. + """ + super().__init__( + **kwargs, + ) + self.remediation_strategy = remediation_strategy + + def to_dict(self) -> None: + super().to_dict() + if not self.yaml_file: + _spec = self.res["spec"] = {"template": {"spec": {}}} + + if self.remediation_strategy: + _spec["template"]["spec"]["remediationStrategy"] = self.remediation_strategy