Skip to content

Commit

Permalink
fix(ecs): add container name for service discovery in server group (#…
Browse files Browse the repository at this point in the history
…8518)

* fix(ecs): ECS Service Discovery container not valid error #5859

* fix(ecs): ECS Service Discovery container not valid error #5859

* fix(ecs): ECS Service Discovery container not valid error #5859

* fix(ecs): ECS Service Discovery container not valid error #5859

* addition of help text

Co-authored-by: Parag Bhingre <pbhingre@gmail.com>
Co-authored-by: allisaurus <34254888+allisaurus@users.noreply.github.com>
  • Loading branch information
3 people committed Sep 4, 2020
1 parent 469a2d0 commit 7c064c7
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 6 deletions.
1 change: 1 addition & 0 deletions app/scripts/modules/ecs/src/ecs.help.ts
Expand Up @@ -71,6 +71,7 @@ const helpContents: { [key: string]: string } = {
'ecs.serviceDiscoveryRegistry': '<p>The AWS Cloud Map service to use for service discovery registration</p>',
'ecs.serviceDiscoveryContainerPort':
'<p>The port to be used for your service discovery service. Required only for services using bridge or host network mode, and for services using awsvpc network mode and a type SRV DNS record',
'ecs.serviceDiscoveryContainerName': '<p>The container name value, already specified in the task definition, to be used for your service discovery service.</p>'
};

Object.keys(helpContents).forEach(key => HelpContentsRegistry.register(key, helpContents[key]));
Expand Up @@ -111,6 +111,7 @@ export interface IEcsTargetGroupMapping {
export interface IEcsServiceDiscoveryRegistryAssociation {
registry: IServiceDiscoveryRegistryDescriptor;
containerPort: number;
containerName: string;
}

export interface IEcsServerGroupCommand extends IServerGroupCommand {
Expand All @@ -130,6 +131,7 @@ export interface IEcsServerGroupCommand extends IServerGroupCommand {
loadBalancedContainer: string;
targetGroupMappings: IEcsTargetGroupMapping[];
serviceDiscoveryAssociations: IEcsServiceDiscoveryRegistryAssociation[];
useTaskDefinitionArtifact: boolean;

subnetTypeChanged: (command: IEcsServerGroupCommand) => IServerGroupCommandResult;
placementStrategyNameChanged: (command: IEcsServerGroupCommand) => IServerGroupCommandResult;
Expand Down
Expand Up @@ -29,8 +29,9 @@ <h3 us-spinner="{radius:30, width:8, length: 16}"></h3>
<ng-include src="pages.logging"></ng-include>
</v2-wizard-page>
</div>
<v2-wizard-page key="serviceDiscovery" label="Service Discovery" done="true">
<ng-include src="pages.serviceDiscovery"></ng-include>
<v2-wizard-page key="serviceDiscovery" label="Service Discovery" done="true">
<ng-include ng-if="!command.useTaskDefinitionArtifact" src="pages.serviceDiscovery" ></ng-include>
<ng-include ng-if="command.useTaskDefinitionArtifact" src="pages.serviceDiscovery" ></ng-include>
</v2-wizard-page>
<v2-wizard-page key="advanced" label="Advanced Settings" mark-complete-on-view="false" done="true">
<ng-include src="pages.advancedSettings"></ng-include>
Expand Down
Expand Up @@ -27,6 +27,7 @@ export interface IEcsServiceDiscoveryRegistry {
interface IServiceDiscoveryState {
serviceDiscoveryAssociations: IEcsServiceDiscoveryRegistryAssociation[];
serviceDiscoveryRegistriesAvailable: IEcsServiceDiscoveryRegistry[];
useTaskDefinitionArtifact: boolean;
}

export class ServiceDiscovery extends React.Component<IServiceDiscoveryProps, IServiceDiscoveryState> {
Expand All @@ -38,7 +39,14 @@ export class ServiceDiscovery extends React.Component<IServiceDiscoveryProps, IS
serviceDiscoveryAssociations: cmd.serviceDiscoveryAssociations,
serviceDiscoveryRegistriesAvailable:
cmd.backingData && cmd.backingData.filtered ? cmd.backingData.filtered.serviceDiscoveryRegistries : [],
useTaskDefinitionArtifact: cmd.useTaskDefinitionArtifact,
};

if (!this.state.useTaskDefinitionArtifact) {
this.state.serviceDiscoveryAssociations.forEach(serviceDiscoveryRegistryAssociation => {
serviceDiscoveryRegistryAssociation.containerName = null
});
}
}

public componentDidMount() {
Expand Down Expand Up @@ -92,9 +100,17 @@ export class ServiceDiscovery extends React.Component<IServiceDiscoveryProps, IS
this.setState({ serviceDiscoveryAssociations: currentAssociations });
};

private updateServiceDiscoveryContainerName = (index: number, targetContainerName: string) => {
const currentAssociations = this.state.serviceDiscoveryAssociations;
const targetAssociations = currentAssociations[index];
targetAssociations.containerName = targetContainerName;
this.props.notifyAngular('serviceDiscoveryAssociations', currentAssociations);
this.setState({ serviceDiscoveryAssociations: currentAssociations });
};

private pushServiceDiscoveryAssociation = () => {
const registryAssociations = this.state.serviceDiscoveryAssociations;
registryAssociations.push({ registry: this.getEmptyRegistry(), containerPort: 80 });
registryAssociations.push({ registry: this.getEmptyRegistry(), containerPort: 80, containerName: '' });
this.setState({ serviceDiscoveryAssociations: registryAssociations });
};

Expand All @@ -109,14 +125,27 @@ export class ServiceDiscovery extends React.Component<IServiceDiscoveryProps, IS
const removeServiceDiscoveryAssociation = this.removeServiceDiscoveryAssociations;
const updateServiceDiscoveryRegistry = this.updateServiceDiscoveryRegistry;
const updateServiceDiscoveryPort = this.updateServiceDiscoveryPort;
const updateServiceDiscoveryContainerName = this.updateServiceDiscoveryContainerName;

const registriesAvailable = this.state.serviceDiscoveryRegistriesAvailable.map(function(registry) {
return { label: `${registry.displayName}`, value: registry.displayName };
});

const useTaskDefinitionArtifact = this.state.useTaskDefinitionArtifact;
const serviceDiscoveryInputs = this.state.serviceDiscoveryAssociations.map(function(mapping, index) {
return (
<tr key={index}>
{useTaskDefinitionArtifact &&
<td>
<input
className="form-control input-sm"
placeholder="Enter a container name ..."
required={true}
value={mapping.containerName}
onChange={e => updateServiceDiscoveryContainerName(index, e.target.value)}
/>
</td>
}
<td>
<TetheredSelect
placeholder="Select a registry..."
Expand Down Expand Up @@ -170,11 +199,21 @@ export class ServiceDiscovery extends React.Component<IServiceDiscoveryProps, IS
<table className="table table-condensed packed tags">
<thead>
<tr>
<th style={{ width: '75%' }}>
{useTaskDefinitionArtifact && <th style={{ width: '30%' }}>
Container name
<HelpField id="ecs.serviceDiscoveryContainerName" />
</th> }
{useTaskDefinitionArtifact ?
<th style={{ width: '55%' }}>
Registry
<HelpField id="ecs.serviceDiscoveryRegistry" />
</th>
<th style={{ width: '18%' }}>
</th>
:
<th style={{ width: '80%' }}>
Registry
<HelpField id="ecs.serviceDiscoveryRegistry" />
</th> }
<th style={{ width: '15%' }}>
Port
<HelpField id="ecs.serviceDiscoveryContainerPort" />
</th>
Expand Down

0 comments on commit 7c064c7

Please sign in to comment.