kubernetes-sigs / controller-tools

Tools to use with the controller-runtime libraries
Apache License 2.0
706 stars 407 forks source link

Update to custom field in custom resource condition is silently dropped #981

Open kangy-google opened 2 months ago

kangy-google commented 2 months ago

Hello,

I added a custom field to the condition field of my CRD that looks like the following:

type CrCondition struct {
    // Ignore standard fields
    Metadata *ConditionMetadata `json:"metadata,omitempty"`
}

type ConditionMetadata struct {
    Items []ConditionMetadataItem `json:"items,omitempty"`
}

type ConditionMetadataItem struct {
    Key   string `json:"key"`
    Value string `json:"value"`
}

I was hoping to keep track of some metadata along with the condition. However, it seems that when the condition was updated, the metadata field was silently dropped. I can verify with kubectl edit. The command went through without validation error, but the output of the new resource doesn't have the metadata field. Why is this?

sbueringer commented 2 months ago

Is that in status?

kangy-google commented 2 months ago

Is that in status?

Yes, this is in status.

sbueringer commented 2 months ago

You have to use --subresource=status to modify status with kubectl edit

kangy-google commented 2 months ago

Hey, if I understand it correctly, that is for the case where subresource is enabled. I have not enabled it for my resource.

Also, other custom fields with string type can be updated just fine, so I wonder if it has anything to do with the data type.

sbueringer commented 2 months ago

I don't see anything obviously wrong. If those fields also exist in the CRD that you have deployed, there should be no reason why the values should be dropped