operator-framework / operator-sdk

SDK for building Kubernetes applications. Provides high level APIs, useful abstractions, and project scaffolding.
https://sdk.operatorframework.io
Apache License 2.0
7.24k stars 1.74k forks source link

Cannot execute 'operator-sdk build' on vendored operator-sdk command #852

Closed miguelsorianod closed 5 years ago

miguelsorianod commented 5 years ago

Hi,

We have our operator-sdk application with the 0.3.0 version and it seems we cannot correctly execute the command operator-sdk build command when having it vendored in the project. We do that as part of our CI process.

To reproduce the problem we:

When executing the previous command the output we obtain is:

msoriano@localhost:~/go/src/github.com/3scale/3scale-operator (upgrade-operatorsdk-to030)$ go run ./vendor/github.com/operator-framework/operator-sdk/commands/operator-sdk build myoperator:latest
# github.com/3scale/3scale-operator/vendor/k8s.io/apiextensions-apiserver/pkg/features
vendor/k8s.io/apiextensions-apiserver/pkg/features/kube_features.go:46:32: feature.DefaultFeatureGate.Add undefined (type feature.FeatureGate has no field or method Add)
# github.com/3scale/3scale-operator/vendor/k8s.io/kubernetes/pkg/kubectl/util/term
vendor/k8s.io/kubernetes/pkg/kubectl/util/term/resize.go:30:23: undefined: term.GetFdInfo
vendor/k8s.io/kubernetes/pkg/kubectl/util/term/resize.go:51:23: undefined: term.GetFdInfo
vendor/k8s.io/kubernetes/pkg/kubectl/util/term/term.go:69:17: undefined: term.GetFdInfo
vendor/k8s.io/kubernetes/pkg/kubectl/util/term/term.go:80:22: undefined: term.GetFdInfo
# github.com/3scale/3scale-operator/vendor/k8s.io/kubernetes/pkg/apis/authentication/v1
vendor/k8s.io/kubernetes/pkg/apis/authentication/v1/zz_generated.conversion.go:266:49: in.Audiences undefined (type *"github.com/3scale/3scale-operator/vendor/k8s.io/api/authentication/v1".TokenReviewSpec has no field or method Audiences)
vendor/k8s.io/kubernetes/pkg/apis/authentication/v1/zz_generated.conversion.go:277:5: out.Audiences undefined (type *"github.com/3scale/3scale-operator/vendor/k8s.io/api/authentication/v1".TokenReviewSpec has no field or method Audiences)
vendor/k8s.io/kubernetes/pkg/apis/authentication/v1/zz_generated.conversion.go:291:49: in.Audiences undefined (type *"github.com/3scale/3scale-operator/vendor/k8s.io/api/authentication/v1".TokenReviewStatus has no field or method Audiences)
vendor/k8s.io/kubernetes/pkg/apis/authentication/v1/zz_generated.conversion.go:306:5: out.Audiences undefined (type *"github.com/3scale/3scale-operator/vendor/k8s.io/api/authentication/v1".TokenReviewStatus has no field or method Audiences)
# github.com/3scale/3scale-operator/vendor/k8s.io/kubernetes/pkg/apis/authentication/v1beta1
vendor/k8s.io/kubernetes/pkg/apis/authentication/v1beta1/zz_generated.conversion.go:116:49: in.Audiences undefined (type *v1beta1.TokenReviewSpec has no field or method Audiences)
vendor/k8s.io/kubernetes/pkg/apis/authentication/v1beta1/zz_generated.conversion.go:127:5: out.Audiences undefined (type *v1beta1.TokenReviewSpec has no field or method Audiences)
vendor/k8s.io/kubernetes/pkg/apis/authentication/v1beta1/zz_generated.conversion.go:141:49: in.Audiences undefined (type *v1beta1.TokenReviewStatus has no field or method Audiences)
vendor/k8s.io/kubernetes/pkg/apis/authentication/v1beta1/zz_generated.conversion.go:156:5: out.Audiences undefined (type *v1beta1.TokenReviewStatus has no field or method Audiences)
# github.com/3scale/3scale-operator/vendor/k8s.io/kubernetes/pkg/apis/policy/v1beta1
vendor/k8s.io/kubernetes/pkg/apis/policy/v1beta1/zz_generated.conversion.go:173:43: undefined: v1beta1.RunAsGroupStrategyOptions
vendor/k8s.io/kubernetes/pkg/apis/policy/v1beta1/zz_generated.conversion.go:174:92: undefined: v1beta1.RunAsGroupStrategyOptions
vendor/k8s.io/kubernetes/pkg/apis/policy/v1beta1/zz_generated.conversion.go:178:85: undefined: v1beta1.RunAsGroupStrategyOptions
vendor/k8s.io/kubernetes/pkg/apis/policy/v1beta1/zz_generated.conversion.go:179:131: undefined: v1beta1.RunAsGroupStrategyOptions
vendor/k8s.io/kubernetes/pkg/apis/policy/v1beta1/zz_generated.conversion.go:538:72: in.RunAsGroup undefined (type *v1beta1.PodSecurityPolicySpec has no field or method RunAsGroup)
vendor/k8s.io/kubernetes/pkg/apis/policy/v1beta1/zz_generated.conversion.go:579:5: out.RunAsGroup undefined (type *v1beta1.PodSecurityPolicySpec has no field or method RunAsGroup)
vendor/k8s.io/kubernetes/pkg/apis/policy/v1beta1/zz_generated.conversion.go:604:92: undefined: v1beta1.RunAsGroupStrategyOptions
vendor/k8s.io/kubernetes/pkg/apis/policy/v1beta1/zz_generated.conversion.go:611:88: undefined: v1beta1.RunAsGroupStrategyOptions
vendor/k8s.io/kubernetes/pkg/apis/policy/v1beta1/zz_generated.conversion.go:615:131: undefined: v1beta1.RunAsGroupStrategyOptions
vendor/k8s.io/kubernetes/pkg/apis/policy/v1beta1/zz_generated.conversion.go:622:127: undefined: v1beta1.RunAsGroupStrategyOptions
vendor/k8s.io/kubernetes/pkg/apis/policy/v1beta1/zz_generated.conversion.go:579:5: too many errors

