You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用corev1.ResourceRequirements时Operator SDK无法生成清单

问题解决方法

1. 确认核心API包导入

检查你的myservice_types.go文件,确保已导入corev1包:

import (
    corev1 "k8s.io/api/core/v1"
    metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

2. 添加kubebuilder注释标记

给Resources字段补充必要的注释,帮助CRD生成器识别内置类型的Schema:

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
    // +kubebuilder:validation:EmbeddedResource
    // +kubebuilder:pruning:PreserveUnknownFields
    Resources corev1.ResourceRequirements `json:"resources,omitempty"`
    
}

3. 刷新依赖并重新生成

执行以下命令确保依赖完整,并重新生成manifests:

go mod tidy
make manifests

4. 检查controller-gen配置(可选)

确认Makefile中manifests目标的controller-gen命令包含正确参数,比如:

manifests: controller-gen
    $(CONTROLLER_GEN) rbac:roleName=manager-role crd:crdVersions=v1 webhook paths="./..." output:crd:artifacts:config=config/crd/bases

注释说明

  • +kubebuilder:validation:EmbeddedResource 告诉生成器该字段是一个嵌入的Kubernetes API资源
  • +kubebuilder:pruning:PreserveUnknownFields 保留字段中可能存在的未知属性,和原生Pod的Resources字段行为一致

内容的提问来源于stack exchange,提问作者Armando

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 10:57:41