@intentius/chant-lexicon-k8s 0.124.103 → 0.124.105

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.
@@ -3,7 +3,7 @@
3
3
  * with K8s-specific fetch, parse, naming, and generation callbacks.
4
4
  */
5
5
  import { type GenerateOptions, type GenerateResult } from "@intentius/chant/codegen/generate";
6
- import { type K8sParseResult } from "../spec/parse.js";
6
+ import { type K8sParseResult, type ParsedDefinitionType } from "../spec/parse.js";
7
7
  import type { CRDSource } from "../crd/types.js";
8
8
  export type { GenerateResult };
9
9
  export interface K8sGenerateOptions extends GenerateOptions {
@@ -38,6 +38,11 @@ export declare function loadCrdSources(sources: readonly CRDSource[], log: (msg:
38
38
  * Run the full Kubernetes generation pipeline.
39
39
  */
40
40
  export declare function generate(opts?: K8sGenerateOptions): Promise<GenerateResult>;
41
+ /**
42
+ * The definition interfaces as interface name -> definition key, sorted by
43
+ * name, for the surface snapshot.
44
+ */
45
+ export declare function generateInterfacesJSON(definitionTypes: ParsedDefinitionType[]): string;
41
46
  /**
42
47
  * Write generated artifacts to disk.
43
48
  */
@@ -3,11 +3,12 @@
3
3
  * with K8s-specific fetch, parse, naming, and generation callbacks.
4
4
  */
5
5
  import { generatePipeline, writeGeneratedArtifacts, } from "@intentius/chant/codegen/generate";
6
+ import { INTERFACES_FILENAME } from "@intentius/chant/codegen/surface-snapshot";
6
7
  import { fetchSchemas } from "../spec/fetch.js";
7
8
  import { parseK8sSwaggerTypes, specListMapKeyPairs, k8sShortName, } from "../spec/parse.js";
8
9
  import { loadMultipleCRDs } from "../crd/loader.js";
9
10
  import { CRD_SOURCES } from "../crd/crd-sources.js";
10
- import { NamingStrategy, propertyTypeName, extractDefName } from "./naming.js";
11
+ import { NamingStrategy, publishedNames, publishedDefinitionNames, propertyTypeName, extractDefName } from "./naming.js";
11
12
  import { generateLexiconJSON } from "./generate-lexicon.js";
12
13
  import { generateOperationsJSON } from "./generate-operations.js";
13
14
  import { generateListMapKeysJSON } from "./generate-list-map-keys.js";
@@ -60,6 +61,13 @@ export async function generate(opts = {}) {
60
61
  let specPairs = [];
61
62
  // chant #3093 — the declaration-only interfaces, which only the `.d.ts` emits.
62
63
  let definitionTypes = [];
64
+ // #5551: a published name stays with the type that published it, so a new
65
+ // kind or CRD sharing its short name is the one prefixed. A caller-supplied
66
+ // schema set names its fixtures by the rule alone.
67
+ const reserved = opts.schemaSource ? {} : publishedNames();
68
+ // The same for the definition interfaces, which the snapshot records as
69
+ // `interface` entries.
70
+ const publishedDefinitions = opts.schemaSource ? {} : publishedDefinitionNames();
63
71
  const config = {
64
72
  fetchSchemas: async (fetchOpts) => {
65
73
  return fetchSchemas(fetchOpts.force, opts.schemaVersion);
@@ -68,7 +76,7 @@ export async function generate(opts = {}) {
68
76
  // The K8s schema is a single document — parseK8sSwaggerTypes returns multiple results.
69
77
  // The pipeline calls this once per schema entry. We return the first result
70
78
  // and use augmentResults to inject the rest.
71
- const { results, definitionTypes: defs } = parseK8sSwaggerTypes(data);
79
+ const { results, definitionTypes: defs } = parseK8sSwaggerTypes(data, { publishedDefinitions });
72
80
  definitionTypes = defs;
73
81
  specPairs = specListMapKeyPairs(data);
74
82
  if (results.length === 0)
@@ -77,7 +85,7 @@ export async function generate(opts = {}) {
77
85
  pendingResults = results.slice(1);
78
86
  return results[0];
79
87
  },
80
- createNaming: (results) => new NamingStrategy(results),
88
+ createNaming: (results) => new NamingStrategy(results, reserved),
81
89
  augmentSchemas: async (schemas, _opts, log) => {
82
90
  // Load third-party CRDs and return as extraResults so they are
83
91
  // included in the generated types alongside the core K8s resources.
@@ -112,10 +120,24 @@ export async function generate(opts = {}) {
112
120
  // chant #1441 — the spec's own associative-list keys, so drift compares
113
121
  // list elements by identity instead of by index.
114
122
  "list-map-keys.json": generateListMapKeysJSON(specPairs, results),
123
+ // The definition interface names, which the surface snapshot records so
124
+ // the next generation keeps them (#5551).
125
+ [INTERFACES_FILENAME]: generateInterfacesJSON(definitionTypes),
115
126
  }),
116
127
  };
117
128
  return generatePipeline(config, opts);
118
129
  }
130
+ /**
131
+ * The definition interfaces as interface name -> definition key, sorted by
132
+ * name, for the surface snapshot.
133
+ */
134
+ export function generateInterfacesJSON(definitionTypes) {
135
+ const names = {};
136
+ for (const dt of [...definitionTypes].sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0))) {
137
+ names[dt.name] = dt.defKey;
138
+ }
139
+ return JSON.stringify(names, null, 2) + "\n";
140
+ }
119
141
  /**
120
142
  * Write generated artifacts to disk.
121
143
  */
@@ -10,5 +10,26 @@ export { propertyTypeName, extractDefName } from "@intentius/chant/codegen/namin
10
10
  * Extends core NamingStrategy with K8s naming config.
11
11
  */
12
12
  export declare class NamingStrategy extends CoreNamingStrategy {
13
- constructor(results: K8sParseResult[]);
13
+ /**
14
+ * @param reservedNames type -> the name the lexicon already published for
15
+ * it, normally {@link publishedNames}. A published name stays with its
16
+ * type, and a new kind or CRD that shares its short name is the one
17
+ * group-prefixed (#5551). Passed in rather than read here so a test or a
18
+ * fixture-driven run names its inputs by the rule alone.
19
+ */
20
+ constructor(results: K8sParseResult[], reservedNames?: Record<string, string>);
14
21
  }
22
+ /** The committed surface snapshot beside this package's `src/`. */
23
+ export declare const SURFACE_SNAPSHOT_PATH: string;
24
+ /**
25
+ * The names the k8s lexicon has published, read from its committed surface
26
+ * snapshot: type -> name. Empty when there is no snapshot or it cannot be
27
+ * parsed.
28
+ */
29
+ export declare function publishedNames(snapshotPath?: string): Record<string, string>;
30
+ /**
31
+ * The definition interface names the k8s lexicon has published, read from the
32
+ * `interface` entries of its committed surface snapshot: definition key ->
33
+ * name. Empty when there is no snapshot or it records none.
34
+ */
35
+ export declare function publishedDefinitionNames(snapshotPath?: string): Record<string, string>;
@@ -2,7 +2,9 @@
2
2
  * Kubernetes naming strategy — maps K8s::{Group}::{Kind} type names
3
3
  * to user-friendly TypeScript class names.
4
4
  */
5
- import { NamingStrategy as CoreNamingStrategy, } from "@intentius/chant/codegen/naming";
5
+ import { dirname, join } from "node:path";
6
+ import { fileURLToPath } from "node:url";
7
+ import { NamingStrategy as CoreNamingStrategy, publishedNamingConfig, readPublishedNames, } from "@intentius/chant/codegen/naming";
6
8
  import { k8sShortName, k8sServiceName } from "../spec/parse.js";
7
9
  export { propertyTypeName, extractDefName } from "@intentius/chant/codegen/naming";
8
10
  const k8sNamingConfig = {
@@ -164,11 +166,36 @@ const k8sNamingConfig = {
164
166
  * Extends core NamingStrategy with K8s naming config.
165
167
  */
166
168
  export class NamingStrategy extends CoreNamingStrategy {
167
- constructor(results) {
169
+ /**
170
+ * @param reservedNames type -> the name the lexicon already published for
171
+ * it, normally {@link publishedNames}. A published name stays with its
172
+ * type, and a new kind or CRD that shares its short name is the one
173
+ * group-prefixed (#5551). Passed in rather than read here so a test or a
174
+ * fixture-driven run names its inputs by the rule alone.
175
+ */
176
+ constructor(results, reservedNames = {}) {
168
177
  const inputs = results.map((r) => ({
169
178
  typeName: r.resource.typeName,
170
179
  propertyTypes: r.propertyTypes,
171
180
  }));
172
- super(inputs, k8sNamingConfig);
181
+ super(inputs, publishedNamingConfig(inputs, k8sNamingConfig, reservedNames));
173
182
  }
174
183
  }
184
+ /** The committed surface snapshot beside this package's `src/`. */
185
+ export const SURFACE_SNAPSHOT_PATH = join(dirname(fileURLToPath(import.meta.url)), "..", "..", "surface.snapshot.json");
186
+ /**
187
+ * The names the k8s lexicon has published, read from its committed surface
188
+ * snapshot: type -> name. Empty when there is no snapshot or it cannot be
189
+ * parsed.
190
+ */
191
+ export function publishedNames(snapshotPath = SURFACE_SNAPSHOT_PATH) {
192
+ return readPublishedNames(snapshotPath);
193
+ }
194
+ /**
195
+ * The definition interface names the k8s lexicon has published, read from the
196
+ * `interface` entries of its committed surface snapshot: definition key ->
197
+ * name. Empty when there is no snapshot or it records none.
198
+ */
199
+ export function publishedDefinitionNames(snapshotPath = SURFACE_SNAPSHOT_PATH) {
200
+ return readPublishedNames(snapshotPath, "interface");
201
+ }
@@ -0,0 +1,283 @@
1
+ {
2
+ "APIResource": "io.k8s.apimachinery.pkg.apis.meta.v1.APIResource",
3
+ "APIServiceSpec": "io.k8s.kube-aggregator.pkg.apis.apiregistration.v1.APIServiceSpec",
4
+ "AWSElasticBlockStoreVolumeSource": "io.k8s.api.core.v1.AWSElasticBlockStoreVolumeSource",
5
+ "AdmissionregistrationServiceReference": "io.k8s.api.admissionregistration.v1.ServiceReference",
6
+ "AdmissionregistrationWebhookClientConfig": "io.k8s.api.admissionregistration.v1.WebhookClientConfig",
7
+ "AggregationRule": "io.k8s.api.rbac.v1.AggregationRule",
8
+ "ApiextensionsServiceReference": "io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.ServiceReference",
9
+ "ApiextensionsWebhookClientConfig": "io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.WebhookClientConfig",
10
+ "ApiregistrationServiceReference": "io.k8s.kube-aggregator.pkg.apis.apiregistration.v1.ServiceReference",
11
+ "AppArmorProfile": "io.k8s.api.core.v1.AppArmorProfile",
12
+ "ApplyConfiguration": "io.k8s.api.admissionregistration.v1.ApplyConfiguration",
13
+ "AuditAnnotation": "io.k8s.api.admissionregistration.v1.AuditAnnotation",
14
+ "AzureDiskVolumeSource": "io.k8s.api.core.v1.AzureDiskVolumeSource",
15
+ "AzureFilePersistentVolumeSource": "io.k8s.api.core.v1.AzureFilePersistentVolumeSource",
16
+ "AzureFileVolumeSource": "io.k8s.api.core.v1.AzureFileVolumeSource",
17
+ "BoundObjectReference": "io.k8s.api.authentication.v1.BoundObjectReference",
18
+ "CELDeviceSelector": "io.k8s.api.resource.v1.CELDeviceSelector",
19
+ "CSIDriverSpec": "io.k8s.api.storage.v1.CSIDriverSpec",
20
+ "CSINodeDriver": "io.k8s.api.storage.v1.CSINodeDriver",
21
+ "CSINodeSpec": "io.k8s.api.storage.v1.CSINodeSpec",
22
+ "CSIPersistentVolumeSource": "io.k8s.api.core.v1.CSIPersistentVolumeSource",
23
+ "CSIVolumeSource": "io.k8s.api.core.v1.CSIVolumeSource",
24
+ "CapacityRequestPolicy": "io.k8s.api.resource.v1.CapacityRequestPolicy",
25
+ "CapacityRequestPolicyRange": "io.k8s.api.resource.v1.CapacityRequestPolicyRange",
26
+ "CapacityRequirements": "io.k8s.api.resource.v1.CapacityRequirements",
27
+ "CephFSPersistentVolumeSource": "io.k8s.api.core.v1.CephFSPersistentVolumeSource",
28
+ "CephFSVolumeSource": "io.k8s.api.core.v1.CephFSVolumeSource",
29
+ "CertificateSigningRequestSpec": "io.k8s.api.certificates.v1.CertificateSigningRequestSpec",
30
+ "CinderPersistentVolumeSource": "io.k8s.api.core.v1.CinderPersistentVolumeSource",
31
+ "CinderVolumeSource": "io.k8s.api.core.v1.CinderVolumeSource",
32
+ "ClientIPConfig": "io.k8s.api.core.v1.ClientIPConfig",
33
+ "ClusterTrustBundleProjection": "io.k8s.api.core.v1.ClusterTrustBundleProjection",
34
+ "ClusterTrustBundleSpec": "io.k8s.api.certificates.v1beta1.ClusterTrustBundleSpec",
35
+ "ComponentCondition": "io.k8s.api.core.v1.ComponentCondition",
36
+ "ConfigMapEnvSource": "io.k8s.api.core.v1.ConfigMapEnvSource",
37
+ "ConfigMapNodeConfigSource": "io.k8s.api.core.v1.ConfigMapNodeConfigSource",
38
+ "ConfigMapProjection": "io.k8s.api.core.v1.ConfigMapProjection",
39
+ "ConfigMapVolumeSource": "io.k8s.api.core.v1.ConfigMapVolumeSource",
40
+ "ContainerResizePolicy": "io.k8s.api.core.v1.ContainerResizePolicy",
41
+ "ContainerResourceMetricSource": "io.k8s.api.autoscaling.v2.ContainerResourceMetricSource",
42
+ "ContainerRestartRule": "io.k8s.api.core.v1.ContainerRestartRule",
43
+ "ContainerRestartRuleOnExitCodes": "io.k8s.api.core.v1.ContainerRestartRuleOnExitCodes",
44
+ "CoreEndpointPort": "io.k8s.api.core.v1.EndpointPort",
45
+ "CoreEventSeries": "io.k8s.api.core.v1.EventSeries",
46
+ "CoreResourceClaim": "io.k8s.api.core.v1.ResourceClaim",
47
+ "Counter": "io.k8s.api.resource.v1.Counter",
48
+ "CounterSet": "io.k8s.api.resource.v1.CounterSet",
49
+ "CronJobSpec": "io.k8s.api.batch.v1.CronJobSpec",
50
+ "CrossVersionObjectReference": "io.k8s.api.autoscaling.v2.CrossVersionObjectReference",
51
+ "CustomResourceColumnDefinition": "io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.CustomResourceColumnDefinition",
52
+ "CustomResourceConversion": "io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.CustomResourceConversion",
53
+ "CustomResourceDefinitionNames": "io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.CustomResourceDefinitionNames",
54
+ "CustomResourceDefinitionSpec": "io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.CustomResourceDefinitionSpec",
55
+ "CustomResourceDefinitionVersion": "io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.CustomResourceDefinitionVersion",
56
+ "CustomResourceSubresourceScale": "io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.CustomResourceSubresourceScale",
57
+ "CustomResourceSubresources": "io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.CustomResourceSubresources",
58
+ "CustomResourceValidation": "io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.CustomResourceValidation",
59
+ "DaemonSetSpec": "io.k8s.api.apps.v1.DaemonSetSpec",
60
+ "DaemonSetUpdateStrategy": "io.k8s.api.apps.v1.DaemonSetUpdateStrategy",
61
+ "DeploymentSpec": "io.k8s.api.apps.v1.DeploymentSpec",
62
+ "Device": "io.k8s.api.resource.v1.Device",
63
+ "DeviceAttribute": "io.k8s.api.resource.v1.DeviceAttribute",
64
+ "DeviceCapacity": "io.k8s.api.resource.v1.DeviceCapacity",
65
+ "DeviceClaim": "io.k8s.api.resource.v1.DeviceClaim",
66
+ "DeviceClaimConfiguration": "io.k8s.api.resource.v1.DeviceClaimConfiguration",
67
+ "DeviceClassConfiguration": "io.k8s.api.resource.v1.DeviceClassConfiguration",
68
+ "DeviceClassSpec": "io.k8s.api.resource.v1.DeviceClassSpec",
69
+ "DeviceConstraint": "io.k8s.api.resource.v1.DeviceConstraint",
70
+ "DeviceCounterConsumption": "io.k8s.api.resource.v1.DeviceCounterConsumption",
71
+ "DeviceRequest": "io.k8s.api.resource.v1.DeviceRequest",
72
+ "DeviceSelector": "io.k8s.api.resource.v1.DeviceSelector",
73
+ "DeviceSubRequest": "io.k8s.api.resource.v1.DeviceSubRequest",
74
+ "DeviceTaintRuleSpec": "io.k8s.api.resource.v1beta2.DeviceTaintRuleSpec",
75
+ "DeviceTaintSelector": "io.k8s.api.resource.v1beta2.DeviceTaintSelector",
76
+ "DeviceToleration": "io.k8s.api.resource.v1.DeviceToleration",
77
+ "DiscoveryEndpointPort": "io.k8s.api.discovery.v1.EndpointPort",
78
+ "DownwardAPIProjection": "io.k8s.api.core.v1.DownwardAPIProjection",
79
+ "DownwardAPIVolumeFile": "io.k8s.api.core.v1.DownwardAPIVolumeFile",
80
+ "DownwardAPIVolumeSource": "io.k8s.api.core.v1.DownwardAPIVolumeSource",
81
+ "EmptyDirVolumeSource": "io.k8s.api.core.v1.EmptyDirVolumeSource",
82
+ "Endpoint": "io.k8s.api.discovery.v1.Endpoint",
83
+ "EndpointAddress": "io.k8s.api.core.v1.EndpointAddress",
84
+ "EndpointConditions": "io.k8s.api.discovery.v1.EndpointConditions",
85
+ "EndpointHints": "io.k8s.api.discovery.v1.EndpointHints",
86
+ "EndpointSubset": "io.k8s.api.core.v1.EndpointSubset",
87
+ "EphemeralVolumeSource": "io.k8s.api.core.v1.EphemeralVolumeSource",
88
+ "EventSource": "io.k8s.api.core.v1.EventSource",
89
+ "EventsEventSeries": "io.k8s.api.events.v1.EventSeries",
90
+ "ExactDeviceRequest": "io.k8s.api.resource.v1.ExactDeviceRequest",
91
+ "ExemptPriorityLevelConfiguration": "io.k8s.api.flowcontrol.v1.ExemptPriorityLevelConfiguration",
92
+ "ExternalDocumentation": "io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.ExternalDocumentation",
93
+ "ExternalMetricSource": "io.k8s.api.autoscaling.v2.ExternalMetricSource",
94
+ "FCVolumeSource": "io.k8s.api.core.v1.FCVolumeSource",
95
+ "FieldSelectorAttributes": "io.k8s.api.authorization.v1.FieldSelectorAttributes",
96
+ "FieldSelectorRequirement": "io.k8s.apimachinery.pkg.apis.meta.v1.FieldSelectorRequirement",
97
+ "FileKeySelector": "io.k8s.api.core.v1.FileKeySelector",
98
+ "FlexPersistentVolumeSource": "io.k8s.api.core.v1.FlexPersistentVolumeSource",
99
+ "FlexVolumeSource": "io.k8s.api.core.v1.FlexVolumeSource",
100
+ "FlockerVolumeSource": "io.k8s.api.core.v1.FlockerVolumeSource",
101
+ "FlowDistinguisherMethod": "io.k8s.api.flowcontrol.v1.FlowDistinguisherMethod",
102
+ "FlowSchemaSpec": "io.k8s.api.flowcontrol.v1.FlowSchemaSpec",
103
+ "FlowcontrolSubject": "io.k8s.api.flowcontrol.v1.Subject",
104
+ "ForNode": "io.k8s.api.discovery.v1.ForNode",
105
+ "ForZone": "io.k8s.api.discovery.v1.ForZone",
106
+ "GCEPersistentDiskVolumeSource": "io.k8s.api.core.v1.GCEPersistentDiskVolumeSource",
107
+ "GRPCAction": "io.k8s.api.core.v1.GRPCAction",
108
+ "GitRepoVolumeSource": "io.k8s.api.core.v1.GitRepoVolumeSource",
109
+ "GlusterfsPersistentVolumeSource": "io.k8s.api.core.v1.GlusterfsPersistentVolumeSource",
110
+ "GlusterfsVolumeSource": "io.k8s.api.core.v1.GlusterfsVolumeSource",
111
+ "GroupResource": "io.k8s.apimachinery.pkg.apis.meta.v1.GroupResource",
112
+ "GroupSubject": "io.k8s.api.flowcontrol.v1.GroupSubject",
113
+ "GroupVersionForDiscovery": "io.k8s.apimachinery.pkg.apis.meta.v1.GroupVersionForDiscovery",
114
+ "HPAScalingPolicy": "io.k8s.api.autoscaling.v2.HPAScalingPolicy",
115
+ "HPAScalingRules": "io.k8s.api.autoscaling.v2.HPAScalingRules",
116
+ "HTTPHeader": "io.k8s.api.core.v1.HTTPHeader",
117
+ "HTTPIngressRuleValue": "io.k8s.api.networking.v1.HTTPIngressRuleValue",
118
+ "HorizontalPodAutoscalerSpec": "io.k8s.api.autoscaling.v2.HorizontalPodAutoscalerSpec",
119
+ "HostPathVolumeSource": "io.k8s.api.core.v1.HostPathVolumeSource",
120
+ "IPAddressSpec": "io.k8s.api.networking.v1.IPAddressSpec",
121
+ "IPBlock": "io.k8s.api.networking.v1.IPBlock",
122
+ "ISCSIPersistentVolumeSource": "io.k8s.api.core.v1.ISCSIPersistentVolumeSource",
123
+ "ISCSIVolumeSource": "io.k8s.api.core.v1.ISCSIVolumeSource",
124
+ "ImageVolumeSource": "io.k8s.api.core.v1.ImageVolumeSource",
125
+ "IngressClassParametersReference": "io.k8s.api.networking.v1.IngressClassParametersReference",
126
+ "IngressClassSpec": "io.k8s.api.networking.v1.IngressClassSpec",
127
+ "IngressSpec": "io.k8s.api.networking.v1.IngressSpec",
128
+ "JSONPatch": "io.k8s.api.admissionregistration.v1.JSONPatch",
129
+ "JSONSchemaProps": "io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.JSONSchemaProps",
130
+ "JobSpec": "io.k8s.api.batch.v1.JobSpec",
131
+ "JobTemplateSpec": "io.k8s.api.batch.v1.JobTemplateSpec",
132
+ "LabelSelectorAttributes": "io.k8s.api.authorization.v1.LabelSelectorAttributes",
133
+ "LeaseCandidateSpec": "io.k8s.api.coordination.v1beta1.LeaseCandidateSpec",
134
+ "LeaseSpec": "io.k8s.api.coordination.v1.LeaseSpec",
135
+ "Lifecycle": "io.k8s.api.core.v1.Lifecycle",
136
+ "LifecycleHandler": "io.k8s.api.core.v1.LifecycleHandler",
137
+ "LimitRangeItem": "io.k8s.api.core.v1.LimitRangeItem",
138
+ "LimitRangeSpec": "io.k8s.api.core.v1.LimitRangeSpec",
139
+ "LimitResponse": "io.k8s.api.flowcontrol.v1.LimitResponse",
140
+ "LimitedPriorityLevelConfiguration": "io.k8s.api.flowcontrol.v1.LimitedPriorityLevelConfiguration",
141
+ "ListMeta": "io.k8s.apimachinery.pkg.apis.meta.v1.ListMeta",
142
+ "LocalVolumeSource": "io.k8s.api.core.v1.LocalVolumeSource",
143
+ "ManagedFieldsEntry": "io.k8s.apimachinery.pkg.apis.meta.v1.ManagedFieldsEntry",
144
+ "MatchCondition": "io.k8s.api.admissionregistration.v1.MatchCondition",
145
+ "MatchResources": "io.k8s.api.admissionregistration.v1.MatchResources",
146
+ "MetricIdentifier": "io.k8s.api.autoscaling.v2.MetricIdentifier",
147
+ "MetricTarget": "io.k8s.api.autoscaling.v2.MetricTarget",
148
+ "MutatingAdmissionPolicyBindingSpec": "io.k8s.api.admissionregistration.v1.MutatingAdmissionPolicyBindingSpec",
149
+ "MutatingAdmissionPolicySpec": "io.k8s.api.admissionregistration.v1.MutatingAdmissionPolicySpec",
150
+ "MutatingWebhook": "io.k8s.api.admissionregistration.v1.MutatingWebhook",
151
+ "Mutation": "io.k8s.api.admissionregistration.v1.Mutation",
152
+ "NFSVolumeSource": "io.k8s.api.core.v1.NFSVolumeSource",
153
+ "NamedRuleWithOperations": "io.k8s.api.admissionregistration.v1.NamedRuleWithOperations",
154
+ "NamespaceSpec": "io.k8s.api.core.v1.NamespaceSpec",
155
+ "NetworkPolicySpec": "io.k8s.api.networking.v1.NetworkPolicySpec",
156
+ "NodeAffinity": "io.k8s.api.core.v1.NodeAffinity",
157
+ "NodeAllocatableResourceMapping": "io.k8s.api.resource.v1.NodeAllocatableResourceMapping",
158
+ "NodeConfigSource": "io.k8s.api.core.v1.NodeConfigSource",
159
+ "NodeSelector": "io.k8s.api.core.v1.NodeSelector",
160
+ "NodeSelectorRequirement": "io.k8s.api.core.v1.NodeSelectorRequirement",
161
+ "NodeSelectorTerm": "io.k8s.api.core.v1.NodeSelectorTerm",
162
+ "NodeSpec": "io.k8s.api.core.v1.NodeSpec",
163
+ "NonResourceAttributes": "io.k8s.api.authorization.v1.NonResourceAttributes",
164
+ "NonResourcePolicyRule": "io.k8s.api.flowcontrol.v1.NonResourcePolicyRule",
165
+ "ObjectFieldSelector": "io.k8s.api.core.v1.ObjectFieldSelector",
166
+ "ObjectMetricSource": "io.k8s.api.autoscaling.v2.ObjectMetricSource",
167
+ "OpaqueDeviceConfiguration": "io.k8s.api.resource.v1.OpaqueDeviceConfiguration",
168
+ "Overhead": "io.k8s.api.node.v1.Overhead",
169
+ "OwnerReference": "io.k8s.apimachinery.pkg.apis.meta.v1.OwnerReference",
170
+ "ParamKind": "io.k8s.api.admissionregistration.v1.ParamKind",
171
+ "ParamRef": "io.k8s.api.admissionregistration.v1.ParamRef",
172
+ "ParentReference": "io.k8s.api.networking.v1.ParentReference",
173
+ "PersistentVolumeClaimTemplate": "io.k8s.api.core.v1.PersistentVolumeClaimTemplate",
174
+ "PersistentVolumeClaimVolumeSource": "io.k8s.api.core.v1.PersistentVolumeClaimVolumeSource",
175
+ "PersistentVolumeSpec": "io.k8s.api.core.v1.PersistentVolumeSpec",
176
+ "PhotonPersistentDiskVolumeSource": "io.k8s.api.core.v1.PhotonPersistentDiskVolumeSource",
177
+ "PodAffinity": "io.k8s.api.core.v1.PodAffinity",
178
+ "PodAffinityTerm": "io.k8s.api.core.v1.PodAffinityTerm",
179
+ "PodAntiAffinity": "io.k8s.api.core.v1.PodAntiAffinity",
180
+ "PodCertificateProjection": "io.k8s.api.core.v1.PodCertificateProjection",
181
+ "PodCertificateRequestSpec": "io.k8s.api.certificates.v1beta1.PodCertificateRequestSpec",
182
+ "PodDNSConfig": "io.k8s.api.core.v1.PodDNSConfig",
183
+ "PodDNSConfigOption": "io.k8s.api.core.v1.PodDNSConfigOption",
184
+ "PodFailurePolicy": "io.k8s.api.batch.v1.PodFailurePolicy",
185
+ "PodFailurePolicyOnExitCodesRequirement": "io.k8s.api.batch.v1.PodFailurePolicyOnExitCodesRequirement",
186
+ "PodFailurePolicyOnPodConditionsPattern": "io.k8s.api.batch.v1.PodFailurePolicyOnPodConditionsPattern",
187
+ "PodFailurePolicyRule": "io.k8s.api.batch.v1.PodFailurePolicyRule",
188
+ "PodOS": "io.k8s.api.core.v1.PodOS",
189
+ "PodReadinessGate": "io.k8s.api.core.v1.PodReadinessGate",
190
+ "PodResourceClaim": "io.k8s.api.core.v1.PodResourceClaim",
191
+ "PodSchedulingGate": "io.k8s.api.core.v1.PodSchedulingGate",
192
+ "PodSchedulingGroup": "io.k8s.api.core.v1.PodSchedulingGroup",
193
+ "PodsMetricSource": "io.k8s.api.autoscaling.v2.PodsMetricSource",
194
+ "PolicyRulesWithSubjects": "io.k8s.api.flowcontrol.v1.PolicyRulesWithSubjects",
195
+ "PortworxVolumeSource": "io.k8s.api.core.v1.PortworxVolumeSource",
196
+ "Preconditions": "io.k8s.apimachinery.pkg.apis.meta.v1.Preconditions",
197
+ "PreferredSchedulingTerm": "io.k8s.api.core.v1.PreferredSchedulingTerm",
198
+ "PriorityLevelConfigurationReference": "io.k8s.api.flowcontrol.v1.PriorityLevelConfigurationReference",
199
+ "PriorityLevelConfigurationSpec": "io.k8s.api.flowcontrol.v1.PriorityLevelConfigurationSpec",
200
+ "ProjectedVolumeSource": "io.k8s.api.core.v1.ProjectedVolumeSource",
201
+ "QueuingConfiguration": "io.k8s.api.flowcontrol.v1.QueuingConfiguration",
202
+ "QuobyteVolumeSource": "io.k8s.api.core.v1.QuobyteVolumeSource",
203
+ "RBDPersistentVolumeSource": "io.k8s.api.core.v1.RBDPersistentVolumeSource",
204
+ "RBDVolumeSource": "io.k8s.api.core.v1.RBDVolumeSource",
205
+ "ReplicaSetSpec": "io.k8s.api.apps.v1.ReplicaSetSpec",
206
+ "ReplicationControllerSpec": "io.k8s.api.core.v1.ReplicationControllerSpec",
207
+ "ResourceAttributes": "io.k8s.api.authorization.v1.ResourceAttributes",
208
+ "ResourceClaimSpec": "io.k8s.api.resource.v1.ResourceClaimSpec",
209
+ "ResourceClaimTemplateSpec": "io.k8s.api.resource.v1.ResourceClaimTemplateSpec",
210
+ "ResourceFieldSelector": "io.k8s.api.core.v1.ResourceFieldSelector",
211
+ "ResourceMetricSource": "io.k8s.api.autoscaling.v2.ResourceMetricSource",
212
+ "ResourcePolicyRule": "io.k8s.api.flowcontrol.v1.ResourcePolicyRule",
213
+ "ResourcePool": "io.k8s.api.resource.v1.ResourcePool",
214
+ "ResourceQuotaSpec": "io.k8s.api.core.v1.ResourceQuotaSpec",
215
+ "ResourceSliceSpec": "io.k8s.api.resource.v1.ResourceSliceSpec",
216
+ "ResourceV1DeviceTaint": "io.k8s.api.resource.v1.DeviceTaint",
217
+ "ResourceV1beta2DeviceTaint": "io.k8s.api.resource.v1beta2.DeviceTaint",
218
+ "RollingUpdateDaemonSet": "io.k8s.api.apps.v1.RollingUpdateDaemonSet",
219
+ "RollingUpdateStatefulSetStrategy": "io.k8s.api.apps.v1.RollingUpdateStatefulSetStrategy",
220
+ "RuleWithOperations": "io.k8s.api.admissionregistration.v1.RuleWithOperations",
221
+ "SELinuxOptions": "io.k8s.api.core.v1.SELinuxOptions",
222
+ "ScaleIOPersistentVolumeSource": "io.k8s.api.core.v1.ScaleIOPersistentVolumeSource",
223
+ "ScaleIOVolumeSource": "io.k8s.api.core.v1.ScaleIOVolumeSource",
224
+ "ScaleSpec": "io.k8s.api.autoscaling.v1.ScaleSpec",
225
+ "Scheduling": "io.k8s.api.node.v1.Scheduling",
226
+ "ScopeSelector": "io.k8s.api.core.v1.ScopeSelector",
227
+ "ScopedResourceSelectorRequirement": "io.k8s.api.core.v1.ScopedResourceSelectorRequirement",
228
+ "SeccompProfile": "io.k8s.api.core.v1.SeccompProfile",
229
+ "SecretEnvSource": "io.k8s.api.core.v1.SecretEnvSource",
230
+ "SecretProjection": "io.k8s.api.core.v1.SecretProjection",
231
+ "SecretReference": "io.k8s.api.core.v1.SecretReference",
232
+ "SecretVolumeSource": "io.k8s.api.core.v1.SecretVolumeSource",
233
+ "SelectableField": "io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.SelectableField",
234
+ "SelfSubjectAccessReviewSpec": "io.k8s.api.authorization.v1.SelfSubjectAccessReviewSpec",
235
+ "SelfSubjectRulesReviewSpec": "io.k8s.api.authorization.v1.SelfSubjectRulesReviewSpec",
236
+ "ServerAddressByClientCIDR": "io.k8s.apimachinery.pkg.apis.meta.v1.ServerAddressByClientCIDR",
237
+ "ServiceAccountSubject": "io.k8s.api.flowcontrol.v1.ServiceAccountSubject",
238
+ "ServiceAccountTokenProjection": "io.k8s.api.core.v1.ServiceAccountTokenProjection",
239
+ "ServiceCIDRSpec": "io.k8s.api.networking.v1.ServiceCIDRSpec",
240
+ "ServiceSpec": "io.k8s.api.core.v1.ServiceSpec",
241
+ "SessionAffinityConfig": "io.k8s.api.core.v1.SessionAffinityConfig",
242
+ "ShardInfo": "io.k8s.apimachinery.pkg.apis.meta.v1.ShardInfo",
243
+ "SleepAction": "io.k8s.api.core.v1.SleepAction",
244
+ "StatefulSetOrdinals": "io.k8s.api.apps.v1.StatefulSetOrdinals",
245
+ "StatefulSetPersistentVolumeClaimRetentionPolicy": "io.k8s.api.apps.v1.StatefulSetPersistentVolumeClaimRetentionPolicy",
246
+ "StatefulSetSpec": "io.k8s.api.apps.v1.StatefulSetSpec",
247
+ "StatefulSetUpdateStrategy": "io.k8s.api.apps.v1.StatefulSetUpdateStrategy",
248
+ "StatusCause": "io.k8s.apimachinery.pkg.apis.meta.v1.StatusCause",
249
+ "StatusDetails": "io.k8s.apimachinery.pkg.apis.meta.v1.StatusDetails",
250
+ "StorageOSPersistentVolumeSource": "io.k8s.api.core.v1.StorageOSPersistentVolumeSource",
251
+ "StorageOSVolumeSource": "io.k8s.api.core.v1.StorageOSVolumeSource",
252
+ "StorageTokenRequest": "io.k8s.api.storage.v1.TokenRequest",
253
+ "StorageVersionMigrationSpec": "io.k8s.api.storagemigration.v1beta1.StorageVersionMigrationSpec",
254
+ "SubjectAccessReviewSpec": "io.k8s.api.authorization.v1.SubjectAccessReviewSpec",
255
+ "SuccessPolicy": "io.k8s.api.batch.v1.SuccessPolicy",
256
+ "SuccessPolicyRule": "io.k8s.api.batch.v1.SuccessPolicyRule",
257
+ "Sysctl": "io.k8s.api.core.v1.Sysctl",
258
+ "Taint": "io.k8s.api.core.v1.Taint",
259
+ "TokenRequestSpec": "io.k8s.api.authentication.v1.TokenRequestSpec",
260
+ "TokenReviewSpec": "io.k8s.api.authentication.v1.TokenReviewSpec",
261
+ "TopologySelectorLabelRequirement": "io.k8s.api.core.v1.TopologySelectorLabelRequirement",
262
+ "TopologySelectorTerm": "io.k8s.api.core.v1.TopologySelectorTerm",
263
+ "TypedLocalObjectReference": "io.k8s.api.core.v1.TypedLocalObjectReference",
264
+ "TypedObjectReference": "io.k8s.api.core.v1.TypedObjectReference",
265
+ "UserSubject": "io.k8s.api.flowcontrol.v1.UserSubject",
266
+ "ValidatingAdmissionPolicyBindingSpec": "io.k8s.api.admissionregistration.v1.ValidatingAdmissionPolicyBindingSpec",
267
+ "ValidatingAdmissionPolicySpec": "io.k8s.api.admissionregistration.v1.ValidatingAdmissionPolicySpec",
268
+ "ValidatingWebhook": "io.k8s.api.admissionregistration.v1.ValidatingWebhook",
269
+ "Validation": "io.k8s.api.admissionregistration.v1.Validation",
270
+ "ValidationRule": "io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.ValidationRule",
271
+ "Variable": "io.k8s.api.admissionregistration.v1.Variable",
272
+ "VolumeAttachmentSource": "io.k8s.api.storage.v1.VolumeAttachmentSource",
273
+ "VolumeAttachmentSpec": "io.k8s.api.storage.v1.VolumeAttachmentSpec",
274
+ "VolumeDevice": "io.k8s.api.core.v1.VolumeDevice",
275
+ "VolumeNodeAffinity": "io.k8s.api.core.v1.VolumeNodeAffinity",
276
+ "VolumeNodeResources": "io.k8s.api.storage.v1.VolumeNodeResources",
277
+ "VolumeProjection": "io.k8s.api.core.v1.VolumeProjection",
278
+ "VolumeResourceRequirements": "io.k8s.api.core.v1.VolumeResourceRequirements",
279
+ "VsphereVirtualDiskVolumeSource": "io.k8s.api.core.v1.VsphereVirtualDiskVolumeSource",
280
+ "WebhookConversion": "io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.WebhookConversion",
281
+ "WeightedPodAffinityTerm": "io.k8s.api.core.v1.WeightedPodAffinityTerm",
282
+ "WindowsSecurityContextOptions": "io.k8s.api.core.v1.WindowsSecurityContextOptions"
283
+ }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "algorithm": "sha256",
3
3
  "artifacts": {
4
- "manifest.json": "b99accdbf26e50527cad56bf9d5fafbe5f9621d2649c3c9b0ddad03c3f46a756",
4
+ "manifest.json": "d99e34f684f78949982c35543d8c5550f4d82d7a5a15a6545028a11ad4f9575d",
5
5
  "meta.json": "c8a4cb1d36eba59a277083c8b888b150b025384e429b26db4203ec748d5e7f08",
6
6
  "types/index.d.ts": "35f6ca4fa77c28ecad363920b444f27ab72f0fe49e82eb20e42824c312ac689b",
7
7
  "rules/argo-appset-single-project.ts": "afa9f310753aa2d475f35012b13135b2dfaebed2a35d44edbe185ebc07673674",
@@ -80,5 +80,5 @@
80
80
  "skills/chant-k8s-argo.md": "24c9a85b78a2fc5c6657424baac9cc6d6caff6f47605b8146b2c0082133181cf",
81
81
  "skills/chant-k8s-flux.md": "9670efc2e9854bd14686b5adeb707396b9030a4dcaee6529b30abf56efe2c50c"
82
82
  },
83
- "composite": "c81d25d37b71408ceaaa47f66ad55d5cbae309d62834df3515af1b436cbdb0b5"
83
+ "composite": "6b8e03ee8cabb5ecdb7be11945033c1d9ee53c553a2ff43ab09a3d75e8775013"
84
84
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "k8s",
3
- "version": "0.124.103",
3
+ "version": "0.124.105",
4
4
  "chantVersion": ">=0.1.0",
5
5
  "namespace": "K8s",
6
6
  "intrinsics": [],
@@ -151,6 +151,30 @@ const POD_SPECS = [
151
151
  ["K8s::Batch::Job", "spec.template.spec"],
152
152
  ["K8s::Batch::CronJob", "spec.jobTemplate.spec.template.spec"],
153
153
  ];
154
+ /**
155
+ * Namespaced built-in kinds a cluster lists that no rule here reads by name:
156
+ * they get the `in namespace` containment edge and nothing else (#5284). Their
157
+ * namespace is a short word as often as not (`shop`), which the identity pass
158
+ * skips, so without a rule here an Endpoints or an EndpointSlice sits in no
159
+ * namespace.
160
+ */
161
+ const CONTAINED_KINDS = [
162
+ "K8s::Core::Endpoints",
163
+ "K8s::Discovery::EndpointSlice",
164
+ "K8s::Apps::ControllerRevision",
165
+ "K8s::Core::ReplicationController",
166
+ "K8s::Core::PodTemplate",
167
+ "K8s::Core::ResourceQuota",
168
+ "K8s::Core::LimitRange",
169
+ "K8s::Core::Event",
170
+ "K8s::Events::Event",
171
+ "K8s::Coordination::Lease",
172
+ "K8s::Coordination::LeaseCandidate",
173
+ "K8s::Resource::ResourceClaim",
174
+ "K8s::Resource::ResourceClaimTemplate",
175
+ "K8s::Storage::CSIStorageCapacity",
176
+ "K8s::Certificates::PodCertificateRequest",
177
+ ];
154
178
  /** Kinds that sit in a namespace, so `metadata.namespace` places them. */
155
179
  const NAMESPACED_KINDS = [
156
180
  ...POD_SPECS.map(([kind]) => kind),
@@ -229,6 +253,43 @@ function roleRefRules(from, roleKinds) {
229
253
  },
230
254
  }));
231
255
  }
256
+ /**
257
+ * A binding's `subjects` name a ServiceAccount by `name` and `namespace`
258
+ * (#5284). The subject's own namespace says where the account is: a RoleBinding
259
+ * in `shop2` can name `shop/web-sa`, and a ClusterRoleBinding, which sits in no
260
+ * namespace, reaches its account only through that field. A subject with no
261
+ * namespace is the binding's own namespace for a RoleBinding, and names nothing
262
+ * on a ClusterRoleBinding. Only `kind: ServiceAccount` subjects are read: a
263
+ * User or a Group of the same name is not an account.
264
+ */
265
+ function subjectRules(from, inOwnNamespace) {
266
+ return [
267
+ {
268
+ from,
269
+ path: "subjects[].name",
270
+ targetKind: "K8s::Core::ServiceAccount",
271
+ relation: "reference",
272
+ label: "grants",
273
+ optional: true,
274
+ join(holder, find) {
275
+ const subjects = holder.attrs.subjects;
276
+ if (!Array.isArray(subjects))
277
+ return [];
278
+ const out = [];
279
+ for (const s of subjects) {
280
+ if (!s || s.kind !== "ServiceAccount" || typeof s.name !== "string" || s.name === "")
281
+ continue;
282
+ const ns = typeof s.namespace === "string" && s.namespace !== "" ? s.namespace : undefined;
283
+ if (ns === undefined && !inOwnNamespace)
284
+ continue;
285
+ const found = ns === undefined ? find(s.name) : find(s.name, ns);
286
+ out.push({ value: ns === undefined ? s.name : `${ns}/${s.name}`, targets: found.filter((n) => n.kind === "K8s::Core::ServiceAccount"), via: "subjects" });
287
+ }
288
+ return out;
289
+ },
290
+ },
291
+ ];
292
+ }
232
293
  /** What a pod spec names: its service account, mounted config and secrets, claims, pull secrets. */
233
294
  function podSpecRules(kind, p) {
234
295
  const containers = [`${p}.containers[]`, `${p}.initContainers[]`];
@@ -430,7 +491,7 @@ const identityRules = [
430
491
  ];
431
492
  const refs = [
432
493
  // ── containment: the namespace an object is in ──
433
- ...NAMESPACED_KINDS.map((kind) => ref(kind, "metadata.namespace", "K8s::Core::Namespace", "in namespace", "containment")),
494
+ ...[...NAMESPACED_KINDS, ...CONTAINED_KINDS].map((kind) => ref(kind, "metadata.namespace", "K8s::Core::Namespace", "in namespace", "containment")),
434
495
  // ── owner references, by name inside the namespace ──
435
496
  ...anyOf("K8s::Core::Pod", "metadata.ownerReferences[].name", ["K8s::Apps::ReplicaSet", "K8s::Apps::StatefulSet", "K8s::Apps::DaemonSet", "K8s::Batch::Job"], "owned by"),
436
497
  ...anyOf("K8s::Apps::ReplicaSet", "metadata.ownerReferences[].name", ["K8s::Apps::Deployment"], "owned by"),
@@ -453,9 +514,9 @@ const refs = [
453
514
  ref("K8s::Core::PersistentVolumeClaim", "spec.storageClassName", "K8s::Storage::StorageClass", "class"),
454
515
  ref("K8s::Core::PersistentVolume", "spec.storageClassName", "K8s::Storage::StorageClass", "class"),
455
516
  ...roleRefRules("K8s::Rbac::RoleBinding", ["K8s::Rbac::Role", "K8s::Rbac::ClusterRole"]),
456
- ...anyOf("K8s::Rbac::RoleBinding", "subjects[].name", ["K8s::Core::ServiceAccount"], "grants"),
517
+ ...subjectRules("K8s::Rbac::RoleBinding", true),
457
518
  ...roleRefRules("K8s::Rbac::ClusterRoleBinding", ["K8s::Rbac::ClusterRole"]),
458
- ...anyOf("K8s::Rbac::ClusterRoleBinding", "subjects[].name", ["K8s::Core::ServiceAccount"], "grants"),
519
+ ...subjectRules("K8s::Rbac::ClusterRoleBinding", false),
459
520
  ref("K8s::Core::ServiceAccount", "secrets[].name", "K8s::Core::Secret", "token"),
460
521
  ref("K8s::Core::ServiceAccount", "imagePullSecrets[].name", "K8s::Core::Secret", "pulls with"),
461
522
  // ── External Secrets: the store, and the cloud secret through it ──
@@ -143,12 +143,21 @@ type SwaggerPathItem = Record<string, SwaggerOperation | unknown>;
143
143
  * Returns one result per top-level resource identified by x-kubernetes-group-version-kind.
144
144
  */
145
145
  export declare function parseK8sSwagger(data: string | Buffer): K8sParseResult[];
146
+ export interface K8sSwaggerParseOptions {
147
+ /**
148
+ * Definition key -> the interface name the lexicon already published for it,
149
+ * normally the `interface` entries of the committed surface snapshot. A
150
+ * published name stays with its definition, and a new definition with the
151
+ * same last segment is the one qualified (#5551).
152
+ */
153
+ publishedDefinitions?: Record<string, string>;
154
+ }
146
155
  /**
147
156
  * Parse the swagger document into resource and property-type results, and the
148
157
  * declaration-only interfaces for every other object definition a resource
149
158
  * reaches (chant #3093).
150
159
  */
151
- export declare function parseK8sSwaggerTypes(data: string | Buffer): K8sSwaggerParse;
160
+ export declare function parseK8sSwaggerTypes(data: string | Buffer, opts?: K8sSwaggerParseOptions): K8sSwaggerParse;
152
161
  /** Stable key for a GVK, used to join the `paths` pass onto the `definitions` pass. */
153
162
  /**
154
163
  * Every `(property name, list-map keys)` pair the spec declares, across ALL
@@ -7,6 +7,7 @@
7
7
  * nested property types within their parent resources.
8
8
  */
9
9
  import { extractConstraints as coreExtractConstraints, primaryType, } from "@intentius/chant/codegen/json-schema";
10
+ import { NamingStrategy, publishedNamingConfig, } from "@intentius/chant/codegen/naming";
10
11
  import { namespaceSegmentForGroup } from "../group-namespace.js";
11
12
  // ── Well-known property type definitions ───────────────────────────
12
13
  /**
@@ -78,7 +79,7 @@ export function parseK8sSwagger(data) {
78
79
  * declaration-only interfaces for every other object definition a resource
79
80
  * reaches (chant #3093).
80
81
  */
81
- export function parseK8sSwaggerTypes(data) {
82
+ export function parseK8sSwaggerTypes(data, opts = {}) {
82
83
  const spec = JSON.parse(typeof data === "string" ? data : data.toString("utf-8"));
83
84
  const definitions = spec.definitions ?? {};
84
85
  const results = [];
@@ -101,7 +102,7 @@ export function parseK8sSwaggerTypes(data) {
101
102
  const reachable = reachableDefinitions(resourceDefs.map((r) => r.def), definitions);
102
103
  const ctx = {
103
104
  definitions,
104
- names: nameDefinitions(reachable, definitions),
105
+ names: nameDefinitions(reachable, definitions, opts.publishedDefinitions),
105
106
  resources: new Set(resourceDefs.map((r) => r.defKey)),
106
107
  };
107
108
  // Phase 1: Extract top-level resources (definitions with GVK)
@@ -247,41 +248,55 @@ function definitionKeyParts(defKey) {
247
248
  * version when one group has several (`ResourceV1beta2Device`). The rule
248
249
  * reads only the set of keys, so the result does not depend on the order of
249
250
  * the document.
251
+ *
252
+ * `published` (definition key -> name) keeps each published name with its
253
+ * definition through core's {@link publishedNamingConfig}, the step that keeps
254
+ * resource names: a new definition sharing a published name's last segment is
255
+ * the one qualified, and the published interface is not renamed (#5551).
250
256
  */
251
- function nameDefinitions(reachable, definitions) {
252
- const names = new Map();
253
- const taken = new Set();
257
+ function nameDefinitions(reachable, definitions, published = {}) {
258
+ // Fixed names: the friendly property types, and every resource kind, which
259
+ // no interface may take. A kind enters as a pseudo-type that only holds its
260
+ // name.
261
+ const fixed = {};
262
+ for (const [defKey, config] of Object.entries(PROPERTY_TYPE_DEFS))
263
+ fixed[defKey] = k8sShortName(config.typeName);
254
264
  for (const def of Object.values(definitions)) {
255
265
  for (const gvk of def["x-kubernetes-group-version-kind"] ?? [])
256
- taken.add(gvk.kind);
257
- }
258
- for (const [defKey, config] of Object.entries(PROPERTY_TYPE_DEFS)) {
259
- const name = k8sShortName(config.typeName);
260
- names.set(defKey, name);
261
- taken.add(name);
266
+ fixed[`gvk:${gvk.kind}`] = gvk.kind;
262
267
  }
263
- const byKind = new Map();
264
- for (const defKey of reachable) {
265
- if (names.has(defKey))
266
- continue;
267
- const { kind } = definitionKeyParts(defKey);
268
- byKind.set(kind, [...(byKind.get(kind) ?? []), defKey]);
269
- }
270
- for (const [kind, keys] of byKind) {
271
- if (keys.length === 1 && !taken.has(kind)) {
272
- names.set(keys[0], kind);
273
- continue;
274
- }
275
- const groupCount = new Map();
276
- for (const k of keys) {
277
- const { group } = definitionKeyParts(k);
278
- groupCount.set(group, (groupCount.get(group) ?? 0) + 1);
279
- }
280
- for (const k of keys) {
281
- const { group, version } = definitionKeyParts(k);
282
- names.set(k, groupCount.get(group) > 1 ? `${group}${version}${kind}` : `${group}${kind}`);
283
- }
268
+ const contenders = reachable.filter((k) => fixed[k] === undefined);
269
+ const groupsByKind = new Map();
270
+ for (const defKey of contenders) {
271
+ const { group, kind } = definitionKeyParts(defKey);
272
+ const groups = groupsByKind.get(kind) ?? new Map();
273
+ groups.set(group, (groups.get(group) ?? 0) + 1);
274
+ groupsByKind.set(kind, groups);
284
275
  }
276
+ // The qualifier a contender takes when its last segment is shared: its
277
+ // group, or group and version when that group has several of the segment.
278
+ const qualifier = (defKey) => {
279
+ const { group, version, kind } = definitionKeyParts(defKey);
280
+ return groupsByKind.get(kind).get(group) > 1 ? `${group}${version}` : group;
281
+ };
282
+ const inputs = [...Object.keys(fixed), ...contenders].map((typeName) => ({
283
+ typeName,
284
+ propertyTypes: [],
285
+ }));
286
+ const config = {
287
+ priorityNames: fixed,
288
+ priorityAliases: {},
289
+ priorityPropertyAliases: {},
290
+ serviceAbbreviations: {},
291
+ shortName: (defKey) => definitionKeyParts(defKey).kind,
292
+ serviceName: qualifier,
293
+ };
294
+ const naming = new NamingStrategy(inputs, publishedNamingConfig(inputs, config, published));
295
+ const names = new Map();
296
+ for (const [defKey, config] of Object.entries(PROPERTY_TYPE_DEFS))
297
+ names.set(defKey, k8sShortName(config.typeName));
298
+ for (const defKey of contenders)
299
+ names.set(defKey, naming.resolve(defKey));
285
300
  const owner = new Map();
286
301
  for (const [defKey, name] of names) {
287
302
  const prev = owner.get(name);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intentius/chant-lexicon-k8s",
3
- "version": "0.124.103",
3
+ "version": "0.124.105",
4
4
  "description": "Kubernetes lexicon for chant — declarative IaC in TypeScript",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://intentius.io/chant",
@@ -85,7 +85,7 @@
85
85
  },
86
86
  "peerDependencies": {
87
87
  "zod": "^4.3.6",
88
- "@intentius/chant": "^0.124.104",
88
+ "@intentius/chant": "^0.124.121",
89
89
  "@intentius/chant-k8s-client": "^0.124.101"
90
90
  },
91
91
  "peerDependenciesMeta": {