feat(kubernetes): support rancher with path prefix

Signed-off-by: Jeff Stein <jeff@jeffvstein.org>
This commit is contained in:
Jeff Stein
2021-10-05 12:26:58 -07:00
parent 7d3228fefb
commit c148c8854b
3 changed files with 22 additions and 2 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-kubernetes': patch
---
Support Rancher urls with an existing path component
@@ -99,4 +99,19 @@ describe('clusterLinks - rancher formatter', () => {
'https://k8s.foo.com/explorer/autoscaling.horizontalpodautoscaler/bar/foobar',
);
});
it('should support subpaths in dashboardUrl', () => {
const url = rancherFormatter({
dashboardUrl: new URL('https://k8s.foo.com/dashboard/c/c-28a4b/'),
object: {
metadata: {
name: 'foobar',
namespace: 'bar',
},
},
kind: 'Deployment',
});
expect(url.href).toBe(
'https://k8s.foo.com/dashboard/c/c-28a4b/explorer/apps.deployment/bar/foobar',
);
});
});
@@ -28,9 +28,9 @@ export function rancherFormatter(options: ClusterLinksFormatterOptions): URL {
const namespace = options.object.metadata?.namespace;
const validKind = kindMappings[options.kind.toLocaleLowerCase('en-US')];
if (validKind && name && namespace) {
result.pathname = `explorer/${validKind}/${namespace}/${name}`;
result.pathname += `explorer/${validKind}/${namespace}/${name}`;
} else if (namespace) {
result.pathname = 'explorer/workload';
result.pathname += 'explorer/workload';
}
return result;
}