- self.harness.charm.on.start.emit()
-
- # Verifying status
- self.assertNotIsInstance(self.harness.charm.unit.status, BlockedStatus)
-
- pod_spec, _ = self.harness.get_pod_spec()
-
- self.assertDictEqual(expected_result, pod_spec)
-
- def test_ingress_resources_with_http(self) -> NoReturn:
- """Test ingress resources with HTTP."""
- expected_result = {
- "version": 3,
- "containers": [
- {
- "name": "prometheus",
- "imageDetails": self.harness.charm.image.fetch(),
- "imagePullPolicy": "Always",
- "ports": [
- {
- "name": "prometheus",
- "containerPort": 9090,
- "protocol": "TCP",
- }
- ],
- "envConfig": {},
- "volumeConfig": [
- {
- "name": "config",
- "mountPath": "/etc/prometheus",
- "files": [
- {
- "path": "prometheus.yml",
- "content": (
- "global:\n"
- " scrape_interval: 15s\n"
- " evaluation_interval: 15s\n"
- "alerting:\n"
- " alertmanagers:\n"
- " - static_configs:\n"
- " - targets:\n"
- "rule_files:\n"
- "scrape_configs:\n"
- " - job_name: 'prometheus'\n"
- " static_configs:\n"
- " - targets: [{}]\n".format("")
- ),
- }
- ],
- }
- ],
- "command": [
- "/bin/prometheus",
- "--config.file=/etc/prometheus/prometheus.yml",
- "--storage.tsdb.path=/prometheus",
- "--web.console.libraries=/usr/share/prometheus/console_libraries",
- "--web.console.templates=/usr/share/prometheus/consoles",
- "--web.route-prefix={}".format("/"),
- "--web.external-url=http://localhost:{}{}".format(9090, "/"),
- ],
- "kubernetes": {
- "readinessProbe": {
- "httpGet": {
- "path": "/-/ready",
- "port": 9090,
- },
- "initialDelaySeconds": 10,
- "timeoutSeconds": 30,
- },
- "livenessProbe": {
- "httpGet": {
- "path": "/-/healthy",
- "port": 9090,
- },
- "initialDelaySeconds": 30,
- "periodSeconds": 30,
- },
- },
- }
- ],
- "kubernetesResources": {
- "ingressResources": [
- {
- "name": "prometheus-ingress",
- "annotations": {
- "nginx.ingress.kubernetes.io/proxy-body-size": "0",
- "nginx.ingress.kubernetes.io/ssl-redirect": "false",
- },
- "spec": {
- "rules": [
- {
- "host": "prometheus",
- "http": {
- "paths": [
- {
- "path": "/",
- "backend": {
- "serviceName": "prometheus",
- "servicePort": 9090,
- },
- }
- ]
- },
- }
- ]
- },
- }
- ],
- },
- }
-
- self.harness.charm.on.start.emit()
-
- self.harness.update_config({"site_url": "http://prometheus"})
-
- pod_spec, _ = self.harness.get_pod_spec()
-
- self.assertDictEqual(expected_result, pod_spec)
-
- def test_ingress_resources_with_https(self) -> NoReturn:
- """Test ingress resources with HTTPS."""
- expected_result = {
- "version": 3,
- "containers": [
- {
- "name": "prometheus",
- "imageDetails": self.harness.charm.image.fetch(),
- "imagePullPolicy": "Always",
- "ports": [
- {
- "name": "prometheus",
- "containerPort": 9090,
- "protocol": "TCP",
- }
- ],
- "envConfig": {},
- "volumeConfig": [
- {
- "name": "config",
- "mountPath": "/etc/prometheus",
- "files": [
- {
- "path": "prometheus.yml",
- "content": (
- "global:\n"
- " scrape_interval: 15s\n"
- " evaluation_interval: 15s\n"
- "alerting:\n"
- " alertmanagers:\n"
- " - static_configs:\n"
- " - targets:\n"
- "rule_files:\n"
- "scrape_configs:\n"
- " - job_name: 'prometheus'\n"
- " static_configs:\n"
- " - targets: [{}]\n".format("")
- ),
- }
- ],
- }
- ],
- "command": [
- "/bin/prometheus",
- "--config.file=/etc/prometheus/prometheus.yml",
- "--storage.tsdb.path=/prometheus",
- "--web.console.libraries=/usr/share/prometheus/console_libraries",
- "--web.console.templates=/usr/share/prometheus/consoles",
- "--web.route-prefix={}".format("/"),
- "--web.external-url=http://localhost:{}{}".format(9090, "/"),
- ],
- "kubernetes": {
- "readinessProbe": {
- "httpGet": {
- "path": "/-/ready",
- "port": 9090,
- },
- "initialDelaySeconds": 10,
- "timeoutSeconds": 30,
- },
- "livenessProbe": {
- "httpGet": {
- "path": "/-/healthy",
- "port": 9090,
- },
- "initialDelaySeconds": 30,
- "periodSeconds": 30,
- },
- },
- }
- ],
- "kubernetesResources": {
- "ingressResources": [
- {
- "name": "prometheus-ingress",
- "annotations": {
- "nginx.ingress.kubernetes.io/proxy-body-size": "0",
- },
- "spec": {
- "rules": [
- {
- "host": "prometheus",
- "http": {
- "paths": [
- {
- "path": "/",
- "backend": {
- "serviceName": "prometheus",
- "servicePort": 9090,
- },
- }
- ]
- },
- }
- ],
- "tls": [
- {"hosts": ["prometheus"], "secretName": "prometheus"}
- ],
- },
- }
- ],
- },
- }