K8S操作员读取原始数据

发布于 2025-02-06 18:45:56 字数 2420 浏览 2 评论 0 原文

我试图从操作员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"`

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

裂开嘴轻声笑有多痛 2025-02-13 18:45:56

当前,您只能将 // +kubebuilder放置:修剪:preserveunknownfields 提供商v1beta1.provider 上,这意味着将允许使用其他未知字段的所有子字段。

好消息是,您的问题将在 https://github.com之后解决。 /kubernetes-sigs/controller-tools/pull/683 合并。之后,您必须不使用 // +kubebuilder:修剪:PreserveUnknownFields 和控制器 - 工具会自动添加 x-kubernetes-preserve-preserve-preserve-inknown-innown-fields:true true RAWEXTENSION 字段。

Currently, you can only put the // +kubebuilder:pruning:PreserveUnknownFields on the Provider 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 add x-kubernetes-preserve-unknown-fields: true for all RawExtension fields.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文