MCPcopy Index your code
hub / github.com/coder/coder / updateDNSNames

Method updateDNSNames

tailnet/controllers.go:1000–1029  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

998// Workspace names are unique per-user & case-insensitive.
999// Agent names are unique per-workspace & case-insensitive.
1000func (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
1031type Agent struct {
1032 ID uuid.UUID

Callers 1

updateDNSNamesLockedMethod · 0.80

Calls 1

AddrFromUUIDMethod · 0.80

Tested by

no test coverage detected