diff --git a/app/kubernetes/components/kubernetes-configuration-data/kubernetesConfigurationData.html b/app/kubernetes/components/kubernetes-configuration-data/kubernetesConfigurationData.html index 432b524ee..59d5c39e4 100644 --- a/app/kubernetes/components/kubernetes-configuration-data/kubernetesConfigurationData.html +++ b/app/kubernetes/components/kubernetes-configuration-data/kubernetesConfigurationData.html @@ -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)" />
- + + + This key is currently used by one or more applications +
diff --git a/app/kubernetes/components/kubernetes-configuration-data/kubernetesConfigurationDataController.js b/app/kubernetes/components/kubernetes-configuration-data/kubernetesConfigurationDataController.js index 49d44307f..09658cf23 100644 --- a/app/kubernetes/components/kubernetes-configuration-data/kubernetesConfigurationDataController.js +++ b/app/kubernetes/components/kubernetes-configuration-data/kubernetesConfigurationDataController.js @@ -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(); } diff --git a/app/kubernetes/views/configurations/edit/configurationController.js b/app/kubernetes/views/configurations/edit/configurationController.js index 3da73e396..50cd65d37 100644 --- a/app/kubernetes/views/configurations/edit/configurationController.js +++ b/app/kubernetes/views/configurations/edit/configurationController.js @@ -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 {