Skip to content

Commit 5a00d57

Browse files
feat(cf-common): add service monitor tpl (#42)
1 parent 2cdba7f commit 5a00d57

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+552
-232
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{{ $templateName := printf "cf-common-%s.serviceMonitor" (index .Subcharts "cf-common").Chart.Version }}
2+
{{- include $templateName . -}}

charts/cf-common-test/tests/service/spec_test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ tests:
4545
app.kubernetes.io/instance: RELEASE-NAME
4646
app.kubernetes.io/name: cf-common-test
4747

48-
- it: Test main service with extart selector label
48+
- it: Test main service with extra selector label
4949
template: templates/service.yaml
5050
values:
5151
- values.yaml

charts/cf-common-test/tests/service/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# mock deployment for HPA
1+
# mock deployment for service
22
controller:
33
enabled: true
44
type: deployment
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/quintush/helm-unittest/master/schema/helm-testsuite.json
2+
suite: service monitor error handler
3+
templates:
4+
- templates/serviceMonitor.yaml
5+
tests:
6+
- it: Test main service monitor with no endpoints
7+
values:
8+
- values.yaml
9+
set:
10+
serviceMonitor:
11+
main:
12+
endpoints: null
13+
asserts:
14+
- failedTemplate:
15+
errorMessage: "endpoints are required for serviceMonitor RELEASE-NAME-cf-common-test"
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/quintush/helm-unittest/master/schema/helm-testsuite.json
2+
suite: service monitor metadata
3+
templates:
4+
- templates/serviceMonitor.yaml
5+
tests:
6+
- it: Test service monitor default metadata
7+
values:
8+
- values.yaml
9+
asserts:
10+
- hasDocuments:
11+
count: 1
12+
- isKind:
13+
of: ServiceMonitor
14+
- isNull:
15+
path: metadata.annotations
16+
- equal:
17+
path: metadata.labels
18+
value:
19+
app.kubernetes.io/instance: RELEASE-NAME
20+
app.kubernetes.io/managed-by: Helm
21+
app.kubernetes.io/name: cf-common-test
22+
helm.sh/chart: cf-common-test-0.0.0
23+
- equal:
24+
path: metadata.name
25+
value: RELEASE-NAME-cf-common-test
26+
27+
- it: Test service monitor custom metadata
28+
values:
29+
- values.yaml
30+
set:
31+
serviceMonitor:
32+
main:
33+
labels:
34+
alice: bob
35+
annotations:
36+
foo: bar
37+
asserts:
38+
- hasDocuments:
39+
count: 1
40+
- isKind:
41+
of: ServiceMonitor
42+
- equal:
43+
path: metadata.annotations
44+
value:
45+
foo: bar
46+
- equal:
47+
path: metadata.labels
48+
value:
49+
app.kubernetes.io/instance: RELEASE-NAME
50+
app.kubernetes.io/managed-by: Helm
51+
app.kubernetes.io/name: cf-common-test
52+
helm.sh/chart: cf-common-test-0.0.0
53+
alice: bob
54+
55+
- it: Test main service monitor with name override
56+
template: templates/serviceMonitor.yaml
57+
values:
58+
- values.yaml
59+
set:
60+
serviceMonitor:
61+
main:
62+
nameOverride: foobar
63+
asserts:
64+
- equal:
65+
path: metadata.name
66+
value: RELEASE-NAME-cf-common-test-foobar
67+
68+
- it: Test main service monitor with full name override
69+
template: templates/serviceMonitor.yaml
70+
values:
71+
- values.yaml
72+
set:
73+
serviceMonitor:
74+
main:
75+
fullnameOverride: foobar
76+
asserts:
77+
- equal:
78+
path: metadata.name
79+
value: foobar
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/quintush/helm-unittest/master/schema/helm-testsuite.json
2+
suite: service monitor spec
3+
templates:
4+
- templates/serviceMonitor.yaml
5+
values:
6+
- values.yaml
7+
tests:
8+
- it: Test main service monitor selector
9+
template: templates/serviceMonitor.yaml
10+
asserts:
11+
- isNotEmpty:
12+
path: spec.selector.matchLabels
13+
- equal:
14+
path: spec.selector.matchLabels
15+
value:
16+
app.kubernetes.io/instance: RELEASE-NAME
17+
app.kubernetes.io/name: cf-common-test
18+
19+
- it: Test main service monitor with selector override
20+
template: templates/serviceMonitor.yaml
21+
values:
22+
- values.yaml
23+
set:
24+
serviceMonitor:
25+
main:
26+
selector:
27+
matchLabels:
28+
alice: bob
29+
asserts:
30+
- isNotEmpty:
31+
path: spec.selector.matchLabels
32+
- equal:
33+
path: spec.selector.matchLabels
34+
value:
35+
alice: bob
36+
37+
- it: Test main service monitor with namespace selector
38+
template: templates/serviceMonitor.yaml
39+
values:
40+
- values.yaml
41+
set:
42+
serviceMonitor:
43+
main:
44+
namespaceSelector:
45+
matchNames:
46+
- foobar
47+
asserts:
48+
- contains:
49+
path: spec.namespaceSelector.matchNames
50+
content:
51+
foobar
52+
53+
- it: Test main service monitor endpoints
54+
template: templates/serviceMonitor.yaml
55+
values:
56+
- values.yaml
57+
asserts:
58+
- contains:
59+
path: spec.endpoints
60+
content:
61+
interval: 1m
62+
path: /metrics
63+
port: metrics
64+
scheme: http
65+
scrapeTimeout: 10s
66+
count: 1
67+
68+
- it: Test main service monitor disabled
69+
template: templates/serviceMonitor.yaml
70+
set:
71+
serviceMonitor:
72+
main:
73+
enabled: false
74+
values:
75+
- values.yaml
76+
asserts:
77+
- hasDocuments:
78+
count: 0
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# mock deployment for service monitor
2+
controller:
3+
enabled: true
4+
type: deployment
5+
replicas: 2
6+
deployment:
7+
strategy: Recreate
8+
revisionHistoryLimit: 5
9+
10+
container:
11+
image:
12+
registry: docker.io
13+
repository: nginx
14+
tag: master
15+
pullPolicy: Always
16+
17+
service:
18+
main:
19+
enabled: true
20+
primary: true
21+
labels: {}
22+
annotations: {}
23+
type: ClusterIP
24+
ports:
25+
http:
26+
port: 8080
27+
protocol: HTTP
28+
metrics:
29+
enabled: true
30+
type: ClusterIP
31+
ports:
32+
metrics:
33+
port: 8082
34+
protocol: HTTP
35+
36+
serviceMonitor:
37+
main:
38+
enabled: true
39+
nameOverride: ""
40+
labels: {}
41+
annotations: {}
42+
selector: {}
43+
namespaceSelector: {}
44+
endpoints:
45+
- port: metrics
46+
scheme: http
47+
path: /metrics
48+
interval: 1m
49+
scrapeTimeout: 10s

charts/cf-common/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: v2
22
appVersion: v0.0.0
33
description: Codefresh library chart
44
name: cf-common
5-
version: 0.8.1
5+
version: 0.9.0
66
type: library
77
keywords:
88
- codefresh

charts/cf-common/README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Codefresh library chart
44

5-
![Version: 0.8.1](https://img.shields.io/badge/Version-0.8.1-informational?style=flat-square) ![Type: library](https://img.shields.io/badge/Type-library-informational?style=flat-square) ![AppVersion: v0.0.0](https://img.shields.io/badge/AppVersion-v0.0.0-informational?style=flat-square)
5+
![Version: 0.9.0](https://img.shields.io/badge/Version-0.9.0-informational?style=flat-square) ![Type: library](https://img.shields.io/badge/Type-library-informational?style=flat-square) ![AppVersion: v0.0.0](https://img.shields.io/badge/AppVersion-v0.0.0-informational?style=flat-square)
66

77
## Installing the Chart
88

@@ -18,7 +18,7 @@ Include this chart as a dependency in your `Chart.yaml` e.g.
1818
# Chart.yaml
1919
dependencies:
2020
- name: cf-common
21-
version: 0.8.1
21+
version: 0.9.0
2222
repository: https://chartmuseum.codefresh.io/cf-common
2323
```
2424
@@ -165,6 +165,16 @@ dependencies:
165165
| serviceAccount.annotations | object | `{}` | Set annotations for Service Account |
166166
| serviceAccount.enabled | bool | `false` | Enable and create Service Account |
167167
| serviceAccount.nameOverride | string | `""` | Override Service Account name (by default, name is generated with `fullname` template) |
168+
| serviceMonitor | object | See below | Configure ServiceMonitors for the chart. Additional ServiceMonitors can be added by adding a dictionary key similar to the 'main' service monitor. |
169+
| serviceMonitor.main | object | `{"annotations":{},"enabled":false,"endpoints":[{"interval":"1m","path":"/metrics","port":"http","scheme":"http","scrapeTimeout":"10s"}],"fullNameOverride":"","labels":{},"nameOverride":"","namespaceSelector":{},"selector":{}}` | Service monitor name |
170+
| serviceMonitor.main.annotations | object | `{}` | Add additional annotations for the service monitor |
171+
| serviceMonitor.main.enabled | bool | `false` | Enable service monitor |
172+
| serviceMonitor.main.endpoints | list | `[{"interval":"1m","path":"/metrics","port":"http","scheme":"http","scrapeTimeout":"10s"}]` | Set endpoints for service monitor |
173+
| serviceMonitor.main.fullNameOverride | string | `""` | Override service monitor full name |
174+
| serviceMonitor.main.labels | object | `{}` | Add additional labels for the service monitor |
175+
| serviceMonitor.main.nameOverride | string | `""` | Override service monitor name suffix |
176+
| serviceMonitor.main.namespaceSelector | object | `{}` | Set namespace selector. If nil, release namespace is used. |
177+
| serviceMonitor.main.selector | object | `{}` | Override the default selector for the serviceMonitor. Takes precedence over default labels. Helm template can be used. |
168178
| terminationGracePeriodSeconds | string | `nil` | Duration in seconds the pod needs to terminate gracefully |
169179
| tolerations | list | `[]` | Set tolerations constrains |
170180
| topologySpreadConstraints | list | `[]` | Set topologySpreadConstraints rules. Helm template supported. Passed through `tpl`, should be configured as string |

charts/cf-common/templates/classic/_helpers.tpl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
Calculate RabbitMQ URI (for On-Prem)
33
Must me called from chart root context.
44
Usage:
5-
{{ include "cf-common-0.8.1.classic.calculateRabbitMqUri" . }}
5+
{{ include "cf-common-0.9.0.classic.calculateRabbitMqUri" . }}
66
*/}}
77

8-
{{- define "cf-common-0.8.1.classic.calculateRabbitMqUri" }}
8+
{{- define "cf-common-0.9.0.classic.calculateRabbitMqUri" }}
99

1010
{{- $rabbitmqProtocol := .Values.global.rabbitmqProtocol | default "amqp" -}}
1111
{{- $rabbitmqUsername := .Values.global.rabbitmqUsername -}}
@@ -23,9 +23,9 @@ coalesce here for backward compatibility
2323
{{/*
2424
Calculate Mongo Uri (for On-Prem)
2525
Usage:
26-
{{ include "cf.common-0.8.1.classic.calculateMongoUri" (dict "dbName" $.Values.global.pipelineManagerService "mongoURI" $.Values.global.mongoURI) }}
26+
{{ include "cf.common-0.9.0.classic.calculateMongoUri" (dict "dbName" $.Values.global.pipelineManagerService "mongoURI" $.Values.global.mongoURI) }}
2727
*/}}
28-
{{- define "cf-common-0.8.1.classic.calculateMongoUri" -}}
28+
{{- define "cf-common-0.9.0.classic.calculateMongoUri" -}}
2929
{{- if contains "?" .mongoURI -}}
3030
{{- $mongoURI := (splitList "?" .mongoURI) -}}
3131
{{- printf "%s%s?%s" (first $mongoURI) .dbName (last $mongoURI) }}
@@ -37,7 +37,7 @@ Usage:
3737
{{/*
3838
Calculate Consul host Uri (for On-Prem)
3939
*/}}
40-
{{- define "cf-common-0.8.1.classic.calculateConsulUri" }}
40+
{{- define "cf-common-0.9.0.classic.calculateConsulUri" }}
4141
{{- if .Values.global.consulHost }}
4242
{{- printf "http://%s:%v" .Values.global.consulHost .Values.global.consulHttpPort -}}
4343
{{- else }}

0 commit comments

Comments
 (0)