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

fix(kubernetes): show Deployment clusters in Find Artifacts from Reso… #6794

Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -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