diff --git a/app/components/cru-hpa/component.js b/app/components/cru-hpa/component.js index 234feb4e3..a8ce9f6f0 100644 --- a/app/components/cru-hpa/component.js +++ b/app/components/cru-hpa/component.js @@ -67,7 +67,7 @@ export default Component.extend(ViewNewEdit, ChildHook, { deploymentsChoices: computed('namespace.id', 'deployments.[]', function() { const namespaceId = get(this, 'namespace.id'); - return (get(this, 'deployments') || []).filter((w) => get(w, 'namespaceId') === namespaceId); + return (get(this, 'deployments') || []).filter((w) => get(w, 'namespaceId') === namespaceId).sortBy('displayName'); }), resourceMetricsAvailable: computed('apiServices', function() { @@ -76,6 +76,36 @@ export default Component.extend(ViewNewEdit, ChildHook, { return apiServices.find((api) => get(api, 'name').split('.').length === 4 && get(api, 'name').endsWith(RESOURCE_METRICS_API_GROUP)); }), + validate() { + this._super(); + + const intl = get(this, 'intl'); + + const errors = get(this, 'errors') || []; + + if ( get(this, 'model.minReplicas') === null ) { + errors.pushObject(intl.t('validation.required', { key: intl.t('cruHpa.minReplicas.label') })); + } + + (get(this, 'model.metrics') || []).forEach((metric) => { + if ( get(metric, 'target.type') === 'Utilization' && (!get(metric, 'target.utilization')) ) { + errors.pushObject(intl.t('validation.required', { key: intl.t('cruHpa.metrics.value.label') })); + } + + if ( get(metric, 'target.type') === 'AverageValue' && (!get(metric, 'target.averageValue')) ) { + errors.pushObject(intl.t('validation.required', { key: intl.t('cruHpa.metrics.value.label') })); + } + + if ( get(metric, 'target.type') === 'Value' && (!get(metric, 'target.value')) ) { + errors.pushObject(intl.t('validation.required', { key: intl.t('cruHpa.metrics.value.label') })); + } + }); + + set(this, 'errors', errors.uniq()); + + return errors.length === 0; + }, + willSave() { set(this, 'model.namespaceId', get(this, 'namespace.id') || '__placeholder__'); const self = this; diff --git a/app/components/cru-hpa/template.hbs b/app/components/cru-hpa/template.hbs index 7e70bfc35..5e50f6d42 100644 --- a/app/components/cru-hpa/template.hbs +++ b/app/components/cru-hpa/template.hbs @@ -122,6 +122,7 @@ nameRequired=true descriptionPlaceholder="cruHpa.description.placeholder" editing=editing + bothColClass="col span-12 mb-0 mt-5" }}
@@ -129,6 +130,7 @@ editable=isNew namespace=namespace errors=namespaceErrors + allowCreate=false registerHook=(action "registerHook") editing=editing }} @@ -166,7 +168,7 @@ {{/if}} {{input-integer - min=0 + min=1 id="input-hpa-min-replicas" max=model.maxReplicas value=model.minReplicas diff --git a/app/components/hpa-metric-row/component.js b/app/components/hpa-metric-row/component.js index 7fb42b911..cead83bbe 100644 --- a/app/components/hpa-metric-row/component.js +++ b/app/components/hpa-metric-row/component.js @@ -186,7 +186,7 @@ export default Component.extend({ } if ( metricName === MEMORY && metricTargetType === AVERAGE_VALUE && metricType === RESOURCE ) { - set(this, 'metric.target.averageValue', `${ stringValue }Mi`) + set(this, 'metric.target.averageValue', stringValue ? `${ stringValue }Mi` : null) } }), diff --git a/app/components/hpa-metric-row/template.hbs b/app/components/hpa-metric-row/template.hbs index c5ed583da..20debe685 100644 --- a/app/components/hpa-metric-row/template.hbs +++ b/app/components/hpa-metric-row/template.hbs @@ -142,7 +142,7 @@ }}
{{input-integer - min=0 + min=1 id=(concat elementId "-input-metrics-target-type") value=metric.target.utilization classNames="form-control" diff --git a/lib/shared/addon/components/form-namespace/component.js b/lib/shared/addon/components/form-namespace/component.js index 4bdda02f3..40db99a90 100644 --- a/lib/shared/addon/components/form-namespace/component.js +++ b/lib/shared/addon/components/form-namespace/component.js @@ -25,10 +25,11 @@ export default Component.extend({ reuseNamespaceId: null, createNamespace: null, - mode: REUSE, - editing: true, - required: true, - hookName: 'saveNamespace', + mode: REUSE, + editing: true, + required: true, + allowCreate: true, + hookName: 'saveNamespace', classNames: ['inline-form'], choices: null, diff --git a/lib/shared/addon/components/form-namespace/template.hbs b/lib/shared/addon/components/form-namespace/template.hbs index a27942700..eb6bc62aa 100644 --- a/lib/shared/addon/components/form-namespace/template.hbs +++ b/lib/shared/addon/components/form-namespace/template.hbs @@ -1,14 +1,16 @@ {{#if editing}}
diff --git a/translations/en-us.yaml b/translations/en-us.yaml index 2eece095a..0de5b4db8 100644 --- a/translations/en-us.yaml +++ b/translations/en-us.yaml @@ -1063,7 +1063,7 @@ cruHpa: status: label: Current Status target: - label: Scale Target + label: Workload name: placeholder: e.g. myscaler description: @@ -1071,10 +1071,10 @@ cruHpa: prompt: deployment: Select a Deployment... minReplicas: - label: Minimum Scale + label: Min Replicas placeholder: e.g. 1 maxReplicas: - label: Maximum Scale + label: Max Replicas placeholder: e.g. 10 metrics: label: Metrics