go mod tidy会导致库与其他供应商的文件冲突;如何解决这个问题?

问题描述

我仍在学习go mod的细微差别,但是几天前我遇到了这个问题,但还没有克服。

我正在扩展我们应用程序之一的功能。该扩展要求使用prometheus运算符中的某些库。由于go mod tidy无法正常运行而运行go get后,我的vendor目录结束了许多更改。嗯太酷了但是,当我去建立供应商库中的不兼容性时,出现了!因此,解决此问题的唯一方法是使正确的go mod伏都教徒正常工作。我不知道该怎么做。

vendor/sigs.k8s.io/controller-runtime/pkg/metrics/client_go_adapter.go:120:24: too many arguments in call to metrics.Register
        have (*latencyAdapter,*resultAdapter)
        want (metrics.RegisterOpts)
# sigs.k8s.io/controller-runtime/pkg/client
vendor/sigs.k8s.io/controller-runtime/pkg/client/typed_client.go:45:62: o.resourceMeta.Interface.Post().NamespaceIfScoped(o.Object.GetNamespace(),o.resourceMeta.isNamespaced()).Resource(o.resourceMeta.resource()).Body(obj).VersionedParams(createOpts.AsCreateOptions(),c.paramCodec).Context undefined (type *rest.Request has no field or method Context)
vendor/sigs.k8s.io/controller-runtime/pkg/client/typed_client.go:65:62: o.resourceMeta.Interface.Put().NamespaceIfScoped(o.Object.GetNamespace(),o.resourceMeta.isNamespaced()).Resource(o.resourceMeta.resource()).Name(o.Object.GetName()).Body(obj).VersionedParams(updateOpts.AsUpdateOptions(),c.paramCodec).Context undefined (type *rest.Request has no field or method Context)
vendor/sigs.k8s.io/controller-runtime/pkg/client/typed_client.go:85:37: o.resourceMeta.Interface.Delete().NamespaceIfScoped(o.Object.GetNamespace(),o.resourceMeta.isNamespaced()).Resource(o.resourceMeta.resource()).Name(o.Object.GetName()).Body(deleteOpts.AsDeleteOptions()).Context undefined (type *rest.Request has no field or method Context)
vendor/sigs.k8s.io/controller-runtime/pkg/client/typed_client.go:105:42: o.resourceMeta.Interface.Delete().NamespaceIfScoped(deleteAllOfOpts.ListOptions.Namespace,o.resourceMeta.isNamespaced()).Resource(o.resourceMeta.resource()).VersionedParams(deleteAllOfOpts.ListOptions.AsListOptions(),c.paramCodec).Body(deleteAllOfOpts.DeleteOptions.AsDeleteOptions()).Context undefined (type *rest.Request has no field or method Context)
vendor/sigs.k8s.io/controller-runtime/pkg/client/typed_client.go:129:13: o.resourceMeta.Interface.Patch(patch.Type()).NamespaceIfScoped(o.Object.GetNamespace(),o.resourceMeta.isNamespaced()).Resource(o.resourceMeta.resource()).Name(o.Object.GetName()).VersionedParams(patchOpts.ApplyOptions(opts).AsPatchOptions(),c.paramCodec).Body(data).Context undefined (type *rest.Request has no field or method Context)
vendor/sigs.k8s.io/controller-runtime/pkg/client/typed_client.go:143:25: r.Interface.Get().NamespaceIfScoped(key.Namespace,r.isNamespaced()).Resource(r.resource()).Context undefined (type *rest.Request has no field or method Context)
vendor/sigs.k8s.io/controller-runtime/pkg/client/typed_client.go:159:58: r.Interface.Get().NamespaceIfScoped(listOpts.Namespace,r.isNamespaced()).Resource(r.resource()).VersionedParams(listOpts.AsListOptions(),c.paramCodec).Context undefined (type *rest.Request has no field or method Context)
vendor/sigs.k8s.io/controller-runtime/pkg/client/typed_client.go:181:89: o.resourceMeta.Interface.Put().NamespaceIfScoped(o.Object.GetNamespace(),o.resourceMeta.isNamespaced()).Resource(o.resourceMeta.resource()).Name(o.Object.GetName()).SubResource("status").Body(obj).VersionedParams((&UpdateOptions literal).ApplyOptions(opts).AsUpdateOptions(),c.paramCodec).Context undefined (type *rest.Request has no field or method Context)
vendor/sigs.k8s.io/controller-runtime/pkg/client/typed_client.go:206:79: o.resourceMeta.Interface.Patch(patch.Type()).NamespaceIfScoped(o.Object.GetNamespace(),o.resourceMeta.isNamespaced()).Resource(o.resourceMeta.resource()).Name(o.Object.GetName()).SubResource("status").Body(data).VersionedParams(patchOpts.ApplyOptions(opts).AsPatchOptions(),c.paramCodec).Context undefined (type *rest.Request has no field or method Context)
vendor/sigs.k8s.io/controller-runtime/pkg/client/unstructured_client.go:51:20: not enough arguments in call to r.Create
        have (*unstructured.Unstructured,v1.CreateOptions)
        want (context.Context,*unstructured.Unstructured,v1.CreateOptions,...string)
