-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit reworks condition and result handling code to add support for perfdata and multi-line output.
- Loading branch information
Robert Wikman
authored
Jan 23, 2020
1 parent
3918448
commit f0aee9f
Showing
17 changed files
with
370 additions
and
249 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
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
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 |
---|---|---|
@@ -1,22 +1,40 @@ | ||
from collections import namedtuple | ||
from enum import Enum | ||
|
||
from k8s.consts import NaemonState | ||
|
||
from ..resource import Resource, NaemonStatus | ||
|
||
from k8s.resource import Resource | ||
from k8s.consts import Severity | ||
|
||
Replicas = namedtuple("Replicas", ["total", "ready", "updated", "available"]) | ||
|
||
|
||
class Deployment(Resource): | ||
def __init__(self, data): | ||
super(Deployment, self).__init__(data) | ||
class PerfMap(Enum): | ||
AVAILABLE = "available" | ||
UNAVAILABLE = "unavailable" | ||
DEGRADED = "degraded" | ||
NOREPS = "noreps" | ||
|
||
def __init__(self, data, *args, **kwargs): | ||
super(Deployment, self).__init__(data, *args, **kwargs) | ||
|
||
self.replicas = Replicas( | ||
self._status["replicas"], | ||
self._status["readyReplicas"], | ||
self._status["updatedReplicas"], | ||
self._status["availableReplicas"] | ||
self._status.get("replicas", 0), | ||
self._status.get("readyReplicas", 0), | ||
self._status.get("updatedReplicas", 0), | ||
self._status.get("availableReplicas", 0) | ||
) | ||
|
||
def _condition_severity(self, _type, status): | ||
if _type == "Available" and status != "True": | ||
return Severity.CRITICAL | ||
def _get_status(self, cnd_type, cnd_status): | ||
reps = self.replicas | ||
|
||
if cnd_type == "Available": | ||
if cnd_status == "True": | ||
return NaemonStatus(NaemonState.OK, self.perf.AVAILABLE) | ||
else: | ||
return NaemonStatus(NaemonState.CRITICAL, self.perf.UNAVAILABLE) | ||
elif reps.available < reps.total or reps.updated < reps.total: | ||
if reps.available != 0 and reps.updated != 0: | ||
return NaemonStatus(NaemonState.WARNING, self.perf.DEGRADED) | ||
return NaemonStatus(NaemonState.CRITICAL, self.perf.NOREPS) |
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
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 |
---|---|---|
@@ -1,16 +1,34 @@ | ||
from k8s.resource import Resource | ||
from k8s.consts import Severity | ||
from enum import Enum | ||
|
||
from k8s.consts import NaemonState | ||
|
||
from ..resource import Resource, NaemonStatus | ||
|
||
|
||
class Node(Resource): | ||
def __init__(self, data): | ||
super(Node, self).__init__(data) | ||
class PerfMap(Enum): | ||
AVAILABLE = "available" | ||
UNAVAILABLE = "unavailable" | ||
DEGRADED = "degraded" | ||
UNSCHEDULABLE = "unschedulable" | ||
|
||
def __init__(self, data, *args, **kwargs): | ||
super(Node, self).__init__(data, *args, **kwargs) | ||
|
||
# https://kubernetes.io/docs/concepts/architecture/nodes/#manual-node-administration | ||
self.unschedulable = data["spec"].get("unschedulable", False) | ||
|
||
def _condition_severity(self, _type, status): | ||
if _type == "Ready" and status != "True": | ||
return Severity.CRITICAL | ||
elif _type != "Ready" and status == "True": | ||
return Severity.WARNING | ||
def _get_status(self, cnd_type, cnd_status): | ||
if self.unschedulable: | ||
return NaemonStatus( | ||
NaemonState.WARNING, | ||
self.perf.UNSCHEDULABLE, | ||
"Node {} is ready, but unschedulable".format(self.meta["name"]) | ||
) | ||
elif cnd_type == "Ready": | ||
if cnd_status == "True": | ||
return NaemonStatus(NaemonState.OK, self.perf.AVAILABLE) | ||
else: | ||
return NaemonStatus(NaemonState.CRITICAL, self.perf.UNAVAILABLE) | ||
elif cnd_type != "Ready" and cnd_status == "True": | ||
return NaemonStatus(NaemonState.WARNING, self.perf.DEGRADED) |
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
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
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
Oops, something went wrong.