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

import cycle not allowed #40721

Closed
oyb001 opened this issue Aug 12, 2020 · 9 comments
Closed

import cycle not allowed #40721

oyb001 opened this issue Aug 12, 2020 · 9 comments

Comments

@oyb001
Copy link

@oyb001 oyb001 commented Aug 12, 2020

Environment:

Minikube version (use minikube version): master@50a8c9824a7610c954043e041ddb6c078d9d756d

OS : MacOS Mojave 10.14.6 (18G103)
Go Env

szitdeMacBook-Pro-oyb:minikube-master ouyangbin$ go version
go version go1.13.12 darwin/amd64
szitdeMacBook-Pro-oyb:minikube-master ouyangbin$ 
szitdeMacBook-Pro-oyb:minikube-master ouyangbin$ echo $GOROOT;echo $GOPATH; go env
/usr/local/go
/Users/ouyangbin/Workspace/dev/golang
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/ouyangbin/Library/Caches/go-build"
GOENV="/Users/ouyangbin/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/ouyangbin/Workspace/dev/golang"
GOPRIVATE=""
GOPROXY="https://goproxy.io"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/ouyangbin/Downloads/source_code/minikube-master/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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/7y/26pq3xkj5j53nl4b5m85s76wzr8ttw/T/go-build476488165=/tmp/go-build -gno-record-gcc-switches -fno-common"
szitdeMacBook-Pro-oyb:minikube-master ouyangbin$ 
What happened: make failed with the following error

GOROOT=/usr/local/go #gosetup
GOPATH=/Users/ouyangbin/Workspace/dev/golang #gosetup
/usr/local/go/bin/go build -o /Users/ouyangbin/Downloads/source_code/minikube-master/go_build_main_go /Users/ouyangbin/Downloads/source_code/minikube-master/cmd/minikube/main.go #gosetup
import cycle not allowed
package main
	imports k8s.io/minikube/cmd/minikube/cmd
	imports k8s.io/minikube/cmd/minikube/cmd/config
	imports k8s.io/minikube/pkg/addons
	imports k8s.io/minikube/pkg/addons/gcpauth
	imports k8s.io/minikube/pkg/minikube/assets
	imports k8s.io/minikube/pkg/minikube/config
	imports k8s.io/minikube/pkg/drivers/kic/oci
	imports k8s.io/minikube/pkg/minikube/out
	imports k8s.io/minikube/pkg/minikube/translate
	imports k8s.io/minikube/pkg/minikube/assets

Compilation finished with exit code 1

What you expected to happen: make to succeed

How to reproduce it (as minimally and precisely as possible): Follow the build guide, and when attempting make it will fail with the above error.

I have search all code by IDE, I believe have not doing any cyclic import, and the error you're getting is a compiler bug,
the follow two file have import "k8s.io/minikube/cmd/minikube/cmd", but that two file package is main

cmd/minikube/cmd/main.go
hack/help_text/gen_help_text.go
@oyb001
Copy link
Author

@oyb001 oyb001 commented Aug 12, 2020

"cmd/minikube/cmd/main.go" that file content

package main

import (
	"bytes"
	"fmt"
	"log"
	"os"
	"regexp"
	"strconv"

	// initflag must be imported before any other minikube pkg.
	// Fix for https://github.com/kubernetes/minikube/issues/4866
	_ "k8s.io/minikube/pkg/initflag"

	// Register drivers
	_ "k8s.io/minikube/pkg/minikube/registry/drvs"

	mlog "github.com/docker/machine/libmachine/log"

	"github.com/golang/glog"
	"github.com/google/slowjam/pkg/stacklog"
	"github.com/pkg/profile"

	"k8s.io/minikube/cmd/minikube/cmd"
	"k8s.io/minikube/pkg/minikube/constants"
	"k8s.io/minikube/pkg/minikube/machine"
	"k8s.io/minikube/pkg/minikube/out"
	_ "k8s.io/minikube/pkg/provision"
)

"hack/help_text/gen_help_text.go" that file content

package main

import (
	"fmt"
	"os"

	"github.com/spf13/cobra/doc"
	"k8s.io/minikube/cmd/minikube/cmd"
)
@martisch
Copy link
Contributor

@martisch martisch commented Aug 12, 2020

I cant build minikube due to other reasons.

