The `.spec.channels` of a `CRD` is missing from `&RawExtension`

7/11/2019

I'm creating a CRD within it, there's a spec field called channel.

However, I can't find this field from my controller, even other fields are showing up fine.

Steps to reproduce the issue,

1, apply the YAML 2, go to the controller to print the spec fields

A. YAML sample

--- 
apiVersion: app.com/v1alpha1
kind: Deploys
metadata: 
  name: sample-cr-foo-channel
  namespace: default
spec: 
  channels: 
    - qa
  overrides: 
    - 
      clusterName: local-cluster
      clusterOverrides: 
        - 
          path: data
          value: 
            database: mongodb3
  template: 
    apiVersion: v1
    data: 
      database: mongodb
    kind: ConfigMap
    metadata: 
      name: example-configmap-channel-deploy
  dependencies:

B. print statement on controller

dpl is the CR

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

    Template     *runtime.RawExtension        `json:"template"`
    Dependencies []Dependency                 `json:"dependencies,omitempty"`
    Placement    *placementv1alpha1.Placement `json:"placement,omitempty"`
    Overrides    []Overrides                  `json:"overrides,omitempty"`
    Channels     []string                     `json:"channels,omitempty"`
}
data, err := json.Marshal(dpl.Spec)
if err != nil {
    glog.V(4).Info("unexpected error: ", err)
}

C. CR with RawExtension

{

...

spec":{"channels":["qa"],"dependencies":null,"overrides":[{"clusterName":"local-cluster","clusterOverrides":[{"path":"data","value":{"database":"mongodb3"}}]}],"template":{"apiVersion":"v1","data":{"database":"mongodb"},"kind":"ConfigMap","metadata":{"name":"example-configmap-channel-deploy"}}}}
] [] nil [] } {&RawExtension{Raw:*[123 34 97 112 105 86 101 114 115 105 111 110 34 58 34 118 49 34 44 34 100 97 116 97 34 58 123 34 100 97 116 97 98 97 115 101 34 58 34 109 111 110 103 111 100 98 34 125 44 34 107 105 110 100 34 58 34 67 111 110 102 105 103 77 97 112 34 44 34 109 101 116 97 100 97 116 97 34 58 123 34 110 97 109 101 34 58 34 101 120 97 109 112 108 101 45 99 111 110 102 105 103 109 97 112 45 99 104 97 110 110 101 108 45 100 101 112 108 111 121 34 125 125],} [] <nil> [{local-cluster [{{[123 34 112 97 116 104 34 58 34 100 97 116 97 34 44 34 118 97 108 117 101 34 58 123 34 100 97 116 97 98 97 115 101 34 58 34 109 111 110 103 111 100 98 51 34 125 125] <nil>}}]}] []} {{Deployed  2019-07-11 11:23:53 -0400 EDT} map[]}}

C. print results

 spec data:{"template":{"apiVersion":"v1","data":{"database":"mongodb"},"kind":"ConfigMap","metadata":{"name":"example-configmap-channel-deploy"}},"overrides":[{"clusterName":"local-cluster","clusterOverrides":[{"path":"data","value":{"database":"mongodb3"}}]}]}

It seems the channels field somehow is ignored, but the other fields are fine.

-- Ian Zhang
go
kubebuilder
kubernetes
yaml

0 Answers