airshipit / sip

4 stars 1 forks source link

Ensure generated objects are kept in sync #12

Open seaneagan opened 3 years ago

seaneagan commented 3 years ago

Describe the bug

Any objects generated by a controller should be:

  1. deleted when the CR is deleted
  2. re-reconciled if they are manipulated outside the controller's control

The controller-runtime has an API which can be used to accomplish both of these pretty easily: https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/controller/controllerutil#SetControllerReference

Prior to #5 we had 1. in place, since we created a standalone namespace for each SIPCluster for service resources to be created in, so when the SIPCluster was deleted we could simply delete that namespace. Now that we are creating service objects in the SIPCluster CR namespace, we should be deleting those objects each individually (as opposed to the whole namespace) when the SIPCluster is deleted.

Steps To Reproduce

  1. Delete a CIPCluster CR, notice the generated objects are not deleted.
  2. Delete a Service which was generated for a CR, not it is not automatically re-created (until the CR itself is reconciled again due to some CR change).