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

WIP feat(ecs): Enable Cloudmap Service Discovery #4

Closed
wants to merge 1 commit into from
Closed

Conversation

SoManyHs
Copy link
Owner

@SoManyHs SoManyHs commented Feb 5, 2019

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license.

*/
public addNamespace(name: string): cloudmap.PrivateDnsNamespace {
const sdNamespace = new cloudmap.PrivateDnsNamespace(this, 'DefaultServiceDiscoveryNamespace', {
name,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to have this autogenerated?

Does it make sense to default it to some particular value that we can derive from another value?

Does it make sense to add a boolean to the constructor props to call this automatically?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have name generated? No, that is usually the one thing customers would want to specify -- it's the domain name, so like foo.com

not sure what you mean by the boolean in the constructor props?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking:

class ClusterProps {
   // ...
   /**
    * Domain name for the private DNS namespace to create
    *
    * @default No namespace is created by default
    */
   privateDnsNamespaceDomainName?: string
}

Which would imply a call to addNamespace.

But looking at this, I do have a couple more questions:

  • Would you ever have more than one namespace? (Right now you can't call this more than once)
  • Would it always be a private namespace? (Right now doesn't look like you could do a public or HTTP namespace even if you wanted to)
  • Is cluster.addNamespace() descriptive enough? (Maybe cluster.addCloudMapNamespace()?).

packages/@aws-cdk/aws-ecs/lib/ec2/ec2-service.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-ecs/lib/ec2/ec2-service.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-ecs/lib/ec2/ec2-service.ts Outdated Show resolved Hide resolved
/**
* Enable CloudMap service discovery for the service
*/
public enableServiceDiscovery(props: ServiceDiscoveryProps): cloudmap.Service {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does use of this method require that the Cluster has addNamespace() called?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does, but since addNamespace() adds the namespaceId (or namespace as a member) on the cluster we can check the value there, if you're concerned about validation.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am, please do.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, I think we're standardizing on FooOptions for arguments to a method (FooProps is for arguments to a constructor)

/**
* Define a Service Discovery HTTP Namespace
*/
export class PrivateDnsNamespace extends cdk.Construct {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there are more generic INamespace interface to be extracted between HttpNamespace and PrivateDnsNamespace, or does that not make sense?

const ns = new CfnPrivateDnsNamespace(this, 'Resource', {
name: props.name,
description: props.description,
vpc: props.vpc.vpcId // NOTE: not sure this is right
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is.

/**
* The ID of the namespace that you want to use for DNS configuration.
*/
namespaceId: string;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels like you should want to pass in an INamespace here.

packages/@aws-cdk/aws-servicediscovery/lib/service.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-servicediscovery/lib/service.ts Outdated Show resolved Hide resolved
@SoManyHs SoManyHs force-pushed the ecs-sd branch 4 times, most recently from 0238252 to 1a766b5 Compare February 11, 2019 09:04
Copy link
Collaborator

@rix0rrr rix0rrr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My big question is: why do we register a namespace on a Cluster at all? Seems like supplying an INamespace to a Service should be enough, no?

/**
* Enable CloudMap service discovery for the service
*/
public enableServiceDiscovery(props: ServiceDiscoveryProps): cloudmap.Service {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am, please do.

/**
* Enable CloudMap service discovery for the service
*/
public enableServiceDiscovery(props: ServiceDiscoveryProps): cloudmap.Service {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, I think we're standardizing on FooOptions for arguments to a method (FooProps is for arguments to a constructor)

}

const cloudmapService = new cloudmap.Service(this, 'CloudmapService', {
namespaceId: props.namespaceId, // FIXME use INamespace instead -- validate if cluster has called addNamespace set?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you not taking the namespaceId from the cluster in any case? It's there, why make the user pass it in again? And in case there can be multiple namespaces why store it on the cluster at all?

Why does cluster.addNamespace() exist, anyway?

// add Cloudmap service to the ECS Service's serviceRegistry
this.serviceRegistries.push({
registryArn: serviceArn,
containerName: this.taskDefinition.defaultContainer!.node.id,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check for existence of a default container. It might not exist if addContainer() hasn't been called yet.

packages/@aws-cdk/aws-servicediscovery/lib/namespace.ts Outdated Show resolved Hide resolved
* The DNS type of the record that you want AWS Cloud Map to create. Supported record types
* include A, AAAA, A_AAAA, CNAME, and SRV.
*/
dnsType: DnsRecordType;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if namespace is of HTTP type? Does that still have a dnsType?

packages/@aws-cdk/aws-servicediscovery/lib/service.ts Outdated Show resolved Hide resolved
{
dnsRecords: [
{
type: dnsType,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validate that dnsType is set when you make it optioanl.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, namespaceId (and routingPolicy) also both seem to not be set in case of an HTTP namespace.

How can this work?


export interface DnsConfig {
dnsRecords: DnsRecord[],
namespaceId: string,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really a nice interface to export. If it's a reference to some other resource, we don't reference it by string-id by by interface (INamespace here)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I was only using it to make it easier in the constructor (line 97), but perhaps exporting the interface this way isn't the way to go?

/**
* The time to live for the record
*/
ttl: string,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ttlSec. WHy is it a string and not a number?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants