kubernetes-sigs / kubebuilder

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

https://book.kubebuilder.io/cronjob-tutorial/cronjob-tutorial #4074

Closed remotejob closed 2 months ago

remotejob commented 3 months ago

make run

go run ./cmd/main.go

vet: api/v1/zz_generated.deepcopy.go:126:10: cannot use c (variable of type *CronJobSpec) as "k8s.io/apimachinery/pkg/runtime".Object value in return statement: *CronJobSpec does not implement "k8s.io/apimachinery/pkg/runtime".Object (missing method GetObjectKind)

sbueringer commented 3 months ago

/transfer kubebuilder

camilamacedo86 commented 2 months ago

Hi @remotejob

The only issue that I found was Too long: must have at most 262144 bytes

$ make install
/Users/camiladeomacedo/go/src/sigs.k8s.io/kubebuilder/docs/book/src/cronjob-tutorial/testdata/project/bin/controller-gen rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
Downloading sigs.k8s.io/kustomize/kustomize/v5@v5.4.2
/Users/camiladeomacedo/go/src/sigs.k8s.io/kubebuilder/docs/book/src/cronjob-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

To address this one we should be scaffolding the Makefile with crd:maxDescLen=0 We need change the hack/docs to add this replace (it seems a regression), as:

.PHONY: manifests
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
    # Note that the option maxDescLen=0 was added in the default scaffold in order to sort out the issue
    # Too long: must have at most 262144 bytes. By using kubectl apply to create / update resources an annotation
    # is created by K8s API to store the latest version of the resource ( kubectl.kubernetes.io/last-applied-configuration).
    # However, it has a size limit and if the CRD is too big with so many long descriptions as this one it will cause the failure.
    $(CONTROLLER_GEN) rbac:roleName=manager-role crd:maxDescLen=0 webhook paths="./..." output:crd:artifacts:config=config/crd/bases

However, after change the make manifest target the make run worked fine:

$ export ENABLE_WEBHOOKS=false
$ make run
# Note that the option maxDescLen=0 was added in the default scaffold in order to sort out the issue
# Too long: must have at most 262144 bytes. By using kubectl apply to create / update resources an annotation
# is created by K8s API to store the latest version of the resource ( kubectl.kubernetes.io/last-applied-configuration).
# However, it has a size limit and if the CRD is too big with so many long descriptions as this one it will cause the failure.
/Users/camiladeomacedo/go/src/sigs.k8s.io/kubebuilder/docs/book/src/cronjob-tutorial/testdata/project/bin/controller-gen rbac:roleName=manager-role crd:maxDescLen=0 webhook paths="./..." output:crd:artifacts:config=config/crd/bases
/Users/camiladeomacedo/go/src/sigs.k8s.io/kubebuilder/docs/book/src/cronjob-tutorial/testdata/project/bin/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
go fmt ./...
go vet ./...
go run ./cmd/main.go
2024-08-13T05:49:31+01:00   INFO    setup   starting manager
2024-08-13T05:49:31+01:00   INFO    starting server {"name": "health probe", "addr": "[::]:8081"}
2024-08-13T05:49:32+01:00   INFO    Starting EventSource    {"controller": "cronjob", "controllerGroup": "batch.tutorial.kubebuilder.io", "controllerKind": "CronJob", "source": "kind source: *v1.CronJob"}
2024-08-13T05:49:32+01:00   INFO    Starting EventSource    {"controller": "cronjob", "controllerGroup": "batch.tutorial.kubebuilder.io", "controllerKind": "CronJob", "source": "kind source: *v1.Job"}
2024-08-13T05:49:32+01:00   INFO    Starting Controller {"controller": "cronjob", "controllerGroup": "batch.tutorial.kubebuilder.io", "controllerKind": "CronJob"}
2024-08-13T05:49:32+01:00   INFO    Starting workers    {"controller": "cronjob", "controllerGroup": "batch.tutorial.kubebuilder.io", "controllerKind": "CronJob", "worker count": 1}

You might be using an unsupported golang version. Could you please validate your env and if you still facing issues can you please provide the steps performed so that we try to reproduce it as what is your SO and go version.

thank you

camilamacedo86 commented 2 months ago

Hi @remotejob

I am closing this one with the fix/change: https://github.com/kubernetes-sigs/kubebuilder/pull/4075 However, if you:

And still facing issues please feel free to open a new issue describing your local env setup , so and steps performed for we try to reproduce this one.

Thank you for your comprehension.