@intentius/chant-lexicon-k8s 0.101.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 +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-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 +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/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 +6 -5
- 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/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 +4 -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/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/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-node.test.ts +174 -0
- package/src/composites/otel-collector-node.ts +213 -0
- package/src/composites/otel-collector.ts +15 -1
- 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 +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/post-synth.test.ts +3 -3
- 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
|
+
}
|
|
@@ -23,7 +23,8 @@ 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";
|
|
27
28
|
import { agentClusterRules, namespacedRoles } from "./otel-collector-rbac";
|
|
28
29
|
import {
|
|
29
30
|
collectorRuntime,
|
|
@@ -52,6 +53,14 @@ export interface OtelCollectorProps {
|
|
|
52
53
|
signals?: Signal[];
|
|
53
54
|
/** Additional labels. */
|
|
54
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;
|
|
55
64
|
/** CPU request (default: "100m"). */
|
|
56
65
|
cpuRequest?: string;
|
|
57
66
|
/** Memory request (default: "256Mi"). */
|
|
@@ -106,6 +115,7 @@ export const OtelCollector = Composite((props: OtelCollectorProps) => {
|
|
|
106
115
|
namespace = "observability",
|
|
107
116
|
image = COLLECTOR_IMAGE,
|
|
108
117
|
labels: extraLabels = {},
|
|
118
|
+
logAccess = "group",
|
|
109
119
|
cpuRequest = "100m",
|
|
110
120
|
memoryRequest = "256Mi",
|
|
111
121
|
cpuLimit = "500m",
|
|
@@ -139,6 +149,10 @@ export const OtelCollector = Composite((props: OtelCollectorProps) => {
|
|
|
139
149
|
configDir: runtime.configDir,
|
|
140
150
|
ports: runtime.containerPorts,
|
|
141
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,
|
|
142
156
|
cpuRequest,
|
|
143
157
|
memoryRequest,
|
|
144
158
|
cpuLimit,
|
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
|
];
|
package/src/crd/loader.test.ts
CHANGED
|
@@ -76,7 +76,15 @@ describe("helm CRD source", () => {
|
|
|
76
76
|
|
|
77
77
|
test("says what to do when helm is missing or the pull fails", async () => {
|
|
78
78
|
await expect(
|
|
79
|
-
loadCRDs({ type: "helm", chart: "
|
|
79
|
+
loadCRDs({ type: "helm", chart: "https://example.invalid/charts/nope", version: "0.0.1" }),
|
|
80
80
|
).rejects.toThrow(/helm (pull failed|not found on PATH)/);
|
|
81
81
|
});
|
|
82
|
+
|
|
83
|
+
// An oci:// chart is pulled over HTTP, so a missing helm cannot change what
|
|
84
|
+
// generation produces; a failed pull names the chart instead.
|
|
85
|
+
test("an oci:// chart does not go through helm", async () => {
|
|
86
|
+
await expect(
|
|
87
|
+
loadCRDs({ type: "helm", chart: "oci://example.invalid/nope", version: "0.0.1" }),
|
|
88
|
+
).rejects.toThrow(/could not pull chart oci:\/\/example\.invalid\/nope 0\.0\.1/);
|
|
89
|
+
});
|
|
82
90
|
});
|
package/src/crd/loader.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { fetchWithRetry } from "@intentius/chant/codegen/fetch";
|
|
|
10
10
|
import type { CRDSource, CRDSpec } from "./types";
|
|
11
11
|
import type { K8sParseResult } from "../spec/parse";
|
|
12
12
|
import { parseCRD } from "./parser";
|
|
13
|
+
import { chartYamlFiles, pullOciChart, readTarGz } from "./oci-chart";
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* Load CRDs from a source and return parsed K8sParseResult entries.
|
|
@@ -93,8 +94,11 @@ async function loadFromURL(source: CRDSource): Promise<string> {
|
|
|
93
94
|
* unchanged — a chart carrying more CRDs than a consumer wants is the same
|
|
94
95
|
* situation as Flux's install bundle.
|
|
95
96
|
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
97
|
+
* An `oci://` chart is pulled over the registry's HTTP API and unpacked in
|
|
98
|
+
* process, so generation does not depend on `helm` being on PATH. Before,
|
|
99
|
+
* a host without helm dropped the chart's kinds with only a warning and the
|
|
100
|
+
* generated surface changed with the machine. Only a classic `https://` chart
|
|
101
|
+
* repository still shells out to `helm pull`.
|
|
98
102
|
*/
|
|
99
103
|
async function loadFromHelmChart(source: CRDSource): Promise<string> {
|
|
100
104
|
if (!source.chart) {
|
|
@@ -107,6 +111,26 @@ async function loadFromHelmChart(source: CRDSource): Promise<string> {
|
|
|
107
111
|
);
|
|
108
112
|
}
|
|
109
113
|
|
|
114
|
+
const subdir = source.chartSubdir ?? "crds";
|
|
115
|
+
|
|
116
|
+
if (source.chart.startsWith("oci://")) {
|
|
117
|
+
let tgz: Buffer;
|
|
118
|
+
try {
|
|
119
|
+
tgz = await pullOciChart(source.chart, source.version, source.digest);
|
|
120
|
+
} catch (err) {
|
|
121
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
122
|
+
throw new Error(`could not pull chart ${source.chart} ${source.version}: ${msg}`);
|
|
123
|
+
}
|
|
124
|
+
const files = chartYamlFiles(readTarGz(tgz), subdir);
|
|
125
|
+
if (files.length === 0) {
|
|
126
|
+
throw new Error(
|
|
127
|
+
`chart ${source.chart} ${source.version} has no CRD YAML in '${subdir}'. ` +
|
|
128
|
+
"Charts that template their CRDs instead of shipping them in crds/ need 'chartSubdir'.",
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
return files.map(([, text]) => text).join("\n---\n");
|
|
132
|
+
}
|
|
133
|
+
|
|
110
134
|
const { execFile } = await import("child_process");
|
|
111
135
|
const { promisify } = await import("util");
|
|
112
136
|
const { mkdtempSync, rmSync, readdirSync, readFileSync: read } = await import("fs");
|
|
@@ -142,7 +166,6 @@ async function loadFromHelmChart(source: CRDSource): Promise<string> {
|
|
|
142
166
|
);
|
|
143
167
|
}
|
|
144
168
|
|
|
145
|
-
const subdir = source.chartSubdir ?? "crds";
|
|
146
169
|
const crdDir = join(workdir, unpacked[0].name, subdir);
|
|
147
170
|
|
|
148
171
|
let entries: string[];
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { describe, test, expect } from "vitest";
|
|
2
|
+
import { createHash } from "crypto";
|
|
3
|
+
import { gzipSync } from "zlib";
|
|
4
|
+
import {
|
|
5
|
+
HELM_CHART_LAYER,
|
|
6
|
+
chartYamlFiles,
|
|
7
|
+
parseOciRef,
|
|
8
|
+
pullOciChart,
|
|
9
|
+
readTarGz,
|
|
10
|
+
type OciHttp,
|
|
11
|
+
} from "./oci-chart";
|
|
12
|
+
|
|
13
|
+
/** A minimal ustar writer, enough to stand in for a Helm chart archive. */
|
|
14
|
+
function tarGz(entries: Array<{ name: string; body: string; type?: string }>): Buffer {
|
|
15
|
+
const blocks: Buffer[] = [];
|
|
16
|
+
for (const { name, body, type = "0" } of entries) {
|
|
17
|
+
const data = Buffer.from(body, "utf8");
|
|
18
|
+
const header = Buffer.alloc(512);
|
|
19
|
+
header.write(name.slice(0, 100), 0, "utf8");
|
|
20
|
+
header.write("0000644\0", 100);
|
|
21
|
+
header.write("0000000\0", 108);
|
|
22
|
+
header.write("0000000\0", 116);
|
|
23
|
+
header.write(data.length.toString(8).padStart(11, "0") + "\0", 124);
|
|
24
|
+
header.write("00000000000\0", 136);
|
|
25
|
+
header.write(" ", 148);
|
|
26
|
+
header.write(type, 156);
|
|
27
|
+
header.write("ustar\0", 257);
|
|
28
|
+
header.write("00", 263);
|
|
29
|
+
let sum = 0;
|
|
30
|
+
for (const b of header) sum += b;
|
|
31
|
+
header.write(sum.toString(8).padStart(6, "0") + "\0 ", 148);
|
|
32
|
+
blocks.push(header, data, Buffer.alloc((512 - (data.length % 512)) % 512));
|
|
33
|
+
}
|
|
34
|
+
blocks.push(Buffer.alloc(1024));
|
|
35
|
+
return gzipSync(Buffer.concat(blocks));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const CHART = tarGz([
|
|
39
|
+
{ name: "op/Chart.yaml", body: "name: op\n" },
|
|
40
|
+
{ name: "op/templates/deployment.yaml", body: "kind: Deployment\n" },
|
|
41
|
+
{ name: "op/crds/b.yml", body: "kind: B\n" },
|
|
42
|
+
{ name: "op/crds/a.yaml", body: "kind: A\n" },
|
|
43
|
+
{ name: "op/crds/README.md", body: "not yaml\n" },
|
|
44
|
+
{ name: "op/crds/nested/c.yaml", body: "kind: C\n" },
|
|
45
|
+
]);
|
|
46
|
+
|
|
47
|
+
describe("readTarGz / chartYamlFiles", () => {
|
|
48
|
+
test("reads regular files and keeps only YAML directly in the subdir, sorted", () => {
|
|
49
|
+
const files = readTarGz(CHART);
|
|
50
|
+
expect(files.get("op/Chart.yaml")?.toString()).toBe("name: op\n");
|
|
51
|
+
expect(chartYamlFiles(files, "crds")).toEqual([
|
|
52
|
+
["op/crds/a.yaml", "kind: A\n"],
|
|
53
|
+
["op/crds/b.yml", "kind: B\n"],
|
|
54
|
+
]);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test("follows a GNU long-name record", () => {
|
|
58
|
+
const long = `op/crds/${"x".repeat(120)}.yaml`;
|
|
59
|
+
const files = readTarGz(
|
|
60
|
+
tarGz([
|
|
61
|
+
{ name: "././@LongLink", body: long + "\0", type: "L" },
|
|
62
|
+
{ name: "truncated", body: "kind: Long\n" },
|
|
63
|
+
]),
|
|
64
|
+
);
|
|
65
|
+
expect(files.get(long)?.toString()).toBe("kind: Long\n");
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test("follows a pax path record", () => {
|
|
69
|
+
const long = `op/crds/${"y".repeat(120)}.yaml`;
|
|
70
|
+
const record = `path=${long}\n`;
|
|
71
|
+
const len = String(record.length + 4).length + 1 + record.length;
|
|
72
|
+
const files = readTarGz(
|
|
73
|
+
tarGz([
|
|
74
|
+
{ name: "PaxHeader", body: `${len} ${record}`, type: "x" },
|
|
75
|
+
{ name: "truncated", body: "kind: Pax\n" },
|
|
76
|
+
]),
|
|
77
|
+
);
|
|
78
|
+
expect(files.get(long)?.toString()).toBe("kind: Pax\n");
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
describe("parseOciRef", () => {
|
|
83
|
+
test("splits host and repository", () => {
|
|
84
|
+
expect(parseOciRef("oci://ghcr.io/org/helm/op")).toEqual({ host: "ghcr.io", repository: "org/helm/op" });
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test("rejects a non-oci reference", () => {
|
|
88
|
+
expect(() => parseOciRef("https://charts.example.com/op")).toThrow(/not an oci:\/\//);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
describe("pullOciChart", () => {
|
|
93
|
+
const digest = `sha256:${createHash("sha256").update(CHART).digest("hex")}`;
|
|
94
|
+
|
|
95
|
+
/** A registry that challenges, hands out a token, and serves one chart. */
|
|
96
|
+
function registry(layerDigest = digest, blob = CHART): { http: OciHttp; seen: string[] } {
|
|
97
|
+
const seen: string[] = [];
|
|
98
|
+
const json = (body: unknown) => new Response(JSON.stringify(body), { status: 200 });
|
|
99
|
+
const http: OciHttp = {
|
|
100
|
+
probe: async (url) => {
|
|
101
|
+
seen.push(url);
|
|
102
|
+
return new Response("", {
|
|
103
|
+
status: 401,
|
|
104
|
+
headers: { "www-authenticate": 'Bearer realm="https://reg.test/token",service="reg.test"' },
|
|
105
|
+
});
|
|
106
|
+
},
|
|
107
|
+
get: async (url, init) => {
|
|
108
|
+
seen.push(url);
|
|
109
|
+
if (url.startsWith("https://reg.test/token")) {
|
|
110
|
+
expect(new URL(url).searchParams.get("scope")).toBe("repository:org/op:pull");
|
|
111
|
+
return json({ token: "t0k" });
|
|
112
|
+
}
|
|
113
|
+
expect((init?.headers as Record<string, string>).Authorization).toBe("Bearer t0k");
|
|
114
|
+
if (url.endsWith("/manifests/1.2.3")) {
|
|
115
|
+
return json({ layers: [{ mediaType: HELM_CHART_LAYER, digest: layerDigest }] });
|
|
116
|
+
}
|
|
117
|
+
if (url.endsWith(`/blobs/${layerDigest}`)) return new Response(new Uint8Array(blob), { status: 200 });
|
|
118
|
+
throw new Error(`unexpected ${url}`);
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
return { http, seen };
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
test("pulls the chart layer with an anonymous token, without helm", async () => {
|
|
125
|
+
const { http, seen } = registry();
|
|
126
|
+
const blob = await pullOciChart("oci://reg.test/org/op", "1.2.3", digest, http);
|
|
127
|
+
expect(blob.equals(CHART)).toBe(true);
|
|
128
|
+
expect(seen).toEqual([
|
|
129
|
+
"https://reg.test/v2/",
|
|
130
|
+
"https://reg.test/token?service=reg.test&scope=repository%3Aorg%2Fop%3Apull",
|
|
131
|
+
"https://reg.test/v2/org/op/manifests/1.2.3",
|
|
132
|
+
`https://reg.test/v2/org/op/blobs/${digest}`,
|
|
133
|
+
]);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test("refuses a re-pushed tag whose layer no longer matches the pin", async () => {
|
|
137
|
+
const { http } = registry();
|
|
138
|
+
await expect(pullOciChart("oci://reg.test/org/op", "1.2.3", "sha256:" + "0".repeat(64), http)).rejects.toThrow(
|
|
139
|
+
/re-pushed/,
|
|
140
|
+
);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
test("refuses a blob whose bytes do not match its digest", async () => {
|
|
144
|
+
const { http } = registry(digest, gzipSync(Buffer.from("tampered")));
|
|
145
|
+
await expect(pullOciChart("oci://reg.test/org/op", "1.2.3", undefined, http)).rejects.toThrow(
|
|
146
|
+
/downloaded as sha256:/,
|
|
147
|
+
);
|
|
148
|
+
});
|
|
149
|
+
});
|