diff --git a/timoni/podinfo/README.md b/timoni/podinfo/README.md index e923f158b..804cf5ff1 100644 --- a/timoni/podinfo/README.md +++ b/timoni/podinfo/README.md @@ -118,10 +118,10 @@ values: { ### Monitoring values -| Key | Type | Default | Description | -|-------------------------|----------|---------|-------------------------------------------------------------------------------| -| `monitoring: enabled:` | `bool` | `false` | Enable [Prometheus ServiceMonitor](https://prometheus-operator.dev/) creation | -| `monitoring: interval:` | `string` | `15s` | Prometheus scrape interval | +| Key | Type | Default | Description | +|-------------------------|--------|---------|-------------------------------------------------------------------------------| +| `monitoring: enabled:` | `bool` | `false` | Enable [Prometheus ServiceMonitor](https://prometheus-operator.dev/) creation | +| `monitoring: interval:` | `int` | `15` | Prometheus scrape interval in seconds | ### Cashing values diff --git a/timoni/podinfo/templates/config.cue b/timoni/podinfo/templates/config.cue index 5fb40efa8..c6921403c 100644 --- a/timoni/podinfo/templates/config.cue +++ b/timoni/podinfo/templates/config.cue @@ -16,7 +16,7 @@ import ( metadata: version: moduleVersion // Deployment - replicas: *1 | int & >0 + replicas: *1 | int & >=0 // Pod podAnnotations?: {[ string]: string} @@ -33,7 +33,11 @@ import ( securityContext?: corev1.#SecurityContext // Service - service: port: *80 | int & >0 & <=65535 + service: { + port: *80 | int & >0 & <=65535 + annotations?: {[ string]: string} + labels?: {[ string]: string} + } // HorizontalPodAutoscaler (optional) autoscaling: { @@ -50,13 +54,14 @@ import ( tls: *false | bool host: *"podinfo.local" | string annotations?: {[ string]: string} + labels?: {[ string]: string} className?: string } // ServiceMonitor (optional) monitoring: { enabled: *false | bool - interval: *"15s" | string + interval: *15 | int & >=5 & <=3600 } // Caching (optional) diff --git a/timoni/podinfo/templates/deployment.cue b/timoni/podinfo/templates/deployment.cue index 5bb932a6c..70cd29762 100644 --- a/timoni/podinfo/templates/deployment.cue +++ b/timoni/podinfo/templates/deployment.cue @@ -21,6 +21,10 @@ import ( if !_config.autoscaling.enabled { replicas: _config.replicas } + strategy: { + type: "RollingUpdate" + rollingUpdate: maxUnavailable: "50%" + } selector: matchLabels: _config.metadata.labelSelector template: { metadata: { @@ -28,6 +32,12 @@ import ( if _config.podAnnotations != _|_ { annotations: _config.podAnnotations } + if !_config.monitoring.enabled { + annotations: { + "prometheus.io/scrape": "true" + "prometheus.io/port": "9797" + } + } } spec: corev1.#PodSpec & { serviceAccountName: _config.metadata.name @@ -42,6 +52,11 @@ import ( containerPort: 9898 protocol: "TCP" }, + { + name: "http-metrics" + containerPort: 9797 + protocol: "TCP" + }, ] livenessProbe: { httpGet: { @@ -64,6 +79,8 @@ import ( command: [ "./podinfo", "--level=info", + "--port=9898", + "--port-metrics=9797", if _config.caching.enabled { "--cache-server=\(_config.caching.redisURL)" }, diff --git a/timoni/podinfo/templates/ingress.cue b/timoni/podinfo/templates/ingress.cue index 0ff98c486..dac1f8b78 100644 --- a/timoni/podinfo/templates/ingress.cue +++ b/timoni/podinfo/templates/ingress.cue @@ -12,6 +12,9 @@ import ( name: _config.metadata.name namespace: _config.metadata.namespace labels: _config.metadata.labels + if _config.ingress.labels != _|_ { + labels: _config.ingress.labels + } if _config.metadata.annotations != _|_ { annotations: _config.metadata.annotations } diff --git a/timoni/podinfo/templates/service.cue b/timoni/podinfo/templates/service.cue index 251bfd921..d286abf8a 100644 --- a/timoni/podinfo/templates/service.cue +++ b/timoni/podinfo/templates/service.cue @@ -12,9 +12,15 @@ import ( name: _config.metadata.name namespace: _config.metadata.namespace labels: _config.metadata.labels + if _config.service.labels != _|_ { + labels: _config.service.labels + } if _config.metadata.annotations != _|_ { annotations: _config.metadata.annotations } + if _config.service.annotations != _|_ { + annotations: _config.service.annotations + } } spec: corev1.#ServiceSpec & { type: corev1.#ServiceTypeClusterIP @@ -26,6 +32,14 @@ import ( targetPort: "\(name)" protocol: "TCP" }, + if _config.monitoring.enabled { + { + name: "http-metrics" + port: 9797 + targetPort: "http-metrics" + protocol: "TCP" + } + }, ] } } diff --git a/timoni/podinfo/templates/servicemonitor.cue b/timoni/podinfo/templates/servicemonitor.cue index 76913f572..8d3a329bc 100644 --- a/timoni/podinfo/templates/servicemonitor.cue +++ b/timoni/podinfo/templates/servicemonitor.cue @@ -18,7 +18,7 @@ import ( endpoints: [{ path: "/metrics" port: "http-metrics" - interval: _config.monitoring.interval + interval: "\(_config.monitoring.interval)s" }] namespaceSelector: matchNames: [_config.metadata.namespace] selector: matchLabels: _config.metadata.labelSelector