github.com/codeready-toolchain/api@v0.0.0-20240507023248-73662d6db2c5/api/v1alpha1/notification_types.go (about)

     1  package v1alpha1
     2  
     3  import (
     4  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
     5  )
     6  
     7  const (
     8  	// These are valid conditions of a Notification
     9  
    10  	// NotificationDeletionError indicates that the notification failed to be deleted
    11  	NotificationDeletionError ConditionType = deletionError
    12  
    13  	// NotificationSent reflects whether the notification has been sent to the user
    14  	NotificationSent ConditionType = "Sent"
    15  
    16  	// Status condition reasons
    17  	NotificationSentReason          = "Sent"
    18  	NotificationDeletionErrorReason = "UnableToDeleteNotification"
    19  	NotificationContextErrorReason  = "NotificationContextError"
    20  	NotificationDeliveryErrorReason = "DeliveryError"
    21  
    22  	// NotificationUserNameLabelKey is used to identify the user that the notification belongs to
    23  	NotificationUserNameLabelKey = LabelKeyPrefix + "username"
    24  
    25  	// NotificationTypeLabelKey is used to identify the notification type, for example: deactivated
    26  	NotificationTypeLabelKey = LabelKeyPrefix + "type"
    27  
    28  	// Notification Types which describe the type of notification being sent
    29  	NotificationTypeDeactivating = "deactivating"
    30  	NotificationTypeDeactivated  = "deactivated"
    31  	NotificationTypeProvisioned  = "provisioned"
    32  	NotificationTypeIdled        = "idled"
    33  )
    34  
    35  // NOTE: json tags are required.  Any new fields you add must have json tags for the fields to be serialized.
    36  
    37  // NotificationSpec defines the desired state of Notification
    38  // +k8s:openapi-gen=true
    39  type NotificationSpec struct {
    40  	// Important: Run "operator-sdk generate k8s" to regenerate code after modifying this file
    41  	// Add custom validation using kubebuilder tags: https://book.kubebuilder.io/beyond_basics/generating_crd.html
    42  
    43  	// UserID is the user ID from RHD Identity Provider token (“sub” claim).  The UserID is used by
    44  	// the notification service (i.e. the NotificationController) to lookup the UserSignup resource for the user,
    45  	// and extract from it the values required to generate the notification content and to deliver the notification
    46  	// Deprecated: replaced by Context
    47  	// +optional
    48  	UserID string `json:"userID,omitempty"`
    49  
    50  	// Recipient is used to specify the email address where the notification will be delivered.  It must comply with
    51  	// section 3.4.1 of RFC2822, and should be formatted to include the user's first and last names,
    52  	// e.g. "John Smith <jsmith@example.com>"
    53  	Recipient string `json:"recipient,omitempty"`
    54  
    55  	// Context is used to set a number of arbitrary values to be passed to the notification content text formatter,
    56  	// for inclusion in the body of the notification.
    57  	// +optional
    58  	Context map[string]string `json:"context,omitempty"`
    59  
    60  	// Template is the name of the NotificationTemplate resource that will be used to generate the notification
    61  	Template string `json:"template,omitempty"`
    62  
    63  	// Subject is used when no template value is specified, in cases where the complete notification subject is
    64  	// specified at notification creation time
    65  	Subject string `json:"subject,omitempty"`
    66  
    67  	// Content is used when no template value is specified, in cases where the complete notification content is
    68  	// specified at notification creation time
    69  	Content string `json:"content,omitempty"`
    70  }
    71  
    72  // NotificationStatus defines the observed state of Notification
    73  // +k8s:openapi-gen=true
    74  type NotificationStatus struct {
    75  	// Important: Run "operator-sdk generate k8s" to regenerate code after modifying this file
    76  	// Add custom validation using kubebuilder tags: https://book.kubebuilder.io/beyond_basics/generating_crd.html
    77  
    78  	// Conditions is an array of current Notification conditions
    79  	// Supported condition types:
    80  	// Sent
    81  	// +optional
    82  	// +patchMergeKey=type
    83  	// +patchStrategy=merge
    84  	// +listType=map
    85  	// +listMapKey=type
    86  	Conditions []Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"`
    87  }
    88  
    89  //+kubebuilder:object:root=true
    90  //+kubebuilder:subresource:status
    91  
    92  // Notification registers a notification in the CodeReady Toolchain
    93  // +k8s:openapi-gen=true
    94  // +kubebuilder:subresource:status
    95  // +kubebuilder:resource:scope=Namespaced
    96  // +kubebuilder:printcolumn:name="User ID",type="string",JSONPath=`.spec.userID`,priority=1
    97  // +kubebuilder:printcolumn:name="Sent",type="string",JSONPath=`.status.conditions[?(@.type=="Sent")].status`
    98  // +kubebuilder:validation:XPreserveUnknownFields
    99  // +operator-sdk:gen-csv:customresourcedefinitions.displayName="Notification"
   100  type Notification struct {
   101  	metav1.TypeMeta   `json:",inline"`
   102  	metav1.ObjectMeta `json:"metadata,omitempty"`
   103  
   104  	Spec   NotificationSpec   `json:"spec,omitempty"`
   105  	Status NotificationStatus `json:"status,omitempty"`
   106  }
   107  
   108  //+kubebuilder:object:root=true
   109  
   110  // NotificationList contains a list of Notification
   111  type NotificationList struct {
   112  	metav1.TypeMeta `json:",inline"`
   113  	metav1.ListMeta `json:"metadata,omitempty"`
   114  	Items           []Notification `json:"items"`
   115  }
   116  
   117  func init() {
   118  	SchemeBuilder.Register(&Notification{}, &NotificationList{})
   119  }