Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
KubeSphere
kubesphere
提交
d4a8f9bf
K
kubesphere
项目概览
KubeSphere
/
kubesphere
通知
144
Star
32
Fork
5
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
2
Wiki
分析
仓库
DevOps
项目成员
Pages
K
kubesphere
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
2
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d4a8f9bf
编写于
2月 23, 2021
作者:
W
wanjunlei
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
resolve conversation
Signed-off-by:
N
wanjunlei
<
wanjunlei@yunify.com
>
上级
f9213fcd
变更
17
隐藏空白更改
内联
并排
Showing
17 changed file
with
61 addition
and
52 deletion
+61
-52
pkg/apis/notification/v2/dingtalkconfig_types.go
pkg/apis/notification/v2/dingtalkconfig_types.go
+1
-0
pkg/apis/notification/v2/dingtalkreceiver_types.go
pkg/apis/notification/v2/dingtalkreceiver_types.go
+1
-0
pkg/apis/notification/v2/emailconfig_types.go
pkg/apis/notification/v2/emailconfig_types.go
+1
-0
pkg/apis/notification/v2/emailreceiver_types.go
pkg/apis/notification/v2/emailreceiver_types.go
+1
-0
pkg/apis/notification/v2/notificationmanager_types.go
pkg/apis/notification/v2/notificationmanager_types.go
+1
-0
pkg/apis/notification/v2/slackconfig_types.go
pkg/apis/notification/v2/slackconfig_types.go
+1
-0
pkg/apis/notification/v2/slackreceiver_types.go
pkg/apis/notification/v2/slackreceiver_types.go
+1
-0
pkg/apis/notification/v2/webhookconfig_types.go
pkg/apis/notification/v2/webhookconfig_types.go
+1
-0
pkg/apis/notification/v2/webhookreceiver_types.go
pkg/apis/notification/v2/webhookreceiver_types.go
+1
-0
pkg/apis/notification/v2/wechatconfig_types.go
pkg/apis/notification/v2/wechatconfig_types.go
+1
-0
pkg/apis/notification/v2/wechatreceiver_types.go
pkg/apis/notification/v2/wechatreceiver_types.go
+1
-0
pkg/constants/constants.go
pkg/constants/constants.go
+3
-3
pkg/controller/notification/notification_controller.go
pkg/controller/notification/notification_controller.go
+5
-5
pkg/controller/notification/notification_controller_test.go
pkg/controller/notification/notification_controller_test.go
+7
-7
pkg/kapis/notification/v2/register.go
pkg/kapis/notification/v2/register.go
+17
-16
pkg/models/notification/notification.go
pkg/models/notification/notification.go
+14
-17
pkg/models/notification/notification_test.go
pkg/models/notification/notification_test.go
+4
-4
未找到文件。
pkg/apis/notification/v2/dingtalkconfig_types.go
浏览文件 @
d4a8f9bf
...
...
@@ -40,6 +40,7 @@ type DingTalkConfigStatus struct {
// +kubebuilder:object:root=true
// +kubebuilder:resource:scope=Cluster,shortName=dc
// +kubebuilder:subresource:status
// +genclient
// +genclient:nonNamespaced
// DingTalkConfig is the Schema for the dingtalkconfigs API
...
...
pkg/apis/notification/v2/dingtalkreceiver_types.go
浏览文件 @
d4a8f9bf
...
...
@@ -55,6 +55,7 @@ type DingTalkReceiverStatus struct {
// +kubebuilder:object:root=true
// +kubebuilder:resource:scope=Cluster,shortName=dr
// +kubebuilder:subresource:status
// +genclient
// +genclient:nonNamespaced
// DingTalkReceiver is the Schema for the dingtalkreceivers API
...
...
pkg/apis/notification/v2/emailconfig_types.go
浏览文件 @
d4a8f9bf
...
...
@@ -52,6 +52,7 @@ type EmailConfigStatus struct {
// +kubebuilder:object:root=true
// +kubebuilder:resource:scope=Cluster,shortName=ec
// +kubebuilder:subresource:status
// +genclient
// +genclient:nonNamespaced
// EmailConfig is the Schema for the emailconfigs API
...
...
pkg/apis/notification/v2/emailreceiver_types.go
浏览文件 @
d4a8f9bf
...
...
@@ -36,6 +36,7 @@ type EmailReceiverStatus struct {
// +kubebuilder:object:root=true
// +kubebuilder:resource:scope=Cluster,shortName=er
// +kubebuilder:subresource:status
// +genclient
// +genclient:nonNamespaced
// EmailReceiver is the Schema for the emailreceivers API
...
...
pkg/apis/notification/v2/notificationmanager_types.go
浏览文件 @
d4a8f9bf
...
...
@@ -186,6 +186,7 @@ type NotificationManagerStatus struct {
// +kubebuilder:object:root=true
// +kubebuilder:resource:scope=Cluster,shortName=nm
// +kubebuilder:subresource:status
// NotificationManager is the Schema for the notificationmanagers API
type
NotificationManager
struct
{
...
...
pkg/apis/notification/v2/slackconfig_types.go
浏览文件 @
d4a8f9bf
...
...
@@ -32,6 +32,7 @@ type SlackConfigStatus struct {
// +kubebuilder:object:root=true
// +kubebuilder:resource:scope=Cluster,shortName=sc
// +kubebuilder:subresource:status
// +genclient
// +genclient:nonNamespaced
// SlackConfig is the Schema for the slackconfigs API
...
...
pkg/apis/notification/v2/slackreceiver_types.go
浏览文件 @
d4a8f9bf
...
...
@@ -36,6 +36,7 @@ type SlackReceiverStatus struct {
// +kubebuilder:object:root=true
// +kubebuilder:resource:scope=Cluster,shortName=sr
// +kubebuilder:subresource:status
// +genclient
// +genclient:nonNamespaced
// SlackReceiver is the Schema for the slackreceivers API
...
...
pkg/apis/notification/v2/webhookconfig_types.go
浏览文件 @
d4a8f9bf
...
...
@@ -30,6 +30,7 @@ type WebhookConfigStatus struct {
// +kubebuilder:object:root=true
// +kubebuilder:resource:scope=Cluster,shortName=wc
// +kubebuilder:subresource:status
// +genclient
// +genclient:nonNamespaced
// WebhookConfig is the Schema for the webhookconfigs API
...
...
pkg/apis/notification/v2/webhookreceiver_types.go
浏览文件 @
d4a8f9bf
...
...
@@ -134,6 +134,7 @@ type WebhookReceiverStatus struct {
// +kubebuilder:object:root=true
// +kubebuilder:resource:scope=Cluster,shortName=wr
// +kubebuilder:subresource:status
// +genclient
// +genclient:nonNamespaced
// WebhookReceiver is the Schema for the webhookreceivers API
...
...
pkg/apis/notification/v2/wechatconfig_types.go
浏览文件 @
d4a8f9bf
...
...
@@ -38,6 +38,7 @@ type WechatConfigStatus struct {
// +kubebuilder:object:root=true
// +kubebuilder:resource:scope=Cluster,shortName=wcc
// +kubebuilder:subresource:status
// +genclient
// +genclient:nonNamespaced
// WechatConfig is the Schema for the wechatconfigs API
...
...
pkg/apis/notification/v2/wechatreceiver_types.go
浏览文件 @
d4a8f9bf
...
...
@@ -38,6 +38,7 @@ type WechatReceiverStatus struct {
// +kubebuilder:object:root=true
// +kubebuilder:resource:scope=Cluster,shortName=wcr
// +kubebuilder:subresource:status
// +genclient
// +genclient:nonNamespaced
// WechatReceiver is the Schema for the wechatreceivers API
...
...
pkg/constants/constants.go
浏览文件 @
d4a8f9bf
...
...
@@ -126,9 +126,9 @@ const (
ApplicationVersion
=
"app.kubernetes.io/version"
AlertingTag
=
"Alerting"
NotificationTag
=
"Notification"
KubeSphereNotificationNamespace
=
"kubesphere-notification-system
"
NotificationManagedLabel
=
"notification-manager/managed"
NotificationTag
=
"Notification"
NotificationSecretNamespace
=
"kubesphere-monitoring-federated
"
NotificationManagedLabel
=
"notification-manager/managed"
)
var
(
...
...
pkg/controller/notification/notification_controller.go
浏览文件 @
d4a8f9bf
...
...
@@ -222,7 +222,7 @@ func (c *Controller) reconcile(obj interface{}) error {
// Only reconcile the secret which created by notification manager.
if
secret
,
ok
:=
obj
.
(
*
corev1
.
Secret
);
ok
{
if
secret
.
Namespace
!=
constants
.
KubeSphereNotification
Namespace
||
secret
.
Labels
[
constants
.
NotificationManagedLabel
]
!=
"true"
{
if
secret
.
Namespace
!=
constants
.
NotificationSecret
Namespace
||
secret
.
Labels
[
constants
.
NotificationManagedLabel
]
!=
"true"
{
klog
.
V
(
8
)
.
Infof
(
"No need to reconcile secret %s/%s"
,
accessor
.
GetNamespace
(),
accessor
.
GetName
())
return
nil
}
...
...
@@ -919,12 +919,12 @@ func (c *Controller) syncFederatedSecret(obj *corev1.Secret) error {
func
(
c
*
Controller
)
ensureNotificationNamespaceExist
()
error
{
ns
:=
corev1
.
Namespace
{}
if
err
:=
c
.
Get
(
context
.
Background
(),
client
.
ObjectKey
{
Name
:
constants
.
KubeSphereNotification
Namespace
},
&
ns
);
err
!=
nil
{
if
err
:=
c
.
Get
(
context
.
Background
(),
client
.
ObjectKey
{
Name
:
constants
.
NotificationSecret
Namespace
},
&
ns
);
err
!=
nil
{
return
err
}
fedNs
:=
v1beta1
.
FederatedNamespace
{}
if
err
:=
c
.
Get
(
context
.
Background
(),
client
.
ObjectKey
{
Name
:
constants
.
KubeSphereNotificationNamespace
,
Namespace
:
constants
.
KubeSphereNotification
Namespace
},
&
fedNs
);
err
!=
nil
{
if
err
:=
c
.
Get
(
context
.
Background
(),
client
.
ObjectKey
{
Name
:
constants
.
NotificationSecretNamespace
,
Namespace
:
constants
.
NotificationSecret
Namespace
},
&
fedNs
);
err
!=
nil
{
if
errors
.
IsAlreadyExists
(
err
)
{
return
nil
}
...
...
@@ -936,8 +936,8 @@ func (c *Controller) ensureNotificationNamespaceExist() error {
APIVersion
:
v1beta1
.
SchemeGroupVersion
.
String
(),
},
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
constants
.
KubeSphereNotification
Namespace
,
Namespace
:
constants
.
KubeSphereNotification
Namespace
,
Name
:
constants
.
NotificationSecret
Namespace
,
Namespace
:
constants
.
NotificationSecret
Namespace
,
},
Spec
:
v1beta1
.
FederatedNamespaceSpec
{
Placement
:
v1beta1
.
GenericPlacementFields
{
...
...
pkg/controller/notification/notification_controller_test.go
浏览文件 @
d4a8f9bf
...
...
@@ -39,14 +39,14 @@ var (
namespace
:=
&
corev1
.
Namespace
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
constants
.
KubeSphereNotification
Namespace
,
Name
:
constants
.
NotificationSecret
Namespace
,
},
}
secret
:=
&
corev1
.
Secret
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"foo"
,
Namespace
:
constants
.
KubeSphereNotification
Namespace
,
Namespace
:
constants
.
NotificationSecret
Namespace
,
Labels
:
map
[
string
]
string
{
constants
.
NotificationManagedLabel
:
"true"
},
},
}
...
...
@@ -101,12 +101,12 @@ var (
fedSecret
:=
&
v1beta1
.
FederatedSecret
{}
By
(
"Expecting to create federated secret successfully"
)
Eventually
(
func
()
bool
{
err
:=
ksCache
.
Get
(
context
.
Background
(),
client
.
ObjectKey
{
Name
:
secret
.
Name
,
Namespace
:
constants
.
KubeSphereNotification
Namespace
},
fedSecret
)
err
:=
ksCache
.
Get
(
context
.
Background
(),
client
.
ObjectKey
{
Name
:
secret
.
Name
,
Namespace
:
constants
.
NotificationSecret
Namespace
},
fedSecret
)
Expect
(
err
)
.
Should
(
Succeed
())
return
!
fedSecret
.
CreationTimestamp
.
IsZero
()
},
timeout
,
interval
)
.
Should
(
BeTrue
())
err
:=
ksCache
.
Get
(
context
.
Background
(),
client
.
ObjectKey
{
Name
:
secret
.
Name
,
Namespace
:
constants
.
KubeSphereNotification
Namespace
},
secret
)
err
:=
ksCache
.
Get
(
context
.
Background
(),
client
.
ObjectKey
{
Name
:
secret
.
Name
,
Namespace
:
constants
.
NotificationSecret
Namespace
},
secret
)
Expect
(
err
)
.
Should
(
Succeed
())
secret
.
StringData
=
map
[
string
]
string
{
"foo"
:
"bar"
}
Expect
(
cl
.
Update
(
context
.
Background
(),
secret
))
.
Should
(
Succeed
())
...
...
@@ -114,7 +114,7 @@ var (
By
(
"Expecting to update federated secret successfully"
)
Eventually
(
func
()
bool
{
err
:=
ksCache
.
Get
(
context
.
Background
(),
client
.
ObjectKey
{
Name
:
secret
.
Name
,
Namespace
:
constants
.
KubeSphereNotification
Namespace
},
fedSecret
)
err
:=
ksCache
.
Get
(
context
.
Background
(),
client
.
ObjectKey
{
Name
:
secret
.
Name
,
Namespace
:
constants
.
NotificationSecret
Namespace
},
fedSecret
)
Expect
(
err
)
.
Should
(
Succeed
())
return
string
(
fedSecret
.
Spec
.
Template
.
Data
[
"foo"
])
==
"bar"
},
timeout
,
interval
)
.
Should
(
BeTrue
())
...
...
@@ -130,9 +130,9 @@ var (
obj
:=
&
v2
.
DingTalkConfig
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"foo"
,
Namespace
:
constants
.
KubeSphereNotification
Namespace
,
Namespace
:
constants
.
NotificationSecret
Namespace
,
Labels
:
map
[
string
]
string
{
"ty
ep
"
:
"default"
,
"ty
pe
"
:
"default"
,
},
},
}
...
...
pkg/kapis/notification/v2/register.go
浏览文件 @
d4a8f9bf
...
...
@@ -55,8 +55,8 @@ func AddToContainer(
To
(
h
.
ListSecret
)
.
Doc
(
"list the secrets"
)
.
Metadata
(
KeyOpenAPITags
,
[]
string
{
constants
.
NotificationTag
})
.
Param
(
ws
.
QueryParameter
(
query
.
ParameterName
,
"name used
to do
filtering"
)
.
Required
(
false
))
.
Param
(
ws
.
QueryParameter
(
query
.
ParameterLabelSelector
,
"label selector used
to do
filtering"
)
.
Required
(
false
))
.
Param
(
ws
.
QueryParameter
(
query
.
ParameterName
,
"name used
for
filtering"
)
.
Required
(
false
))
.
Param
(
ws
.
QueryParameter
(
query
.
ParameterLabelSelector
,
"label selector used
for
filtering"
)
.
Required
(
false
))
.
Param
(
ws
.
QueryParameter
(
query
.
ParameterPage
,
"page"
)
.
Required
(
false
)
.
DataFormat
(
"page=%d"
)
.
DefaultValue
(
"page=1"
))
.
Param
(
ws
.
QueryParameter
(
query
.
ParameterLimit
,
"limit"
)
.
Required
(
false
))
.
Param
(
ws
.
QueryParameter
(
query
.
ParameterAscending
,
"sort parameters, e.g. ascending=false"
)
.
Required
(
false
)
.
DefaultValue
(
"ascending=false"
))
.
...
...
@@ -93,11 +93,11 @@ func AddToContainer(
// apis for global notification config and receiver
ws
.
Route
(
ws
.
GET
(
"/{resources}"
)
.
To
(
h
.
ListResource
)
.
Doc
(
"list the notification config
or receiver
"
)
.
Doc
(
"list the notification config
s or receivers
"
)
.
Metadata
(
KeyOpenAPITags
,
[]
string
{
constants
.
NotificationTag
})
.
Param
(
ws
.
PathParameter
(
"resources"
,
"notification config
or receiver, known values ar
e dingtalkconfigs, dingtalkreceivers, emailconfigs. emailreceivers, slackconfigs, slackreceivers, webhookconfigs, webhookreceivers, wechatconfigs, wechatreceivers"
))
.
Param
(
ws
.
QueryParameter
(
query
.
ParameterName
,
"name used
to do
filtering"
)
.
Required
(
false
))
.
Param
(
ws
.
QueryParameter
(
query
.
ParameterLabelSelector
,
"label selector used
to do
filtering"
)
.
Required
(
false
))
.
Param
(
ws
.
PathParameter
(
"resources"
,
"notification config
s or receivers, known values includ
e dingtalkconfigs, dingtalkreceivers, emailconfigs. emailreceivers, slackconfigs, slackreceivers, webhookconfigs, webhookreceivers, wechatconfigs, wechatreceivers"
))
.
Param
(
ws
.
QueryParameter
(
query
.
ParameterName
,
"name used
for
filtering"
)
.
Required
(
false
))
.
Param
(
ws
.
QueryParameter
(
query
.
ParameterLabelSelector
,
"label selector used
for
filtering"
)
.
Required
(
false
))
.
Param
(
ws
.
QueryParameter
(
query
.
ParameterPage
,
"page"
)
.
Required
(
false
)
.
DataFormat
(
"page=%d"
)
.
DefaultValue
(
"page=1"
))
.
Param
(
ws
.
QueryParameter
(
query
.
ParameterLimit
,
"limit"
)
.
Required
(
false
))
.
Param
(
ws
.
QueryParameter
(
query
.
ParameterAscending
,
"sort parameters, e.g. ascending=false"
)
.
Required
(
false
)
.
DefaultValue
(
"ascending=false"
))
.
...
...
@@ -108,7 +108,7 @@ func AddToContainer(
To
(
h
.
GetResource
)
.
Doc
(
"get the specified notification config or receiver"
)
.
Metadata
(
KeyOpenAPITags
,
[]
string
{
constants
.
NotificationTag
})
.
Param
(
ws
.
PathParameter
(
"resources"
,
"notification config
or receiver, known values ar
e dingtalkconfigs, dingtalkreceivers, emailconfigs. emailreceivers, slackconfigs, slackreceivers, webhookconfigs, webhookreceivers, wechatconfigs, wechatreceivers"
))
.
Param
(
ws
.
PathParameter
(
"resources"
,
"notification config
s or receivers, known values includ
e dingtalkconfigs, dingtalkreceivers, emailconfigs. emailreceivers, slackconfigs, slackreceivers, webhookconfigs, webhookreceivers, wechatconfigs, wechatreceivers"
))
.
Param
(
ws
.
PathParameter
(
"name"
,
"the name of the resource"
))
.
Returns
(
http
.
StatusOK
,
api
.
StatusOK
,
nil
))
...
...
@@ -116,14 +116,14 @@ func AddToContainer(
To
(
h
.
CreateResource
)
.
Doc
(
"create a notification config or receiver"
)
.
Metadata
(
KeyOpenAPITags
,
[]
string
{
constants
.
NotificationTag
})
.
Param
(
ws
.
PathParameter
(
"resource"
,
"notification config
or receiver, known values ar
e dingtalkconfigs, dingtalkreceivers, emailconfigs. emailreceivers, slackconfigs, slackreceivers, webhookconfigs, webhookreceivers, wechatconfigs, wechatreceivers"
))
.
Param
(
ws
.
PathParameter
(
"resource"
,
"notification config
s or receivers, known values includ
e dingtalkconfigs, dingtalkreceivers, emailconfigs. emailreceivers, slackconfigs, slackreceivers, webhookconfigs, webhookreceivers, wechatconfigs, wechatreceivers"
))
.
Returns
(
http
.
StatusOK
,
api
.
StatusOK
,
nil
))
ws
.
Route
(
ws
.
PUT
(
"/{resources}/{name}"
)
.
To
(
h
.
UpdateResource
)
.
Doc
(
"update the specified notification config or receiver"
)
.
Metadata
(
KeyOpenAPITags
,
[]
string
{
constants
.
NotificationTag
})
.
Param
(
ws
.
PathParameter
(
"resources"
,
"notification config
or receiver, known values ar
e dingtalkconfigs, dingtalkreceivers, emailconfigs. emailreceivers, slackconfigs, slackreceivers, webhookconfigs, webhookreceivers, wechatconfigs, wechatreceivers"
))
.
Param
(
ws
.
PathParameter
(
"resources"
,
"notification config
s or receivers, known values includ
e dingtalkconfigs, dingtalkreceivers, emailconfigs. emailreceivers, slackconfigs, slackreceivers, webhookconfigs, webhookreceivers, wechatconfigs, wechatreceivers"
))
.
Param
(
ws
.
PathParameter
(
"name"
,
"the name of the resource"
))
.
Returns
(
http
.
StatusOK
,
api
.
StatusOK
,
nil
))
...
...
@@ -131,18 +131,19 @@ func AddToContainer(
To
(
h
.
DeleteResource
)
.
Doc
(
"delete the specified notification config or receiver"
)
.
Metadata
(
KeyOpenAPITags
,
[]
string
{
constants
.
NotificationTag
})
.
Param
(
ws
.
PathParameter
(
"resources"
,
"notification config
or receiver, known values ar
e dingtalkconfigs, dingtalkreceivers, emailconfigs. emailreceivers, slackconfigs, slackreceivers, webhookconfigs, webhookreceivers, wechatconfigs, wechatreceivers"
))
.
Param
(
ws
.
PathParameter
(
"resources"
,
"notification config
s or receivers, known values includ
e dingtalkconfigs, dingtalkreceivers, emailconfigs. emailreceivers, slackconfigs, slackreceivers, webhookconfigs, webhookreceivers, wechatconfigs, wechatreceivers"
))
.
Param
(
ws
.
PathParameter
(
"name"
,
"the name of the resource"
))
.
Returns
(
http
.
StatusOK
,
api
.
StatusOK
,
errors
.
None
))
// apis for tenant notification config and receiver
ws
.
Route
(
ws
.
GET
(
"/users/{user}/{resources}"
)
.
To
(
h
.
ListResource
)
.
Doc
(
"list the notification config
or receiver
"
)
.
Doc
(
"list the notification config
s or receivers
"
)
.
Metadata
(
KeyOpenAPITags
,
[]
string
{
constants
.
NotificationTag
})
.
Param
(
ws
.
PathParameter
(
"user"
,
"user name"
))
.
Param
(
ws
.
QueryParameter
(
query
.
ParameterName
,
"name used to do filtering"
)
.
Required
(
false
))
.
Param
(
ws
.
QueryParameter
(
query
.
ParameterLabelSelector
,
"label selector used to do filtering"
)
.
Required
(
false
))
.
Param
(
ws
.
PathParameter
(
"resources"
,
"notification configs or receivers, known values include dingtalkconfigs, dingtalkreceivers, emailconfigs. emailreceivers, slackconfigs, slackreceivers, webhookconfigs, webhookreceivers, wechatconfigs, wechatreceivers"
))
.
Param
(
ws
.
QueryParameter
(
query
.
ParameterName
,
"name used for filtering"
)
.
Required
(
false
))
.
Param
(
ws
.
QueryParameter
(
query
.
ParameterLabelSelector
,
"label selector used for filtering"
)
.
Required
(
false
))
.
Param
(
ws
.
QueryParameter
(
query
.
ParameterPage
,
"page"
)
.
Required
(
false
)
.
DataFormat
(
"page=%d"
)
.
DefaultValue
(
"page=1"
))
.
Param
(
ws
.
QueryParameter
(
query
.
ParameterLimit
,
"limit"
)
.
Required
(
false
))
.
Param
(
ws
.
QueryParameter
(
query
.
ParameterAscending
,
"sort parameters, e.g. ascending=false"
)
.
Required
(
false
)
.
DefaultValue
(
"ascending=false"
))
.
...
...
@@ -154,7 +155,7 @@ func AddToContainer(
Doc
(
"get the specified notification config or receiver"
)
.
Metadata
(
KeyOpenAPITags
,
[]
string
{
constants
.
NotificationTag
})
.
Param
(
ws
.
PathParameter
(
"user"
,
"user name"
))
.
Param
(
ws
.
PathParameter
(
"resources"
,
"notification config
or receiver, known values ar
e dingtalkconfigs, dingtalkreceivers, emailconfigs. emailreceivers, slackconfigs, slackreceivers, webhookconfigs, webhookreceivers, wechatconfigs, wechatreceivers"
))
.
Param
(
ws
.
PathParameter
(
"resources"
,
"notification config
s or receivers, known values includ
e dingtalkconfigs, dingtalkreceivers, emailconfigs. emailreceivers, slackconfigs, slackreceivers, webhookconfigs, webhookreceivers, wechatconfigs, wechatreceivers"
))
.
Param
(
ws
.
PathParameter
(
"name"
,
"the name of the resource"
))
.
Returns
(
http
.
StatusOK
,
api
.
StatusOK
,
nil
))
...
...
@@ -170,7 +171,7 @@ func AddToContainer(
Doc
(
"update the specified notification config or receiver"
)
.
Metadata
(
KeyOpenAPITags
,
[]
string
{
constants
.
NotificationTag
})
.
Param
(
ws
.
PathParameter
(
"user"
,
"user name"
))
.
Param
(
ws
.
PathParameter
(
"resources"
,
"notification config
or receiver, known values ar
e dingtalkconfigs, dingtalkreceivers, emailconfigs. emailreceivers, slackconfigs, slackreceivers, webhookconfigs, webhookreceivers, wechatconfigs, wechatreceivers"
))
.
Param
(
ws
.
PathParameter
(
"resources"
,
"notification config
s or receivers, known values includ
e dingtalkconfigs, dingtalkreceivers, emailconfigs. emailreceivers, slackconfigs, slackreceivers, webhookconfigs, webhookreceivers, wechatconfigs, wechatreceivers"
))
.
Param
(
ws
.
PathParameter
(
"name"
,
"the name of the resource"
))
.
Returns
(
http
.
StatusOK
,
api
.
StatusOK
,
nil
))
...
...
@@ -179,7 +180,7 @@ func AddToContainer(
Doc
(
"delete the specified notification config or receiver"
)
.
Metadata
(
KeyOpenAPITags
,
[]
string
{
constants
.
NotificationTag
})
.
Param
(
ws
.
PathParameter
(
"user"
,
"user name"
))
.
Param
(
ws
.
PathParameter
(
"resources"
,
"notification config or receiver, known values
ar
e dingtalkconfigs, dingtalkreceivers, emailconfigs. emailreceivers, slackconfigs, slackreceivers, webhookconfigs, webhookreceivers, wechatconfigs, wechatreceivers"
))
.
Param
(
ws
.
PathParameter
(
"resources"
,
"notification config or receiver, known values
includ
e dingtalkconfigs, dingtalkreceivers, emailconfigs. emailreceivers, slackconfigs, slackreceivers, webhookconfigs, webhookreceivers, wechatconfigs, wechatreceivers"
))
.
Param
(
ws
.
PathParameter
(
"name"
,
"the name of the resource"
))
.
Returns
(
http
.
StatusOK
,
api
.
StatusOK
,
errors
.
None
))
...
...
pkg/models/notification/notification.go
浏览文件 @
d4a8f9bf
...
...
@@ -55,9 +55,8 @@ func NewOperator(
}
}
// List objects, if the user is nil, it will return the global object.
// If the user it not nil, it will return tenant object which the tenant specified in the labels of object
// equal to this user.
// List objects. Only global objects will be returned if the user is nil.
// If the user is not nil, only tenant objects whose tenant label matches the user will be returned.
func
(
o
*
operator
)
List
(
user
,
resource
string
,
q
*
query
.
Query
)
(
*
api
.
ListResult
,
error
)
{
// If user is nil, it will list all global object.
...
...
@@ -86,8 +85,8 @@ func (o *operator) Get(user, resource, name string) (runtime.Object, error) {
return
obj
,
nil
}
// Create a
object, if the user is nil, it only can create a global object
.
//
If the user is not nil, it only can create a tenant object
.
// Create a
n object. A global object will be created if the user is nil
.
//
A tenant object will be created if the user is not nil
.
func
(
o
*
operator
)
Create
(
user
,
resource
string
,
obj
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
if
err
:=
authorizer
(
user
,
obj
);
err
!=
nil
{
...
...
@@ -120,9 +119,8 @@ func (o *operator) Create(user, resource string, obj runtime.Object) (runtime.Ob
}
}
// Delete a object, if the user is nil, it only can delete the global object.
// If the user is not nil, it only can delete the tenant object which the tenant
// specified in the labels of the object equal to this user.
// Delete an object. A global object will be deleted if the user is nil.
// If the user is not nil, a tenant object whose tenant label matches the user will be deleted.
func
(
o
*
operator
)
Delete
(
user
,
resource
,
name
string
)
error
{
if
obj
,
err
:=
o
.
Get
(
user
,
resource
,
name
);
err
!=
nil
{
...
...
@@ -159,9 +157,8 @@ func (o *operator) Delete(user, resource, name string) error {
}
}
// Update a object, if the user is nil, it only can update the global object.
// If the user is not nil, it only can delete the tenant object which the tenant
// specified in the labels of the object equal to this user.
// Update an object, only a global object will be updated if the user is nil.
// If the user is not nil, a tenant object whose tenant label matches the user will be updated.
func
(
o
*
operator
)
Update
(
user
,
resource
string
,
obj
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
name
,
err
:=
getName
(
obj
)
...
...
@@ -206,11 +203,11 @@ func (o *operator) Update(user, resource string, obj runtime.Object) (runtime.Ob
func
(
o
*
operator
)
ListSecret
(
q
*
query
.
Query
)
(
*
api
.
ListResult
,
error
)
{
appendManagedLabel
(
q
)
return
o
.
resourceGetter
.
List
(
"secrets"
,
constants
.
KubeSphereNotification
Namespace
,
q
)
return
o
.
resourceGetter
.
List
(
"secrets"
,
constants
.
NotificationSecret
Namespace
,
q
)
}
func
(
o
*
operator
)
GetSecret
(
name
string
)
(
interface
{},
error
)
{
obj
,
err
:=
o
.
resourceGetter
.
Get
(
"secrets"
,
constants
.
KubeSphereNotification
Namespace
,
name
)
obj
,
err
:=
o
.
resourceGetter
.
Get
(
"secrets"
,
constants
.
NotificationSecret
Namespace
,
name
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -225,15 +222,15 @@ func (o *operator) GetSecret(name string) (interface{}, error) {
func
(
o
*
operator
)
CreateOrUpdateSecret
(
obj
*
corev1
.
Secret
)
(
*
corev1
.
Secret
,
error
)
{
obj
.
Namespace
=
constants
.
KubeSphereNotification
Namespace
obj
.
Namespace
=
constants
.
NotificationSecret
Namespace
if
obj
.
Labels
==
nil
{
obj
.
Labels
=
make
(
map
[
string
]
string
)
}
obj
.
Labels
[
constants
.
NotificationManagedLabel
]
=
"true"
if
obj
.
ResourceVersion
==
""
{
return
o
.
k8sClient
.
CoreV1
()
.
Secrets
(
constants
.
KubeSphereNotification
Namespace
)
.
Create
(
context
.
Background
(),
obj
,
v1
.
CreateOptions
{})
return
o
.
k8sClient
.
CoreV1
()
.
Secrets
(
constants
.
NotificationSecret
Namespace
)
.
Create
(
context
.
Background
(),
obj
,
v1
.
CreateOptions
{})
}
else
{
return
o
.
k8sClient
.
CoreV1
()
.
Secrets
(
constants
.
KubeSphereNotification
Namespace
)
.
Update
(
context
.
Background
(),
obj
,
v1
.
UpdateOptions
{})
return
o
.
k8sClient
.
CoreV1
()
.
Secrets
(
constants
.
NotificationSecret
Namespace
)
.
Update
(
context
.
Background
(),
obj
,
v1
.
UpdateOptions
{})
}
}
...
...
@@ -243,7 +240,7 @@ func (o *operator) DeleteSecret(name string) error {
return
err
}
return
o
.
k8sClient
.
CoreV1
()
.
Secrets
(
constants
.
KubeSphereNotification
Namespace
)
.
Delete
(
context
.
Background
(),
name
,
v1
.
DeleteOptions
{})
return
o
.
k8sClient
.
CoreV1
()
.
Secrets
(
constants
.
NotificationSecret
Namespace
)
.
Delete
(
context
.
Background
(),
name
,
v1
.
DeleteOptions
{})
}
func
(
o
*
operator
)
GetObject
(
resource
string
)
runtime
.
Object
{
...
...
pkg/models/notification/notification_test.go
浏览文件 @
d4a8f9bf
...
...
@@ -109,7 +109,7 @@ func TestOperator_CreateOrUpdateSecret(t *testing.T) {
result
:
&
corev1
.
Secret
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"test"
,
Namespace
:
constants
.
KubeSphereNotification
Namespace
,
Namespace
:
constants
.
NotificationSecret
Namespace
,
Labels
:
map
[
string
]
string
{
constants
.
NotificationManagedLabel
:
"true"
},
},
},
...
...
@@ -168,7 +168,7 @@ var (
secret1
=
&
corev1
.
Secret
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"foo1"
,
Namespace
:
constants
.
KubeSphereNotification
Namespace
,
Namespace
:
constants
.
NotificationSecret
Namespace
,
Labels
:
map
[
string
]
string
{
constants
.
NotificationManagedLabel
:
"true"
},
},
}
...
...
@@ -176,7 +176,7 @@ var (
secret2
=
&
corev1
.
Secret
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"foo2"
,
Namespace
:
constants
.
KubeSphereNotification
Namespace
,
Namespace
:
constants
.
NotificationSecret
Namespace
,
Labels
:
map
[
string
]
string
{
constants
.
NotificationManagedLabel
:
"true"
},
},
}
...
...
@@ -184,7 +184,7 @@ var (
secret3
=
&
corev1
.
Secret
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"foo3"
,
Namespace
:
constants
.
KubeSphereNotification
Namespace
,
Namespace
:
constants
.
NotificationSecret
Namespace
,
Labels
:
map
[
string
]
string
{
constants
.
NotificationManagedLabel
:
"true"
},
},
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录