Skip to content

Commit e1c8f0e

Browse files
author
Sebastian Florek
authored
Merge pull request #869 from bryk/select-namespace
Auto-select namespace in deploy form and add namespace to deamonsetlist
2 parents 243c184 + 17e20e0 commit e1c8f0e

File tree

4 files changed

+36
-6
lines changed

4 files changed

+36
-6
lines changed

src/app/frontend/daemonsetlist/daemonsetlist_stateconfig.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,13 @@ export default function stateConfig($stateProvider) {
5353

5454
/**
5555
* @param {!angular.$resource} $resource
56+
* @param {!./../chrome/chrome_state.StateParams} $stateParams
5657
* @return {!angular.$q.Promise}
5758
* @ngInject
5859
*/
59-
export function resolveDaemonSetList($resource) {
60+
export function resolveDaemonSetList($resource, $stateParams) {
6061
/** @type {!angular.Resource<!backendApi.DaemonSetList>} */
61-
let resource = $resource('api/v1/daemonset');
62+
let resource = $resource(`api/v1/daemonset/${$stateParams.namespace || ''}`);
6263

6364
return resource.get().$promise;
6465
}

src/app/frontend/deploy/deployfromsettings_controller.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ export default class DeployFromSettingsController {
3838
* @param {!angular.$resource} $resource
3939
* @param {!angular.$q} $q
4040
* @param {!md.$dialog} $mdDialog
41+
* @param {!./../chrome/chrome_state.StateParams} $stateParams
4142
* @ngInject
4243
*/
43-
constructor(namespaces, protocols, $log, $state, $resource, $q, $mdDialog) {
44+
constructor(namespaces, protocols, $log, $state, $resource, $q, $mdDialog, $stateParams) {
4445
/**
4546
* Initialized from the template.
4647
* @export {!angular.FormController}
@@ -140,7 +141,7 @@ export default class DeployFromSettingsController {
140141
* Currently chosen namespace.
141142
* @export {string}
142143
*/
143-
this.namespace = this.namespaces[0];
144+
this.namespace = $stateParams.namespace || this.namespaces[0];
144145

145146
/**
146147
* @export {?number}

src/test/frontend/daemonsetlist/daemonsetlist_stateconfig_test.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,21 @@ describe('StateConfig for daemon set list', () => {
2424
let resource = jasmine.createSpy('$resource');
2525
resource.and.returnValue({get: function() { return {$promise: promise}; }});
2626

27-
let actual = resolveDaemonSetList(resource);
27+
let actual = resolveDaemonSetList(resource, {namespace: 'foo'});
2828

29-
expect(resource).toHaveBeenCalledWith('api/v1/daemonset');
29+
expect(resource).toHaveBeenCalledWith('api/v1/daemonset/foo');
30+
expect(actual).toBe(promise);
31+
}));
32+
33+
it('should resolve daemon sets with no namespace', angular.mock.inject(($q) => {
34+
let promise = $q.defer().promise;
35+
36+
let resource = jasmine.createSpy('$resource');
37+
resource.and.returnValue({get: function() { return {$promise: promise}; }});
38+
39+
let actual = resolveDaemonSetList(resource, {});
40+
41+
expect(resource).toHaveBeenCalledWith('api/v1/daemonset/');
3042
expect(actual).toBe(promise);
3143
}));
3244
});

src/test/frontend/deploy/deployfromsettings_controller_test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,22 @@ describe('DeployFromSettings controller', () => {
6666
expect(result).toEqual('');
6767
});
6868

69+
it('should select initial namespace', angular.mock.inject(($controller) => {
70+
ctrl = $controller(
71+
DeployFromSettingController,
72+
{namespaces: {namespaces: ['foo', 'bar']}, protocols: {protocols: []}, $stateParams: {}});
73+
74+
expect(ctrl.namespace).toBe('foo');
75+
76+
ctrl = $controller(DeployFromSettingController, {
77+
namespaces: {namespaces: ['foo', 'bar']},
78+
protocols: {protocols: []},
79+
$stateParams: {namespace: 'bar'},
80+
});
81+
82+
expect(ctrl.namespace).toBe('bar');
83+
}));
84+
6985
it('should return empty string when containerImage is empty', () => {
7086
// given
7187
ctrl.containerImage = '';

0 commit comments

Comments
 (0)