daniel-hutao / Advanced-Kubernetes-Operator

纸质书,2023年1月初出版
45 stars 16 forks source link

【勘误-P38】PodTemplateSpec字段添加报错 #10

Open Shuimo03 opened 1 year ago

Shuimo03 commented 1 year ago

我的代码:

// CoffeeSpec defines the desired state of Coffee
type CoffeeSpec struct {
    // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
    // Important: Run "make" to regenerate code after modifying this file
    Replicas int32                  `json:"replicas,omitempty"`
    Template corev1.PodTemplateSpec `json:"template,omitempty"`
}

我的环境

错误

* spec.validation.openAPIV3Schema.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[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[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[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
make: *** [install] Error 1
Sucran commented 1 year ago

同样遇到这个问题

Sucran commented 1 year ago

我是这样解决的 go.mod文件 k8s.io/api v0.26.0 改成 k8s.io/api v0.26.1 然后修改Makefile 里的ENVTEST_K8S_VERSION = 1.26.0 改成 ENVTEST_K8S_VERSION = 1.25.0 就能正常make install 了 机器是MacBookpro14'(2021) M1 chip,使用插件--plugins=go/v4-alpha

kubectl version --short :

Client Version: v1.25.0 Kustomize Version: v4.5.7 Server Version: v1.25.0

Sucran commented 1 year ago

@Shuimo03 可以参考一下我的解决方案

Shuimo03 commented 1 year ago

@Sucran 好咧,多谢大佬,最近没看了,到时候试试看

kcxg commented 1 year ago

kubebuilder 版本用的3.8 可以,现在v3.9.0版本和kubernetes 1.25.0版本结合有报错

kcxg commented 1 year ago

解决方法2,修改go.mod,加入replace k8s.io/api v0.26.0 => k8s.io/api v0.25.0定义,然后执行go mod tidy

vavikast commented 1 year ago

参考https://github.com/kubernetes-sigs/kubebuilder/issues/3303.升级k8s.io/api即可 。 目前发现升级太高会引起其他问题,暂时升级为go get k8s.io/api@v0.26.1 ,go mod tidy.

MajLuu commented 1 year ago

https://github.com/kubernetes-sigs/kubebuilder/issues/3303#issuecomment-1510520496

升级版本