Skip to content

Commit

Permalink
change to service.name to show correct ingress url's (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
hsubramanianaks authored Sep 14, 2023
1 parent 605623b commit ef2b003
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/clients/KubectlClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export class KubectlClient implements IClient {
const usesHttps: boolean = ingressItem.spec.tls != null && ingressItem.spec.tls.find(item => item != null && item.hosts != null && item.hosts.indexOf(ingressRule.host) > -1) != null;

for (const path of ingressRule.http.paths) {
if (path == null || path.backend == null || path.backend.serviceName == null) {
if (path == null || path.backend == null || path.backend.service == null || path.backend.service.name == null) {
continue;
}

Expand Down
134 changes: 126 additions & 8 deletions src/tests/suites/KubectlClient-Test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe(`KubectlClient Test`, () => {
"apiVersion": "v1",
"items": [
{
"apiVersion": "extensions/v1beta1",
"apiVersion": "networking.k8s.io/v1",
"kind": "Ingress",
"metadata": {
"annotations": {
Expand All @@ -41,7 +41,6 @@ describe(`KubectlClient Test`, () => {
"name": "bikesharingweb",
"namespace": "dev",
"resourceVersion": "1314825",
"selfLink": "/apis/extensions/v1beta1/namespaces/dev/ingresses/bikesharingweb",
"uid": "8044fe48-4e8c-454b-b8de-553d0988666e"
},
"spec": {
Expand All @@ -52,8 +51,12 @@ describe(`KubectlClient Test`, () => {
"paths": [
{
"backend": {
"serviceName": "bikesharingweb",
"servicePort": "http"
"service": {
"name": "bikesharingweb",
"port": {
"number": 80
}
}
},
"path": "/"
}
Expand All @@ -73,7 +76,7 @@ describe(`KubectlClient Test`, () => {
}
},
{
"apiVersion": "extensions/v1beta1",
"apiVersion": "networking.k8s.io/v1",
"kind": "Ingress",
"metadata": {
"annotations": {
Expand All @@ -93,7 +96,6 @@ describe(`KubectlClient Test`, () => {
"name": "gateway",
"namespace": "dev",
"resourceVersion": "1314824",
"selfLink": "/apis/extensions/v1beta1/namespaces/dev/ingresses/gateway",
"uid": "0b61f6fa-f6ad-4a01-b1b2-89255bed41ca"
},
"spec": {
Expand All @@ -104,8 +106,12 @@ describe(`KubectlClient Test`, () => {
"paths": [
{
"backend": {
"serviceName": "gateway",
"servicePort": "http"
"service": {
"name": "gateway",
"port": {
"number": 80
}
}
},
"path": "/"
}
Expand Down Expand Up @@ -153,6 +159,118 @@ describe(`KubectlClient Test`, () => {
expect(ingresses.length).to.equal(0);
});

it(`getIngressesAsync when the kubectl command returns ingresses without service`, async () => {
const returnString = `{
"apiVersion": "v1",
"items": [
{
"apiVersion": "networking.k8s.io/v1",
"kind": "Ingress",
"metadata": {
"annotations": {
"kubernetes.io/ingress.class": "traefik",
"meta.helm.sh/release-name": "bikesharingsampleapp",
"meta.helm.sh/release-namespace": "dev"
},
"creationTimestamp": "2020-05-12T01:02:49Z",
"generation": 1,
"labels": {
"app": "bikesharingweb",
"app.kubernetes.io/managed-by": "Helm",
"chart": "bikesharingweb-0.1.0",
"heritage": "Helm",
"release": "bikesharingsampleapp"
},
"name": "bikesharingweb",
"namespace": "dev",
"resourceVersion": "1314825",
"uid": "8044fe48-4e8c-454b-b8de-553d0988666e"
},
"spec": {
"rules": [
{
"host": "dev.bikesharingweb.j7l6v4gz8d.eus.mindaro.io",
"http": {
"paths": [
{
"backend": {},
"path": "/"
}
]
}
}
]
},
"status": {
"loadBalancer": {
"ingress": [
{
"ip": "13.72.80.227"
}
]
}
}
},
{
"apiVersion": "networking.k8s.io/v1",
"kind": "Ingress",
"metadata": {
"annotations": {
"kubernetes.io/ingress.class": "traefik",
"meta.helm.sh/release-name": "bikesharingsampleapp",
"meta.helm.sh/release-namespace": "dev"
},
"creationTimestamp": "2020-05-12T01:02:49Z",
"generation": 1,
"labels": {
"app": "gateway",
"app.kubernetes.io/managed-by": "Helm",
"chart": "gateway-0.1.0",
"heritage": "Helm",
"release": "bikesharingsampleapp"
},
"name": "gateway",
"namespace": "dev",
"resourceVersion": "1314824",
"uid": "0b61f6fa-f6ad-4a01-b1b2-89255bed41ca"
},
"spec": {
"rules": [
{
"host": "dev.gateway.j7l6v4gz8d.eus.mindaro.io",
"http": {
"paths": [
{
"backend": {
"service": {}
},
"path": "/"
}
]
}
}
]
},
"status": {
"loadBalancer": {
"ingress": [
{
"ip": "13.72.80.227"
}
]
}
}
}
]
}`;
const commandRunnerStub = sinon.createStubInstance(CommandRunner);
commandRunnerStub.runAsync.resolves(returnString);
const kubectlClient = new KubectlClient(`my/path/kubectl.exe`, commandRunnerStub, accountContextManagerStub, loggerStub);
let ingresses: IKubernetesIngress[];
ingresses = await kubectlClient.getIngressesAsync(`dev`, `c:/users/alias/.kube/config`, false);
expect(ingresses.length).to.equal(0);
});

it(`getServicesAsync when the kubectl command returns a set of various services`, async () => {
const returnString = `{
"items": [
Expand Down

0 comments on commit ef2b003

Please sign in to comment.