1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-08-05 22:05:23 +02:00

Merge branch 'develop' into feat/EE-809/EE-466/kube-advanced-apps

This commit is contained in:
Felix Han 2021-09-01 10:41:22 +12:00
commit 1cbfd96738
45 changed files with 901 additions and 166 deletions

View file

@ -0,0 +1,15 @@
export default class KubeConfigController {
/* @ngInject */
constructor($window, KubernetesConfigService) {
this.$window = $window;
this.KubernetesConfigService = KubernetesConfigService;
}
async downloadKubeconfig() {
await this.KubernetesConfigService.downloadConfig();
}
$onInit() {
this.state = { isHTTPS: this.$window.location.protocol === 'https:' };
}
}

View file

@ -0,0 +1,11 @@
<button
ng-if="$ctrl.state.isHTTPS"
type="button"
class="btn btn-xs btn-primary"
ng-click="$ctrl.downloadKubeconfig()"
analytics-on
analytics-category="kubernetes"
analytics-event="kubernetes-kubectl-kubeconfig"
>
Kubeconfig <i class="fas fa-download space-right"></i>
</button>

View file

@ -0,0 +1,7 @@
import angular from 'angular';
import controller from './kube-config-download-button.controller';
angular.module('portainer.kubernetes').component('kubeConfigDownloadButton', {
templateUrl: './kube-config-download-button.html',
controller,
});

View file

