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 v0.4.0
Additional context
printenv | grep GOPATH is empty
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.
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.
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!
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.
@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)
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.
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
Added in the #1001 PR.
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
@zephinzer The SDK currently still requires projects to be created in $GOPATH. See the discussion in https://github.com/operator-framework/operator-sdk/pull/1417.
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.
@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
@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.
@joelandford Thank you for quick reply. I believe operator-sdk v0.9.0 is not released yet.
We released it about a month ago 馃檪
https://github.com/operator-framework/operator-sdk/releases/tag/v0.9.0
Thank you @joelandford. I tried v0.9.0 and got following error :
pwdgo: 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
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
Help page seems confusing which asks --repo to use as follows :+1:
--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.
@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
@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.
Most helpful comment
This still doesn't work for me, running MacOS 10.11.6 with Go 1.12.5 and
GO111MODULE=onset.operator-sdk versionoutput:operator-sdk new some-operator --type=go --skip-git-initoutput (from outside$GOPATH):