github.com/oam-dev/cluster-gateway@v1.9.0/pkg/event/secret_handler.go (about)

     1  package event
     2  
     3  import (
     4  	"github.com/oam-dev/cluster-gateway/pkg/common"
     5  
     6  	"context"
     7  
     8  	corev1 "k8s.io/api/core/v1"
     9  	"k8s.io/apimachinery/pkg/types"
    10  	"k8s.io/client-go/util/workqueue"
    11  	"sigs.k8s.io/controller-runtime/pkg/event"
    12  	"sigs.k8s.io/controller-runtime/pkg/handler"
    13  	"sigs.k8s.io/controller-runtime/pkg/reconcile"
    14  )
    15  
    16  var _ handler.EventHandler = &SecretHandler{}
    17  
    18  type SecretHandler struct {
    19  }
    20  
    21  func (s *SecretHandler) Create(_ context.Context, event event.CreateEvent, q workqueue.RateLimitingInterface) {
    22  	s.process(event.Object.(*corev1.Secret), q)
    23  }
    24  
    25  func (s *SecretHandler) Update(_ context.Context, event event.UpdateEvent, q workqueue.RateLimitingInterface) {
    26  	s.process(event.ObjectNew.(*corev1.Secret), q)
    27  }
    28  
    29  func (s *SecretHandler) Delete(_ context.Context, event event.DeleteEvent, q workqueue.RateLimitingInterface) {
    30  	s.process(event.Object.(*corev1.Secret), q)
    31  }
    32  
    33  func (s *SecretHandler) Generic(_ context.Context, event event.GenericEvent, q workqueue.RateLimitingInterface) {
    34  	s.process(event.Object.(*corev1.Secret), q)
    35  }
    36  
    37  func (s *SecretHandler) process(secret *corev1.Secret, q workqueue.RateLimitingInterface) {
    38  	for _, ref := range secret.OwnerReferences {
    39  		if ref.Kind == "ManagedServiceAccount" && ref.Name == common.AddonName {
    40  			q.Add(reconcile.Request{
    41  				NamespacedName: types.NamespacedName{
    42  					Name: common.AddonName,
    43  				},
    44  			})
    45  		}
    46  	}
    47  }