vmware-tanzu / tanzu-framework

Tanzu Framework provides a set of building blocks to build atop of the Tanzu platform and leverages Carvel packaging and plugins to provide users with a much stronger, more integrated experience than the loose coupling and stand-alone commands of the previous generation of tools.
Apache License 2.0
197 stars 193 forks source link

Unable to pull `cli/cmd/tanzu` package via `go get` #444

Open jpmcb opened 3 years ago

jpmcb commented 3 years ago

Bug description

In a brand new VM, in a fresh go module, I am unable to pull get the cmd/cli/tanzu package as a dependency:

vagrant@ubuntu-focal:~$ mkdir example

vagrant@ubuntu-focal:~$ cd example/

vagrant@ubuntu-focal:~/example$ go mod init example.com
go: creating new go.mod: module example.com

vagrant@ubuntu-focal:~/example$ go get github.com/vmware-tanzu/tanzu-framework/cmd/cli/tanzu@main
go: downloading github.com/vmware-tanzu/tanzu-framework v1.4.0-pre-alpha-2.0.20210817015447-9bb81197689f
go: downloading github.com/aunum/log v0.0.0-20200821225356-38d2e2c8b489
go: downloading github.com/AlecAivazis/survey/v2 v2.1.1
go: downloading github.com/briandowns/spinner v1.16.0
go: downloading github.com/lithammer/dedent v1.1.0
go: downloading github.com/logrusorgru/aurora v2.0.3+incompatible
go: downloading github.com/pkg/errors v0.9.1
go: downloading github.com/spf13/cobra v1.1.3
go: downloading golang.org/x/mod v0.4.0
go: downloading gopkg.in/yaml.v2 v2.4.0
go: downloading k8s.io/apimachinery v0.21.2
go: downloading github.com/fatih/color v1.10.0
go: downloading github.com/ghodss/yaml v1.0.0
go: downloading github.com/golang/protobuf v1.5.2
go: downloading github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
go: downloading golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e
go: downloading sigs.k8s.io/controller-runtime v0.7.0
go: downloading cloud.google.com/go v0.74.0
go: downloading github.com/adrg/xdg v0.2.1
go: downloading go.uber.org/multierr v1.5.0
go: downloading google.golang.org/api v0.40.0
go: downloading google.golang.org/grpc v1.34.0
go: downloading cloud.google.com/go/storage v1.10.0
go: downloading github.com/olekukonko/tablewriter v0.0.4
go: downloading k8s.io/client-go v0.21.2
go: downloading github.com/inconshreveable/mousetrap v1.0.0
go: downloading github.com/spf13/pflag v1.0.5
go: downloading github.com/cpuguy83/go-md2man v1.0.10
go: downloading github.com/cpuguy83/go-md2man/v2 v2.0.0
go: downloading github.com/mattn/go-colorable v0.1.8
go: downloading github.com/mattn/go-isatty v0.0.12
go: downloading github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b
go: downloading golang.org/x/text v0.3.6
go: downloading google.golang.org/protobuf v1.27.1
go: downloading github.com/gogo/protobuf v1.3.2
go: downloading github.com/google/gofuzz v1.2.0
go: downloading k8s.io/klog v1.0.0
go: downloading k8s.io/klog/v2 v2.8.0
go: downloading sigs.k8s.io/structured-merge-diff v1.0.1-0.20191108220359-b1b620dd3f06
go: downloading sigs.k8s.io/structured-merge-diff/v4 v4.1.0
go: downloading go.uber.org/atomic v1.6.0
go: downloading golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b
go: downloading github.com/json-iterator/go v1.1.11
go: downloading github.com/modern-go/reflect2 v1.0.1
go: downloading sigs.k8s.io/yaml v1.2.0
go: downloading github.com/mattn/go-runewidth v0.0.7
go: downloading k8s.io/api v0.21.2
go: downloading github.com/googleapis/gax-go v2.0.2+incompatible
go: downloading github.com/googleapis/gax-go/v2 v2.0.5
go: downloading google.golang.org/genproto v0.0.0-20201214200347-8c77b98c765d
go: downloading github.com/evanphx/json-patch v4.11.0+incompatible
go: downloading github.com/go-logr/logr v0.4.0
go: downloading github.com/prometheus/client_golang v1.11.0
go: downloading gomodules.xyz/jsonpatch/v2 v2.2.0
go: downloading github.com/russross/blackfriday v1.5.2
go: downloading golang.org/x/sys v0.0.0-20210616094352-59db8d763f22
go: downloading github.com/russross/blackfriday/v2 v2.0.1
go: downloading gopkg.in/inf.v0 v0.9.1
go: downloading github.com/google/go-cmp v0.5.6
go: downloading github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd
go: downloading github.com/jstemmer/go-junit-report v0.9.1
go: downloading golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5
go: downloading golang.org/x/tools v0.1.0
go: downloading go.opencensus.io v0.22.5
go: downloading golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914
go: downloading google.golang.org/appengine v1.6.7
go: downloading k8s.io/utils v0.0.0-20210527160623-6fdb442a123b
go: downloading golang.org/x/net v0.0.0-20210614182718-04defd469f4e
go: downloading golang.org/x/time v0.0.0-20210611083556-38a9dc6acbc6
go: downloading github.com/imdario/mergo v0.3.12
go: downloading github.com/prometheus/client_model v0.2.0
go: downloading github.com/prometheus/common v0.29.0
go: downloading github.com/beorn7/perks v1.0.1
go: downloading github.com/cespare/xxhash v1.1.0
go: downloading github.com/cespare/xxhash/v2 v2.1.1
go: downloading github.com/prometheus/procfs v0.6.0
go: downloading github.com/fsnotify/fsnotify v1.4.9
go: downloading github.com/shurcooL/sanitized_anchor_name v1.0.0
go: downloading github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da
go: downloading k8s.io/apiextensions-apiserver v0.21.2
go: downloading k8s.io/component-base v0.21.2
go: downloading github.com/davecgh/go-spew v1.1.1
go: downloading github.com/googleapis/gnostic v0.5.1
go: downloading github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369
go: downloading github.com/google/uuid v1.2.0
go: downloading k8s.io/kube-openapi v0.0.0-20210305001622-591a79e4bda7
go: downloading golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
go: downloading gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
go: downloading github.com/hashicorp/golang-lru v0.5.4
go: downloading github.com/evanphx/json-patch v0.5.2
go: downloading k8s.io/client-go v1.5.2
# sigs.k8s.io/controller-runtime/pkg/metrics
../go/pkg/mod/sigs.k8s.io/controller-runtime@v0.7.0/pkg/metrics/client_go_adapter.go:134:3: cannot use &latencyAdapter{...} (type *latencyAdapter) as type metrics.LatencyMetric in field value:
        *latencyAdapter does not implement metrics.LatencyMetric (wrong type for Observe method)
                have Observe(string, url.URL, time.Duration)
                want Observe(context.Context, string, url.URL, time.Duration)
