Skip to content
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

frontend: Mark http field in IngressRule as optional and fix type errors #2696

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading