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(appmesh): Move Client Policy from Virtual Service to backend structure #12943

Merged
merged 12 commits into from
Mar 12, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ export class AppMeshExtension extends ServiceExtension {
// Next update the app mesh config so that the local Envoy
// proxy on this service knows how to route traffic to
// nodes from the other service.
this.virtualNode.addBackend(appmesh.Backend.virtualService({ virtualService: otherAppMesh.virtualService }));
this.virtualNode.addBackend(appmesh.Backend.virtualService(otherAppMesh.virtualService ));
skinny85 marked this conversation as resolved.
Show resolved Hide resolved
}

private routeSpec(weightedTargets: appmesh.WeightedTarget[], serviceName: string): appmesh.RouteSpec {
Expand Down
8 changes: 2 additions & 6 deletions packages/@aws-cdk/aws-appmesh/lib/shared-interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,6 @@ export interface BackendDefaults {
* Represents the properties needed to define a Virtual Service backend
*/
export interface VirtualServiceBackendOptions {
/**
* The Virtual Service this backend points to
*/
readonly virtualService: IVirtualService;

/**
* Client policy for the backend
Expand Down Expand Up @@ -243,8 +239,8 @@ export abstract class Backend {
/**
* Construct a Virtual Service backend
*/
public static virtualService(props: VirtualServiceBackendOptions): Backend {
return new VirtualServiceBackend(props.virtualService, props.clientPolicy);
public static virtualService(virtualService: IVirtualService, props: VirtualServiceBackendOptions = {}): Backend {
return new VirtualServiceBackend(virtualService, props.clientPolicy);
}

/**
Expand Down
16 changes: 7 additions & 9 deletions packages/@aws-cdk/aws-appmesh/test/integ.mesh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,15 @@ const node = mesh.addVirtualNode('node', {
path: '/check-path',
},
})],
backends: [appmesh.Backend.virtualService({
virtualService: virtualService,
})],
backends: [appmesh.Backend.virtualService(virtualService)],
});

node.addBackend(appmesh.Backend.virtualService({
virtualService: new appmesh.VirtualService(stack, 'service-2', {
node.addBackend(appmesh.Backend.virtualService(
new appmesh.VirtualService(stack, 'service-2', {
virtualServiceName: 'service2.domain.local',
virtualServiceProvider: appmesh.VirtualServiceProvider.none(mesh),
}),
}));
));

router.addRoute('route-1', {
routeSpec: appmesh.RouteSpec.http({
Expand Down Expand Up @@ -84,12 +82,12 @@ const node2 = mesh.addVirtualNode('node2', {
certificateChain: 'path/to/cert',
}),
},
backends: [appmesh.Backend.virtualService({
virtualService: new appmesh.VirtualService(stack, 'service-3', {
backends: [appmesh.Backend.virtualService(
new appmesh.VirtualService(stack, 'service-3', {
virtualServiceName: 'service3.domain.local',
virtualServiceProvider: appmesh.VirtualServiceProvider.none(mesh),
}),
})],
)],
});

const node3 = mesh.addVirtualNode('node3', {
Expand Down
4 changes: 1 addition & 3 deletions packages/@aws-cdk/aws-appmesh/test/test.mesh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,7 @@ export = {
listeners: [appmesh.VirtualNodeListener.http({
port: 8080,
})],
backends: [appmesh.Backend.virtualService({
virtualService: service1,
})],
backends: [appmesh.Backend.virtualService(service1)],
});

// THEN
Expand Down
9 changes: 3 additions & 6 deletions packages/@aws-cdk/aws-appmesh/test/test.virtual-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,10 @@ export = {
const node = new appmesh.VirtualNode(stack, 'test-node', {
mesh,
serviceDiscovery: appmesh.ServiceDiscovery.dns('test'),
backends: [appmesh.Backend.virtualService({
virtualService: service1,
})],
backends: [appmesh.Backend.virtualService(service1)],
});

node.addBackend(appmesh.Backend.virtualService({ virtualService: service2 }));
node.addBackend(appmesh.Backend.virtualService(service2));

// THEN
expect(stack).to(haveResourceLike('AWS::AppMesh::VirtualNode', {
Expand Down Expand Up @@ -326,8 +324,7 @@ export = {
virtualServiceProvider: appmesh.VirtualServiceProvider.none(mesh),
});

node.addBackend(appmesh.Backend.virtualService({
virtualService: service1,
node.addBackend(appmesh.Backend.virtualService(service1, {
clientPolicy: appmesh.ClientPolicy.fileTrust({
certificateChain: 'path-to-certificate',
ports: [8080, 8081],
Expand Down
20 changes: 5 additions & 15 deletions packages/@aws-cdk/aws-appmesh/test/test.virtual-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,7 @@ export = {
listeners: [appmesh.VirtualNodeListener.http({
port: 8080,
})],
backends: [appmesh.Backend.virtualService({
virtualService: service1,
})],
backends: [appmesh.Backend.virtualService(service1)],
});

router.addRoute('route-1', {
Expand Down Expand Up @@ -184,27 +182,21 @@ export = {
listeners: [appmesh.VirtualNodeListener.http({
port: 8080,
})],
backends: [appmesh.Backend.virtualService({
virtualService: service1,
})],
backends: [appmesh.Backend.virtualService(service1)],
});
const node2 = mesh.addVirtualNode('test-node2', {
serviceDiscovery: appmesh.ServiceDiscovery.dns('test'),
listeners: [appmesh.VirtualNodeListener.http({
port: 8080,
})],
backends: [appmesh.Backend.virtualService({
virtualService: service2,
})],
backends: [appmesh.Backend.virtualService(service2)],
});
const node3 = mesh.addVirtualNode('test-node3', {
serviceDiscovery: appmesh.ServiceDiscovery.dns('test'),
listeners: [appmesh.VirtualNodeListener.http({
port: 8080,
})],
backends: [appmesh.Backend.virtualService({
virtualService: service1,
})],
backends: [appmesh.Backend.virtualService(service1)],
});

router.addRoute('route-1', {
Expand Down Expand Up @@ -342,9 +334,7 @@ export = {
listeners: [appmesh.VirtualNodeListener.http({
port: 8080,
})],
backends: [appmesh.Backend.virtualService({
virtualService: service1,
})],
backends: [appmesh.Backend.virtualService(service1)],
});

router.addRoute('route-tcp-1', {
Expand Down