../go/pkg/mod/sigs.k8s.io/controller-runtime@v0.7.0/pkg/metrics/client_go_adapter.go:135:3: cannot use &resultAdapter{...} (type *resultAdapter) as type metrics.ResultMetric in field value:
        *resultAdapter does not implement metrics.ResultMetric (wrong type for Increment method)
                have Increment(string, string, string)
                want Increment(context.Context, string, string, string)

I believe this is related to the v0.7.0 controller-runtime dependency being incompatible with the v0.21 client-go dependency. I'm not 100% sure of the internal workings of go mod, but I was first suspicious of this seeing the go/pkg/mod/sigs.k8s.io/controller-runtime@v0.7.0/ log lines in the go get error. Locally, if I bump the v0.7.0 dep to v0.9.0 it works. PR for this incoming

This issue may also be related: https://github.com/kubernetes-sigs/controller-runtime/issues/1473

Affected product area (please put an X in all that apply)

Expected behavior I would expect the library (and it's various packages) to always be "go getable" when using go get to grab dependencies. This mainly affects TCE as we pull down the cmd/cli/tanzu package to build.

Steps to reproduce the bug

  1. Create a new go module using go mod init example.com
  2. Attempt to pull down the cmd/cli/tanzu dependency via go get github.com/vmware-tanzu/tanzu-framework/cmd/cli/tanzu@main - see failures

Version (include the SHA if the version is not obvious) Latest commits on main @ 9bb81197689f2405b24bfc79433302fd5085bbe8

Environment where the bug was observed (cloud, OS, etc) Using Go 1.16

VM environment:

NAME="Ubuntu"
VERSION="20.04.2 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.2 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal
rajathagasthya commented 3 years ago

Curious – are you trying to add tanzu-framework as a dependency or install tanzu CLI using go get? The go get github.com/vmware-tanzu/tanzu-framework/cmd/cli/tanzu@main command is pointing to the main package and is generally what is used to install a binary (although the recommended way to do from Go 1.16+ is to use go install).

But also you cannot add a main package like cmd/cli/tanzu to your dependency. go get github.com/vmware-tanzu/tanzu-framework@main should work though and will add an entry to your go.mod file.

jpmcb commented 3 years ago

The go get is intended to populate a go module with the necessary dependencies for TCE where we run the tanzu CLI remotely like this:

TANZU_CLI_NO_INIT=true go run github.com/vmware-tanzu/tanzu-framework/cmd/cli/tanzu --help

This will only work in a module with the necessary dependencies declared. Otherwise, you hit this error:

no required module provides package github.com/vmware-tanzu/tanzu-framework/cmd/cli/tanzu

Therefore, we need the ability to go get the package into a module to run the code.

rajathagasthya commented 3 years ago

Thanks! Interesting use case.