Skip to content

Commit

Permalink
Merge pull request #20 from seznam/zdenek_servicemonitor
Browse files Browse the repository at this point in the history
ServiceMonitor and PodMonitor objects
  • Loading branch information
zdenekbauer committed Jan 25, 2024
2 parents 86d3ebf + af26274 commit ddce073
Show file tree
Hide file tree
Showing 7 changed files with 201 additions and 29 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Version 4.5.0

* Added support for PodMonitor and ServiceMonitor objects

# Version 4.4.0

* Waiting for deployments to rollout now checks if succesfully rolled out.
Expand Down
3 changes: 2 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pyyaml = "*"
[dev-packages]
pytest = "*"
pytest-cov = "*"
codecov = "*"
codecov = "==2.1.13"
importlib-metadata = "*"
typing-extensions = "*"
coverage = "==6.2"
143 changes: 118 additions & 25 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified latest/vindaloo.pex
Binary file not shown.
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "4.4.0"
"version": "4.5.0"
}
63 changes: 63 additions & 0 deletions vindaloo/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
'CronJob',
'Job',
'Service',
'ServiceMonitor',
'PodMonitor',
)


Expand Down Expand Up @@ -523,3 +525,64 @@ def serialize(self, *args, **kwargs):
res['immutable'] = True

return res


class MonitorMixin:
api_version = "monitoring.coreos.com/v1"
kind = "Monitor"

def serialize(self, *args, **kwargs):
res = {
'apiVersion': self.api_version,
'kind': self.kind,
'metadata': self.metadata.serialize(*args, **kwargs),
'spec': self.spec.serialize(*args, **kwargs),
}
return res

def set_name(self, name):
self.name = name
self.metadata.name = name


class MonitorSpec(Dict):
selector: Dict()
endpoints: List()


class ServiceMonitor(MonitorMixin, KubernetesManifestMixin):
obj_type = "servicemonitor"
kind = "ServiceMonitor"

def __init__(self, name: str, path: str, port: str, service_name: str, metadata: DictType[str, Any] = None):
super().__init__(metadata, None)
self.spec = MonitorSpec(
selector=Dict({
'matchLabels': Dict({'app': service_name})
}),
endpoints=[{
'port': port,
'path': path,
'followRedirects': True,
}]
)
self.set_name(name)


class PodMonitor(MonitorMixin, KubernetesManifestMixin):
obj_type = "podmonitor"
kind = "PodMonitor"

def __init__(self, name: str, path: str, port: str, pod_name: str, metadata: DictType[str, Any] = None):
super().__init__(metadata, None)
self.spec = MonitorSpec(
selector=Dict({
'matchLabels': Dict({'app': pod_name})
}),
podMetricsEndpoints=[{
'port': port,
'path': path,
'followRedirects': True,
}]
)
self.set_name(name)
15 changes: 13 additions & 2 deletions vindaloo/vindaloo.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,16 @@

NONE = "base"
K8S_OBJECT_TYPES = [
"configmap", "secret", "podpreset", "deployment", "service", "ingres", "cronjob", "job"
"configmap",
"secret",
"podpreset",
"deployment",
"service",
"ingres",
"cronjob",
"job",
"servicemonitor",
"podmonitor",
]
K8S_OBJECT_TYPES_YAML_PREFIX = {
"configmap": "1",
Expand All @@ -46,6 +55,8 @@
"ingres": "6",
"cronjob": "7",
"job": "8",
"servicemonitor": "9",
"podmonitor": "10",
}
SUCCESS_REPLY = ("Y", "y", "a", "A")
ENVS_CONFIG_NAME = 'vindaloo_conf'
Expand All @@ -54,7 +65,7 @@
GIT_HASH_PLACEHOLDER = '{{git}}'
CHECK_VERSION_URL = 'https://raw.githubusercontent.com/seznam/vindaloo/master/version.json'

VERSION = '4.4.0'
VERSION = '4.5.0'


class RefreshException(Exception):
Expand Down

0 comments on commit ddce073

Please sign in to comment.