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
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"`
}
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.