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

Does not work with Modules #992

Closed
abergmeier opened this issue Jan 24, 2019 · 20 comments
Closed

Does not work with Modules #992

abergmeier opened this issue Jan 24, 2019 · 20 comments
Labels
kind/feature Categorizes issue or PR as related to a new feature. lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. needs discussion

Comments

@abergmeier
Copy link

abergmeier commented Jan 24, 2019

Feature Request

What did you do?
I tried to run operator-sdk new foo --skip-git-init both in an empty directory as well as a directory containing both go.mod and go.sum.

What did you expect to see?
I expected it to generate without any fuss.

What did you see instead? Under which circumstances?
Output is:

INFO[0000] Creating new Go operator 'foo'.             
FATA[0000] Project not in $GOPATH

Environment

  • operator-sdk version:

    operator-sdk version v0.4.0

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

Additional context
printenv | grep GOPATH is empty

@AlexNPavel AlexNPavel added the kind/bug Categorizes issue or PR as related to a bug. label Jan 25, 2019
@AlexNPavel
Copy link
Contributor

Can you set your GOPATH environment variable and create your project in the GOPATH? Currently, we require all go operators to be in your GOPATH.

@abergmeier
Copy link
Author

Can you set your GOPATH environment variable and create your project in the GOPATH?

We switched all our Go code to Modules by now and will not be using GOPATH anymore.

@lilic lilic added kind/feature Categorizes issue or PR as related to a new feature. and removed kind/bug Categorizes issue or PR as related to a bug. labels Jan 25, 2019
@lilic
Copy link
Member

lilic commented Jan 25, 2019

Like @AlexNPavel we need our operators to be created in the GOPATH, so this is not a bug for us but a new feature request. Would it be possible @abergmeier to just adjust your text in the issue to reflect that, thanks!

@abergmeier
Copy link
Author

abergmeier commented Jan 25, 2019

so this is not a bug for us but a new feature request.

Fair enough. You are aware that GOPATH will get deprecated, right?

Our aim is for Go 1.13, scheduled for August 2019, to enable module mode by default

See 1

Would it be possible @abergmeier to just adjust your text in the issue to reflect that

Sorry, I do not follow. What do you want to be adjusted? To me the issue is sufficient neutral.

@lilic
Copy link
Member

lilic commented Jan 25, 2019

@abergmeier Sorry if I wasn't clear enough, just wanted this to be turned into a feature request instead of a Bug Report. :) This is so we can prioritize the feature request and possibly work on it. I can also edit the description of the issue, no problem. (just to avoid confusion between bug and feature requests)

@abergmeier
Copy link
Author

abergmeier commented Jan 25, 2019

Sorry if I wasn't clear enough, just wanted this to be turned into a feature request instead of a Bug Report

Ah sorry, didn't see that. Changed now.

@openshift-bot
Copy link

Issues go stale after 90d of inactivity.

Mark the issue as fresh by commenting /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.
Exclude this issue from closing by commenting /lifecycle frozen.

If this issue is safe to close now please do so with /close.

/lifecycle stale

@openshift-ci-robot openshift-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label May 10, 2019
@lilic
Copy link
Member

lilic commented May 10, 2019

Added in the #1001 PR.

@lilic lilic closed this as completed May 10, 2019
@zephinzer
Copy link

This still doesn't work for me, running MacOS 10.11.6 with Go 1.12.5 and GO111MODULE=on set.

operator-sdk version output:

operator-sdk version: v0.8.0, commit: 78c472461e75e6c64589cfadf577a2004b8a26b3

operator-sdk new some-operator --type=go --skip-git-init output (from outside $GOPATH):

INFO[0000] Creating new Go operator 'some-operator'.    
FATA[0000] Project not in $GOPATH

@joelanford
Copy link
Member

@zephinzer The SDK currently still requires projects to be created in $GOPATH. See the discussion in #1417.

@jleach
Copy link

jleach commented Jul 19, 2019

EDIT.. I figured this out... 🧐