@ -3,13 +3,12 @@ import * as fit from 'xterm/lib/addons/fit/fit';
export default class KubectlShellController {
/* @ngInject */
constructor(TerminalWindow, $window, $async, EndpointProvider, LocalStorage, KubernetesConfigService, Notifications) {
constructor(TerminalWindow, $window, $async, EndpointProvider, LocalStorage, Notifications) {
this.$async = $async;
this.$window = $window;
this.TerminalWindow = TerminalWindow;
this.EndpointProvider = EndpointProvider;
this.LocalStorage = LocalStorage;
this.KubernetesConfigService = KubernetesConfigService;
this.Notifications = Notifications;
}
@ -83,7 +82,7 @@ export default class KubectlShellController {
endpointId: this.EndpointProvider.endpointID(),
};
const wsProtocol = this.state.isHTTPS ? 'wss://' : 'ws://';
const wsProtocol = this.$window.location.protocol === 'https:' ? 'wss://' : 'ws://';
const path = '/api/websocket/kubernetes-shell';
const queryParams = Object.entries(params)
.map(([k, v]) => `${k}=${v}`)
@ -97,17 +96,12 @@ export default class KubectlShellController {
this.configureSocketAndTerminal(this.state.shell.socket, this.state.shell.term);
}
async downloadKubeconfig() {
await this.KubernetesConfigService.downloadConfig();
}
$onInit() {
return this.$async(async () => {
this.state = {
css: 'normal',
checked: false,
icon: 'fa-window-minimize',
isHTTPS: this.$window.location.protocol === 'https:',
shell: {
connected: false,
socket: null,

View file

@ -1,14 +1,12 @@
<button type="button" class="btn btn-xs btn-primary" ng-click="$ctrl.connectConsole()" ng-disabled="$ctrl.state.shell.connected" data-cy="k8sSidebar-shellButton">
<i class="fa fa-terminal" style="margin-right: 2px;"></i>
kubectl shell
<i class="fa fa-terminal space-right"></i> kubectl shell
</button>
<kube-config-download-button></kube-config-download-button>
<div ng-if="$ctrl.state.checked" class="{{ $ctrl.state.css }}-kubectl-shell">
<div class="shell-container">
<div class="shell-item"><i class="fas fa-terminal" style="margin-right: 5px;"></i>kubectl shell</div>
<div ng-if="$ctrl.state.isHTTPS" class="shell-item-center">
<a href="" ng-click="$ctrl.downloadKubeconfig()"><i class="fas fa-file-download" style="margin-right: 5px;"></i>Download Kubeconfig</a>
</div>
<div class="shell-item-right">
<i class="fas fa-redo-alt" ng-click="$ctrl.screenClear();" data-cy="k8sShell-refreshButton"></i>
<i

View file

@ -19,10 +19,10 @@ export class KubernetesIngressConverter {
: _.map(rule.http.paths, (path) => {
const ingRule = new KubernetesIngressRule();
ingRule.IngressName = data.metadata.name;
ingRule.ServiceName = path.backend.serviceName;
ingRule.ServiceName = path.backend.service.name;
ingRule.Host = rule.host || '';
ingRule.IP = data.status.loadBalancer.ingress ? data.status.loadBalancer.ingress[0].ip : undefined;
ingRule.Port = path.backend.servicePort;
ingRule.Port = path.backend.service.port.number;
ingRule.Path = path.path;
return ingRule;
});
@ -151,8 +151,8 @@ export class KubernetesIngressConverter {
rule.http.paths = _.map(paths, (p) => {
const path = new KubernetesIngressRulePathCreatePayload();
path.path = p.Path;
path.backend.serviceName = p.ServiceName;
path.backend.servicePort = p.Port;
path.backend.service.name = p.ServiceName;
path.backend.service.port.number = p.Port;
return path;
});
hostsWithRules.push(host);
@ -173,7 +173,7 @@ export class KubernetesIngressConverter {
res.spec.rules = [];
_.forEach(data.Hosts, (host) => {
if (!host.NeedsDeletion) {
res.spec.rules.push({ host: host.Host });
res.spec.rules.push({ host: host.Host || host });
}
});
} else {

View file

@ -20,10 +20,15 @@ export function KubernetesIngressRuleCreatePayload() {
export function KubernetesIngressRulePathCreatePayload() {
return {
backend: {
serviceName: '',
servicePort: 0,
},
path: '',
pathType: 'ImplementationSpecific',
backend: {
service: {
name: '',
port: {
number: 0,
},
},
},
};
}

View file

@ -5,7 +5,7 @@ angular.module('portainer.kubernetes').factory('KubernetesIngresses', factory);
function factory($resource, API_ENDPOINT_ENDPOINTS, EndpointProvider) {
'use strict';
return function (namespace) {
const url = `${API_ENDPOINT_ENDPOINTS}/:endpointId/kubernetes/apis/networking.k8s.io/v1beta1${namespace ? '/namespaces/:namespace' : ''}/ingresses/:id/:action`;
const url = `${API_ENDPOINT_ENDPOINTS}/:endpointId/kubernetes/apis/networking.k8s.io/v1${namespace ? '/namespaces/:namespace' : ''}/ingresses/:id/:action`;
return $resource(
url,
{

View file

@ -0,0 +1,65 @@
import _ from 'lodash-es';
/**
* NodesLimits Model
*/
export class KubernetesNodesLimits {
constructor(nodesLimits) {
this.MaxCPU = 0;
this.MaxMemory = 0;
this.nodesLimits = this.convertCPU(nodesLimits);
this.calculateMaxCPUMemory();
}
convertCPU(nodesLimits) {
_.forEach(nodesLimits, (value) => {
if (value.CPU) {
value.CPU /= 1000.0;
}
});
return nodesLimits;
}
calculateMaxCPUMemory() {
const nodesLimitsArray = Object.values(this.nodesLimits);
this.MaxCPU = _.maxBy(nodesLimitsArray, 'CPU').CPU;
this.MaxMemory = _.maxBy(nodesLimitsArray, 'Memory').Memory;
}
// check if there is enough cpu and memory to allocate containers in replica mode
overflowForReplica(cpu, memory, instances) {
_.forEach(this.nodesLimits, (value) => {
instances -= Math.min(Math.floor(value.CPU / cpu), Math.floor(value.Memory / memory));
});
return instances > 0;
}
// check if there is enough cpu and memory to allocate containers in global mode
overflowForGlobal(cpu, memory) {
let overflow = false;
_.forEach(this.nodesLimits, (value) => {
if (cpu > value.CPU || memory > value.Memory) {
overflow = true;
}
});
return overflow;
}
excludesPods(pods, cpuLimit, memoryLimit) {
const nodesLimits = this.nodesLimits;
_.forEach(pods, (value) => {
const node = value.Node;
if (node && nodesLimits[node]) {
nodesLimits[node].CPU += cpuLimit;
nodesLimits[node].Memory += memoryLimit;
}
});
this.calculateMaxCPUMemory();
}
}

View file

@ -0,0 +1,21 @@
import angular from 'angular';
angular.module('portainer.kubernetes').factory('KubernetesNodesLimits', KubernetesNodesLimitsFactory);
/* @ngInject */
function KubernetesNodesLimitsFactory($resource, API_ENDPOINT_KUBERNETES, EndpointProvider) {
const url = API_ENDPOINT_KUBERNETES + '/:endpointId/nodes_limits';
return $resource(
url,
{
endpointId: EndpointProvider.endpointID,
},
{
get: {
method: 'GET',
ignoreLoadingBar: true,
transformResponse: (data) => ({ data: JSON.parse(data) }),
},
}
);
}

View file

@ -9,7 +9,6 @@ class KubernetesConfigService {
async downloadConfig() {
const response = await this.KubernetesConfig.get();
const headers = response.headers();
const contentDispositionHeader = headers['content-disposition'];
const filename = contentDispositionHeader.replace('attachment;', '').trim();

View file

@ -0,0 +1,25 @@
import angular from 'angular';
import PortainerError from 'Portainer/error';
import { KubernetesNodesLimits } from 'Kubernetes/models/nodes-limits/models';
class KubernetesNodesLimitsService {
/* @ngInject */
constructor(KubernetesNodesLimits) {
this.KubernetesNodesLimits = KubernetesNodesLimits;
}
/**
* GET
*/
async get() {
try {
const nodesLimits = await this.KubernetesNodesLimits.get().$promise;
return new KubernetesNodesLimits(nodesLimits.data);
} catch (err) {
throw new PortainerError('Unable to retrieve nodes limits', err);
}
}
}
export default KubernetesNodesLimitsService;
angular.module('portainer.kubernetes').service('KubernetesNodesLimitsService', KubernetesNodesLimitsService);

View file

@ -96,7 +96,6 @@
</editor-description>
</web-editor-form>
<!-- #endregion -->
<div ng-if="ctrl.state.appType === ctrl.KubernetesDeploymentTypes.APPLICATION_FORM">
<div class="col-sm-12 form-section-title">
Application
@ -116,6 +115,7 @@
auto-focus
required
ng-disabled="ctrl.state.isEdit"
data-cy="k8sAppCreate-applicationName"
/>
</div>
</div>
@ -773,6 +773,13 @@
</p>
</div>
</div>
<div class="form-group" ng-if="ctrl.nodeLimitsOverflow()">
<div class="col-sm-12 small text-danger">
<i class="fa fa-exclamation-circle red-icon" aria-hidden="true" style="margin-right: 2px;"></i>
These reservations would exceed the resources currently available in the cluster.
</div>
</div>
<!-- !cpu-limit-input -->
<!-- #endregion -->
@ -1394,7 +1401,7 @@
class="form-control"
name="ingress_class_{{ $index }}"
ng-model="publishedPort.IngressName"
ng-options="ingress.Name as ingress.Name for ingress in ctrl.filteredIngresses"
ng-options="ingress.Name as ingress.Name for ingress in ctrl.ingresses"
ng-required="!publishedPort.NeedsDeletion"
ng-change="ctrl.onChangePortMappingIngress($index)"
ng-disabled="ctrl.disableLoadBalancerEdit() || ctrl.isEditAndNotNewPublishedPort($index)"
@ -1601,10 +1608,10 @@
old-form-values="ctrl.savedFormValues"
></kubernetes-summary-view>
</div>
<div class="col-sm-12 form-section-title" ng-if="ctrl.state.appType !== ctrl.KubernetesDeploymentTypes.GIT">
Actions
</div>
<!-- #region ACTIONS -->
<div class="form-group">
<div class="col-sm-12">

View file

@ -51,7 +51,8 @@ class KubernetesCreateApplicationController {
KubernetesPersistentVolumeClaimService,
KubernetesVolumeService,
RegistryService,
StackService
StackService,
KubernetesNodesLimitsService
) {
this.$async = $async;
this.$state = $state;
@ -68,6 +69,7 @@ class KubernetesCreateApplicationController {
this.KubernetesPersistentVolumeClaimService = KubernetesPersistentVolumeClaimService;
this.RegistryService = RegistryService;
this.StackService = StackService;
this.KubernetesNodesLimitsService = KubernetesNodesLimitsService;
this.ApplicationDeploymentTypes = KubernetesApplicationDeploymentTypes;
this.ApplicationDataAccessPolicies = KubernetesApplicationDataAccessPolicies;
@ -98,6 +100,10 @@ class KubernetesCreateApplicationController {
memory: 0,
cpu: 0,
},
namespaceLimits: {
memory: 0,
cpu: 0,
},
resourcePoolHasQuota: false,
viewReady: false,
availableSizeUnits: ['MB', 'GB', 'TB'],
@ -406,7 +412,7 @@ class KubernetesCreateApplicationController {
/* #region PUBLISHED PORTS UI MANAGEMENT */
addPublishedPort() {
const p = new KubernetesApplicationPublishedPortFormValue();
const ingresses = this.filteredIngresses;
const ingresses = this.ingresses;
p.IngressName = ingresses && ingresses.length ? ingresses[0].Name : undefined;
p.IngressHost = ingresses && ingresses.length ? ingresses[0].Hosts[0] : undefined;
p.IngressHosts = ingresses && ingresses.length ? ingresses[0].Hosts : undefined;
@ -417,7 +423,7 @@ class KubernetesCreateApplicationController {
}
resetPublishedPorts() {
const ingresses = this.filteredIngresses;
const ingresses = this.ingresses;
_.forEach(this.formValues.PublishedPorts, (p) => {
p.IngressName = ingresses && ingresses.length ? ingresses[0].Name : undefined;
p.IngressHost = ingresses && ingresses.length ? ingresses[0].Hosts[0] : undefined;
@ -476,7 +482,7 @@ class KubernetesCreateApplicationController {
onChangePortMappingIngress(index) {
const publishedPort = this.formValues.PublishedPorts[index];
const ingress = _.find(this.filteredIngresses, { Name: publishedPort.IngressName });
const ingress = _.find(this.ingresses, { Name: publishedPort.IngressName });
publishedPort.IngressHosts = ingress.Hosts;
this.ingressHostnames = ingress.Hosts;
publishedPort.IngressHost = this.ingressHostnames.length ? this.ingressHostnames[0] : [];
@ -624,14 +630,28 @@ class KubernetesCreateApplicationController {
return !this.state.sliders.memory.max || !this.state.sliders.cpu.max;
}
resourceReservationsOverflow() {
const instances = this.formValues.ReplicaCount;
nodeLimitsOverflow() {
const cpu = this.formValues.CpuLimit;
const maxCpu = this.state.sliders.cpu.max;
const memory = this.formValues.MemoryLimit;
const maxMemory = this.state.sliders.memory.max;
const memory = KubernetesResourceReservationHelper.bytesValue(this.formValues.MemoryLimit);
if (cpu * instances > maxCpu) {
const overflow = this.nodesLimits.overflowForReplica(cpu, memory, 1);
return overflow;
}
effectiveInstances() {
return this.formValues.DeploymentType === this.ApplicationDeploymentTypes.GLOBAL ? this.nodeNumber : this.formValues.ReplicaCount;
}
resourceReservationsOverflow() {
const instances = this.effectiveInstances();
const cpu = this.formValues.CpuLimit;
const maxCpu = this.state.namespaceLimits.cpu;
const memory = KubernetesResourceReservationHelper.bytesValue(this.formValues.MemoryLimit);
const maxMemory = this.state.namespaceLimits.memory;
// multiply 1000 can avoid 0.1 * 3 > 0.3
if (cpu * 1000 * instances > maxCpu * 1000) {
return true;
}
@ -639,17 +659,23 @@ class KubernetesCreateApplicationController {
return true;
}
return false;
if (this.formValues.DeploymentType === this.ApplicationDeploymentTypes.REPLICATED) {
return this.nodesLimits.overflowForReplica(cpu, memory, instances);
}
// DeploymentType == GLOBAL
return this.nodesLimits.overflowForGlobal(cpu, memory);
}
autoScalerOverflow() {
const instances = this.formValues.AutoScaler.MaxReplicas;
const cpu = this.formValues.CpuLimit;
const maxCpu = this.state.sliders.cpu.max;
const memory = this.formValues.MemoryLimit;
const maxMemory = this.state.sliders.memory.max;
const maxCpu = this.state.namespaceLimits.cpu;
const memory = KubernetesResourceReservationHelper.bytesValue(this.formValues.MemoryLimit);
const maxMemory = this.state.namespaceLimits.memory;
if (cpu * instances > maxCpu) {
// multiply 1000 can avoid 0.1 * 3 > 0.3
if (cpu * 1000 * instances > maxCpu * 1000) {
return true;
}
@ -657,7 +683,7 @@ class KubernetesCreateApplicationController {
return true;
}
return false;
return this.nodesLimits.overflowForReplica(cpu, memory, instances);
}
publishViaLoadBalancerEnabled() {
@ -665,7 +691,7 @@ class KubernetesCreateApplicationController {
}
publishViaIngressEnabled() {
return this.filteredIngresses.length;
return this.ingresses.length;
}
isEditAndNoChangesMade() {
@ -773,50 +799,66 @@ class KubernetesCreateApplicationController {
/* #region DATA AUTO REFRESH */
updateSliders() {
const quota = this.formValues.ResourcePool.Quota;
let minCpu = 0,
minMemory = 0,
maxCpu = this.state.namespaceLimits.cpu,
maxMemory = this.state.namespaceLimits.memory;
if (quota) {
if (quota.CpuLimit) {
minCpu = KubernetesApplicationQuotaDefaults.CpuLimit;
}
if (quota.MemoryLimit) {
minMemory = KubernetesResourceReservationHelper.bytesValue(KubernetesApplicationQuotaDefaults.MemoryLimit);
}
}
maxCpu = Math.min(maxCpu, this.nodesLimits.MaxCPU);
maxMemory = Math.min(maxMemory, this.nodesLimits.MaxMemory);
if (maxMemory < minMemory) {
minMemory = 0;
maxMemory = 0;
}
this.state.sliders.memory.min = KubernetesResourceReservationHelper.megaBytesValue(minMemory);
this.state.sliders.memory.max = KubernetesResourceReservationHelper.megaBytesValue(maxMemory);
this.state.sliders.cpu.min = minCpu;
this.state.sliders.cpu.max = _.floor(maxCpu, 2);
if (!this.state.isEdit) {
this.formValues.CpuLimit = minCpu;
this.formValues.MemoryLimit = KubernetesResourceReservationHelper.megaBytesValue(minMemory);
}
}
updateNamespaceLimits() {
let maxCpu = this.state.nodes.cpu;
let maxMemory = this.state.nodes.memory;
const quota = this.formValues.ResourcePool.Quota;
this.state.resourcePoolHasQuota = false;
const quota = this.formValues.ResourcePool.Quota;
let minCpu,
maxCpu,
minMemory,
maxMemory = 0;
if (quota) {
if (quota.CpuLimit) {
this.state.resourcePoolHasQuota = true;
minCpu = KubernetesApplicationQuotaDefaults.CpuLimit;
maxCpu = quota.CpuLimit - quota.CpuLimitUsed;
if (this.state.isEdit && this.savedFormValues.CpuLimit) {
maxCpu += this.savedFormValues.CpuLimit * this.savedFormValues.ReplicaCount;
maxCpu += this.savedFormValues.CpuLimit * this.effectiveInstances();
}
} else {
minCpu = 0;
maxCpu = this.state.nodes.cpu;
}
if (quota.MemoryLimit) {
this.state.resourcePoolHasQuota = true;
minMemory = KubernetesApplicationQuotaDefaults.MemoryLimit;
maxMemory = quota.MemoryLimit - quota.MemoryLimitUsed;
if (this.state.isEdit && this.savedFormValues.MemoryLimit) {
maxMemory += KubernetesResourceReservationHelper.bytesValue(this.savedFormValues.MemoryLimit) * this.savedFormValues.ReplicaCount;
maxMemory += KubernetesResourceReservationHelper.bytesValue(this.savedFormValues.MemoryLimit) * this.effectiveInstances();
}
} else {
minMemory = 0;
maxMemory = this.state.nodes.memory;
}
} else {
minCpu = 0;
maxCpu = this.state.nodes.cpu;
minMemory = 0;
maxMemory = this.state.nodes.memory;
}
this.state.sliders.memory.min = minMemory;
this.state.sliders.memory.max = KubernetesResourceReservationHelper.megaBytesValue(maxMemory);
this.state.sliders.cpu.min = minCpu;
this.state.sliders.cpu.max = _.round(maxCpu, 2);
if (!this.state.isEdit) {
this.formValues.CpuLimit = minCpu;
this.formValues.MemoryLimit = minMemory;
}
this.state.namespaceLimits.cpu = maxCpu;
this.state.namespaceLimits.memory = maxMemory;
}
refreshStacks(namespace) {
@ -870,16 +912,22 @@ class KubernetesCreateApplicationController {
}
refreshIngresses(namespace) {
this.filteredIngresses = _.filter(this.ingresses, { Namespace: namespace });
this.ingressHostnames = this.filteredIngresses.length ? this.filteredIngresses[0].Hosts : [];
if (!this.publishViaIngressEnabled()) {
if (this.savedFormValues) {
this.formValues.PublishingType = this.savedFormValues.PublishingType;
} else {
this.formValues.PublishingType = this.ApplicationPublishingTypes.INTERNAL;
return this.$async(async () => {
try {
this.ingresses = await this.KubernetesIngressService.get(namespace);
this.ingressHostnames = this.ingresses.length ? this.ingresses[0].Hosts : [];
if (!this.publishViaIngressEnabled()) {
if (this.savedFormValues) {
this.formValues.PublishingType = this.savedFormValues.PublishingType;
} else {
this.formValues.PublishingType = this.ApplicationPublishingTypes.INTERNAL;
}
}
this.formValues.OriginalIngresses = this.ingresses;
} catch (err) {
this.Notifications.error('Failure', err, 'Unable to retrieve ingresses');
}
}
this.formValues.OriginalIngresses = this.filteredIngresses;
});
}
refreshNamespaceData(namespace) {
@ -904,6 +952,7 @@ class KubernetesCreateApplicationController {
onResourcePoolSelectionChange() {
return this.$async(async () => {
const namespace = this.formValues.ResourcePool.Namespace.Name;
this.updateNamespaceLimits();
this.updateSliders();
await this.refreshNamespaceData(namespace);
this.resetFormValues();
@ -988,12 +1037,12 @@ class KubernetesCreateApplicationController {
this.state.useLoadBalancer = this.endpoint.Kubernetes.Configuration.UseLoadBalancer;
this.state.useServerMetrics = this.endpoint.Kubernetes.Configuration.UseServerMetrics;
const [resourcePools, nodes, ingresses] = await Promise.all([
const [resourcePools, nodes, nodesLimits] = await Promise.all([
this.KubernetesResourcePoolService.get(),
this.KubernetesNodeService.get(),
this.KubernetesIngressService.get(),
this.KubernetesNodesLimitsService.get(),
]);
this.ingresses = ingresses;
this.nodesLimits = nodesLimits;
this.resourcePools = _.filter(resourcePools, (resourcePool) => !KubernetesNamespaceHelper.isSystemNamespace(resourcePool.Namespace.Name));
this.formValues.ResourcePool = this.resourcePools[0];
@ -1006,6 +1055,7 @@ class KubernetesCreateApplicationController {
this.state.nodes.cpu += item.CPU;
});
this.nodesLabels = KubernetesNodeHelper.generateNodeLabelsFromNodes(nodes);
this.nodeNumber = nodes.length;
const namespace = this.state.isEdit ? this.$state.params.namespace : this.formValues.ResourcePool.Namespace.Name;
await this.refreshNamespaceData(namespace);
@ -1018,7 +1068,7 @@ class KubernetesCreateApplicationController {
this.configurations,
this.persistentVolumeClaims,
this.nodesLabels,
this.filteredIngresses
this.ingresses
);
if (this.application.ApplicationKind) {
@ -1031,7 +1081,7 @@ class KubernetesCreateApplicationController {
}
}
this.formValues.OriginalIngresses = this.filteredIngresses;
this.formValues.OriginalIngresses = this.ingresses;
this.formValues.ImageModel = await this.parseImageConfiguration(this.formValues.ImageModel);
this.savedFormValues = angular.copy(this.formValues);
delete this.formValues.ApplicationType;
@ -1048,8 +1098,13 @@ class KubernetesCreateApplicationController {
await this.refreshNamespaceData(namespace);
} else {
this.formValues.AutoScaler = KubernetesApplicationHelper.generateAutoScalerFormValueFromHorizontalPodAutoScaler(null, this.formValues.ReplicaCount);
this.formValues.OriginalIngressClasses = angular.copy(this.ingresses);
}
if (this.state.isEdit) {
this.nodesLimits.excludesPods(this.application.Pods, this.formValues.CpuLimit, KubernetesResourceReservationHelper.bytesValue(this.formValues.MemoryLimit));
}
this.updateNamespaceLimits();
this.updateSliders();
} catch (err) {
this.Notifications.error('Failure', err, 'Unable to load view data');

View file

@ -293,7 +293,7 @@ class KubernetesResourcePoolController {
this.state.ingressesLoading = true;
try {
const namespace = this.pool.Namespace.Name;
this.allIngresses = await this.KubernetesIngressService.get();
this.allIngresses = await this.KubernetesIngressService.get(this.state.hasWriteAuthorization ? '' : namespace);
this.ingresses = _.filter(this.allIngresses, { Namespace: namespace });
_.forEach(this.ingresses, (ing) => {
ing.Namespace = namespace;

View file

@ -1,12 +1,4 @@
import { KEY_REGEX, VALUE_REGEX } from '@/portainer/helpers/env-vars';
class EnvironmentVariablesSimpleModeItemController {
/* @ngInject */
constructor() {
this.KEY_REGEX = KEY_REGEX;
this.VALUE_REGEX = VALUE_REGEX;
}
onChangeName(name) {
const fieldIsInvalid = typeof name === 'undefined';
if (fieldIsInvalid) {

View file

@ -9,7 +9,6 @@
placeholder="e.g. FOO"
ng-model="$ctrl.variable.name"
ng-disabled="$ctrl.variable.added"
ng-pattern="$ctrl.KEY_REGEX"
ng-change="$ctrl.onChangeName($ctrl.variable.name)"
required
/>
@ -36,7 +35,6 @@
ng-model="$ctrl.variable.value"
placeholder="e.g. bar"
ng-trim="false"
ng-pattern="$ctrl.VALUE_REGEX"
name="value"
ng-change="$ctrl.onChangeValue($ctrl.variable.value)"
/>

View file

@ -1,7 +1,6 @@
import _ from 'lodash-es';
export const KEY_REGEX = /[a-zA-Z]([-_a-zA-Z0-9]*[a-zA-Z0-9])?/.source;
export const KEY_REGEX = /(.+)/.source;
export const VALUE_REGEX = /(.*)?/.source;
const KEY_VALUE_REGEX = new RegExp(`^(${KEY_REGEX})\\s*=(${VALUE_REGEX})$`);
@ -16,7 +15,7 @@ export function parseDotEnvFile(src) {
return parseArrayOfStrings(
_.compact(src.split(NEWLINES_REGEX))
.map((v) => v.trim())
.filter((v) => !v.startsWith('#'))
.filter((v) => !v.startsWith('#') && v !== '')
);
}
@ -40,7 +39,7 @@ export function parseArrayOfStrings(array) {
const parsedKeyValArr = variableString.trim().match(KEY_VALUE_REGEX);
if (parsedKeyValArr != null && parsedKeyValArr.length > 4) {
return { name: parsedKeyValArr[1], value: parsedKeyValArr[3] || '' };
return { name: parsedKeyValArr[1].trim(), value: parsedKeyValArr[3].trim() || '' };
}
})
);

View file

@ -10,6 +10,7 @@ export function SettingsViewModel(data) {
this.EnableEdgeComputeFeatures = data.EnableEdgeComputeFeatures;
this.UserSessionTimeout = data.UserSessionTimeout;
this.EnableTelemetry = data.EnableTelemetry;
this.KubeconfigExpiry = data.KubeconfigExpiry;
}
export function PublicSettingsViewModel(settings) {

View file

@ -118,6 +118,24 @@
</div>
</div>
<!-- !edge -->
<!-- kube -->
<div class="col-sm-12 form-section-title">
Kubernetes
</div>
<div class="form-group">
<label for="edge_checkin" class="col-sm-2 control-label text-left">
Kubeconfig expiry
</label>
<div class="col-sm-10">
<select
id="kubeconfig_expiry"
class="form-control"
ng-model="settings.KubeconfigExpiry"
ng-options="opt.value as opt.key for opt in state.availableKubeconfigExpiryOptions"
></select>
</div>
</div>
<!-- ! kube -->
<!-- actions -->
<div class="form-group">
<div class="col-sm-12">

View file

@ -24,7 +24,28 @@ angular.module('portainer.app').controller('SettingsController', [
value: 30,
},
],
availableKubeconfigExpiryOptions: [
{
key: '1 day',
value: '24h',
},
{
key: '7 days',
value: `${24 * 7}h`,
},
{
key: '30 days',
value: `${24 * 30}h`,
},
{
key: '1 year',
value: `${24 * 30 * 12}h`,
},
{
key: 'No expiry',
value: '0',
},
],
backupInProgress: false,
};