kubernetes-sigs / kubebuilder

Kubebuilder - SDK for building Kubernetes APIs using CRDs
http://book.kubebuilder.io
Apache License 2.0
7.9k stars 1.45k forks source link

BUG: failed to initialize project: unable to scaffold with "base.go.kubebuilder.io/v3": exit status 2 #2512

Closed kevdowney closed 2 years ago

kevdowney commented 2 years ago

What broke? What's expected?

Starting a project with kubebuilder v3.3.0 fails with scaffolding error.

$ kubebuilder version
Version: main.version{KubeBuilderVersion:"3.3.0", KubernetesVendor:"1.23.1", GitCommit:"47859bf2ebf96a64db69a2f7074ffdec7f15c1ec", BuildDate:"2022-01-18T17:03:29Z", GoOs:"darwin", GoArch:"amd64"}

Go 1.16

go version
go version go1.16.14 darwin/amd64
mkdir -p ~/projects/guestbook
cd ~/projects/guestbook
go mod init my.domain/guestbook
kubebuilder init --domain my.domain --repo my.domain/guestbook
kubebuilder init --domain my.domain --repo my.domain/guestbook
Writing kustomize manifests for you to edit...
Writing scaffold for you to edit...
Get controller runtime:
$ go get sigs.k8s.io/controller-runtime@v0.11.0
# sigs.k8s.io/json/internal/golang/encoding/json
../../go/pkg/mod/sigs.k8s.io/json@v0.0.0-20211020170558-c049b76a60c6/internal/golang/encoding/json/encode.go:1249:12: sf.IsExported undefined (type reflect.StructField has no field or method IsExported)
../../go/pkg/mod/sigs.k8s.io/json@v0.0.0-20211020170558-c049b76a60c6/internal/golang/encoding/json/encode.go:1255:18: sf.IsExported undefined (type reflect.StructField has no field or method IsExported)
Error: failed to initialize project: unable to scaffold with "base.go.kubebuilder.io/v3": exit status 2
Usage:
  kubebuilder init [flags]

Examples:
  # Initialize a new project with your domain and name in copyright
  kubebuilder init --plugins go/v3 --domain example.org --owner "Your name"

  # Initialize a new project defining a specific project version
  kubebuilder init --plugins go/v3 --project-version 3

Flags:
      --component-config         create a versioned ComponentConfig file, may be 'true' or 'false'
      --domain string            domain for groups (default "my.domain")
      --fetch-deps               ensure dependencies are downloaded (default true)
  -h, --help                     help for init
      --license string           license to use to boilerplate, may be one of 'apache2', 'none' (default "apache2")
      --owner string             owner to add to the copyright
      --project-name string      name of this project
      --project-version string   project version (default "3")
      --repo string              name to use for go module (e.g., github.com/user/repo), defaults to the go package of the current working directory.
      --skip-go-version-check    if specified, skip checking the Go version

Global Flags:
      --plugins strings   plugin keys to be used for this subcommand execution

2022/02/15 15:53:05 failed to initialize project: unable to scaffold with "base.go.kubebuilder.io/v3": exit status 2

Reproducing this issue

KubeBuilder (CLI) Version

Version: main.version{KubeBuilderVersion:"3.3.0", KubernetesVendor:"1.23.1", GitCommit:"47859bf2ebf96a64db69a2f7074ffdec7f15c1ec", BuildDate:"2022-01-18T17:03:29Z", GoOs:"darwin", GoArch:"amd64"}

PROJECT version

No response

Plugin versions

No response

Other versions

go version go1.16.14 darwin/amd64

Extra Labels

/kind regression

easternK commented 2 years ago

kubebuilder version is too high,golang version v1.16+ (kubebuilder v3.1 < v3.3).

kevdowney commented 2 years ago

It works today w/ go1.17.7 darwin/amd64

kubebuilder init --domain my.domain --repo my.domain/guestbook
Writing kustomize manifests for you to edit...
Writing scaffold for you to edit...
Get controller runtime:
$ go get sigs.k8s.io/controller-runtime@v0.10.0
Update dependencies:
$ go mod tidy
Next: define a resource with:
$ kubebuilder create api

I did try this using go1.17 the other day it failed w/ the same error but I noticed today that it used sigs.k8s.io/controller-runtime@v0.10.0 and before it was using sigs.k8s.io/controller-runtime@v0.11.0.

This specific error appears to be solely related to the sigs.k8s.io/controller-runtime@v0.11.0

Old Error:

$ go get sigs.k8s.io/controller-runtime@v0.11.0
# sigs.k8s.io/json/internal/golang/encoding/json
../../go/pkg/mod/sigs.k8s.io/json@v0.0.0-20211020170558-c049b76a60c6/internal/golang/encoding/json/encode.go:1249:12: sf.IsExported undefined (type reflect.StructField has no field or method IsExported)
../../go/pkg/mod/sigs.k8s.io/json@v0.0.0-20211020170558-c049b76a60c6/internal/golang/encoding/json/encode.go:1255:18: sf.IsExported undefined (type reflect.StructField has no field or method IsExported)
Error: failed to initialize project: unable to scaffold with "base.go.kubebuilder.io/v3": exit status 2
Usage:
camilamacedo86 commented 2 years ago

Hi @kevdowney,

Each KB CLI version scaffolds the deps which are compatible with:

Screenshot 2022-02-22 at 10 11 08

We cannot ensure all possible combinations since breaking changes on them can be faced and we recommend you use the versions scaffolds by default always. Another recommendation is to keep your project updated with the latest changes. You can follow the upgrade guide https://book.kubebuilder.io/migrations.html to check the major ones.

However, to update the project usually, means re-scaffold the files with the CLI tool and ensuring that your code is on top of the default scaffolds. See that you can also compare the diffs looking at the samples such as kubebuilder/testdata/project-v3/.

Also, note that the go version supported is defined in the pre-requisites as well and you can check it by looking at the Kubebuilder tags in this repo and checking what go version was adopted for each release, e.g : for v3.0.0 the supported go version was 1.15. See: https://github.com/kubernetes-sigs/kubebuilder/blob/v3.0.0/go.mod#L3

In this way, these ones shows sorted out. The problems faced here was because you or not using the go version which is supported by the CLI version adopted as you did not use its dops scaffolded by default.

I hope that you do not mind if we close this one, however, also please feel free to re-open or raise new issues if you see that you need.