Generate 'oneOf' property with operator-sdk

Viewed 527

I'm currently a newcomer to the operator-sdk, however, I want to ask about something.

I'm trying to generate a CRD contained oneOf property in the spec. However, I got stuck in this task.

When I searched on google, I didn't find a way to implement the property using the operator-sdk.

If I wanted to implement generate the property oneOf as my CRD, is there any way to do it?

For example,

type: object
properties:
  spec:
    ...
    oneOf:
      - required: [someproperties1]
      - required: [someproperties2]

Thanks.

1 Answers

Yes! Follow either the Ansible, Helm or Go quickstart docs.

Assuming your question is about creating a CRD.

For example. if you are following the Go quickstart, you can use the operator-sdk CLI like this:

$ operator-sdk add api --api-version=my.example.com/v1alpha1 --kind=OneOf

or with Ansible:

$ operator-sdk new my-operator --api-version=my.example.com/v1alpha1 --kind=OneOf --type=ansible

Note that your CRD needs to start with caps (K8s convention): OneOf

Now, if you want to define a 'spec' in your CRD, you can also follow the quickstart guides (The boilerplate will be created by the operator-sdk CLI). For example for Go, it would be creating a struct in the code:

type OneOfSpec struct {
    // Size is the size of your OneOf
    Size int32 `json:"size"`
}
type OneOfStatus struct {
    // Nodes are the names of the oneof pods
    Nodes []string `json:"nodes"`
}
Related