-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add LoadBalancer information to the Ingress view #1064
Conversation
Add a new LoadBalancer column in the Ingress view so that users can see the hostname or IP of the Ingress Controller to be used. Signed-off-by: Steve Richards <srichards@mirantis.com>
@@ -2,6 +2,7 @@ import { KubeObject } from "../kube-object"; | |||
import { autobind } from "../../utils"; | |||
import { IMetrics, metricsApi } from "./metrics.api"; | |||
import { KubeApi } from "../kube-api"; | |||
import { hostname } from "os"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this used anywhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Have removed in the next commit
|
||
if (!loadBalancer) return []; | ||
|
||
loadBalancer.ingress.forEach(address => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This crashes when there are no external addresses
loadBalancer.ingress.forEach(address => { | |
loadBalancer.ingress?.forEach(address => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good spot @jim-docker. I guess the only time this can happen though is if an ingress object exists without an ingress controller being present? Still something we should handle
const ingressAddresses: string[] = []; | ||
const { status: { loadBalancer } } = this; | ||
|
||
if (!loadBalancer) return []; | ||
|
||
loadBalancer.ingress.forEach(address => { | ||
const entry = address.hostname ? address.hostname : address.ip; | ||
ingressAddresses.push(entry); | ||
}) | ||
|
||
return ingressAddresses; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest making this a map as it is much cleaner
const ingressAddresses: string[] = []; | |
const { status: { loadBalancer } } = this; | |
if (!loadBalancer) return []; | |
loadBalancer.ingress.forEach(address => { | |
const entry = address.hostname ? address.hostname : address.ip; | |
ingressAddresses.push(entry); | |
}) | |
return ingressAddresses; | |
const { status: { loadBalancer = {} } } = this; | |
return (loadBalancer.ingress ?? []).map(address => ( | |
address.hostname || address.ip | |
)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is much cleaner @Nokel81 - I'm still learning so having these examples is awesome to help me improve. One question, as loadBalancer
could end up being an empty array are we good with the ingress and address property throwing up a warning in IDE validation? For example, in VS Code I get the following:
any
Property 'ingress' does not exist on type '{}'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The above actually causes a CI/CD failure in integration tests so will see if I can resolve
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amended as follows:
const { status: { loadBalancer = {ingress: []} } } = this;
This gives the loadBalancer an empty ingress object by default.
This ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that would be better
Signed-off-by: Steve Richards <srichards@mirantis.com>
Add a new LoadBalancer column in the Ingress view so that users can see the hostname or IP of the Ingress Controller to be used.
Fixes #772
Signed-off-by: Steve Richards srichards@mirantis.com