On LocalKubectlProxyClusterLocator, when resolving localhost, IPv4 address is placed before IPv6 address
Signed-off-by: Andres Mauricio Gomez P <andmagom@outlook.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-kubernetes-backend': patch
|
||||
---
|
||||
|
||||
On LocalKubectlProxyClusterLocator, when resolving localhost, IPv4 address is placed before IPv6 address, ignoring the order from the DNS resolver. This change is necessary since by default kubectl proxy listen on IPv4
|
||||
@@ -15,18 +15,25 @@
|
||||
*/
|
||||
|
||||
import { ANNOTATION_KUBERNETES_AUTH_PROVIDER } from '@backstage/plugin-kubernetes-common';
|
||||
import { ClusterDetails, KubernetesClustersSupplier } from '../types/types';
|
||||
import {
|
||||
ClusterDetails,
|
||||
KubernetesClustersSupplier,
|
||||
} from '@backstage/plugin-kubernetes-node';
|
||||
import dns from 'node:dns';
|
||||
|
||||
export class LocalKubectlProxyClusterLocator
|
||||
implements KubernetesClustersSupplier
|
||||
{
|
||||
private readonly clusterDetails: ClusterDetails[];
|
||||
// verbatim: when false, IPv4 addresses are placed before IPv6 addresses, ignoring the order from the DNS resolver
|
||||
// By default kubectl proxy listens on 127.0.0.1 instead of [::1]
|
||||
private lookupPromise = dns.promises.lookup('localhost', { verbatim: false });
|
||||
|
||||
public constructor() {
|
||||
this.clusterDetails = [
|
||||
{
|
||||
name: 'local',
|
||||
url: 'http:/localhost:8001',
|
||||
url: 'http://localhost:8001',
|
||||
authMetadata: {
|
||||
[ANNOTATION_KUBERNETES_AUTH_PROVIDER]: 'localKubectlProxy',
|
||||
},
|
||||
@@ -36,6 +43,8 @@ export class LocalKubectlProxyClusterLocator
|
||||
}
|
||||
|
||||
async getClusters(): Promise<ClusterDetails[]> {
|
||||
const lookupResolution = await this.lookupPromise;
|
||||
this.clusterDetails[0].url = `http://${lookupResolution.address}:8001`;
|
||||
return this.clusterDetails;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -646,7 +646,7 @@ describe('KubernetesProxy', () => {
|
||||
});
|
||||
|
||||
worker.use(
|
||||
rest.get('http://localhost:8001/api/v1/namespaces', (req, res, ctx) => {
|
||||
rest.get('http://127.0.0.1:8001/api/v1/namespaces', (req, res, ctx) => {
|
||||
return req.headers.get('Authorization')
|
||||
? res(ctx.status(401))
|
||||
: res(
|
||||
|
||||
Reference in New Issue
Block a user