updateDNSNames updates the DNS names for all agents in the workspace. DNS hosts must be all lowercase, or the resolver won't be able to find them. Usernames are globally unique & case-insensitive. Workspace names are unique per-user & case-insensitive. Agent names are unique per-workspace & case-ins
(options DNSNameOptions)
| 998 | // Workspace names are unique per-user & case-insensitive. |
| 999 | // Agent names are unique per-workspace & case-insensitive. |
| 1000 | func (w *Workspace) updateDNSNames(options DNSNameOptions) error { |
| 1001 | wsName := strings.ToLower(w.Name) |
| 1002 | username := strings.ToLower(w.ownerUsername) |
| 1003 | for id, a := range w.agents { |
| 1004 | agentName := strings.ToLower(a.Name) |
| 1005 | names := make(map[dnsname.FQDN][]netip.Addr) |
| 1006 | // TODO: technically, DNS labels cannot start with numbers, but the rules are often not |
| 1007 | // strictly enforced. |
| 1008 | fqdn, err := dnsname.ToFQDN(fmt.Sprintf("%s.%s.me.%s.", agentName, wsName, options.Suffix)) |
| 1009 | if err != nil { |
| 1010 | return err |
| 1011 | } |
| 1012 | names[fqdn] = []netip.Addr{CoderServicePrefix.AddrFromUUID(a.ID)} |
| 1013 | fqdn, err = dnsname.ToFQDN(fmt.Sprintf("%s.%s.%s.%s.", agentName, wsName, username, options.Suffix)) |
| 1014 | if err != nil { |
| 1015 | return err |
| 1016 | } |
| 1017 | names[fqdn] = []netip.Addr{CoderServicePrefix.AddrFromUUID(a.ID)} |
| 1018 | if len(w.agents) == 1 { |
| 1019 | fqdn, err = dnsname.ToFQDN(fmt.Sprintf("%s.%s.", wsName, options.Suffix)) |
| 1020 | if err != nil { |
| 1021 | return err |
| 1022 | } |
| 1023 | names[fqdn] = []netip.Addr{CoderServicePrefix.AddrFromUUID(a.ID)} |
| 1024 | } |
| 1025 | a.Hosts = names |
| 1026 | w.agents[id] = a |
| 1027 | } |
| 1028 | return nil |
| 1029 | } |
| 1030 | |
| 1031 | type Agent struct { |
| 1032 | ID uuid.UUID |
no test coverage detected