support customize notification receiver

Signed-off-by: wanjunlei <wanjunlei@yunify.com>
This commit is contained in:
wanjunlei
2021-01-27 14:37:44 +08:00
parent 01600081f6
commit f9213fcdc8
130 changed files with 18870 additions and 1 deletions

View File

@@ -0,0 +1,65 @@
/*
Copyright 2020 The KubeSphere Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package v2
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// Configuration of conversation
type DingTalkApplicationConfig struct {
// The key of the application with which to send messages.
AppKey *SecretKeySelector `json:"appkey,omitempty"`
// The key in the secret to be used. Must be a valid secret key.
AppSecret *SecretKeySelector `json:"appsecret,omitempty"`
}
// DingTalkConfigSpec defines the desired state of DingTalkConfig
type DingTalkConfigSpec struct {
// Only needed when send alerts to the conversation.
Conversation *DingTalkApplicationConfig `json:"conversation,omitempty"`
}
// DingTalkConfigStatus defines the observed state of DingTalkConfig
type DingTalkConfigStatus struct {
}
// +kubebuilder:object:root=true
// +kubebuilder:resource:scope=Cluster,shortName=dc
// +genclient
// +genclient:nonNamespaced
// DingTalkConfig is the Schema for the dingtalkconfigs API
type DingTalkConfig struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec DingTalkConfigSpec `json:"spec,omitempty"`
Status DingTalkConfigStatus `json:"status,omitempty"`
}
// +kubebuilder:object:root=true
// DingTalkConfigList contains a list of DingTalkConfig
type DingTalkConfigList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []DingTalkConfig `json:"items"`
}
func init() {
SchemeBuilder.Register(&DingTalkConfig{}, &DingTalkConfigList{})
}

View File

@@ -0,0 +1,80 @@
/*
Copyright 2020 The KubeSphere Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package v2
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// Configuration of ChatBot
type DingTalkChatBot struct {
// The webhook of ChatBot which the message will send to.
Webhook *SecretKeySelector `json:"webhook"`
// Custom keywords of ChatBot
Keywords []string `json:"keywords,omitempty"`
// Secret of ChatBot, you can get it after enabled Additional Signature of ChatBot.
Secret *SecretKeySelector `json:"secret,omitempty"`
}
// Configuration of conversation
type DingTalkConversation struct {
ChatID string `json:"chatid"`
}
// DingTalkReceiverSpec defines the desired state of DingTalkReceiver
type DingTalkReceiverSpec struct {
// DingTalkConfig to be selected for this receiver
DingTalkConfigSelector *metav1.LabelSelector `json:"dingtalkConfigSelector,omitempty"`
// Selector to filter alerts.
AlertSelector *metav1.LabelSelector `json:"alertSelector,omitempty"`
// Be careful, a ChatBot only can send 20 message per minute.
ChatBot *DingTalkChatBot `json:"chatbot,omitempty"`
// The conversation which message will send to.
Conversation *DingTalkConversation `json:"conversation,omitempty"`
}
// DingTalkReceiverStatus defines the observed state of DingTalkReceiver
type DingTalkReceiverStatus struct {
}
// +kubebuilder:object:root=true
// +kubebuilder:resource:scope=Cluster,shortName=dr
// +genclient
// +genclient:nonNamespaced
// DingTalkReceiver is the Schema for the dingtalkreceivers API
type DingTalkReceiver struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec DingTalkReceiverSpec `json:"spec,omitempty"`
Status DingTalkReceiverStatus `json:"status,omitempty"`
}
// +kubebuilder:object:root=true
// DingTalkReceiverList contains a list of DingTalkReceiver
type DingTalkReceiverList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []DingTalkReceiver `json:"items"`
}
func init() {
SchemeBuilder.Register(&DingTalkReceiver{}, &DingTalkReceiverList{})
}

View File

@@ -0,0 +1,21 @@
/*
Copyright 2020 The KubeSphere Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Package v1alpha1 contains API Schema definitions for the notification v2 API group
// +groupName=notification.kubesphere.io
// +genclient
// +genclient:nonNamespaced
package v2

View File

@@ -0,0 +1,77 @@
/*
Copyright 2020 The KubeSphere Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package v2
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// EmailConfigSpec defines the desired state of EmailConfig
type EmailConfigSpec struct {
// The sender address.
From string `json:"from"`
// The address of the SMTP server.
SmartHost HostPort `json:"smartHost"`
// The hostname to use when identifying to the SMTP server.
Hello *string `json:"hello,omitempty"`
// The username for CRAM-MD5, LOGIN and PLAIN authentications.
AuthUsername *string `json:"authUsername,omitempty"`
// The identity for PLAIN authentication.
AuthIdentify *string `json:"authIdentify,omitempty"`
// The secret contains the SMTP password for LOGIN and PLAIN authentications.
AuthPassword *SecretKeySelector `json:"authPassword,omitempty"`
// The secret contains the SMTP secret for CRAM-MD5 authentication.
AuthSecret *SecretKeySelector `json:"authSecret,omitempty"`
// The default SMTP TLS requirement.
RequireTLS *bool `json:"requireTLS,omitempty"`
TLS *TLSConfig `json:"tls,omitempty"`
}
type HostPort struct {
Host string `json:"host"`
Port string `json:"port"`
}
// EmailConfigStatus defines the observed state of EmailConfig
type EmailConfigStatus struct {
}
// +kubebuilder:object:root=true
// +kubebuilder:resource:scope=Cluster,shortName=ec
// +genclient
// +genclient:nonNamespaced
// EmailConfig is the Schema for the emailconfigs API
type EmailConfig struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec EmailConfigSpec `json:"spec,omitempty"`
Status EmailConfigStatus `json:"status,omitempty"`
}
// +kubebuilder:object:root=true
// EmailConfigList contains a list of EmailConfig
type EmailConfigList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []EmailConfig `json:"items"`
}
func init() {
SchemeBuilder.Register(&EmailConfig{}, &EmailConfigList{})
}

View File

@@ -0,0 +1,61 @@
/*
Copyright 2020 The KubeSphere Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package v2
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// EmailReceiverSpec defines the desired state of EmailReceiver
type EmailReceiverSpec struct {
// Receivers' email addresses
To []string `json:"to"`
// EmailConfig to be selected for this receiver
EmailConfigSelector *metav1.LabelSelector `json:"emailConfigSelector,omitempty"`
// Selector to filter alerts.
AlertSelector *metav1.LabelSelector `json:"alertSelector,omitempty"`
}
// EmailReceiverStatus defines the observed state of EmailReceiver
type EmailReceiverStatus struct {
}
// +kubebuilder:object:root=true
// +kubebuilder:resource:scope=Cluster,shortName=er
// +genclient
// +genclient:nonNamespaced
// EmailReceiver is the Schema for the emailreceivers API
type EmailReceiver struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec EmailReceiverSpec `json:"spec,omitempty"`
Status EmailReceiverStatus `json:"status,omitempty"`
}
// +kubebuilder:object:root=true
// EmailReceiverList contains a list of EmailReceiver
type EmailReceiverList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []EmailReceiver `json:"items"`
}
func init() {
SchemeBuilder.Register(&EmailReceiver{}, &EmailReceiverList{})
}

View File

@@ -0,0 +1,210 @@
/*
Copyright 2020 The KubeSphere Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package v2
import (
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"time"
)
// SecretKeySelector selects a key of a Secret.
type SecretKeySelector struct {
// The namespace of the secret, default to the pod's namespace.
// +optional
Namespace string `json:"namespace,omitempty" protobuf:"bytes,1,opt,name=namespace"`
// Name of the secret.
// +optional
Name string `json:"name" protobuf:"bytes,1,opt,name=name"`
// The key of the secret to select from. Must be a valid secret key.
Key string `json:"key" protobuf:"bytes,2,opt,name=key"`
}
// NotificationManagerSpec defines the desired state of NotificationManager
type NotificationManagerSpec struct {
// Compute Resources required by container.
Resources v1.ResourceRequirements `json:"resources,omitempty"`
// Docker Image used to start Notification Manager container,
// for example kubesphere/notification-manager:v0.1.0
Image *string `json:"image,omitempty"`
// Image pull policy. One of Always, Never, IfNotPresent.
// Defaults to IfNotPresent if not specified
ImagePullPolicy *v1.PullPolicy `json:"imagePullPolicy,omitempty"`
// Number of instances to deploy for Notification Manager deployment.
Replicas *int32 `json:"replicas,omitempty"`
// Define which Nodes the Pods will be scheduled to.
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
// Pod's scheduling constraints.
Affinity *v1.Affinity `json:"affinity,omitempty"`
// Pod's tolerations.
Tolerations []v1.Toleration `json:"tolerations,omitempty"`
// ServiceAccountName is the name of the ServiceAccount to use to run Notification Manager Pods.
// ServiceAccount 'default' in notification manager's namespace will be used if not specified.
ServiceAccountName string `json:"serviceAccountName,omitempty"`
// Port name used for the pods and service, defaults to webhook
PortName string `json:"portName,omitempty"`
// Default Email/Wechat/Slack/Webhook Config to be selected
DefaultConfigSelector *metav1.LabelSelector `json:"defaultConfigSelector,omitempty"`
// Receivers to send notifications to
Receivers *ReceiversSpec `json:"receivers"`
// List of volumes that can be mounted by containers belonging to the pod.
Volumes []v1.Volume `json:"volumes,omitempty"`
// Pod volumes to mount into the container's filesystem.
// Cannot be updated.
VolumeMounts []v1.VolumeMount `json:"volumeMounts,omitempty"`
// Arguments to the entrypoint.
// The docker image's CMD is used if this is not provided.
// Variable references $(VAR_NAME) are expanded using the container's environment. If a variable
// cannot be resolved, the reference in the input string will remain unchanged. The $(VAR_NAME) syntax
// can be escaped with a double $$, ie: $$(VAR_NAME). Escaped references will never be expanded,
// regardless of whether the variable exists or not.
// Cannot be updated.
// +optional
Args []string `json:"args,omitempty"`
}
type ReceiversSpec struct {
// Key used to identify tenant, default to be "namespace" if not specified
TenantKey string `json:"tenantKey"`
// Selector to find global notification receivers
// which will be used when tenant receivers cannot be found.
// Only matchLabels expression is allowed.
GlobalReceiverSelector *metav1.LabelSelector `json:"globalReceiverSelector"`
// Selector to find tenant notification receivers.
// Only matchLabels expression is allowed.
TenantReceiverSelector *metav1.LabelSelector `json:"tenantReceiverSelector"`
// Various receiver options
Options *Options `json:"options,omitempty"`
}
type GlobalOptions struct {
// Template file path, must be a absolute path.
TemplateFiles []string `json:"templateFile,omitempty"`
// The name of the template to generate message.
// If the receiver dose not setup template, it will use this.
Template string `json:"template,omitempty"`
// The name of the cluster in which the notification manager is deployed.
Cluster string `json:"cluster,omitempty"`
}
type EmailOptions struct {
// Notification Sending Timeout
NotificationTimeout *int32 `json:"notificationTimeout,omitempty"`
// Type of sending email, bulk or single
DeliveryType string `json:"deliveryType,omitempty"`
// The maximum size of receivers in one email.
MaxEmailReceivers int `json:"maxEmailReceivers,omitempty"`
// The name of the template to generate email message.
// If the global template is not set, it will use default.
Template string `json:"template,omitempty"`
// The name of the template to generate email subject
SubjectTemplate string `json:"subjectTemplate,omitempty"`
}
type WechatOptions struct {
// Notification Sending Timeout
NotificationTimeout *int32 `json:"notificationTimeout,omitempty"`
// The name of the template to generate wechat message.
Template string `json:"template,omitempty"`
// The maximum message size that can be sent in a request.
MessageMaxSize int `json:"messageMaxSize,omitempty"`
// The time of token expired.
TokenExpires time.Duration `json:"tokenExpires,omitempty"`
}
type SlackOptions struct {
// Notification Sending Timeout
NotificationTimeout *int32 `json:"notificationTimeout,omitempty"`
// The name of the template to generate slack message.
// If the global template is not set, it will use default.
Template string `json:"template,omitempty"`
}
type WebhookOptions struct {
// Notification Sending Timeout
NotificationTimeout *int32 `json:"notificationTimeout,omitempty"`
// The name of the template to generate webhook message.
// If the global template is not set, it will use default.
Template string `json:"template,omitempty"`
}
// The config of flow control.
type Throttle struct {
// The maximum calls in `Unit`.
Threshold int `json:"threshold,omitempty"`
Unit time.Duration `json:"unit,omitempty"`
// The maximum tolerable waiting time when the calls trigger flow control, if the actual waiting time is more than this time, it will
// return a error, else it will wait for the flow restriction lifted, and send the message.
// Nil means do not wait, the maximum value is `Unit`.
MaxWaitTime time.Duration `json:"maxWaitTime,omitempty"`
}
type DingTalkOptions struct {
// Notification Sending Timeout
NotificationTimeout *int32 `json:"notificationTimeout,omitempty"`
// The name of the template to generate DingTalk message.
// If the global template is not set, it will use default.
Template string `json:"template,omitempty"`
// The time of token expired.
TokenExpires time.Duration `json:"tokenExpires,omitempty"`
// The maximum message size that can be sent to conversation in a request.
ConversationMessageMaxSize int `json:"conversationMessageMaxSize,omitempty"`
// The maximum message size that can be sent to chatbot in a request.
ChatbotMessageMaxSize int `json:"chatbotMessageMaxSize,omitempty"`
// The flow control fo chatbot.
ChatBotThrottle *Throttle `json:"chatBotThrottle,omitempty"`
// The flow control fo conversation.
ConversationThrottle *Throttle `json:"conversationThrottle,omitempty"`
}
type Options struct {
Global *GlobalOptions `json:"global,omitempty"`
Email *EmailOptions `json:"email,omitempty"`
Wechat *WechatOptions `json:"wechat,omitempty"`
Slack *SlackOptions `json:"slack,omitempty"`
Webhook *WebhookOptions `json:"webhook,omitempty"`
DingTalk *DingTalkOptions `json:"dingtalk,omitempty"`
}
// NotificationManagerStatus defines the observed state of NotificationManager
type NotificationManagerStatus struct {
}
// +kubebuilder:object:root=true
// +kubebuilder:resource:scope=Cluster,shortName=nm
// NotificationManager is the Schema for the notificationmanagers API
type NotificationManager struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec NotificationManagerSpec `json:"spec,omitempty"`
Status NotificationManagerStatus `json:"status,omitempty"`
}
// +kubebuilder:object:root=true
// NotificationManagerList contains a list of NotificationManager
type NotificationManagerList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []NotificationManager `json:"items"`
}
func init() {
SchemeBuilder.Register(&NotificationManager{}, &NotificationManagerList{})
}

View File

@@ -0,0 +1,41 @@
/*
Copyright 2020 The KubeSphere Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// NOTE: Boilerplate only. Ignore this file.
// Package v1alpha1 contains API Schema definitions for the notification v2 API group
// +k8s:deepcopy-gen=package,register
// +groupName=notification.kubesphere.io
package v2
import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/runtime/scheme"
)
var (
// SchemeGroupVersion is group version used to register these objects
SchemeGroupVersion = schema.GroupVersion{Group: "notification.kubesphere.io", Version: "v2"}
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion}
AddToScheme = SchemeBuilder.AddToScheme
)
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}

View File

@@ -0,0 +1,57 @@
/*
Copyright 2020 The KubeSphere Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package v2
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// SlackConfigSpec defines the desired state of SlackConfig
type SlackConfigSpec struct {
// The token of user or bot.
SlackTokenSecret *SecretKeySelector `json:"slackTokenSecret,omitempty"`
}
// SlackConfigStatus defines the observed state of SlackConfig
type SlackConfigStatus struct {
}
// +kubebuilder:object:root=true
// +kubebuilder:resource:scope=Cluster,shortName=sc
// +genclient
// +genclient:nonNamespaced
// SlackConfig is the Schema for the slackconfigs API
type SlackConfig struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec SlackConfigSpec `json:"spec,omitempty"`
Status SlackConfigStatus `json:"status,omitempty"`
}
// +kubebuilder:object:root=true
// SlackConfigList contains a list of SlackConfig
type SlackConfigList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []SlackConfig `json:"items"`
}
func init() {
SchemeBuilder.Register(&SlackConfig{}, &SlackConfigList{})
}

View File

@@ -0,0 +1,61 @@
/*
Copyright 2020 The KubeSphere Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package v2
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// SlackReceiverSpec defines the desired state of SlackReceiver
type SlackReceiverSpec struct {
// SlackConfig to be selected for this receiver
SlackConfigSelector *metav1.LabelSelector `json:"slackConfigSelector,omitempty"`
// Selector to filter alerts.
AlertSelector *metav1.LabelSelector `json:"alertSelector,omitempty"`
// The channel or user to send notifications to.
Channel string `json:"channel"`
}
// SlackReceiverStatus defines the observed state of SlackReceiver
type SlackReceiverStatus struct {
}
// +kubebuilder:object:root=true
// +kubebuilder:resource:scope=Cluster,shortName=sr
// +genclient
// +genclient:nonNamespaced
// SlackReceiver is the Schema for the slackreceivers API
type SlackReceiver struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec SlackReceiverSpec `json:"spec,omitempty"`
Status SlackReceiverStatus `json:"status,omitempty"`
}
// +kubebuilder:object:root=true
// SlackReceiverList contains a list of SlackReceiver
type SlackReceiverList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []SlackReceiver `json:"items"`
}
func init() {
SchemeBuilder.Register(&SlackReceiver{}, &SlackReceiverList{})
}

View File

@@ -0,0 +1,41 @@
/*
Copyright 2020 The KubeSphere Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package v2
const (
ResourcesPluralDingTalkConfig = "dingtalkconfigs"
ResourcesPluralDingTalkReceiver = "dingtalkreceivers"
ResourcesPluralEmailConfig = "emailconfigs"
ResourcesPluralEmailReceiver = "emailreceivers"
ResourcesPluralSlackConfig = "slackconfigs"
ResourcesPluralSlackReceiver = "slackreceivers"
ResourcesPluralWebhookConfig = "webhookconfigs"
ResourcesPluralWebhookReceiver = "webhookreceivers"
ResourcesPluralWechatConfig = "wechatconfigs"
ResourcesPluralWechatReceiver = "wechatreceivers"
ResourcesSingularDingTalkConfig = "dingtalkconfig"
ResourcesSingularDingTalkReceiver = "dingtalkreceiver"
ResourcesSingularEmailConfig = "emailconfig"
ResourcesSingularEmailReceiver = "emailreceiver"
ResourcesSingularSlackConfig = "slackconfig"
ResourcesSingularSlackReceiver = "slackreceiver"
ResourcesSingularWebhookConfig = "webhookconfig"
ResourcesSingularWebhookReceiver = "webhookreceiver"
ResourcesSingularWechatConfig = "wechatconfig"
ResourcesSingularWechatReceiver = "wechatreceiver"
)

View File

@@ -0,0 +1,54 @@
/*
Copyright 2020 The KubeSphere Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package v2
import (
"log"
"os"
"path/filepath"
"testing"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/envtest"
)
var cfg *rest.Config
func TestMain(m *testing.M) {
t := &envtest.Environment{
CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "..", "config", "crds")},
}
err := SchemeBuilder.AddToScheme(scheme.Scheme)
if err != nil {
log.Fatal(err)
}
if cfg, err = t.Start(); err != nil {
log.Fatal(err)
}
if _, err = client.New(cfg, client.Options{Scheme: scheme.Scheme}); err != nil {
log.Fatal(err)
}
code := m.Run()
_ = t.Stop()
os.Exit(code)
}

View File

@@ -0,0 +1,55 @@
/*
Copyright 2020 The KubeSphere Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package v2
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// WebhookConfigSpec defines the desired state of WebhookConfig
type WebhookConfigSpec struct {
}
// WebhookConfigStatus defines the observed state of WebhookConfig
type WebhookConfigStatus struct {
}
// +kubebuilder:object:root=true
// +kubebuilder:resource:scope=Cluster,shortName=wc
// +genclient
// +genclient:nonNamespaced
// WebhookConfig is the Schema for the webhookconfigs API
type WebhookConfig struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec WebhookConfigSpec `json:"spec,omitempty"`
Status WebhookConfigStatus `json:"status,omitempty"`
}
// +kubebuilder:object:root=true
// WebhookConfigList contains a list of WebhookConfig
type WebhookConfigList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []WebhookConfig `json:"items"`
}
func init() {
SchemeBuilder.Register(&WebhookConfig{}, &WebhookConfigList{})
}

View File

@@ -0,0 +1,159 @@
/*
Copyright 2020 The KubeSphere Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package v2
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
type ClientCertificate struct {
// The client cert file for the targets.
Cert *SecretKeySelector `json:"cert,omitempty"`
// The client key file for the targets.
Key *SecretKeySelector `json:"key,omitempty"`
}
// TLSConfig configures the options for TLS connections.
type TLSConfig struct {
// RootCA defines the root certificate authorities
// that clients use when verifying server certificates.
RootCA *SecretKeySelector `json:"rootCA,omitempty"`
// The certificate of the client.
*ClientCertificate `json:"clientCertificate,omitempty"`
// Used to verify the hostname for the targets.
ServerName string `json:"serverName,omitempty"`
// Disable target certificate validation.
InsecureSkipVerify bool `json:"insecureSkipVerify,omitempty"`
}
// BasicAuth contains basic HTTP authentication credentials.
type BasicAuth struct {
Username string `json:"username"`
Password *SecretKeySelector `json:"password,omitempty"`
}
// HTTPClientConfig configures an HTTP client.
type HTTPClientConfig struct {
// The HTTP basic authentication credentials for the targets.
BasicAuth *BasicAuth `json:"basicAuth,omitempty"`
// The bearer token for the targets.
BearerToken *SecretKeySelector `json:"bearerToken,omitempty"`
// HTTP proxy server to use to connect to the targets.
ProxyURL string `json:"proxyUrl,omitempty"`
// TLSConfig to use to connect to the targets.
TLSConfig *TLSConfig `json:"tlsConfig,omitempty"`
}
// ServiceReference holds a reference to Service.legacy.k8s.io
type ServiceReference struct {
// `namespace` is the namespace of the service.
// Required
Namespace string `json:"namespace"`
// `name` is the name of the service.
// Required
Name string `json:"name"`
// `path` is an optional URL path which will be sent in any request to
// this service.
// +optional
Path *string `json:"path,omitempty"`
// If specified, the port on the service that hosting webhook.
// Default to 443 for backward compatibility.
// `port` should be a valid port number (1-65535, inclusive).
// +optional
Port *int32 `json:"port,omitempty"`
// Http scheme, default is http.
// +optional
Scheme *string `json:"scheme,omitempty"`
}
// WebhookReceiverSpec defines the desired state of WebhookReceiver
type WebhookReceiverSpec struct {
// WebhookConfig to be selected for this receiver
WebhookConfigSelector *metav1.LabelSelector `json:"webhookConfigSelector,omitempty"`
// Selector to filter alerts.
AlertSelector *metav1.LabelSelector `json:"alertSelector,omitempty"`
// `url` gives the location of the webhook, in standard URL form
// (`scheme://host:port/path`). Exactly one of `url` or `service`
// must be specified.
//
// The `host` should not refer to a service running in the cluster; use
// the `service` field instead. The host might be resolved via external
// DNS in some api servers (e.g., `kube-apiserver` cannot resolve
// in-cluster DNS as that would be a layering violation). `host` may
// also be an IP address.
//
// Please note that using `localhost` or `127.0.0.1` as a `host` is
// risky unless you take great care to run this webhook on all hosts
// which run an apiserver which might need to make calls to this
// webhook. Such installs are likely to be non-portable, i.e., not easy
// to turn up in a new cluster.
//
// A path is optional, and if present may be any string permissible in
// a URL. You may use the path to pass an arbitrary string to the
// webhook, for example, a cluster identifier.
//
// Attempting to use a user or basic auth e.g. "user:password@" is not
// allowed. Fragments ("#...") and query parameters ("?...") are not
// allowed, either.
//
// +optional
URL *string `json:"url,omitempty"`
// `service` is a reference to the service for this webhook. Either
// `service` or `url` must be specified.
//
// If the webhook is running within the cluster, then you should use `service`.
//
// +optional
Service *ServiceReference `json:"service,omitempty"`
HTTPConfig *HTTPClientConfig `json:"httpConfig,omitempty"`
}
// WebhookReceiverStatus defines the observed state of WebhookReceiver
type WebhookReceiverStatus struct {
}
// +kubebuilder:object:root=true
// +kubebuilder:resource:scope=Cluster,shortName=wr
// +genclient
// +genclient:nonNamespaced
// WebhookReceiver is the Schema for the webhookreceivers API
type WebhookReceiver struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec WebhookReceiverSpec `json:"spec,omitempty"`
Status WebhookReceiverStatus `json:"status,omitempty"`
}
// +kubebuilder:object:root=true
// WebhookReceiverList contains a list of WebhookReceiver
type WebhookReceiverList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []WebhookReceiver `json:"items"`
}
func init() {
SchemeBuilder.Register(&WebhookReceiver{}, &WebhookReceiverList{})
}

View File

@@ -0,0 +1,63 @@
/*
Copyright 2020 The KubeSphere Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package v2
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// WechatConfigSpec defines the desired state of WechatConfig
type WechatConfigSpec struct {
// The WeChat API URL.
WechatApiUrl string `json:"wechatApiUrl,omitempty"`
// The corp id for authentication.
WechatApiCorpId string `json:"wechatApiCorpId"`
// The id of the application which sending message.
WechatApiAgentId string `json:"wechatApiAgentId"`
// The API key to use when talking to the WeChat API.
WechatApiSecret *SecretKeySelector `json:"wechatApiSecret"`
}
// WechatConfigStatus defines the observed state of WechatConfig
type WechatConfigStatus struct {
}
// +kubebuilder:object:root=true
// +kubebuilder:resource:scope=Cluster,shortName=wcc
// +genclient
// +genclient:nonNamespaced
// WechatConfig is the Schema for the wechatconfigs API
type WechatConfig struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec WechatConfigSpec `json:"spec,omitempty"`
Status WechatConfigStatus `json:"status,omitempty"`
}
// +kubebuilder:object:root=true
// WechatConfigList contains a list of WechatConfig
type WechatConfigList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []WechatConfig `json:"items"`
}
func init() {
SchemeBuilder.Register(&WechatConfig{}, &WechatConfigList{})
}

View File

@@ -0,0 +1,63 @@
/*
Copyright 2020 The KubeSphere Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package v2
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// WechatReceiverSpec defines the desired state of WechatReceiver
type WechatReceiverSpec struct {
// WechatConfig to be selected for this receiver
WechatConfigSelector *metav1.LabelSelector `json:"wechatConfigSelector,omitempty"`
// Selector to filter alerts.
AlertSelector *metav1.LabelSelector `json:"alertSelector,omitempty"`
// +optional
ToUser string `json:"toUser,omitempty"`
ToParty string `json:"toParty,omitempty"`
ToTag string `json:"toTag,omitempty"`
}
// WechatReceiverStatus defines the observed state of WechatReceiver
type WechatReceiverStatus struct {
}
// +kubebuilder:object:root=true
// +kubebuilder:resource:scope=Cluster,shortName=wcr
// +genclient
// +genclient:nonNamespaced
// WechatReceiver is the Schema for the wechatreceivers API
type WechatReceiver struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec WechatReceiverSpec `json:"spec,omitempty"`
Status WechatReceiverStatus `json:"status,omitempty"`
}
// +kubebuilder:object:root=true
// WechatReceiverList contains a list of WechatReceiver
type WechatReceiverList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []WechatReceiver `json:"items"`
}
func init() {
SchemeBuilder.Register(&WechatReceiver{}, &WechatReceiverList{})
}

File diff suppressed because it is too large Load Diff