backport of commit a35acdb84e2445930598663bb8cbc133e9832b4d (#19264)
Co-authored-by: Phil Renaud <phil.renaud@hashicorp.com>
This commit is contained in:
parent
655b6fa97f
commit
c7086d5a96
|
@ -0,0 +1,3 @@
|
||||||
|
```release-note:bug
|
||||||
|
ui: fix an issue where starting a stopped job with default-less variables would not retain those variables when done via the job page start button in the web ui
|
||||||
|
```
|
|
@ -11,6 +11,7 @@ import { task } from 'ember-concurrency';
|
||||||
import messageFromAdapterError from 'nomad-ui/utils/message-from-adapter-error';
|
import messageFromAdapterError from 'nomad-ui/utils/message-from-adapter-error';
|
||||||
import localStorageProperty from 'nomad-ui/utils/properties/local-storage';
|
import localStorageProperty from 'nomad-ui/utils/properties/local-storage';
|
||||||
import { tracked } from '@glimmer/tracking';
|
import { tracked } from '@glimmer/tracking';
|
||||||
|
import jsonToHcl from 'nomad-ui/utils/json-to-hcl';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JobEditor component that provides an interface for editing and managing Nomad jobs.
|
* JobEditor component that provides an interface for editing and managing Nomad jobs.
|
||||||
|
@ -39,9 +40,7 @@ export default class JobEditor extends Component {
|
||||||
if (this.args.variables) {
|
if (this.args.variables) {
|
||||||
this.args.job.set(
|
this.args.job.set(
|
||||||
'_newDefinitionVariables',
|
'_newDefinitionVariables',
|
||||||
this.jsonToHcl(this.args.variables.flags).concat(
|
jsonToHcl(this.args.variables.flags).concat(this.args.variables.literal)
|
||||||
this.args.variables.literal
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -258,24 +257,6 @@ export default class JobEditor extends Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert a JSON object to an HCL string.
|
|
||||||
*
|
|
||||||
* @param {Object} obj - The JSON object to convert.
|
|
||||||
* @returns {string} The HCL string representation of the JSON object.
|
|
||||||
*/
|
|
||||||
jsonToHcl(obj) {
|
|
||||||
const hclLines = [];
|
|
||||||
|
|
||||||
for (const key in obj) {
|
|
||||||
const value = obj[key];
|
|
||||||
const hclValue = typeof value === 'string' ? `"${value}"` : value;
|
|
||||||
hclLines.push(`${key}=${hclValue}\n`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return hclLines.join('\n');
|
|
||||||
}
|
|
||||||
|
|
||||||
get data() {
|
get data() {
|
||||||
return {
|
return {
|
||||||
cancelable: this.args.cancelable,
|
cancelable: this.args.cancelable,
|
||||||
|
|
|
@ -10,6 +10,7 @@ import { inject as service } from '@ember/service';
|
||||||
import messageFromAdapterError from 'nomad-ui/utils/message-from-adapter-error';
|
import messageFromAdapterError from 'nomad-ui/utils/message-from-adapter-error';
|
||||||
import { tagName } from '@ember-decorators/component';
|
import { tagName } from '@ember-decorators/component';
|
||||||
import classic from 'ember-classic-decorator';
|
import classic from 'ember-classic-decorator';
|
||||||
|
import jsonToHcl from 'nomad-ui/utils/json-to-hcl';
|
||||||
|
|
||||||
@classic
|
@classic
|
||||||
@tagName('')
|
@tagName('')
|
||||||
|
@ -76,6 +77,16 @@ export default class Title extends Component {
|
||||||
// In the event that this fails, fall back to the raw definition.
|
// In the event that this fails, fall back to the raw definition.
|
||||||
try {
|
try {
|
||||||
const specification = yield job.fetchRawSpecification();
|
const specification = yield job.fetchRawSpecification();
|
||||||
|
|
||||||
|
let _newDefinitionVariables = job.get('_newDefinitionVariables') || '';
|
||||||
|
if (specification.VariableFlags) {
|
||||||
|
_newDefinitionVariables += jsonToHcl(specification.VariableFlags);
|
||||||
|
}
|
||||||
|
if (specification.Variables) {
|
||||||
|
_newDefinitionVariables += specification.Variables;
|
||||||
|
}
|
||||||
|
job.set('_newDefinitionVariables', _newDefinitionVariables);
|
||||||
|
|
||||||
job.set('_newDefinition', specification.Source);
|
job.set('_newDefinition', specification.Source);
|
||||||
} catch {
|
} catch {
|
||||||
const definition = yield job.fetchRawDefinition();
|
const definition = yield job.fetchRawDefinition();
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) HashiCorp, Inc.
|
||||||
|
* SPDX-License-Identifier: BUSL-1.1
|
||||||
|
*/
|
||||||
|
|
||||||
|
// @ts-check
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert a JSON object to an HCL string.
|
||||||
|
*
|
||||||
|
* @param {Object} obj - The JSON object to convert.
|
||||||
|
* @returns {string} The HCL string representation of the JSON object.
|
||||||
|
*/
|
||||||
|
export default function jsonToHcl(obj) {
|
||||||
|
const hclLines = [];
|
||||||
|
|
||||||
|
for (const key in obj) {
|
||||||
|
const value = obj[key];
|
||||||
|
const hclValue = typeof value === 'string' ? `"${value}"` : value;
|
||||||
|
hclLines.push(`${key}=${hclValue}\n`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return hclLines.join('\n');
|
||||||
|
}
|
Loading…
Reference in New Issue