Skip to content

Commit

Permalink
fix(kubernetes): show Deployment clusters in Find Artifacts from Reso…
Browse files Browse the repository at this point in the history
…urce stages (spinnaker#6794)
  • Loading branch information
maggieneterval authored Apr 2, 2019
1 parent cc05339 commit d7f6fbd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Select, { Creatable, Option } from 'react-select';
import { IPromise } from 'angular';
import { Observable, Subject } from 'rxjs';
import { $q } from 'ngimport';
import { get } from 'lodash';
import { get, isEmpty } from 'lodash';

import {
AppListExtractor,
Expand All @@ -17,6 +17,7 @@ import {
AccountService,
noop,
ScopeClusterSelector,
IServerGroup,
} from '@spinnaker/core';

import {
Expand Down Expand Up @@ -288,6 +289,28 @@ export class ManifestSelector extends React.Component<IManifestSelectorProps, IM

private getSelectedMode = (): SelectorMode => this.state.selector.mode || SelectorMode.Static;

private getFilteredClusters = (): string[] => {
const { application, includeSpinnakerKinds } = this.props;
const { selector } = this.state;
const applications = application ? [application] : [];
// If the only whitelisted Spinnaker kind is `serverGroups`, exclude server groups with `serverGroupManagers`.
// This is because traffic management stages only allow ReplicaSets.
const includeServerGroupsWithManagers: boolean =
isEmpty(includeSpinnakerKinds) || includeSpinnakerKinds.length > 1 || includeSpinnakerKinds[0] !== 'serverGroups';
const filter = (serverGroup: IServerGroup): boolean => {
const accountAndNamespaceFilter: boolean = AppListExtractor.clusterFilterForCredentialsAndRegion(
selector.account,
selector.location,
)(serverGroup);
const hasServerGroupManagers: boolean = get(serverGroup, 'serverGroupManagers.length', 0) > 0;
const serverGroupManagerFilter: boolean = includeServerGroupsWithManagers || !hasServerGroupManagers;
const nameToParseKind: string = hasServerGroupManagers ? serverGroup.cluster : serverGroup.name;
const kindFilter: boolean = parseSpinnakerName(nameToParseKind).kind === this.modeDelegate().getKind();
return accountAndNamespaceFilter && serverGroupManagerFilter && kindFilter;
};
return AppListExtractor.getClusters(applications, filter);
};

public render() {
const { TargetSelect } = NgReact;
const selectedMode = this.getSelectedMode();
Expand All @@ -296,13 +319,6 @@ export class ManifestSelector extends React.Component<IManifestSelectorProps, IM
const kind = this.modeDelegate().getKind();
const name = parseSpinnakerName(selector.manifestName).name;
const resourceNames = resources.map(resource => parseSpinnakerName(resource).name);
const clusters = AppListExtractor.getClusters(
this.props.application ? [this.props.application] : [],
serverGroup =>
AppListExtractor.clusterFilterForCredentialsAndRegion(selector.account, selector.location)(serverGroup) &&
get(serverGroup, 'serverGroupManagers.length', 0) === 0 &&
parseSpinnakerName(serverGroup.name).kind === this.modeDelegate().getKind(),
);
const selectedKinds = selector.kinds || [];
const KindField = (
<StageConfigField label="Kind">
Expand Down Expand Up @@ -369,7 +385,11 @@ export class ManifestSelector extends React.Component<IManifestSelectorProps, IM
{modes.includes(SelectorMode.Dynamic) && selectedMode === SelectorMode.Dynamic && (
<>
<StageConfigField label="Cluster">
<ScopeClusterSelector clusters={clusters} model={selector.cluster} onChange={this.handleClusterChange} />
<ScopeClusterSelector
clusters={this.getFilteredClusters()}
model={selector.cluster}
onChange={this.handleClusterChange}
/>
</StageConfigField>
<StageConfigField label="Target">
<TargetSelect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ export class KubernetesV2FindArtifactsFromResourceConfigCtrl implements IControl

public static $inject = ['$scope'];
constructor(private $scope: IScope) {
this.application = this.$scope.$parent.application;
if (this.$scope.stage.isNew) {
this.application = this.$scope.$parent.application;
const defaultSelection: IManifestSelector = {
location: '',
account: '',
Expand Down

0 comments on commit d7f6fbd

Please sign in to comment.