Pass nested map data through a CR's spec field

174 views
Skip to first unread message

K M

unread,
Feb 28, 2023, 9:23:00 AM2/28/23
to Operator Framework
Hello,

I would like to pass a nested map (ie map[string]string-or-int) through a CR's spec field to the operator. For this I attempted:

type ChannelSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

// Replicas is the number of replicas of the ESNI deployment
//+operator-sdk:csv:customresourcedefinitions:type=spec
Replicas int32  `json:"replicas"`
//+kubebuilder:pruning:PreserveUnknownFields
Overrides unstructured.Unstructured `json:"overrides,omitempty"`
}
and

apiVersion: foo.com/v1alpha1
kind: Channel
metadata:
  labels:
    app.kubernetes.io/name: Channel1
    app.kubernetes.io/instance: Channel1
    app.kubernetes.io/part-of: src
    app.kubernetes.io/managed-by: kustomize
    app.kubernetes.io/created-by: src
  name: Channel1
spec:
  replicas: 1
  overrides:
    channel-worker:
      configMapRef:
        name: channel-worker-config
        file: config.json

which resulted in the operator error:
// reflector.go:140] pkg/mod/k8s.io/clie...@v0.26.1/tools/cache/reflector.go:169: Failed to watch *v1alpha1.Channel: failed to list *v1alpha1.Channel: Object 'Kind' is missing in '{"component":"channel-worker","configMapRef":"channel-worker-config"}'
// reflector.go:424] pkg/mod/k8s.io/clie...@v0.26.1/tools/cache/reflector.go:169: failed to list *v1alpha1.Channel: Object 'Kind' is missing in '{"component":"channel-worker","configMapRef":"channel-worker-config"}'

Is it possible to pass through such config data without it being a complete Kube object (without Kind for eg) and without disabling validations entirely? (related https://github.com/operator-framework/operator-sdk/issues/1795)

Thanks

K M

unread,
Mar 1, 2023, 5:01:33 AM3/1/23
to Operator Framework
I tried modifying the CRD by adding
                overrides:
                  type: object
                  x-kubernetes-preserve-unknown-fields: true
                  x-kubernetes-embedded-resource: false
as in 
https://book.kubebuilder.io/reference/markers/crd-processing.html  (//+kubebuilder:validation:EmbeddedResource)
but this does not avoid the reflector.go errors.

Setting
                 x-kubernetes-embedded-resource: true
in the generated CRD results in the following errors when "kubectl apply" is called on the CR:
    * spec.overrides.apiVersion: Required value: must not be empty
    * spec.overrides.kind: Required value: must not be empty

Thanks
Reply all
Reply to author
Forward
0 new messages