Skip to content

Commit

Permalink
feat: implement support for creating services for agent presets
Browse files Browse the repository at this point in the history
  • Loading branch information
pkoutsovasilis committed Dec 30, 2024
1 parent f1b080c commit a83b27a
Show file tree
Hide file tree
Showing 11 changed files with 447 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
extraIntegrations:
netflow:
id: netflow-netflow-60a9d5b2-c611-4749-90bf-5e2443936c1d
name: netflow-1
preset: netflow
revision: 1
type: netflow
use_output: default
meta:
package:
name: netflow
version: 2.19.1
data_stream:
namespace: default
package_policy_id: 60a9d5b2-c611-4749-90bf-5e2443936c1d
streams:
- id: netflow-netflow.log-60a9d5b2-c611-4749-90bf-5e2443936c1d
data_stream:
dataset: netflow.log
type: logs
protocols:
- v1
- v5
- v6
- v7
- v8
- v9
- ipfix
host: '0.0.0.0:2055'
max_message_size: 10KiB
expiration_timeout: 30m
queue_size: 8192
detect_sequence_reset: true
tags:
- netflow
- forwarded
publisher_pipeline.disable_host: true

kubernetes:
enabled: false

agent:
unprivileged: true
presets:
netflow:
automountServiceAccountToken: false
mode: deployment
service:
type: NodePort
ports:
- containerPort: 2055
servicePort: 2055
serviceAccount:
create: false
clusterRole:
create: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
---
# Source: elastic-agent/templates/agent/k8s/secret.yaml
apiVersion: v1
kind: Secret
metadata:
name: agent-netflow-example
namespace: "default"
labels:
helm.sh/chart: elastic-agent-9.0.0-beta
app.kubernetes.io/name: elastic-agent
app.kubernetes.io/instance: example
app.kubernetes.io/version: 9.0.0
stringData:

