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 import `v0.16.0` as go mod dependency #1590

Closed jpmcb closed 2 years ago

jpmcb commented 2 years ago

Bug description

Unable to pull in v0.16.0 of tanzu-framework as a plugin dependency with the following error

go: sigs.k8s.io/cluster-api/test@v1.0.1 requires
        sigs.k8s.io/cluster-api@v0.0.0-00010101000000-000000000000: invalid version: unknown revision 000000000000

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

Expected behavior

Expected to be able to use the v0.16.0 release without a version discrepancy. This was when attempting to use the latest tanzu-framework version in TCE: https://github.com/vmware-tanzu/community-edition/issues/2985

Steps to reproduce the bug

  1. In a fresh go module:
    $ cd /tmp
    $ mkdir test-framework
    $ cd test-framework
    $ go mod init example.com
  2. add the following to a main.go file in this new module, a very very simple plugin program:
    
    package main

import ( "log"

    "github.com/vmware-tanzu/tanzu-framework/pkg/v1/buildinfo"

    cliv1alpha1 "github.com/vmware-tanzu/tanzu-framework/apis/cli/v1alpha1"
    "github.com/vmware-tanzu/tanzu-framework/pkg/v1/cli/command/plugin"

)

var descriptor = cliv1alpha1.PluginDescriptor{ Name: "Test plugin", Description: "Some test plugin", Group: cliv1alpha1.RunCmdGroup, Version: buildinfo.Version, }

var ( defaultVersion = "v0.0.1-unversioned" )❯

var logLevel int32

func main() { if descriptor.Version == "" { descriptor.Version = defaultVersion }

    // create plugin!
    _, err := plugin.NewPlugin(&descriptor)
    if err != nil {
            log.Fatalf("%v", err)
    }

}

3. Then, attempt to resolve the dependency with `go mod tidy` and notice the following error

$ go mod tidy go: finding module for package github.com/vmware-tanzu/tanzu-framework/apis/cli/v1alpha1 go: finding module for package github.com/vmware-tanzu/tanzu-framework/pkg/v1/buildinfo go: finding module for package github.com/vmware-tanzu/tanzu-framework/pkg/v1/cli/command/plugin go: found github.com/vmware-tanzu/tanzu-framework/apis/cli/v1alpha1 in github.com/vmware-tanzu/tanzu-framework v0.16.0 go: found github.com/vmware-tanzu/tanzu-framework/pkg/v1/buildinfo in github.com/vmware-tanzu/tanzu-framework v0.16.0 go: found github.com/vmware-tanzu/tanzu-framework/pkg/v1/cli/command/plugin in github.com/vmware-tanzu/tanzu-framework v0.16.0 go: sigs.k8s.io/cluster-api/test@v1.0.1 requires sigs.k8s.io/cluster-api@v0.0.0-00010101000000-000000000000: invalid version: unknown revision 000000000000

This results in the file not being buildable and no `go.sum` output.

**Environment where the bug was observed (cloud, OS, etc)**

OS: Pop!_OS 21.10 x86_64 Kernel: 5.15.15-76051515-generic Packages: 2511 (dpkg), 73 (brew), 9 (flatpak) Shell: zsh 5.8 CPU: AMD Ryzen 5 2600X (12) @ 3.600GHz GPU: AMD ATI Radeon RX 5600 OEM/5600 XT / 5700/5700 XT Memory: 12472MiB / 16012MiB

Go environment:

$ go env GO111MODULE="on" GOARCH="amd64" GOBIN="/home/jmcb/.asdf/installs/golang/1.14/go/bin" GOCACHE="/home/jmcb/.cache/go-build" GOENV="/home/jmcb/.config/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/home/jmcb/.asdf/installs/golang/1.17.2/packages/pkg/mod" GONOPROXY="github.com/vmware-tanzu-private/" GONOSUMDB="github.com/vmware-tanzu-private/" GOOS="linux" GOPATH="/home/jmcb/.asdf/installs/golang/1.17.2/packages" GOPRIVATE="github.com/vmware-tanzu-private/*" GOPROXY="https://proxy.golang.org,direct" GOROOT="/home/jmcb/.asdf/installs/golang/1.17.2/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/home/jmcb/.asdf/installs/golang/1.17.2/go/pkg/tool/linux_amd64" GOVCS="" GOVERSION="go1.17.2" GCCGO="gccgo" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="/tmp/test-framework/go.mod" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3627896367=/tmp/go-build -gno-record-gcc-switches"

