diff --git a/backend/services/collector.go b/backend/services/collector.go index 3c3b82d..91e1ef6 100644 --- a/backend/services/collector.go +++ b/backend/services/collector.go @@ -274,6 +274,13 @@ func (s *CollectorService) Create(req *CreateCollectorRequest) (*models.Collecto refType = "host" } + // DaemonSet 的部署命名空间固定为 Loki 所在命名空间(通常 log): + // 采集器与 LokiStack 放在一起,用户不需要也不应该选。 + // 这里强制清空,渲染与部署两侧都会回退到 d.loki.Namespace。 + if req.Type == "k8s-daemonset" { + req.Namespace = "" + } + collector := models.Collector{ ID: repository.GetDB().NextID("collectors"), Name: req.Name, @@ -374,6 +381,11 @@ func (s *CollectorService) Update(id uint, updates map[string]interface{}) error if v, ok := updates["labels"].(string); ok { db.Collectors[i].Labels = v } + // DaemonSet 的 namespace 一律不接受修改(固定跟随 Loki 所在命名空间) + if v, ok := updates["namespace"].(string); ok && v != "" && db.Collectors[i].Type != "k8s-daemonset" { + db.Collectors[i].Namespace = v + db.Collectors[i].StatusMessage = "部署命名空间已保存,点击部署以应用新配置" + } // targetNamespaces: 采集哪些命名空间([]string;空=全集群) if v, ok := updates["targetNamespaces"]; ok { var nss []string diff --git a/frontend/src/i18n/locales/en/collectors.ts b/frontend/src/i18n/locales/en/collectors.ts index dc377b2..0d9b3ef 100644 --- a/frontend/src/i18n/locales/en/collectors.ts +++ b/frontend/src/i18n/locales/en/collectors.ts @@ -81,6 +81,7 @@ const collectors = { namespaceHintSidecar: 'The namespace where the TARGET Deployment lives. The platform finds that Deployment there and injects a Fluent Bit sidecar; collected logs also carry this namespace label. It is NOT a log filter.', namespaceHintDaemonset: 'The namespace where the Promtail DaemonSet is deployed. The DaemonSet collects container logs from ALL namespaces in the cluster — it does not filter by namespace (usually just the Loki namespace, e.g. log).', namespaceHintHost: 'Not used in host mode.', + namespaceFixedDaemonset: 'The DaemonSet is always deployed into the Loki namespace (usually log), together with LokiStack — nothing to choose. To limit what gets collected, use "Only collect from these namespaces" below.', targetNamespaces: 'Only collect from these namespaces', targetNamespacesHint: 'Leave empty to collect container stdout from ALL namespaces. Selecting specific ones cuts log volume significantly.', targetNamespacesAll: 'All namespaces', diff --git a/frontend/src/i18n/locales/zh/collectors.ts b/frontend/src/i18n/locales/zh/collectors.ts index 2a643c2..06cf685 100644 --- a/frontend/src/i18n/locales/zh/collectors.ts +++ b/frontend/src/i18n/locales/zh/collectors.ts @@ -85,6 +85,7 @@ const collectors = { namespaceHintSidecar: '填「目标应用(Deployment)所在的命名空间」。平台会在该命名空间里找到目标 Deployment 并注入 Fluent Bit sidecar,采集到的日志也会打上这个 namespace 标签。它不是日志过滤条件。', namespaceHintDaemonset: '填「Promtail DaemonSet 部署到哪个命名空间」。DaemonSet 会采集整个集群所有命名空间的容器日志,不按命名空间过滤(一般就用 Loki 所在的 log)。', namespaceHintHost: '主机模式不使用该字段。', + namespaceFixedDaemonset: '采集器部署命名空间固定为 Loki 所在命名空间(通常 log),与 LokiStack 放在一起,无需选择。要限制采集范围请用下面的「只采集这些命名空间」。', targetNamespaces: '只采集这些命名空间', targetNamespacesHint: '不选 = 采集整个集群所有命名空间的容器标准输出。选了就只采这几个(能显著减少日志量)。', targetNamespacesAll: '全集群', diff --git a/frontend/src/pages/collectors/components/CollectorFormDialog.tsx b/frontend/src/pages/collectors/components/CollectorFormDialog.tsx index 0f2af58..a617a19 100644 --- a/frontend/src/pages/collectors/components/CollectorFormDialog.tsx +++ b/frontend/src/pages/collectors/components/CollectorFormDialog.tsx @@ -212,7 +212,8 @@ export const CollectorFormDialog = memo(function CollectorFormDialog({ : undefined, targetDeployment: values.type === 'k8s-fluentbit-sidecar' ? values.targetDeployment : undefined, - namespace: values.type !== 'host-promtail' ? values.namespace : undefined, + // DaemonSet 的后端会强制用 Loki 所在命名空间(固定 log),这里不传 + namespace: values.type !== 'host-promtail' && values.type !== 'k8s-daemonset' ? values.namespace : undefined, // DaemonSet 的日志路径由平台固定为 /var/log/pods//*.log,不需要用户填; // 真要限制范围用 targetNamespaces(空 = 全集群) logPath: values.type === 'k8s-daemonset' ? '' : values.logPath, @@ -368,6 +369,9 @@ export const CollectorFormDialog = memo(function CollectorFormDialog({ )} />
+ {/* DaemonSet 的部署命名空间固定跟随 Loki(通常在 log), + 与 LokiStack 放在一起,用户不需要选,所以整块隐藏。 */} + {!isDaemonsetType && ( ) : ( - { + { field.onChange(event) if (isSidecarType) form.setValue('targetDeployment', '') }} /> @@ -416,6 +420,12 @@ export const CollectorFormDialog = memo(function CollectorFormDialog({ )} /> + )} + {isDaemonsetType && ( +
+ {t('form.namespaceFixedDaemonset')} +
+ )} {isSidecarType && (