Skip to content

Commit

Permalink
Client: Fix for things expecting v1beta1 api version
Browse files Browse the repository at this point in the history
Some tools (like Lens) don't understand the client.authentication.k8s.io/v1 apiversion yet. This commit makes the client respond with v1beta1 responses if given a v1beta1 request.

Additionally, a newline is emitted after the password is entered, which provides better user experience
  • Loading branch information
mich181189 committed Dec 13, 2021
1 parent 390347d commit b6240d7
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion auth-client/main.go
Expand Up @@ -147,6 +147,7 @@ func main() {
var givenUsername string
// ignore any errors here - we will just check the string
fmt.Scanln(&givenUsername)
fmt.Fprintf(os.Stderr, "\n")

if len(givenUsername) == 0 {
givenUsername = user
Expand All @@ -171,10 +172,24 @@ func main() {
expiration = metav1.NewTime(time.Now().Add(time.Hour * 6))
}

// We really only care about this so we can return the same version string we were given
var inputExecCredential clientauth.ExecCredential
inputExecCredentialData := os.Getenv("KUBERNETES_EXEC_INFO")
err := json.Unmarshal([]byte(inputExecCredentialData), &inputExecCredential)
if err != nil {
fmt.Fprintln(os.Stderr, "Could not read KUBERNETES_EXEC_INFO")
// set some sane-ish defaults
inputExecCredential = clientauth.ExecCredential{
TypeMeta: metav1.TypeMeta{
APIVersion: "client.authentication.k8s.io/v1",
},
}
}

output := clientauth.ExecCredential{
TypeMeta: metav1.TypeMeta{
Kind: "ExecCredential",
APIVersion: "client.authentication.k8s.io/v1",
APIVersion: inputExecCredential.APIVersion,
},
Status: &clientauth.ExecCredentialStatus{
Token: token,
Expand Down

0 comments on commit b6240d7

Please sign in to comment.