jpmcb commented 2 years ago

Adding the following line to the go.mod corrects the issue.

replace sigs.k8s.io/cluster-api => sigs.k8s.io/cluster-api v1.0.1

Are there any plans to eliminate this relative import between cluster-api/test and cluster-api? As a consumer of tanzu-framework as a library, it'd be great to not have to also include cluster-api as a dependency

rajathagasthya commented 2 years ago

Are there any plans to eliminate this relative import between cluster-api/test and cluster-api?

The relative import happens in cluster-api/test upstream and Go modules requiring every cluster-api/test consumer to add a replace directive. Not sure what we can do in tanzu-framework, tbh.

As a consumer of tanzu-framework as a library, it'd be great to not have to also include cluster-api as a dependency

+1 on this. tanzu-framework consumers shouldn't need to include additional dependencies, especially plugin developers.

jpmcb commented 2 years ago

Still unable to build.

After using the replace, I'm able to resolve the dependencies and produce a go.sum but now I can't build:

❯ go build -o build.out
# github.com/k14s/kbld/pkg/kbld/image
/home/jmcb/.asdf/installs/golang/1.17.2/packages/pkg/mod/github.com/k14s/kbld@v0.31.0/pkg/kbld/image/tag_selected.go:43:18: undefined: v1alpha1.NewRelaxedSemversNoErr

Any thoughts @rajathagasthya ?

jpmcb commented 2 years ago

The above requires another replace statment:

replace github.com/k14s/kbld => github.com/anujc25/carvel-kbld v0.31.0-update-vendir

This results in the following go mod and a buildable binary

$ cat go.mod
module example.com

go 1.17

replace sigs.k8s.io/cluster-api => sigs.k8s.io/cluster-api v1.0.1

replace github.com/k14s/kbld => github.com/anujc25/carvel-kbld v0.31.0-update-vendir

require github.com/vmware-tanzu/tanzu-framework v0.16.0