$ git clone https://github.com/kubernetes/minikube
$ cd minikube/cmd/minikube/
$ go build
# k8s.io/minikube/pkg/minikube/translate
../../pkg/minikube/translate/translate.go:80:12: undefined: Asset

how was the code in /Users/ouyangbin/Downloads/source_code/minikube-master/ obtained?

Follow the build guide

Please link to the build guide used or better list the exact commands executed to get to the error.

There seems to be a corresponding issue open on the minikube issue tracker: kubernetes/minikube#8964

@mdempsky
Copy link
Member

@mdempsky mdempsky commented Aug 12, 2020

cmd/go is identifying the loop:

package main
	imports k8s.io/minikube/cmd/minikube/cmd
	imports k8s.io/minikube/cmd/minikube/cmd/config
	imports k8s.io/minikube/pkg/addons
	imports k8s.io/minikube/pkg/addons/gcpauth
	imports k8s.io/minikube/pkg/minikube/assets    <---
	imports k8s.io/minikube/pkg/minikube/config
	imports k8s.io/minikube/pkg/drivers/kic/oci
	imports k8s.io/minikube/pkg/minikube/out
	imports k8s.io/minikube/pkg/minikube/translate
	imports k8s.io/minikube/pkg/minikube/assets    <---

It's not related to the main packages.

Looking at https://github.com/kubernetes/minikube/tree/master/pkg/minikube/translate, I don't see any import of "k8s.io/minikube/pkg/minikube/assets". Did you add that dependency loop while trying to fix the undefined Asset error that @martisch pointed out above?

@oyb001
Copy link
Author

@oyb001 oyb001 commented Aug 13, 2020

@martisch ,About "undefined: Asset" issue,Please view reference that url kubernetes/minikube#2656,

1.install go-bindata soft
2.On project root directory(Ie:/Users/ouyangbin/Downloads/source_code/minikube-master),run the fellow command

go-bindata -nomemcopy -o pkg/minikube/assets/assets.go -pkg assets deploy/addons/...

3.Import Asset packet, change code on translate.go

import (
	"encoding/json"
	"fmt"
	"github.com/cloudfoundry-attic/jibber_jabber"
	"github.com/golang/glog"
	"golang.org/x/text/language"
	"k8s.io/minikube/pkg/minikube/assets"
	"path"
	"strings"
)
 Asset.(translationFile) ->assets.Asset(translationFile)
@oyb001
Copy link
Author

@oyb001 oyb001 commented Aug 13, 2020

@mdempsky I have import of "k8s.io/minikube/pkg/minikube/assets" in "master/pkg/minikube/translate", fix the undefined Asset erro

@davecheney
Copy link
Contributor

@davecheney davecheney commented Aug 13, 2020

@oyb001 the root cause is assets depends on the template package. Adding assets as a dependency of template creates a loop.

@mdempsky
Copy link
Member

@mdempsky mdempsky commented Aug 13, 2020

@oyb001 Thanks, then it sounds like cmd/go is working as intended. Dependency cycles like that are not allowed in Go.

This is either a minikube issue or an issue with your undefined Asset fix.

@mdempsky mdempsky closed this Aug 13, 2020
@oyb001
Copy link
Author

@oyb001 oyb001 commented Aug 13, 2020

/Users/ouyangbin/Documents/001_work/01_git/minikube/pkg/minikube/assets/assets.go
that file is template package, the file not import any minikube package

package assets

import (
	"bytes"
	"compress/gzip"
	"fmt"
	"io"
	"reflect"
	"strings"
	"unsafe"
)

func bindata_read(data, name string) ([]byte, error) {
	var empty [0]byte
	sx := (*reflect.StringHeader)(unsafe.Pointer(&data))
	b := empty[:]
	bx := (*reflect.SliceHeader)(unsafe.Pointer(&b))
	bx.Data = sx.Data
	bx.Len = len(data)
	bx.Cap = bx.Len
@mdempsky
Copy link
Member

@mdempsky mdempsky commented Aug 13, 2020

"k8s.io/minikube/pkg/minikube/assets" imports "k8s.io/minikube/pkg/minikube/config" here:

https://github.com/kubernetes/minikube/blob/7257b9b295e5db0afe796282107328f51ff868c3/pkg/minikube/assets/addons.go#L22

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.