vendor/sigs.k8s.io/controller-runtime/pkg/client/unstructured_client.go:51:20: too many errors
# k8s.io/kubernetes/pkg/kubectl/drain
vendor/k8s.io/kubernetes/pkg/kubectl/drain/cordon.go:92:24: not enough arguments in call to client.Patch
        have (string,types.PatchType,[]byte)
        want (context.Context,string,[]byte,"k8s.io/apimachinery/pkg/apis/meta/v1".PatchOptions,...string)
vendor/k8s.io/kubernetes/pkg/kubectl/drain/cordon.go:94:25: not enough arguments in call to client.Update
        have (*"k8s.io/api/core/v1".Node)
        want (context.Context,*"k8s.io/api/core/v1".Node,"k8s.io/apimachinery/pkg/apis/meta/v1".UpdateOptions)
vendor/k8s.io/kubernetes/pkg/kubectl/drain/drain.go:96:53: not enough arguments in call to d.Client.CoreV1().Pods(pod.ObjectMeta.Namespace).Delete
        have (string,*"k8s.io/apimachinery/pkg/apis/meta/v1".DeleteOptions)
        want (context.Context,"k8s.io/apimachinery/pkg/apis/meta/v1".DeleteOptions)
vendor/k8s.io/kubernetes/pkg/kubectl/drain/drain.go:113:69: not enough arguments in call to d.Client.PolicyV1beta1().Evictions(eviction.ObjectMeta.Namespace).Evict
        have (*"k8s.io/api/policy/v1beta1".Eviction)
        want (context.Context,*"k8s.io/api/policy/v1beta1".Eviction)
vendor/k8s.io/kubernetes/pkg/kubectl/drain/drain.go:126:66: not enough arguments in call to d.Client.CoreV1().Pods("k8s.io/apimachinery/pkg/apis/meta/v1".NamespaceAll).List
        have ("k8s.io/apimachinery/pkg/apis/meta/v1".ListOptions)
        want (context.Context,"k8s.io/apimachinery/pkg/apis/meta/v1".ListOptions)
vendor/k8s.io/kubernetes/pkg/kubectl/drain/filters.go:171:62: not enough arguments in call to d.Client.AppsV1().DaemonSets(pod.ObjectMeta.Namespace).Get
        have (string,"k8s.io/apimachinery/pkg/apis/meta/v1".GetOptions)
        want (context.Context,"k8s.io/apimachinery/pkg/apis/meta/v1".GetOptions)
make: *** [kaas-bin-darwin] Error 2

我天真的认为go mod tidy会阻止这种事情发生吗?是否存在一些命令可以解决此问题?

这是我的go.mod文件:

$ \cat go.mod
module github.com/project/ims-kaas

go 1.12

