Reputation: 31
I have a requirement so that my crd accept dynamic structure with some predefined structure for a particular parameter like PmScrape.
So, I have defined below in types.go of go operator
type PmScrape struct {
Enable bool json:"enable,omitempty" yaml:"enable"
Port int32 json:"port,omitempty" yaml:"port"
AddData runtime.RawExtension json:",inline" yaml:",inline"
}
so that additional data can be passed. Below section of CRD generated which is good as it is expecting unknown-fields and it is preserving them as well.
pmScrape:
description: PM Scrape Settings
properties:
enable:
type: boolean
port:
format: int32
type: integer
type: object
x-kubernetes-preserve-unknown-fields: true
Now I passed below section in CR Spec.
pmScrape: f: 1 enable: true port: 9250
As per my understanding by using inline, f: 1 will be saved to AddData and I can use it in go code. But When I am trying to print Cr.Spec.PmScrape at the start of reconcile, it is printing as
{true 9250 {[] }}
AddData is null and i cant find f: 1.
How can I handle this?
Upvotes: 1
Views: 75