github.com/argoproj-labs/argocd-operator@v0.10.0/controllers/argocd/hooks.go (about)

     1  package argocd
     2  
     3  import (
     4  	"sync"
     5  
     6  	argoproj "github.com/argoproj-labs/argocd-operator/api/v1beta1"
     7  )
     8  
     9  var (
    10  	mutex sync.RWMutex
    11  	hooks = []Hook{}
    12  )
    13  
    14  // Hook changes resources as they are created or updated by the reconciler.
    15  type Hook func(*argoproj.ArgoCD, interface{}, string) error
    16  
    17  // Register adds a modifier for updating resources during reconciliation.
    18  func Register(h ...Hook) {
    19  	mutex.Lock()
    20  	defer mutex.Unlock()
    21  	hooks = append(hooks, h...)
    22  }
    23  
    24  // nolint:unparam
    25  func applyReconcilerHook(cr *argoproj.ArgoCD, i interface{}, hint string) error {
    26  	mutex.Lock()
    27  	defer mutex.Unlock()
    28  	for _, v := range hooks {
    29  		if err := v(cr, i, hint); err != nil {
    30  			return err
    31  		}
    32  	}
    33  	return nil
    34  }