aws / constructs

Define composable configuration models through code
Apache License 2.0
403 stars 38 forks source link

`Node.of(this).uniqueId` is bound to CloudFormation's logical ID rules #250

Closed foriequal0 closed 3 years ago

foriequal0 commented 3 years ago

I understand that constructs were supposed to support cdk, so It was also understandable that Node.of(this).uniqueId is bound to CloudFormation's logical ID rules: ([A-Za-z0-9]{255}) https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/resources-section-structure.html#resources-section-structure-resource-fields https://docs.amazonaws.cn/en_us/AWSCloudFormation/latest/UserGuide/cloudformation-limits.html

However, constructs is now also used as a foundation of cdk8s, and Kubernetes imposes different rules to resource names and labels:

DNS Subdomain Names

Most resource types require a name that can be used as a DNS subdomain name as defined in RFC 1123. This means the name must:

  • contain no more than 253 characters
  • contain only lowercase alphanumeric characters, '-' or '.'
  • start with an alphanumeric character
  • end with an alphanumeric character

DNS Label Names

Some resource types require their names to follow the DNS label standard as defined in RFC 1123. This means the name must:

  • contain at most 63 characters
  • contain only lowercase alphanumeric characters or '-'
  • start with an alphanumeric character
  • end with an alphanumeric character

https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-subdomain-names

Valid label keys have two segments: an optional prefix and name, separated by a slash (/). The name segment is required and must be 63 characters or less, beginning and ending with an alphanumeric character ([a-z0-9A-Z]) with dashes (-), underscores (_), dots (.), and alphanumerics between. The prefix is optional. If specified, the prefix must be a DNS subdomain (...)

Valid label values must be 63 characters or less and must be empty or begin and end with an alphanumeric character ([a-z0-9A-Z]) with dashes (-), underscores (_), dots (.), and alphanumerics between.

https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#syntax-and-character-set

Some CF names might exceed K8s' name length limit, and contain upper case letters, and some K8s names/labels might contain invalid characters for CF ('-', '_', '.', '_')

Removing Node.of(this).uniqueId from constructs and letting cdk and cdk8s to implement their own uniqueId would prevent confusions and unnecessary limits on each frameworks.

Maybe this is related to this: https://github.com/aws/constructs/issues/120

eladb commented 3 years ago

The new addr property should be used to generate unique IDs (see https://github.com/aws/constructs/pull/314).

Resolved by https://github.com/aws/constructs/pull/314