From 56eb6f453d92792649ab05e844e9acacf9b2eaa7 Mon Sep 17 00:00:00 2001 From: Anthony Brice Date: Fri, 26 Jul 2024 19:39:25 -0700 Subject: [PATCH] Allow endpoint config. --- modules/oracledb-exporter/README.md | 41 ++++++++++--------- .../oracledb-exporter/templates/config.cue | 9 ++-- .../templates/servicemonitor.cue | 20 +++++---- 3 files changed, 40 insertions(+), 30 deletions(-) diff --git a/modules/oracledb-exporter/README.md b/modules/oracledb-exporter/README.md index 2a4458a..f79736c 100644 --- a/modules/oracledb-exporter/README.md +++ b/modules/oracledb-exporter/README.md @@ -45,30 +45,31 @@ timoni -n default delete oracledb-exporter ### Oracle DB Exporter values -| Key | Type | Default | Description | -|--------|-----------------------|---------|----------------------------------------------------------------------| -| `env:` | `[...corev1.#EnvVar]` | `[]` | Environment variables passed to the container. `DATA_SOURCE_NAME` required. | +| Key | Type | Default | Description | +| ------------ | ------------------------------------ | ------- | --------------------------------------------------------------------------- | +| `env:` | `[...corev1.#EnvVar]` | `[]` | Environment variables passed to the container. `DATA_SOURCE_NAME` required. | +| `endpoints:` | `smv1.#ServiceMonitorSpec.endpoints` | `[...]` | Prometheus Service Monitor endpoints. | ### General values -| Key | Type | Default | Description | -|------------------------------|-----------------------------------------|-------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------| -| `image: tag:` | `string` | `` | Container image tag | -| `image: digest:` | `string` | `` | Container image digest, takes precedence over `tag` when specified | +| Key | Type | Default | Description | +| ---------------------------- | --------------------------------------- | ----------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- | +| `image: tag:` | `string` | `` | Container image tag | +| `image: digest:` | `string` | `` | Container image digest, takes precedence over `tag` when specified | | `image: repository:` | `string` | `ghcr.io/iamseth/oracledb_exporter` | Container image repository | -| `image: pullPolicy:` | `string` | `IfNotPresent` | [Kubernetes image pull policy](https://kubernetes.io/docs/concepts/containers/images/#image-pull-policy) | -| `metadata: labels:` | `{[ string]: string}` | `{}` | Common labels for all resources | -| `metadata: annotations:` | `{[ string]: string}` | `{}` | Common annotations for all resources | -| `podAnnotations:` | `{[ string]: string}` | `{}` | Annotations applied to pods | -| `imagePullSecrets:` | `[...timoniv1.ObjectReference]` | `[]` | [Kubernetes image pull secrets](https://kubernetes.io/docs/concepts/containers/images/#specifying-imagepullsecrets-on-a-pod) | -| `tolerations:` | `[ ...corev1.#Toleration]` | `[]` | [Kubernetes toleration](https://kubernetes.io/docs/concepts/scheduling-eviction/taint-and-toleration) | -| `affinity:` | `corev1.#Affinity` | `{}` | [Kubernetes affinity and anti-affinity](https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#affinity-and-anti-affinity) | -| `resources:` | `timoniv1.#ResourceRequirements` | `{}` | [Kubernetes resource requests and limits](https://kubernetes.io/docs/concepts/configuration/manage-resources-containers) | -| `topologySpreadConstraints:` | `[...corev1.#TopologySpreadConstraint]` | `[]` | [Kubernetes pod topology spread constraints](https://kubernetes.io/docs/concepts/scheduling-eviction/topology-spread-constraints) | -| `podSecurityContext:` | `corev1.#PodSecurityContext` | `{}` | [Kubernetes pod security context](https://kubernetes.io/docs/tasks/configure-pod-container/security-context) | -| `securityContext:` | `corev1.#SecurityContext` | `{}` | [Kubernetes container security context](https://kubernetes.io/docs/tasks/configure-pod-container/security-context) | -| `service: annotations:` | `{[ string]: string}` | `{}` | Annotations applied to the Kubernetes Service | -| `service: port:` | `int` | `9161` | Kubernetes Service HTTP port | +| `image: pullPolicy:` | `string` | `IfNotPresent` | [Kubernetes image pull policy](https://kubernetes.io/docs/concepts/containers/images/#image-pull-policy) | +| `metadata: labels:` | `{[ string]: string}` | `{}` | Common labels for all resources | +| `metadata: annotations:` | `{[ string]: string}` | `{}` | Common annotations for all resources | +| `podAnnotations:` | `{[ string]: string}` | `{}` | Annotations applied to pods | +| `imagePullSecrets:` | `[...timoniv1.ObjectReference]` | `[]` | [Kubernetes image pull secrets](https://kubernetes.io/docs/concepts/containers/images/#specifying-imagepullsecrets-on-a-pod) | +| `tolerations:` | `[ ...corev1.#Toleration]` | `[]` | [Kubernetes toleration](https://kubernetes.io/docs/concepts/scheduling-eviction/taint-and-toleration) | +| `affinity:` | `corev1.#Affinity` | `{}` | [Kubernetes affinity and anti-affinity](https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#affinity-and-anti-affinity) | +| `resources:` | `timoniv1.#ResourceRequirements` | `{}` | [Kubernetes resource requests and limits](https://kubernetes.io/docs/concepts/configuration/manage-resources-containers) | +| `topologySpreadConstraints:` | `[...corev1.#TopologySpreadConstraint]` | `[]` | [Kubernetes pod topology spread constraints](https://kubernetes.io/docs/concepts/scheduling-eviction/topology-spread-constraints) | +| `podSecurityContext:` | `corev1.#PodSecurityContext` | `{}` | [Kubernetes pod security context](https://kubernetes.io/docs/tasks/configure-pod-container/security-context) | +| `securityContext:` | `corev1.#SecurityContext` | `{}` | [Kubernetes container security context](https://kubernetes.io/docs/tasks/configure-pod-container/security-context) | +| `service: annotations:` | `{[ string]: string}` | `{}` | Annotations applied to the Kubernetes Service | +| `service: port:` | `int` | `9161` | Kubernetes Service HTTP port | #### Recommended values diff --git a/modules/oracledb-exporter/templates/config.cue b/modules/oracledb-exporter/templates/config.cue index 10a5b39..3a43d31 100644 --- a/modules/oracledb-exporter/templates/config.cue +++ b/modules/oracledb-exporter/templates/config.cue @@ -3,6 +3,7 @@ package templates import ( corev1 "k8s.io/api/core/v1" timoniv1 "timoni.sh/core/v1alpha1" + smv1 "monitoring.coreos.com/servicemonitor/v1" ) // Config defines the schema and defaults for the Instance values. @@ -80,9 +81,8 @@ import ( env!: [...corev1.#EnvVar] & [ { // An Oracle Database connection string for the Go lang driver. https://github.com/iamseth/oracledb_exporter?tab=readme-ov-file#running - name: "DATA_SOURCE_NAME" - value: string - }, + name: "DATA_SOURCE_NAME" + } & corev1.#EnvVar ] // Pod optional settings. @@ -92,6 +92,9 @@ import ( tolerations?: [...corev1.#Toleration] affinity?: corev1.#Affinity topologySpreadConstraints?: [...corev1.#TopologySpreadConstraint] + + // Service Monitor optional settings. + endpoints?: smv1.#ServiceMonitorSpec.endpoints } // Instance takes the config values and outputs the Kubernetes objects. diff --git a/modules/oracledb-exporter/templates/servicemonitor.cue b/modules/oracledb-exporter/templates/servicemonitor.cue index 7de9b43..0a0fec3 100644 --- a/modules/oracledb-exporter/templates/servicemonitor.cue +++ b/modules/oracledb-exporter/templates/servicemonitor.cue @@ -12,12 +12,18 @@ import ( spec: { selector: matchLabels: "app.kubernetes.io/name": #config.metadata.name namespaceSelector: matchNames: [#config.metadata.namespace] - endpoints: [ - { - port: "http" - path: "/metrics" - interval: "1s" - }, - ] + if #config.endpoints == _|_ { + endpoints: [ + { + port: "http" + path: "/metrics" + interval: "1m" + scrapeTimeout: "30s" + }, + ] + } + if #config.endpoints != _|_ { + endpoints: #config.endpoints + } } }