diff --git a/cmd/tailscale/cli/configure-kube.go b/cmd/tailscale/cli/configure-kube.go index 1231991de..dcda2f030 100644 --- a/cmd/tailscale/cli/configure-kube.go +++ b/cmd/tailscale/cli/configure-kube.go @@ -119,7 +119,7 @@ func updateKubeconfig(cfgYaml []byte, fqdn string) ([]byte, error) { var clusters []any if cm, ok := cfg["clusters"]; ok { - clusters = cm.([]any) + clusters, _ = cm.([]any) } cfg["clusters"] = appendOrSetNamed(clusters, fqdn, map[string]any{ "name": fqdn, @@ -130,7 +130,7 @@ func updateKubeconfig(cfgYaml []byte, fqdn string) ([]byte, error) { var users []any if um, ok := cfg["users"]; ok { - users = um.([]any) + users, _ = um.([]any) } cfg["users"] = appendOrSetNamed(users, "tailscale-auth", map[string]any{ // We just need one of these, and can reuse it for all clusters. @@ -144,7 +144,7 @@ func updateKubeconfig(cfgYaml []byte, fqdn string) ([]byte, error) { var contexts []any if cm, ok := cfg["contexts"]; ok { - contexts = cm.([]any) + contexts, _ = cm.([]any) } cfg["contexts"] = appendOrSetNamed(contexts, fqdn, map[string]any{ "name": fqdn, diff --git a/cmd/tailscale/cli/configure-kube_test.go b/cmd/tailscale/cli/configure-kube_test.go index 0f326cd64..d71a9b627 100644 --- a/cmd/tailscale/cli/configure-kube_test.go +++ b/cmd/tailscale/cli/configure-kube_test.go @@ -48,6 +48,31 @@ func TestKubeconfig(t *testing.T) { current-context: foo.tail-scale.ts.net kind: Config users: +- name: tailscale-auth + user: + token: unused`, + }, + { + name: "all configs, clusters, users have been deleted", + in: `apiVersion: v1 +clusters: null +contexts: null +kind: Config +current-context: some-non-existent-cluster +users: null`, + want: `apiVersion: v1 +clusters: +- cluster: + server: https://foo.tail-scale.ts.net + name: foo.tail-scale.ts.net +contexts: +- context: + cluster: foo.tail-scale.ts.net + user: tailscale-auth + name: foo.tail-scale.ts.net +current-context: foo.tail-scale.ts.net +kind: Config +users: - name: tailscale-auth user: token: unused`,