Skip to content

user-guide on a fresh install (for go) #1688

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

Closed
p-sforza opened this issue Jul 17, 2019 · 9 comments · Fixed by #1713
Closed

user-guide on a fresh install (for go) #1688

p-sforza opened this issue Jul 17, 2019 · 9 comments · Fixed by #1713

Comments

@p-sforza
Copy link

p-sforza commented Jul 17, 2019

Bug Report

What did you do?
From a fresh fedora installation (Fedora release 30) I've just followed the quick start in the readme

SDK Setup

RELEASE_VERSION=v0.9.0
$ curl -OJL https://github.com/operator-framework/operator-sdk/releases/download/${RELEASE_VERSION}/operator-sdk-${RELEASE_VERSION}-x86_64-linux-gnu
$ curl -OJL https://github.com/operator-framework/operator-sdk/releases/download/${RELEASE_VERSION}/operator-sdk-${RELEASE_VERSION}-x86_64-linux-gnu.asc

$ gpg --verify operator-sdk-${RELEASE_VERSION}-x86_64-linux-gnu.asc
KEY_ID=<KEY_ID>
$ gpg --recv-key "$KEY_ID"
$ gpg --verify operator-sdk-${RELEASE_VERSION}-x86_64-linux-gnu.asc

--> check ok

$ chmod +x operator-sdk-${RELEASE_VERSION}-x86_64-linux-gnu && sudo cp operator-sdk-${RELEASE_VERSION}-x86_64-linux-gnu /usr/local/bin/operator-sdk

Dependency setup

$ dnf install -y git go mercurial bzr origin-clients dep

Quick Start

$ mkdir -p $HOME/projects/example.com/
$ cd $HOME/projects/example.com/
$ operator-sdk new memcached-operator

What did you expect to see?
Completion of the go scaffold setup

What did you see instead? Under which circumstances?
$ operator-sdk new memcached-operator

The cmd breaks with:
Error: dependency manager "modules" requires the flag --repo to be set if the working directory is not in $GOPATH/src. See "operator-sdk new -h"

I've tried
$ operator-sdk new memcached-operator --repo ./

but this breaks after a wile:
can't load package: package .//cmd/manager: non-canonical import path: ".//cmd/manager" should be "cmd/manager"

Environment

  • operator-sdk version:

operator-sdk version: v0.9.0, commit: 560208d

  • go version:

go version go1.12.7 linux/amd64

  • Kubernetes version information:

Client Version: version.Info{Major:"1", Minor:"10+", GitVersion:"v1.10.0+d4cacc0", GitCommit:"d4cacc0", GitTreeState:"clean", BuildDate:"2018-12-06T15:15:06Z", GoVersion:"go1.11.2", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"11+", GitVersion:"v1.11.0+d4cacc0", GitCommit:"d4cacc0", GitTreeState:"clean", BuildDate:"2019-07-08T19:16:39Z", GoVersion:"go1.10.8", Compiler:"gc", Platform:"linux/amd64"}

  • Kubernetes cluster kind: OKD

  • Are you writing your operator in ansible, helm, or go?
    go

Possible Solution
maybe define the go path... but this is not more required for newer go versions

Additional context

@johananl
Copy link
Contributor

@p-sforza you should include --repo github.com/example/my-operator when running operator-sdk new.

The reason is - when you run outside the GOPATH, the SDK can't figure out the import path to use for the operator so you have to specify --repo explicitly.

--repo ./ gives you an error because .//something is not a valid Go import path.

@nzaharioudakis
Copy link

@johananl well I think it seems to be a bit more peculiar in my case

[root@fed-30-0 src]# pwd

/root/go/src
[root@fed-30-0 src]# echo $GOPATH
/root/go
[root@fed-30-0 src]# operator-sdk new test-operator
INFO[0000] Creating new Go operator 'test-operator'.
Error: dependency manager "modules" requires working directory to be in $GOPATH/src and GO111MODULE=on, or outside of $GOPATH/src and GO111MODULE="on", "auto", or unset
Usage:
operator-sdk new [flags]

Flags:
< snipped >

then the same for dir >/root/go/

[root@fed-30-0 src]# operator-sdk version
operator-sdk version: v0.9.0, commit: 560208d

Any good thought ?

@vincmarz
Copy link

Hi johananl,
I tried running "operator-sdk new app-operator" on GOPATH/src path and it worked fine.
My environment:
go version go1.12.7 linux/amd64
operator-sdk version: v0.9.0-17-gd6e1aba, commit: d6e1aba

Best regards

@johananl
Copy link
Contributor

johananl commented Jul 26, 2019

@nzaharioudakis you have two options:

Option 1

cd $GOPATH/src/github.com/yourgithubuser
export GO111MODULE=on
operator-sdk new test-operator

Option 2

cd /tmp/somedir
operator-sdk new test-operator --repo github.com/yourgithubuser/test-operator

I personally use option 2.

You can check how GO111MODULE is set for you using go env GO111MODULE (nothing means unset).

EDIT: Actually GO111MODULE isn't included in go env, so env | grep GO111MODULE could be useful.

@johananl
Copy link
Contributor

I tried running "operator-sdk new app-operator" on GOPATH/src path and it worked fine.

@vincmarz cool. I'm guessing you have GO111MODULE=on then?

@vincmarz
Copy link

@johananl Yes, I did it

@nzaharioudakis
Copy link

@johananl Option #2 always wins !
Perhaps an idea to include it in the error message next time. Thanks a bunch !

@Katiyman
Copy link

@nzaharioudakis you have two options:

Option 1

cd $GOPATH/src/github.com/yourgithubuser
export GO111MODULE=on
operator-sdk new test-operator

Option 2

cd /tmp/somedir
operator-sdk new test-operator --repo github.com/yourgithubuser/test-operator

I personally use option 2.

You can check how GO111MODULE is set for you using go env GO111MODULE (nothing means unset).

EDIT: Actually GO111MODULE isn't included in go env, so env | grep GO111MODULE could be useful.

Does this mean that the dependecies for the project will be in $GOPATH/src/github.com/yourgithubuser/test-operator

@johananl
Copy link
Contributor

@Katiyman If I understood your question correctly, when using Go modules any dependencies are downloaded to $GOPATH/pkg/mod.

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

Successfully merging a pull request may close this issue.

5 participants