Tweakhancement: use routeNamespace as fallback for k8s gateway integration (#7009)
Docker CI / Docker Build & Push (push) Has been cancelled
Lint / Linting Checks (push) Has been cancelled
Release Drafter / Update Release Draft (push) Has been cancelled
Release Drafter / Auto Label PR (push) Has been cancelled
Tests / vitest (1) (push) Has been cancelled
Tests / vitest (2) (push) Has been cancelled
Tests / vitest (3) (push) Has been cancelled
Tests / vitest (4) (push) Has been cancelled

This commit is contained in:
shamoon
2026-08-18 10:55:33 -07:00
committed by GitHub
parent b5084ba8b3
commit d7cc2d3f19
2 changed files with 34 additions and 3 deletions
+4 -3
View File
@@ -14,13 +14,14 @@ import createLogger from "utils/logger";
const logger = createLogger("resource-helpers");
const kc = getKubeConfig();
const getSchemaFromGateway = async (parentRef) => {
const getSchemaFromGateway = async (parentRef, routeNamespace) => {
const crd = kc.makeApiClient(CustomObjectsApi);
const schema = await crd
.getNamespacedCustomObject({
group: HTTPROUTE_API_GROUP,
version: HTTPROUTE_API_VERSION,
namespace: parentRef.namespace,
// parentRef namespace is optional, defaults to the route's namespace
namespace: parentRef.namespace ?? routeNamespace,
plural: "gateways",
name: parentRef.name,
})
@@ -48,7 +49,7 @@ async function getUrlFromHttpRoute(resource) {
if (resource.spec.rules[0].matches[0].path.type !== "RegularExpression") {
const urlHost = resource.spec.hostnames[0];
const urlPath = resource.spec.rules[0].matches[0].path.value;
const urlSchema = await getSchemaFromGateway(resource.spec.parentRefs[0]);
const urlSchema = await getSchemaFromGateway(resource.spec.parentRefs[0], resource.metadata.namespace);
url = `${urlSchema}://${urlHost}${urlPath}`;
}
}
@@ -137,6 +137,36 @@ describe("utils/kubernetes/resource-helpers", () => {
expect(service.href).toBe("https://example.com/r");
});
it("falls back to the route namespace when the parentRef omits one", async () => {
const kc = getKubeConfig();
const crd = kc.makeApiClient();
const base = "gethomepage.dev";
const resource = {
kind: "HTTPRoute",
metadata: {
name: "route",
namespace: "ns",
annotations: {
[`${base}/enabled`]: "true",
},
},
spec: {
hostnames: ["example.com"],
parentRefs: [{ name: "gw", sectionName: "web" }],
rules: [
{
matches: [{ path: { type: "PathPrefix", value: "/r" } }],
},
],
},
};
const service = await constructedServiceFromResource(resource);
expect(crd.getNamespacedCustomObject).toHaveBeenCalledWith(expect.objectContaining({ namespace: "ns" }));
expect(service.href).toBe("https://example.com/r");
});
it("falls back to http when the gateway listener protocol cannot be resolved", async () => {
const kc = getKubeConfig();
const crd = kc.makeApiClient();