我试图从操作员CR中获取 RAW
数据,然后我获得空对象。 (其他所有价值都按预期工作)
我已经为问题创建了一个最小示例,在示例中,我试图读取 infrastructureconfig
object
trick的部分,我的struct是我的struct引用另一个结构具有属性类型RAWDATA
https://github.com/jennymet/jennymet/gardnymet/gardner_test
简单的cr
https://github.com/jennymet/gardner_test/blob/main/main/config/samples/mygroup_v1alpha1_rawtest.yaml#l11
在这里读取数据?
这是我使用的类型的参考
园丁 :true
https://book.kubebuilder.io/reference/reference/markers/markers/markers/crd-processing。 html
这不是现有的
如何将其添加到这里的模式?
blob/main/api/v1alpha1/rawtest_types.go#L32 as under the hood it uses
https://github.com/gardener/gardener/blob/5522be0e17ccf38aae36efb9fdb6463c66d6e4f1/pkg/apis/core/v1beta1/types_shoot.go#L1184
I mean我尝试过,并且它不适用于基础结构,
raw在
type System struct {
Type system `json:"type,omitempty"`
// +kubebuilder:pruning:PreserveUnknownFields
Provider v1beta1.Provider `json:"provider,omitempty"`
}
下面是 provider
,这不是我的struct ,它不是我的struct, im只是使用它。 /strong>
这样,请参见 InfrastructureConfig
类型...
type Provider struct {
Type string `json:"type" protobuf:"bytes,1,opt,name=type"`
ControlPlaneConfig *runtime.RawExtension `json:"controlPlaneConfig,omitempty" protobuf:"bytes,2,opt,name=controlPlaneConfig"`
InfrastructureConfig *runtime.RawExtension `json:"infrastructureConfig,omitempty" protobuf:"bytes,3,opt,name=infrastructureConfig"`
}
Im trying to get RAW
data from operator CR and im getting an empty object . (all others value are working as expected )
I’ve created a minimal example for the issue, in the example im trying to read the infrastructureConfig
object
The tricky part here that my struct is reference to another struct which have a property type rawdata
https://github.com/JennyMet/gardner_test
Here the simple CR
https://github.com/JennyMet/gardner_test/blob/main/config/samples/mygroup_v1alpha1_rawtest.yaml#L11
Here im tying to read the data and get an empty object, any idea?
https://github.com/JennyMet/gardner_test/blob/main/controllers/rawtest_controller.go#L70
this is the reference of the type which im using
https://github.com/gardener/gardener/blob/5522be0e17ccf38aae36efb9fdb6463c66d6e4f1/pkg/apis/core/v1beta1/types_shoot.go#L1184
I think its related to fields
x-kubernetes-preserve-unknown-fields: true
https://book.kubebuilder.io/reference/markers/crd-processing.html
which is not existing
How can I add it to the schema here ?
https://github.com/JennyMet/gardner_test/blob/main/api/v1alpha1/rawtest_types.go#L32 as under the hood it uses
https://github.com/gardener/gardener/blob/5522be0e17ccf38aae36efb9fdb6463c66d6e4f1/pkg/apis/core/v1beta1/types_shoot.go#L1184
I mean I tried and it doesnt work as the InfrastructureConfig
which is RAW is under the
type System struct {
Type system `json:"type,omitempty"`
// +kubebuilder:pruning:PreserveUnknownFields
Provider v1beta1.Provider `json:"provider,omitempty"`
}
But the rawData is under Provider
which is not my struct, im just using it.
which is like this , see the InfrastructureConfig
type...
type Provider struct {
Type string `json:"type" protobuf:"bytes,1,opt,name=type"`
ControlPlaneConfig *runtime.RawExtension `json:"controlPlaneConfig,omitempty" protobuf:"bytes,2,opt,name=controlPlaneConfig"`
InfrastructureConfig *runtime.RawExtension `json:"infrastructureConfig,omitempty" protobuf:"bytes,3,opt,name=infrastructureConfig"`
}
发布评论
评论(1)
当前,您只能将
// +kubebuilder放置:修剪:preserveunknownfields
在提供商v1beta1.provider
上,这意味着将允许使用其他未知字段的所有子字段。好消息是,您的问题将在 https://github.com之后解决。 /kubernetes-sigs/controller-tools/pull/683 合并。之后,您必须不使用
// +kubebuilder:修剪:PreserveUnknownFields
和控制器 - 工具会自动添加x-kubernetes-preserve-preserve-preserve-inknown-innown-fields:true
trueRAWEXTENSION
字段。Currently, you can only put the
// +kubebuilder:pruning:PreserveUnknownFields
on theProvider v1beta1.Provider
, which means all sub fields in it will be allowed with additional unknown fields.The good news is, your problem will be solved after https://github.com/kubernetes-sigs/controller-tools/pull/683 merged. After that, you have not to use
// +kubebuilder:pruning:PreserveUnknownFields
and controller-tools would automatically addx-kubernetes-preserve-unknown-fields: true
for allRawExtension
fields.