Thank you.

miguelsorianod commented 5 years ago

I add more information. The Gopkt.toml file we have for an empty 0.3.0 project is what it is automatically generated plus the github.com/operator-framework/operator-sdk/commands/operator-sdk that we manually add. We execute dep ensure -v (removing before the 'vendor' directory just in case) after the change. The content of this Gopkt.toml is:

soriano@localhost:~/go/src/github.com/3scale/testproject (master)$ cat Gopkg.toml 
# Force dep to vendor the code generators, which aren't imported just used at dev time.
required = [
  "k8s.io/code-generator/cmd/defaulter-gen",
  "k8s.io/code-generator/cmd/deepcopy-gen",
  "k8s.io/code-generator/cmd/conversion-gen",
  "k8s.io/code-generator/cmd/client-gen",
  "k8s.io/code-generator/cmd/lister-gen",
  "k8s.io/code-generator/cmd/informer-gen",
  "k8s.io/code-generator/cmd/openapi-gen",
  "k8s.io/gengo/args",

  "github.com/operator-framework/operator-sdk/commands/operator-sdk",
]

[[override]]
  name = "k8s.io/code-generator"
  # revision for tag "kubernetes-1.12.3"
  revision = "3dcf91f64f638563e5106f21f50c31fa361c918d"

[[override]]
  name = "k8s.io/api"
  # revision for tag "kubernetes-1.12.3"
  revision = "b503174bad5991eb66f18247f52e41c3258f6348"

[[override]]
  name = "k8s.io/apiextensions-apiserver"
  # revision for tag "kubernetes-1.12.3"
  revision = "0cd23ebeb6882bd1cdc2cb15fc7b2d72e8a86a5b"