You need to add your project to the GOPATH with something like export GOPATH=$GOPATH:$HOME/projects. The example commands below are tweaked from the Quick Start guide:

bash-4.4# mkdir -p $HOME/projects/example-inc/
bash-4.4# export GOPATH=$GOPATH:$HOME/projects
bash-4.4# cd $HOME/projects/example-inc/
bash-4.4# export GO111MODULE=on
bash-4.4# operator-sdk new app-operator

And that should work. What's strange about this is being in my original GOPATH of /opt/go did not work. Only when I appended $HOME/projects to my GOPATH did it work.

@deepaktawri
Copy link

@jleach solution suggested by you didn't work for me somehow. I get following error :

[server3 project]$ operator-sdk new dataservice-operator
INFO[0000] Creating new Go operator 'dataservice-operator'.
INFO[0000] Created go.mod
INFO[0000] Created tools.go
INFO[0000] Created cmd/manager/main.go
INFO[0000] Created build/Dockerfile
INFO[0000] Created build/bin/entrypoint
INFO[0000] Created build/bin/user_setup
INFO[0000] Created deploy/service_account.yaml
INFO[0000] Created deploy/role.yaml
INFO[0000] Created deploy/role_binding.yaml
INFO[0000] Created deploy/operator.yaml
INFO[0000] Created pkg/apis/apis.go
INFO[0000] Created pkg/controller/controller.go
INFO[0000] Created version/version.go
INFO[0000] Created .gitignore
INFO[0000] Running go mod ...
$GOPATH/go.mod exists but should not
Error: failed to exec []string{"go", "mod", "vendor", "-v"}: exit status 1
Usage:
operator-sdk new [flags]

@joelanford
Copy link
Member

@deepaktawri Looks like you're getting an error about having a go.mod file in $GOPATH.

FWIW, operator-sdk should support projects outside of GOPATH with Go modules as of v0.9.0.

@deepaktawri
Copy link

@joelandford Thank you for quick reply. I believe operator-sdk v0.9.0 is not released yet.

@joelanford
Copy link
Member

We released it about a month ago 🙂

https://github.com/operator-framework/operator-sdk/releases/tag/v0.9.0

@deepaktawri
Copy link

Thank you @joelandford. I tried v0.9.0 and got following error :

#operator-sdk new dataservice-operator --repo pwd

go: bitbucket.org/ww/[email protected]: hg clone -U https://bitbucket.org/ww/goautoneg . in /dwshome/deepak/master/main/.go/pkg/mod/cache/vcs/59c2185b80ea440a7c3b8c5eff3d8abb68c53dea1f20f615370c924c4150b27f: exec: "hg": executable file not found in $PATH
go: error loading module requirements
Error: failed to exec []string{"go", "build", "./..."}: exit status 1

@deepaktawri
Copy link

Installing Mercurial on system fixes above problem.
And then the next error I see is :

cmd/manager/main.go:14:2: import path cannot be absolute path
cmd/manager/main.go:15:2: import path cannot be absolute path
cmd/manager/main.go:105:12: undefined: apis
cmd/manager/main.go:111:12: undefined: controller
cmd/manager/main.go:145:53: undefined: apis
Error: failed to exec []string{"go", "build", "./..."}: exit status 2

@deepaktawri
Copy link

Help page seems confusing which asks --repo to use as follows 👍

  --repo string                 Project repository path for Go operators. Used as the project's Go import path. This must be set if outside of $GOPATH/src with Go modules, and cannot be set if --dep-manager=dep

Where as, it should be --repo=

= is important.

@joelanford
Copy link
Member

@deepaktawri I think there's some confusion about what to use for --repo. It's supposed to be something like --repo github.com/deepaktawri/dataservice-operator

@jleach
Copy link

jleach commented Aug 8, 2019

@deepaktawri Looks like I made a mistake at set it to export GOPATH=$GOPATH:. I don't know why, but by adding : it made things work. I imagine this is a hack but its enough to get you going until a more correct, long term solution is found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Categorizes issue or PR as related to a new feature. lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. needs discussion
Projects
None yet
Development

No branches or pull requests

9 participants