Skip to content

Commit

Permalink
Merge pull request #12082 from hashicorp/f-ui/refactor-namespace
Browse files Browse the repository at this point in the history
namespace refactoring
  • Loading branch information
ChaiWithJai committed Feb 17, 2022
2 parents 36e31c5 + 02218c6 commit cc3a7bf
Show file tree
Hide file tree
Showing 30 changed files with 802 additions and 414 deletions.
6 changes: 2 additions & 4 deletions ui/app/components/breadcrumbs/job.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
<li>
<LinkTo
@route="jobs.job.index"
@model={{trigger.data.result.plainId}}
@query={{hash namespace=(or trigger.data.result.namespace.name "default")}}
@model={{trigger.data.result}}
data-test-breadcrumb={{"jobs.job.index"}}
>
<dl>
Expand All @@ -30,8 +29,7 @@
<li>
<LinkTo
@route="jobs.job.index"
@model={{this.job.plainId}}
@query={{hash namespace=(or this.job.namespace.name "default")}}
@model={{this.job}}
data-test-breadcrumb={{"jobs.job.index"}}
data-test-job-breadcrumb
>
Expand Down
9 changes: 6 additions & 3 deletions ui/app/components/job-dispatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,12 @@ export default class JobDispatch extends Component {
const dispatch = yield this.args.job.dispatch(paramValues, this.payload);

// Navigate to the newly created instance.
this.router.transitionTo('jobs.job', dispatch.DispatchedJobID, {
queryParams: { namespace: this.args.job.get('namespace.name') },
});
const namespaceId = this.args.job.belongsTo('namespace').id();
const jobId = namespaceId
? `${dispatch.DispatchedJobID}@${namespaceId}`
: dispatch.DispatchedJobID;

this.router.transitionTo('jobs.job', jobId);
} catch (err) {
const error = messageFromAdapterError(err) || 'Could not dispatch job';
this.errors.pushObject(error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export default class JobClientStatusSummary extends Component {
this.router.transitionTo('jobs.job.clients', this.job, {
queryParams: {
status: JSON.stringify(statusFilter),
namespace: this.job.get('namespace.name'),
},
});
}
Expand Down
4 changes: 1 addition & 3 deletions ui/app/components/job-row.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ export default class JobRow extends Component {
@action
gotoJob() {
const { job } = this;
this.router.transitionTo('jobs.job', job.plainId, {
queryParams: { namespace: job.get('namespace.name') },
});
this.router.transitionTo('jobs.job.index', job.idWithNamespace);
}
}
3 changes: 1 addition & 2 deletions ui/app/controllers/allocations/allocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ export default class AllocationsAllocationController extends Controller {
label: allocation.taskGroupName,
args: [
'jobs.job.task-group',
job.plainId,
job.idWithNamespace,
allocation.taskGroupName,
jobQueryParams,
],
},
{
Expand Down
7 changes: 4 additions & 3 deletions ui/app/controllers/csi/volumes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,10 @@ export default class IndexController extends Controller.extend(
gotoVolume(volume, event) {
lazyClick([
() =>
this.transitionToRoute('csi.volumes.volume', volume.get('plainId'), {
queryParams: { volumeNamespace: volume.get('namespace.name') },
}),
this.transitionToRoute(
'csi.volumes.volume',
volume.get('idWithNamespace')
),
event,
]);
}
Expand Down
8 changes: 1 addition & 7 deletions ui/app/controllers/jobs/job/task-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import Controller from '@ember/controller';
import { action, computed, get } from '@ember/object';
import { scheduleOnce } from '@ember/runloop';
import intersection from 'lodash.intersection';
import { qpBuilder } from 'nomad-ui/utils/classes/query-params';
import Sortable from 'nomad-ui/mixins/sortable';
import Searchable from 'nomad-ui/mixins/searchable';
import WithNamespaceResetting from 'nomad-ui/mixins/with-namespace-resetting';
Expand Down Expand Up @@ -174,12 +173,7 @@ export default class TaskGroupController extends Controller.extend(
return {
title: 'Task Group',
label: name,
args: [
'jobs.job.task-group',
job,
name,
qpBuilder({ jobNamespace: job.get('namespace.name') || 'default' }),
],
args: ['jobs.job.task-group', job, name],
};
}
}
11 changes: 11 additions & 0 deletions ui/app/models/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ export default class Job extends Model {
@attr() periodicDetails;
@attr() parameterizedDetails;

@computed('plainId')
get idWithNamespace() {
const namespaceId = this.belongsTo('namespace').id();

if (!namespaceId || namespaceId === 'default') {
return this.plainId;
} else {
return `${this.plainId}@${namespaceId}`;
}
}

@computed('periodic', 'parameterized', 'dispatched')
get hasChildren() {
return this.periodic || (this.parameterized && !this.dispatched);
Expand Down
7 changes: 7 additions & 0 deletions ui/app/models/volume.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ export default class Volume extends Model {
@attr('number') controllersHealthy;
@attr('number') controllersExpected;

@computed('plainId')
get idWithNamespace() {
// does this handle default namespace -- I think the backend handles this for us
// but the client would always need to recreate that logic
return `${this.plainId}@${this.belongsTo('namespace').id()}`;
}

@computed('controllersHealthy', 'controllersExpected')
get controllersHealthyProportion() {
return this.controllersHealthy / this.controllersExpected;
Expand Down
12 changes: 8 additions & 4 deletions ui/app/routes/csi/volumes/volume.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@ export default class VolumeRoute extends Route.extend(WithWatchers) {
}

serialize(model) {
return { volume_name: model.get('plainId') };
return { volume_name: JSON.parse(model.get('id')).join('@') };
}

model(params, transition) {
const namespace = transition.to.queryParams.namespace;
const name = params.volume_name;
model(params) {
// Issue with naming collissions
const url = params.volume_name.split('@');
const namespace = url.pop();
const name = url.join('');

const fullId = JSON.stringify([`csi/${name}`, namespace || 'default']);

return RSVP.hash({
volume: this.store.findRecord('volume', fullId, { reload: true }),
namespaces: this.store.findAll('namespace'),
Expand Down
8 changes: 4 additions & 4 deletions ui/app/routes/jobs/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ export default class JobRoute extends Route {
@service token;

serialize(model) {
return { job_name: model.get('plainId') };
return { job_name: model.get('idWithNamespace') };
}

model(params, transition) {
const namespace = transition.to.queryParams.namespace || 'default';
const name = params.job_name;
model(params) {
const [name, namespace = 'default'] = params.job_name.split('@');

const fullId = JSON.stringify([name, namespace]);

return this.store
Expand Down
Loading

0 comments on commit cc3a7bf

Please sign in to comment.