agent.yml: |-
id: agent-netflow-example
outputs:
default:
hosts:
- http://elasticsearch:9200
password: changeme
type: elasticsearch
username: elastic
secret_references: []
inputs:
- data_stream:
namespace: default
id: netflow-netflow-60a9d5b2-c611-4749-90bf-5e2443936c1d
meta:
package:
name: netflow
version: 2.19.1
name: netflow-1
package_policy_id: 60a9d5b2-c611-4749-90bf-5e2443936c1d
preset: netflow
revision: 1
streams:
- data_stream:
dataset: netflow.log
type: logs
detect_sequence_reset: true
expiration_timeout: 30m
host: 0.0.0.0:2055
id: netflow-netflow.log-60a9d5b2-c611-4749-90bf-5e2443936c1d
max_message_size: 10KiB
protocols:
- v1
- v5
- v6
- v7
- v8
- v9
- ipfix
publisher_pipeline.disable_host: true
queue_size: 8192
tags:
- netflow
- forwarded
type: netflow
use_output: default
providers:
kubernetes_leaderelection:
enabled: false
leader_lease: example-netflow
---
# Source: elastic-agent/templates/agent/service.yaml
apiVersion: v1
kind: Service
metadata:
name: agent-netflow-example
namespace: "default"
labels:
helm.sh/chart: elastic-agent-9.0.0-beta
app.kubernetes.io/name: elastic-agent
app.kubernetes.io/instance: example
app.kubernetes.io/version: 9.0.0
spec:
type: NodePort
selector:
name: agent-netflow-example
ports:
- port: 2055
targetPort: 2055
protocol: TCP
---
# Source: elastic-agent/templates/agent/k8s/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: agent-netflow-example
namespace: "default"
labels:
helm.sh/chart: elastic-agent-9.0.0-beta
app.kubernetes.io/name: elastic-agent
app.kubernetes.io/instance: example
app.kubernetes.io/version: 9.0.0
spec:
selector:
matchLabels:
name: agent-netflow-example
template:
metadata:
labels:
name: agent-netflow-example
annotations:
checksum/config: 533260d6be94166b430e541939f3647c2b24c91e908dfe4ddfd590894489c321
spec:
automountServiceAccountToken: false
containers:
- args:
- -c
- /etc/elastic-agent/agent.yml
- -e
env:
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: STATE_PATH
value: /usr/share/elastic-agent/state
image: docker.elastic.co/beats/elastic-agent:9.0.0-SNAPSHOT
imagePullPolicy: IfNotPresent
name: agent
ports:
- containerPort: 2055
protocol: TCP
securityContext:
capabilities:
add:
- CHOWN
- SETPCAP
- DAC_READ_SEARCH
- SYS_PTRACE
drop:
- ALL
privileged: false
runAsGroup: 1000
runAsUser: 1000
volumeMounts:
- mountPath: /usr/share/elastic-agent/state
name: agent-data
- mountPath: /etc/elastic-agent/agent.yml
name: config
readOnly: true
subPath: agent.yml
dnsPolicy: ClusterFirstWithHostNet
volumes:
- hostPath:
path: /etc/elastic-agent/default/agent-netflow-example/state
type: DirectoryOrCreate
name: agent-data
- name: config
secret:
defaultMode: 292
secretName: agent-netflow-example
18 changes: 18 additions & 0 deletions deploy/helm/elastic-agent/templates/agent/eck/_pod_template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,24 @@ template:
resources:
{{- . | toYaml | nindent 10 }}
{{- end }}
{{- with ($presetVal).ports }}
ports:
{{- range $idx, $port := . }}
- containerPort: {{ $port.containerPort }}
{{- with $port.protocol | default "TCP" }}
protocol: {{ . }}
{{- end }}
{{- with $port.name }}
name: {{ . }}
{{- end }}
{{- with $port.hostPort }}
hostPort: {{ . }}
{{- end }}
{{- with $port.hostIP }}
hostIP: {{ . }}
{{- end }}
{{- end }}
{{- end }}
volumeMounts:
{{- with ($presetVal).extraVolumeMounts }}
{{- . | toYaml | nindent 10 }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{{- range $presetName, $presetVal := $.Values.agent.presets -}}
{{- if and (eq ($presetVal).mode "deployment") (eq $.Values.agent.engine "eck") -}}
{{- $agentName := include "elasticagent.preset.fullname" (list $ $presetName) -}}
{{- $podTemplateResource := include "elasticagent.engine.eck.podTemplate" (list $ $presetVal $agentName) | fromYaml -}}
{{- $podTemplateResource := include "elasticagent.engine.eck.podTemplate" (list $ $presetVal $agentName) | fromYaml }}
apiVersion: agent.k8s.elastic.co/v1alpha1
kind: Agent
metadata:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{{- range $presetName, $presetVal := $.Values.agent.presets -}}
{{- if and (eq ($presetVal).mode "statefulset") (eq $.Values.agent.engine "eck") -}}
{{- $agentName := include "elasticagent.preset.fullname" (list $ $presetName) -}}
{{- $podTemplateResource := include "elasticagent.engine.eck.podTemplate" (list $ $presetVal $agentName) | fromYaml -}}
{{- $podTemplateResource := include "elasticagent.engine.eck.podTemplate" (list $ $presetVal $agentName) | fromYaml }}
apiVersion: agent.k8s.elastic.co/v1alpha1
kind: Agent
metadata:
Expand Down
18 changes: 18 additions & 0 deletions deploy/helm/elastic-agent/templates/agent/k8s/_pod_template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,24 @@ template:
resources:
{{- . | toYaml | nindent 10 }}
{{- end }}
{{- with ($presetVal).ports }}
ports:
{{- range $idx, $port := . }}
- containerPort: {{ $port.containerPort }}
{{- with $port.protocol | default "TCP" }}
protocol: {{ . }}
{{- end }}
{{- with $port.name }}
name: {{ . }}
{{- end }}
{{- with $port.hostPort }}
hostPort: {{ . }}
{{- end }}
{{- with $port.hostIP }}
hostIP: {{ . }}
{{- end }}
{{- end }}
{{- end }}
volumeMounts:
{{- $definedAgentStateVolumeMount := false -}}
{{- with ($presetVal).extraVolumeMounts }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{{- range $presetName, $presetVal := $.Values.agent.presets -}}
{{- if and (eq ($presetVal).mode "daemonset") (eq $.Values.agent.engine "k8s") -}}
{{- $agentName := include "elasticagent.preset.fullname" (list $ $presetName) -}}
{{- $podTemplateResource := include "elasticagent.engine.k8s.podTemplate" (list $ $presetVal $agentName) | fromYaml -}}
{{- $podTemplateResource := include "elasticagent.engine.k8s.podTemplate" (list $ $presetVal $agentName) | fromYaml }}
apiVersion: apps/v1
kind: DaemonSet
metadata:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{{- range $presetName, $presetVal := $.Values.agent.presets -}}
{{- if and (eq ($presetVal).mode "deployment") (eq $.Values.agent.engine "k8s") -}}
{{- $agentName := include "elasticagent.preset.fullname" (list $ $presetName) -}}
{{- $podTemplateResource := include "elasticagent.engine.k8s.podTemplate" (list $ $presetVal $agentName) | fromYaml -}}
{{- $podTemplateResource := include "elasticagent.engine.k8s.podTemplate" (list $ $presetVal $agentName) | fromYaml }}
apiVersion: apps/v1
kind: Deployment
metadata:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{{- range $presetName, $presetVal := $.Values.agent.presets -}}
{{- if and (eq ($presetVal).mode "statefulset") (eq $.Values.agent.engine "k8s") -}}
{{- $agentName := include "elasticagent.preset.fullname" (list $ $presetName) -}}
{{- $podTemplateResource := include "elasticagent.engine.k8s.podTemplate" (list $ $presetVal $agentName) | fromYaml -}}
{{- $podTemplateResource := include "elasticagent.engine.k8s.podTemplate" (list $ $presetVal $agentName) | fromYaml }}
apiVersion: apps/v1
kind: StatefulSet
metadata:
Expand Down
48 changes: 48 additions & 0 deletions deploy/helm/elastic-agent/templates/agent/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{{- range $presetName, $presetVal := $.Values.agent.presets -}}
{{- $presetService := dig "service" dict $presetVal -}}
{{- $ports := dig "ports" list $presetVal -}}
{{- if and $presetService $ports -}}
{{- $agentName := include "elasticagent.preset.fullname" (list $ $presetName) -}}
apiVersion: v1
kind: Service
metadata:
name: {{ $agentName }}
namespace: {{ $.Release.Namespace | quote }}
labels:
{{- include "elasticagent.labels" $ | nindent 4 }}
{{- with ($presetVal).labels -}}
{{ toYaml . | nindent 4 }}
{{- end }}
{{- $presetValAnnotations := ($presetVal).annotations | default dict }}
{{- $presetServiceAnnotations := $presetService.annotations | default dict }}
{{- with merge dict $presetValAnnotations $presetServiceAnnotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
type: {{ $presetService.type }}
selector:
name: {{ $agentName }}
ports:
{{- range $idx, $port := $ports }}
- port: {{ $port.servicePort | default $port.containerPort }}
targetPort: {{ $port.containerPort }}
{{- with $port.protocol | default "TCP" }}
protocol: {{ . }}
{{- end }}
{{- with $port.name }}
name: {{ . }}
{{- end }}
{{- with $port.appProtocol }}
appProtocol: {{ . }}
{{- end }}
{{- with $port.nodePort }}
nodePort: {{ . }}
{{- end }}
{{- end }}
{{- with omit $presetService "type" "ports" "selector" }}
{{- toYaml | nindent 2 }}
{{- end }}
---
{{- end }}
{{- end }}
Loading

0 comments on commit a83b27a

Please sign in to comment.