|
| 1 | +# AWS Filters |
| 2 | + |
| 3 | +This document provides guidance on filtering AWS zones using various strategies and flags. |
| 4 | + |
| 5 | +## Strategies for Scoping Zones |
| 6 | + |
| 7 | +> Without specifying these flags, management applies to all zones. |
| 8 | +
|
| 9 | +In order to manage specific zones, there is a possibility to combine multiple options |
| 10 | + |
| 11 | +| Argument | Description | Flow Control | |
| 12 | +|:---------------------------|:-----------------------------------------------------------|:------------:| |
| 13 | +| `--zone-id-filter` | Specify multiple times if needed | OR | |
| 14 | +| `--domain-filter` | By domain suffix - specify multiple times if needed | OR | |
| 15 | +| `--regex-domain-filter` | By domain suffix but as a regex - overrides domain-filter | AND | |
| 16 | +| `--exclude-domains` | To exclude a domain or subdomain | OR | |
| 17 | +| `--regex-domain-exclusion` | Subtracts its matches from `regex-domain-filter`'s matches | AND | |
| 18 | +| `--aws-zone-type` | Only sync zones of this type `[public\|private]` | OR | |
| 19 | +| `--aws-zone-tags` | Only sync zones with this tag | AND | |
| 20 | + |
| 21 | +Minimum required configuration |
| 22 | + |
| 23 | +```sh |
| 24 | +args: |
| 25 | + --provider=aws |
| 26 | + --registry=txt |
| 27 | + --source=service |
| 28 | +``` |
| 29 | + |
| 30 | +### Filter by Zone Type |
| 31 | + |
| 32 | +> If this flag is not specified, management applies to both public and private zones. |
| 33 | +
|
| 34 | +```sh |
| 35 | +args: |
| 36 | + --aws-zone-type=private|public # choose between public or private |
| 37 | + ... |
| 38 | +``` |
| 39 | + |
| 40 | +### Filter by Domain |
| 41 | + |
| 42 | +> Specify multiple times if needed. |
| 43 | +
|
| 44 | +```sh |
| 45 | +args: |
| 46 | + --domain-filter=example.com |
| 47 | + --domain-filter=.paradox.example.com |
| 48 | + ... |
| 49 | +``` |
| 50 | + |
| 51 | +Example `--domain-filter=example.com` will allow for zone `example.com` and any zones that end in `.example.com`, including `an.example.com`, i.e., the subdomains of example.com. |
| 52 | + |
| 53 | +When there are multiple domains, filter `--domain-filter=example.com` will match domains `example.com`, `ex.par.example.com`, `par.example.com`, `x.par.eu-west-1.example.com`. |
| 54 | + |
| 55 | +And if the filter is prepended with `.` e.g., `--domain-filter=.example.com` it will allow *only* zones that end in `.example.com`, i.e., the subdomains of example.com but not the `example.com` zone itself. Example result: `ex.par.eu-west-1.example.com`, `ex.par.example.com`, `par.example.com`. |
| 56 | + |
| 57 | +> Note: if you prepend the filter with ".", it will not attempt to match parent zones. |
| 58 | +
|
| 59 | +### Filter by Zone ID |
| 60 | + |
| 61 | +> Specify multiple times if needed, the flow logic is OR |
| 62 | +
|
| 63 | +```sh |
| 64 | +args: |
| 65 | + --zone-id-filter=ABCDEF12345678 |
| 66 | + --zone-id-filter=XYZDEF12345888 |
| 67 | + ... |
| 68 | +``` |
| 69 | + |
| 70 | +### Filter by Tag |
| 71 | + |
| 72 | +> Specify multiple times if needed, the flow logic is AND |
| 73 | +
|
| 74 | +Keys only |
| 75 | + |
| 76 | +```sh |
| 77 | +args: |
| 78 | + --aws-zone-tags=owner |
| 79 | + --aws-zone-tags=vertical |
| 80 | +``` |
| 81 | + |
| 82 | +Or specify keys with values |
| 83 | + |
| 84 | +```sh |
| 85 | +args: |
| 86 | + --aws-zone-tags=owner=k8s |
| 87 | + --aws-zone-tags=vertical=k8s |
| 88 | +``` |
| 89 | + |
| 90 | +Can't specify multiple or separate values with commas: `key1=val1,key2=val2` at the moment. |
| 91 | +Filter only by value `--aws-zone-tags==tag-value` is not supported. |
| 92 | + |
| 93 | +```sh |
| 94 | +args: |
| 95 | + --aws-zone-tags=team=k8s,vertical=platform # this is not supported |
| 96 | + --aws-zone-tags==tag-value # this is not supported |
| 97 | +``` |
| 98 | + |
| 99 | +## Filtering Workflows |
| 100 | + |
| 101 | +***Filtering Sequence*** |
| 102 | + |
| 103 | +The diagram describes the sequence for filtering AWS zones. |
| 104 | + |
| 105 | +```mermaid |
| 106 | +flowchart TD |
| 107 | + A["zones"] --> B{"Is zonesCache valid?"} |
| 108 | + B -- Yes --> C["Return cached zones"] |
| 109 | + B -- No --> D["Initialize zones map"] |
| 110 | + D --> E["For each profile and client"] |
| 111 | + E --> F["Create paginator"] |
| 112 | + F --> G{"Has more pages?"} |
| 113 | + G -- Yes --> H["Get next page"] |
| 114 | + H --> I["For each zone in page"] |
| 115 | + I --> J{"Match zoneIDFilter?"} |
| 116 | + J -- No --> G |
| 117 | + J -- Yes --> K{"Match zoneTypeFilter?"} |
| 118 | + K -- No --> G |
| 119 | + K -- Yes --> L{"Match domainFilter?"} |
| 120 | + L -- No --> M{"zoneMatchParent?"} |
| 121 | + M -- No --> G |
| 122 | + M -- Yes --> N{"Match domainFilter parent?"} |
| 123 | + N -- No --> G |
| 124 | + N -- Yes --> O{"zoneTagFilter specified?"} |
| 125 | + O -- Yes --> P["Add zone to zonesToValidate"] |
| 126 | + O -- No --> Q["Add zone to zones map"] |
| 127 | + P --> Q |
| 128 | + Q --> G |
| 129 | + G -- No --> R{"zonesToValidate not empty?"} |
| 130 | + R -- Yes --> S["Get tags for zones"] |
| 131 | + S --> T["For each zone and tags"] |
| 132 | + T --> U{"Match zoneTagFilter?"} |
| 133 | + U -- No --> V["Delete zone from zones map"] |
| 134 | + U -- Yes --> W["Keep zone in zones map"] |
| 135 | + V --> W |
| 136 | + W --> R |
| 137 | + R -- No --> X["Update zonesCache"] |
| 138 | + X --> Y["Return zones"] |
| 139 | +``` |
| 140 | + |
| 141 | +***Filtering Flow*** |
| 142 | + |
| 143 | +The is a sequence diagram that describes the interaction between `external-dns`, `AWSProvider`, and `Route53Client` |
| 144 | +during the filtering process. Here is a high-level description: |
| 145 | + |
| 146 | +```mermaid |
| 147 | +sequenceDiagram |
| 148 | + participant external-dns |
| 149 | + participant AWSProvider |
| 150 | + participant Route53Client |
| 151 | +
|
| 152 | + external-dns->>AWSProvider: zones |
| 153 | + alt Cache is valid |
| 154 | + AWSProvider-->>external-dns: return cached zones |
| 155 | + else |
| 156 | +
|
| 157 | + AWSProvider->>Route53Client: ListHostedZonesPaginator |
| 158 | + loop While paginator.HasMorePages |
| 159 | + Route53Client->>AWSProvider: paginator.NextPage |
| 160 | + alt ThrottlingException |
| 161 | + AWSProvider->>external-dns: error |
| 162 | + else |
| 163 | + AWSProvider-->>external-dns: return error |
| 164 | + end |
| 165 | + AWSProvider->>AWSProvider: Filter zones |
| 166 | + alt Tags need validation |
| 167 | + AWSProvider->>Route53Client: ListTagsForResources |
| 168 | + Route53Client->>AWSProvider: return tags |
| 169 | + AWSProvider->>AWSProvider: Validate tags |
| 170 | + end |
| 171 | + end |
| 172 | + alt Cache duration > 0 |
| 173 | + AWSProvider->>AWSProvider: Update cache |
| 174 | + end |
| 175 | + AWSProvider-->>external-dns: return zones |
| 176 | + end |
| 177 | +``` |
0 commit comments