...

Source file src/edge-infra.dev/pkg/k8s/runtime/controller/reconcile/recerr/options.go

Documentation: edge-infra.dev/pkg/k8s/runtime/controller/reconcile/recerr

     1  package recerr
     2  
     3  import corev1 "k8s.io/api/core/v1"
     4  
     5  // Option is a public error option that can be used to customize some of the
     6  // [Base] error's behavior.
     7  type Option func(*options)
     8  
     9  type options struct {
    10  	notification bool
    11  	eventType    string
    12  }
    13  
    14  // WithoutNotification forces a reconciliation error to not result in a K8s
    15  // event notifiation.
    16  //
    17  // NOTE: All corev1.EventTypeWarning events will result in a notification
    18  func WithoutNotification() Option {
    19  	return func(o *options) {
    20  		o.notification = false
    21  	}
    22  }
    23  
    24  // WithEvent sets the event type that should be used for the error. Some
    25  // specialized errors, like Stalled, set an appropriate Event type by default.
    26  // This [Option] can be used to configure generic reconcile errors or override
    27  // the behavior of specialized errors.
    28  func WithEvent(eventType string) Option {
    29  	return func(o *options) {
    30  		o.eventType = eventType
    31  	}
    32  }
    33  
    34  func makeOptions(o *options, opts ...Option) *options {
    35  	if o.eventType == "" {
    36  		o.eventType = corev1.EventTypeWarning
    37  	}
    38  	for _, opt := range opts {
    39  		opt(o)
    40  	}
    41  	return o
    42  }
    43  

View as plain text