@intentius/chant-lexicon-k8s 0.101.0 → 0.104.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions/apps.d.ts +4 -4
- package/dist/actions/apps.d.ts.map +1 -1
- package/dist/actions/core.d.ts +5 -5
- package/dist/actions/core.d.ts.map +1 -1
- package/dist/actions/networking.d.ts.map +1 -1
- package/dist/codegen/generate-typescript.d.ts +2 -2
- package/dist/codegen/generate-typescript.d.ts.map +1 -1
- package/dist/codegen/generate.d.ts +26 -0
- package/dist/codegen/generate.d.ts.map +1 -1
- package/dist/codegen/naming.d.ts.map +1 -1
- package/dist/codegen/versions.d.ts.map +1 -1
- package/dist/components/capability-plugin.d.ts.map +1 -1
- package/dist/components/kubectl-apply.d.ts +4 -1
- package/dist/components/kubectl-apply.d.ts.map +1 -1
- package/dist/composites/catalog.d.ts.map +1 -1
- package/dist/composites/cockroachdb-cluster.d.ts +2 -2
- package/dist/composites/gke-otel-collector.d.ts.map +1 -1
- package/dist/composites/index.d.ts +1 -0
- package/dist/composites/index.d.ts.map +1 -1
- package/dist/composites/otel-collector-agent.d.ts +19 -1
- package/dist/composites/otel-collector-agent.d.ts.map +1 -1
- package/dist/composites/otel-collector-node.d.ts +88 -0
- package/dist/composites/otel-collector-node.d.ts.map +1 -0
- package/dist/composites/otel-collector-rbac.d.ts.map +1 -1
- package/dist/composites/otel-collector-shape.d.ts +3 -1
- package/dist/composites/otel-collector-shape.d.ts.map +1 -1
- package/dist/composites/otel-collector.d.ts +9 -1
- package/dist/composites/otel-collector.d.ts.map +1 -1
- package/dist/composites/ray-cluster.d.ts +6 -6
- package/dist/composites/ray-job.d.ts +5 -5
- package/dist/composites/ray-service.d.ts +6 -6
- package/dist/crd/crd-sources.d.ts.map +1 -1
- package/dist/crd/loader.d.ts.map +1 -1
- package/dist/crd/oci-chart.d.ts +50 -0
- package/dist/crd/oci-chart.d.ts.map +1 -0
- package/dist/crd/types.d.ts +5 -0
- package/dist/crd/types.d.ts.map +1 -1
- package/dist/effect-receipt-row.d.ts.map +1 -1
- package/dist/generated/index.d.ts +764 -729
- package/dist/generated/index.d.ts.map +1 -1
- package/dist/import/embedded.d.ts +4 -2
- package/dist/import/embedded.d.ts.map +1 -1
- package/dist/import/generator.d.ts.map +1 -1
- package/dist/import/parser.d.ts.map +1 -1
- package/dist/import/testdata/embedded/fixtures.d.ts +6 -0
- package/dist/import/testdata/embedded/fixtures.d.ts.map +1 -1
- package/dist/integrity.json +8 -7
- package/dist/lint/audit-catalog.d.ts.map +1 -1
- package/dist/lint/post-synth/index.d.ts.map +1 -1
- package/dist/lint/post-synth/otel-placement-helpers.d.ts.map +1 -1
- package/dist/lint/post-synth/wk8604.d.ts +3 -2
- package/dist/lint/post-synth/wk8604.d.ts.map +1 -1
- package/dist/lint/post-synth/wk8605.d.ts +23 -0
- package/dist/lint/post-synth/wk8605.d.ts.map +1 -0
- package/dist/manifest.json +1 -1
- package/dist/meta.json +194 -17
- package/dist/okf/index.md +5 -0
- package/dist/okf/rules/WK8605.md +11 -0
- package/dist/okf/types/APIGroup.md +3 -3
- package/dist/okf/types/APIGroupList.md +1 -1
- package/dist/okf/types/APIResourceList.md +1 -1
- package/dist/okf/types/APIService.md +1 -1
- package/dist/okf/types/APIServiceList.md +2 -2
- package/dist/okf/types/APIVersions.md +1 -1
- package/dist/okf/types/BatchJob.md +1 -1
- package/dist/okf/types/CSIDriver.md +1 -1
- package/dist/okf/types/CSIDriverList.md +2 -2
- package/dist/okf/types/CSINode.md +1 -1
- package/dist/okf/types/CSINodeList.md +2 -2
- package/dist/okf/types/CSIStorageCapacity.md +2 -2
- package/dist/okf/types/CSIStorageCapacityList.md +2 -2
- package/dist/okf/types/CertificateSigningRequest.md +1 -1
- package/dist/okf/types/CertificateSigningRequestList.md +2 -2
- package/dist/okf/types/ClusterRole.md +1 -1
- package/dist/okf/types/ClusterRoleBindingList.md +2 -2
- package/dist/okf/types/ClusterRoleList.md +2 -2
- package/dist/okf/types/ClusterTrustBundle.md +1 -1
- package/dist/okf/types/ClusterTrustBundleList.md +2 -2
- package/dist/okf/types/ComponentStatus.md +1 -1
- package/dist/okf/types/ComponentStatusList.md +2 -2
- package/dist/okf/types/ConfigMapList.md +2 -2
- package/dist/okf/types/ControllerRevisionList.md +2 -2
- package/dist/okf/types/CoreEventList.md +2 -2
- package/dist/okf/types/CronJob.md +1 -1
- package/dist/okf/types/CronJobList.md +2 -2
- package/dist/okf/types/CustomResourceDefinition.md +1 -1
- package/dist/okf/types/CustomResourceDefinitionList.md +2 -2
- package/dist/okf/types/DaemonSet.md +1 -1
- package/dist/okf/types/DaemonSetList.md +2 -2
- package/dist/okf/types/DeleteOptions.md +1 -1
- package/dist/okf/types/Deploy.md +1 -1
- package/dist/okf/types/DeploymentList.md +2 -2
- package/dist/okf/types/DeviceClass.md +1 -1
- package/dist/okf/types/DeviceClassList.md +2 -2
- package/dist/okf/types/DeviceTaintRule.md +1 -1
- package/dist/okf/types/DeviceTaintRuleList.md +2 -2
- package/dist/okf/types/EndpointSlice.md +2 -2
- package/dist/okf/types/EndpointSliceList.md +2 -2
- package/dist/okf/types/Endpoints.md +1 -1
- package/dist/okf/types/EndpointsList.md +2 -2
- package/dist/okf/types/Event.md +2 -2
- package/dist/okf/types/EventsEvent.md +2 -2
- package/dist/okf/types/EventsEventList.md +2 -2
- package/dist/okf/types/Eviction.md +1 -1
- package/dist/okf/types/FlowSchema.md +1 -1
- package/dist/okf/types/FlowSchemaList.md +2 -2
- package/dist/okf/types/GrafanaDashboard.md +14 -0
- package/dist/okf/types/GrafanaDatasource.md +14 -0
- package/dist/okf/types/GrafanaFolder.md +14 -0
- package/dist/okf/types/GrafanaLibraryPanel.md +14 -0
- package/dist/okf/types/HorizontalPodAutoscaler.md +1 -1
- package/dist/okf/types/HorizontalPodAutoscalerList.md +2 -2
- package/dist/okf/types/IPAddress.md +1 -1
- package/dist/okf/types/IPAddressList.md +2 -2
- package/dist/okf/types/Ing.md +1 -1
- package/dist/okf/types/IngressClass.md +1 -1
- package/dist/okf/types/IngressClassList.md +2 -2
- package/dist/okf/types/IngressList.md +2 -2
- package/dist/okf/types/JobList.md +2 -2
- package/dist/okf/types/Lease.md +1 -1
- package/dist/okf/types/LeaseCandidate.md +1 -1
- package/dist/okf/types/LeaseCandidateList.md +2 -2
- package/dist/okf/types/LeaseList.md +2 -2
- package/dist/okf/types/LimitRange.md +1 -1
- package/dist/okf/types/LimitRangeList.md +2 -2
- package/dist/okf/types/LocalSubjectAccessReview.md +1 -1
- package/dist/okf/types/MutatingAdmissionPolicy.md +1 -1
- package/dist/okf/types/MutatingAdmissionPolicyBinding.md +1 -1
- package/dist/okf/types/MutatingAdmissionPolicyBindingList.md +2 -2
- package/dist/okf/types/MutatingAdmissionPolicyList.md +2 -2
- package/dist/okf/types/MutatingWebhookConfiguration.md +1 -1
- package/dist/okf/types/MutatingWebhookConfigurationList.md +2 -2
- package/dist/okf/types/Namespace.md +1 -1
- package/dist/okf/types/NamespaceList.md +2 -2
- package/dist/okf/types/NetPol.md +1 -1
- package/dist/okf/types/NetworkPolicyList.md +2 -2
- package/dist/okf/types/Node.md +1 -1
- package/dist/okf/types/NodeList.md +2 -2
- package/dist/okf/types/PersistentVolume.md +1 -1
- package/dist/okf/types/PersistentVolumeClaimList.md +2 -2
- package/dist/okf/types/PersistentVolumeList.md +2 -2
- package/dist/okf/types/PodCertificateRequest.md +1 -1
- package/dist/okf/types/PodCertificateRequestList.md +2 -2
- package/dist/okf/types/PodDisruptionBudgetList.md +2 -2
- package/dist/okf/types/PodList.md +2 -2
- package/dist/okf/types/PodTemplateList.md +2 -2
- package/dist/okf/types/PriorityClassList.md +2 -2
- package/dist/okf/types/PriorityLevelConfiguration.md +1 -1
- package/dist/okf/types/PriorityLevelConfigurationList.md +2 -2
- package/dist/okf/types/ReplicaSet.md +1 -1
- package/dist/okf/types/ReplicaSetList.md +2 -2
- package/dist/okf/types/ReplicationController.md +1 -1
- package/dist/okf/types/ReplicationControllerList.md +2 -2
- package/dist/okf/types/ResourceClaim.md +1 -1
- package/dist/okf/types/ResourceClaimList.md +2 -2
- package/dist/okf/types/ResourceClaimTemplate.md +1 -1
- package/dist/okf/types/ResourceClaimTemplateList.md +2 -2
- package/dist/okf/types/ResourceQuota.md +1 -1
- package/dist/okf/types/ResourceQuotaList.md +2 -2
- package/dist/okf/types/ResourceSlice.md +1 -1
- package/dist/okf/types/ResourceSliceList.md +2 -2
- package/dist/okf/types/RoleBindingList.md +2 -2
- package/dist/okf/types/RoleList.md +2 -2
- package/dist/okf/types/RuntimeClass.md +2 -2
- package/dist/okf/types/RuntimeClassList.md +2 -2
- package/dist/okf/types/Scale.md +1 -1
- package/dist/okf/types/SecretList.md +2 -2
- package/dist/okf/types/SelfSubjectAccessReview.md +1 -1
- package/dist/okf/types/SelfSubjectRulesReview.md +1 -1
- package/dist/okf/types/Service.md +1 -1
- package/dist/okf/types/ServiceAccountList.md +2 -2
- package/dist/okf/types/ServiceCIDR.md +1 -1
- package/dist/okf/types/ServiceCIDRList.md +2 -2
- package/dist/okf/types/ServiceList.md +2 -2
- package/dist/okf/types/StatefulSet.md +1 -1
- package/dist/okf/types/StatefulSetList.md +2 -2
- package/dist/okf/types/Status.md +2 -2
- package/dist/okf/types/StorageClass.md +1 -1
- package/dist/okf/types/StorageClassList.md +2 -2
- package/dist/okf/types/StorageVersionMigration.md +1 -1
- package/dist/okf/types/StorageVersionMigrationList.md +2 -2
- package/dist/okf/types/SubjectAccessReview.md +1 -1
- package/dist/okf/types/TokenRequest.md +1 -1
- package/dist/okf/types/TokenReview.md +1 -1
- package/dist/okf/types/ValidatingAdmissionPolicy.md +1 -1
- package/dist/okf/types/ValidatingAdmissionPolicyBinding.md +1 -1
- package/dist/okf/types/ValidatingAdmissionPolicyBindingList.md +2 -2
- package/dist/okf/types/ValidatingAdmissionPolicyList.md +2 -2
- package/dist/okf/types/ValidatingWebhookConfiguration.md +1 -1
- package/dist/okf/types/ValidatingWebhookConfigurationList.md +2 -2
- package/dist/okf/types/VolumeAttachment.md +1 -1
- package/dist/okf/types/VolumeAttachmentList.md +2 -2
- package/dist/okf/types/VolumeAttributesClassList.md +2 -2
- package/dist/op/activities/argo.d.ts.map +1 -1
- package/dist/op/activities/index.d.ts +3 -3
- package/dist/op/activities/index.d.ts.map +1 -1
- package/dist/op/activities/wait-for-ready.d.ts.map +1 -1
- package/dist/op/builders.d.ts.map +1 -1
- package/dist/rules/wk8602.ts +2 -2
- package/dist/rules/wk8604.ts +3 -2
- package/dist/rules/wk8605.ts +131 -0
- package/dist/serializer.d.ts +0 -3
- package/dist/serializer.d.ts.map +1 -1
- package/dist/skills/chant-k8s.md +1 -1
- package/dist/spec/parse.d.ts +27 -0
- package/dist/spec/parse.d.ts.map +1 -1
- package/dist/telemetry-release.d.ts +15 -0
- package/dist/telemetry-release.d.ts.map +1 -0
- package/dist/types/index.d.ts +5373 -972
- package/dist/variables.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/codegen/declarations.test.ts +118 -0
- package/src/codegen/generate-crd-sources.test.ts +49 -0
- package/src/codegen/generate-typescript.ts +69 -4
- package/src/codegen/generate.ts +66 -18
- package/src/components/kubectl-apply.test.ts +87 -0
- package/src/components/kubectl-apply.ts +17 -1
- package/src/composites/catalog.ts +6 -0
- package/src/composites/gke-otel-collector.ts +6 -1
- package/src/composites/index.ts +1 -0
- package/src/composites/otel-collector-agent.ts +39 -2
- package/src/composites/otel-collector-gateway.test.ts +24 -1
- package/src/composites/otel-collector-gateway.ts +1 -1
- package/src/composites/otel-collector-node.test.ts +193 -0
- package/src/composites/otel-collector-node.ts +211 -0
- package/src/composites/otel-collector-rbac.test.ts +11 -0
- package/src/composites/otel-collector-rbac.ts +6 -4
- package/src/composites/otel-collector-shape.ts +9 -8
- package/src/composites/otel-collector.ts +16 -2
- package/src/crd/crd-sources.ts +28 -0
- package/src/crd/loader.test.ts +9 -1
- package/src/crd/loader.ts +26 -3
- package/src/crd/oci-chart.test.ts +149 -0
- package/src/crd/oci-chart.ts +178 -0
- package/src/crd/types.ts +5 -0
- package/src/generated/index.d.ts +5373 -972
- package/src/generated/index.ts +35 -0
- package/src/generated/lexicon-k8s.json +194 -17
- package/src/generated/operations.json +64 -0
- package/src/import/embedded-live.test.ts +46 -4
- package/src/import/embedded-roundtrip.test.ts +73 -7
- package/src/import/embedded-types.e2e.test.ts +3 -1
- package/src/import/embedded.test.ts +64 -0
- package/src/import/embedded.ts +31 -2
- package/src/import/generator.test.ts +19 -0
- package/src/import/generator.ts +20 -2
- package/src/import/testdata/embedded/README.md +4 -1
- package/src/import/testdata/embedded/alertmanager-configmap.yaml +91 -0
- package/src/import/testdata/embedded/fixtures.ts +18 -0
- package/src/import/testdata/embedded/grafana-operator-dashboard.yaml +363 -0
- package/src/import/testdata/embedded/grafana-v2-dashboard-configmap.yaml +851 -0
- package/src/lint/audit-catalog.ts +1 -0
- package/src/lint/post-synth/index.ts +2 -0
- package/src/lint/post-synth/otel-placement.test.ts +14 -0
- package/src/lint/post-synth/post-synth.test.ts +3 -3
- package/src/lint/post-synth/wk8602.ts +2 -2
- package/src/lint/post-synth/wk8604.ts +3 -2
- package/src/lint/post-synth/wk8605.test.ts +153 -0
- package/src/lint/post-synth/wk8605.ts +131 -0
- package/src/serializer-telemetry.test.ts +146 -0
- package/src/serializer.ts +75 -0
- package/src/skills/chant-k8s.md +1 -1
- package/src/spec/parse.test.ts +118 -0
- package/src/spec/parse.ts +250 -29
- package/src/telemetry-build.test.ts +79 -0
- package/src/telemetry-release.ts +93 -0
|
@@ -17,6 +17,16 @@
|
|
|
17
17
|
import { mergeDefaults } from "@intentius/chant";
|
|
18
18
|
import { DaemonSet, ServiceAccount, ClusterRole, ClusterRoleBinding, ConfigMap } from "../generated";
|
|
19
19
|
import type { CollectorPolicyRule } from "./otel-collector-rbac";
|
|
20
|
+
import { nodeVolumeMounts, nodeVolumes, type CollectorNodeAccess } from "./otel-collector-node";
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* How a collector that reads the kubelet's container logs gets past their
|
|
24
|
+
* owner. The files are root's, readable by group root (containerd writes
|
|
25
|
+
* them mode 0640), so `group` keeps user 10001 and adds the pod to group 0
|
|
26
|
+
* with `supplementalGroups`. `root` runs the container as user 0 instead,
|
|
27
|
+
* for a runtime that writes the logs readable by their owner only.
|
|
28
|
+
*/
|
|
29
|
+
export type CollectorLogAccess = "group" | "root";
|
|
20
30
|
|
|
21
31
|
export interface CollectorAgentOptions {
|
|
22
32
|
name: string;
|
|
@@ -45,6 +55,10 @@ export interface CollectorAgentOptions {
|
|
|
45
55
|
workloadAnnotations?: Record<string, string>;
|
|
46
56
|
/** Annotations on the ConfigMap. */
|
|
47
57
|
configMapAnnotations?: Record<string, string>;
|
|
58
|
+
/** What the config reads from the node, from `collectorNodeAccess`: the node name variables and host mounts. */
|
|
59
|
+
nodeAccess?: CollectorNodeAccess;
|
|
60
|
+
/** How a config that reads container logs gets read access to them (default `group`). */
|
|
61
|
+
logAccess?: CollectorLogAccess;
|
|
48
62
|
defaults?: {
|
|
49
63
|
daemonSet?: Partial<Record<string, unknown>>;
|
|
50
64
|
serviceAccount?: Partial<Record<string, unknown>>;
|
|
@@ -69,7 +83,15 @@ export function collectorAgentResources(opts: CollectorAgentOptions): CollectorA
|
|
|
69
83
|
const bindingName = `${name}-binding`;
|
|
70
84
|
const configMapName = `${name}-config`;
|
|
71
85
|
|
|
72
|
-
const
|
|
86
|
+
const access = opts.nodeAccess;
|
|
87
|
+
const asRoot = access?.readsLogs === true && opts.logAccess === "root";
|
|
88
|
+
const baseContainer = collectorContainer({
|
|
89
|
+
...opts,
|
|
90
|
+
env: access?.env,
|
|
91
|
+
extraVolumeMounts: access ? nodeVolumeMounts(access.mounts) : undefined,
|
|
92
|
+
});
|
|
93
|
+
const container = asRoot ? runAsRoot(baseContainer) : baseContainer;
|
|
94
|
+
const podSecurity = access?.readsLogs && !asRoot ? { securityContext: { supplementalGroups: [0] } } : {};
|
|
73
95
|
|
|
74
96
|
const daemonSet = new DaemonSet(mergeDefaults({
|
|
75
97
|
metadata: {
|
|
@@ -87,8 +109,10 @@ export function collectorAgentResources(opts: CollectorAgentOptions): CollectorA
|
|
|
87
109
|
containers: [container],
|
|
88
110
|
volumes: [
|
|
89
111
|
{ name: "config", configMap: { name: configMapName } },
|
|
112
|
+
...(access ? nodeVolumes(access.mounts) : []),
|
|
90
113
|
],
|
|
91
114
|
tolerations: [{ operator: "Exists" }],
|
|
115
|
+
...podSecurity,
|
|
92
116
|
},
|
|
93
117
|
},
|
|
94
118
|
},
|
|
@@ -139,7 +163,12 @@ export function collectorAgentResources(opts: CollectorAgentOptions): CollectorA
|
|
|
139
163
|
export type CollectorContainerOptions = Pick<
|
|
140
164
|
CollectorAgentOptions,
|
|
141
165
|
"name" | "image" | "configDir" | "ports" | "cpuRequest" | "memoryRequest" | "cpuLimit" | "memoryLimit" | "containerExtra"
|
|
142
|
-
|
|
166
|
+
> & {
|
|
167
|
+
/** Environment variables, such as the node name from the downward API. Left out when empty. */
|
|
168
|
+
env?: Array<Record<string, unknown>>;
|
|
169
|
+
/** Mounts after the config mount, such as read-only host directories. */
|
|
170
|
+
extraVolumeMounts?: Array<Record<string, unknown>>;
|
|
171
|
+
};
|
|
143
172
|
|
|
144
173
|
/**
|
|
145
174
|
* The collector container: the image, the config file argument, the ports,
|
|
@@ -152,6 +181,7 @@ export function collectorContainer(opts: CollectorContainerOptions): Record<stri
|
|
|
152
181
|
name: opts.name,
|
|
153
182
|
image: opts.image,
|
|
154
183
|
args: [`--config=${opts.configDir}/config.yaml`],
|
|
184
|
+
...(opts.env?.length ? { env: opts.env } : {}),
|
|
155
185
|
ports: opts.ports,
|
|
156
186
|
resources: {
|
|
157
187
|
requests: { cpu: opts.cpuRequest, memory: opts.memoryRequest },
|
|
@@ -159,6 +189,7 @@ export function collectorContainer(opts: CollectorContainerOptions): Record<stri
|
|
|
159
189
|
},
|
|
160
190
|
volumeMounts: [
|
|
161
191
|
{ name: "config", mountPath: opts.configDir, readOnly: true },
|
|
192
|
+
...(opts.extraVolumeMounts ?? []),
|
|
162
193
|
],
|
|
163
194
|
securityContext: {
|
|
164
195
|
runAsNonRoot: true,
|
|
@@ -170,6 +201,12 @@ export function collectorContainer(opts: CollectorContainerOptions): Record<stri
|
|
|
170
201
|
};
|
|
171
202
|
}
|
|
172
203
|
|
|
204
|
+
/** The container run as user 0, for `logAccess: "root"`; the rest of its security context is kept. */
|
|
205
|
+
function runAsRoot(container: Record<string, unknown>): Record<string, unknown> {
|
|
206
|
+
const sc = (container.securityContext ?? {}) as Record<string, unknown>;
|
|
207
|
+
return { ...container, securityContext: { ...sc, runAsNonRoot: false, runAsUser: 0 } };
|
|
208
|
+
}
|
|
209
|
+
|
|
173
210
|
/** The ConfigMap holding the rendered collector config under `config.yaml`. */
|
|
174
211
|
export function collectorConfigMap(
|
|
175
212
|
opts: Pick<CollectorAgentOptions, "namespace" | "commonLabels" | "configYaml"> & {
|
|
@@ -9,6 +9,8 @@ import {
|
|
|
9
9
|
LoadBalancingExporter,
|
|
10
10
|
OtlpReceiver,
|
|
11
11
|
Pipeline,
|
|
12
|
+
PrometheusExporter,
|
|
13
|
+
defineComponent,
|
|
12
14
|
Service as CollectorService,
|
|
13
15
|
TailSamplingProcessor,
|
|
14
16
|
collectorTopology,
|
|
@@ -80,6 +82,26 @@ describe("OtelCollectorGateway", () => {
|
|
|
80
82
|
expect(container.securityContext.capabilities).toEqual({ drop: ["ALL"] });
|
|
81
83
|
});
|
|
82
84
|
|
|
85
|
+
test("a UDP receiver's port is UDP on the container and the Services, and the prometheus exporter's port is exposed (#3122)", () => {
|
|
86
|
+
const StatsdReceiver = defineComponent<{ endpoint: string }>()({
|
|
87
|
+
kind: "receiver",
|
|
88
|
+
type: "statsd",
|
|
89
|
+
pin: { source: "github.com/open-telemetry/opentelemetry-collector-contrib", version: "v0.130.0" },
|
|
90
|
+
});
|
|
91
|
+
const statsd = new StatsdReceiver({ endpoint: "0.0.0.0:8125" });
|
|
92
|
+
const prom = new PrometheusExporter({ endpoint: "0.0.0.0:8889" });
|
|
93
|
+
const gw = OtelCollectorGateway({ config: [new Pipeline({ signal: "metrics", receivers: [statsd], exporters: [prom] })] });
|
|
94
|
+
expect(p(gw.service).spec.ports).toEqual([
|
|
95
|
+
{ name: "statsd", port: 8125, targetPort: "statsd", protocol: "UDP" },
|
|
96
|
+
{ name: "prometheus", port: 8889, targetPort: "prometheus", protocol: "TCP" },
|
|
97
|
+
]);
|
|
98
|
+
const container = p(gw.deployment).spec.template.spec.containers[0];
|
|
99
|
+
expect(container.ports).toEqual([
|
|
100
|
+
{ containerPort: 8125, name: "statsd", protocol: "UDP" },
|
|
101
|
+
{ containerPort: 8889, name: "prometheus" },
|
|
102
|
+
]);
|
|
103
|
+
});
|
|
104
|
+
|
|
83
105
|
test("clusterRules adds a ClusterRole bound to the gateway's ServiceAccount", () => {
|
|
84
106
|
const rules = [{ apiGroups: [""], resources: ["pods", "nodes"], verbs: ["get", "list", "watch"] }];
|
|
85
107
|
const gw = OtelCollectorGateway({ name: "gw", namespace: "obs", clusterRules: rules });
|
|
@@ -199,7 +221,8 @@ describe("gatewayExporter", () => {
|
|
|
199
221
|
const agent = agentOf(exporter, { name: "agent" });
|
|
200
222
|
expect(config(agent).exporters?.["otlphttp/gateway"]).toEqual({ endpoint: "http://otel-gateway.observability.svc:4318" });
|
|
201
223
|
expect(p(agent.configMap).metadata.annotations[A.gateways]).toBe("observability/otel-gateway=service");
|
|
202
|
-
|
|
224
|
+
// agentOf's pipeline has no batch processor, which OTEL125 reports for an otlphttp exporter.
|
|
225
|
+
expect(validateCollectorConfig(config(agent)).filter((i) => i.code !== "OTEL125")).toEqual([]);
|
|
203
226
|
});
|
|
204
227
|
|
|
205
228
|
test("with protocol http and TLS, https and the TLS settings without insecure", () => {
|
|
@@ -200,7 +200,7 @@ export const OtelCollectorGateway = Composite((props: OtelCollectorGatewayProps)
|
|
|
200
200
|
},
|
|
201
201
|
}, defs?.deployment));
|
|
202
202
|
|
|
203
|
-
const servicePorts = runtime.servicePorts.map((p) => ({ name: p.name, port: p.port, targetPort: p.name, protocol: "TCP" }));
|
|
203
|
+
const servicePorts = runtime.servicePorts.map((p) => ({ name: p.name, port: p.port, targetPort: p.name, protocol: p.protocol ?? "TCP" }));
|
|
204
204
|
|
|
205
205
|
const service = new Service(mergeDefaults({
|
|
206
206
|
metadata: { name, namespace, labels: gatewayLabels },
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
DebugExporter,
|
|
4
|
+
FileLogReceiver,
|
|
5
|
+
HostMetricsReceiver,
|
|
6
|
+
NodeAgent,
|
|
7
|
+
OtlpExporter,
|
|
8
|
+
OtlpReceiver,
|
|
9
|
+
Pipeline,
|
|
10
|
+
} from "@intentius/chant-lexicon-otel";
|
|
11
|
+
import { collectorNodeAccess, fixedDirectory } from "./otel-collector-node";
|
|
12
|
+
import { OtelCollector } from "./otel-collector";
|
|
13
|
+
import { GkeOtelCollector } from "./gke-otel-collector";
|
|
14
|
+
|
|
15
|
+
const NODE_NAME = { name: "K8S_NODE_NAME", valueFrom: { fieldRef: { fieldPath: "spec.nodeName" } } };
|
|
16
|
+
|
|
17
|
+
/** A config whose pipelines run the given receivers and processors. */
|
|
18
|
+
function cfg(receivers: Record<string, unknown>, processors: Record<string, unknown> = {}) {
|
|
19
|
+
return {
|
|
20
|
+
receivers,
|
|
21
|
+
processors,
|
|
22
|
+
service: { pipelines: { logs: { receivers: Object.keys(receivers), processors: Object.keys(processors), exporters: ["debug"] } } },
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
type Props = { props: Record<string, any> };
|
|
27
|
+
const podSpec = (r: { daemonSet: unknown }) => (r.daemonSet as Props).props.spec.template.spec;
|
|
28
|
+
const containerOf = (r: { daemonSet: unknown }) => podSpec(r).containers[0];
|
|
29
|
+
|
|
30
|
+
describe("fixedDirectory", () => {
|
|
31
|
+
test.each([
|
|
32
|
+
["/var/log/pods/*/*/*.log", "/var/log/pods"],
|
|
33
|
+
["/var/log/containers/*.log", "/var/log/containers"],
|
|
34
|
+
["/var/log/syslog", "/var/log"],
|
|
35
|
+
["/var/log/{a,b}/x.log", "/var/log"],
|
|
36
|
+
["/*.log", undefined],
|
|
37
|
+
["logs/*.log", undefined],
|
|
38
|
+
])("%s gives %s", (pattern, dir) => {
|
|
39
|
+
expect(fixedDirectory(pattern)).toBe(dir);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe("collectorNodeAccess", () => {
|
|
44
|
+
test("a config that reads nothing from the node needs nothing", () => {
|
|
45
|
+
expect(collectorNodeAccess(cfg({ otlp: {} }, { batch: {}, k8sattributes: {} }))).toEqual({ env: [], mounts: [], readsLogs: false });
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test("k8sattributes filtering by node gets its variable from spec.nodeName", () => {
|
|
49
|
+
const access = collectorNodeAccess(cfg({ otlp: {} }, { "k8sattributes/node": { filter: { node_from_env_var: "KUBE_NODE_NAME" } } }));
|
|
50
|
+
expect(access.env).toEqual([{ name: "KUBE_NODE_NAME", valueFrom: { fieldRef: { fieldPath: "spec.nodeName" } } }]);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test("the collector's newer names read the node the same as the old ones", () => {
|
|
54
|
+
const old = collectorNodeAccess(
|
|
55
|
+
cfg(
|
|
56
|
+
{ kubeletstats: { node: "${env:K8S_NODE_NAME}" }, hostmetrics: { root_path: "/hostfs" }, filelog: { include: ["/var/log/pods/*/*/*.log"] } },
|
|
57
|
+
{ k8sattributes: { filter: { node_from_env_var: "KUBE_NODE_NAME" } } },
|
|
58
|
+
),
|
|
59
|
+
);
|
|
60
|
+
const renamed = collectorNodeAccess(
|
|
61
|
+
cfg(
|
|
62
|
+
{ kubelet_stats: { node: "${env:K8S_NODE_NAME}" }, host_metrics: { root_path: "/hostfs" }, file_log: { include: ["/var/log/pods/*/*/*.log"] } },
|
|
63
|
+
{ k8s_attributes: { filter: { node_from_env_var: "KUBE_NODE_NAME" } } },
|
|
64
|
+
),
|
|
65
|
+
);
|
|
66
|
+
expect(renamed.env).toEqual(old.env);
|
|
67
|
+
expect(renamed.mounts.map(({ component: _, ...m }) => m)).toEqual(old.mounts.map(({ component: _, ...m }) => m));
|
|
68
|
+
expect(renamed.readsLogs).toBe(true);
|
|
69
|
+
expect(renamed.mounts).toHaveLength(2);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test("kubeletstats: node and a NODE_NAME endpoint get the node name, a NODE_IP endpoint the host IP", () => {
|
|
73
|
+
expect(collectorNodeAccess(cfg({ kubeletstats: { endpoint: "https://${env:K8S_NODE_NAME}:10250", node: "${env:K8S_NODE_NAME}" } })).env).toEqual([NODE_NAME]);
|
|
74
|
+
expect(collectorNodeAccess(cfg({ kubeletstats: { endpoint: "https://${env:K8S_NODE_IP}:10250" } })).env).toEqual([
|
|
75
|
+
{ name: "K8S_NODE_IP", valueFrom: { fieldRef: { fieldPath: "status.hostIP" } } },
|
|
76
|
+
]);
|
|
77
|
+
// A variable whose meaning can't be told from its name is the caller's to set.
|
|
78
|
+
expect(collectorNodeAccess(cfg({ kubeletstats: { endpoint: "${env:KUBELET}:10250" } })).env).toEqual([]);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test("hostmetrics with root_path mounts the host root there; without it, nothing", () => {
|
|
82
|
+
expect(collectorNodeAccess(cfg({ hostmetrics: { root_path: "/hostfs/" } })).mounts).toEqual([
|
|
83
|
+
{ name: "hostfs", hostPath: "/", mountPath: "/hostfs", component: "hostmetrics", partial: true, mountPropagation: "HostToContainer" },
|
|
84
|
+
]);
|
|
85
|
+
expect(collectorNodeAccess(cfg({ hostmetrics: { scrapers: { cpu: {} } } })).mounts).toEqual([]);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test("filelog mounts the outermost fixed directory of its patterns, and /var/log/pods behind /var/log/containers", () => {
|
|
89
|
+
const access = collectorNodeAccess(cfg({
|
|
90
|
+
filelog: { include: ["/var/log/pods/*/*/*.log", "/var/log/pods/x/*.log"] },
|
|
91
|
+
"filelog/symlinks": { include: ["/var/log/containers/*.log"] },
|
|
92
|
+
}));
|
|
93
|
+
expect(access.mounts.map((m) => [m.name, m.hostPath, m.mountPath])).toEqual([
|
|
94
|
+
["host-var-log-pods", "/var/log/pods", "/var/log/pods"],
|
|
95
|
+
["host-var-log-containers", "/var/log/containers", "/var/log/containers"],
|
|
96
|
+
]);
|
|
97
|
+
expect(access.readsLogs).toBe(true);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test("a log directory covering the config directory, or under the host root mount, is not mounted", () => {
|
|
101
|
+
expect(collectorNodeAccess(cfg({ filelog: { include: ["/etc/**/*.log"] } })).mounts).toEqual([]);
|
|
102
|
+
const access = collectorNodeAccess(cfg({ hostmetrics: { root_path: "/hostfs" }, filelog: { include: ["/hostfs/var/log/*.log"] } }));
|
|
103
|
+
expect(access.mounts.map((m) => m.name)).toEqual(["hostfs"]);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test("a component no pipeline runs needs nothing", () => {
|
|
107
|
+
const access = collectorNodeAccess({
|
|
108
|
+
receivers: { otlp: {}, filelog: { include: ["/var/log/pods/*.log"] } },
|
|
109
|
+
service: { pipelines: { logs: { receivers: ["otlp"], exporters: ["debug"] } } },
|
|
110
|
+
});
|
|
111
|
+
expect(access.mounts).toEqual([]);
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
describe("OtelCollector running NodeAgent", () => {
|
|
116
|
+
const gateway = new OtlpExporter({ name: "gateway", endpoint: "otel-gateway.observability.svc:4317", tls: { insecure: true } });
|
|
117
|
+
const agent = (props: Parameters<typeof NodeAgent>[0]) => Object.values(NodeAgent(props).members);
|
|
118
|
+
|
|
119
|
+
test("gets the node name, read-only host mounts, group access to the logs and nodes/stats", () => {
|
|
120
|
+
const r = OtelCollector({ config: agent({ exporters: [gateway], kubeletStats: true }) });
|
|
121
|
+
const c = containerOf(r);
|
|
122
|
+
expect(c.env).toEqual([NODE_NAME]);
|
|
123
|
+
expect(c.volumeMounts).toEqual([
|
|
124
|
+
{ name: "config", mountPath: "/etc/otel", readOnly: true },
|
|
125
|
+
{ name: "hostfs", mountPath: "/hostfs", readOnly: true, mountPropagation: "HostToContainer" },
|
|
126
|
+
{ name: "host-var-log-pods", mountPath: "/var/log/pods", readOnly: true },
|
|
127
|
+
]);
|
|
128
|
+
expect(c.securityContext).toMatchObject({ runAsNonRoot: true, runAsUser: 10001 });
|
|
129
|
+
const pod = podSpec(r);
|
|
130
|
+
expect(pod.volumes).toEqual([
|
|
131
|
+
{ name: "config", configMap: { name: "otel-collector-config" } },
|
|
132
|
+
{ name: "hostfs", hostPath: { path: "/" } },
|
|
133
|
+
{ name: "host-var-log-pods", hostPath: { path: "/var/log/pods" } },
|
|
134
|
+
]);
|
|
135
|
+
expect(pod.securityContext).toEqual({ supplementalGroups: [0] });
|
|
136
|
+
const rules = (r.clusterRole as unknown as Props).props.rules;
|
|
137
|
+
expect(rules).toContainEqual({ apiGroups: [""], resources: ["nodes/stats"], verbs: ["get"] });
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
test("logAccess root runs the container as user 0 instead of adding group 0", () => {
|
|
141
|
+
const r = OtelCollector({ config: agent({ exporters: [gateway] }), logAccess: "root" });
|
|
142
|
+
expect(containerOf(r).securityContext).toMatchObject({ runAsNonRoot: false, runAsUser: 0, readOnlyRootFilesystem: true, allowPrivilegeEscalation: false });
|
|
143
|
+
expect(podSpec(r).securityContext).toBeUndefined();
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test("without logs or host metrics, only the node name is added", () => {
|
|
147
|
+
const r = OtelCollector({ config: agent({ exporters: [gateway], hostMetrics: false, containerLogs: false }) });
|
|
148
|
+
expect(containerOf(r).env).toEqual([NODE_NAME]);
|
|
149
|
+
expect(containerOf(r).volumeMounts).toHaveLength(1);
|
|
150
|
+
expect(podSpec(r).securityContext).toBeUndefined();
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
test("a custom nodeNameEnv is the variable set", () => {
|
|
154
|
+
const r = OtelCollector({ config: agent({ exporters: [gateway], nodeNameEnv: "MY_NODE", kubeletStats: true }) });
|
|
155
|
+
expect(containerOf(r).env).toEqual([{ name: "MY_NODE", valueFrom: { fieldRef: { fieldPath: "spec.nodeName" } } }]);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
test("a hand-declared filelog and hostmetrics config is wired the same way", () => {
|
|
159
|
+
const logs = new FileLogReceiver({ include: ["/var/log/pods/*/*/*.log"] });
|
|
160
|
+
const host = new HostMetricsReceiver({ root_path: "/hostfs", scrapers: { cpu: {} } });
|
|
161
|
+
const debug = new DebugExporter({});
|
|
162
|
+
const r = OtelCollector({
|
|
163
|
+
config: [
|
|
164
|
+
new Pipeline({ signal: "logs", receivers: [logs], exporters: [debug] }),
|
|
165
|
+
new Pipeline({ signal: "metrics", receivers: [host], exporters: [debug] }),
|
|
166
|
+
],
|
|
167
|
+
});
|
|
168
|
+
expect(containerOf(r).env).toBeUndefined();
|
|
169
|
+
expect(podSpec(r).volumes.map((v: { name: string }) => v.name)).toEqual(["config", "hostfs", "host-var-log-pods"]);
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
describe("configs that don't read the node keep their output", () => {
|
|
174
|
+
test("OtelCollector's default config adds no env, volume or pod security context", () => {
|
|
175
|
+
const r = OtelCollector({});
|
|
176
|
+
expect(containerOf(r).env).toBeUndefined();
|
|
177
|
+
expect(containerOf(r).volumeMounts).toEqual([{ name: "config", mountPath: "/etc/otel", readOnly: true }]);
|
|
178
|
+
expect(Object.keys(podSpec(r))).toEqual(["serviceAccountName", "containers", "volumes", "tolerations"]);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
test("an OTLP-only full config adds nothing either", () => {
|
|
182
|
+
const rx = new OtlpReceiver({ protocols: { grpc: { endpoint: "0.0.0.0:4317" } } });
|
|
183
|
+
const r = OtelCollector({ config: [new Pipeline({ signal: "traces", receivers: [rx], exporters: [new DebugExporter({})] })] });
|
|
184
|
+
expect(containerOf(r).env).toBeUndefined();
|
|
185
|
+
expect(podSpec(r).volumes).toHaveLength(1);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
test("GkeOtelCollector, whose config is OTLP only, adds nothing", () => {
|
|
189
|
+
const r = GkeOtelCollector({ clusterName: "c", projectId: "p" });
|
|
190
|
+
expect(containerOf(r).env).toBeUndefined();
|
|
191
|
+
expect(Object.keys(podSpec(r))).toEqual(["serviceAccountName", "containers", "volumes", "tolerations"]);
|
|
192
|
+
});
|
|
193
|
+
});
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a collector pod needs from its node, worked out from the collector
|
|
3
|
+
* config it runs, the way `agentClusterRules` works out its RBAC (chant
|
|
4
|
+
* #3103). `OtelCollector` and `GkeOtelCollector` add the result to their
|
|
5
|
+
* DaemonSet, and WK8605 reports a workload that runs such a config without it.
|
|
6
|
+
*
|
|
7
|
+
* Only components a pipeline runs count, since the collector starts no
|
|
8
|
+
* other. A config that reads nothing from the node gets nothing, so its
|
|
9
|
+
* DaemonSet is unchanged. Each requirement cites the component's README at
|
|
10
|
+
* collector-contrib v0.130.0, the version the otel lexicon pins:
|
|
11
|
+
*
|
|
12
|
+
* - The node's name, from the downward API (`spec.nodeName`), in each
|
|
13
|
+
* variable a `k8sattributes` processor names in `filter.node_from_env_var`
|
|
14
|
+
* (processor/k8sattributesprocessor README, "Deployment scenarios": "Use
|
|
15
|
+
* the downward API to inject the node name as an environment variable"),
|
|
16
|
+
* and in each `${env:VAR}` a `kubeletstats` receiver's `node` uses, or its
|
|
17
|
+
* `endpoint` uses when the variable's name ends in `NODE_NAME`
|
|
18
|
+
* (receiver/kubeletstatsreceiver README, "Service Account Authentication
|
|
19
|
+
* Example"). An `endpoint` variable ending in `NODE_IP` or `HOST_IP` gets
|
|
20
|
+
* `status.hostIP` instead. Any other variable is the caller's to set.
|
|
21
|
+
* - The host root, read-only at a `hostmetrics` receiver's `root_path`
|
|
22
|
+
* (receiver/hostmetricsreceiver README, "Collecting host metrics from
|
|
23
|
+
* inside a container (Linux only)": bind mount the host filesystem, then
|
|
24
|
+
* configure `root_path`). Mounted with `HostToContainer` propagation so
|
|
25
|
+
* filesystems the node mounts later show up, as the upstream Helm chart's
|
|
26
|
+
* hostMetrics preset does.
|
|
27
|
+
* - The directories a `filelog` receiver's `include` patterns read, read-only
|
|
28
|
+
* at the same path (receiver/filelogreceiver README, "Configuration":
|
|
29
|
+
* `include` is a list of file glob patterns the receiver reads). The mount
|
|
30
|
+
* is the fixed directory part of each pattern, so `/var/log/pods/*\/*\/*.log`
|
|
31
|
+
* mounts `/var/log/pods`. `/var/log/containers` holds symlinks into
|
|
32
|
+
* `/var/log/pods`, so reading it mounts both. A pattern with no fixed
|
|
33
|
+
* directory below `/`, or one that would cover the config directory, is
|
|
34
|
+
* left to the caller.
|
|
35
|
+
*
|
|
36
|
+
* `readsLogs` is set when a `filelog` receiver reads a host directory: the
|
|
37
|
+
* kubelet's container logs there are owned by root, which the composites
|
|
38
|
+
* deal with (see `logAccess` on `OtelCollector`).
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
import { canonicalTypeOf } from "@intentius/chant-lexicon-otel/model";
|
|
42
|
+
|
|
43
|
+
/** A variable set from the downward API. A type alias, so it fits where container fields are a plain record. */
|
|
44
|
+
export type NodeEnvVar = {
|
|
45
|
+
name: string;
|
|
46
|
+
valueFrom: { fieldRef: { fieldPath: "spec.nodeName" | "status.hostIP" } };
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/** A host directory the collector reads, mounted read-only. */
|
|
50
|
+
export interface NodeHostMount {
|
|
51
|
+
/** Volume name, a DNS label. */
|
|
52
|
+
name: string;
|
|
53
|
+
/** Path on the node. */
|
|
54
|
+
hostPath: string;
|
|
55
|
+
/** Path in the container. */
|
|
56
|
+
mountPath: string;
|
|
57
|
+
/** Which component needs it, for messages. */
|
|
58
|
+
component: string;
|
|
59
|
+
/** `hostmetrics` takes any host mount at or under `mountPath` (the README allows mounting only parts of the root). */
|
|
60
|
+
partial?: boolean;
|
|
61
|
+
mountPropagation?: "HostToContainer";
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface CollectorNodeAccess {
|
|
65
|
+
env: NodeEnvVar[];
|
|
66
|
+
mounts: NodeHostMount[];
|
|
67
|
+
/** A `filelog` receiver reads a host directory, whose files are root-owned. */
|
|
68
|
+
readsLogs: boolean;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** The part of a collector config this reads; both the built config and a parsed ConfigMap value fit. */
|
|
72
|
+
export interface NodeReadingConfig {
|
|
73
|
+
receivers?: Record<string, unknown>;
|
|
74
|
+
processors?: Record<string, unknown>;
|
|
75
|
+
service?: { pipelines?: Record<string, unknown> } | unknown;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function isRecord(v: unknown): v is Record<string, unknown> {
|
|
79
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Component ids of one kind that some pipeline runs. */
|
|
83
|
+
function runningIds(config: NodeReadingConfig, kind: "receivers" | "processors"): Set<string> {
|
|
84
|
+
const ids = new Set<string>();
|
|
85
|
+
const pipelines = isRecord(config.service) && isRecord(config.service.pipelines) ? config.service.pipelines : {};
|
|
86
|
+
for (const p of Object.values(pipelines)) {
|
|
87
|
+
const list = isRecord(p) ? p[kind] : undefined;
|
|
88
|
+
if (Array.isArray(list)) for (const id of list) if (typeof id === "string") ids.add(id);
|
|
89
|
+
}
|
|
90
|
+
return ids;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** [id, settings] of each running component of `type`, under its old or new name (`kubelet_stats`). */
|
|
94
|
+
function running(config: NodeReadingConfig, kind: "receivers" | "processors", type: string): Array<[string, Record<string, unknown>]> {
|
|
95
|
+
const ids = runningIds(config, kind);
|
|
96
|
+
const section = isRecord(config[kind]) ? (config[kind] as Record<string, unknown>) : {};
|
|
97
|
+
const componentKind = kind === "receivers" ? "receiver" : "processor";
|
|
98
|
+
return Object.entries(section)
|
|
99
|
+
.filter(([id]) => ids.has(id) && canonicalTypeOf(componentKind, id) === type)
|
|
100
|
+
.map(([id, cfg]) => [id, isRecord(cfg) ? cfg : {}]);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** The variables a string reads as `${env:NAME}`. */
|
|
104
|
+
function envRefs(value: unknown): string[] {
|
|
105
|
+
if (typeof value !== "string") return [];
|
|
106
|
+
return [...value.matchAll(/\$\{env:([A-Za-z_][A-Za-z0-9_]*)\}/g)].map((m) => m[1]);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** The directory part of a glob before its first wildcard: `/var/log/pods/*\/x.log` is `/var/log/pods`. */
|
|
110
|
+
export function fixedDirectory(pattern: string): string | undefined {
|
|
111
|
+
if (!pattern.startsWith("/")) return undefined;
|
|
112
|
+
const parts = pattern.split("/");
|
|
113
|
+
const fixed: string[] = [];
|
|
114
|
+
for (const part of parts) {
|
|
115
|
+
if (/[*?[{]/.test(part)) break;
|
|
116
|
+
fixed.push(part);
|
|
117
|
+
}
|
|
118
|
+
// No wildcard at all: a file, so its directory.
|
|
119
|
+
if (fixed.length === parts.length) fixed.pop();
|
|
120
|
+
const dir = fixed.join("/").replace(/\/+$/, "");
|
|
121
|
+
return dir === "" ? undefined : dir;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function within(path: string, dir: string): boolean {
|
|
125
|
+
return path === dir || path.startsWith(`${dir}/`);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function volumeName(prefix: string, path: string): string {
|
|
129
|
+
const slug = path.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
130
|
+
return `${prefix}-${slug}`.slice(0, 63).replace(/-+$/, "");
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* What a collector config needs from the node. `configDir` is where the
|
|
135
|
+
* collector's own config is mounted; a log directory covering it is skipped.
|
|
136
|
+
*/
|
|
137
|
+
export function collectorNodeAccess(config: NodeReadingConfig, configDir = "/etc/otel"): CollectorNodeAccess {
|
|
138
|
+
const env = new Map<string, NodeEnvVar["valueFrom"]["fieldRef"]["fieldPath"]>();
|
|
139
|
+
const setEnv = (name: string, fieldPath: NodeEnvVar["valueFrom"]["fieldRef"]["fieldPath"]) => {
|
|
140
|
+
if (!env.has(name)) env.set(name, fieldPath);
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
for (const [, p] of running(config, "processors", "k8sattributes")) {
|
|
144
|
+
const name = isRecord(p.filter) ? p.filter.node_from_env_var : undefined;
|
|
145
|
+
if (typeof name === "string" && /^[A-Za-z_][A-Za-z0-9_]*$/.test(name)) setEnv(name, "spec.nodeName");
|
|
146
|
+
}
|
|
147
|
+
for (const [, r] of running(config, "receivers", "kubeletstats")) {
|
|
148
|
+
for (const name of envRefs(r.node)) setEnv(name, "spec.nodeName");
|
|
149
|
+
for (const name of envRefs(r.endpoint)) {
|
|
150
|
+
if (/(NODE|HOST)_IP$/.test(name)) setEnv(name, "status.hostIP");
|
|
151
|
+
else if (/NODE_NAME$/.test(name)) setEnv(name, "spec.nodeName");
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const mounts: NodeHostMount[] = [];
|
|
156
|
+
const rootPaths = new Set<string>();
|
|
157
|
+
for (const [id, r] of running(config, "receivers", "hostmetrics")) {
|
|
158
|
+
const root = typeof r.root_path === "string" ? r.root_path.replace(/\/+$/, "") : "";
|
|
159
|
+
if (!root.startsWith("/") || rootPaths.has(root)) continue;
|
|
160
|
+
rootPaths.add(root);
|
|
161
|
+
mounts.push({
|
|
162
|
+
name: rootPaths.size === 1 ? "hostfs" : volumeName("hostfs", root),
|
|
163
|
+
hostPath: "/",
|
|
164
|
+
mountPath: root,
|
|
165
|
+
component: id,
|
|
166
|
+
partial: true,
|
|
167
|
+
mountPropagation: "HostToContainer",
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const logDirs: Array<{ dir: string; component: string }> = [];
|
|
172
|
+
for (const [id, r] of running(config, "receivers", "filelog")) {
|
|
173
|
+
const include = Array.isArray(r.include) ? r.include : [];
|
|
174
|
+
for (const pattern of include) {
|
|
175
|
+
if (typeof pattern !== "string") continue;
|
|
176
|
+
const dir = fixedDirectory(pattern);
|
|
177
|
+
if (!dir || within(configDir, dir)) continue;
|
|
178
|
+
logDirs.push({ dir, component: id });
|
|
179
|
+
if (within(dir, "/var/log/containers")) logDirs.push({ dir: "/var/log/pods", component: id });
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
// One mount per directory, the outermost of nested ones.
|
|
183
|
+
const kept = logDirs.filter(({ dir }, i) =>
|
|
184
|
+
!logDirs.some((o, j) => (o.dir !== dir && within(dir, o.dir)) || (o.dir === dir && j < i)),
|
|
185
|
+
);
|
|
186
|
+
for (const { dir, component } of kept) {
|
|
187
|
+
if ([...rootPaths].some((root) => within(dir, root))) continue;
|
|
188
|
+
mounts.push({ name: volumeName("host", dir), hostPath: dir, mountPath: dir, component });
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return {
|
|
192
|
+
env: [...env].map(([name, fieldPath]) => ({ name, valueFrom: { fieldRef: { fieldPath } } })),
|
|
193
|
+
mounts,
|
|
194
|
+
readsLogs: kept.length > 0,
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** The pod volumes for a set of mounts. */
|
|
199
|
+
export function nodeVolumes(mounts: NodeHostMount[]): Array<Record<string, unknown>> {
|
|
200
|
+
return mounts.map((m) => ({ name: m.name, hostPath: { path: m.hostPath } }));
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** The container volume mounts for a set of mounts, all read-only. */
|
|
204
|
+
export function nodeVolumeMounts(mounts: NodeHostMount[]): Array<Record<string, unknown>> {
|
|
205
|
+
return mounts.map((m) => ({
|
|
206
|
+
name: m.name,
|
|
207
|
+
mountPath: m.mountPath,
|
|
208
|
+
readOnly: true,
|
|
209
|
+
...(m.mountPropagation ? { mountPropagation: m.mountPropagation } : {}),
|
|
210
|
+
}));
|
|
211
|
+
}
|
|
@@ -49,6 +49,17 @@ describe("agentClusterRules", () => {
|
|
|
49
49
|
expect(rules[2].resources).toEqual(["nodes/stats"]);
|
|
50
50
|
});
|
|
51
51
|
|
|
52
|
+
test("k8s_attributes and kubelet_stats, the collector's newer names, get the same rules as the old ones", () => {
|
|
53
|
+
const kubelet = { extra_metadata_labels: ["container.id"], k8s_api_config: { auth_type: "serviceAccount" } };
|
|
54
|
+
const extract = { extract: { labels: [{ key: "team", from: "deployment" }] } };
|
|
55
|
+
const old = agentClusterRules(cfg({ processors: { "k8sattributes/x": extract }, receivers: { kubeletstats: kubelet } } as any));
|
|
56
|
+
const renamed = agentClusterRules(cfg({ processors: { "k8s_attributes/x": extract }, receivers: { kubelet_stats: kubelet } } as any));
|
|
57
|
+
expect(renamed).toEqual(old);
|
|
58
|
+
expect(renamed.flatMap((r) => r.resources)).toEqual(
|
|
59
|
+
expect.arrayContaining(["deployments", "nodes/stats", "nodes/proxy", "persistentvolumes"]),
|
|
60
|
+
);
|
|
61
|
+
});
|
|
62
|
+
|
|
52
63
|
test("kubeletstats with k8s_api_config reads persistent volumes and claims", () => {
|
|
53
64
|
const rules = agentClusterRules(cfg({ receivers: { kubeletstats: { k8s_api_config: { auth_type: "serviceAccount" } } } as any }));
|
|
54
65
|
expect(rules.at(-1)).toEqual({ apiGroups: [""], resources: ["persistentvolumeclaims", "persistentvolumes"], verbs: ["get"] });
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
|
|
17
17
|
import { mergeDefaults } from "@intentius/chant";
|
|
18
18
|
import type { CollectorConfig } from "@intentius/chant-lexicon-otel";
|
|
19
|
+
import { canonicalTypeOf, type ComponentKind } from "@intentius/chant-lexicon-otel/model";
|
|
19
20
|
import { Role, RoleBinding } from "../generated";
|
|
20
21
|
|
|
21
22
|
/** One RBAC rule, as a Role or ClusterRole lists it. */
|
|
@@ -28,9 +29,10 @@ export interface CollectorPolicyRule {
|
|
|
28
29
|
|
|
29
30
|
const READ = ["get", "list", "watch"];
|
|
30
31
|
|
|
31
|
-
|
|
32
|
+
/** The configs of the components of `kind` whose type is `type`, under its old or new name (`k8s_attributes`). */
|
|
33
|
+
function componentsOfType(kind: ComponentKind, section: Record<string, unknown> | undefined, type: string): Array<Record<string, unknown>> {
|
|
32
34
|
return Object.entries(section ?? {})
|
|
33
|
-
.filter(([id]) => id === type
|
|
35
|
+
.filter(([id]) => canonicalTypeOf(kind, id) === type)
|
|
34
36
|
.map(([, cfg]) => (cfg && typeof cfg === "object" ? (cfg as Record<string, unknown>) : {}));
|
|
35
37
|
}
|
|
36
38
|
|
|
@@ -58,7 +60,7 @@ function componentsOfType(section: Record<string, unknown> | undefined, type: st
|
|
|
58
60
|
*/
|
|
59
61
|
export function agentClusterRules(config: CollectorConfig): CollectorPolicyRule[] {
|
|
60
62
|
const apps = ["replicasets"];
|
|
61
|
-
const k8sattributes = componentsOfType(config.processors as Record<string, unknown> | undefined, "k8sattributes");
|
|
63
|
+
const k8sattributes = componentsOfType("processor", config.processors as Record<string, unknown> | undefined, "k8sattributes");
|
|
62
64
|
const fromDeployment = k8sattributes.some((p) => {
|
|
63
65
|
const extract = p.extract as { labels?: Array<{ from?: string }>; annotations?: Array<{ from?: string }> } | undefined;
|
|
64
66
|
return [...(extract?.labels ?? []), ...(extract?.annotations ?? [])].some((f) => f?.from === "deployment");
|
|
@@ -70,7 +72,7 @@ export function agentClusterRules(config: CollectorConfig): CollectorPolicyRule[
|
|
|
70
72
|
{ apiGroups: ["apps"], resources: apps, verbs: READ },
|
|
71
73
|
];
|
|
72
74
|
|
|
73
|
-
const kubeletstats = componentsOfType(config.receivers as Record<string, unknown> | undefined, "kubeletstats");
|
|
75
|
+
const kubeletstats = componentsOfType("receiver", config.receivers as Record<string, unknown> | undefined, "kubeletstats");
|
|
74
76
|
if (kubeletstats.length) {
|
|
75
77
|
const nodeSubresources = ["nodes/stats"];
|
|
76
78
|
const needsProxy = kubeletstats.some((r) => {
|