@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
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
import type { Declarable } from "@intentius/chant/declarable";
|
|
15
15
|
import {
|
|
16
16
|
buildCollectorConfig,
|
|
17
|
+
canonicalTypeOf,
|
|
17
18
|
collectorEndpoints,
|
|
18
19
|
collectorYaml,
|
|
19
20
|
COLLECTOR_CONFIG_PATH,
|
|
@@ -79,9 +80,9 @@ export interface CollectorRuntime {
|
|
|
79
80
|
built: BuiltCollector;
|
|
80
81
|
configYaml: string;
|
|
81
82
|
configDir: string;
|
|
82
|
-
containerPorts: Array<{ containerPort: number; name: string }>;
|
|
83
|
-
/** The receiver ports, which the Services expose. The health port is left out. */
|
|
84
|
-
servicePorts: Array<{ name: string; port: number }>;
|
|
83
|
+
containerPorts: Array<{ containerPort: number; name: string; protocol?: "UDP" }>;
|
|
84
|
+
/** The receiver and exporter ports, which the Services expose. The health port is left out. */
|
|
85
|
+
servicePorts: Array<{ name: string; port: number; protocol?: "UDP" }>;
|
|
85
86
|
/** Security context and, when the config enables `health_check`, the probes. */
|
|
86
87
|
containerExtra: Record<string, unknown>;
|
|
87
88
|
}
|
|
@@ -93,11 +94,11 @@ export function collectorRuntime(entities: Declarable[]): CollectorRuntime {
|
|
|
93
94
|
|
|
94
95
|
// The probe names the port. A health_check on a receiver's port reuses that
|
|
95
96
|
// port's name, since a container port is declared once.
|
|
96
|
-
const healthPortName = healthCheck ? (ports.find((p) => p.port === healthCheck.port)?.name ?? "health") : undefined;
|
|
97
|
+
const healthPortName = healthCheck ? (ports.find((p) => p.port === healthCheck.port && !p.protocol)?.name ?? "health") : undefined;
|
|
97
98
|
const probe = healthCheck ? { httpGet: { path: healthCheck.path, port: healthPortName } } : undefined;
|
|
98
99
|
const containerPorts = [
|
|
99
|
-
...ports.map((p) => ({ containerPort: p.port, name: p.name })),
|
|
100
|
-
...(healthCheck && !ports.some((p) => p.port === healthCheck.port)
|
|
100
|
+
...ports.map((p) => ({ containerPort: p.port, name: p.name, ...(p.protocol ? { protocol: p.protocol } : {}) })),
|
|
101
|
+
...(healthCheck && !ports.some((p) => p.port === healthCheck.port && !p.protocol)
|
|
101
102
|
? [{ containerPort: healthCheck.port, name: "health" }]
|
|
102
103
|
: []),
|
|
103
104
|
];
|
|
@@ -107,7 +108,7 @@ export function collectorRuntime(entities: Declarable[]): CollectorRuntime {
|
|
|
107
108
|
configYaml: collectorYaml(entities),
|
|
108
109
|
configDir,
|
|
109
110
|
containerPorts,
|
|
110
|
-
servicePorts: ports.map((p) => ({ name: p.name, port: p.port })),
|
|
111
|
+
servicePorts: ports.map((p) => ({ name: p.name, port: p.port, ...(p.protocol ? { protocol: p.protocol } : {}) })),
|
|
111
112
|
containerExtra: {
|
|
112
113
|
imagePullPolicy: "IfNotPresent",
|
|
113
114
|
securityContext: {
|
|
@@ -130,7 +131,7 @@ export function collectorRuntime(entities: Declarable[]): CollectorRuntime {
|
|
|
130
131
|
export function k8sResolverNamespaces(built: BuiltCollector, ownNamespace: string): string[] {
|
|
131
132
|
const out: string[] = [];
|
|
132
133
|
for (const [id, cfg] of Object.entries(built.config.exporters ?? {})) {
|
|
133
|
-
if (id !== "loadbalancing"
|
|
134
|
+
if (canonicalTypeOf("exporter", id) !== "loadbalancing") continue;
|
|
134
135
|
const service = (cfg as { resolver?: { k8s?: { service?: string } } })?.resolver?.k8s?.service;
|
|
135
136
|
if (!service) continue;
|
|
136
137
|
const dot = service.indexOf(".");
|
|
@@ -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,
|
|
@@ -166,7 +180,7 @@ export const OtelCollector = Composite((props: OtelCollectorProps) => {
|
|
|
166
180
|
spec: {
|
|
167
181
|
selector: { "app.kubernetes.io/name": name },
|
|
168
182
|
internalTrafficPolicy: "Local",
|
|
169
|
-
ports: runtime.servicePorts.map((p) => ({ name: p.name, port: p.port, targetPort: p.name, protocol: "TCP" })),
|
|
183
|
+
ports: runtime.servicePorts.map((p) => ({ name: p.name, port: p.port, targetPort: p.name, protocol: p.protocol ?? "TCP" })),
|
|
170
184
|
},
|
|
171
185
|
}, defs?.service));
|
|
172
186
|
|
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,27 @@ 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
|
+
* K8s::Grafana::GrafanaLibraryPanel → grafana.integreatly.org/v1beta1, kind: GrafanaLibraryPanel
|
|
493
|
+
*
|
|
494
|
+
* The operator's other kinds (Grafana itself, alerting, service accounts,
|
|
495
|
+
* manifests) are left out until something uses them.
|
|
496
|
+
*
|
|
497
|
+
* Operator install: kubectl apply --server-side -f
|
|
498
|
+
* https://github.com/grafana/grafana-operator/releases/download/v5.25.0/kustomize-cluster_scoped.yaml
|
|
499
|
+
*/
|
|
500
|
+
const GRAFANA_OPERATOR_VERSION = "v5.25.0";
|
|
501
|
+
const GRAFANA_OPERATOR_CRD_BASE = `https://raw.githubusercontent.com/grafana/grafana-operator/${GRAFANA_OPERATOR_VERSION}/config/crd/bases`;
|
|
502
|
+
|
|
480
503
|
export const CRD_SOURCES: CRDSource[] = [
|
|
481
504
|
{ type: "url", url: `${KUBERAY_CRD_BASE}/ray.io_rayclusters.yaml` },
|
|
482
505
|
{ type: "url", url: `${KUBERAY_CRD_BASE}/ray.io_rayjobs.yaml` },
|
|
@@ -542,6 +565,7 @@ export const CRD_SOURCES: CRDSource[] = [
|
|
|
542
565
|
type: "helm",
|
|
543
566
|
chart: KUBEMICROVM_CHART,
|
|
544
567
|
version: KUBEMICROVM_VERSION,
|
|
568
|
+
digest: KUBEMICROVM_CHART_DIGEST,
|
|
545
569
|
kinds: ["MicroVM", "MicroVMImage", "MicroVMNetwork", "MicroVMClass", "MicroVMReplicaSet"],
|
|
546
570
|
},
|
|
547
571
|
{ type: "url", url: `${KSERVE_CRD_BASE}/serving.kserve.io_inferenceservices.yaml` },
|
|
@@ -561,4 +585,8 @@ export const CRD_SOURCES: CRDSource[] = [
|
|
|
561
585
|
{ type: "url", url: `${ACK_IAM_CRD_BASE}/iam.services.k8s.aws_users.yaml` },
|
|
562
586
|
{ type: "url", url: `${ACK_IAM_CRD_BASE}/iam.services.k8s.aws_policies.yaml` },
|
|
563
587
|
{ type: "url", url: `${ACK_EKS_CRD_BASE}/eks.services.k8s.aws_podidentityassociations.yaml` },
|
|
588
|
+
{ type: "url", url: `${GRAFANA_OPERATOR_CRD_BASE}/grafana.integreatly.org_grafanadashboards.yaml` },
|
|
589
|
+
{ type: "url", url: `${GRAFANA_OPERATOR_CRD_BASE}/grafana.integreatly.org_grafanadatasources.yaml` },
|
|
590
|
+
{ type: "url", url: `${GRAFANA_OPERATOR_CRD_BASE}/grafana.integreatly.org_grafanafolders.yaml` },
|
|
591
|
+
{ type: "url", url: `${GRAFANA_OPERATOR_CRD_BASE}/grafana.integreatly.org_grafanalibrarypanels.yaml` },
|
|
564
592
|
];
|
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
|
+
});
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pull a Helm chart out of an OCI registry over plain HTTP, and read its files.
|
|
3
|
+
*
|
|
4
|
+
* Generation used to shell out to `helm pull` for these. A machine without
|
|
5
|
+
* helm on PATH (a fresh CI runner, a container) then dropped the chart's kinds
|
|
6
|
+
* with only a warning, and the generated surface depended on which tools the
|
|
7
|
+
* host happened to have. The registry API is three requests, and a chart is a
|
|
8
|
+
* small gzipped tarball, so neither needs the binary.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { createHash } from "crypto";
|
|
12
|
+
import { gunzipSync } from "zlib";
|
|
13
|
+
import { fetchWithRetry } from "@intentius/chant/codegen/fetch";
|
|
14
|
+
|
|
15
|
+
/** The layer media type Helm pushes a chart's content under. */
|
|
16
|
+
export const HELM_CHART_LAYER = "application/vnd.cncf.helm.chart.content.v1.tar+gzip";
|
|
17
|
+
|
|
18
|
+
const MANIFEST_ACCEPT = [
|
|
19
|
+
"application/vnd.oci.image.manifest.v1+json",
|
|
20
|
+
"application/vnd.docker.distribution.manifest.v2+json",
|
|
21
|
+
].join(", ");
|
|
22
|
+
|
|
23
|
+
type Fetch = (url: string, init?: RequestInit) => Promise<Response>;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The two kinds of request a pull makes. `probe` must return a 401 as a
|
|
27
|
+
* response (the registry's auth challenge); `get` throws on any failure and
|
|
28
|
+
* retries transient ones.
|
|
29
|
+
*/
|
|
30
|
+
export interface OciHttp {
|
|
31
|
+
probe: Fetch;
|
|
32
|
+
get: Fetch;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const defaultHttp: OciHttp = {
|
|
36
|
+
probe: (url, init) => fetch(url, init),
|
|
37
|
+
get: (url, init) => fetchWithRetry(url, undefined, undefined, init),
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export interface OciChartRef {
|
|
41
|
+
/** Registry host, e.g. "ghcr.io". */
|
|
42
|
+
host: string;
|
|
43
|
+
/** Repository path inside the registry, e.g. "codriverlabs/helm/kube-microvm-operator". */
|
|
44
|
+
repository: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Split an `oci://host/repo/path` chart reference. */
|
|
48
|
+
export function parseOciRef(chart: string): OciChartRef {
|
|
49
|
+
const m = /^oci:\/\/([^/]+)\/(.+)$/.exec(chart);
|
|
50
|
+
if (!m) throw new Error(`not an oci:// chart reference: ${chart}`);
|
|
51
|
+
return { host: m[1], repository: m[2].replace(/\/+$/, "") };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Get an anonymous pull token, following the registry's own challenge
|
|
56
|
+
* (`WWW-Authenticate: Bearer realm=...,service=...`). Returns undefined when
|
|
57
|
+
* the registry does not ask for one.
|
|
58
|
+
*/
|
|
59
|
+
async function anonymousToken(ref: OciChartRef, http: OciHttp): Promise<string | undefined> {
|
|
60
|
+
const probe = await http.probe(`https://${ref.host}/v2/`);
|
|
61
|
+
if (probe.status !== 401) return undefined;
|
|
62
|
+
const challenge = probe.headers.get("www-authenticate") ?? "";
|
|
63
|
+
const params = Object.fromEntries(
|
|
64
|
+
[...challenge.matchAll(/(\w+)="([^"]*)"/g)].map((m) => [m[1], m[2]]),
|
|
65
|
+
);
|
|
66
|
+
if (!/^bearer/i.test(challenge) || !params.realm) {
|
|
67
|
+
throw new Error(`registry ${ref.host} asks for auth this loader does not speak: ${challenge || "(no challenge)"}`);
|
|
68
|
+
}
|
|
69
|
+
const url = new URL(params.realm);
|
|
70
|
+
if (params.service) url.searchParams.set("service", params.service);
|
|
71
|
+
url.searchParams.set("scope", `repository:${ref.repository}:pull`);
|
|
72
|
+
const res = await http.get(url.toString());
|
|
73
|
+
const body = (await res.json()) as { token?: string; access_token?: string };
|
|
74
|
+
const token = body.token ?? body.access_token;
|
|
75
|
+
if (!token) throw new Error(`registry ${ref.host} returned no token for ${ref.repository}`);
|
|
76
|
+
return token;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Download a chart's content layer (the .tgz `helm pull` would fetch).
|
|
81
|
+
*
|
|
82
|
+
* @param digest When given ("sha256:..."), the layer must have this digest.
|
|
83
|
+
* Pinning it makes the source content-addressed: a re-pushed
|
|
84
|
+
* tag fails loudly instead of changing generated output.
|
|
85
|
+
*/
|
|
86
|
+
export async function pullOciChart(
|
|
87
|
+
chart: string,
|
|
88
|
+
version: string,
|
|
89
|
+
digest?: string,
|
|
90
|
+
http: OciHttp = defaultHttp,
|
|
91
|
+
): Promise<Buffer> {
|
|
92
|
+
const ref = parseOciRef(chart);
|
|
93
|
+
const token = await anonymousToken(ref, http);
|
|
94
|
+
const auth: Record<string, string> = token ? { Authorization: `Bearer ${token}` } : {};
|
|
95
|
+
const base = `https://${ref.host}/v2/${ref.repository}`;
|
|
96
|
+
|
|
97
|
+
const manifestRes = await http.get(`${base}/manifests/${version}`, {
|
|
98
|
+
headers: { ...auth, Accept: MANIFEST_ACCEPT },
|
|
99
|
+
});
|
|
100
|
+
const manifest = (await manifestRes.json()) as { layers?: Array<{ mediaType: string; digest: string }> };
|
|
101
|
+
const layer = manifest.layers?.find((l) => l.mediaType === HELM_CHART_LAYER);
|
|
102
|
+
if (!layer) {
|
|
103
|
+
throw new Error(`${chart}:${version} has no layer of type ${HELM_CHART_LAYER}; is it a Helm chart?`);
|
|
104
|
+
}
|
|
105
|
+
if (digest && layer.digest !== digest) {
|
|
106
|
+
throw new Error(
|
|
107
|
+
`${chart}:${version} chart layer is ${layer.digest}, but the source pins ${digest}. ` +
|
|
108
|
+
"The tag was re-pushed; review the new chart and update the pin.",
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const blobRes = await http.get(`${base}/blobs/${layer.digest}`, { headers: auth });
|
|
113
|
+
const blob = Buffer.from(await blobRes.arrayBuffer());
|
|
114
|
+
const actual = `sha256:${createHash("sha256").update(blob).digest("hex")}`;
|
|
115
|
+
if (actual !== layer.digest) {
|
|
116
|
+
throw new Error(`${chart}:${version} chart layer downloaded as ${actual}, expected ${layer.digest}`);
|
|
117
|
+
}
|
|
118
|
+
return blob;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Read the regular files out of a gzipped tarball, as path to content.
|
|
123
|
+
* Handles ustar, plus the pax (`x`) and GNU (`L`) long-name records Helm's
|
|
124
|
+
* Go archiver may write.
|
|
125
|
+
*/
|
|
126
|
+
export function readTarGz(tgz: Buffer): Map<string, Buffer> {
|
|
127
|
+
const tar = gunzipSync(tgz);
|
|
128
|
+
const files = new Map<string, Buffer>();
|
|
129
|
+
let offset = 0;
|
|
130
|
+
let longName: string | undefined;
|
|
131
|
+
|
|
132
|
+
const field = (start: number, len: number): string => {
|
|
133
|
+
const raw = tar.subarray(offset + start, offset + start + len);
|
|
134
|
+
const nul = raw.indexOf(0);
|
|
135
|
+
return raw.subarray(0, nul === -1 ? raw.length : nul).toString("utf8");
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
while (offset + 512 <= tar.length) {
|
|
139
|
+
// Two zero blocks end the archive; one is enough to stop reading.
|
|
140
|
+
if (tar.subarray(offset, offset + 512).every((b) => b === 0)) break;
|
|
141
|
+
|
|
142
|
+
const size = parseInt(field(124, 12).trim() || "0", 8);
|
|
143
|
+
const type = field(156, 1) || "0";
|
|
144
|
+
const prefix = field(345, 155);
|
|
145
|
+
const name = longName ?? (prefix ? `${prefix}/${field(0, 100)}` : field(0, 100));
|
|
146
|
+
const data = tar.subarray(offset + 512, offset + 512 + size);
|
|
147
|
+
longName = undefined;
|
|
148
|
+
|
|
149
|
+
if (type === "x") {
|
|
150
|
+
const path = /(?:^|\n)\d+ path=([^\n]*)\n/.exec(data.toString("utf8"));
|
|
151
|
+
if (path) longName = path[1];
|
|
152
|
+
} else if (type === "L") {
|
|
153
|
+
longName = data.toString("utf8").replace(/\0+$/, "");
|
|
154
|
+
} else if (type === "0" || type === "\0") {
|
|
155
|
+
files.set(name, Buffer.from(data));
|
|
156
|
+
}
|
|
157
|
+
offset += 512 + Math.ceil(size / 512) * 512;
|
|
158
|
+
}
|
|
159
|
+
return files;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* The YAML files directly inside `<chart dir>/<subdir>/`, sorted by path so
|
|
164
|
+
* the concatenation does not depend on archive order.
|
|
165
|
+
*/
|
|
166
|
+
export function chartYamlFiles(files: Map<string, Buffer>, subdir: string): Array<[string, string]> {
|
|
167
|
+
const dir = subdir.replace(/^\/+|\/+$/g, "");
|
|
168
|
+
return [...files.entries()]
|
|
169
|
+
.filter(([path]) => {
|
|
170
|
+
// Strip the single top-level chart directory, whatever it is named.
|
|
171
|
+
const rest = path.split("/").slice(1).join("/");
|
|
172
|
+
if (!rest.startsWith(`${dir}/`)) return false;
|
|
173
|
+
const leaf = rest.slice(dir.length + 1);
|
|
174
|
+
return !leaf.includes("/") && (leaf.endsWith(".yaml") || leaf.endsWith(".yml"));
|
|
175
|
+
})
|
|
176
|
+
.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
|
|
177
|
+
.map(([path, buf]) => [path, buf.toString("utf8")]);
|
|
178
|
+
}
|
package/src/crd/types.ts
CHANGED
|
@@ -28,6 +28,11 @@ export interface CRDSource {
|
|
|
28
28
|
chart?: string;
|
|
29
29
|
/** Chart version for type="helm". Required: an unpinned source is not auditable. */
|
|
30
30
|
version?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Digest of an `oci://` chart's content layer ("sha256:..."). Optional; when
|
|
33
|
+
* set, a re-pushed tag fails generation instead of changing its output.
|
|
34
|
+
*/
|
|
35
|
+
digest?: string;
|
|
31
36
|
/**
|
|
32
37
|
* Directory inside the chart holding the CRDs. Defaults to Helm's own
|
|
33
38
|
* convention, "crds". Charts that instead template their CRDs need this
|