I am creating a Kubernetes operator using Operator SDK. I am learning this framework by doing. Recently I encountered an issue. I want my CRD to allow users to define workload resources exactly how it is done for a Pod. So I just thought that in my CRD spec I would be able to define Resources corev1.ResourceRequirements json:"resources,omitempty"
and be done with it. The problem is that when I run make manifests
or make run
, I get the following error...
.../.asdf/installs/golang/1.23.0/packages/pkg/mod/k8s.io/api@v0.31.1/core/v1/doc.go:21:1: missing argument "" (at <input>)
k8s.io/api/core/v1:-: unknown type "k8s.io/api/core/v1".ResourceRequirements
my-service/api/v1alpha1:-: unable to locate schema for type "k8s.io/api/core/v1".ResourceRequirements
Error: not all generators ran successfully
According to the docs the schemas for all core APIs should be added by default. Do you know what I am missing?
Here's my CRD's spec
type MyServiceSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file
Image ImageSpec `json:"image,omitempty"`
// +optional
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
}
Here's my dependencies in go.mod
go 1.23.0
require (
github.com/fluxcd/helm-controller/api v1.1.0
github.com/onsi/ginkgo/v2 v2.19.0
github.com/onsi/gomega v1.33.1
k8s.io/api v0.31.1
k8s.io/apiextensions-apiserver v0.31.1
k8s.io/apimachinery v0.31.1
k8s.io/client-go v0.31.1
sigs.k8s.io/controller-runtime v0.19.0
)
...
https://github.com/kubernetes-sigs/controller-tools/issues/1064
GO11MODULE=on go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.16.5
latest controller-tools can fix it