Skip to content
Open
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
2 changes: 1 addition & 1 deletion .cruft.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"name": "icap-virusscan",
"slug": "icap-virusscan",
"parameter_key": "icap_virusscan",
"test_cases": "defaults with_squid_proxy",
"test_cases": "defaults with_squid_proxy monitoring",
"add_lib": "n",
"add_pp": "n",
"add_golden": "y",
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
instance:
- defaults
- with_squid_proxy
- monitoring
defaults:
run:
working-directory: ${{ env.COMPONENT_NAME }}
Expand All @@ -50,6 +51,7 @@ jobs:
instance:
- defaults
- with_squid_proxy
- monitoring
defaults:
run:
working-directory: ${{ env.COMPONENT_NAME }}
Expand Down
2 changes: 1 addition & 1 deletion Makefile.vars.mk
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ KUBENT_IMAGE ?= ghcr.io/doitintl/kube-no-trouble:latest
KUBENT_DOCKER ?= $(DOCKER_CMD) $(DOCKER_ARGS) $(root_volume) --entrypoint=/app/kubent $(KUBENT_IMAGE)

instance ?= defaults
test_instances = tests/defaults.yml tests/with_squid_proxy.yml
test_instances = tests/defaults.yml tests/with_squid_proxy.yml tests/monitoring.yml
32 changes: 32 additions & 0 deletions class/defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,38 @@ parameters:
namespaceAnnotations: {}
namespaceLabels: {}

monitoring:
enabled: false
prometheusruleGroup:
- name: monitoring
rules:
- alert: KubernetesReplicasetReplicasMismatch
annotations:
runbook_url: "alert.rubook.com"
summary: "Kubernetes ReplicaSet replicas mismatch (instance {{ $labels.instance }})"
description: >-
"ReplicaSet {{ $labels.namespace }}/{{ $labels.replicaset }} replicas mismatch\n
VALUE = {{ $value }}\n LABELS = {{ $labels }}"
expr: >-
kube_replicaset_spec_replicas{namespace=~"${_instance}"} >
kube_replicaset_status_ready_replicas{namespace=~"${_instance}"}
for: 2m
keep_firing_for: 10m
labels:
severity: warning
- alert: ContainerOOMKilled
expr: >-
(kube_pod_container_status_restarts_total{namespace="${_instance}"} -
kube_pod_container_status_restarts_total{namespace="${_instance}"} offset 10m >= 1)
and ignoring (reason) min_over_time(kube_pod_container_status_last_terminated_reason{reason="OOMKilled",namespace="${_instance}"}[10m]) == 1
for: 2m
labels:
severity: warning
annotations:
summary: Kubernetes Container oom killer (instance {{ $labels.instance }})
description: "Container {{ $labels.container }} in pod {{ $labels.namespace }}/{{ $labels.pod }} has been OOMKilled {{ $value }} times in the last 10 minutes.\n VALUE = {{ $value }}\n LABELS = {{ $labels }}"
keep_firing_for: 10m

enable_squid: false
squid_domain:
httproute:
Expand Down
39 changes: 35 additions & 4 deletions component/main.jsonnet
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// main template for icap-virusscan
local kap = import 'lib/kapitan.libjsonnet';
local kube = import 'lib/kube.libjsonnet';
local inv = kap.inventory();
local prometheus = import 'lib/prometheus.libsonnet';
local com = import 'lib/commodore.libjsonnet';
local sanitizedContainerLib = import 'lib/sanitizedContainer.libsonnet';
local inv = kap.inventory();
local sanitizedContainer = sanitizedContainerLib.sanitizedContainer;

// The hiera parameters for the component
Expand All @@ -18,10 +20,21 @@ local selectorLabels = {
instance: instance,
};

