apache / solr-operator

Official Kubernetes operator for Apache Solr
https://solr.apache.org/operator
Apache License 2.0
246 stars 111 forks source link

Use patch when updating the statuses of resources. #544

Closed HoustonPutman closed 1 year ago

HoustonPutman commented 1 year ago

Currently the most confusing logging for users is:

2023-04-05T10:27:56-04:00   ERROR   Reconciler error    {"controller": "solrcloud", "controllerGroup": "solr.apache.org", "controllerKind": "SolrCloud", "SolrCloud": {"name":"foo","namespace":"default"}, "namespace": "default", "name": "foo", "reconcileID": "87f9ba03-d059-499b-835c-bf94117edf6e", "error": "Operation cannot be fulfilled on solrclouds.solr.apache.org \"foo\": the object has been modified; please apply your changes to the latest version and try again"}
  sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler
    /Users/houstonputman/dev/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.14.2/pkg/internal/controller/controller.go:329
  sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem
    /Users/houstonputman/dev/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.14.2/pkg/internal/controller/controller.go:274
  sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2.2
    /Users/houstonputman/dev/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.14.2/pkg/internal/controller/controller.go:235

This occurs when we try to update the SolrCloud status at the end of the reconcile loop. Since we already have the before state and the after state, it should be easy to change this from an "Update" to a "Patch", which will make this error go away.

We do need to ensure that all fields have the correct annotations so that patching works as expected. These annotations can be found here: https://book.kubebuilder.io/reference/markers/crd-validation.html

Note: while eventually we want these annotations to be correct across the whole of the CRD, this ticket only requires that they be correct for the status SubResources.