Skip to content

Commit b05744f

Browse files
committed
Fix schema resolution of Kubernetes RBAC resources
RBAC resources weren't being resolved properly, since the group name is `rbac.authorization`, yet only `rbac` appears in their IDs. Fixes #1204 Signed-off-by: David Thompson <davthomp@redhat.com>
1 parent 703a4b8 commit b05744f

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/languageservice/services/crdUtil.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export function autoDetectKubernetesSchemaFromDocument(
3737
})
3838
.filter((ref) => ref)
3939
.map((ref) => ref.replace('_definitions.json#/definitions/', '').toLowerCase());
40-
const groupWithoutK8sIO = group.replace('.k8s.io', '');
40+
const groupWithoutK8sIO = group.replace('.k8s.io', '').replace('rbac.authorization', 'rbac');
4141
const k8sTypeName = `io.k8s.api.${groupWithoutK8sIO.toLowerCase()}.${version.toLowerCase()}.${kind.toLowerCase()}`;
4242

4343
if (kubernetesBuildIns.includes(k8sTypeName)) {

test/yamlSchemaService.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,5 +456,36 @@ spec:
456456
expect(requestServiceMock).calledWithExactly('file:///_definitions.json');
457457
expect(requestServiceMock).calledTwice;
458458
});
459+
460+
it('should not get schema from crd catalog for RBAC-related resources', async () => {
461+
const documentContent = 'apiVersion: rbac.authorization.k8s.io/v1\nkind: RoleBinding';
462+
const content = `${documentContent}`;
463+
const yamlDock = parse(content);
464+
465+
const settings = new SettingsState();
466+
settings.schemaAssociations = {
467+
kubernetes: ['*.yaml'],
468+
};
469+
settings.kubernetesCRDStoreEnabled = true;
470+
requestServiceMock = sandbox.fake.resolves(
471+
`
472+
{
473+
"oneOf": [
474+
{
475+
"$ref": "_definitions.json#/definitions/io.k8s.api.rbac.v1.RoleBinding"
476+
}
477+
]
478+
}
479+
`
480+
);
481+
const service = new SchemaService.YAMLSchemaService(requestServiceMock, undefined, undefined, settings);
482+
service.registerExternalSchema(KUBERNETES_SCHEMA_URL, ['*.yaml']);
483+
const resolvedSchema = await service.getSchemaForResource('test.yaml', yamlDock.documents[0]);
484+
expect(resolvedSchema.schema.url).eqls(KUBERNETES_SCHEMA_URL);
485+
486+
expect(requestServiceMock).calledWithExactly(KUBERNETES_SCHEMA_URL);
487+
expect(requestServiceMock).calledWithExactly('file:///_definitions.json');
488+
expect(requestServiceMock).calledTwice;
489+
});
459490
});
460491
});

0 commit comments

Comments
 (0)