require (
        cloud.google.com/go v0.99.0 // indirect
        cloud.google.com/go/storage v1.10.0 // indirect
        github.com/AlecAivazis/survey/v2 v2.1.1 // indirect
        github.com/Azure/azure-sdk-for-go v58.1.0+incompatible // indirect
        github.com/Azure/go-autorest v14.2.0+incompatible // indirect
        github.com/Azure/go-autorest/autorest v0.11.21 // indirect
        github.com/Azure/go-autorest/autorest/adal v0.9.16 // indirect
        github.com/Azure/go-autorest/autorest/azure/auth v0.5.8 // indirect
        github.com/Azure/go-autorest/autorest/azure/cli v0.4.2 // indirect
        github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
        github.com/Azure/go-autorest/autorest/to v0.4.0 // indirect
        github.com/Azure/go-autorest/autorest/validation v0.3.1 // indirect
        github.com/Azure/go-autorest/logger v0.2.1 // indirect
        github.com/Azure/go-autorest/tracing v0.6.0 // indirect
        github.com/MakeNowJust/heredoc v1.0.0 // indirect
        github.com/Masterminds/semver v1.5.0 // indirect
        github.com/Microsoft/go-winio v0.5.0 // indirect
        github.com/PuerkitoBio/purell v1.1.1 // indirect
        github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
        github.com/adrg/xdg v0.2.1 // indirect
        github.com/apparentlymart/go-cidr v1.1.0 // indirect
        github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect
        github.com/aunum/log v0.0.0-20200821225356-38d2e2c8b489 // indirect
        github.com/beorn7/perks v1.0.1 // indirect
        github.com/blang/semver v3.5.1+incompatible // indirect
        github.com/briandowns/spinner v1.18.0 // indirect
        github.com/cespare/xxhash/v2 v2.1.2 // indirect
        github.com/cheggaaa/pb v1.0.29 // indirect
        github.com/containerd/containerd v1.5.7 // indirect
        github.com/containerd/stargz-snapshotter/estargz v0.7.0 // indirect
        github.com/coredns/caddy v1.1.1 // indirect
        github.com/coredns/corefile-migration v1.0.13 // indirect
        github.com/cppforlife/cobrautil v0.0.0-20200514214827-bb86e6965d72 // indirect
        github.com/cppforlife/color v1.9.1-0.20200716202919-6706ac40b835 // indirect
        github.com/cppforlife/go-cli-ui v0.0.0-20200716203538-1e47f820817f // indirect
        github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect
        github.com/davecgh/go-spew v1.1.1 // indirect
        github.com/dimchansky/utfbom v1.1.1 // indirect
        github.com/docker/cli v20.10.7+incompatible // indirect
        github.com/docker/distribution v2.7.1+incompatible // indirect
        github.com/docker/docker v20.10.9+incompatible // indirect
        github.com/docker/docker-credential-helpers v0.6.3 // indirect
        github.com/docker/go-connections v0.4.0 // indirect
        github.com/docker/go-units v0.4.0 // indirect
        github.com/drone/envsubst/v2 v2.0.0-20210730161058-179042472c46 // indirect
        github.com/evanphx/json-patch v4.11.0+incompatible // indirect
        github.com/fatih/color v1.13.0 // indirect
        github.com/fsnotify/fsnotify v1.5.1 // indirect
        github.com/ghodss/yaml v1.0.0 // indirect
        github.com/go-logr/logr v0.4.0 // indirect
        github.com/go-openapi/analysis v0.19.5 // indirect
        github.com/go-openapi/errors v0.19.2 // indirect
        github.com/go-openapi/jsonpointer v0.19.5 // indirect
        github.com/go-openapi/jsonreference v0.19.5 // indirect
        github.com/go-openapi/loads v0.19.4 // indirect
        github.com/go-openapi/runtime v0.19.4 // indirect
        github.com/go-openapi/spec v0.19.5 // indirect
        github.com/go-openapi/strfmt v0.19.5 // indirect
        github.com/go-openapi/swag v0.19.14 // indirect
        github.com/go-openapi/validate v0.19.8 // indirect
        github.com/go-stack/stack v1.8.0 // indirect
        github.com/gobuffalo/flect v0.2.3 // indirect
        github.com/gogo/protobuf v1.3.2 // indirect
        github.com/golang-jwt/jwt/v4 v4.0.0 // indirect
        github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
        github.com/golang/protobuf v1.5.2 // indirect
        github.com/golang/snappy v0.0.3 // indirect
        github.com/google/go-cmp v0.5.6 // indirect
        github.com/google/go-containerregistry v0.6.0 // indirect
        github.com/google/go-github/v33 v33.0.0 // indirect
        github.com/google/go-querystring v1.1.0 // indirect
        github.com/google/gofuzz v1.2.0 // indirect
        github.com/google/uuid v1.3.0 // indirect
        github.com/googleapis/gax-go/v2 v2.1.1 // indirect
        github.com/googleapis/gnostic v0.5.5 // indirect
        github.com/hashicorp/go-version v1.3.0 // indirect
        github.com/hashicorp/hcl v1.0.0 // indirect
        github.com/imdario/mergo v0.3.12 // indirect
        github.com/inconshreveable/mousetrap v1.0.0 // indirect
        github.com/josharian/intern v1.0.0 // indirect
        github.com/json-iterator/go v1.1.12 // indirect
        github.com/juju/fslock v0.0.0-20160525022230-4d5c94c67b4b // indirect
        github.com/k14s/imgpkg v0.17.0 // indirect
        github.com/k14s/kbld v0.31.0 // indirect
        github.com/k14s/semver/v4 v4.0.1-0.20210701191048-266d47ac6115 // indirect
        github.com/k14s/starlark-go v0.0.0-20200720175618-3a5c849cc368 // indirect
        github.com/k14s/ytt v0.32.1-0.20210511155130-214258be2519 // indirect
        github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
        github.com/klauspost/compress v1.13.0 // indirect
        github.com/lithammer/dedent v1.1.0 // indirect
        github.com/logrusorgru/aurora v2.0.3+incompatible // indirect
        github.com/magiconair/properties v1.8.5 // indirect
        github.com/mailru/easyjson v0.7.6 // indirect
        github.com/mattn/go-colorable v0.1.12 // indirect
        github.com/mattn/go-isatty v0.0.14 // indirect
        github.com/mattn/go-runewidth v0.0.13 // indirect
        github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
        github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
        github.com/mitchellh/go-homedir v1.1.0 // indirect
        github.com/mitchellh/mapstructure v1.4.3 // indirect
        github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
        github.com/modern-go/reflect2 v1.0.2 // indirect
        github.com/olekukonko/tablewriter v0.0.4 // indirect
        github.com/onsi/gomega v1.16.0 // indirect
        github.com/opencontainers/go-digest v1.0.0 // indirect
        github.com/opencontainers/image-spec v1.0.1 // indirect
        github.com/pelletier/go-toml v1.9.4 // indirect
        github.com/pkg/errors v0.9.1 // indirect
        github.com/prometheus/client_golang v1.11.0 // indirect
        github.com/prometheus/client_model v0.2.0 // indirect
        github.com/prometheus/common v0.31.1 // indirect
        github.com/prometheus/procfs v0.7.3 // indirect
        github.com/rivo/uniseg v0.2.0 // indirect
        github.com/russross/blackfriday/v2 v2.1.0 // indirect
        github.com/sirupsen/logrus v1.8.1 // indirect
        github.com/spf13/afero v1.6.0 // indirect
        github.com/spf13/cast v1.4.1 // indirect
        github.com/spf13/cobra v1.3.0 // indirect
        github.com/spf13/jwalterweatherman v1.1.0 // indirect
        github.com/spf13/pflag v1.0.5 // indirect
        github.com/spf13/viper v1.10.0 // indirect
        github.com/subosito/gotenv v1.2.0 // indirect
        github.com/vito/go-interact v0.0.0-20171111012221-fa338ed9e9ec // indirect
        github.com/vmware-tanzu/carvel-kapp-controller v0.25.0 // indirect
        github.com/vmware-tanzu/carvel-vendir v0.23.0 // indirect
        github.com/vmware/govmomi v0.27.1 // indirect
        github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0 // indirect
        go.mongodb.org/mongo-driver v1.1.2 // indirect
        go.opencensus.io v0.23.0 // indirect
        go.uber.org/atomic v1.7.0 // indirect
        go.uber.org/multierr v1.6.0 // indirect
        golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect
        golang.org/x/mod v0.5.1 // indirect
        golang.org/x/net v0.0.0-20211005215030-d2e5035098b3 // indirect
        golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
        golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
        golang.org/x/sys v0.0.0-20211205182925-97ca703d548d // indirect
        golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
        golang.org/x/text v0.3.7 // indirect
        golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
        golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
        gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
        google.golang.org/api v0.62.0 // indirect
        google.golang.org/appengine v1.6.7 // indirect
        google.golang.org/genproto v0.0.0-20211208223120-3a66f561d7aa // indirect
        google.golang.org/grpc v1.42.0 // indirect
        google.golang.org/protobuf v1.27.1 // indirect
        gopkg.in/inf.v0 v0.9.1 // indirect
        gopkg.in/ini.v1 v1.66.2 // indirect
        gopkg.in/yaml.v2 v2.4.0 // indirect
        gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
        k8s.io/api v0.22.2 // indirect
        k8s.io/apiextensions-apiserver v0.22.2 // indirect
        k8s.io/apimachinery v0.22.2 // indirect
        k8s.io/client-go v0.22.2 // indirect
        k8s.io/cluster-bootstrap v0.22.2 // indirect
        k8s.io/component-base v0.22.2 // indirect
        k8s.io/klog/v2 v2.10.0 // indirect
        k8s.io/kube-openapi v0.0.0-20210929172449-94abcedd1aa4 // indirect
        k8s.io/utils v0.0.0-20210930125809-cb0fa318a74b // indirect
        sigs.k8s.io/cluster-api v1.0.1 // indirect
        sigs.k8s.io/cluster-api-provider-aws v1.0.0 // indirect
        sigs.k8s.io/cluster-api-provider-azure v1.0.1 // indirect
        sigs.k8s.io/cluster-api-provider-vsphere v1.0.2 // indirect
        sigs.k8s.io/cluster-api/test v1.0.1 // indirect
        sigs.k8s.io/controller-runtime v0.10.3 // indirect
        sigs.k8s.io/structured-merge-diff/v4 v4.1.2 // indirect
        sigs.k8s.io/yaml v1.3.0 // indirect
)
vuil commented 2 years ago

Thanks for the really detailed report, @jpmcb

Will take a closer look tomorrow, but this seems to be a recurring issue with repos consuming cluster-api. E.g. https://github.com/kubernetes-sigs/cluster-api/issues/1895

@rajathagasthya did you encounter this when generating pkg/v1/builder/template/plugintemplates/gomod.tmpl?

rajathagasthya commented 2 years ago

@vuil I did. That go mod template also has replace for the same reason. It's worth reopening the upstream issue.