Skip to content

Commit

Permalink
Widgets in discovered services now work correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
jameswynn committed Jan 9, 2023
1 parent 9a072cd commit 4d6ce1f
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions src/utils/config/service-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,17 @@ export async function servicesFromDocker() {
}

function getUrlFromIngress(ingress) {
let url = ingress.metadata.annotations['homepage/url'];
if(!url) {
const urlHost = ingress.spec.rules[0].host;
const urlPath = ingress.spec.rules[0].http.paths[0].path;
const urlSchema = ingress.spec.tls ? 'https' : 'http';

url = `${urlSchema}:https://${urlHost}${urlPath}`;
}
return url;
const urlHost = ingress.spec.rules[0].host;
const urlPath = ingress.spec.rules[0].http.paths[0].path;
const urlSchema = ingress.spec.tls ? 'https' : 'http';
return `${urlSchema}:https://${urlHost}${urlPath}`;
}

export async function servicesFromKubernetes() {
const ANNOTATION_BASE = 'gethomepage.dev';
const ANNOTATION_WIDGET_BASE = `${ANNOTATION_BASE}/widget.`;
const ANNOTATION_POD_SELECTOR = `${ANNOTATION_BASE}/pod-selector`;

This comment has been minimized.

Copy link
@shamoon

shamoon Oct 13, 2023

Collaborator

@jameswynn Just double-check something for me, why is this not podSelector? e.g. the docs ( https://gethomepage.dev/v0.7.3/configs/kubernetes/#__codelineno-4-14 ) suggest gethomepage.dev/podSelector: ""

This comment has been minimized.

Copy link
@jameswynn

jameswynn Oct 13, 2023

Author Contributor

Camel case is technically supported, but it is atypical in kubernetes. Whenever possible I try to follow standard practices for a given platform. I'm not sure why the documentation uses camel case.

This comment has been minimized.

Copy link
@shamoon

shamoon Oct 13, 2023

Collaborator

So are you saying we should change either the docs to be pod-selector or this to use camel case? 9a072cd

Thats my q, looking at it on the screen I think this wouldn't work as-is? It will look for gethomepage.dev/pod-selector: ... but we're telling people to use gethomepage.dev/podSelector: .... Just want to make sure im not misunderstanding. Again, Im still limited to the humble k3d, so I'm left with trying to reverse-engineer the code when responding to e.g. questions

This comment has been minimized.

Copy link
@jameswynn

jameswynn Oct 14, 2023

Author Contributor

Yeah they should definitely match. I think we should update the documentation. Changing the code at this point would probably break some people's deployments.

This comment has been minimized.

Copy link
@shamoon

shamoon Oct 14, 2023

Collaborator

Thanks mate, #2187


checkAndCopyConfig("kubernetes.yaml");

try {
Expand All @@ -145,23 +144,23 @@ export async function servicesFromKubernetes() {
return [];
}
const services = ingressList.items
.filter((ingress) => ingress.metadata.annotations && ingress.metadata.annotations['gethomepage.dev/enabled'] === 'true')
.filter((ingress) => ingress.metadata.annotations && ingress.metadata.annotations[`${ANNOTATION_BASE}/enabled`] === 'true')
.map((ingress) => {
const constructedService = {
app: ingress.metadata.name,
namespace: ingress.metadata.namespace,
href: ingress.metadata.annotations['gethomepage.dev/href'] || getUrlFromIngress(ingress),
name: ingress.metadata.annotations['gethomepage.dev/name'] || ingress.metadata.name,
group: ingress.metadata.annotations['gethomepage.dev/group'] || "Kubernetes",
icon: ingress.metadata.annotations['gethomepage.dev/icon'] || '',
description: ingress.metadata.annotations['gethomepage.dev/description'] || '',
href: ingress.metadata.annotations[`${ANNOTATION_BASE}/href`] || getUrlFromIngress(ingress),
name: ingress.metadata.annotations[`${ANNOTATION_BASE}/name`] || ingress.metadata.name,
group: ingress.metadata.annotations[`${ANNOTATION_BASE}/group`] || "Kubernetes",
icon: ingress.metadata.annotations[`${ANNOTATION_BASE}/icon`] || '',
description: ingress.metadata.annotations[`${ANNOTATION_BASE}/description`] || '',
};
if (ingress.metadata.annotations['gethomepage.dev/pod-selector']) {
constructedService.podSelector = ingress.metadata.annotations['gethomepage.dev/pod-selector'];
if (ingress.metadata.annotations[ANNOTATION_POD_SELECTOR]) {
constructedService.podSelector = ingress.metadata.annotations[ANNOTATION_POD_SELECTOR];
}
Object.keys(ingress.metadata.annotations).forEach((annotation) => {
if (annotation.startsWith("gethomepage.dev/widget/")) {
shvl.set(constructedService, annotation.replace("homepage/widget/", ""), ingress.metadata.annotations[annotation]);
if (annotation.startsWith(ANNOTATION_WIDGET_BASE)) {
shvl.set(constructedService, annotation.replace(`${ANNOTATION_BASE}/`, ""), ingress.metadata.annotations[annotation]);
}
});

Expand Down

0 comments on commit 4d6ce1f

Please sign in to comment.