local namespace = kube.Namespace(params.namespace) {
local namespace = (
if params.monitoring.enabled && std.member(inv.applications, 'prometheus') then
prometheus.RegisterNamespace(kube.Namespace(params.namespace))
else if params.monitoring.enabled && inv.parameters.facts.distribution == 'openshift4' then
kube.Namespace(params.namespace) {
metadata+: {
labels+: { 'openshift.io/cluster-monitoring': 'true' },
},
}
else
kube.Namespace(params.namespace)
) + {
metadata+: {
labels+: params.namespaceLabels,
annotations+: params.namespaceAnnotations,
labels+: com.makeMergeable(params.namespaceLabels),
annotations+: com.makeMergeable(params.namespaceAnnotations),
},
};

Expand Down Expand Up @@ -167,11 +180,29 @@ local networkPolicies = {
},
};

local prometheusRule = {
apiVersion: 'monitoring.coreos.com/v1',
kind: 'PrometheusRule',
metadata: {
name: 'monitoringRules',
namespace: params.namespace,
labels: selectorLabels,
},
spec: {
groups: if std.objectHas( params.monitoring, 'syn_team')
then
[params.monitoring.prometheusruleGroup[0] + {labels: {syn_team: params.monitoring.syn_team}}]
else
params.monitoring.prometheusruleGroup
}
};