require (
        github.com/Masterminds/godir v0.0.0-20160728192234-40ddaca750b2
        github.com/Masterminds/goutils v1.1.0 // indirect
        github.com/Masterminds/semver v1.4.2 // indirect
        github.com/Masterminds/sprig v2.20.0+incompatible
        github.com/coreos/prometheus-operator v0.41.1
        github.com/elazarl/go-bindata-assetfs v1.0.0
        github.com/fsnotify/fsnotify v1.4.7
        github.com/go-logr/zapr v0.1.1 // indirect
        github.com/golang/protobuf v1.4.1
        github.com/google/uuid v1.1.1
        github.com/grpc-ecosystem/grpc-gateway v1.14.6
        github.com/huandu/xstrings v1.2.0 // indirect
        github.com/imdario/mergo v0.3.7 // indirect
        github.com/jteeuwen/go-bindata v3.0.7+incompatible
        github.com/juju/clock v0.0.0-20190205081909-9c5c9712527c // indirect
        github.com/juju/collections v0.0.0-20180717171555-9be91dc79b7c // indirect
        github.com/juju/errors v0.0.0-20190207033735-e65537c515d7 // indirect
        github.com/juju/gomaasapi v0.0.0-20180919150011-8a8cec793ba7
        github.com/juju/loggo v0.0.0-20190212223446-d976af380377 // indirect
        github.com/juju/retry v0.0.0-20180821225755-9058e192b216 // indirect
        github.com/juju/schema v1.0.0 // indirect
        github.com/juju/testing v0.0.0-20190429233213-dfc56b8c09fc // indirect
        github.com/juju/utils v0.0.0-20180820210520-bf9cc5bdd62d // indirect
        github.com/juju/version v0.0.0-20180108022336-b64dbd566305 // indirect
        github.com/lyft/protoc-gen-validate v0.1.0 // indirect
        github.com/mwitkow/go-proto-validators v0.0.0-20190212092829-1f388280e944 // indirect
        github.com/pkg/errors v0.9.1
        github.com/pseudomuto/protoc-gen-doc v1.3.0
        github.com/pseudomuto/protokit v0.2.0 // indirect
        github.com/soheilhy/cmux v0.1.4
        github.com/spf13/cobra v0.0.5
        github.com/spf13/jwalterweatherman v1.1.0 // indirect
        github.com/spf13/pflag v1.0.5
        github.com/spf13/viper v1.3.2
        gitlab.com/mvenezia/version-info v0.0.0-20190320033107-d83c50c7bd4e
        golang.org/x/net v0.0.0-20200602114024-627f9648deb9
        google.golang.org/genproto v0.0.0-20200603110839-e855014d5736
        google.golang.org/grpc v1.29.1
        gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce // indirect
        k8s.io/api v0.18.3
        k8s.io/apiextensions-apiserver v0.18.2
        k8s.io/apimachinery v0.18.3
        k8s.io/client-go v0.18.3
        k8s.io/code-generator v0.18.2
        k8s.io/klog v1.0.0
        k8s.io/kubernetes v1.14.1
        sigs.k8s.io/controller-runtime v0.4.0
        sigs.k8s.io/controller-tools v0.2.4
        sigs.k8s.io/kustomize v2.0.3+incompatible
)

这是git diff,以查看发生了什么变化:

