kubebuilder: metadata.annotations: Too long: must have at most 262144 bytes

What broke? What’s expected?

clone this project on the machine, an go to dir docs/book/src/multiversion-tutorial/testdata/project . make install deploy; then this error appear

 make install deploy
/var/tmp/kubebuilder-master/docs/book/src/multiversion-tutorial/testdata/project/bin/controller-gen rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
/var/tmp/kubebuilder-master/docs/book/src/multiversion-tutorial/testdata/project/bin/kustomize build config/crd | kubectl apply -f -
The CustomResourceDefinition "cronjobs.batch.tutorial.kubebuilder.io" is invalid: metadata.annotations: Too long: must have at most 262144 bytes
make: *** [install] Error 1

Reproducing this issue

No response

KubeBuilder (CLI) Version

3.3.0

PROJECT version

3

Plugin versions

No response

Other versions

k8s: v1.21.9 go: 1.16.2 kustomize: v4.5.2 centos: 3.10.0-693.el7.x86_64

Extra Labels

No response

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 25 (8 by maintainers)

Commits related to this issue

Most upvoted comments

Could you please test with go: 1.17+ < 1.18 just for we ensure that is not related? Also, the kustomize: v4.5.2 is not the version scaffold on it (https://github.com/kubernetes-sigs/kubebuilder/blob/master/testdata/project-v3/Makefile#L116) and from v3 to v4 it has breaking changes

See:

  1. CRD_OPTIONS ?= "crd:maxDescLen=0" in Makefile not work. that’s why
  2. modify Makefile manifests target . change crd => crd:maxDescLen=0 ; then make install; it solved

.PHONY: manifests
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
	$(CONTROLLER_GEN) rbac:roleName=manager-role crd:maxDescLen=0 webhook paths="./..." output:crd:artifacts:config=config/crd/bases

Just adding that kubectl apply --server-side=true -f avoids metadata byte limit

Same here, when following the tutorial https://book.kubebuilder.io/cronjob-tutorial/running

make install throws this erro message : The CustomResourceDefinition "cronjobs.batch.tutorial.kubebuilder.io" is invalid: metadata.annotations: Too long: must have at most 262144 bytes

I am following the book one to one and I got the same problem. Fixed by @ka-keung . This should be fixed asap since it’s literally the tutorial

I solved this problem by adding comments.

	// Specifies the job that will be created when executing a CronJob.
	// +kubebuilder:pruning:PreserveUnknownFields
	// +kubebuilder:validation:Schemaless
	JobTemplate batchv1.JobTemplateSpec `json:"jobTemplate"`

Hi @camilamacedo86 -

I was able to recreate the issue. There are two ways through which we can fix this issue.

  1. As mentioned in the issue, modify the Makefile manifests target. change crd => crd:maxDescLen=0;
  2. Change kubectl apply to kubectl replace --force` as mentioned here

Please take a look at PR and let me know your thoughts.

I was able to resolve this issue in the cronjob example by making the following changes. However, I don’t know if this actually fixes the issue.

File: docs/book/src/cronjob-tutorial/testdata/project/Makefile Lines: 45-53

##@ Development

.PHONY: manifests
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
-	$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
+	$(CONTROLLER_GEN) rbac:roleName=manager-role crd:maxDescLen=0 webhook paths="./..." output:crd:artifacts:config=config/crd/bases

.PHONY: generate
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
	$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."

This seems to happen because the kubectl apply from the make install step adds the kubectl.kubernetes.io/last-applied-configuration annotation. You can circumvent this behaviour by using a server-side apply. In the Makefile, replace the install with:

.PHONY: install
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
	$(KUSTOMIZE) build config/crd | $(KUBECTL) apply --server-side -f -

Also just ran into this working my way through the tutorial. Definitely should be fixed asap