Skip to content

Commit

Permalink
Merge pull request #2696 from headlamp-k8s/ingress-map-fix
Browse files Browse the repository at this point in the history
frontend: Mark http field in IngressRule as optional and fix type errors
  • Loading branch information
sniok authored Dec 16, 2024
2 parents 372ff2c + 70faa79 commit c97a07c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
8 changes: 5 additions & 3 deletions frontend/src/components/ingress/Details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export default function IngressDetails(props: { name?: string; namespace?: strin
function getPorts(item: Ingress) {
const ports: string[] = [];
item.getRules().forEach(rule => {
rule.http.paths.forEach(path => {
rule.http?.paths.forEach(path => {
if (!!path.backend.service) {
const portNumber =
path.backend.service.port.number ?? path.backend.service.port.name ?? '';
Expand Down Expand Up @@ -243,7 +243,7 @@ export default function IngressDetails(props: { name?: string; namespace?: strin
{
label: t('translation|Path'),
getter: (data: IngressRule) =>
data.http.paths.map(({ path }) => (
data.http?.paths.map(({ path }) => (
<LinkStringFormat
key={path}
url={data.host || '*'}
Expand All @@ -255,7 +255,9 @@ export default function IngressDetails(props: { name?: string; namespace?: strin
{
label: t('Backends'),
getter: (data: IngressRule) => (
<BackendFormat backend={data.http.paths.map(({ backend }) => backend)} />
<BackendFormat
backend={data.http?.paths.map(({ backend }) => backend) ?? []}
/>
),
},
]}
Expand Down
23 changes: 12 additions & 11 deletions frontend/src/components/ingress/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@ function RulesDisplay(props: { ingress: Ingress }) {
let labels: string[] = [];

rules.forEach(({ http }) => {
const text = http.paths.map(({ path, backend }) => {
let target = '';
if (!!backend.service) {
const service = backend.service.name;
const port = backend.service.port.number ?? backend.service.port.name ?? '';
target = `${!!service ? service + ':' + port.toString() : port.toString()}`;
} else if (!!backend.resource) {
target = `${backend.resource.kind}:${backend.resource.name}`;
}
return `${path} 🞂 ${target}`;
});
const text =
http?.paths.map(({ path, backend }) => {
let target = '';
if (!!backend.service) {
const service = backend.service.name;
const port = backend.service.port.number ?? backend.service.port.name ?? '';
target = `${!!service ? service + ':' + port.toString() : port.toString()}`;
} else if (!!backend.resource) {
target = `${backend.resource.kind}:${backend.resource.name}`;
}
return `${path} 🞂 ${target}`;
}) ?? '';
labels = labels.concat(text);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const ingressListSource: GraphSource = {

ingresses.forEach(ingress => {
ingress.spec.rules.forEach((rule: IngressRule) => {
rule.http.paths.forEach(path => {
rule.http?.paths?.forEach(path => {
const service = services.find(
service => service.metadata.name === path?.backend?.service?.name
);
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lib/k8s/ingress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface LegacyIngressRule {

export interface IngressRule {
host: string;
http: {
http?: {
paths: {
path: string;
pathType?: string;
Expand Down

0 comments on commit c97a07c

Please sign in to comment.