Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(moniker): adds monikers to stages that includes cluster-selects #4220

Merged
merged 2 commits into from
Oct 6, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,3 @@ module.exports = angular.module('spinnaker.amazon.pipeline.stage.disableClusterS
}
stage.preferLargerOverNewer = stage.preferLargerOverNewer.toString();
});

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -45,13 +46,24 @@ 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);
};

this.resetSelectedCluster = () => {
$scope.precondition.context.cluster = undefined;
$scope.precondition.context.moniker = undefined;
setClusterList();
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
<div class="col-sm-9">
<cluster-selector
clusters="clusterList"
model="precondition.context.cluster">
model="precondition.context.cluster"
on-change="preconditionCtrl.clusterChanged(clusterName)">
</cluster-selector>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<cluster-selector
clusters="vm.clusterList"
model="vm.component[vm.clusterField]"
toggled="vm.clusterSelectInputToggled(isToggled)">
toggled="vm.clusterSelectInputToggled(isToggled)"
on-change="vm.clusterChanged(clusterName)">
</cluster-selector>
</stage-config-field>
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()"/>
</div>

<div class="pull-right">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand All @@ -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) {
Expand Down