From a436bcc828fbae754d1aa1d402b7f6f47dbd33cd Mon Sep 17 00:00:00 2001 From: Westly Wright Date: Thu, 30 Apr 2020 09:26:51 -0700 Subject: [PATCH] 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 --- app/components/cru-registry/component.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/app/components/cru-registry/component.js b/app/components/cru-registry/component.js index fe25dc408..6439baa3c 100644 --- a/app/components/cru-registry/component.js +++ b/app/components/cru-registry/component.js @@ -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); } },