@intentius/chant-lexicon-k8s 0.100.0 → 0.102.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.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/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 +24 -2
- package/dist/composites/otel-collector-agent.d.ts.map +1 -1
- package/dist/composites/otel-collector-gateway.d.ts +37 -52
- package/dist/composites/otel-collector-gateway.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 +74 -0
- package/dist/composites/otel-collector-rbac.d.ts.map +1 -0
- package/dist/composites/otel-collector-shape.d.ts +7 -0
- package/dist/composites/otel-collector-shape.d.ts.map +1 -1
- package/dist/composites/otel-collector.d.ts +17 -21
- 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 +752 -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/live-export.d.ts +5 -0
- package/dist/import/live-export.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 -6
- 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 +5 -1
- package/dist/lint/post-synth/otel-placement-helpers.d.ts.map +1 -1
- package/dist/lint/post-synth/wk8604.d.ts +19 -0
- package/dist/lint/post-synth/wk8604.d.ts.map +1 -0
- 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 +156 -17
- package/dist/okf/index.md +5 -0
- package/dist/okf/rules/WK8604.md +11 -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/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/otel-placement-helpers.ts +7 -11
- package/dist/rules/wk8604.ts +29 -0
- package/dist/rules/wk8605.ts +131 -0
- 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/types/index.d.ts +5360 -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-typescript.ts +69 -4
- package/src/codegen/generate.ts +15 -6
- package/src/composites/__snapshots__/gke-otel-collector.snapshot.test.ts.snap +2 -68
- package/src/composites/catalog.ts +12 -0
- package/src/composites/gke-otel-collector.snapshot.test.ts +3 -1
- package/src/composites/gke-otel-collector.ts +13 -2
- package/src/composites/index.ts +1 -0
- package/src/composites/otel-collector-agent.ts +45 -11
- package/src/composites/otel-collector-gateway.test.ts +102 -5
- package/src/composites/otel-collector-gateway.ts +96 -18
- package/src/composites/otel-collector-node.test.ts +174 -0
- package/src/composites/otel-collector-node.ts +213 -0
- package/src/composites/otel-collector-rbac.test.ts +114 -0
- package/src/composites/otel-collector-rbac.ts +144 -0
- package/src/composites/otel-collector-shape.ts +19 -0
- package/src/composites/otel-collector.ts +40 -35
- package/src/crd/crd-sources.ts +26 -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 +5360 -972
- package/src/generated/index.ts +23 -0
- package/src/generated/lexicon-k8s.json +156 -17
- package/src/generated/operations.json +48 -0
- package/src/import/embedded-live.test.ts +180 -0
- 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/live-export.ts +10 -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 +2 -0
- package/src/lint/post-synth/index.ts +4 -0
- package/src/lint/post-synth/otel-placement-helpers.ts +7 -11
- package/src/lint/post-synth/otel-placement.test.ts +35 -0
- package/src/lint/post-synth/post-synth.test.ts +3 -3
- package/src/lint/post-synth/wk8604.ts +29 -0
- package/src/lint/post-synth/wk8605.test.ts +141 -0
- package/src/lint/post-synth/wk8605.ts +131 -0
- package/src/skills/chant-k8s.md +1 -1
- package/src/spec/parse.test.ts +118 -0
- package/src/spec/parse.ts +250 -29
|
@@ -0,0 +1,213 @@
|
|
|
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
|
+
/** A variable set from the downward API. A type alias, so it fits where container fields are a plain record. */
|
|
42
|
+
export type NodeEnvVar = {
|
|
43
|
+
name: string;
|
|
44
|
+
valueFrom: { fieldRef: { fieldPath: "spec.nodeName" | "status.hostIP" } };
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/** A host directory the collector reads, mounted read-only. */
|
|
48
|
+
export interface NodeHostMount {
|
|
49
|
+
/** Volume name, a DNS label. */
|
|
50
|
+
name: string;
|
|
51
|
+
/** Path on the node. */
|
|
52
|
+
hostPath: string;
|
|
53
|
+
/** Path in the container. */
|
|
54
|
+
mountPath: string;
|
|
55
|
+
/** Which component needs it, for messages. */
|
|
56
|
+
component: string;
|
|
57
|
+
/** `hostmetrics` takes any host mount at or under `mountPath` (the README allows mounting only parts of the root). */
|
|
58
|
+
partial?: boolean;
|
|
59
|
+
mountPropagation?: "HostToContainer";
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface CollectorNodeAccess {
|
|
63
|
+
env: NodeEnvVar[];
|
|
64
|
+
mounts: NodeHostMount[];
|
|
65
|
+
/** A `filelog` receiver reads a host directory, whose files are root-owned. */
|
|
66
|
+
readsLogs: boolean;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** The part of a collector config this reads; both the built config and a parsed ConfigMap value fit. */
|
|
70
|
+
export interface NodeReadingConfig {
|
|
71
|
+
receivers?: Record<string, unknown>;
|
|
72
|
+
processors?: Record<string, unknown>;
|
|
73
|
+
service?: { pipelines?: Record<string, unknown> } | unknown;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function isRecord(v: unknown): v is Record<string, unknown> {
|
|
77
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function typeOf(id: string): string {
|
|
81
|
+
const slash = id.indexOf("/");
|
|
82
|
+
return slash === -1 ? id : id.slice(0, slash);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Component ids of one kind that some pipeline runs. */
|
|
86
|
+
function runningIds(config: NodeReadingConfig, kind: "receivers" | "processors"): Set<string> {
|
|
87
|
+
const ids = new Set<string>();
|
|
88
|
+
const pipelines = isRecord(config.service) && isRecord(config.service.pipelines) ? config.service.pipelines : {};
|
|
89
|
+
for (const p of Object.values(pipelines)) {
|
|
90
|
+
const list = isRecord(p) ? p[kind] : undefined;
|
|
91
|
+
if (Array.isArray(list)) for (const id of list) if (typeof id === "string") ids.add(id);
|
|
92
|
+
}
|
|
93
|
+
return ids;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** [id, settings] of each running component of `type`. */
|
|
97
|
+
function running(config: NodeReadingConfig, kind: "receivers" | "processors", type: string): Array<[string, Record<string, unknown>]> {
|
|
98
|
+
const ids = runningIds(config, kind);
|
|
99
|
+
const section = isRecord(config[kind]) ? (config[kind] as Record<string, unknown>) : {};
|
|
100
|
+
return Object.entries(section)
|
|
101
|
+
.filter(([id]) => ids.has(id) && typeOf(id) === type)
|
|
102
|
+
.map(([id, cfg]) => [id, isRecord(cfg) ? cfg : {}]);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** The variables a string reads as `${env:NAME}`. */
|
|
106
|
+
function envRefs(value: unknown): string[] {
|
|
107
|
+
if (typeof value !== "string") return [];
|
|
108
|
+
return [...value.matchAll(/\$\{env:([A-Za-z_][A-Za-z0-9_]*)\}/g)].map((m) => m[1]);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** The directory part of a glob before its first wildcard: `/var/log/pods/*\/x.log` is `/var/log/pods`. */
|
|
112
|
+
export function fixedDirectory(pattern: string): string | undefined {
|
|
113
|
+
if (!pattern.startsWith("/")) return undefined;
|
|
114
|
+
const parts = pattern.split("/");
|
|
115
|
+
const fixed: string[] = [];
|
|
116
|
+
for (const part of parts) {
|
|
117
|
+
if (/[*?[{]/.test(part)) break;
|
|
118
|
+
fixed.push(part);
|
|
119
|
+
}
|
|
120
|
+
// No wildcard at all: a file, so its directory.
|
|
121
|
+
if (fixed.length === parts.length) fixed.pop();
|
|
122
|
+
const dir = fixed.join("/").replace(/\/+$/, "");
|
|
123
|
+
return dir === "" ? undefined : dir;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function within(path: string, dir: string): boolean {
|
|
127
|
+
return path === dir || path.startsWith(`${dir}/`);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function volumeName(prefix: string, path: string): string {
|
|
131
|
+
const slug = path.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
132
|
+
return `${prefix}-${slug}`.slice(0, 63).replace(/-+$/, "");
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* What a collector config needs from the node. `configDir` is where the
|
|
137
|
+
* collector's own config is mounted; a log directory covering it is skipped.
|
|
138
|
+
*/
|
|
139
|
+
export function collectorNodeAccess(config: NodeReadingConfig, configDir = "/etc/otel"): CollectorNodeAccess {
|
|
140
|
+
const env = new Map<string, NodeEnvVar["valueFrom"]["fieldRef"]["fieldPath"]>();
|
|
141
|
+
const setEnv = (name: string, fieldPath: NodeEnvVar["valueFrom"]["fieldRef"]["fieldPath"]) => {
|
|
142
|
+
if (!env.has(name)) env.set(name, fieldPath);
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
for (const [, p] of running(config, "processors", "k8sattributes")) {
|
|
146
|
+
const name = isRecord(p.filter) ? p.filter.node_from_env_var : undefined;
|
|
147
|
+
if (typeof name === "string" && /^[A-Za-z_][A-Za-z0-9_]*$/.test(name)) setEnv(name, "spec.nodeName");
|
|
148
|
+
}
|
|
149
|
+
for (const [, r] of running(config, "receivers", "kubeletstats")) {
|
|
150
|
+
for (const name of envRefs(r.node)) setEnv(name, "spec.nodeName");
|
|
151
|
+
for (const name of envRefs(r.endpoint)) {
|
|
152
|
+
if (/(NODE|HOST)_IP$/.test(name)) setEnv(name, "status.hostIP");
|
|
153
|
+
else if (/NODE_NAME$/.test(name)) setEnv(name, "spec.nodeName");
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const mounts: NodeHostMount[] = [];
|
|
158
|
+
const rootPaths = new Set<string>();
|
|
159
|
+
for (const [id, r] of running(config, "receivers", "hostmetrics")) {
|
|
160
|
+
const root = typeof r.root_path === "string" ? r.root_path.replace(/\/+$/, "") : "";
|
|
161
|
+
if (!root.startsWith("/") || rootPaths.has(root)) continue;
|
|
162
|
+
rootPaths.add(root);
|
|
163
|
+
mounts.push({
|
|
164
|
+
name: rootPaths.size === 1 ? "hostfs" : volumeName("hostfs", root),
|
|
165
|
+
hostPath: "/",
|
|
166
|
+
mountPath: root,
|
|
167
|
+
component: id,
|
|
168
|
+
partial: true,
|
|
169
|
+
mountPropagation: "HostToContainer",
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const logDirs: Array<{ dir: string; component: string }> = [];
|
|
174
|
+
for (const [id, r] of running(config, "receivers", "filelog")) {
|
|
175
|
+
const include = Array.isArray(r.include) ? r.include : [];
|
|
176
|
+
for (const pattern of include) {
|
|
177
|
+
if (typeof pattern !== "string") continue;
|
|
178
|
+
const dir = fixedDirectory(pattern);
|
|
179
|
+
if (!dir || within(configDir, dir)) continue;
|
|
180
|
+
logDirs.push({ dir, component: id });
|
|
181
|
+
if (within(dir, "/var/log/containers")) logDirs.push({ dir: "/var/log/pods", component: id });
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
// One mount per directory, the outermost of nested ones.
|
|
185
|
+
const kept = logDirs.filter(({ dir }, i) =>
|
|
186
|
+
!logDirs.some((o, j) => (o.dir !== dir && within(dir, o.dir)) || (o.dir === dir && j < i)),
|
|
187
|
+
);
|
|
188
|
+
for (const { dir, component } of kept) {
|
|
189
|
+
if ([...rootPaths].some((root) => within(dir, root))) continue;
|
|
190
|
+
mounts.push({ name: volumeName("host", dir), hostPath: dir, mountPath: dir, component });
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return {
|
|
194
|
+
env: [...env].map(([name, fieldPath]) => ({ name, valueFrom: { fieldRef: { fieldPath } } })),
|
|
195
|
+
mounts,
|
|
196
|
+
readsLogs: kept.length > 0,
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** The pod volumes for a set of mounts. */
|
|
201
|
+
export function nodeVolumes(mounts: NodeHostMount[]): Array<Record<string, unknown>> {
|
|
202
|
+
return mounts.map((m) => ({ name: m.name, hostPath: { path: m.hostPath } }));
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/** The container volume mounts for a set of mounts, all read-only. */
|
|
206
|
+
export function nodeVolumeMounts(mounts: NodeHostMount[]): Array<Record<string, unknown>> {
|
|
207
|
+
return mounts.map((m) => ({
|
|
208
|
+
name: m.name,
|
|
209
|
+
mountPath: m.mountPath,
|
|
210
|
+
readOnly: true,
|
|
211
|
+
...(m.mountPropagation ? { mountPropagation: m.mountPropagation } : {}),
|
|
212
|
+
}));
|
|
213
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
|
+
import { DebugExporter, KubeletStatsReceiver, OtlpReceiver, Pipeline, type CollectorConfig } from "@intentius/chant-lexicon-otel";
|
|
3
|
+
import { agentClusterRules, namespacedRoles } from "./otel-collector-rbac";
|
|
4
|
+
import { OtelCollector } from "./otel-collector";
|
|
5
|
+
import { GkeOtelCollector } from "./gke-otel-collector";
|
|
6
|
+
|
|
7
|
+
const READ = ["get", "list", "watch"];
|
|
8
|
+
const BASE = [
|
|
9
|
+
{ apiGroups: [""], resources: ["pods", "namespaces", "nodes"], verbs: READ },
|
|
10
|
+
{ apiGroups: ["apps"], resources: ["replicasets"], verbs: READ },
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
function cfg(c: Partial<CollectorConfig>): CollectorConfig {
|
|
14
|
+
return { service: { pipelines: {} }, ...c } as CollectorConfig;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
describe("agentClusterRules", () => {
|
|
18
|
+
test("an OTLP-only config gets k8sattributes' rules and nothing else", () => {
|
|
19
|
+
expect(agentClusterRules(cfg({ receivers: { otlp: {} } }))).toEqual(BASE);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test("k8sattributes extracting from a deployment adds deployments", () => {
|
|
23
|
+
const rules = agentClusterRules(
|
|
24
|
+
cfg({ processors: { "k8sattributes/x": { extract: { labels: [{ key: "team", from: "deployment" }] } } } as any }),
|
|
25
|
+
);
|
|
26
|
+
expect(rules[1]).toEqual({ apiGroups: ["apps"], resources: ["replicasets", "deployments"], verbs: READ });
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test("kubeletstats gets nodes/stats", () => {
|
|
30
|
+
expect(agentClusterRules(cfg({ receivers: { kubeletstats: { auth_type: "serviceAccount" } } as any }))).toEqual([
|
|
31
|
+
...BASE,
|
|
32
|
+
{ apiGroups: [""], resources: ["nodes/stats"], verbs: ["get"] },
|
|
33
|
+
]);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test.each([
|
|
37
|
+
[{ extra_metadata_labels: ["container.id"] }],
|
|
38
|
+
[{ metrics: { "k8s.pod.cpu_limit_utilization": { enabled: true } } }],
|
|
39
|
+
[{ metrics: { "k8s.container.memory_request_utilization": { enabled: true } } }],
|
|
40
|
+
])("kubeletstats needing the kubelet's /pods gets nodes/proxy (%o)", (extra) => {
|
|
41
|
+
const rules = agentClusterRules(cfg({ receivers: { "kubeletstats/node": { auth_type: "serviceAccount", ...extra } } as any }));
|
|
42
|
+
expect(rules[2]).toEqual({ apiGroups: [""], resources: ["nodes/stats", "nodes/proxy"], verbs: ["get"] });
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test("a disabled utilization metric does not add nodes/proxy", () => {
|
|
46
|
+
const rules = agentClusterRules(
|
|
47
|
+
cfg({ receivers: { kubeletstats: { metrics: { "k8s.pod.cpu_limit_utilization": { enabled: false } } } } as any }),
|
|
48
|
+
);
|
|
49
|
+
expect(rules[2].resources).toEqual(["nodes/stats"]);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test("kubeletstats with k8s_api_config reads persistent volumes and claims", () => {
|
|
53
|
+
const rules = agentClusterRules(cfg({ receivers: { kubeletstats: { k8s_api_config: { auth_type: "serviceAccount" } } } as any }));
|
|
54
|
+
expect(rules.at(-1)).toEqual({ apiGroups: [""], resources: ["persistentvolumeclaims", "persistentvolumes"], verbs: ["get"] });
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe("the agent ClusterRole", () => {
|
|
59
|
+
const rulesOf = (r: { clusterRole: unknown }) => (r.clusterRole as { props: { rules: unknown } }).props.rules;
|
|
60
|
+
|
|
61
|
+
test("OtelCollector and GkeOtelCollector grant k8sattributes' rules by default", () => {
|
|
62
|
+
expect(rulesOf(OtelCollector({}))).toEqual(BASE);
|
|
63
|
+
expect(rulesOf(GkeOtelCollector({ clusterName: "c", projectId: "p" }))).toEqual(BASE);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test("an OtelCollector config with kubeletstats gets its rules", () => {
|
|
67
|
+
const kubelet = new KubeletStatsReceiver({ auth_type: "serviceAccount", extra_metadata_labels: ["container.id"] });
|
|
68
|
+
const otlp = new OtlpReceiver({ protocols: { grpc: { endpoint: "0.0.0.0:4317" } } });
|
|
69
|
+
const debug = new DebugExporter({});
|
|
70
|
+
const agent = OtelCollector({ config: [new Pipeline({ signal: "metrics", receivers: [otlp, kubelet], exporters: [debug] })] });
|
|
71
|
+
expect(rulesOf(agent)).toEqual([...BASE, { apiGroups: [""], resources: ["nodes/stats", "nodes/proxy"], verbs: ["get"] }]);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test("defaults.clusterRole.rules are appended", () => {
|
|
75
|
+
const extra = { apiGroups: [""], resources: ["services"], verbs: READ };
|
|
76
|
+
expect(rulesOf(OtelCollector({ defaults: { clusterRole: { rules: [extra] } } }))).toEqual([...BASE, extra]);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
describe("namespacedRoles", () => {
|
|
81
|
+
const base = {
|
|
82
|
+
key: "endpoints",
|
|
83
|
+
name: "agent-endpoints",
|
|
84
|
+
rules: [{ apiGroups: [""], resources: ["endpoints"], verbs: READ }],
|
|
85
|
+
labels: { app: "x" },
|
|
86
|
+
serviceAccount: { name: "agent-sa", namespace: "agents" },
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
test("no namespaces, no members", () => {
|
|
90
|
+
expect(namespacedRoles({ ...base, namespaces: [] })).toEqual({});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test("the first namespace keeps the plain member names, the rest are suffixed", () => {
|
|
94
|
+
expect(Object.keys(namespacedRoles({ ...base, namespaces: ["obs", "team-a", "b2"] }))).toEqual([
|
|
95
|
+
"endpointsRole",
|
|
96
|
+
"endpointsRoleBinding",
|
|
97
|
+
"endpointsRoleInTeamA",
|
|
98
|
+
"endpointsRoleBindingInTeamA",
|
|
99
|
+
"endpointsRoleInB2",
|
|
100
|
+
"endpointsRoleBindingInB2",
|
|
101
|
+
]);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test("namespaces that give the same member name are refused", () => {
|
|
105
|
+
expect(() => namespacedRoles({ ...base, namespaces: ["obs", "a-b", "a--b"] })).toThrow(/a-b and a--b/);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test("defaults apply to each Role", () => {
|
|
109
|
+
const out = namespacedRoles({ ...base, namespaces: ["one", "two"], roleDefaults: { metadata: { annotations: { x: "y" } } } });
|
|
110
|
+
for (const key of ["endpointsRole", "endpointsRoleInTwo"]) {
|
|
111
|
+
expect((out[key] as any).props.metadata.annotations).toEqual({ x: "y" });
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
});
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The RBAC the collector composites grant, worked out from the collector
|
|
3
|
+
* config they deploy.
|
|
4
|
+
*
|
|
5
|
+
* `agentClusterRules` is the ClusterRole `OtelCollector` and
|
|
6
|
+
* `GkeOtelCollector` share: what the `k8sattributes` processor needs, plus
|
|
7
|
+
* what the config's Kubernetes receivers need. Each rule cites the
|
|
8
|
+
* component's RBAC requirements at collector-contrib v0.130.0, the version the
|
|
9
|
+
* otel lexicon pins.
|
|
10
|
+
*
|
|
11
|
+
* `namespacedRoles` builds one Role and RoleBinding per namespace, for access
|
|
12
|
+
* a collector needs in namespaces other than its own: Endpoints for a
|
|
13
|
+
* `loadbalancing` exporter's `k8s` resolver, Leases for a
|
|
14
|
+
* `k8s_leader_elector` extension.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { mergeDefaults } from "@intentius/chant";
|
|
18
|
+
import type { CollectorConfig } from "@intentius/chant-lexicon-otel";
|
|
19
|
+
import { Role, RoleBinding } from "../generated";
|
|
20
|
+
|
|
21
|
+
/** One RBAC rule, as a Role or ClusterRole lists it. */
|
|
22
|
+
export interface CollectorPolicyRule {
|
|
23
|
+
apiGroups: string[];
|
|
24
|
+
resources: string[];
|
|
25
|
+
verbs: string[];
|
|
26
|
+
resourceNames?: string[];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const READ = ["get", "list", "watch"];
|
|
30
|
+
|
|
31
|
+
function componentsOfType(section: Record<string, unknown> | undefined, type: string): Array<Record<string, unknown>> {
|
|
32
|
+
return Object.entries(section ?? {})
|
|
33
|
+
.filter(([id]) => id === type || id.startsWith(`${type}/`))
|
|
34
|
+
.map(([, cfg]) => (cfg && typeof cfg === "object" ? (cfg as Record<string, unknown>) : {}));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The agent ClusterRole's rules for a collector config.
|
|
39
|
+
*
|
|
40
|
+
* Always, for `k8sattributes` (processor/k8sattributesprocessor README,
|
|
41
|
+
* "Cluster-scoped RBAC"): `get`, `list` and `watch` on pods, namespaces and
|
|
42
|
+
* nodes, and on `apps` replicasets for `k8s.deployment.name`, which is
|
|
43
|
+
* extracted by default. The processor lists ReplicaSets through `apps/v1`
|
|
44
|
+
* only, so the README's `extensions` group is left out. When a
|
|
45
|
+
* `k8sattributes` processor extracts labels or annotations `from: deployment`,
|
|
46
|
+
* `apps` deployments are added.
|
|
47
|
+
*
|
|
48
|
+
* For each `kubeletstats` receiver (receiver/kubeletstatsreceiver README,
|
|
49
|
+
* "Role-based access control"): `get` on `nodes/stats`; `get` on
|
|
50
|
+
* `nodes/proxy` when it sets `extra_metadata_labels` or enables a
|
|
51
|
+
* `*_request_utilization` or `*_limit_utilization` metric; and, when it sets
|
|
52
|
+
* `k8s_api_config`, `get` on persistentvolumeclaims and persistentvolumes,
|
|
53
|
+
* which it reads for volume metadata (scraper.go).
|
|
54
|
+
*
|
|
55
|
+
* Other components that read the Kubernetes API, such as `k8s_cluster`
|
|
56
|
+
* (which belongs on a gateway, see WK8603), add their rules through
|
|
57
|
+
* `defaults.clusterRole.rules`, which are appended.
|
|
58
|
+
*/
|
|
59
|
+
export function agentClusterRules(config: CollectorConfig): CollectorPolicyRule[] {
|
|
60
|
+
const apps = ["replicasets"];
|
|
61
|
+
const k8sattributes = componentsOfType(config.processors as Record<string, unknown> | undefined, "k8sattributes");
|
|
62
|
+
const fromDeployment = k8sattributes.some((p) => {
|
|
63
|
+
const extract = p.extract as { labels?: Array<{ from?: string }>; annotations?: Array<{ from?: string }> } | undefined;
|
|
64
|
+
return [...(extract?.labels ?? []), ...(extract?.annotations ?? [])].some((f) => f?.from === "deployment");
|
|
65
|
+
});
|
|
66
|
+
if (fromDeployment) apps.push("deployments");
|
|
67
|
+
|
|
68
|
+
const rules: CollectorPolicyRule[] = [
|
|
69
|
+
{ apiGroups: [""], resources: ["pods", "namespaces", "nodes"], verbs: READ },
|
|
70
|
+
{ apiGroups: ["apps"], resources: apps, verbs: READ },
|
|
71
|
+
];
|
|
72
|
+
|
|
73
|
+
const kubeletstats = componentsOfType(config.receivers as Record<string, unknown> | undefined, "kubeletstats");
|
|
74
|
+
if (kubeletstats.length) {
|
|
75
|
+
const nodeSubresources = ["nodes/stats"];
|
|
76
|
+
const needsProxy = kubeletstats.some((r) => {
|
|
77
|
+
const labels = r.extra_metadata_labels;
|
|
78
|
+
if (Array.isArray(labels) && labels.length) return true;
|
|
79
|
+
const metrics = (r.metrics ?? {}) as Record<string, { enabled?: boolean } | undefined>;
|
|
80
|
+
return Object.entries(metrics).some(([metric, toggle]) => /_(request|limit)_utilization$/.test(metric) && toggle?.enabled === true);
|
|
81
|
+
});
|
|
82
|
+
if (needsProxy) nodeSubresources.push("nodes/proxy");
|
|
83
|
+
rules.push({ apiGroups: [""], resources: nodeSubresources, verbs: ["get"] });
|
|
84
|
+
if (kubeletstats.some((r) => r.k8s_api_config)) {
|
|
85
|
+
rules.push({ apiGroups: [""], resources: ["persistentvolumeclaims", "persistentvolumes"], verbs: ["get"] });
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return rules;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function pascal(namespace: string): string {
|
|
93
|
+
return namespace
|
|
94
|
+
.split(/[^a-zA-Z0-9]+/)
|
|
95
|
+
.filter(Boolean)
|
|
96
|
+
.map((part) => part[0].toUpperCase() + part.slice(1))
|
|
97
|
+
.join("");
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export interface NamespacedRolesOptions {
|
|
101
|
+
/** Prefix of the member names: `<key>Role` and `<key>RoleBinding`. */
|
|
102
|
+
key: string;
|
|
103
|
+
/** Name of each Role and RoleBinding. They live in different namespaces, so one name serves all. */
|
|
104
|
+
name: string;
|
|
105
|
+
/** Namespaces to grant in, in declaration order. */
|
|
106
|
+
namespaces: string[];
|
|
107
|
+
rules: CollectorPolicyRule[];
|
|
108
|
+
labels: Record<string, string>;
|
|
109
|
+
/** The ServiceAccount every RoleBinding binds. */
|
|
110
|
+
serviceAccount: { name: string; namespace: string };
|
|
111
|
+
/** Defaults laid over each Role and each RoleBinding. */
|
|
112
|
+
roleDefaults?: Partial<Record<string, unknown>>;
|
|
113
|
+
roleBindingDefaults?: Partial<Record<string, unknown>>;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* One Role and RoleBinding per namespace, as composite members. The first
|
|
118
|
+
* namespace's are `<key>Role` and `<key>RoleBinding`, so a single-namespace
|
|
119
|
+
* config keeps the member names it had before; each further namespace's are
|
|
120
|
+
* `<key>RoleIn<Namespace>` and `<key>RoleBindingIn<Namespace>`, with the
|
|
121
|
+
* namespace in PascalCase (`team-a` gives `endpointsRoleInTeamA`).
|
|
122
|
+
*/
|
|
123
|
+
export function namespacedRoles(opts: NamespacedRolesOptions): Record<string, InstanceType<typeof Role> | InstanceType<typeof RoleBinding>> {
|
|
124
|
+
const out: Record<string, InstanceType<typeof Role> | InstanceType<typeof RoleBinding>> = {};
|
|
125
|
+
const seen = new Map<string, string>();
|
|
126
|
+
opts.namespaces.forEach((namespace, i) => {
|
|
127
|
+
const suffix = i === 0 ? "" : `In${pascal(namespace)}`;
|
|
128
|
+
const clash = seen.get(suffix);
|
|
129
|
+
if (clash !== undefined) {
|
|
130
|
+
throw new Error(`${opts.name}: namespaces ${clash} and ${namespace} give the same member name ${opts.key}Role${suffix}`);
|
|
131
|
+
}
|
|
132
|
+
seen.set(suffix, namespace);
|
|
133
|
+
out[`${opts.key}Role${suffix}`] = new Role(mergeDefaults({
|
|
134
|
+
metadata: { name: opts.name, namespace, labels: opts.labels },
|
|
135
|
+
rules: opts.rules,
|
|
136
|
+
}, opts.roleDefaults));
|
|
137
|
+
out[`${opts.key}RoleBinding${suffix}`] = new RoleBinding(mergeDefaults({
|
|
138
|
+
metadata: { name: opts.name, namespace, labels: opts.labels },
|
|
139
|
+
roleRef: { apiGroup: "rbac.authorization.k8s.io", kind: "Role", name: opts.name },
|
|
140
|
+
subjects: [{ kind: "ServiceAccount", name: opts.serviceAccount.name, namespace: opts.serviceAccount.namespace }],
|
|
141
|
+
}, opts.roleBindingDefaults));
|
|
142
|
+
});
|
|
143
|
+
return out;
|
|
144
|
+
}
|
|
@@ -139,3 +139,22 @@ export function k8sResolverNamespaces(built: BuiltCollector, ownNamespace: strin
|
|
|
139
139
|
}
|
|
140
140
|
return out;
|
|
141
141
|
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* The namespaces of the Leases a config's `k8s_leader_elector` extensions
|
|
145
|
+
* take, for those `service.extensions` enables (the collector starts no
|
|
146
|
+
* other). An elector without `lease_namespace` fails the otel lexicon's
|
|
147
|
+
* OTEL107 and is skipped here.
|
|
148
|
+
*/
|
|
149
|
+
export function leaderElectorLeaseNamespaces(built: BuiltCollector): string[] {
|
|
150
|
+
const out: string[] = [];
|
|
151
|
+
const enabled = built.config.service?.extensions ?? [];
|
|
152
|
+
for (const [id, cfg] of Object.entries(built.config.extensions ?? {})) {
|
|
153
|
+
if (id !== "k8s_leader_elector" && !id.startsWith("k8s_leader_elector/")) continue;
|
|
154
|
+
if (!enabled.includes(id)) continue;
|
|
155
|
+
const ns = (cfg as { lease_namespace?: unknown } | null)?.lease_namespace;
|
|
156
|
+
if (typeof ns !== "string" || ns === "") continue;
|
|
157
|
+
if (!out.includes(ns)) out.push(ns);
|
|
158
|
+
}
|
|
159
|
+
return out;
|
|
160
|
+
}
|
|
@@ -23,7 +23,9 @@ import {
|
|
|
23
23
|
type Signal,
|
|
24
24
|
} from "@intentius/chant-lexicon-otel";
|
|
25
25
|
import { Service, Role, RoleBinding } from "../generated";
|
|
26
|
-
import { collectorAgentResources, type CollectorAgentResources } from "./otel-collector-agent";
|
|
26
|
+
import { collectorAgentResources, type CollectorAgentResources, type CollectorLogAccess } from "./otel-collector-agent";
|
|
27
|
+
import { collectorNodeAccess } from "./otel-collector-node";
|
|
28
|
+
import { agentClusterRules, namespacedRoles } from "./otel-collector-rbac";
|
|
27
29
|
import {
|
|
28
30
|
collectorRuntime,
|
|
29
31
|
gatewaysAnnotation,
|
|
@@ -51,6 +53,14 @@ export interface OtelCollectorProps {
|
|
|
51
53
|
signals?: Signal[];
|
|
52
54
|
/** Additional labels. */
|
|
53
55
|
labels?: Record<string, string>;
|
|
56
|
+
/**
|
|
57
|
+
* How a config with a `filelog` receiver reads the node's container logs,
|
|
58
|
+
* which are root's: `group` (default) keeps user 10001 and adds the pod to
|
|
59
|
+
* group 0, enough where the runtime writes them group-readable
|
|
60
|
+
* (containerd); `root` runs the container as user 0. Ignored when the
|
|
61
|
+
* config reads no logs from the node.
|
|
62
|
+
*/
|
|
63
|
+
logAccess?: CollectorLogAccess;
|
|
54
64
|
/** CPU request (default: "100m"). */
|
|
55
65
|
cpuRequest?: string;
|
|
56
66
|
/** Memory request (default: "256Mi"). */
|
|
@@ -74,9 +84,15 @@ export interface OtelCollectorProps {
|
|
|
74
84
|
|
|
75
85
|
export type OtelCollectorResult = CollectorAgentResources & {
|
|
76
86
|
service: InstanceType<typeof Service>;
|
|
77
|
-
/**
|
|
87
|
+
/**
|
|
88
|
+
* Read access to Endpoints for a `loadbalancing` exporter's `k8s` resolver,
|
|
89
|
+
* in the first namespace the resolvers point at. Each further namespace
|
|
90
|
+
* gets `endpointsRoleIn<Namespace>` and `endpointsRoleBindingIn<Namespace>`.
|
|
91
|
+
*/
|
|
78
92
|
endpointsRole?: InstanceType<typeof Role>;
|
|
79
93
|
endpointsRoleBinding?: InstanceType<typeof RoleBinding>;
|
|
94
|
+
[member: `endpointsRoleIn${string}`]: InstanceType<typeof Role>;
|
|
95
|
+
[member: `endpointsRoleBindingIn${string}`]: InstanceType<typeof RoleBinding>;
|
|
80
96
|
};
|
|
81
97
|
|
|
82
98
|
/**
|
|
@@ -99,6 +115,7 @@ export const OtelCollector = Composite((props: OtelCollectorProps) => {
|
|
|
99
115
|
namespace = "observability",
|
|
100
116
|
image = COLLECTOR_IMAGE,
|
|
101
117
|
labels: extraLabels = {},
|
|
118
|
+
logAccess = "group",
|
|
102
119
|
cpuRequest = "100m",
|
|
103
120
|
memoryRequest = "256Mi",
|
|
104
121
|
cpuLimit = "500m",
|
|
@@ -131,6 +148,11 @@ export const OtelCollector = Composite((props: OtelCollectorProps) => {
|
|
|
131
148
|
configYaml: runtime.configYaml,
|
|
132
149
|
configDir: runtime.configDir,
|
|
133
150
|
ports: runtime.containerPorts,
|
|
151
|
+
clusterRules: agentClusterRules(runtime.built.config),
|
|
152
|
+
// The node name, host mounts and log access the config's node-reading
|
|
153
|
+
// components need (#3103); nothing for a config that reads no node.
|
|
154
|
+
nodeAccess: collectorNodeAccess(runtime.built.config, runtime.configDir),
|
|
155
|
+
logAccess,
|
|
134
156
|
cpuRequest,
|
|
135
157
|
memoryRequest,
|
|
136
158
|
cpuLimit,
|
|
@@ -165,39 +187,22 @@ export const OtelCollector = Composite((props: OtelCollectorProps) => {
|
|
|
165
187
|
// The loadbalancing exporter's k8s resolver runs in this agent and watches
|
|
166
188
|
// the gateway's headless Service, so the agent's ServiceAccount gets read
|
|
167
189
|
// access to Endpoints (what the resolver watches at the pinned collector
|
|
168
|
-
// version) and EndpointSlices (what later versions watch)
|
|
169
|
-
|
|
170
|
-
if (resolverNamespaces.length > 1) {
|
|
171
|
-
throw new Error(
|
|
172
|
-
`OtelCollector ${name}: loadbalancing exporters resolve Services in ${resolverNamespaces.join(" and ")}; ` +
|
|
173
|
-
`one agent can watch Endpoints in one namespace. Use one gateway namespace, or grant the rest through defaults.clusterRole`,
|
|
174
|
-
);
|
|
175
|
-
}
|
|
190
|
+
// version) and EndpointSlices (what later versions watch), with one Role
|
|
191
|
+
// and RoleBinding in each namespace the resolvers point at.
|
|
176
192
|
const saName = (resources.serviceAccount as unknown as { props: { metadata: { name: string } } }).props.metadata.name;
|
|
177
|
-
const endpointsRbac =
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
endpointsRoleBinding: new RoleBinding(mergeDefaults({
|
|
191
|
-
metadata: {
|
|
192
|
-
name: `${name}-endpoints`,
|
|
193
|
-
namespace: resolverNamespaces[0],
|
|
194
|
-
labels: { ...commonLabels, "app.kubernetes.io/component": "rbac" },
|
|
195
|
-
},
|
|
196
|
-
roleRef: { apiGroup: "rbac.authorization.k8s.io", kind: "Role", name: `${name}-endpoints` },
|
|
197
|
-
subjects: [{ kind: "ServiceAccount", name: saName, namespace }],
|
|
198
|
-
}, defs?.endpointsRoleBinding)),
|
|
199
|
-
}
|
|
200
|
-
: {};
|
|
193
|
+
const endpointsRbac = namespacedRoles({
|
|
194
|
+
key: "endpoints",
|
|
195
|
+
name: `${name}-endpoints`,
|
|
196
|
+
namespaces: k8sResolverNamespaces(runtime.built, namespace),
|
|
197
|
+
rules: [
|
|
198
|
+
{ apiGroups: [""], resources: ["endpoints"], verbs: ["get", "list", "watch"] },
|
|
199
|
+
{ apiGroups: ["discovery.k8s.io"], resources: ["endpointslices"], verbs: ["get", "list", "watch"] },
|
|
200
|
+
],
|
|
201
|
+
labels: { ...commonLabels, "app.kubernetes.io/component": "rbac" },
|
|
202
|
+
serviceAccount: { name: saName, namespace },
|
|
203
|
+
roleDefaults: defs?.endpointsRole,
|
|
204
|
+
roleBindingDefaults: defs?.endpointsRoleBinding,
|
|
205
|
+
});
|
|
201
206
|
|
|
202
|
-
return { ...resources, service, ...endpointsRbac };
|
|
207
|
+
return { ...resources, service, ...endpointsRbac } as OtelCollectorResult;
|
|
203
208
|
}, "OtelCollector");
|
package/src/crd/crd-sources.ts
CHANGED
|
@@ -276,6 +276,8 @@ const FLUX_OPERATOR_INSTALL = `https://github.com/controlplaneio-fluxcd/flux-ope
|
|
|
276
276
|
*/
|
|
277
277
|
const KUBEMICROVM_CHART = "oci://ghcr.io/codriverlabs/helm/kube-microvm-operator";
|
|
278
278
|
const KUBEMICROVM_VERSION = "1.0.11";
|
|
279
|
+
// The chart layer of 1.0.11 on ghcr.io, so a re-pushed tag cannot change generated output.
|
|
280
|
+
const KUBEMICROVM_CHART_DIGEST = "sha256:b15570736277f69bc69bc6bd1d6b89470404b8bbd45970b7dcb29ca9ab69170c";
|
|
279
281
|
|
|
280
282
|
/**
|
|
281
283
|
* k3s bundled-controller CRDs — helm.cattle.io/v1 + k3s.cattle.io/v1
|
|
@@ -477,6 +479,26 @@ const ACK_IAM_CRD_BASE = `https://raw.githubusercontent.com/aws-controllers-k8s/
|
|
|
477
479
|
const ACK_EKS_VERSION = "v1.20.0";
|
|
478
480
|
const ACK_EKS_CRD_BASE = `https://raw.githubusercontent.com/aws-controllers-k8s/eks-controller/${ACK_EKS_VERSION}/config/crd/bases`;
|
|
479
481
|
|
|
482
|
+
/**
|
|
483
|
+
* Grafana Operator CRDs — grafana.integreatly.org/v1beta1
|
|
484
|
+
*
|
|
485
|
+
* The delivery path for a Grafana the Grafana Operator runs, used by
|
|
486
|
+
* `GrafanaOperatorResources` in `@intentius/chant-lexicon-grafana/k8s`
|
|
487
|
+
* (#3015). Produces (the `grafana.integreatly.org` group maps to the
|
|
488
|
+
* `Grafana` namespace via the first-segment rule):
|
|
489
|
+
* K8s::Grafana::GrafanaDashboard → grafana.integreatly.org/v1beta1, kind: GrafanaDashboard
|
|
490
|
+
* K8s::Grafana::GrafanaDatasource → grafana.integreatly.org/v1beta1, kind: GrafanaDatasource
|
|
491
|
+
* K8s::Grafana::GrafanaFolder → grafana.integreatly.org/v1beta1, kind: GrafanaFolder
|
|
492
|
+
*
|
|
493
|
+
* The operator's other kinds (Grafana itself, alerting, library panels,
|
|
494
|
+
* service accounts, manifests) are left out until something uses them.
|
|
495
|
+
*
|
|
496
|
+
* Operator install: kubectl apply --server-side -f
|
|
497
|
+
* https://github.com/grafana/grafana-operator/releases/download/v5.25.0/kustomize-cluster_scoped.yaml
|
|
498
|
+
*/
|
|
499
|
+
const GRAFANA_OPERATOR_VERSION = "v5.25.0";
|
|
500
|
+
const GRAFANA_OPERATOR_CRD_BASE = `https://raw.githubusercontent.com/grafana/grafana-operator/${GRAFANA_OPERATOR_VERSION}/config/crd/bases`;
|
|
501
|
+
|
|
480
502
|
export const CRD_SOURCES: CRDSource[] = [
|
|
481
503
|
{ type: "url", url: `${KUBERAY_CRD_BASE}/ray.io_rayclusters.yaml` },
|
|
482
504
|
{ type: "url", url: `${KUBERAY_CRD_BASE}/ray.io_rayjobs.yaml` },
|
|
@@ -542,6 +564,7 @@ export const CRD_SOURCES: CRDSource[] = [
|
|
|
542
564
|
type: "helm",
|
|
543
565
|
chart: KUBEMICROVM_CHART,
|
|
544
566
|
version: KUBEMICROVM_VERSION,
|
|
567
|
+
digest: KUBEMICROVM_CHART_DIGEST,
|
|
545
568
|
kinds: ["MicroVM", "MicroVMImage", "MicroVMNetwork", "MicroVMClass", "MicroVMReplicaSet"],
|
|
546
569
|
},
|
|
547
570
|
{ type: "url", url: `${KSERVE_CRD_BASE}/serving.kserve.io_inferenceservices.yaml` },
|
|
@@ -561,4 +584,7 @@ export const CRD_SOURCES: CRDSource[] = [
|
|
|
561
584
|
{ type: "url", url: `${ACK_IAM_CRD_BASE}/iam.services.k8s.aws_users.yaml` },
|
|
562
585
|
{ type: "url", url: `${ACK_IAM_CRD_BASE}/iam.services.k8s.aws_policies.yaml` },
|
|
563
586
|
{ type: "url", url: `${ACK_EKS_CRD_BASE}/eks.services.k8s.aws_podidentityassociations.yaml` },
|
|
587
|
+
{ type: "url", url: `${GRAFANA_OPERATOR_CRD_BASE}/grafana.integreatly.org_grafanadashboards.yaml` },
|
|
588
|
+
{ type: "url", url: `${GRAFANA_OPERATOR_CRD_BASE}/grafana.integreatly.org_grafanadatasources.yaml` },
|
|
589
|
+
{ type: "url", url: `${GRAFANA_OPERATOR_CRD_BASE}/grafana.integreatly.org_grafanafolders.yaml` },
|
|
564
590
|
];
|