utils.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright (c) Tailscale Inc & AUTHORS
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. //go:build !plan9
  4. // Package kube contains types and utilities for the Tailscale Kubernetes Operator.
  5. package kube
  6. import (
  7. "fmt"
  8. "tailscale.com/tailcfg"
  9. )
  10. const (
  11. Alpha1Version = "v1alpha1"
  12. DNSRecordsCMName = "dnsrecords"
  13. DNSRecordsCMKey = "records.json"
  14. )
  15. type Records struct {
  16. // Version is the version of this Records configuration. Version is
  17. // written by the operator, i.e when it first populates the Records.
  18. // k8s-nameserver must verify that it knows how to parse a given
  19. // version.
  20. Version string `json:"version"`
  21. // IP4 contains a mapping of DNS names to IPv4 address(es).
  22. IP4 map[string][]string `json:"ip4"`
  23. // IP6 contains a mapping of DNS names to IPv6 address(es).
  24. // This field is optional and will be omitted from JSON if empty.
  25. // It enables dual-stack DNS support in Kubernetes clusters.
  26. // +optional
  27. IP6 map[string][]string `json:"ip6,omitempty"`
  28. }
  29. // TailscaledConfigFileName returns a tailscaled config file name in
  30. // format expected by containerboot for the given CapVer.
  31. func TailscaledConfigFileName(cap tailcfg.CapabilityVersion) string {
  32. return fmt.Sprintf("cap-%v.hujson", cap)
  33. }
  34. // CapVerFromFileName parses the capability version from a tailscaled
  35. // config file name previously generated by TailscaledConfigFileNameForCap.
  36. func CapVerFromFileName(name string) (tailcfg.CapabilityVersion, error) {
  37. if name == "tailscaled" {
  38. return 0, nil
  39. }
  40. var cap tailcfg.CapabilityVersion
  41. _, err := fmt.Sscanf(name, "cap-%d.hujson", &cap)
  42. return cap, err
  43. }