refactor cru-registry ns save logic

Not sure this every put registry secrets into the desired namespace. The
`namespaceId` was never set on the primaryResource by the namespace components,
rather those components worked on a namespace object. Ive gotten rid of
`namespaceId` and refactored to use the namespace object in its place.

rancher/rancher#26813
This commit is contained in:
Westly Wright 2020-04-30 09:26:51 -07:00
parent d0d790681a
commit a436bcc828
No known key found for this signature in database
GPG Key ID: 4FAB3D8673DC54A3
1 changed files with 9 additions and 10 deletions

View File

@ -7,6 +7,8 @@ import { PRESETS_BY_NAME } from 'ui/models/dockercredential';
import { inject as service } from '@ember/service'
import { isEmpty } from '@ember/utils';
const TEMP_NAMESPACE_ID = '__TEMP__';
export default Component.extend(ViewNewEdit, OptionallyNamespaced, {
globalStore: service(),
clusterStore: service(),
@ -82,16 +84,15 @@ export default Component.extend(ViewNewEdit, OptionallyNamespaced, {
hostname: window.location.host,
willSave() {
let pr = get(this, 'primaryResource');
const {
namespace: { id: nsId },
primaryResource: pr,
} = this;
// Namespace is required, but doesn't exist yet... so lie to the validator
let nsId = get(pr, 'namespaceId');
set(pr, 'namespaceId', nsId ? nsId : TEMP_NAMESPACE_ID);
set(pr, 'namespaceId', '__TEMP__');
let ok = this.validate();
set(pr, 'namespaceId', nsId);
return ok;
},
@ -111,13 +112,11 @@ export default Component.extend(ViewNewEdit, OptionallyNamespaced, {
doSave() {
let self = this;
let sup = self._super;
const currentProjectsNamespace = get(this, 'clusterStore').all('namespace').findBy('projectId', get(this, 'scopeService.currentProject.id'));
const { primaryResource: { namespaceId } } = this;
if (isEmpty(currentProjectsNamespace)) {
if (isEmpty(namespaceId) || namespaceId === TEMP_NAMESPACE_ID) {
return this.namespacePromise().then(() => sup.apply(self, arguments));
} else {
set(this, 'namespace', currentProjectsNamespace);
return sup.apply(self, arguments);
}
},