kubesphere.io/api@v0.0.0-20231107125330-c9a03957060c/notification/v2beta2/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 v2beta2 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 const ( 27 Tenant = "tenant" 28 ) 29 30 // SecretKeySelector selects a key of a Secret. 31 type SecretKeySelector struct { 32 // The namespace of the secret, default to the `defaultSecretNamespace` of `NotificationManager` crd. 33 // If the `defaultSecretNamespace` does not set, default to the pod's namespace. 34 // +optional 35 Namespace string `json:"namespace,omitempty" protobuf:"bytes,1,opt,name=namespace"` 36 // Name of the secret. 37 Name string `json:"name" protobuf:"bytes,1,opt,name=name"` 38 // The key of the secret to select from. Must be a valid secret key. 39 Key string `json:"key" protobuf:"bytes,2,opt,name=key"` 40 } 41 42 // ConfigmapKeySelector selects a key of a Configmap. 43 type ConfigmapKeySelector struct { 44 // The namespace of the configmap, default to the `defaultSecretNamespace` of `NotificationManager` crd. 45 // If the `defaultSecretNamespace` does not set, default to the pod's namespace. 46 // +optional 47 Namespace string `json:"namespace,omitempty" protobuf:"bytes,1,opt,name=namespace"` 48 // Name of the configmap. 49 Name string `json:"name" protobuf:"bytes,1,opt,name=name"` 50 // The key of the configmap to select from. Must be a valid configmap key. 51 Key string `json:"key,omitempty" protobuf:"bytes,2,opt,name=key"` 52 } 53 54 type ValueSource struct { 55 // Selects a key of a secret in the pod's namespace 56 // +optional 57 SecretKeyRef *SecretKeySelector `json:"secretKeyRef,omitempty" protobuf:"bytes,4,opt,name=secretKeyRef"` 58 } 59 60 type Credential struct { 61 // +optional 62 Value string `json:"value,omitempty" protobuf:"bytes,2,opt,name=value"` 63 ValueFrom *ValueSource `json:"valueFrom,omitempty" protobuf:"bytes,3,opt,name=valueFrom"` 64 } 65 66 // Sidecar defines a sidecar container which will be added to the notification manager deployment pod. 67 type Sidecar struct { 68 // The type of sidecar, it can be specified to any value. 69 // Notification manager built-in sidecar for KubeSphere, 70 // It can be used with set `type` to `kubesphere`. 71 Type string `json:"type" protobuf:"bytes,2,opt,name=type"` 72 // Container of sidecar. 73 *v1.Container `json:",inline"` 74 } 75 76 // HistoryReceiver used to collect notification history. 77 type HistoryReceiver struct { 78 // Use a webhook to collect notification history, it will create a virtual receiver. 79 Webhook *WebhookReceiver `json:"webhook"` 80 } 81 82 type Template struct { 83 // Template file. 84 Text *ConfigmapKeySelector `json:"text,omitempty"` 85 // Time to reload template file. 86 // 87 // +kubebuilder:default="1m" 88 ReloadCycle metav1.Duration `json:"reloadCycle,omitempty"` 89 // Configmap which the i18n file be in. 90 LanguagePack []*ConfigmapKeySelector `json:"languagePack,omitempty"` 91 // The language used to send notification. 92 // 93 // +kubebuilder:default="English" 94 Language string `json:"language,omitempty"` 95 } 96 97 // NotificationManagerSpec defines the desired state of NotificationManager 98 type NotificationManagerSpec struct { 99 // Compute Resources required by container. 100 Resources v1.ResourceRequirements `json:"resources,omitempty"` 101 // Docker Image used to start Notification Manager container, 102 // for example kubesphere/notification-manager:v0.1.0 103 Image *string `json:"image,omitempty"` 104 // Image pull policy. One of Always, Never, IfNotPresent. 105 // Defaults to IfNotPresent if not specified 106 ImagePullPolicy *v1.PullPolicy `json:"imagePullPolicy,omitempty"` 107 // Number of instances to deploy for Notification Manager deployment. 108 Replicas *int32 `json:"replicas,omitempty"` 109 // Define which Nodes the Pods will be scheduled to. 110 NodeSelector map[string]string `json:"nodeSelector,omitempty"` 111 // Pod's scheduling constraints. 112 Affinity *v1.Affinity `json:"affinity,omitempty"` 113 // Pod's toleration. 114 Tolerations []v1.Toleration `json:"tolerations,omitempty"` 115 // ServiceAccountName is the name of the ServiceAccount to use to run Notification Manager Pods. 116 // ServiceAccount 'default' in notification manager's namespace will be used if not specified. 117 ServiceAccountName string `json:"serviceAccountName,omitempty"` 118 // Port name used for the pods and service, defaults to webhook 119 PortName string `json:"portName,omitempty"` 120 // Default Email/WeChat/Slack/Webhook Config to be selected 121 DefaultConfigSelector *metav1.LabelSelector `json:"defaultConfigSelector,omitempty"` 122 // Receivers to send notifications to 123 Receivers *ReceiversSpec `json:"receivers"` 124 // The default namespace to which notification manager secrets belong. 125 DefaultSecretNamespace string `json:"defaultSecretNamespace,omitempty"` 126 // List of volumes that can be mounted by containers belonging to the pod. 127 Volumes []v1.Volume `json:"volumes,omitempty"` 128 // Pod volumes to mount into the container's filesystem. 129 // Cannot be updated. 130 VolumeMounts []v1.VolumeMount `json:"volumeMounts,omitempty"` 131 // Arguments to the entrypoint. 132 // The docker image's CMD is used if this is not provided. 133 // +optional 134 Args []string `json:"args,omitempty"` 135 // Sidecar containers. The key is the type of sidecar, known value include: tenant. 136 // Tenant sidecar used to manage the tenants which will receive notifications. 137 // It needs to provide the API `/api/v2/tenant` at port `19094`, this api receives 138 // a parameter `namespace` and return all tenants which need to receive notifications in this namespace. 139 Sidecars map[string]*Sidecar `json:"sidecars,omitempty"` 140 // History used to collect notification history. 141 History *HistoryReceiver `json:"history,omitempty"` 142 // Labels for grouping notifiations. 143 GroupLabels []string `json:"groupLabels,omitempty"` 144 // The maximum size of a batch. A batch used to buffer alerts and asynchronously process them. 145 // 146 // +kubebuilder:default=100 147 BatchMaxSize int `json:"batchMaxSize,omitempty"` 148 // The amount of time to wait before force processing the batch that hadn't reached the max size. 149 // 150 // +kubebuilder:default="1m" 151 BatchMaxWait metav1.Duration `json:"batchMaxWait,omitempty"` 152 // The RoutePolicy determines how to find receivers to which notifications will be sent. 153 // Valid RoutePolicy include All, RouterFirst, and RouterOnly. 154 // All: The alerts will be sent to the receivers that match any router, 155 // and also will be sent to the receivers of those tenants with the right to access the namespace to which the alert belongs. 156 // RouterFirst: The alerts will be sent to the receivers that match any router first. 157 // If no receivers match any router, alerts will send to the receivers of those tenants with the right to access the namespace to which the alert belongs. 158 // RouterOnly: The alerts will only be sent to the receivers that match any router. 159 // 160 // +kubebuilder:default=All 161 RoutePolicy string `json:"routePolicy,omitempty"` 162 // Template used to define information about templates 163 Template *Template `json:"template,omitempty"` 164 } 165 166 type ReceiversSpec struct { 167 // Key used to identify tenant, default to be "namespace" if not specified 168 TenantKey string `json:"tenantKey"` 169 // Selector to find global notification receivers 170 // which will be used when tenant receivers cannot be found. 171 // Only matchLabels expression is allowed. 172 GlobalReceiverSelector *metav1.LabelSelector `json:"globalReceiverSelector"` 173 // Selector to find tenant notification receivers. 174 // Only matchLabels expression is allowed. 175 TenantReceiverSelector *metav1.LabelSelector `json:"tenantReceiverSelector"` 176 // Various receiver options 177 Options *Options `json:"options,omitempty"` 178 } 179 180 type GlobalOptions struct { 181 // Template file path, must be an absolute path. 182 // 183 // Deprecated 184 TemplateFiles []string `json:"templateFile,omitempty"` 185 // The name of the template to generate message. 186 // If the receiver dose not setup template, it will use this. 187 Template string `json:"template,omitempty"` 188 // The name of the cluster in which the notification manager is deployed. 189 Cluster string `json:"cluster,omitempty"` 190 } 191 192 type EmailOptions struct { 193 // Notification Sending Timeout 194 NotificationTimeout *int32 `json:"notificationTimeout,omitempty"` 195 // Deprecated 196 DeliveryType string `json:"deliveryType,omitempty"` 197 // The maximum size of receivers in one email. 198 MaxEmailReceivers int `json:"maxEmailReceivers,omitempty"` 199 // The name of the template to generate email message. 200 // If the global template is not set, it will use default. 201 Template string `json:"template,omitempty"` 202 // The name of the template to generate email subject 203 SubjectTemplate string `json:"subjectTemplate,omitempty"` 204 // template type: text or html, default type is html 205 TmplType string `json:"tmplType,omitempty"` 206 } 207 208 type WechatOptions struct { 209 // Notification Sending Timeout 210 NotificationTimeout *int32 `json:"notificationTimeout,omitempty"` 211 // The name of the template to generate WeChat message. 212 Template string `json:"template,omitempty"` 213 // template type: text or markdown, default type is text 214 TmplType string `json:"tmplType,omitempty"` 215 // The maximum message size that can be sent in a request. 216 MessageMaxSize int `json:"messageMaxSize,omitempty"` 217 // The time of token expired. 218 TokenExpires time.Duration `json:"tokenExpires,omitempty"` 219 } 220 221 type SlackOptions struct { 222 // Notification Sending Timeout 223 NotificationTimeout *int32 `json:"notificationTimeout,omitempty"` 224 // The name of the template to generate Slack message. 225 // If the global template is not set, it will use default. 226 Template string `json:"template,omitempty"` 227 } 228 229 type WebhookOptions struct { 230 // Notification Sending Timeout 231 NotificationTimeout *int32 `json:"notificationTimeout,omitempty"` 232 // The name of the template to generate webhook message. 233 // If the global template is not set, it will use default. 234 Template string `json:"template,omitempty"` 235 } 236 237 // Throttle is the config of flow control. 238 type Throttle struct { 239 // The maximum calls in `Unit`. 240 Threshold int `json:"threshold,omitempty"` 241 Unit time.Duration `json:"unit,omitempty"` 242 // The maximum tolerable waiting time when the calls trigger flow control, if the actual waiting time is more than this time, it will 243 // return an error, else it will wait for the flow restriction lifted, and send the message. 244 // Nil means do not wait, the maximum value is `Unit`. 245 MaxWaitTime time.Duration `json:"maxWaitTime,omitempty"` 246 } 247 248 type DingTalkOptions struct { 249 // Notification Sending Timeout 250 NotificationTimeout *int32 `json:"notificationTimeout,omitempty"` 251 // The name of the template to generate DingTalk message. 252 // If the global template is not set, it will use default. 253 Template string `json:"template,omitempty"` 254 // The name of the template to generate markdown title 255 TitleTemplate string `json:"titleTemplate,omitempty"` 256 // template type: text or markdown, default type is text 257 TmplType string `json:"tmplType,omitempty"` 258 // The time of token expired. 259 TokenExpires time.Duration `json:"tokenExpires,omitempty"` 260 // The maximum message size that can be sent to conversation in a request. 261 ConversationMessageMaxSize int `json:"conversationMessageMaxSize,omitempty"` 262 // The maximum message size that can be sent to chatbot in a request. 263 ChatbotMessageMaxSize int `json:"chatbotMessageMaxSize,omitempty"` 264 // The flow control for chatbot. 265 ChatBotThrottle *Throttle `json:"chatBotThrottle,omitempty"` 266 // The flow control for conversation. 267 ConversationThrottle *Throttle `json:"conversationThrottle,omitempty"` 268 } 269 270 type SmsOptions struct { 271 // Notification Sending Timeout 272 NotificationTimeout *int32 `json:"notificationTimeout,omitempty"` 273 // The name of the template to generate sms message. 274 // If the global template is not set, it will use default. 275 Template string `json:"template,omitempty"` 276 } 277 278 type PushoverOptions struct { 279 // Notification Sending Timeout 280 NotificationTimeout *int32 `json:"notificationTimeout,omitempty"` 281 // The name of the template to generate pushover message. 282 // If the global template is not set, it will use default. 283 Template string `json:"template,omitempty"` 284 // The name of the template to generate message title 285 TitleTemplate string `json:"titleTemplate,omitempty"` 286 } 287 288 type FeishuOptions struct { 289 // Notification Sending Timeout 290 NotificationTimeout *int32 `json:"notificationTimeout,omitempty"` 291 // The name of the template to generate DingTalk message. 292 // If the global template is not set, it will use default. 293 Template string `json:"template,omitempty"` 294 // template type: text or post, default type is post 295 TmplType string `json:"tmplType,omitempty"` 296 // The time of token expired. 297 TokenExpires time.Duration `json:"tokenExpires,omitempty"` 298 } 299 300 type Options struct { 301 Global *GlobalOptions `json:"global,omitempty"` 302 Email *EmailOptions `json:"email,omitempty"` 303 Wechat *WechatOptions `json:"wechat,omitempty"` 304 Slack *SlackOptions `json:"slack,omitempty"` 305 Webhook *WebhookOptions `json:"webhook,omitempty"` 306 DingTalk *DingTalkOptions `json:"dingtalk,omitempty"` 307 Sms *SmsOptions `json:"sms,omitempty"` 308 Pushover *PushoverOptions `json:"pushover,omitempty"` 309 Feishu *FeishuOptions `json:"feishu,omitempty"` 310 } 311 312 // NotificationManagerStatus defines the observed state of NotificationManager 313 type NotificationManagerStatus struct { 314 } 315 316 // +genclient 317 // +genclient:nonNamespaced 318 // +kubebuilder:object:root=true 319 // +k8s:openapi-gen=true 320 321 // NotificationManager is the Schema for the notificationmanagers API 322 type NotificationManager struct { 323 metav1.TypeMeta `json:",inline"` 324 metav1.ObjectMeta `json:"metadata,omitempty"` 325 326 Spec NotificationManagerSpec `json:"spec,omitempty"` 327 Status NotificationManagerStatus `json:"status,omitempty"` 328 } 329 330 // +kubebuilder:object:root=true 331 // +k8s:openapi-gen=true 332 333 // NotificationManagerList contains a list of NotificationManager 334 type NotificationManagerList struct { 335 metav1.TypeMeta `json:",inline"` 336 metav1.ListMeta `json:"metadata,omitempty"` 337 Items []NotificationManager `json:"items"` 338 } 339 340 func init() { 341 SchemeBuilder.Register(&NotificationManager{}, &NotificationManagerList{}) 342 }