argo-cd: ArgoCD go.mod requires k8s.io/kubernetes directly, resulting in go build unknown revision v0.0.0
If you are trying to resolve an environment-specific issue or have a one-off question about the edge case that does not require a feature then please consider asking a question in argocd slack channel.
Checklist:
- I’ve searched in the docs and FAQ for my answer: http://bit.ly/argocd-faq.
- I’ve included steps to reproduce the bug.
- I’ve pasted the output of
argocd version
. (I’m including the types from 1.6.2)
Describe the bug
The ArgoCD go.mod file requires k8s.io/kubernetes instead of individually published kubernetes packages. https://github.com/argoproj/argo-cd/blob/master/go.mod#L80
https://github.com/kubernetes/kubernetes/issues/79384#issuecomment-505725449 According to the issue linked above, this is not supported behavior, and leads to issues with including argocd types for use with go-client.
To Reproduce
Add argocd to an external project’s go.mod.
module my-module
require (
github.com/argoproj/argo-cd v1.6.2
...
Import the argocd types and client into your package.
package my-package
import (
argocd "github.com/argoproj/argo-cd/pkg/apis/application/v1alpha1"
argocdclient "github.com/argoproj/argo-cd/pkg/client/clientset/versioned"
)
Attempt to go build
.
$ go build
go: finding module for package github.com/argoproj/argo-cd/pkg/client/clientset/versioned
go: found github.com/argoproj/argo-cd/pkg/client/clientset/versioned in github.com/argoproj/argo-cd v1.6.2
go: github.com/argoproj/argo-cd@v1.6.2 requires
k8s.io/kubernetes@v1.16.6 requires
k8s.io/api@v0.0.0: reading k8s.io/api/go.mod at revision v0.0.0: unknown revision v0.0.0
Notice you can’t go build
, because k8s.io/api@v0.0.0
is an unknown revision.
Expected behavior
Including argocd types is supported and compiles successfully with go build
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 14
- Comments: 17 (4 by maintainers)
Commits related to this issue
- chore: Remove usages of k8s.io/kubernetes (#4055) (#5434) * chore:Remove usages of k8s.io/kubernetes Signed-off-by: Mark Pim <j.mark.pim@gmail.com> * Linting fix Signed-off-by: Mark Pim <j.m... — committed to argoproj/argo-cd by jMarkP 3 years ago
- chore: Remove usages of k8s.io/kubernetes (#4055) (#5434) * chore:Remove usages of k8s.io/kubernetes Signed-off-by: Mark Pim <j.mark.pim@gmail.com> * Linting fix Signed-off-by: Mark Pim <j.m... — committed to shubhamagarwal19/argo-cd by jMarkP 3 years ago
We’ve been using the above linked workaround but ideally we would not need replace directives in every project where we import Argo code. Argo projects should only require and import k8s.io modules as needed.
@yhrn at a glance, I wouldn’t be opposed to that refactor… I’m not sure how it might complicate our already-complex codegen code though.
Hello,
Here is my
go.mod
file where I managed to referencegithub.com/argoproj/argo-cd/v2 v2.0.5
Argo CD imports k8s.io/kubernetes package to perform client-side diffing and execute
kubectl apply/auth reconcile
programmatically instead of using fork exec.kubectl apply/auth reconcile
reduces the amount of used memory. https://github.com/kubernetes/enhancements/issues/1020 is supposed to solve this issue.We also wanted to use the structs in
"github.com/argoproj/argo-cd/pkg/apis/application/v1alpha1"
to programmatically create Argo CD applications from a controller. Because of this problem we decided to go with creating our own structs for now. It would be really nice though if the API structs could be moved to their own module with minimal dependencies.Any thoughts on that?
I assume that the more common reason to take a dependency on
github.com/argoproj/argo-cd/v2
is just to be able to use these structs. I also realize that it might be a large refactoring given how many receiver functions there are for those structs, but in my opinion it would be a lot cleaner to separate that out from the data objects.ok after knowing my solution above was a terrible hack with the potential for being a maintenance nightmare I persisted on looking for a better solution and found this article:
https://itnext.io/generically-working-with-kubernetes-resources-in-go-53bce678f887
works perfectly for reading resources at least
kudos to https://medium.com/@jsnouff
@sidheshdivekar29 Thanks. I was actually able to make it work with v1.5.5.
Added following:
Hi, I am trying to import
"github.com/argoproj/argo-cd/pkg/apis/application/v1alpha1"
on client side to populate v1alpha1.AppProjectSpec{} and then json marshal it and send the data using rest api. I am hitting this exact same issue. How do I get it working with this bug being open.