Skip to content

Commit

Permalink
feat(cf): Add Map/Unmap SGs and LBs
Browse files Browse the repository at this point in the history
Co-Authored-By: Jason Chu <jjchu@protonmail.com>
Co-Authored-By: Joris Melchior <joris.melchior@gmail.com>
  • Loading branch information
3 people committed Feb 1, 2019
1 parent c5e6d3d commit 04bc98b
Show file tree
Hide file tree
Showing 17 changed files with 712 additions and 12 deletions.
4 changes: 4 additions & 0 deletions app/scripts/modules/cloudfoundry/src/cf.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import { CLOUD_FOUNDRY_DESTROY_ASG_STAGE } from './pipeline/stages/destroyAsg/cl
import { CLOUD_FOUNDRY_DESTROY_SERVICE_STAGE } from './pipeline/stages/destroyService/cloudfoundryDestroyServiceStage.module';
import { CLOUD_FOUNDRY_DISABLE_ASG_STAGE } from './pipeline/stages/disableAsg/cloudfoundryDisableAsgStage.module';
import { CLOUD_FOUNDRY_ENABLE_ASG_STAGE } from './pipeline/stages/enableAsg/cloudfoundryEnableAsgStage.module';
import { CLOUD_FOUNDRY_MAP_LOAD_BALANCERS_STAGE } from './pipeline/stages/mapLoadBalancers/cloudfoundryMapLoadBalancersStage.module';
import { CLOUD_FOUNDRY_UNMAP_LOAD_BALANCERS_STAGE } from './pipeline/stages/unmapLoadBalancers/cloudfoundryUnmapLoadBalancersStage.module';
import { CLOUD_FOUNDRY_RESIZE_ASG_STAGE } from './pipeline/stages/resizeAsg/cloudfoundryResizeAsgStage.module';
import { CLOUD_FOUNDRY_ROLLBACK_CLUSTER_STAGE } from './pipeline/stages/rollbackCluster/cloudfoundryRollbackClusterStage.module';
import { CloudFoundryCreateServerGroupModal } from 'cloudfoundry/serverGroup/configure/wizard/CreateServerGroupModal';
Expand All @@ -53,6 +55,8 @@ module(CLOUD_FOUNDRY_MODULE, [
CLOUD_FOUNDRY_ENABLE_ASG_STAGE,
CLOUD_FOUNDRY_INSTANCE_DETAILS,
CLOUD_FOUNDRY_LOAD_BALANCER_MODULE,
CLOUD_FOUNDRY_MAP_LOAD_BALANCERS_STAGE,
CLOUD_FOUNDRY_UNMAP_LOAD_BALANCERS_STAGE,
CLOUD_FOUNDRY_REACT_MODULE,
CLOUD_FOUNDRY_RESIZE_ASG_STAGE,
CLOUD_FOUNDRY_ROLLBACK_CLUSTER_STAGE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { react2angular } from 'react2angular';

import { CloudfoundryDeployServiceStageConfig } from './CloudfoundryDeployServiceStageConfig';
import { ExecutionDetailsTasks, IStage, Registry } from '@spinnaker/core';
import { CloudfoundryDeployServiceExecutionDetails } from 'cloudfoundry/pipeline/stages/deployService/CloudfoundryDeployServiceExecutionDetails';
import { CloudfoundryDeployServiceExecutionDetails } from './CloudfoundryDeployServiceExecutionDetails';
import { IServiceFieldValidatorConfig } from 'cloudfoundry/pipeline/config/validation/ServiceFieldValidatorConfig';

class CloudFoundryDeployServiceStageCtrl implements IController {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class CloudfoundryDestroyAsgStageConfig extends React.Component<

public componentDidMount = (): void => {
AccountService.listAccounts('cloudfoundry').then(accounts => {
this.setState({ accounts: accounts });
this.setState({ accounts });
this.accountUpdated();
});
this.props.stageFieldUpdated();
Expand All @@ -61,18 +61,18 @@ export class CloudfoundryDestroyAsgStageConfig extends React.Component<
const { credentials } = this.props.stage;
if (credentials) {
AccountService.getRegionsForAccount(credentials).then(regions => {
this.setState({ regions: regions });
this.setState({ regions });
});
}
};

private targetUpdated = (target: string) => {
this.setState({ target: target });
this.setState({ target });
this.props.stage.target = target;
this.props.stageFieldUpdated();
};

private componentUpdate = (stage: any): void => {
private componentUpdated = (stage: any): void => {
this.props.stage.credentials = stage.credentials;
this.props.stage.regions = stage.regions;
this.props.stage.cluster = stage.cluster;
Expand All @@ -90,13 +90,13 @@ export class CloudfoundryDestroyAsgStageConfig extends React.Component<
accounts={accounts}
application={application}
cloudProvider={'cloudfoundry'}
onComponentUpdate={this.componentUpdate}
onComponentUpdate={this.componentUpdated}
component={stage}
/>
)}

<StageConfigField label="Target">
<TargetSelect model={{ target: target }} options={StageConstants.TARGET_LIST} onChange={this.targetUpdated} />
<TargetSelect model={{ target }} options={StageConstants.TARGET_LIST} onChange={this.targetUpdated} />
</StageConfigField>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class CloudfoundryEnableAsgStageConfig extends React.Component<
this.props.stageFieldUpdated();
};

private componentUpdate = (stage: any): void => {
private componentUpdated = (stage: any): void => {
this.props.stage.credentials = stage.credentials;
this.props.stage.regions = stage.regions;
this.props.stage.cluster = stage.cluster;
Expand All @@ -88,7 +88,7 @@ export class CloudfoundryEnableAsgStageConfig extends React.Component<
accounts={accounts}
application={application}
cloudProvider={'cloudfoundry'}
onComponentUpdate={this.componentUpdate}
onComponentUpdate={this.componentUpdated}
component={stage}
/>
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import * as React from 'react';

import {
ExecutionDetailsSection,
IExecutionDetailsSectionProps,
StageExecutionLogs,
StageFailureMessage,
} from '@spinnaker/core';

export function CloudfoundryMapLoadBalancersExecutionDetails(props: IExecutionDetailsSectionProps) {
return (
<ExecutionDetailsSection name={props.name} current={props.current}>
<StageFailureMessage stage={props.stage} message={props.stage.failureMessage} />
<StageExecutionLogs stage={props.stage} />
</ExecutionDetailsSection>
);
}

export namespace CloudfoundryMapLoadBalancersExecutionDetails {
export const title = 'cloudfoundryMapLoadBalancersConfig';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import * as React from 'react';

import {
Application,
IAccount,
IPipeline,
IStageConfigProps,
NgReact,
StageConfigField,
StageConstants,
} from '@spinnaker/core';

import { AccountRegionClusterSelector, Routes } from 'cloudfoundry/presentation';
import { Formik } from 'formik';

interface ICloudfoundryLoadBalancerStageConfigProps extends IStageConfigProps {
accounts: IAccount[];
pipeline: IPipeline;
}

interface ICloudFoundryMapLoadBalancersValues {
routes: string[];
}

interface ICloudfoundryMapLoadBalancersStageConfigState {
application: Application;
cloudProvider: string;
credentials: string;
initialValues: ICloudFoundryMapLoadBalancersValues;
pipeline: IPipeline;
region: string;
target: string;
}

export class CloudfoundryMapLoadBalancersStageConfig extends React.Component<
ICloudfoundryLoadBalancerStageConfigProps,
ICloudfoundryMapLoadBalancersStageConfigState
> {
private formikRef = React.createRef<Formik<ICloudFoundryMapLoadBalancersValues>>();

constructor(props: ICloudfoundryLoadBalancerStageConfigProps) {
super(props);
props.stage.cloudProvider = 'cloudfoundry';
this.state = {
application: props.application,
cloudProvider: 'cloudfoundry',
credentials: props.stage.credentials,
initialValues: {
routes: props.stage.loadBalancerNames,
},
pipeline: props.pipeline,
region: props.stage.region,
target: props.stage.target,
};
}

private targetUpdated = (target: string) => {
this.setState({ target });
this.props.stage.target = target;
this.props.stageFieldUpdated();
};

private componentUpdated = (stage: any): void => {
this.props.stage.credentials = stage.credentials;
this.props.stage.region = stage.region;
this.props.stage.cluster = stage.cluster;
this.props.stage.loadBalancerNames = stage.loadBalancerNames;
this.props.stageFieldUpdated();
};

public render() {
const { accounts, stage } = this.props;
const { application, initialValues, pipeline, target } = this.state;
const { TargetSelect } = NgReact;
return (
<div className="form-horizontal">
{!pipeline.strategy && (
<AccountRegionClusterSelector
accounts={accounts}
application={application}
cloudProvider={'cloudfoundry'}
isSingleRegion={true}
onComponentUpdate={this.componentUpdated}
component={stage}
/>
)}
<StageConfigField label="Target">
<TargetSelect model={{ target }} options={StageConstants.TARGET_LIST} onChange={this.targetUpdated} />
</StageConfigField>
<Formik<ICloudFoundryMapLoadBalancersValues>
ref={this.formikRef}
initialValues={initialValues}
onSubmit={null}
render={() => {
return (
<Routes
fieldName={'routes'}
onChange={(routes: string[]) => {
stage.loadBalancerNames = routes;
this.componentUpdated(stage);
}}
/>
);
}}
/>
</div>
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<cf-map-load-balancers-stage accounts="accounts" application="application" pipeline="pipeline" stage="stage" stage-field-updated="stageFieldUpdated" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { IController, IScope, module } from 'angular';
import { react2angular } from 'react2angular';

import { CloudfoundryMapLoadBalancersStageConfig } from './CloudfoundryMapLoadBalancersStageConfig';
import { AccountService, ExecutionDetailsTasks, IStage, Registry } from '@spinnaker/core';
import { CloudfoundryMapLoadBalancersExecutionDetails } from './CloudfoundryMapLoadBalancersExecutionDetails';

class CloudFoundryMapLoadBalancersStageCtrl implements IController {
constructor(public $scope: IScope) {
'ngInject';
$scope.accounts = [];
AccountService.listAccounts('cloudfoundry').then(accounts => {
$scope.accounts = accounts;
});
}
}

export const CLOUD_FOUNDRY_MAP_LOAD_BALANCERS_STAGE = 'spinnaker.cloudfoundry.pipeline.stage.mapLoadBalancersStage';
module(CLOUD_FOUNDRY_MAP_LOAD_BALANCERS_STAGE, [])
.config(function() {
Registry.pipeline.registerStage({
accountExtractor: (stage: IStage) => stage.context.credentials,
configAccountExtractor: (stage: IStage) => [stage.credentials],
cloudProvider: 'cloudfoundry',
controller: 'cfMapLoadBalancersStageCtrl',
description: 'Map load balancers',
executionDetailsSections: [CloudfoundryMapLoadBalancersExecutionDetails, ExecutionDetailsTasks],
key: 'mapLoadBalancers',
label: 'Map Load Balancers',
templateUrl: require('./cloudfoundryMapLoadBalancersStage.html'),
validators: [
{ type: 'requiredField', fieldName: 'cluster' },
{ type: 'requiredField', fieldName: 'credentials', fieldLabel: 'account' },
{ type: 'requiredField', fieldName: 'region' },
{ type: 'requiredField', fieldName: 'target' },
],
});
})
.component(
'cfMapLoadBalancersStage',
react2angular(CloudfoundryMapLoadBalancersStageConfig, [
'accounts',
'application',
'pipeline',
'stage',
'stageFieldUpdated',
]),
)
.controller('cfMapLoadBalancersStageCtrl', CloudFoundryMapLoadBalancersStageCtrl);
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import * as React from 'react';

import {
ExecutionDetailsSection,
IExecutionDetailsSectionProps,
StageExecutionLogs,
StageFailureMessage,
} from '@spinnaker/core';

export function CloudfoundryUnmapLoadBalancersExecutionDetails(props: IExecutionDetailsSectionProps) {
return (
<ExecutionDetailsSection name={props.name} current={props.current}>
<StageFailureMessage stage={props.stage} message={props.stage.failureMessage} />
<StageExecutionLogs stage={props.stage} />
</ExecutionDetailsSection>
);
}

export namespace CloudfoundryUnmapLoadBalancersExecutionDetails {
export const title = 'cloudfoundryUnmapLoadBalancersConfig';
}
Loading

0 comments on commit 04bc98b

Please sign in to comment.