mirror of
https://github.com/portainer/portainer.git
synced 2025-07-19 21:39:40 +02:00
commite4605d990d
Author: yi-portainer <yi.chen@portainer.io> Date: Tue Feb 2 17:42:57 2021 +1300 * update portainer version commit768697157c
Author: LP B <xAt0mZ@users.noreply.github.com> Date: Tue Feb 2 05:00:19 2021 +0100 sec(app): remove unused and vulnerable dependencies (#4801) commitd3086da139
Author: cong meng <mcpacino@gmail.com> Date: Tue Feb 2 15:10:06 2021 +1300 fix(k8s) trigger port validation while changing protocol (ce#394) (#4804) Co-authored-by: Simon Meng <simon.meng@portainer.io> commit95894e8047
Author: cong meng <mcpacino@gmail.com> Date: Tue Feb 2 15:03:11 2021 +1300 fix(k8s) parse empty configuration as empty string yaml instead of {} (ce#395) (#4805) Co-authored-by: Simon Meng <simon.meng@portainer.io> commit81de55fedd
Author: Yi Chen <69284638+yi-portainer@users.noreply.github.com> Date: Tue Feb 2 11:12:40 2021 +1300 * fix missing kubectl download (#4802) commit84827b8782
Author: Steven Kang <skan070@gmail.com> Date: Sun Jan 31 17:32:30 2021 +1300 feat(build): introducing buildx for Windows (#4792) * feat(build): introducing buildx for Windows * feat(build): re-ordered USER * feat(build): Fixed Typo * feat(build): fixed typo
73 lines
2.4 KiB
JavaScript
73 lines
2.4 KiB
JavaScript
import { KubernetesConfigurationTypes } from 'Kubernetes/models/configuration/models';
|
|
import { KubernetesConfigurationFormValuesEntry } from 'Kubernetes/models/configuration/formvalues';
|
|
import _ from 'lodash-es';
|
|
import YAML from 'yaml';
|
|
|
|
class KubernetesConfigurationHelper {
|
|
static getUsingApplications(config, applications) {
|
|
return _.filter(applications, (app) => {
|
|
let envFind;
|
|
let volumeFind;
|
|
if (config.Type === KubernetesConfigurationTypes.CONFIGMAP) {
|
|
envFind = _.find(app.Env, { valueFrom: { configMapKeyRef: { name: config.Name } } });
|
|
volumeFind = _.find(app.Volumes, { configMap: { name: config.Name } });
|
|
} else {
|
|
envFind = _.find(app.Env, { valueFrom: { secretKeyRef: { name: config.Name } } });
|
|
volumeFind = _.find(app.Volumes, { secret: { secretName: config.Name } });
|
|
}
|
|
return envFind || volumeFind;
|
|
});
|
|
}
|
|
|
|
static isSystemToken(config) {
|
|
return _.startsWith(config.Name, 'default-token-');
|
|
}
|
|
|
|
static isBinary(encoding) {
|
|
return encoding !== '' && !_.includes(encoding, 'ISO') && !_.includes(encoding, 'UTF');
|
|
}
|
|
|
|
static setConfigurationUsed(config) {
|
|
config.Used = config.Applications && config.Applications.length !== 0;
|
|
}
|
|
|
|
static setConfigurationsUsed(configurations, applications) {
|
|
_.forEach(configurations, (config) => {
|
|
config.Applications = KubernetesConfigurationHelper.getUsingApplications(config, applications);
|
|
KubernetesConfigurationHelper.setConfigurationUsed(config);
|
|
});
|
|
}
|
|
|
|
static parseYaml(formValues) {
|
|
YAML.defaultOptions.customTags = ['binary'];
|
|
const data = _.map(YAML.parse(formValues.DataYaml), (value, key) => {
|
|
const entry = new KubernetesConfigurationFormValuesEntry();
|
|
entry.Key = key;
|
|
entry.Value = value;
|
|
const oldEntry = _.find(formValues.Data, { Key: entry.Key });
|
|
entry.IsBinary = oldEntry ? oldEntry.IsBinary : false;
|
|
return entry;
|
|
});
|
|
return data;
|
|
}
|
|
|
|
static parseData(formValues) {
|
|
if (!formValues.Data.length) return '';
|
|
|
|
const data = _.reduce(
|
|
formValues.Data,
|
|
(acc, entry) => {
|
|
acc[entry.Key] = entry.Value;
|
|
return acc;
|
|
},
|
|
{}
|
|
);
|
|
return YAML.stringify(data);
|
|
}
|
|
|
|
static isExternalConfiguration(configuration) {
|
|
return !configuration.ConfigurationOwner;
|
|
}
|
|
}
|
|
|
|
export default KubernetesConfigurationHelper;
|