From 6c7d90c1ce633e873898ce711a9a2d767ce02b4a Mon Sep 17 00:00:00 2001 From: Vincent Fiduccia Date: Tue, 26 Jul 2016 14:20:55 -0700 Subject: [PATCH] Split/migrate K8s template name for backwards compatibility (#799) --- app/catalog-tab/launch/route.js | 12 ++++++--- app/components/new-catalog/component.js | 15 ++++++++--- .../orchestration/wait-steps/template.hbs | 2 +- app/models/environment.js | 26 +++++++++++++++++-- app/services/k8s.js | 2 +- app/utils/constants.js | 10 ++++--- app/utils/navigation-tree.js | 14 +++++----- app/utils/parse-externalid.js | 2 +- 8 files changed, 60 insertions(+), 23 deletions(-) diff --git a/app/catalog-tab/launch/route.js b/app/catalog-tab/launch/route.js index 0ded089aa..b7d4b7027 100644 --- a/app/catalog-tab/launch/route.js +++ b/app/catalog-tab/launch/route.js @@ -9,15 +9,21 @@ export default Ember.Route.extend({ model: function(params/*, transition*/) { var store = this.get('store'); + var version = this.get('settings.rancherVersion'); + + let url = this.get('app.catalogEndpoint')+'/templates/'+params.template; + if ( version ) + { + url = Util.addQueryParam(url, 'minimumRancherVersion_lte', version); + } var dependencies = { - tpl: store.request({url: this.get('app.catalogEndpoint')+'/templates/'+params.template}), + tpl: store.request({url: url}), }; if ( params.upgrade ) { - var version = this.get('settings.rancherVersion'); - var url = this.get('app.catalogEndpoint')+'/templateversions/'+params.upgrade; + url = this.get('app.catalogEndpoint')+'/templateversions/'+params.upgrade; if ( version ) { url = Util.addQueryParam(url, 'minimumRancherVersion_lte', version); diff --git a/app/components/new-catalog/component.js b/app/components/new-catalog/component.js index 34d8472eb..c17689fcd 100644 --- a/app/components/new-catalog/component.js +++ b/app/components/new-catalog/component.js @@ -2,11 +2,13 @@ import Ember from 'ember'; import NewOrEdit from 'ui/mixins/new-or-edit'; import ShellQuote from 'npm:shell-quote'; import C from 'ui/utils/constants'; -import { compare as compareVersion} from 'ui/utils/parse-version'; +import Util from 'ui/utils/util'; +import { compare as compareVersion } from 'ui/utils/parse-version'; export default Ember.Component.extend(NewOrEdit, { k8s: Ember.inject.service(), projects: Ember.inject.service(), + settings: Ember.inject.service(), allTemplates: null, templateResource: null, @@ -74,13 +76,18 @@ export default Ember.Component.extend(NewOrEdit, { }.property('versionsArray'), templateChanged: function() { - var link = this.get('selectedTemplateUrl'); - if (link) { + var url = this.get('selectedTemplateUrl'); + if (url) { this.set('loading', true); + var version = this.get('settings.rancherVersion'); + if ( version ) { + url = Util.addQueryParam(url, 'minimumRancherVersion_lte', version); + } + var current = this.get('environmentResource.environment'); this.get('store').request({ - url: link + url: url }).then((response) => { if (response.questions) { response.questions.forEach((item) => { diff --git a/app/components/orchestration/wait-steps/template.hbs b/app/components/orchestration/wait-steps/template.hbs index 73403d7ab..46ca030d2 100644 --- a/app/components/orchestration/wait-steps/template.hbs +++ b/app/components/orchestration/wait-steps/template.hbs @@ -15,7 +15,7 @@ {{/if}} - {{t step}}{{#if (and subCount (eq currentStep index))}} {{t 'waitOrchestration.count' sub=subStep count=subCount}}{{/if}} + {{t step}}{{#if (and subStep subCount (eq currentStep index))}} {{t 'waitOrchestration.count' sub=subStep count=subCount}}{{/if}} {{/each}} diff --git a/app/models/environment.js b/app/models/environment.js index f213d98a3..4187de4b7 100644 --- a/app/models/environment.js +++ b/app/models/environment.js @@ -192,13 +192,35 @@ var Environment = Resource.extend({ }.property('services'), externalIdInfo: function() { - return parseExternalId(this.get('externalId')); + let eid = this.get('externalId'); + let info = parseExternalId(eid); + + // Migrate kubernetes -> k8s + // 1.1.x did not send minimumRancherVersion correctly, so the catalog template + // was changed from "kubernetes" to "k8s" so that they won't upgrade from 1.2 to 1.3 + if ( info && info.kind === C.EXTERNAL_ID.KIND_SYSTEM_CATALOG ) + { + const base = C.EXTERNAL_ID.KIND_SYSTEM_CATALOG + C.EXTERNAL_ID.KIND_SEPARATOR + C.CATALOG.LIBRARY_KEY + C.EXTERNAL_ID.GROUP_SEPARATOR; + let old_prefix = base + C.EXTERNAL_ID.KIND_LEGACY_KUBERNETES + C.EXTERNAL_ID.GROUP_SEPARATOR; + let neu_prefix = base + C.EXTERNAL_ID.KIND_KUBERNETES + C.EXTERNAL_ID.GROUP_SEPARATOR; + + if ( eid.indexOf(old_prefix) === 0 ) + { + let neu = eid.replace(old_prefix,neu_prefix); + console.log('Migrating Stack ' + this.get('id') + ' from ' + eid + ' to ' + neu); + this.set('externalId', neu); + this.save(); + return parseExternalId(neu); + } + } + + return info; }.property('externalId'), grouping: function() { var kind = this.get('externalIdInfo.kind'); - if ( kind === C.EXTERNAL_ID.KIND_KUBERNETES ) + if ( kind === C.EXTERNAL_ID.KIND_KUBERNETES || kind === C.EXTERNAL_ID.KIND_LEGACY_KUBERNETES ) { return C.EXTERNAL_ID.KIND_KUBERNETES; } diff --git a/app/services/k8s.js b/app/services/k8s.js index 39b5ed4ec..1ab74de36 100644 --- a/app/services/k8s.js +++ b/app/services/k8s.js @@ -501,7 +501,7 @@ export default Ember.Service.extend({ }.property('version.{minor,major}'), filterSystemStack(stacks) { - const OLD_STACK_ID = C.EXTERNAL_ID.KIND_SYSTEM + C.EXTERNAL_ID.KIND_SEPARATOR + C.EXTERNAL_ID.KIND_KUBERNETES; + const OLD_STACK_ID = C.EXTERNAL_ID.KIND_SYSTEM + C.EXTERNAL_ID.KIND_SEPARATOR + C.EXTERNAL_ID.KIND_LEGACY_KUBERNETES; const NEW_STACK_PREFIX = C.EXTERNAL_ID.KIND_SYSTEM_CATALOG + C.EXTERNAL_ID.KIND_SEPARATOR + C.CATALOG.LIBRARY_KEY + C.EXTERNAL_ID.GROUP_SEPARATOR + C.EXTERNAL_ID.KIND_KUBERNETES + C.EXTERNAL_ID.GROUP_SEPARATOR; var stack = (stacks||[]).filter((stack) => { diff --git a/app/utils/constants.js b/app/utils/constants.js index d19d29e69..1470553de 100644 --- a/app/utils/constants.js +++ b/app/utils/constants.js @@ -2,12 +2,13 @@ const KIND_USER = 'user'; const KIND_CATALOG = 'catalog'; const KIND_SYSTEM = 'system'; const KIND_SYSTEM_CATALOG = 'system-catalog'; -const KIND_KUBERNETES = 'kubernetes'; +const KIND_LEGACY_KUBERNETES = 'kubernetes'; +const KIND_KUBERNETES = 'k8s'; const KIND_SWARM = 'swarm'; const KIND_MESOS = 'mesos'; -const KIND_NOT_KUBERNETES = `not-${KIND_KUBERNETES}`; -const KIND_NOT_SWARM = `not-${KIND_SWARM}`; -const KIND_NOT_MESOS = `not-${KIND_MESOS}`; +const KIND_NOT_KUBERNETES = `sys-${KIND_KUBERNETES}`; +const KIND_NOT_SWARM = `sys-${KIND_SWARM}`; +const KIND_NOT_MESOS = `sys-${KIND_MESOS}`; var C = { COOKIE: { @@ -25,6 +26,7 @@ var C = { KIND_CATALOG: KIND_CATALOG, KIND_SYSTEM: KIND_SYSTEM, KIND_SYSTEM_CATALOG: KIND_SYSTEM_CATALOG, + KIND_LEGACY_KUBERNETES: KIND_LEGACY_KUBERNETES, KIND_KUBERNETES: KIND_KUBERNETES, KIND_SWARM: KIND_SWARM, KIND_MESOS: KIND_MESOS, diff --git a/app/utils/navigation-tree.js b/app/utils/navigation-tree.js index de48ae8c8..099dfa17a 100644 --- a/app/utils/navigation-tree.js +++ b/app/utils/navigation-tree.js @@ -116,7 +116,7 @@ const navTree = [ icon: 'icon icon-network', route: 'environments', ctx: [getProjectId], - queryParams: {which: 'not-kubernetes'}, + queryParams: {which: C.EXTERNAL_ID.KIND_NOT_KUBERNETES}, }, ], }, @@ -160,7 +160,7 @@ const navTree = [ icon: 'icon icon-network', route: 'environments', ctx: [getProjectId], - queryParams: {which: 'not-swarm'}, + queryParams: {which: C.EXTERNAL_ID.KIND_NOT_SWARM}, }, ] }, @@ -188,7 +188,7 @@ const navTree = [ icon: 'icon icon-network', route: 'environments', ctx: [getProjectId], - queryParams: {which: 'not-mesos'}, + queryParams: {which: C.EXTERNAL_ID.KIND_NOT_MESOS}, }, ], }, @@ -198,7 +198,7 @@ const navTree = [ id: 'cattle', localizedLabel: 'nav.cattle.tab', route: 'environments', - queryParams: {which: 'user'}, + queryParams: {which: C.EXTERNAL_ID.KIND_USER}, ctx: [getProjectId], moreCurrentWhen: ['authenticated.project.waiting'], condition: function() { return this.get('hasProject') && !this.get('hasKubernetes') && !this.get('hasSwarm') && !this.get('hasMesos'); }, @@ -209,7 +209,7 @@ const navTree = [ icon: 'icon icon-globe', route: 'environments', ctx: [getProjectId], - queryParams: {which: 'all'}, + queryParams: {which: C.EXTERNAL_ID.KIND_ALL}, }, {divider: true}, { @@ -218,7 +218,7 @@ const navTree = [ icon: 'icon icon-layers', route: 'environments', ctx: [getProjectId], - queryParams: {which: 'user'}, + queryParams: {which: C.EXTERNAL_ID.KIND_USER}, }, { id: 'cattle-system', @@ -226,7 +226,7 @@ const navTree = [ icon: 'icon icon-network', route: 'environments', ctx: [getProjectId], - queryParams: {which: 'system'}, + queryParams: {which: C.EXTERNAL_ID.KIND_SYSTEM}, }, ], }, diff --git a/app/utils/parse-externalid.js b/app/utils/parse-externalid.js index 36d93b4a7..da786852c 100644 --- a/app/utils/parse-externalid.js +++ b/app/utils/parse-externalid.js @@ -18,7 +18,7 @@ export function parseExternalId(externalId) { var idx = externalId.indexOf(C.EXTERNAL_ID.KIND_SEPARATOR); if (idx >= 0) { - // New style kind://[group:]ido + // New style kind://[group:]id out.kind = externalId.substr(0, idx); var rest = externalId.substr(idx + C.EXTERNAL_ID.KIND_SEPARATOR.length);