[[override]]
  name = "k8s.io/apimachinery"
  # revision for tag "kubernetes-1.12.3"
  revision = "eddba98df674a16931d2d4ba75edc3a389bf633a"

[[override]]
  name = "k8s.io/client-go"
  # revision for tag "kubernetes-1.12.3"
  revision = "d082d5923d3cc0bfbb066ee5fbdea3d0ca79acf8"

[[override]]
  name = "sigs.k8s.io/controller-runtime"
  version = "=v0.1.8"

[[constraint]]
  name = "github.com/operator-framework/operator-sdk"
  # The version rule is used for a specific release and the master branch for in between releases.
  # branch = "master" #osdk_branch_annotation
  version = "=v0.3.0" #osdk_version_annotation

[prune]
  go-tests = true
  non-go = true

  [[prune.project]]
    name = "k8s.io/code-generator"
    non-go = false
lilic commented 5 years ago

Hello @miguelsorianod, have you done all of these with the following command:

go run ./vendor/github.com/operator-framework/operator-sdk/commands/operator-sdk build myoperator:latest

Since you already have installed operator-sdk and it's in your path juding by the version output that one should work fine. I tested it locally and it works for me when calling the following command operator-sdk build myoperator:latest. Let me know if that still doesn't work for you, thanks!

miguelsorianod commented 5 years ago

Hello @LiliC,

The locally installed operator-sdk build works correctly in my local machine.

The motivation on executing the operator-sdk command from the vendored location (go run ./vendor/github.com/operator-framework/operator-sdk/commands/operator-sdk build myoperator:latest) however is because we execute it from a CI environment where we do not have the operator-sdk locally installed but in the vendor directory (with dep).

lilic commented 5 years ago

@miguelsorianod Any reason why not install the operator-sdk in CI as with any other dependencies? E.g. curl the release or install in the gopath?

mikz commented 5 years ago

@LiliC yes, because we have several projects that are using several operator-sdk versions. We would like to enforce that every project is using version it is locked to.

We prefer not to duplicate dependency locking. Installing a release would require us to download operator-sdk into every project and keep it in sync with the locked version.

joelanford commented 5 years ago

@mikz @miguelsorianod The reason you're getting errors is that operator-sdk has declared dependencies in its Gopkg.toml that are not in your Gopkg.toml. You'll need to pull those into your Gopkg.toml to get things working.

Also, note that running the main.go file out of the vendor directory is not the same as running the published release because the go build environment in CI and your project dependencies may cause the compiled binary to differ. For that reason, this is not something we'd suggest or support.

However, if you must, I was able to get the operator-sdk build command to work by adding the below additions in the operator's Gopkg.toml:

[[override]]
  name = "k8s.io/kubernetes"
  version = "=1.12.3"

[[override]]
  name = "k8s.io/apiserver"
  version = "kubernetes-1.12.3"

[[override]]
  name = "k8s.io/cli-runtime"
  version = "kubernetes-1.12.3"

[[override]]
  name = "github.com/sergi/go-diff"
  version = "1.0.0"

[[override]]
  name = "k8s.io/helm"
  version = "=v2.12.0"

[[override]]
  name = "github.com/sirupsen/logrus"
  version = "1.0.4"

[[override]]
  name = "github.com/spf13/cobra"
  version = "0.0.3"

[[override]]
  name = "github.com/russross/blackfriday"
  revision = "300106c228d52c8941d4b3de6054a6062a86dda3"

[[override]]
  name = "github.com/docker/distribution"
  revision = "edc3ab29cdff8694dd6feb85cfeb4b5f1b38ed9c"

[[override]]
  name = "github.com/docker/docker"
  revision = "a9fbbdc8dd8794b20af358382ab780559bca589d"
joelanford commented 5 years ago

@miguelsorianod It looks like you were able to resolve your issues? Can this issue be closed as well?

lilic commented 5 years ago

Closing, if @miguelsorianod you still have a problem with this, feel free to reopen or open a new issue.