kubesphere.io/api@v0.0.0-20231107125330-c9a03957060c/notification/v2beta1/notificationmanager_types.go (about)

     1  /*
     2  
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package v2beta1
    18  
    19  import (
    20  	"time"
    21  
    22  	v1 "k8s.io/api/core/v1"
    23  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    24  )
    25  
    26  // SecretKeySelector selects a key of a Secret.
    27  type SecretKeySelector struct {
    28  	// The namespace of the secret, default to the pod's namespace.
    29  	// +optional
    30  	Namespace string `json:"namespace,omitempty" protobuf:"bytes,1,opt,name=namespace"`
    31  	// Name of the secret.
    32  	// +optional
    33  	Name string `json:"name" protobuf:"bytes,1,opt,name=name"`
    34  	// The key of the secret to select from.  Must be a valid secret key.
    35  	Key string `json:"key" protobuf:"bytes,2,opt,name=key"`
    36  }
    37  
    38  // NotificationManagerSpec defines the desired state of NotificationManager
    39  type NotificationManagerSpec struct {
    40  	// Compute Resources required by container.
    41  	Resources v1.ResourceRequirements `json:"resources,omitempty"`
    42  	// Docker Image used to start Notification Manager container,
    43  	// for example kubesphere/notification-manager:v0.1.0
    44  	Image *string `json:"image,omitempty"`
    45  	// Image pull policy. One of Always, Never, IfNotPresent.
    46  	// Defaults to IfNotPresent if not specified
    47  	ImagePullPolicy *v1.PullPolicy `json:"imagePullPolicy,omitempty"`
    48  	// Number of instances to deploy for Notification Manager deployment.
    49  	Replicas *int32 `json:"replicas,omitempty"`
    50  	// Define which Nodes the Pods will be scheduled to.
    51  	NodeSelector map[string]string `json:"nodeSelector,omitempty"`
    52  	// Pod's scheduling constraints.
    53  	Affinity *v1.Affinity `json:"affinity,omitempty"`
    54  	// Pod's tolerations.
    55  	Tolerations []v1.Toleration `json:"tolerations,omitempty"`
    56  	// ServiceAccountName is the name of the ServiceAccount to use to run Notification Manager Pods.
    57  	// ServiceAccount 'default' in notification manager's namespace will be used if not specified.
    58  	ServiceAccountName string `json:"serviceAccountName,omitempty"`
    59  	// Port name used for the pods and service, defaults to webhook
    60  	PortName string `json:"portName,omitempty"`
    61  	// Default Email/Wechat/Slack/Webhook Config to be selected
    62  	DefaultConfigSelector *metav1.LabelSelector `json:"defaultConfigSelector,omitempty"`
    63  	// Receivers to send notifications to
    64  	Receivers *ReceiversSpec `json:"receivers"`
    65  	// The default namespace to which notification manager secrets belong.
    66  	DefaultSecretNamespace string `json:"defaultSecretNamespace,omitempty"`
    67  	// List of volumes that can be mounted by containers belonging to the pod.
    68  	Volumes []v1.Volume `json:"volumes,omitempty"`
    69  	// Pod volumes to mount into the container's filesystem.
    70  	// Cannot be updated.
    71  	VolumeMounts []v1.VolumeMount `json:"volumeMounts,omitempty"`
    72  	// Arguments to the entrypoint.
    73  	// The docker image's CMD is used if this is not provided.
    74  	// Variable references $(VAR_NAME) are expanded using the container's environment. If a variable
    75  	// cannot be resolved, the reference in the input string will remain unchanged. The $(VAR_NAME) syntax
    76  	// can be escaped with a double $$, ie: $$(VAR_NAME). Escaped references will never be expanded,
    77  	// regardless of whether the variable exists or not.
    78  	// Cannot be updated.
    79  	// +optional
    80  	Args []string `json:"args,omitempty"`
    81  }
    82  
    83  type ReceiversSpec struct {
    84  	// Key used to identify tenant, default to be "namespace" if not specified
    85  	TenantKey string `json:"tenantKey"`
    86  	// Selector to find global notification receivers
    87  	// which will be used when tenant receivers cannot be found.
    88  	// Only matchLabels expression is allowed.
    89  	GlobalReceiverSelector *metav1.LabelSelector `json:"globalReceiverSelector"`
    90  	// Selector to find tenant notification receivers.
    91  	// Only matchLabels expression is allowed.
    92  	TenantReceiverSelector *metav1.LabelSelector `json:"tenantReceiverSelector"`
    93  	// Various receiver options
    94  	Options *Options `json:"options,omitempty"`
    95  }
    96  
    97  type GlobalOptions struct {
    98  	// Template file path, must be a absolute path.
    99  	TemplateFiles []string `json:"templateFile,omitempty"`
   100  	// The name of the template to generate message.
   101  	// If the receiver dose not setup template, it will use this.
   102  	Template string `json:"template,omitempty"`
   103  	// The name of the cluster in which the notification manager is deployed.
   104  	Cluster string `json:"cluster,omitempty"`
   105  }
   106  
   107  type EmailOptions struct {
   108  	// Notification Sending Timeout
   109  	NotificationTimeout *int32 `json:"notificationTimeout,omitempty"`
   110  	// Type of sending email, bulk or single
   111  	DeliveryType string `json:"deliveryType,omitempty"`
   112  	// The maximum size of receivers in one email.
   113  	MaxEmailReceivers int `json:"maxEmailReceivers,omitempty"`
   114  	// The name of the template to generate email message.
   115  	// If the global template is not set, it will use default.
   116  	Template string `json:"template,omitempty"`
   117  	// The name of the template to generate email subject
   118  	SubjectTemplate string `json:"subjectTemplate,omitempty"`
   119  }
   120  
   121  type WechatOptions struct {
   122  	// Notification Sending Timeout
   123  	NotificationTimeout *int32 `json:"notificationTimeout,omitempty"`
   124  	// The name of the template to generate wechat message.
   125  	Template string `json:"template,omitempty"`
   126  	// The maximum message size that can be sent in a request.
   127  	MessageMaxSize int `json:"messageMaxSize,omitempty"`
   128  	// The time of token expired.
   129  	TokenExpires time.Duration `json:"tokenExpires,omitempty"`
   130  }
   131  
   132  type SlackOptions struct {
   133  	// Notification Sending Timeout
   134  	NotificationTimeout *int32 `json:"notificationTimeout,omitempty"`
   135  	// The name of the template to generate slack message.
   136  	// If the global template is not set, it will use default.
   137  	Template string `json:"template,omitempty"`
   138  }
   139  
   140  type WebhookOptions struct {
   141  	// Notification Sending Timeout
   142  	NotificationTimeout *int32 `json:"notificationTimeout,omitempty"`
   143  	// The name of the template to generate webhook message.
   144  	// If the global template is not set, it will use default.
   145  	Template string `json:"template,omitempty"`
   146  }
   147  
   148  // The config of flow control.
   149  type Throttle struct {
   150  	// The maximum calls in `Unit`.
   151  	Threshold int           `json:"threshold,omitempty"`
   152  	Unit      time.Duration `json:"unit,omitempty"`
   153  	// The maximum tolerable waiting time when the calls trigger flow control, if the actual waiting time is more than this time, it will
   154  	// return a error, else it will wait for the flow restriction lifted, and send the message.
   155  	// Nil means do not wait, the maximum value is `Unit`.
   156  	MaxWaitTime time.Duration `json:"maxWaitTime,omitempty"`
   157  }
   158  
   159  type DingTalkOptions struct {
   160  	// Notification Sending Timeout
   161  	NotificationTimeout *int32 `json:"notificationTimeout,omitempty"`
   162  	// The name of the template to generate DingTalk message.
   163  	// If the global template is not set, it will use default.
   164  	Template string `json:"template,omitempty"`
   165  	// The time of token expired.
   166  	TokenExpires time.Duration `json:"tokenExpires,omitempty"`
   167  	// The maximum message size that can be sent to conversation in a request.
   168  	ConversationMessageMaxSize int `json:"conversationMessageMaxSize,omitempty"`
   169  	// The maximum message size that can be sent to chatbot in a request.
   170  	ChatbotMessageMaxSize int `json:"chatbotMessageMaxSize,omitempty"`
   171  	// The flow control fo chatbot.
   172  	ChatBotThrottle *Throttle `json:"chatBotThrottle,omitempty"`
   173  	// The flow control fo conversation.
   174  	ConversationThrottle *Throttle `json:"conversationThrottle,omitempty"`
   175  }
   176  
   177  type Options struct {
   178  	Global   *GlobalOptions   `json:"global,omitempty"`
   179  	Email    *EmailOptions    `json:"email,omitempty"`
   180  	Wechat   *WechatOptions   `json:"wechat,omitempty"`
   181  	Slack    *SlackOptions    `json:"slack,omitempty"`
   182  	Webhook  *WebhookOptions  `json:"webhook,omitempty"`
   183  	DingTalk *DingTalkOptions `json:"dingtalk,omitempty"`
   184  }
   185  
   186  // NotificationManagerStatus defines the observed state of NotificationManager
   187  type NotificationManagerStatus struct {
   188  }
   189  
   190  // +kubebuilder:object:root=true
   191  // +kubebuilder:resource:scope=Cluster,shortName=nm,categories=notification-manager
   192  // +kubebuilder:subresource:status
   193  
   194  // NotificationManager is the Schema for the notificationmanagers API
   195  type NotificationManager struct {
   196  	metav1.TypeMeta   `json:",inline"`
   197  	metav1.ObjectMeta `json:"metadata,omitempty"`
   198  
   199  	Spec   NotificationManagerSpec   `json:"spec,omitempty"`
   200  	Status NotificationManagerStatus `json:"status,omitempty"`
   201  }
   202  
   203  // +kubebuilder:object:root=true
   204  
   205  // NotificationManagerList contains a list of NotificationManager
   206  type NotificationManagerList struct {
   207  	metav1.TypeMeta `json:",inline"`
   208  	metav1.ListMeta `json:"metadata,omitempty"`
   209  	Items           []NotificationManager `json:"items"`
   210  }
   211  
   212  func init() {
   213  	SchemeBuilder.Register(&NotificationManager{}, &NotificationManagerList{})
   214  }