mirror of
https://github.com/portainer/portainer.git
synced 2025-08-02 20:35:25 +02:00
feat(configurations): Review UI/UX configurations (#4691)
* feat(configurations): Review UI/UX configurations * feat(configurations): fix binary secret value * fix(frontend): populate data between simple and advanced modes (#4503) * fix(configuration): parseYaml before create configuration * fix(configurations): change c to C in ConfigurationOwner * fix(application): change configuration index to configuration key in the view * fix(configuration): resolve problem in application create with configuration not overriden. * fix(configuration): fix bad import in helper Co-authored-by: Simon Meng <simon.meng@portainer.io>
This commit is contained in:
parent
46ff8a01bc
commit
41308d570d
19 changed files with 246 additions and 73 deletions
|
@ -3,13 +3,13 @@
|
|||
Data
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="form-group" ng-if="$ctrl.isCreation">
|
||||
<div class="col-sm-12">
|
||||
<p>
|
||||
<a class="small interactive" ng-if="$ctrl.formValues.IsSimple" ng-click="$ctrl.formValues.IsSimple = false">
|
||||
<a class="small interactive" ng-if="$ctrl.formValues.IsSimple" ng-click="$ctrl.showAdvancedMode()">
|
||||
<i class="fa fa-list-ol space-right" aria-hidden="true"></i> Advanced mode
|
||||
</a>
|
||||
<a class="small interactive" ng-if="!$ctrl.formValues.IsSimple" ng-click="$ctrl.formValues.IsSimple = true">
|
||||
<a class="small interactive" ng-if="!$ctrl.formValues.IsSimple" ng-click="$ctrl.showSimpleMode()">
|
||||
<i class="fa fa-edit space-right" aria-hidden="true"></i> Simple mode
|
||||
</a>
|
||||
</p>
|
||||
|
@ -61,7 +61,7 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group" ng-if="$ctrl.formValues.IsSimple">
|
||||
<div class="form-group" ng-if="$ctrl.formValues.IsSimple && !entry.IsBinary">
|
||||
<label for="configuration_data_value_{{ index }}" class="col-sm-1 control-label text-left">Value</label>
|
||||
<div class="col-sm-11">
|
||||
<textarea
|
||||
|
@ -80,6 +80,13 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group" ng-if="$ctrl.formValues.IsSimple && entry.IsBinary">
|
||||
<label for="configuration_data_value_{{ index }}" class="col-sm-1 control-label text-left">Value</label>
|
||||
<div class="col-sm-11 control-label small text-muted text-left"
|
||||
>Binary data <portainer-tooltip position="bottom" message="This key holds binary data and cannot be displayed."></portainer-tooltip
|
||||
></div>
|
||||
</div>
|
||||
|
||||
<div class="form-group" ng-if="$ctrl.formValues.IsSimple">
|
||||
<div class="col-sm-1"></div>
|
||||
<div class="col-sm-11">
|
||||
|
|
|
@ -4,5 +4,6 @@ angular.module('portainer.kubernetes').component('kubernetesConfigurationData',
|
|||
bindings: {
|
||||
formValues: '=',
|
||||
isValid: '=',
|
||||
isCreation: '=',
|
||||
},
|
||||
});
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
import angular from 'angular';
|
||||
import _ from 'lodash-es';
|
||||
import { KubernetesConfigurationFormValuesDataEntry } from 'Kubernetes/models/configuration/formvalues';
|
||||
import chardet from 'chardet';
|
||||
import { Base64 } from 'js-base64';
|
||||
import KubernetesFormValidationHelper from 'Kubernetes/helpers/formValidationHelper';
|
||||
import KubernetesConfigurationHelper from 'Kubernetes/helpers/configurationHelper';
|
||||
import { KubernetesConfigurationFormValuesEntry } from 'Kubernetes/models/configuration/formvalues';
|
||||
|
||||
class KubernetesConfigurationDataController {
|
||||
/* @ngInject */
|
||||
|
@ -12,6 +15,8 @@ class KubernetesConfigurationDataController {
|
|||
this.editorUpdateAsync = this.editorUpdateAsync.bind(this);
|
||||
this.onFileLoad = this.onFileLoad.bind(this);
|
||||
this.onFileLoadAsync = this.onFileLoadAsync.bind(this);
|
||||
this.showSimpleMode = this.showSimpleMode.bind(this);
|
||||
this.showAdvancedMode = this.showAdvancedMode.bind(this);
|
||||
}
|
||||
|
||||
onChangeKey() {
|
||||
|
@ -20,7 +25,7 @@ class KubernetesConfigurationDataController {
|
|||
}
|
||||
|
||||
addEntry() {
|
||||
this.formValues.Data.push(new KubernetesConfigurationFormValuesDataEntry());
|
||||
this.formValues.Data.push(new KubernetesConfigurationFormValuesEntry());
|
||||
}
|
||||
|
||||
removeEntry(index) {
|
||||
|
@ -37,9 +42,20 @@ class KubernetesConfigurationDataController {
|
|||
}
|
||||
|
||||
async onFileLoadAsync(event) {
|
||||
const entry = new KubernetesConfigurationFormValuesDataEntry();
|
||||
const entry = new KubernetesConfigurationFormValuesEntry();
|
||||
const encoding = chardet.detect(Buffer.from(event.target.result));
|
||||
const decoder = new TextDecoder(encoding);
|
||||
|
||||
entry.Key = event.target.fileName;
|
||||
entry.Value = event.target.result;
|
||||
entry.IsBinary = KubernetesConfigurationHelper.isBinary(encoding);
|
||||
|
||||
if (!entry.IsBinary) {
|
||||
entry.Value = decoder.decode(event.target.result);
|
||||
} else {
|
||||
const stringValue = decoder.decode(event.target.result);
|
||||
entry.Value = Base64.encode(stringValue);
|
||||
}
|
||||
|
||||
this.formValues.Data.push(entry);
|
||||
this.onChangeKey();
|
||||
}
|
||||
|
@ -53,10 +69,20 @@ class KubernetesConfigurationDataController {
|
|||
const temporaryFileReader = new FileReader();
|
||||
temporaryFileReader.fileName = file.name;
|
||||
temporaryFileReader.onload = this.onFileLoad;
|
||||
temporaryFileReader.readAsText(file);
|
||||
temporaryFileReader.readAsArrayBuffer(file);
|
||||
}
|
||||
}
|
||||
|
||||
showSimpleMode() {
|
||||
this.formValues.IsSimple = true;
|
||||
this.formValues.Data = KubernetesConfigurationHelper.parseYaml(this.formValues);
|
||||
}
|
||||
|
||||
showAdvancedMode() {
|
||||
this.formValues.IsSimple = false;
|
||||
this.formValues.DataYaml = KubernetesConfigurationHelper.parseData(this.formValues);
|
||||
}
|
||||
|
||||
$onInit() {
|
||||
this.state = {
|
||||
duplicateKeys: {},
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import _ from 'lodash-es';
|
||||
import YAML from 'yaml';
|
||||
import { KubernetesConfigMap } from 'Kubernetes/models/config-map/models';
|
||||
import { KubernetesConfigMapCreatePayload, KubernetesConfigMapUpdatePayload } from 'Kubernetes/models/config-map/payloads';
|
||||
import { KubernetesPortainerConfigurationOwnerLabel } from 'Kubernetes/models/configuration/models';
|
||||
import { KubernetesConfigurationFormValuesEntry } from 'Kubernetes/models/configuration/formvalues';
|
||||
|
||||
class KubernetesConfigMapConverter {
|
||||
/**
|
||||
|
@ -16,7 +16,23 @@ class KubernetesConfigMapConverter {
|
|||
res.ConfigurationOwner = data.metadata.labels ? data.metadata.labels[KubernetesPortainerConfigurationOwnerLabel] : '';
|
||||
res.CreationDate = data.metadata.creationTimestamp;
|
||||
res.Yaml = yaml ? yaml.data : '';
|
||||
res.Data = data.data;
|
||||
|
||||
res.Data = _.concat(
|
||||
_.map(data.data, (value, key) => {
|
||||
const entry = new KubernetesConfigurationFormValuesEntry();
|
||||
entry.Key = key;
|
||||
entry.Value = value;
|
||||
return entry;
|
||||
}),
|
||||
_.map(data.binaryData, (value, key) => {
|
||||
const entry = new KubernetesConfigurationFormValuesEntry();
|
||||
entry.Key = key;
|
||||
entry.Value = value;
|
||||
entry.IsBinary = true;
|
||||
return entry;
|
||||
})
|
||||
);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -41,7 +57,14 @@ class KubernetesConfigMapConverter {
|
|||
res.metadata.namespace = data.Namespace;
|
||||
const configurationOwner = _.truncate(data.ConfigurationOwner, { length: 63, omission: '' });
|
||||
res.metadata.labels[KubernetesPortainerConfigurationOwnerLabel] = configurationOwner;
|
||||
res.data = data.Data;
|
||||
|
||||
_.forEach(data.Data, (entry) => {
|
||||
if (entry.IsBinary) {
|
||||
res.binaryData[entry.Key] = entry.Value;
|
||||
} else {
|
||||
res.data[entry.Key] = entry.Value;
|
||||
}
|
||||
});
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -54,7 +77,13 @@ class KubernetesConfigMapConverter {
|
|||
res.metadata.name = data.Name;
|
||||
res.metadata.namespace = data.Namespace;
|
||||
res.metadata.labels[KubernetesPortainerConfigurationOwnerLabel] = data.ConfigurationOwner;
|
||||
res.data = data.Data;
|
||||
_.forEach(data.Data, (entry) => {
|
||||
if (entry.IsBinary) {
|
||||
res.binaryData[entry.Key] = entry.Value;
|
||||
} else {
|
||||
res.data[entry.Key] = entry.Value;
|
||||
}
|
||||
});
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -64,18 +93,7 @@ class KubernetesConfigMapConverter {
|
|||
res.Name = formValues.Name;
|
||||
res.Namespace = formValues.ResourcePool.Namespace.Name;
|
||||
res.ConfigurationOwner = formValues.ConfigurationOwner;
|
||||
if (formValues.IsSimple) {
|
||||
res.Data = _.reduce(
|
||||
formValues.Data,
|
||||
(acc, entry) => {
|
||||
acc[entry.Key] = entry.Value;
|
||||
return acc;
|
||||
},
|
||||
{}
|
||||
);
|
||||
} else {
|
||||
res.Data = YAML.parse(formValues.DataYaml);
|
||||
}
|
||||
res.Data = formValues.Data;
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import _ from 'lodash-es';
|
||||
import { KubernetesConfiguration, KubernetesConfigurationTypes } from 'Kubernetes/models/configuration/models';
|
||||
|
||||
class KubernetesConfigurationConverter {
|
||||
|
@ -9,7 +10,9 @@ class KubernetesConfigurationConverter {
|
|||
res.Namespace = secret.Namespace;
|
||||
res.CreationDate = secret.CreationDate;
|
||||
res.Yaml = secret.Yaml;
|
||||
res.Data = secret.Data;
|
||||
_.forEach(secret.Data, (entry) => {
|
||||
res.Data[entry.Key] = entry.Value;
|
||||
});
|
||||
res.ConfigurationOwner = secret.ConfigurationOwner;
|
||||
return res;
|
||||
}
|
||||
|
@ -22,7 +25,9 @@ class KubernetesConfigurationConverter {
|
|||
res.Namespace = configMap.Namespace;
|
||||
res.CreationDate = configMap.CreationDate;
|
||||
res.Yaml = configMap.Yaml;
|
||||
res.Data = configMap.Data;
|
||||
_.forEach(configMap.Data, (entry) => {
|
||||
res.Data[entry.Key] = entry.Value;
|
||||
});
|
||||
res.ConfigurationOwner = configMap.ConfigurationOwner;
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -1,17 +1,30 @@
|
|||
import { KubernetesSecretCreatePayload, KubernetesSecretUpdatePayload } from 'Kubernetes/models/secret/payloads';
|
||||
import { KubernetesApplicationSecret } from 'Kubernetes/models/secret/models';
|
||||
import YAML from 'yaml';
|
||||
import { KubernetesPortainerConfigurationDataAnnotation } from 'Kubernetes/models/configuration/models';
|
||||
import _ from 'lodash-es';
|
||||
import { KubernetesPortainerConfigurationOwnerLabel } from 'Kubernetes/models/configuration/models';
|
||||
import { KubernetesConfigurationFormValuesEntry } from 'Kubernetes/models/configuration/formvalues';
|
||||
|
||||
class KubernetesSecretConverter {
|
||||
static createPayload(secret) {
|
||||
const res = new KubernetesSecretCreatePayload();
|
||||
res.metadata.name = secret.Name;
|
||||
res.metadata.namespace = secret.Namespace;
|
||||
const configurationOwner = _.truncate(secret.configurationOwner, { length: 63, omission: '' });
|
||||
const configurationOwner = _.truncate(secret.ConfigurationOwner, { length: 63, omission: '' });
|
||||
res.metadata.labels[KubernetesPortainerConfigurationOwnerLabel] = configurationOwner;
|
||||
res.stringData = secret.Data;
|
||||
|
||||
let annotation = '';
|
||||
_.forEach(secret.Data, (entry) => {
|
||||
if (entry.IsBinary) {
|
||||
res.data[entry.Key] = entry.Value;
|
||||
annotation += annotation !== '' ? '|' + entry.Key : entry.Key;
|
||||
} else {
|
||||
res.stringData[entry.Key] = entry.Value;
|
||||
}
|
||||
});
|
||||
if (annotation !== '') {
|
||||
res.metadata.annotations[KubernetesPortainerConfigurationDataAnnotation] = annotation;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -20,7 +33,19 @@ class KubernetesSecretConverter {
|
|||
res.metadata.name = secret.Name;
|
||||
res.metadata.namespace = secret.Namespace;
|
||||
res.metadata.labels[KubernetesPortainerConfigurationOwnerLabel] = secret.ConfigurationOwner;
|
||||
res.stringData = secret.Data;
|
||||
|
||||
let annotation = '';
|
||||
_.forEach(secret.Data, (entry) => {
|
||||
if (entry.IsBinary) {
|
||||
res.data[entry.Key] = entry.Value;
|
||||
annotation += annotation !== '' ? '|' + entry.Key : entry.Key;
|
||||
} else {
|
||||
res.stringData[entry.Key] = entry.Value;
|
||||
}
|
||||
});
|
||||
if (annotation !== '') {
|
||||
res.metadata.annotations[KubernetesPortainerConfigurationDataAnnotation] = annotation;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -32,7 +57,21 @@ class KubernetesSecretConverter {
|
|||
res.ConfigurationOwner = payload.metadata.labels ? payload.metadata.labels[KubernetesPortainerConfigurationOwnerLabel] : '';
|
||||
res.CreationDate = payload.metadata.creationTimestamp;
|
||||
res.Yaml = yaml ? yaml.data : '';
|
||||
res.Data = payload.data;
|
||||
|
||||
res.Data = _.map(payload.data, (value, key) => {
|
||||
const annotations = payload.metadata.annotations ? payload.metadata.annotations[KubernetesPortainerConfigurationDataAnnotation] : '';
|
||||
const entry = new KubernetesConfigurationFormValuesEntry();
|
||||
entry.Key = key;
|
||||
entry.IsBinary = _.includes(annotations, entry.Key);
|
||||
|
||||
if (!entry.IsBinary) {
|
||||
entry.Value = atob(value);
|
||||
} else {
|
||||
entry.Value = value;
|
||||
}
|
||||
return entry;
|
||||
});
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -41,18 +80,7 @@ class KubernetesSecretConverter {
|
|||
res.Name = formValues.Name;
|
||||
res.Namespace = formValues.ResourcePool.Namespace.Name;
|
||||
res.ConfigurationOwner = formValues.ConfigurationOwner;
|
||||
if (formValues.IsSimple) {
|
||||
res.Data = _.reduce(
|
||||
formValues.Data,
|
||||
(acc, entry) => {
|
||||
acc[entry.Key] = entry.Value;
|
||||
return acc;
|
||||
},
|
||||
{}
|
||||
);
|
||||
} else {
|
||||
res.Data = YAML.parse(formValues.DataYaml);
|
||||
}
|
||||
res.Data = formValues.Data;
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
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) {
|
||||
|
@ -21,6 +23,10 @@ class KubernetesConfigurationHelper {
|
|||
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;
|
||||
}
|
||||
|
@ -32,6 +38,31 @@ class KubernetesConfigurationHelper {
|
|||
});
|
||||
}
|
||||
|
||||
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) {
|
||||
const data = _.reduce(
|
||||
formValues.Data,
|
||||
(acc, entry) => {
|
||||
acc[entry.Key] = entry.Value;
|
||||
return acc;
|
||||
},
|
||||
{}
|
||||
);
|
||||
return YAML.stringify(data);
|
||||
}
|
||||
|
||||
static isExternalConfiguration(configuration) {
|
||||
return !configuration.ConfigurationOwner;
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ const _KubernetesConfigMap = Object.freeze({
|
|||
Namespace: '',
|
||||
Yaml: '',
|
||||
ConfigurationOwner: '',
|
||||
Data: {},
|
||||
Data: [],
|
||||
});
|
||||
|
||||
export class KubernetesConfigMap {
|
||||
|
|
|
@ -6,6 +6,7 @@ import { KubernetesCommonMetadataPayload } from 'Kubernetes/models/common/payloa
|
|||
const _KubernetesConfigMapCreatePayload = Object.freeze({
|
||||
metadata: new KubernetesCommonMetadataPayload(),
|
||||
data: {},
|
||||
binaryData: {},
|
||||
});
|
||||
export class KubernetesConfigMapCreatePayload {
|
||||
constructor() {
|
||||
|
@ -19,6 +20,7 @@ export class KubernetesConfigMapCreatePayload {
|
|||
const _KubernetesConfigMapUpdatePayload = Object.freeze({
|
||||
metadata: new KubernetesCommonMetadataPayload(),
|
||||
data: {},
|
||||
binaryData: {},
|
||||
});
|
||||
export class KubernetesConfigMapUpdatePayload {
|
||||
constructor() {
|
||||
|
|
|
@ -20,16 +20,14 @@ export class KubernetesConfigurationFormValues {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* KubernetesConfigurationEntry Model
|
||||
*/
|
||||
const _KubernetesConfigurationFormValuesDataEntry = Object.freeze({
|
||||
const _KubernetesConfigurationFormValuesEntry = Object.freeze({
|
||||
Key: '',
|
||||
Value: '',
|
||||
IsBinary: false,
|
||||
});
|
||||
|
||||
export class KubernetesConfigurationFormValuesDataEntry {
|
||||
export class KubernetesConfigurationFormValuesEntry {
|
||||
constructor() {
|
||||
Object.assign(this, JSON.parse(JSON.stringify(_KubernetesConfigurationFormValuesDataEntry)));
|
||||
Object.assign(this, JSON.parse(JSON.stringify(_KubernetesConfigurationFormValuesEntry)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
export const KubernetesPortainerConfigurationOwnerLabel = 'io.portainer.kubernetes.configuration.owner';
|
||||
export const KubernetesPortainerConfigurationDataAnnotation = 'io.portainer.kubernetes.configuration.data';
|
||||
|
||||
/**
|
||||
* Configuration Model (Composite)
|
||||
|
|
|
@ -8,7 +8,7 @@ const _KubernetesApplicationSecret = Object.freeze({
|
|||
CreationDate: '',
|
||||
ConfigurationOwner: '',
|
||||
Yaml: '',
|
||||
Data: {},
|
||||
Data: [],
|
||||
});
|
||||
|
||||
export class KubernetesApplicationSecret {
|
||||
|
|
|
@ -7,6 +7,7 @@ const _KubernetesSecretCreatePayload = Object.freeze({
|
|||
metadata: new KubernetesCommonMetadataPayload(),
|
||||
type: 'Opaque',
|
||||
data: {},
|
||||
stringData: {},
|
||||
});
|
||||
|
||||
export class KubernetesSecretCreatePayload {
|
||||
|
@ -22,6 +23,7 @@ const _KubernetesSecretUpdatePayload = Object.freeze({
|
|||
metadata: new KubernetesCommonMetadataPayload(),
|
||||
type: 'Opaque',
|
||||
data: {},
|
||||
stringData: {},
|
||||
});
|
||||
|
||||
export class KubernetesSecretUpdatePayload {
|
||||
|
|
|
@ -115,8 +115,12 @@
|
|||
<a href="https://kubernetes.io/docs/concepts/configuration/secret/#secret-types" target="_blank">official documentation</a>.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<kubernetes-configuration-data ng-if="ctrl.formValues" form-values="ctrl.formValues" is-valid="ctrl.state.isDataValid"></kubernetes-configuration-data>
|
||||
<kubernetes-configuration-data
|
||||
ng-if="ctrl.formValues"
|
||||
form-values="ctrl.formValues"
|
||||
is-valid="ctrl.state.isDataValid"
|
||||
is-creation="true"
|
||||
></kubernetes-configuration-data>
|
||||
|
||||
<!-- actions -->
|
||||
<div class="col-sm-12 form-section-title" style="margin-top: 10px;">
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import angular from 'angular';
|
||||
import _ from 'lodash-es';
|
||||
import { KubernetesConfigurationFormValues, KubernetesConfigurationFormValuesDataEntry } from 'Kubernetes/models/configuration/formvalues';
|
||||
import { KubernetesConfigurationFormValues, KubernetesConfigurationFormValuesEntry } from 'Kubernetes/models/configuration/formvalues';
|
||||
import { KubernetesConfigurationTypes } from 'Kubernetes/models/configuration/models';
|
||||
import KubernetesConfigurationHelper from 'Kubernetes/helpers/configurationHelper';
|
||||
|
||||
class KubernetesCreateConfigurationController {
|
||||
/* @ngInject */
|
||||
|
@ -41,6 +42,9 @@ class KubernetesCreateConfigurationController {
|
|||
try {
|
||||
this.state.actionInProgress = true;
|
||||
this.formValues.ConfigurationOwner = this.Authentication.getUserDetails().username;
|
||||
if (!this.formValues.IsSimple) {
|
||||
this.formValues.Data = KubernetesConfigurationHelper.parseYaml(this.formValues);
|
||||
}
|
||||
await this.KubernetesConfigurationService.create(this.formValues);
|
||||
this.Notifications.success('Configuration succesfully created');
|
||||
this.$state.go('kubernetes.configurations');
|
||||
|
@ -76,7 +80,7 @@ class KubernetesCreateConfigurationController {
|
|||
};
|
||||
|
||||
this.formValues = new KubernetesConfigurationFormValues();
|
||||
this.formValues.Data.push(new KubernetesConfigurationFormValuesDataEntry());
|
||||
this.formValues.Data.push(new KubernetesConfigurationFormValuesEntry());
|
||||
|
||||
try {
|
||||
const resourcePools = await this.KubernetesResourcePoolService.get();
|
||||
|
|
|
@ -77,7 +77,12 @@
|
|||
<rd-widget>
|
||||
<rd-widget-body>
|
||||
<form ng-if="!ctrl.isSystemNamespace()" class="form-horizontal" name="kubernetesConfigurationCreationForm" autocomplete="off">
|
||||
<kubernetes-configuration-data ng-if="ctrl.formValues" form-values="ctrl.formValues" is-valid="ctrl.state.isDataValid"></kubernetes-configuration-data>
|
||||
<kubernetes-configuration-data
|
||||
ng-if="ctrl.formValues"
|
||||
form-values="ctrl.formValues"
|
||||
is-valid="ctrl.state.isDataValid"
|
||||
is-creation="false"
|
||||
></kubernetes-configuration-data>
|
||||
|
||||
<!-- actions -->
|
||||
<div class="col-sm-12 form-section-title" style="margin-top: 10px;">
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import angular from 'angular';
|
||||
import { KubernetesConfigurationFormValues, KubernetesConfigurationFormValuesDataEntry } from 'Kubernetes/models/configuration/formvalues';
|
||||
import { KubernetesConfigurationFormValues } from 'Kubernetes/models/configuration/formvalues';
|
||||
import { KubernetesConfigurationTypes } from 'Kubernetes/models/configuration/models';
|
||||
import KubernetesConfigurationHelper from 'Kubernetes/helpers/configurationHelper';
|
||||
import KubernetesConfigurationConverter from 'Kubernetes/converters/configuration';
|
||||
import KubernetesEventHelper from 'Kubernetes/helpers/eventHelper';
|
||||
import _ from 'lodash-es';
|
||||
|
||||
|
@ -14,6 +15,8 @@ class KubernetesConfigurationController {
|
|||
Notifications,
|
||||
LocalStorage,
|
||||
KubernetesConfigurationService,
|
||||
KubernetesConfigMapService,
|
||||
KubernetesSecretService,
|
||||
KubernetesResourcePoolService,
|
||||
ModalService,
|
||||
KubernetesApplicationService,
|
||||
|
@ -32,6 +35,8 @@ class KubernetesConfigurationController {
|
|||
this.KubernetesEventService = KubernetesEventService;
|
||||
this.KubernetesConfigurationTypes = KubernetesConfigurationTypes;
|
||||
this.KubernetesNamespaceHelper = KubernetesNamespaceHelper;
|
||||
this.KubernetesConfigMapService = KubernetesConfigMapService;
|
||||
this.KubernetesSecretService = KubernetesSecretService;
|
||||
|
||||
this.onInit = this.onInit.bind(this);
|
||||
this.getConfigurationAsync = this.getConfigurationAsync.bind(this);
|
||||
|
@ -126,7 +131,18 @@ class KubernetesConfigurationController {
|
|||
this.state.configurationLoading = true;
|
||||
const name = this.$transition$.params().name;
|
||||
const namespace = this.$transition$.params().namespace;
|
||||
this.configuration = await this.KubernetesConfigurationService.get(namespace, name);
|
||||
const [configMap, secret] = await Promise.allSettled([this.KubernetesConfigMapService.get(namespace, name), this.KubernetesSecretService.get(namespace, name)]);
|
||||
if (secret.status === 'fulfilled') {
|
||||
this.configuration = KubernetesConfigurationConverter.secretToConfiguration(secret.value);
|
||||
this.formValues.Data = secret.value.Data;
|
||||
} else {
|
||||
this.configuration = KubernetesConfigurationConverter.configMapToConfiguration(configMap.value);
|
||||
this.formValues.Data = configMap.value.Data;
|
||||
}
|
||||
this.formValues.ResourcePool = _.find(this.resourcePools, (resourcePool) => resourcePool.Namespace.Name === this.configuration.Namespace);
|
||||
this.formValues.Id = this.configuration.Id;
|
||||
this.formValues.Name = this.configuration.Name;
|
||||
this.formValues.Type = this.configuration.Type;
|
||||
} catch (err) {
|
||||
this.Notifications.error('Failure', err, 'Unable to retrieve configuration');
|
||||
} finally {
|
||||
|
@ -211,20 +227,6 @@ class KubernetesConfigurationController {
|
|||
await this.getConfiguration();
|
||||
await this.getApplications(this.configuration.Namespace);
|
||||
await this.getEvents(this.configuration.Namespace);
|
||||
this.formValues.ResourcePool = _.find(this.resourcePools, (resourcePool) => resourcePool.Namespace.Name === this.configuration.Namespace);
|
||||
this.formValues.Id = this.configuration.Id;
|
||||
this.formValues.Name = this.configuration.Name;
|
||||
this.formValues.Type = this.configuration.Type;
|
||||
this.formValues.Data = _.map(this.configuration.Data, (value, key) => {
|
||||
if (this.configuration.Type === KubernetesConfigurationTypes.SECRET) {
|
||||
value = atob(value);
|
||||
}
|
||||
this.formValues.DataYaml += key + ': ' + value + '\n';
|
||||
const entry = new KubernetesConfigurationFormValuesDataEntry();
|
||||
entry.Key = key;
|
||||
entry.Value = value;
|
||||
return entry;
|
||||
});
|
||||
await this.getConfigurations();
|
||||
} catch (err) {
|
||||
this.Notifications.error('Failure', err, 'Unable to load view data');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue