kubebuilder: CronJob tutorial results in error at step 1.9

What broke? What’s expected?

Packages that were included when initializing the project may be out of date. After running the command go get -u I can run the make install command successfully.

Reproducing this issue

Follow the CronJob tutorial on book.kubebuilder.io. On Step 1.9, run make manifests then make install and you will see the following error:

make install                                                                                                                                                         zsh  ﮫ 798ms  18:44:53 
test -s /home/paul/repos/pauldotyu/kubebuilder-book-tutorial/bin/controller-gen && /home/paul/repos/pauldotyu/kubebuilder-book-tutorial/bin/controller-gen --version | grep -q v0.11.1 || \
GOBIN=/home/paul/repos/pauldotyu/kubebuilder-book-tutorial/bin go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.11.1
/home/paul/repos/pauldotyu/kubebuilder-book-tutorial/bin/controller-gen rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
test -s /home/paul/repos/pauldotyu/kubebuilder-book-tutorial/bin/kustomize || { curl -Ss "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash -s -- 3.8.7 /home/paul/repos/pauldotyu/kubebuilder-book-tutorial/bin; }
{Version:kustomize/v3.8.7 GitCommit:ad092cc7a91c07fdf63a2e4b7f13fa588a39af4f BuildDate:2020-11-11T23:14:14Z GoOs:linux GoArch:amd64}
kustomize installed to /home/paul/repos/pauldotyu/kubebuilder-book-tutorial/bin/kustomize
/home/paul/repos/pauldotyu/kubebuilder-book-tutorial/bin/kustomize build config/crd | kubectl apply -f -
The CustomResourceDefinition "cronjobs.batch.tutorial.kubebuilder.io" is invalid: 
* spec.validation.openAPIV3Schema.properties[spec].properties[jobTemplate].properties[spec].properties[template].properties[spec].properties[containers].items.properties[resources].properties[claims].items.x-kubernetes-map-type: Invalid value: "null": must be atomic as item of a list with x-kubernetes-list-type=set
* spec.validation.openAPIV3Schema.properties[spec].properties[jobTemplate].properties[spec].properties[template].properties[spec].properties[initContainers].items.properties[resources].properties[claims].items.x-kubernetes-map-type: Invalid value: "null": must be atomic as item of a list with x-kubernetes-list-type=set
* spec.validation.openAPIV3Schema.properties[spec].properties[jobTemplate].properties[spec].properties[template].properties[spec].properties[ephemeralContainers].items.properties[resources].properties[claims].items.x-kubernetes-map-type: Invalid value: "null": must be atomic as item of a list with x-kubernetes-list-type=set
* spec.validation.openAPIV3Schema.properties[spec].properties[jobTemplate].properties[spec].properties[template].properties[spec].properties[volumes].items.properties[ephemeral].properties[volumeClaimTemplate].properties[spec].properties[resources].properties[claims].items.x-kubernetes-map-type: Invalid value: "null": must be atomic as item of a list with x-kubernetes-list-type=set
make: *** [Makefile:107: install] Error 1```

### KubeBuilder (CLI) Version

Version: main.version{KubeBuilderVersion:"3.9.1", KubernetesVendor:"1.26.0", GitCommit:"cbccafa75d58bf6ac84c2f5d34ad045980f551be", BuildDate:"2023-03-08T21:23:07Z", GoOs:"linux", GoArch:"amd64"}

### PROJECT version

3

### Plugin versions

```yaml
go.kubebuilder.io/v3

Other versions

go version go1.20.2 linux/amd64

Client Version: version.Info{Major:“1”, Minor:“26”, GitVersion:“v1.26.3”, GitCommit:“9e644106593f3f4aa98f8a84b23db5fa378900bd”, GitTreeState:“clean”, BuildDate:“2023-03-15T13:40:17Z”, GoVersion:“go1.19.7”, Compiler:“gc”, Platform:“linux/amd64”} Kustomize Version: v4.5.7 Server Version: version.Info{Major:“1”, Minor:“25”, GitVersion:“v1.25.3”, GitCommit:“434bfd82814af038ad94d62ebe59b133fcb50506”, GitTreeState:“clean”, BuildDate:“2022-10-25T19:35:11Z”, GoVersion:“go1.19.2”, Compiler:“gc”, Platform:“linux/amd64”}

Extra Labels

No response

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 19 (11 by maintainers)

Commits related to this issue

Most upvoted comments

problem solving

change k8s.io/api v0.26.0 => k8s.io/api v0.26.1 in go.mod

problem solving change k8s.io/api v0.26.0 => k8s.io/api v0.26.1 in go.mod

I noticed running go get -u resolves the issue as well.

This problem occurs because you update the go dependencies incompatible with the controller-runtime version used.

I have not upgraded any go dependencies and I still got the same error. I was following the kubebuilder book using

Version: main.version{KubeBuilderVersion:"3.9.1", KubernetesVendor:"1.26.0", GitCommit:"cbccafa75d58bf6ac84c2f5d34ad045980f551be", BuildDate:"2023-03-08T21:23:07Z", GoOs:"linux", GoArch:"amd64"}

and had initially in my go.mod

       k8s.io/api v0.26.0
       k8s.io/apimachinery v0.26.0
       k8s.io/client-go v0.26.0
       sigs.k8s.io/controller-runtime v0.14.1

which lead to same errors on make install.

Once upgraded to

	k8s.io/api v0.26.1
	k8s.io/apimachinery v0.26.1
	k8s.io/client-go v0.26.1
	sigs.k8s.io/controller-runtime v0.14.4

it works but I have the feeling that Kubebuilder should scaffold go.mod with right versions to start with?

Hi @xiao-jay,

I think you created the project using some KubeBuilder release which scaffolds by default the layout of go/v3 with the previous dependencies versions and not the master branch (see https://github.com/kubernetes-sigs/kubebuilder/blob/master/CONTRIBUTING.md#how-to-build-kubebuilder-locally).

If you look at https://github.com/kubernetes-sigs/kubebuilder/tree/master/docs/book/src/cronjob-tutorial/testdata/project it is build with go/v4. (kubebuilder init --plugins=go/v4) which is using:

k8s.io/apimachinery v0.26.1 k8s.io/client-go v0.26.1 sigs.k8s.io/controller-runtime v0.14.4

https://github.com/kubernetes-sigs/kubebuilder/blob/master/docs/book/src/cronjob-tutorial/testdata/project/go.mod#L9-L11

And controller-tools version (v0.11.3) https://github.com/kubernetes-sigs/kubebuilder/blob/master/docs/book/src/cronjob-tutorial/testdata/project/Makefile#L136.

Therefore, I think this issue is sorted out by using the upper versions and for the next Kubebuilder release. Could you please check it with the master branch and let us know?

I found the error too, just appears in kubebuilder v3.9.1,and next code lead to error.

// CronJobSpec defines the desired state of CronJob
type CronJobSpec struct {

	// Specifies the job that will be created when executing a CronJob.
	JobTemplate batchv1.JobTemplateSpec `json:"jobTemplate"`
}

You just exec make manifests && make install

error info
* spec.validation.openAPIV3Schema.properties[spec].properties[jobTemplate].properties[spec].properties[template].properties[spec].properties[containers].items.properties[resources].properties[claims].items.x-kubernetes-map-type: Invalid value: "null": must be atomic as item of a list with x-kubernetes-list-type=set
* spec.validation.openAPIV3Schema.properties[spec].properties[jobTemplate].properties[spec].properties[template].properties[spec].properties[volumes].items.properties[ephemeral].properties[volumeClaimTemplate].properties[spec].properties[resources].properties[claims].items.x-kubernetes-map-type: Invalid value: "null": must be atomic as item of a list with x-kubernetes-list-type=set
* spec.validation.openAPIV3Schema.properties[spec].properties[jobTemplate].properties[spec].properties[template].properties[spec].properties[initContainers].items.properties[resources].properties[claims].items.x-kubernetes-map-type: Invalid value: "null": must be atomic as item of a list with x-kubernetes-list-type=set
* spec.validation.openAPIV3Schema.properties[spec].properties[jobTemplate].properties[spec].properties[template].properties[spec].properties[ephemeralContainers].items.properties[resources].properties[claims].items.x-kubernetes-map-type: Invalid value: "null": must be atomic as item of a list with x-kubernetes-list-type=set