From 964d4889c4649407979a2bcf5638a26fbb3c91d4 Mon Sep 17 00:00:00 2001 From: Monis Khan Date: Fri, 19 Mar 2021 18:40:17 -0400 Subject: [PATCH 1/2] pinniped whoami: print correct cluster info when --kubeconfig-context is used Signed-off-by: Monis Khan --- cmd/pinniped/cmd/whoami.go | 17 +++++++---- cmd/pinniped/cmd/whoami_test.go | 54 +++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 6 deletions(-) diff --git a/cmd/pinniped/cmd/whoami.go b/cmd/pinniped/cmd/whoami.go index bf973981..e0e83c01 100644 --- a/cmd/pinniped/cmd/whoami.go +++ b/cmd/pinniped/cmd/whoami.go @@ -78,7 +78,7 @@ func runWhoami(output io.Writer, getClientset getConciergeClientsetFunc, flags * return fmt.Errorf("could not configure Kubernetes client: %w", err) } - clusterInfo, err := getCurrentCluster(clientConfig) + clusterInfo, err := getCurrentCluster(clientConfig, flags.kubeconfigContextOverride) if err != nil { return fmt.Errorf("could not get current cluster info: %w", err) } @@ -101,24 +101,29 @@ func runWhoami(output io.Writer, getClientset getConciergeClientsetFunc, flags * return nil } -func getCurrentCluster(clientConfig clientcmd.ClientConfig) (*clusterInfo, error) { - currentKubeconfig, err := clientConfig.RawConfig() +func getCurrentCluster(clientConfig clientcmd.ClientConfig, currentContextNameOverride string) (*clusterInfo, error) { + currentKubeConfig, err := clientConfig.RawConfig() if err != nil { return nil, err } + contextName := currentKubeConfig.CurrentContext + if len(currentContextNameOverride) > 0 { + contextName = currentContextNameOverride + } + unknownClusterInfo := &clusterInfo{name: "???", url: "???"} - context, ok := currentKubeconfig.Contexts[currentKubeconfig.CurrentContext] + ctx, ok := currentKubeConfig.Contexts[contextName] if !ok { return unknownClusterInfo, nil } - cluster, ok := currentKubeconfig.Clusters[context.Cluster] + cluster, ok := currentKubeConfig.Clusters[ctx.Cluster] if !ok { return unknownClusterInfo, nil } - return &clusterInfo{name: context.Cluster, url: cluster.Server}, nil + return &clusterInfo{name: ctx.Cluster, url: cluster.Server}, nil } func writeWhoamiOutput(output io.Writer, flags *whoamiFlags, cInfo *clusterInfo, whoAmI *identityv1alpha1.WhoAmIRequest) error { diff --git a/cmd/pinniped/cmd/whoami_test.go b/cmd/pinniped/cmd/whoami_test.go index 38c7f99c..c5480036 100644 --- a/cmd/pinniped/cmd/whoami_test.go +++ b/cmd/pinniped/cmd/whoami_test.go @@ -205,6 +205,60 @@ func TestWhoami(t *testing.T) { wantError: true, wantStderr: "Error: could not get current cluster info: stat this-file-does-not-exist: no such file or directory\n", }, + { + name: "different kubeconfig context, but same as current", + args: []string{ + "--kubeconfig", "./testdata/kubeconfig.yaml", + "--kubeconfig-context", "kind-kind", + }, + wantStdout: here.Doc(` + Current cluster info: + + Name: kind-kind + URL: https://fake-server-url-value + + Current user info: + + Username: some-username + Groups: some-group-0, some-group-1 + `), + }, + { + name: "different kubeconfig context, not current", + args: []string{ + "--kubeconfig", "./testdata/kubeconfig.yaml", + "--kubeconfig-context", "some-other-context", + }, + wantStdout: here.Doc(` + Current cluster info: + + Name: some-other-cluster + URL: https://some-other-fake-server-url-value + + Current user info: + + Username: some-username + Groups: some-group-0, some-group-1 + `), + }, + { + name: "invalid kubeconfig context prints ???", + args: []string{ + "--kubeconfig", "./testdata/kubeconfig.yaml", + "--kubeconfig-context", "invalid", + }, + wantStdout: here.Doc(` + Current cluster info: + + Name: ??? + URL: ??? + + Current user info: + + Username: some-username + Groups: some-group-0, some-group-1 + `), + }, { name: "getting clientset fails", gettingClientsetErr: constable.Error("some get clientset error"), From 1e7f2c7735560144406560fa41b49e49e81b7a72 Mon Sep 17 00:00:00 2001 From: Matt Moyer Date: Mon, 22 Mar 2021 09:33:29 -0500 Subject: [PATCH 2/2] Upgrade Kubernetes runtime libraries to v0.20.5. Signed-off-by: Matt Moyer --- go.mod | 12 ++++++------ go.sum | 30 +++++++++++++++--------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/go.mod b/go.mod index c8717c7f..fbdd5ea0 100644 --- a/go.mod +++ b/go.mod @@ -30,14 +30,14 @@ require ( golang.org/x/sync v0.0.0-20201207232520-09787c993a3a golang.org/x/tools v0.0.0-20200825202427-b303f430e36d // indirect gopkg.in/square/go-jose.v2 v2.5.1 - k8s.io/api v0.20.4 - k8s.io/apimachinery v0.20.4 - k8s.io/apiserver v0.20.4 - k8s.io/client-go v0.20.4 - k8s.io/component-base v0.20.4 + k8s.io/api v0.20.5 + k8s.io/apimachinery v0.20.5 + k8s.io/apiserver v0.20.5 + k8s.io/client-go v0.20.5 + k8s.io/component-base v0.20.5 k8s.io/gengo v0.0.0-20201113003025-83324d819ded k8s.io/klog/v2 v2.8.0 - k8s.io/kube-aggregator v0.20.4 + k8s.io/kube-aggregator v0.20.5 k8s.io/kube-openapi v0.0.0-20201113171705-d219536bb9fd k8s.io/utils v0.0.0-20201110183641-67b214c5f920 sigs.k8s.io/yaml v1.2.0 diff --git a/go.sum b/go.sum index a0accf60..d8a68fbe 100644 --- a/go.sum +++ b/go.sum @@ -1511,17 +1511,17 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= howett.net/plist v0.0.0-20181124034731-591f970eefbb/go.mod h1:vMygbs4qMhSZSc4lCUl2OEE+rDiIIJAIdR4m7MiMcm0= -k8s.io/api v0.20.4 h1:xZjKidCirayzX6tHONRQyTNDVIR55TYVqgATqo6ZULY= -k8s.io/api v0.20.4/go.mod h1:++lNL1AJMkDymriNniQsWRkMDzRaX2Y/POTUi8yvqYQ= -k8s.io/apimachinery v0.20.4 h1:vhxQ0PPUUU2Ns1b9r4/UFp13UPs8cw2iOoTjnY9faa0= -k8s.io/apimachinery v0.20.4/go.mod h1:WlLqWAHZGg07AeltaI0MV5uk1Omp8xaN0JGLY6gkRpU= -k8s.io/apiserver v0.20.4 h1:zMMKIgIUDIFiwK3LyY7qOV4Z4wKsHVYExL6vXY9fPX4= -k8s.io/apiserver v0.20.4/go.mod h1:Mc80thBKOyy7tbvFtB4kJv1kbdD0eIH8k8vianJcbFM= -k8s.io/client-go v0.20.4 h1:85crgh1IotNkLpKYKZHVNI1JT86nr/iDCvq2iWKsql4= -k8s.io/client-go v0.20.4/go.mod h1:LiMv25ND1gLUdBeYxBIwKpkSC5IsozMMmOOeSJboP+k= -k8s.io/code-generator v0.20.4/go.mod h1:UsqdF+VX4PU2g46NC2JRs4gc+IfrctnwHb76RNbWHJg= -k8s.io/component-base v0.20.4 h1:gdvPs4G11e99meQnW4zN+oYOjH8qkLz1sURrAzvKWqc= -k8s.io/component-base v0.20.4/go.mod h1:t4p9EdiagbVCJKrQ1RsA5/V4rFQNDfRlevJajlGwgjI= +k8s.io/api v0.20.5 h1:zsMTffV0Le2EiI0aKvlTHEnXGxk1HiqGRhJcCPiI7JI= +k8s.io/api v0.20.5/go.mod h1:FQjAceXnVaWDeov2YUWhOb6Yt+5UjErkp6UO3nczO1Y= +k8s.io/apimachinery v0.20.5 h1:wO/FxMVRn223rAKxnBbwCyuN96bS9MFTIvP0e/V7cps= +k8s.io/apimachinery v0.20.5/go.mod h1:WlLqWAHZGg07AeltaI0MV5uk1Omp8xaN0JGLY6gkRpU= +k8s.io/apiserver v0.20.5 h1:J8l/MJ9pdYncrc1lhxzObDa7jgrUNfettKGNF8mFV+c= +k8s.io/apiserver v0.20.5/go.mod h1:AY3lKhcJ2Tm81XvvcBzk2VnKINSoN+qczYsdo2YEvIc= +k8s.io/client-go v0.20.5 h1:dJGtYUvFrFGjQ+GjXEIby0gZWdlAOc0xJBJqY3VyDxA= +k8s.io/client-go v0.20.5/go.mod h1:Ee5OOMMYvlH8FCZhDsacjMlCBwetbGZETwo1OA+e6Zw= +k8s.io/code-generator v0.20.5/go.mod h1:UsqdF+VX4PU2g46NC2JRs4gc+IfrctnwHb76RNbWHJg= +k8s.io/component-base v0.20.5 h1:8BZQKLJGhWrxtB7kIOEejKDtAKr1HOYvB0PZNeTyLS0= +k8s.io/component-base v0.20.5/go.mod h1:l0isoBLGyQKwRoTWbPHR6jNDd3/VqQD43cNlsjddGng= k8s.io/gengo v0.0.0-20200413195148-3a45101e95ac/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0= k8s.io/gengo v0.0.0-20201113003025-83324d819ded h1:JApXBKYyB7l9xx+DK7/+mFjC7A9Bt5A93FPvFD0HIFE= k8s.io/gengo v0.0.0-20201113003025-83324d819ded/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E= @@ -1530,8 +1530,8 @@ k8s.io/klog/v2 v2.2.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y= k8s.io/klog/v2 v2.4.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y= k8s.io/klog/v2 v2.8.0 h1:Q3gmuM9hKEjefWFFYF0Mat+YyFJvsUyYuwyNNJ5C9Ts= k8s.io/klog/v2 v2.8.0/go.mod h1:hy9LJ/NvuK+iVyP4Ehqva4HxZG/oXyIS3n3Jmire4Ec= -k8s.io/kube-aggregator v0.20.4 h1:j/SUwPy1eO+ud3XOUGmH18gISPyerqhXOoNRZDbv3fs= -k8s.io/kube-aggregator v0.20.4/go.mod h1:0ixQ9De7KXyHteXizS6nVtrnKqGa4kiuxl9rEBsNccw= +k8s.io/kube-aggregator v0.20.5 h1:tusb7NBtlZkdkwTFO4gd+em60iI5sH1T/ijL9Li0ObU= +k8s.io/kube-aggregator v0.20.5/go.mod h1:0S88kjWs/0UzOMOko6fjy4nwu1OTRrxlpa7rsx0PErA= k8s.io/kube-openapi v0.0.0-20201113171705-d219536bb9fd h1:sOHNzJIkytDF6qadMNKhhDRpc6ODik8lVC6nOur7B2c= k8s.io/kube-openapi v0.0.0-20201113171705-d219536bb9fd/go.mod h1:WOJ3KddDSol4tAGcJo0Tvi+dK12EcqSLqcWsryKMpfM= k8s.io/utils v0.0.0-20201110183641-67b214c5f920 h1:CbnUZsM497iRC5QMVkHwyl8s2tB3g7yaSHkYPkpgelw= @@ -1545,8 +1545,8 @@ rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8 rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= -sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.14 h1:TihvEz9MPj2u0KWds6E2OBUXfwaL4qRJ33c7HGiJpqk= -sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.14/go.mod h1:LEScyzhFmoF5pso/YSeBstl57mOzx9xlU9n85RGrDQg= +sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.15 h1:4uqm9Mv+w2MmBYD+F4qf/v6tDFUdPOk29C095RbU5mY= +sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.15/go.mod h1:LEScyzhFmoF5pso/YSeBstl57mOzx9xlU9n85RGrDQg= sigs.k8s.io/structured-merge-diff/v4 v4.0.2 h1:YHQV7Dajm86OuqnIR6zAelnDWBRjo+YhYV9PmGrh1s8= sigs.k8s.io/structured-merge-diff/v4 v4.0.2/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK1F7G282QMXDPYydCw= sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=