Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gscloud path gets hard-coded into kubectl config #10

Open
dennisjac opened this issue Feb 12, 2020 · 7 comments
Open

gscloud path gets hard-coded into kubectl config #10

dennisjac opened this issue Feb 12, 2020 · 7 comments
Labels
bug Something isn't working

Comments

@dennisjac
Copy link

After setting up kubectl using gscloud kubectl now complains that it cannot find gscloud in /home/dennis/Downloads for some reason (I copied gscloud to /usr/local/bin):

$ kubectl get nodes
Unable to connect to the server: getting credentials: exec: fork/exec /home/dennis/Downloads/gscloud: no such file or directory

The problem seems to be that the path is hard-coded into the kubernetes config file as command: /home/dennis/Dowloads/gscloud. When I replace this with command: gscloud then kubectl finds the copy in /usr/local/bin and no longer throws an error.

@itakouna
Copy link
Contributor

@dennisjac thanks for opening the issue. We will work on it ASAP.

@neur0manc
Copy link

As far as I can tell the current working directory is assumed to be the path to the gscloud executable. It should be relatively simple to determine the absolute path of the running executable, which should lead to a more robust solution:

package main

import (
    "fmt"
    "log"
    "os"
    "path/filepath"
)

func main() {
    dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
    if err != nil {
        log.Fatal(err)
    }
    absPath := fmt.Sprintf("%s%s%s", dir, string(os.PathSeparator), os.Args[0])
    fmt.Println(absPath)
}

Which results in something like

~/source/personal/go % go build -o test test.go && ./test
/Users/Stephan/source/personal/go/./test

@itakouna
Copy link
Contributor

itakouna commented Mar 11, 2020

@ls42 I think @dennisjac meant that gscloud path is hardcoded in ~/.kubeconfig/config. However, we provided subcommand kubernetes cluster save-kubeconfig that updates the ~/.kubeconfig/config with the right path. However, @dennisjac has moved gscloud after generating ~/.kubeconfig/config. Thus, he needs to update ~/.kubeconfig/config with the new gscloud path or he can use the subcommand kubernetes cluster save-kubeconfig.

part of kubeconfig file:

users:
- name: k8s-1-16-4-ss-test-admin
  user:
    exec:
      apiVersion: client.authentication.k8s.io/v1beta1
      args:
      - --config
........
      command: /usr/local/bin/gscloud

@neur0manc
Copy link

meant that gscloud path is hardcoded in ~/.kubeconfig/config

Yes, that's true. But I think the issue is, that we assume the wrong directory as the path to the binary. @dennisjac seems to have the binary in /usr/local/bin, but we assume that it is in $PWD (and I don't think he moved it afterwards).

So in order to make a more robust solution, we should not assume that the binary is in the current working directory, but determine the absolute path to it and then write ~/.kube/config with the full path.

@bkircher
Copy link
Contributor

So in order to make a more robust solution, we should not assume that the binary is in the current working directory, but determine the absolute path to it and then write ~/.kube/config with the full path.

Couldn't we just assume that the binary is installed in $PATH and not write the path to gscloud in kubeconfig at all?

@bkircher bkircher added the bug Something isn't working label Jul 14, 2020
@bkircher bkircher added this to the v0.4.0 milestone Jul 14, 2020
@bkircher
Copy link
Contributor

bkircher commented Aug 6, 2020

ping

@ajfriesen
Copy link
Contributor

ajfriesen commented Aug 7, 2020

Just an idea:

How about storing the path of the gscloud binary in something like .cache/gscloud/path.env
Is it possible to store the path for gscloud in .cache/gscloud/path.env on every call?
Then kubectl could lookup this via an environment variable (I am not sure if this is possible).

@bkircher bkircher removed this from the v0.4.0 milestone Aug 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants