prevent useres from sending negative concurrency values

rancher/rancher#25982
This commit is contained in:
Westly Wright 2020-03-12 11:21:38 -07:00
parent 7075130421
commit 651f1f3089
No known key found for this signature in database
GPG Key ID: 4FAB3D8673DC54A3
3 changed files with 30 additions and 3 deletions

View File

@ -12,6 +12,7 @@ export default Component.extend(ClusterDriver, {
globalStore: service(),
growl: service(),
settings: service(),
intl: service(),
layout,
configField: 'importedConfig',
@ -41,8 +42,6 @@ export default Component.extend(ClusterDriver, {
if (isEmpty(this.model.cluster.k3sConfig)) {
set(this, 'model.cluster.k3sConfig', this.globalStore.createRecord({
type: 'k3sConfig',
serverConcurrency: 1,
workerConcurrency: 1,
kubernetesVersion: this.cluster.version.gitVersion
}));
}
@ -102,6 +101,30 @@ export default Component.extend(ClusterDriver, {
} ));
}),
willSave() {
const {
configField: field,
config
} = this;
let errors = [];
if (field === 'k3sConfig' && config.k3supgradeStrategy) {
// doesn't work because missing deep validation
// errors = config.k3supgradeStrategy.validationErrors();
if (config.k3supgradeStrategy.serverConcurrency <= 0 || config.k3supgradeStrategy.workerConcurrency <= 0) {
errors.push(this.intl.t('clusterNew.k3simport.errors.concurrency.negative'))
}
}
if (!isEmpty(errors)) {
set(this, 'errors', errors);
return false;
}
return this._super();
},
doneSaving() {
if ( get(this, 'isEdit') ) {
if (this.close) {

View File

@ -1,6 +1,5 @@
<div class="row">
<div class="col span-6">
<!-- TODO use form-versions here when we have the api ready -->
<label class="acc-label">Kubernetes Version</label>
<div class="form-control">
{{#input-or-display
@ -60,6 +59,7 @@
id="node-server-concurrency"
class="form-control"
type="number"
min=1
value=k3sConfig.k3supgradeStrategy.serverConcurrency
}}
{{/input-or-display}}
@ -78,6 +78,7 @@
id="node-worker-concurrency"
class="form-control"
type="number"
min=1
value=k3sConfig.k3supgradeStrategy.workerConcurrency
}}
{{/input-or-display}}

View File

@ -3820,6 +3820,9 @@ clusterNew:
k3simport:
label: Rancher K3S
shortLabel: K3S
errors:
concurrency:
negative: Only non-negative and non-zero concurrency values are valid.
huaweicce:
label: Huawei Cloud Container Engine
shortLabel: Huawei CCE