Operator-sdk: user-guide on a fresh install (for go)

Created on 17 Jul 2019  路  9Comments  路  Source: operator-framework/operator-sdk

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=
$ 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: 560208dc998de497bbf59fea1b63426aec430934

  • 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

Most helpful comment

@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.

All 9 comments

@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.

@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: 560208dc998de497bbf59fea1b63426aec430934

Any good thought ?

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: d6e1aba9fa512ff9d441b648f548399c86929643

Best regards

@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.

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?

@johananl Yes, I did it

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

@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

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

danielsig727 picture danielsig727  路  4Comments

joelanford picture joelanford  路  3Comments

hasbro17 picture hasbro17  路  3Comments

bobdonat picture bobdonat  路  3Comments

surajssd picture surajssd  路  3Comments