feat(k8s/config): disable edit used config keys (#4754)

* feat(k8s/config): tag used data keys

* feat(k8s/config): disabled edit of used data keys
pull/4889/head
Chaim Lev-Ari 2021-02-23 01:53:33 +02:00 committed by GitHub
parent c84da11a91
commit 20f8d03366
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 4 deletions

View File

@ -45,8 +45,9 @@
id="configuration_data_key_{{ index }}"
name="configuration_data_key_{{ index }}"
ng-model="$ctrl.formValues.Data[index].Key"
ng-disabled="entry.Used"
required
ng-change="$ctrl.onChangeKey()"
ng-change="$ctrl.onChangeKey(entry)"
/>
</div>
<div
@ -90,9 +91,13 @@
<div class="form-group" ng-if="$ctrl.formValues.IsSimple">
<div class="col-sm-1"></div>
<div class="col-sm-11">
<button type="button" class="btn btn-sm btn-danger" style="margin-left: 0;" ng-click="$ctrl.removeEntry(index)">
<button type="button" class="btn btn-sm btn-danger space-right" style="margin-left: 0;" ng-disabled="entry.Used" ng-click="$ctrl.removeEntry(index, entry)">
<i class="fa fa-trash-alt" aria-hidden="true"></i> Remove entry
</button>
<span class="small text-muted" ng-if="entry.Used">
<i class="fa fa-info-circle blue-icon space-right" aria-hidden="true"></i>
This key is currently used by one or more applications
</span>
</div>
</div>
</div>

View File

@ -19,7 +19,11 @@ class KubernetesConfigurationDataController {
this.showAdvancedMode = this.showAdvancedMode.bind(this);
}
onChangeKey() {
onChangeKey(entry) {
if (entry.Used) {
return;
}
this.state.duplicateKeys = KubernetesFormValidationHelper.getDuplicates(_.map(this.formValues.Data, (data) => data.Key));
this.isValid = Object.keys(this.state.duplicateKeys).length === 0;
}
@ -28,7 +32,11 @@ class KubernetesConfigurationDataController {
this.formValues.Data.push(new KubernetesConfigurationFormValuesEntry());
}
removeEntry(index) {
removeEntry(index, entry) {
if (entry.Used) {
return;
}
this.formValues.Data.splice(index, 1);
this.onChangeKey();
}

View File

@ -204,6 +204,23 @@ class KubernetesConfigurationController {
return this.$async(this.getConfigurationsAsync);
}
tagUsedDataKeys() {
const configName = this.$transition$.params().name;
const usedDataKeys = _.uniq(
this.configuration.Applications.flatMap((app) =>
app.Env.filter((e) => e.valueFrom && e.valueFrom.configMapKeyRef && e.valueFrom.configMapKeyRef.name === configName).map((e) => e.name)
)
);
this.formValues.Data = this.formValues.Data.map((variable) => {
if (!usedDataKeys.includes(variable.Key)) {
return variable;
}
return { ...variable, Used: true };
});
}
async onInit() {
try {
this.state = {
@ -228,6 +245,8 @@ class KubernetesConfigurationController {
await this.getApplications(this.configuration.Namespace);
await this.getEvents(this.configuration.Namespace);
await this.getConfigurations();
this.tagUsedDataKeys();
} catch (err) {
this.Notifications.error('Failure', err, 'Unable to load view data');
} finally {