Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Prometheus Exporter to Helm Charts #343

Merged
merged 2 commits into from
Jan 11, 2024
Merged
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: 2 additions & 0 deletions charts/kubescape-operator/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ serviceDiscovery:
enabled: {{ $configurations.submit }}
storage:
enabled: true
prometheusExporter:
enabled: {{ eq .Values.capabilities.prometheusExporter "enable" }}
cloudSecret:
create: {{ $configurations.createCloudSecret }}
name: {{ if $configurations.createCloudSecret }}"cloud-secret"{{ else }}{{ .Values.credentials.cloudSecret }}{{ end }}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{- $components := fromYaml (include "components" .) }}
{{- if $components.prometheusExporter.enabled }}
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: {{ .Values.prometheusExporter.name }}
rules:
- apiGroups: ["spdx.softwarecomposition.kubescape.io"]
resources: ["configurationscansummaries", "vulnerabilitysummaries"]
verbs: ["get", "watch", "list"]
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{{- $components := fromYaml (include "components" .) }}
{{- if $components.prometheusExporter.enabled }}
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: {{ .Values.prometheusExporter.name }}
subjects:
- kind: ServiceAccount
name: {{ .Values.prometheusExporter.name }}
namespace: {{ .Values.ksNamespace }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ .Values.prometheusExporter.name }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
{{- $components := fromYaml (include "components" .) }}
{{- if $components.prometheusExporter.enabled }}
{{- $no_proxy_envar_list := (include "no_proxy_envar_list" .) -}}
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Values.prometheusExporter.name }}
namespace: {{ .Values.ksNamespace }}
labels:
app.kubernetes.io/name: {{ .Values.prometheusExporter.name }}
app.kubernetes.io/instance: {{ .Release.Name }}
app: {{ .Values.prometheusExporter.name }}
tier: {{ .Values.global.namespaceTier }}
spec:
replicas: {{ .Values.prometheusExporter.replicaCount }}
revisionHistoryLimit: 2
strategy:
type: Recreate
selector:
matchLabels:
app.kubernetes.io/name: {{ .Values.prometheusExporter.name }}
app.kubernetes.io/instance: {{ .Release.Name }}
tier: {{ .Values.global.namespaceTier }}
template:
metadata:
labels:
app.kubernetes.io/name: {{ .Values.prometheusExporter.name }}
app.kubernetes.io/instance: {{ .Release.Name }}
tier: {{ .Values.global.namespaceTier }}
app: {{ .Values.prometheusExporter.name }}
spec:
{{- if .Values.imagePullSecrets }}
imagePullSecrets:
- name: {{ toYaml .Values.imagePullSecrets }}
{{- end }}
securityContext:
runAsUser: 65532
fsGroup: 65532
containers:
- name: {{ .Values.prometheusExporter.name }}
image: {{ .Values.prometheusExporter.image.repository }}:{{ .Values.prometheusExporter.image.tag }}
imagePullPolicy: {{ .Values.prometheusExporter.image.pullPolicy }}
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
runAsNonRoot: true
ports:
- name: metrics
containerPort: {{ .Values.prometheusExporter.service.port }}
protocol: TCP
livenessProbe:
tcpSocket:
port: {{ .Values.prometheusExporter.service.port }}
initialDelaySeconds: 3
periodSeconds: 3
readinessProbe:
tcpSocket:
port: {{ .Values.prometheusExporter.service.port }}
resources:
{{ toYaml .Values.prometheusExporter.resources | indent 12 }}
env:
- name: GOMEMLIMIT
value: "{{ .Values.prometheusExporter.resources.requests.memory }}B"
- name: KS_LOGGER_LEVEL
value: "{{ .Values.logger.level }}"
- name: KS_LOGGER_NAME
value: "{{ .Values.logger.name }}"
volumeMounts:
- name: {{ .Values.global.cloudConfig }}
mountPath: /etc/config
readOnly: true
{{- if .Values.volumeMounts }}
{{ toYaml .Values.volumeMounts | indent 12 }}
{{- end }}
{{- if .Values.kubevuln.volumeMounts }}
{{ toYaml .Values.kubevuln.volumeMounts | indent 12 }}
{{- end }}
volumes:
- name: {{ .Values.global.cloudConfig }}
configMap:
name: {{ .Values.global.cloudConfig }}
items:
- key: "clusterData"
path: "clusterData.json"
{{- if .Values.volumes }}
{{ toYaml .Values.volumes | indent 8 }}
{{- end }}
{{- if .Values.prometheusExporter.volumes }}
{{ toYaml .Values.prometheusExporter.volumes | indent 8 }}
{{- end }}
serviceAccountName: {{ .Values.prometheusExporter.name }}
automountServiceAccountToken: true
nodeSelector:
{{- if .Values.prometheusExporter.nodeSelector }}
{{- toYaml .Values.prometheusExporter.nodeSelector | nindent 8 }}
{{- else if .Values.customScheduling.nodeSelector }}
{{- toYaml .Values.customScheduling.nodeSelector | nindent 8 }}
{{- end }}
affinity:
{{- if .Values.prometheusExporter.affinity }}
{{- toYaml .Values.prometheusExporter.affinity | nindent 8 }}
{{- else if .Values.customScheduling.affinity }}
{{- toYaml .Values.customScheduling.affinity | nindent 8 }}
{{- end }}
tolerations:
{{- if .Values.prometheusExporter.tolerations }}
{{- toYaml .Values.prometheusExporter.tolerations | nindent 8 }}
{{- else if .Values.customScheduling.tolerations }}
{{- toYaml .Values.customScheduling.tolerations | nindent 8 }}
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{{- $components := fromYaml (include "components" .) }}
{{- if and .Values.global.networkPolicy.enabled $components.prometheusExporter.enabled }}
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: {{ .Values.prometheusExporter.name }}
namespace: {{ .Values.ksNamespace }}
labels:
app: {{ .Values.prometheusExporter.name }}
tier: {{ .Values.global.namespaceTier }}
spec:
podSelector:
matchLabels:
app.kubernetes.io/name: {{ .Values.prometheusExporter.name }}
app.kubernetes.io/instance: {{ .Release.Name }}
tier: {{ .Values.global.namespaceTier }}
policyTypes:
- Ingress
ingress:
- ports:
- port: {{ .Values.prometheusExporter.service.port }}
protocol: TCP
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{{- $components := fromYaml (include "components" .) }}
{{- if $components.prometheusExporter.enabled }}
apiVersion: v1
kind: Service
metadata:
name: {{ .Values.prometheusExporter.name }}
namespace: {{ .Values.ksNamespace }}
labels:
app: {{ .Values.prometheusExporter.name }}
spec:
type: {{ .Values.prometheusExporter.service.type }}
ports:
- port: {{ .Values.prometheusExporter.service.port }}
targetPort: {{ .Values.prometheusExporter.service.targetPort }}
protocol: {{ .Values.prometheusExporter.service.protocol }}
selector:
app: {{ .Values.prometheusExporter.name }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{{- $components := fromYaml (include "components" .) }}
{{- if $components.prometheusExporter.enabled }}
kind: ServiceAccount
apiVersion: v1
metadata:
{{- if .Values.cloudProviderMetadata.awsIamRoleArn }}
annotations:
eks.amazonaws.com/role-arn: {{ .Values.cloudProviderMetadata.awsIamRoleArn }}
{{- else if .Values.cloudProviderMetadata.gkeServiceAccount }}
annotations:
iam.gke.io/gcp-service-account: {{ .Values.cloudProviderMetadata.gkeServiceAccount }}
{{- end }}
labels:
app: {{ .Values.prometheusExporter.name }}
name: {{ .Values.prometheusExporter.name }}
namespace: {{ .Values.ksNamespace }}
automountServiceAccountToken: false
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{{- $components := fromYaml (include "components" .) }}
{{- if $components.prometheusExporter.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: {{ .Values.prometheusExporter.name }}
namespace: {{ .Values.ksNamespace }}
labels:
app: {{ .Values.prometheusExporter.name }}
spec:
namespaceSelector:
matchNames:
- {{ .Values.ksNamespace }}
selector:
matchLabels:
app: {{ .Values.prometheusExporter.name }}
{{ end }}
Loading
Loading