0

Should it work for adding index to the field in the status subresource of custom resource?

I keep getting field not supported error though I add index to the filed in the status.

kubectl get obejct --field-selector status.objectRef=xxxx
Error from server (BadRequest): Unable to find "xxxx/v1alpha1, Resource=xxx" that match label selector "", field selector "status.objectRef=xxx": field label not supported: status.objectRef

My CRD is:

type Object struct {
    metav1.TypeMeta   `json:",inline"`
    metav1.ObjectMeta `json:"metadata,omitempty"`

    Spec   ObjectSpec   `json:"spec,omitempty"`
    Status ObjectStatus `json:"status,omitempty"`
}

type ObjectStatus struct {
    
    // +required
    ObjectRef string `json:"objectRef"`
    ...
}

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: Object
spec:
  group: xxx.com
  names:
    kind: Object
    listKind: ObjectList
  scope: Cluster
  versions:
  - additionalPrinterColumns:
    - jsonPath: .status.objectRef
      name: ObjectRef
      type: string
    name: v1alpha1
    schema:
      openAPIV3Schema:
        description: ...
        properties:
          metadata:
            type: object
          spec:
          ...
            type: object
          status:
            description: ....
            properties:
              objectRef:
                description: ObjectRef is the name of the Object
                  resource that this item belongs to.
                type: string
            type: object
        type: object
    served: true
    storage: true
    subresources:
      status: {}

Here is how I add index in the controller:

if err := mgr.GetFieldIndexer().IndexField(ctx, &v1alpha1.Object{}, "status.objectRef",
        func(obj client.Object) []string {
            return []string{obj.(*v1alpha1.Object).Status.ObjectRef}
        }); err != nil {
        return err
    }

If index should be supported to status subresource, what can be the issue here?

JoyceLee
  • 85
  • 3
  • 11

0 Answers0