{
[if params.createNamespace then '00_namespace']: namespace,
'01_deployment': deployment,
[if params.replicas > 1 then '02_podDisruptionBudget']: podDisruptionBudget,
'03_service': service,
[if hasNetworkPolicies then '04_networkPolicies']: networkPolicies,
[if params.monitoring.enabled then '05_prometheusRule']: prometheusRule,
} + (import 'lib/testSetup.libsonnet')
+ (import 'lib/debug.libsonnet')
4 changes: 4 additions & 0 deletions tests/golden/monitoring/monitoring/apps/monitoring.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
spec:
syncPolicy:
syncOptions:
- ServerSideApply=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: Namespace
metadata:
annotations: {}
labels:
name: monitoring
openshift.io/cluster-monitoring: 'true'
name: monitoring
107 changes: 107 additions & 0 deletions tests/golden/monitoring/monitoring/monitoring/01_deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: clamav-icap
instance: monitoring
name: clamav-icap
namespace: monitoring
spec:
replicas: 2
selector:
matchLabels:
app: clamav-icap
instance: monitoring
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
template:
metadata:
labels:
app: clamav-icap
instance: monitoring
spec:
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- podAffinityTerm:
labelSelector:
matchLabels:
app: clamav-icap
instance: monitoring
topologyKey: kubernetes.io/hostname
weight: 1
containers:
- env: []
image: ghcr.io/vshn/clamav:20260420_095651
livenessProbe:
failureThreshold: 3
periodSeconds: 5
tcpSocket:
port: 3310
timeoutSeconds: 5
name: clamav
ports:
- containerPort: 3310
name: clamav
readinessProbe:
failureThreshold: 1
initialDelaySeconds: 0
periodSeconds: 5
successThreshold: 1
tcpSocket:
port: 3310
timeoutSeconds: 3
resources:
limits:
cpu: 2000m
memory: 3072Mi
requests:
cpu: 120m
memory: 1280Mi
startupProbe:
failureThreshold: 3
initialDelaySeconds: 0
periodSeconds: 5
tcpSocket:
port: 3310
timeoutSeconds: 5
- env:
- name: CLAMD_IP
value: 127.0.0.1
- name: CLAMD_MAXSIZE
value: 50m
image: ghcr.io/vshn/c-icap:20260420_095301
livenessProbe:
failureThreshold: 3
periodSeconds: 5
tcpSocket:
port: 1344
timeoutSeconds: 5
name: c-icap
ports:
- containerPort: 1344
name: icap
readinessProbe:
failureThreshold: 1
initialDelaySeconds: 0
periodSeconds: 5
successThreshold: 1
tcpSocket:
port: 1344
timeoutSeconds: 3
resources:
limits:
cpu: 500m
memory: 500Mi
requests:
cpu: 120m
memory: 200Mi
startupProbe:
failureThreshold: 3
initialDelaySeconds: 0
periodSeconds: 5
tcpSocket:
port: 1344
timeoutSeconds: 5
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
labels:
app: clamav-icap
instance: monitoring
name: clamav-icap
namespace: monitoring
spec:
minAvailable: 1
selector:
matchLabels:
app: clamav-icap
instance: monitoring
unhealthyPodEvictionPolicy: IfHealthyBudget
18 changes: 18 additions & 0 deletions tests/golden/monitoring/monitoring/monitoring/03_service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: v1
kind: Service
metadata:
labels:
app: clamav-icap
instance: monitoring
name: icap
namespace: monitoring
spec:
ports:
- name: icap
port: 80
protocol: TCP
targetPort: icap
selector:
app: clamav-icap
instance: monitoring
type: ClusterIP
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
labels:
app: clamav-icap
instance: monitoring
name: monitoringRules
namespace: monitoring
spec:
groups:
- labels:
syn_team: team_monitoring
name: monitoring
rules:
- alert: KubernetesReplicasetReplicasMismatch
annotations:
description: '"ReplicaSet {{ $labels.namespace }}/{{ $labels.replicaset
}} replicas mismatch\n VALUE = {{ $value }}\n LABELS = {{ $labels }}"'
runbook_url: alert.rubook.com
summary: Kubernetes ReplicaSet replicas mismatch (instance {{ $labels.instance
}})
expr: kube_replicaset_spec_replicas{namespace=~"monitoring"} > kube_replicaset_status_ready_replicas{namespace=~"monitoring"}
for: 2m
keep_firing_for: 10m
labels:
severity: warning
- alert: ContainerOOMKilled
annotations:
description: |-
Container {{ $labels.container }} in pod {{ $labels.namespace }}/{{ $labels.pod }} has been OOMKilled {{ $value }} times in the last 10 minutes.
VALUE = {{ $value }}
LABELS = {{ $labels }}
summary: Kubernetes Container oom killer (instance {{ $labels.instance
}})
expr: (kube_pod_container_status_restarts_total{namespace="monitoring"}
- kube_pod_container_status_restarts_total{namespace="monitoring"} offset
10m >= 1) and ignoring (reason) min_over_time(kube_pod_container_status_last_terminated_reason{reason="OOMKilled",namespace="monitoring"}[10m])
== 1
for: 2m
keep_firing_for: 10m
labels:
severity: warning
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,30 @@ data:
gatewayNamespace: "gateway-dev-ns"
sectionName: "http-default"
minAvailable: 1
monitoring:
enabled: false
prometheusruleGroup:
- name: "monitoring"
rules:
- alert: "KubernetesReplicasetReplicasMismatch"
annotations:
description: "\"ReplicaSet {{ $labels.namespace }}/{{ $labels.replicaset }} replicas mismatch\\n VALUE = {{ $value }}\\n LABELS = {{ $labels }}\""
runbook_url: "alert.rubook.com"
summary: "Kubernetes ReplicaSet replicas mismatch (instance {{ $labels.instance }})"
expr: "kube_replicaset_spec_replicas{namespace=~\"with_squid_proxy\"} > kube_replicaset_status_ready_replicas{namespace=~\"with_squid_proxy\"}"
for: "2m"
keep_firing_for: "10m"
labels:
severity: "warning"
- alert: "ContainerOOMKilled"
annotations:
description: "Container {{ $labels.container }} in pod {{ $labels.namespace }}/{{ $labels.pod }} has been OOMKilled {{ $value }} times in the last 10 minutes.\n VALUE = {{ $value }}\n LABELS = {{ $labels }}"
summary: "Kubernetes Container oom killer (instance {{ $labels.instance }})"
expr: "(kube_pod_container_status_restarts_total{namespace=\"with_squid_proxy\"} - kube_pod_container_status_restarts_total{namespace=\"with_squid_proxy\"} offset 10m >= 1) and ignoring (reason) min_over_time(kube_pod_container_status_last_terminated_reason{reason=\"OOMKilled\",namespace=\"with_squid_proxy\"}[10m]) == 1"
for: "2m"
keep_firing_for: "10m"
labels:
severity: "warning"
namespace: "with_squid_proxy"
namespaceAnnotations: {}
namespaceLabels: {}
Expand Down
9 changes: 9 additions & 0 deletions tests/monitoring.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
parameters:
facts:
distribution: openshift4

icap_virusscan:
monitoring:
enabled: true
syn_team: "team_monitoring"
Loading