1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-19 13:29:41 +02:00
portainer/app/kubernetes/helpers/serviceHelper.js
Ali 4c0049edbe
fix(app): allow editing pod services [EE-6480] (#10875)
* fix(app): allow editing pod services [EE-6480]
* address review comment

---------

Co-authored-by: testa113 <testa113>
Co-authored-by: prabhat khera <prabhat.khera@portainer.io>
2024-01-23 10:10:16 +13:00

25 lines
953 B
JavaScript

import _ from 'lodash-es';
import { KubernetesServiceHeadlessPrefix } from 'Kubernetes/models/service/models';
class KubernetesServiceHelper {
static generateHeadlessServiceName(name) {
return KubernetesServiceHeadlessPrefix + name;
}
static findApplicationBoundService(services, rawApp) {
if (!rawApp.spec.template) {
return undefined;
}
return _.find(services, (item) => item.spec.selector && _.isMatch(rawApp.spec.template.metadata.labels, item.spec.selector));
}
static findApplicationBoundServices(services, rawApp) {
// if the app is a naked pod (doesn't have a template), then get the pod labels
const appLabels = rawApp.spec.template ? rawApp.spec.template.metadata.labels : rawApp.metadata.labels;
if (!appLabels) {
return undefined;
}
return _.filter(services, (item) => item.spec.selector && _.isMatch(appLabels, item.spec.selector));
}
}
export default KubernetesServiceHelper;