Improve events message for StackGres clusters

When creating a new cluster and describing the CR, we see in the Status and Events output similar to:

Status:
  Conditions:
    Last Transition Time:  2020-03-18T17:44:05.810Z
    Status:                False
    Type:                  PendingRestart
Events:
  Type  Reason          Age   From                Message
  ----  ------          ----  ----                -------
        ClusterUpdated  3s    stackgres-operator  StackGres Cluster default.simple updated

What is that PendingRestart means? And what is "updated"?

These messages need to provide more detailed information.

Proposition

Cluster created and updated message should show what created/changed using the following format:

  • For each resource created the message will be composed like so: Cluster <namespace>.<name> [created|updated]: +<resource>[, +<resource>, ...]
  • For each resource deleted the message will be composed like so: Cluster <namespace>.<name> [created|updated]: -<resource>[, -<resource>, ...]
  • For each resource updated the message will be composed like so: Cluster <namespace>.<name> [created|updated]: <resource> (<field> -> <new value>[, <field> -> <new value>, ...])[, <resource> (<field> -> <new value>[, <field> -> <new value>, ...]), ...]
  • A <resource> is expressed as <resource kind>:<resource name>
  • A <field> is expressed as the <field path> (e.g. /spec/replicas) prefixed by a + or - character if it is a new field or a removed field or without prefix if it is a changed field.
  • Values for Secret will be obfuscated
  • Resources will be ordered by created, deleted and updated and in each grup they will be order by kind, first SGCluster (see below), StatefulSet, CronJob, Job, Pod, Service, Endpoints, ServiceAccount, Role, RoleBinding, PersistentVolumeClaim, ConfigMap, Secret, then others in alphabetical order
  • If too many resources are updated, the log will be stripped to a maximum length of 256 characters becoming like: "Cluster <namespace>.<name> updated: X (a -> b), Y (c -> d), Z (e -> f) and 7 other resources"
  • In case the change is about number of instances the message will be transformed to: "StatefulSet: (instances have been updated to 2 (cluster instances are now 2))"
Edited by Matteo Melli