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

argocd version --client does not work offline in --core mode #7986

Closed
jessesuen opened this issue Dec 17, 2021 · 11 comments · Fixed by #8341
Closed

argocd version --client does not work offline in --core mode #7986

jessesuen opened this issue Dec 17, 2021 · 11 comments · Fixed by #8341
Labels
bug Something isn't working component:cli Affects the Argo CD CLI good first issue Good for newcomers

Comments

@jessesuen
Copy link
Member

jessesuen commented Dec 17, 2021

When using ArgoCD in --core mode, I had just wanted to see argocd client version, and I did not have a connection to k8s or argocd server. But argocd version --client still tries to connect:

When k8s access is unavailable:

$ argocd version --client
I1217 11:52:18.998450   63040 trace.go:205] Trace[425192877]: "Reflector ListAndWatch" name:pkg/mod/k8s.io/client-go@v0.22.2/tools/cache/reflector.go:167 (17-Dec-2021 11:51:50.485) (total time: 28513ms):
Trace[425192877]: [28.513512417s] [28.513512417s] END
I1217 11:52:18.999184   63040 trace.go:205] Trace[528268835]: "Reflector ListAndWatch" name:pkg/mod/k8s.io/client-go@v0.22.2/tools/cache/reflector.go:167 (17-Dec-2021 11:51:58.043) (total time: 20955ms):
Trace[528268835]: [20.955849917s] [20.955849917s] END

When k8s is available, but argocd is not installed:

$ argocd version --client
FATA[0000] configmap "argocd-cm" not found

The expectation is that argocd version --client should always work in an offline mode.

To reproduce:

k3d cluster start
argocd login --core
k3d cluster stop
argocd version --client

Affected Version:

argocd: v2.2.0+6da92a8
  BuildDate: 2021-12-14T18:11:55Z
  GitCommit: 6da92a8e8103ce4145bb0fe2b7e952be79c9ff0a
  GitTreeState: clean
  GoVersion: go1.16.11
  Compiler: gc
  Platform: darwin/amd64
@jessesuen jessesuen added bug Something isn't working good first issue Good for newcomers component:cli Affects the Argo CD CLI labels Dec 17, 2021
@jessesuen jessesuen changed the title argocd version --client still requires k8s access in --core mode argocd version --client does not work offline in --core mode Dec 17, 2021
@jannfis
Copy link
Member

jannfis commented Dec 19, 2021

This affects much more parts of the CLI. E.g. when your kubectl context is not set up correctly, top level commands behave weird:

# Login should not work with a broken client config
vagrant@argocd-nutshell:~$ argocd login --core
Context 'kubernetes' updated
vagrant@argocd-nutshell:~$ argocd app 
FATA[0000] configmap "argocd-cm" not found              
vagrant@argocd-nutshell:~$ argocd repo
FATA[0000] configmap "argocd-cm" not found          
# etc etc

Surprisingly, explicitly calling a top level command with --help works:

vagrant@argocd-nutshell:~$ argocd app --help
Manage applications

Usage:
  argocd app [flags]
  argocd app [command]

...

@khalilswdp
Copy link

Hi, I'm interested in solving this problem since it is tagged good first issue. Can I get some more help or guidance on how to do contribute?

@ishitasequeira
Copy link
Member

Thanks @khalilswdp. You can follow this link

@debu99
Copy link

debu99 commented Dec 26, 2021

any update?

@khalilswdp
Copy link

Hi @debu99, I found out that we're using cobra go client for the cli, and that this is the exact line in cobra that deals with the entered command

versionCmd.Flags().BoolVar(&client, "client", false, "client version only (no server required)")
. I still need some more time and some help to get used to Go, Cobra, ArgoCD and reproduce the problem myself and try to understand why it happens and how I can fix it to suit the expected behavior. If you have any suggestions or guidance for me to follow I'll be greatly appreciative. If this issue is time sensitive and needs to be done faster then it's okay if someone else solves it, but if it is not, then I would really like to have a go at it and learn a ton along the way...

@khalilswdp
Copy link

I think we should find a way to deal with an error if one occurs especially in this line:

errors.CheckError(err)

please, if you have advice or suggestions, let me know

@debu99
Copy link

debu99 commented Dec 27, 2021

haven't checked the root cause yet but my workaround is change the default namespace to arogcd then no more errors

@joebowbeer
Copy link
Contributor

joebowbeer commented Dec 31, 2021

@jessesuen Dup of #7426?

I see several issues that at first glance seem related to this, or to one of the errors mentioned in the description.

#7721
#7426
#7226
#5473
#5219

They all involve the argocd namespace and/or context that the CLI uses.

@khalilswdp
Copy link

khalilswdp commented Dec 31, 2021

I think we can propose instead of checking the version and getting an error immediately afterwards if there's an error:

	errors.CheckError(err)

	return v

We check if there's no error, we return the version as usual, otherwise, we get it from common (which doesn't return an error):

	if err == nil {
		return v
	}
	vers := common.GetVersion()
	return &version.VersionMessage{Version: vers.Version}

I am sorry, i'm not really good at Go or Cobra or argocd, and I haven't fully understood how it works. I also don't know how to test the changes I've made even after reading the toolchain guide.
It shows me this error when writing make test:

FAIL
+ report
+ set -eux -o pipefail
+ go-junit-report
make: *** [Makefile:362: test-local] Error 1
make: *** [Makefile:357: test] Error 2

and:

--- FAIL: TestVerifyCommitSignature (98.67s)
    git_test.go:300: 
                Error Trace:    git_test.go:300
                Error:          Received unexpected error:
                                `git fetch origin --tags --force` failed timeout after 1m30s
                Test:           TestVerifyCommitSignature
    git_test.go:306: 
                Error Trace:    git_test.go:306
                Error:          Received unexpected error:
                                `git checkout --force cb1f06c72ad4e52b5a8df4d016010d738b3cb1c4` failed exit status 128: fatal: reference is not a tree: cb1f06c72ad4e52b5a8df4d016010d738b3cb1c4
                Test:           TestVerifyCommitSignature
    git_test.go:314: 
                Error Trace:    git_test.go:314
                Error:          "error: 28027897aad1262662096745f2ce2d4c74d02b7f: unable to read file." does not contain "gpg: Signature made"
                Test:           TestVerifyCommitSignature
    git_test.go:321: 
                Error Trace:    git_test.go:321
                Error:          Should be empty, but was error: 85d660f0b967960becce3d49bd51c678ba2a5d24: unable to read file.
                Test:           TestVerifyCommitSignature
FAIL

And

go mod vendor
go mod vendor: read /go/pkg/mod/github.com/!knetic/govaluate@v3.0.1-0.20171022003610-9aa49832a739+incompatible/MANUAL.md: input/output error
make: *** [Makefile:311: mod-vendor-local] Error 1
make: *** [Makefile:215: codegen] Error 2

when trying to run make codegen
How do I generate a binary of argocd or something similar that I can test on the fly and swap easily and run and test the commands against? (how do you guys develop and test your changes?)

@cwilkers
Copy link
Contributor

I had more luck with the local toolchain on Fedora 35. Podman cannot quite manage the docker permissions the same as docker, so I had to switch. To make just the client, do make cli-local

@gdsoumya
Copy link
Member

gdsoumya commented Feb 2, 2022

I was debugging where the error originates from and it appears that even for client version calls the PreRun hook tries to startup the local API server. I have added a check for version --client that skips this hook solving the issue. PR #8341

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working component:cli Affects the Argo CD CLI good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants