Skip to content

Commit 0e92786

Browse files
feat(dynamic-exporter): Add dynamic flow exporter support for hubble
1 parent 8db4de4 commit 0e92786

File tree

6 files changed

+49
-6
lines changed

6 files changed

+49
-6
lines changed

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ CERT_FILES := tls.crt:tls-client-cert-file \
5353
tls.key:tls-client-key-file \
5454
ca.crt:tls-ca-cert-files
5555

56+
##################
57+
# Dynamic Export #
58+
##################
59+
ENABLE_DYNAMIC_EXPORT ?= false
60+
5661
# TAG is OS and platform agonstic, which can be used for binary version and image manifest tag,
5762
# while RETINA_PLATFORM_TAG is platform specific, which can be used for image built for specific platforms.
5863
RETINA_PLATFORM_TAG ?= $(TAG)-$(subst /,-,$(PLATFORM))
@@ -518,6 +523,7 @@ helm-install-hubble:
518523
--set agent.init.repository=$(IMAGE_REGISTRY)/$(RETINA_INIT_IMAGE) \
519524
--set agent.init.tag=$(HELM_IMAGE_TAG) \
520525
--set logLevel=info \
526+
--set hubble.export.dynamic.enabled=$(ENABLE_DYNAMIC_EXPORT) \
521527
--set hubble.tls.enabled=$(ENABLE_TLS) \
522528
--set hubble.relay.tls.server.enabled=$(ENABLE_TLS) \
523529
--set hubble.tls.auto.enabled=$(ENABLE_TLS) \
@@ -577,7 +583,7 @@ quick-deploy:
577583
.PHONY: quick-deploy-hubble
578584
quick-deploy-hubble:
579585
$(MAKE) helm-uninstall || true
580-
$(MAKE) helm-install-without-tls HELM_IMAGE_TAG=$(TAG)-linux-amd64
586+
$(MAKE) helm-install-without-tls HELM_IMAGE_TAG=$(TAG)-linux-amd64 ENABLE_DYNAMIC_EXPORT=true
581587

582588

583589
.PHONY: simplify-dashboards

controller/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ ENTRYPOINT ["./retina/initretina"]
116116

117117

118118
# agent final image
119-
# mcr.microsoft.com/cbl-mariner/distroless/minimal:2.0
120-
# mcr.microsoft.com/cbl-mariner/distroless/minimal@sha256:63a0a70ceaa1320bc6eb98b81106667d43e46b674731ea8d28e4de1b87e0747f
119+
# For debug: mcr.microsoft.com/cbl-mariner/distroless/debug:2.0
120+
# k exec -it ds/retina-agent -- busybox tail -f /var/run/retina/hubble/events.log
121121
FROM mariner-distroless AS agent
122122
COPY --from=tools /lib/ /lib
123123
COPY --from=tools /usr/lib/ /usr/lib

deploy/hubble/manifests/controller/helm/retina/templates/agent/daemonset.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ spec:
112112
mountPath: /var/lib/cilium/tls/hubble
113113
readOnly: true
114114
{{- end }}
115+
{{- if .Values.hubble.export.dynamic.enabled }}
116+
- name: hubble-flowlog-config
117+
mountPath: /flowlog-config
118+
readOnly: true
119+
{{- end }}
115120
{{- end }}
116121
terminationGracePeriodSeconds: 90 # Allow for retina to cleanup plugin resources.
117122
volumes:
@@ -142,6 +147,12 @@ spec:
142147
- key: ca.crt
143148
path: client-ca.crt
144149
{{- end }}
150+
{{- if .Values.hubble.export.dynamic.enabled }}
151+
- name: hubble-flowlog-config
152+
configMap:
153+
name: {{ .Values.hubble.export.dynamic.config.configMapName }}
154+
optional: true
155+
{{- end }}
145156
{{- end }}
146157
---
147158
{{- if .Values.os.windows}}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{{- if and .Values.hubble.export.dynamic.enabled .Values.hubble.export.dynamic.config.createConfigMap }}
2+
---
3+
apiVersion: v1
4+
kind: ConfigMap
5+
metadata:
6+
name: {{ .Values.hubble.export.dynamic.config.configMapName }}
7+
namespace: {{ .Release.Namespace }}
8+
data:
9+
flowlogs.yaml: |
10+
flowLogs:
11+
{{ .Values.hubble.export.dynamic.config.content | toYaml | indent 4 }}
12+
{{- end }}

deploy/hubble/manifests/controller/helm/retina/values.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -821,10 +821,10 @@ hubble:
821821
# --- Dynamic exporters configuration.
822822
# Dynamic exporters may be reconfigured without a need of agent restarts.
823823
dynamic:
824-
enabled: false
824+
enabled: true
825825
config:
826826
# ---- Name of configmap with configuration that may be altered to reconfigure exporters within a running agents.
827-
configMapName: cilium-flowlog-config
827+
configMapName: retina-flowlog-config
828828
# ---- True if helm installer should create config map.
829829
# Switch to false if you want to self maintain the file content.
830830
createConfigMap: true
@@ -834,7 +834,7 @@ hubble:
834834
fieldMask: []
835835
includeFilters: []
836836
excludeFilters: []
837-
filePath: "/var/run/cilium/hubble/events.log"
837+
filePath: "/var/run/retina/hubble/events.log"
838838
#- name: "test002"
839839
# filePath: "/var/log/network/flow-log/pa/test002.log"
840840
# fieldMask: ["source.namespace", "source.pod_name", "destination.namespace", "destination.pod_name", "verdict"]

pkg/hubble/hubble_linux.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"github.com/pkg/errors"
2727
"sigs.k8s.io/controller-runtime/pkg/client"
2828

29+
"github.com/cilium/cilium/pkg/hubble/exporter"
2930
"github.com/sirupsen/logrus"
3031
"go.uber.org/zap"
3132
)
@@ -114,6 +115,19 @@ func (rh *RetinaHubble) start(ctx context.Context) error {
114115
}),
115116
)
116117

118+
// Start the dynamic exporter if the config file path is provided.
119+
rh.log.Info("Starting dynamic exporter", zap.String("config", option.Config.HubbleFlowlogsConfigFilePath))
120+
if option.Config.HubbleFlowlogsConfigFilePath != "" {
121+
dynamicHubbleExporter := exporter.NewDynamicExporter(
122+
rh.log,
123+
option.Config.HubbleFlowlogsConfigFilePath,
124+
option.Config.HubbleExportFileMaxSizeMB,
125+
option.Config.HubbleExportFileMaxBackups)
126+
opt := observeroption.WithOnDecodedEvent(dynamicHubbleExporter)
127+
observerOpts = append(observerOpts, opt)
128+
rh.log.Info("Started dynamic exporter")
129+
}
130+
117131
// TODO: Replace with our custom parser.
118132
payloadParser := parser.New(rh.log, rh.ipc)
119133

0 commit comments

Comments
 (0)