bonnefoa / kubectl-fzf

A fast kubectl autocompletion with fzf
MIT License
447 stars 33 forks source link

Cache builder as startup service #22

Closed delucca closed 2 years ago

delucca commented 4 years ago

Hi!

I'm trying to add cache_builder as a startup service on my computer, but I get the following error on systemctl status:

● cache-builder.service - Cache Builder for Kubectl-FZF Service
     Loaded: loaded (/etc/systemd/system/cache-builder.service; disabled; vendor preset: disabled)
     Active: failed (Result: exit-code) since Mon 2020-03-30 12:35:39 -03; 9min ago
    Process: 37840 ExecStart=/usr/local/bin/cache_builder (code=exited, status=255/EXCEPTION)
   Main PID: 37840 (code=exited, status=255/EXCEPTION)

mar 30 12:35:39 SPF1LT-PJ000443.ldap.quintoandar.com.br cache_builder[37840]:         /Users/anthoninbonnefoy/git-repos/kubectl-fzf/pkg/util/uti>
mar 30 12:35:39 SPF1LT-PJ000443.ldap.quintoandar.com.br cache_builder[37840]: main.getClientConfigAndCluster(0x8, 0x1382dd8, 0xc00027e390)
mar 30 12:35:39 SPF1LT-PJ000443.ldap.quintoandar.com.br cache_builder[37840]:         /Users/anthoninbonnefoy/git-repos/kubectl-fzf/cmd/cache_bu>
mar 30 12:35:39 SPF1LT-PJ000443.ldap.quintoandar.com.br cache_builder[37840]: main.start()
mar 30 12:35:39 SPF1LT-PJ000443.ldap.quintoandar.com.br cache_builder[37840]:         /Users/anthoninbonnefoy/git-repos/kubectl-fzf/cmd/cache_bu>
mar 30 12:35:39 SPF1LT-PJ000443.ldap.quintoandar.com.br cache_builder[37840]: main.main()
mar 30 12:35:39 SPF1LT-PJ000443.ldap.quintoandar.com.br cache_builder[37840]:         /Users/anthoninbonnefoy/git-repos/kubectl-fzf/cmd/cache_bu>
mar 30 12:35:39 SPF1LT-PJ000443.ldap.quintoandar.com.br cache_builder[37840]: Fatal error: open : no such file or directory
mar 30 12:35:39 SPF1LT-PJ000443.ldap.quintoandar.com.br systemd[1]: cache-builder.service: Main process exited, code=exited, status=255/EXCEPTION
mar 30 12:35:39 SPF1LT-PJ000443.ldap.quintoandar.com.br systemd[1]: cache-builder.service: Failed with result 'exit-code'.

Any idea on how to fix it? It apppears that it is trying to use a different user upon startup. Also, when I run this as a normal command after startup, it works as expected.

deamwork commented 4 years ago

The log indicated that systemctl managed cache builder cannot find the right kubeconfig (which located at ~/.kube/config).

cache_builder support setting kubeconfig by flag

https://github.com/bonnefoa/kubectl-fzf/blob/af8ac639c501b274aecb18bbddb709f433ef4a30/cmd/cache_builder/main.go#L56-L60

So just set the absolute path to the kubeconfig file as param will be fine. Make sure that file's permission is correct and readable.

bonnefoa commented 2 years ago

There's an example on how to use kubectl-fzf as a systemd service now https://github.com/bonnefoa/kubectl-fzf#install-kubectl-fzf-server-as-a-systemd-service kubectl-fzf now only relies on KUBECONFIG to look for the correct kubeconfig file.