mirror of
https://github.com/tailscale/tailscale.git
synced 2025-05-03 14:11:02 +00:00
cmd/tailscale/cli: fix configuring partially empty kubeconfig (#11417)
When a user deletes the last cluster/user/context from their kubeconfig via 'kubectl delete-[cluster|user|context] command, kubectx sets the relevant field in kubeconfig to 'null'. This was breaking our conversion logic that was assuming that the field is either non-existant or is an array. Updates tailscale/corp#18320 Signed-off-by: Irbe Krumina <irbe@tailscale.com>
This commit is contained in:
parent
cf8948da5f
commit
ea55f96310
@ -119,7 +119,7 @@ func updateKubeconfig(cfgYaml []byte, fqdn string) ([]byte, error) {
|
|||||||
|
|
||||||
var clusters []any
|
var clusters []any
|
||||||
if cm, ok := cfg["clusters"]; ok {
|
if cm, ok := cfg["clusters"]; ok {
|
||||||
clusters = cm.([]any)
|
clusters, _ = cm.([]any)
|
||||||
}
|
}
|
||||||
cfg["clusters"] = appendOrSetNamed(clusters, fqdn, map[string]any{
|
cfg["clusters"] = appendOrSetNamed(clusters, fqdn, map[string]any{
|
||||||
"name": fqdn,
|
"name": fqdn,
|
||||||
@ -130,7 +130,7 @@ func updateKubeconfig(cfgYaml []byte, fqdn string) ([]byte, error) {
|
|||||||
|
|
||||||
var users []any
|
var users []any
|
||||||
if um, ok := cfg["users"]; ok {
|
if um, ok := cfg["users"]; ok {
|
||||||
users = um.([]any)
|
users, _ = um.([]any)
|
||||||
}
|
}
|
||||||
cfg["users"] = appendOrSetNamed(users, "tailscale-auth", map[string]any{
|
cfg["users"] = appendOrSetNamed(users, "tailscale-auth", map[string]any{
|
||||||
// We just need one of these, and can reuse it for all clusters.
|
// 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
|
var contexts []any
|
||||||
if cm, ok := cfg["contexts"]; ok {
|
if cm, ok := cfg["contexts"]; ok {
|
||||||
contexts = cm.([]any)
|
contexts, _ = cm.([]any)
|
||||||
}
|
}
|
||||||
cfg["contexts"] = appendOrSetNamed(contexts, fqdn, map[string]any{
|
cfg["contexts"] = appendOrSetNamed(contexts, fqdn, map[string]any{
|
||||||
"name": fqdn,
|
"name": fqdn,
|
||||||
|
@ -48,6 +48,31 @@ contexts:
|
|||||||
current-context: foo.tail-scale.ts.net
|
current-context: foo.tail-scale.ts.net
|
||||||
kind: Config
|
kind: Config
|
||||||
users:
|
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
|
- name: tailscale-auth
|
||||||
user:
|
user:
|
||||||
token: unused`,
|
token: unused`,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user