mirror of
https://github.com/gethomepage/homepage.git
synced 2026-09-12 07:05:56 -07:00
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
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:
@@ -14,13 +14,14 @@ import createLogger from "utils/logger";
|
|||||||
const logger = createLogger("resource-helpers");
|
const logger = createLogger("resource-helpers");
|
||||||
const kc = getKubeConfig();
|
const kc = getKubeConfig();
|
||||||
|
|
||||||
const getSchemaFromGateway = async (parentRef) => {
|
const getSchemaFromGateway = async (parentRef, routeNamespace) => {
|
||||||
const crd = kc.makeApiClient(CustomObjectsApi);
|
const crd = kc.makeApiClient(CustomObjectsApi);
|
||||||
const schema = await crd
|
const schema = await crd
|
||||||
.getNamespacedCustomObject({
|
.getNamespacedCustomObject({
|
||||||
group: HTTPROUTE_API_GROUP,
|
group: HTTPROUTE_API_GROUP,
|
||||||
version: HTTPROUTE_API_VERSION,
|
version: HTTPROUTE_API_VERSION,
|
||||||
namespace: parentRef.namespace,
|
// parentRef namespace is optional, defaults to the route's namespace
|
||||||
|
namespace: parentRef.namespace ?? routeNamespace,
|
||||||
plural: "gateways",
|
plural: "gateways",
|
||||||
name: parentRef.name,
|
name: parentRef.name,
|
||||||
})
|
})
|
||||||
@@ -48,7 +49,7 @@ async function getUrlFromHttpRoute(resource) {
|
|||||||
if (resource.spec.rules[0].matches[0].path.type !== "RegularExpression") {
|
if (resource.spec.rules[0].matches[0].path.type !== "RegularExpression") {
|
||||||
const urlHost = resource.spec.hostnames[0];
|
const urlHost = resource.spec.hostnames[0];
|
||||||
const urlPath = resource.spec.rules[0].matches[0].path.value;
|
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}`;
|
url = `${urlSchema}://${urlHost}${urlPath}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -137,6 +137,36 @@ describe("utils/kubernetes/resource-helpers", () => {
|
|||||||
expect(service.href).toBe("https://example.com/r");
|
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 () => {
|
it("falls back to http when the gateway listener protocol cannot be resolved", async () => {
|
||||||
const kc = getKubeConfig();
|
const kc = getKubeConfig();
|
||||||
const crd = kc.makeApiClient();
|
const crd = kc.makeApiClient();
|
||||||
|
|||||||
Reference in New Issue
Block a user