Closed HenryXie1 closed 5 years ago
the go.mod is below
module mycrontab
go 1.12
require (
github.com/go-logr/logr v0.1.0
github.com/onsi/ginkgo v1.8.0
github.com/onsi/gomega v1.5.0
github.com/robfig/cron v1.1.0
golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09
k8s.io/api v0.0.0-20190409021203-6e4e0e4f393b
k8s.io/apimachinery v0.0.0-20190404173353-6a84e37a896d
k8s.io/client-go v11.0.1-0.20190409021438-1a26190bd76a+incompatible
sigs.k8s.io/controller-runtime v0.2.0-beta.1
sigs.k8s.io/controller-tools v0.2.0-beta.1 // indirect
)
if i use go.mod in the book https://book.kubebuilder.io/cronjob-tutorial/basic-project.html I got another error when i ran make install
go build sigs.k8s.io/controller-runtime/pkg/scheme: no Go files in
Usage:
controller-gen [flags]
Examples:
……………...
module mycrontab
go 1.12
require (
github.com/go-logr/logr v0.1.0
github.com/robfig/cron v1.1.0
k8s.io/api v0.0.0-20190222213804-5cb15d344471
k8s.io/apimachinery v0.0.0-20190221213512-86fb29eff628
k8s.io/client-go v0.0.0-20190228174230-b40b2a5939e4
sigs.k8s.io/controller-runtime v0.2.0-alpha.0.0.20190503051552-b666157c41da
sigs.k8s.io/controller-tools v0.2.0-alpha.1 // indirect
)
yep, go.mod/makefile in book need to be updated, it appears. As for the crash on your end, I'd need to see your source -- those lines don't line up with the ones in the book directory, and I can't reproduce the crash. Perhaps you've copied something incorrectly?
Thank you Solly. If you can put your sample codes in a public repo of github, it would be great. So I can compare with mine.
They are in a public repo: this one ;-) All the code in the book is actually generated off of real, runnable code: https://github.com/kubernetes-sigs/kubebuilder/tree/master/docs/book/src/cronjob-tutorial/testdata/project. The makefile needs to be updated to use controller-tools v0.2.0-beta.2 (as mentioned above), but otherwise you can just run that.
When i compare with sample code, the differences i see is i used my test domain "mycrontab" and some doc-gen comments. Here is the public repo I am testing based on the sample code. go.mod is the one which "make install and make run" were running successfully. https://github.com/HenryXie1/mycrontab thank you
Ah! I see the issue. You're missing scheme in main.go -- see https://book.kubebuilder.io/cronjob-tutorial/main-revisited.html. It's trying to use r.Scheme
, which is nil.
Thank you Solly. I confirm the issue is fixed.
I met the runtime error: invalid memory address or nil pointer dereference with kubebuilder v3.
It seems that if we want to use log
in *_controller.go,
log := r.Log.WithValues("cronjob", req.NamespacedName)
we need to pass Log
to CronJobReconciler
in main.go
err = (&controllers.CronJobReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("CronJob"), # add this line
Scheme: mgr.GetScheme(), // we've added this ourselves
}).SetupWithManager(mgr)
When i compare with sample code, the differences i see is i used my test domain "mycrontab" and some doc-gen comments. Here is the public repo I am testing based on the sample code. go.mod is the one which "make install and make run" were running successfully. https://github.com/HenryXie1/mycrontab thank you
We follow https://book.kubebuilder.io/ using kubebuilder v2 to build a new sample "mycontab" After we make install, we run make run it error out runtime error: invalid memory address or nil pointer dereference kubernetes env: v.1.12.7