Merge pull request #7459 from jvstein/rancher_urls_with_path

Support rancher with path prefix
This commit is contained in:
Ben Lambert
2021-10-06 14:01:42 +02:00
committed by GitHub
3 changed files with 22 additions and 2 deletions
@@ -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;
}