controller-tools: install controller-gen failed: sf.IsExported undefined

go build -o ${HOME}/go/bin/controller-gen main.go
# sigs.k8s.io/json/internal/golang/encoding/json
/root/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)
/root/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)
go version
go version go1.16.10 linux/amd64

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 38
  • Comments: 22 (2 by maintainers)

Commits related to this issue

Most upvoted comments

I’ve solved this problem by upgating golang to v1.17. Not sure whether it is a bug for v1.16 or not.

Same issue here, trying to bump golang version, but it causes massive refactor to lots of other components.

Any alternative options?

reflect.StructField was added in go 1.17. If you are using it and compiling with an earlier version of go, you will have a bad time.

Edit:

MR #639 introduced a new version of sigs.k8s.io/json. That version requires go v1.17. That MR did bump the go version for controller-tools to v1.17. But, it looks like that change wasn’t “documented” anywhere, so it’s easy to understand why nobody knew that they needed to move to a newer version of go.