Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions ocp_resources/grafana.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from ocp_resources.resource import NamespacedResource


class Grafana(NamespacedResource):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty class without to_dict implement required is not allowed.
Please introduce to_dict().

"""
Grafana Resource. API Reference:
https://github.com/grafana-operator/grafana-operator/blob/master/documentation/api.md
"""

api_group = NamespacedResource.ApiGroup.INTEGREATLY_ORG
68 changes: 68 additions & 0 deletions ocp_resources/grafana_dashboard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
from ocp_resources.resource import NamespacedResource


class GrafanaDashboard(NamespacedResource):
"""
GrafanaDashboard Resource. API Reference:
https://github.com/grafana-operator/grafana-operator/blob/master/documentation/api.md
"""

api_group = NamespacedResource.ApiGroup.INTEGREATLY_ORG

def __init__(
self,
name=None,
namespace=None,
label=None,
configmap_name=None,
configmap_key=None,
data_sources=None,
yaml_file=None,
**kwargs
):
"""

Args:
name (str): Resource name
namespace (str): Resource namespace
label (dict): Resource labels (Used by Grafana to identify GrafanaDashboards)
configmap_name (str): Name of ConfigMap containing dashboard JSON
configmap_key (str): Key in ConfigMap referencing dashboard JSON
data_sources (list): List of data sources
yaml_file (str): yaml file for the resource (in lieu of other arguments)

Example:
GrafanaDashboard(
name="dashboard",
namespace="grafana",
label={"app": "grafana"},
configmap_name="my_dashboard_configmap",
configmap_key="dashboard_1",
data_sources=[{"inputName": "DS_PROMETHEUS", "datasourceName": "Prometheus"}]
)

"""
super().__init__(name=name, namespace=namespace, yaml_file=yaml_file, **kwargs)
self.label = label
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of those required? Please add verification for required args under if not self.yaml_file:

self.configmap_name = configmap_name
self.configmap_key = configmap_key
self.data_sources = data_sources

def to_dict(self):
super().to_dict()
if not self.yaml_file:
self.res.update(
{
"metadata": {
"labels": self.label,
},
"spec": {
"json": "",
"configMapRef": {
"name": self.configmap_name,
"key": self.configmap_key,
},
"datasources": self.data_sources,
},
}
)
10 changes: 10 additions & 0 deletions ocp_resources/grafana_data_source.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from ocp_resources.resource import NamespacedResource


class GrafanaDataSource(NamespacedResource):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty class without to_dict implement required is not allowed.
Please introduce to_dict().

"""
GrafanaDataSource Resource. API Reference:
https://github.com/grafana-operator/grafana-operator/blob/master/documentation/api.md
"""

api_group = NamespacedResource.ApiGroup.INTEGREATLY_ORG
1 change: 1 addition & 0 deletions ocp_resources/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ class ApiGroup:
HOSTPATHPROVISIONER_KUBEVIRT_IO = "hostpathprovisioner.kubevirt.io"
IMAGE_OPENSHIFT_IO = "image.openshift.io"
IMAGE_REGISTRY = "registry.redhat.io"
INTEGREATLY_ORG = "integreatly.org"
K8S_CNI_CNCF_IO = "k8s.cni.cncf.io"
K8S_V1_CNI_CNCF_IO = "k8s.v1.cni.cncf.io"
KUBERNETES_IO = "kubernetes.io"
Expand Down