$ g diff go.mod
diff --git a/go.mod b/go.mod
index 37c35254..88ec157e 100644
--- a/go.mod
+++ b/go.mod
@@ -7,14 +7,13 @@ require (
        github.com/Masterminds/goutils v1.1.0 // indirect
        github.com/Masterminds/semver v1.4.2 // indirect
        github.com/Masterminds/sprig v2.20.0+incompatible
-       github.com/beorn7/perks v1.0.0 // indirect
+       github.com/coreos/prometheus-operator v0.41.1
        github.com/elazarl/go-bindata-assetfs v1.0.0
        github.com/fsnotify/fsnotify v1.4.7
        github.com/go-logr/zapr v0.1.1 // indirect
-       github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef // indirect
-       github.com/golang/protobuf v1.3.2
+       github.com/golang/protobuf v1.4.1
        github.com/google/uuid v1.1.1
-       github.com/grpc-ecosystem/grpc-gateway v1.9.6
+       github.com/grpc-ecosystem/grpc-gateway v1.14.6
        github.com/huandu/xstrings v1.2.0 // indirect
        github.com/imdario/mergo v0.3.7 // indirect
        github.com/jteeuwen/go-bindata v3.0.7+incompatible
@@ -30,35 +29,26 @@ require (
        github.com/juju/version v0.0.0-20180108022336-b64dbd566305 // indirect
        github.com/lyft/protoc-gen-validate v0.1.0 // indirect
        github.com/mwitkow/go-proto-validators v0.0.0-20190212092829-1f388280e944 // indirect
-       github.com/pelletier/go-toml v1.3.0 // indirect
-       github.com/pkg/errors v0.8.1
-       github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829 // indirect
-       github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90 // indirect
-       github.com/prometheus/common v0.3.0 // indirect
-       github.com/prometheus/procfs v0.0.0-20190416084830-8368d24ba045 // indirect
+       github.com/pkg/errors v0.9.1
        github.com/pseudomuto/protoc-gen-doc v1.3.0
        github.com/pseudomuto/protokit v0.2.0 // indirect
        github.com/soheilhy/cmux v0.1.4
        github.com/spf13/cobra v0.0.5
        github.com/spf13/jwalterweatherman v1.1.0 // indirect
-       github.com/spf13/pflag v1.0.3
+       github.com/spf13/pflag v1.0.5
        github.com/spf13/viper v1.3.2
-       github.com/urfave/cli v1.22.0 // indirect
        gitlab.com/mvenezia/version-info v0.0.0-20190320033107-d83c50c7bd4e
-       golang.org/x/net v0.0.0-20190812203447-cdfb69ac37fc
-       golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 // indirect
-       google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873
-       google.golang.org/grpc v1.23.0
-       gopkg.in/fsnotify.v1 v1.4.7
+       golang.org/x/net v0.0.0-20200602114024-627f9648deb9
+       google.golang.org/genproto v0.0.0-20200603110839-e855014d5736
+       google.golang.org/grpc v1.29.1
        gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce // indirect
-       k8s.io/api v0.16.4
-       k8s.io/apiextensions-apiserver v0.0.0-20190918161926-8f644eb6e783
-       k8s.io/apimachinery v0.16.4
-       k8s.io/client-go v0.16.4
-       k8s.io/code-generator v0.0.0-20190912054826-cd179ad6a269
-       k8s.io/klog v0.4.0
+       k8s.io/api v0.18.3
+       k8s.io/apiextensions-apiserver v0.18.2
+       k8s.io/apimachinery v0.18.3
+       k8s.io/client-go v0.18.3
+       k8s.io/code-generator v0.18.2
+       k8s.io/klog v1.0.0
        k8s.io/kubernetes v1.14.1
-       k8s.io/utils v0.0.0-20190907131718-3d4f5b7dea0b // indirect
        sigs.k8s.io/controller-runtime v0.4.0
        sigs.k8s.io/controller-tools v0.2.4
        sigs.k8s.io/kustomize v2.0.3+incompatible

我认为我将罪魁祸首库隔离为这两个:

vendor/sigs.k8s.io/controller-runtime/pkg/metrics/client_go_adapter.go
vendor/sigs.k8s.io/controller-runtime/pkg/client/typed_client.go
vendor/sigs.k8s.io/controller-runtime/pkg/client/unstructured_client.go

  sigs.k8s.io/controller-runtime v0.4.0

vendor/k8s.io/kubernetes/pkg/kubectl/drain/cordon.go
vendor/k8s.io/kubernetes/pkg/kubectl/drain/drain.go
vendor/k8s.io/kubernetes/pkg/kubectl/drain/filters.go

  k8s.io/kubernetes v1.14.1

太好了。任何指针都是宏伟的!谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...