diff --git a/app/scripts/modules/amazon/src/pipeline/stages/cloneServerGroup/awsCloneServerGroupStage.js b/app/scripts/modules/amazon/src/pipeline/stages/cloneServerGroup/awsCloneServerGroupStage.js index 2072c37347d..f9fa3bb2982 100644 --- a/app/scripts/modules/amazon/src/pipeline/stages/cloneServerGroup/awsCloneServerGroupStage.js +++ b/app/scripts/modules/amazon/src/pipeline/stages/cloneServerGroup/awsCloneServerGroupStage.js @@ -60,7 +60,7 @@ module.exports = angular.module('spinnaker.amazon.pipeline.stage.cloneServerGrou this.targetClusterUpdated = () => { if (stage.targetCluster) { - const filterByCluster = (serverGroup) => serverGroup.moniker.cluster === stage.targetCluster; + const filterByCluster = appListExtractorService.monikerClusterNameFilter(stage.targetCluster); let moniker = _.first(appListExtractorService.getMonikers([$scope.application], filterByCluster)); stage.stack = moniker.stack; stage.freeFormDetails = moniker.detail; diff --git a/app/scripts/modules/amazon/src/pipeline/stages/disableCluster/awsDisableClusterStage.js b/app/scripts/modules/amazon/src/pipeline/stages/disableCluster/awsDisableClusterStage.js index f512fabc3eb..2946087068d 100644 --- a/app/scripts/modules/amazon/src/pipeline/stages/disableCluster/awsDisableClusterStage.js +++ b/app/scripts/modules/amazon/src/pipeline/stages/disableCluster/awsDisableClusterStage.js @@ -68,4 +68,3 @@ module.exports = angular.module('spinnaker.amazon.pipeline.stage.disableClusterS } stage.preferLargerOverNewer = stage.preferLargerOverNewer.toString(); }); - diff --git a/app/scripts/modules/core/src/application/listExtractor/listExtractor.service.ts b/app/scripts/modules/core/src/application/listExtractor/listExtractor.service.ts index b4a1bc535c1..c51985ec00a 100644 --- a/app/scripts/modules/core/src/application/listExtractor/listExtractor.service.ts +++ b/app/scripts/modules/core/src/application/listExtractor/listExtractor.service.ts @@ -87,6 +87,12 @@ export class AppListExtractor { }; } + public monikerClusterNameFilter(clusterName: string): IServerGroupFilter { + return (serverGroup: IServerGroup) => { + return serverGroup.moniker.cluster === clusterName; + } + } + public clusterFilterForCredentialsAndRegion(credentials: string, region: string | string[]): IServerGroupFilter { return (serverGroup: IServerGroup) => { const accountMatches = credentials ? serverGroup.account === credentials : true; diff --git a/app/scripts/modules/core/src/pipeline/config/preconditions/selector/preconditionSelector.directive.js b/app/scripts/modules/core/src/pipeline/config/preconditions/selector/preconditionSelector.directive.js index e80698fcf55..083ca5eadde 100644 --- a/app/scripts/modules/core/src/pipeline/config/preconditions/selector/preconditionSelector.directive.js +++ b/app/scripts/modules/core/src/pipeline/config/preconditions/selector/preconditionSelector.directive.js @@ -3,6 +3,7 @@ const angular = require('angular'); import {ACCOUNT_SERVICE} from 'core/account/account.service'; import {LIST_EXTRACTOR_SERVICE} from 'core/application/listExtractor/listExtractor.service'; +import { isNil, first } from 'lodash'; module.exports = angular.module('spinnaker.core.pipeline.config.preconditions.selector', [ ACCOUNT_SERVICE, @@ -45,6 +46,16 @@ module.exports = angular.module('spinnaker.core.pipeline.config.preconditions.se return preconditionConfig ? preconditionConfig.contextTemplateUrl : ''; }; + this.clusterChanged = function (clusterName) { + let clusterFilter = appListExtractorService.monikerClusterNameFilter(clusterName); + let moniker = first(appListExtractorService.getMonikers([$scope.application], clusterFilter)); + if (!isNil(moniker)) { + //cluster monikers dont have sequences + moniker.sequence = undefined; + } + $scope.precondition.context.moniker = moniker; + }; + let setClusterList = () => { let clusterFilter = appListExtractorService.clusterFilterForCredentialsAndRegion($scope.precondition.context.credentials, $scope.precondition.context.regions); $scope.clusterList = appListExtractorService.getClusters([$scope.application], clusterFilter); @@ -52,6 +63,7 @@ module.exports = angular.module('spinnaker.core.pipeline.config.preconditions.se this.resetSelectedCluster = () => { $scope.precondition.context.cluster = undefined; + $scope.precondition.context.moniker = undefined; setClusterList(); }; diff --git a/app/scripts/modules/core/src/pipeline/config/preconditions/types/clusterSize/additionalFields.html b/app/scripts/modules/core/src/pipeline/config/preconditions/types/clusterSize/additionalFields.html index 3ec56437425..6c71300d639 100644 --- a/app/scripts/modules/core/src/pipeline/config/preconditions/types/clusterSize/additionalFields.html +++ b/app/scripts/modules/core/src/pipeline/config/preconditions/types/clusterSize/additionalFields.html @@ -28,7 +28,8 @@
+ model="precondition.context.cluster" + on-change="preconditionCtrl.clusterChanged(clusterName)">
diff --git a/app/scripts/modules/core/src/widgets/accountRegionClusterSelector.component.html b/app/scripts/modules/core/src/widgets/accountRegionClusterSelector.component.html index f2a8772fa0b..deafd8f1a66 100644 --- a/app/scripts/modules/core/src/widgets/accountRegionClusterSelector.component.html +++ b/app/scripts/modules/core/src/widgets/accountRegionClusterSelector.component.html @@ -31,6 +31,7 @@ + toggled="vm.clusterSelectInputToggled(isToggled)" + on-change="vm.clusterChanged(clusterName)"> diff --git a/app/scripts/modules/core/src/widgets/accountRegionClusterSelector.component.js b/app/scripts/modules/core/src/widgets/accountRegionClusterSelector.component.js index 0de1675e781..95b7119ab43 100644 --- a/app/scripts/modules/core/src/widgets/accountRegionClusterSelector.component.js +++ b/app/scripts/modules/core/src/widgets/accountRegionClusterSelector.component.js @@ -75,6 +75,19 @@ module.exports = angular isToggled ? setToggledState() : setUnToggledState(); }; + vm.clusterChanged = (clusterName) => { + const filterByCluster = appListExtractorService.monikerClusterNameFilter(clusterName); + let clusterMoniker = _.first(_.uniq(appListExtractorService.getMonikers([vm.application], filterByCluster))); + if(_.isNil(clusterMoniker)) { + //remove the moniker from the stage if one doesn't exist. + vm.component.moniker = undefined; + } else { + //clusters don't contain sequences, so null it out. + clusterMoniker.sequence = null; + vm.component.moniker = clusterMoniker; + } + }; + vm.accountUpdated = () => { vm.component[this.clusterField] = undefined; setRegionList(); diff --git a/app/scripts/modules/core/src/widgets/scopeClusterSelector.directive.html b/app/scripts/modules/core/src/widgets/scopeClusterSelector.directive.html index e59af096078..bb6281ecfde 100644 --- a/app/scripts/modules/core/src/widgets/scopeClusterSelector.directive.html +++ b/app/scripts/modules/core/src/widgets/scopeClusterSelector.directive.html @@ -22,7 +22,8 @@ class="form-control input-sm" ng-if="vm.freeFormClusterField" ng-required="vm.required" - ng-model="vm.model" /> + ng-model="vm.model" + ng-blur="vm.clusterChanged()"/>
diff --git a/app/scripts/modules/core/src/widgets/scopeClusterSelector.directive.js b/app/scripts/modules/core/src/widgets/scopeClusterSelector.directive.js index ae402fddc4d..0de1da023a5 100644 --- a/app/scripts/modules/core/src/widgets/scopeClusterSelector.directive.js +++ b/app/scripts/modules/core/src/widgets/scopeClusterSelector.directive.js @@ -14,12 +14,14 @@ module.exports = angular clusters: '=', required: '=?', toggled: '&?', + onChange: '&?' }, controllerAs: 'vm', controller: function controller() { var vm = this; vm.toggled = vm.toggled || angular.noop; + vm.onChange = vm.onChange || angular.noop; vm.required = vm.required || false; let selectedNotInClusterList = () => { @@ -30,6 +32,10 @@ module.exports = angular return vm.model !== undefined || vm.model !== null || vm.model.trim() !== ''; }; + vm.clusterChanged = function() { + vm.onChange({clusterName:vm.model}); + }; + vm.freeFormClusterField = modelIsSet() ? selectedNotInClusterList() : false; vm.toggleFreeFormClusterField = function(event) {