mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-30 05:25:35 +00:00
44aa809cb0
* cmd/k8s-nameserver,k8s-operator: add a nameserver that can resolve ts.net DNS names in cluster. Adds a simple nameserver that can respond to A record queries for ts.net DNS names. It can respond to queries from in-memory records, populated from a ConfigMap mounted at /config. It dynamically updates its records as the ConfigMap contents changes. It will respond with NXDOMAIN to queries for any other record types (AAAA to be implemented in the future). It can respond to queries over UDP or TCP. It runs a miekg/dns DNS server with a single registered handler for ts.net domain names. Queries for other domain names will be refused. The intended use of this is: 1) to allow non-tailnet cluster workloads to talk to HTTPS tailnet services exposed via Tailscale operator egress over HTTPS 2) to allow non-tailnet cluster workloads to talk to workloads in the same cluster that have been exposed to tailnet over their MagicDNS names but on their cluster IPs. DNSConfig CRD can be used to configure the operator to deploy kube nameserver (./cmd/k8s-nameserver) to cluster. Updates tailscale/tailscale#10499 Signed-off-by: Irbe Krumina <irbe@tailscale.com>
81 lines
3.1 KiB
Go
81 lines
3.1 KiB
Go
// Copyright (c) Tailscale Inc & AUTHORS
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
//go:build !plan9 && !windows
|
|
|
|
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func Test_generate(t *testing.T) {
|
|
base, err := os.Getwd()
|
|
base = filepath.Join(base, "../../../")
|
|
if err != nil {
|
|
t.Fatalf("error getting current working directory: %v", err)
|
|
}
|
|
defer cleanup(base)
|
|
if err := generate(base); err != nil {
|
|
t.Fatalf("CRD template generation: %v", err)
|
|
}
|
|
|
|
tempDir := t.TempDir()
|
|
helmCLIPath := filepath.Join(base, "tool/helm")
|
|
helmChartTemplatesPath := filepath.Join(base, "cmd/k8s-operator/deploy/chart")
|
|
helmPackageCmd := exec.Command(helmCLIPath, "package", helmChartTemplatesPath, "--destination", tempDir, "--version", "0.0.1")
|
|
helmPackageCmd.Stderr = os.Stderr
|
|
helmPackageCmd.Stdout = os.Stdout
|
|
if err := helmPackageCmd.Run(); err != nil {
|
|
t.Fatalf("error packaging Helm chart: %v", err)
|
|
}
|
|
helmPackagePath := filepath.Join(tempDir, "tailscale-operator-0.0.1.tgz")
|
|
helmLintCmd := exec.Command(helmCLIPath, "lint", helmPackagePath)
|
|
helmLintCmd.Stderr = os.Stderr
|
|
helmLintCmd.Stdout = os.Stdout
|
|
if err := helmLintCmd.Run(); err != nil {
|
|
t.Fatalf("Helm chart linter failed: %v", err)
|
|
}
|
|
|
|
// Test that default Helm install contains the Connector and ProxyClass CRDs.
|
|
installContentsWithCRD := bytes.NewBuffer([]byte{})
|
|
helmTemplateWithCRDCmd := exec.Command(helmCLIPath, "template", helmPackagePath)
|
|
helmTemplateWithCRDCmd.Stderr = os.Stderr
|
|
helmTemplateWithCRDCmd.Stdout = installContentsWithCRD
|
|
if err := helmTemplateWithCRDCmd.Run(); err != nil {
|
|
t.Fatalf("templating Helm chart with CRDs failed: %v", err)
|
|
}
|
|
if !strings.Contains(installContentsWithCRD.String(), "name: connectors.tailscale.com") {
|
|
t.Errorf("Connector CRD not found in default chart install")
|
|
}
|
|
if !strings.Contains(installContentsWithCRD.String(), "name: proxyclasses.tailscale.com") {
|
|
t.Errorf("ProxyClass CRD not found in default chart install")
|
|
}
|
|
if !strings.Contains(installContentsWithCRD.String(), "name: dnsconfigs.tailscale.com") {
|
|
t.Errorf("DNSConfig CRD not found in default chart install")
|
|
}
|
|
|
|
// Test that CRDs can be excluded from Helm chart install
|
|
installContentsWithoutCRD := bytes.NewBuffer([]byte{})
|
|
helmTemplateWithoutCRDCmd := exec.Command(helmCLIPath, "template", helmPackagePath, "--set", "installCRDs=false")
|
|
helmTemplateWithoutCRDCmd.Stderr = os.Stderr
|
|
helmTemplateWithoutCRDCmd.Stdout = installContentsWithoutCRD
|
|
if err := helmTemplateWithoutCRDCmd.Run(); err != nil {
|
|
t.Fatalf("templating Helm chart without CRDs failed: %v", err)
|
|
}
|
|
if strings.Contains(installContentsWithoutCRD.String(), "name: connectors.tailscale.com") {
|
|
t.Errorf("Connector CRD found in chart install that should not contain a CRD")
|
|
}
|
|
if strings.Contains(installContentsWithoutCRD.String(), "name: connectors.tailscale.com") {
|
|
t.Errorf("ProxyClass CRD found in chart install that should not contain a CRD")
|
|
}
|
|
if strings.Contains(installContentsWithoutCRD.String(), "name: dnsconfigs.tailscale.com") {
|
|
t.Errorf("DNSConfig CRD found in chart install that should not contain a CRD")
|
|
}
|
|
}
|