Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
KubeSphere
kubesphere
提交
8e28925d
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,发现更多精彩内容 >>
提交
8e28925d
编写于
3月 16, 2021
作者:
W
wanjunlei
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
change kubesphere-monitoring-federated to system namespace
Signed-off-by:
N
wanjunlei
<
wanjunlei@yunify.com
>
上级
3a79df0d
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
37 addition
and
63 deletion
+37
-63
pkg/constants/constants.go
pkg/constants/constants.go
+1
-0
pkg/controller/notification/notification_controller.go
pkg/controller/notification/notification_controller.go
+2
-49
pkg/models/notification/notification.go
pkg/models/notification/notification.go
+32
-12
pkg/models/notification/notification_test.go
pkg/models/notification/notification_test.go
+2
-2
未找到文件。
pkg/constants/constants.go
浏览文件 @
8e28925d
...
...
@@ -128,6 +128,7 @@ const (
NotificationTag
=
"Notification"
NotificationSecretNamespace
=
"kubesphere-monitoring-federated"
NotificationManagedLabel
=
"notification/managed"
)
var
(
...
...
pkg/controller/notification/notification_controller.go
浏览文件 @
8e28925d
...
...
@@ -214,14 +214,11 @@ 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
.
NotificationSecretNamespace
{
if
secret
.
Namespace
!=
constants
.
NotificationSecretNamespace
||
secret
.
Labels
==
nil
||
secret
.
Labels
[
constants
.
NotificationManagedLabel
]
!=
"true"
{
klog
.
V
(
8
)
.
Infof
(
"No need to reconcile secret %s/%s"
,
accessor
.
GetNamespace
(),
accessor
.
GetName
())
return
nil
}
if
err
:=
c
.
ensureNotificationNamespaceExist
();
err
!=
nil
{
return
err
}
}
name
:=
accessor
.
GetName
()
...
...
@@ -444,50 +441,6 @@ func (c *Controller) syncFederatedSecret(obj *corev1.Secret) error {
return
nil
}
func
(
c
*
Controller
)
ensureNotificationNamespaceExist
()
error
{
ns
:=
corev1
.
Namespace
{}
if
err
:=
c
.
Get
(
context
.
Background
(),
client
.
ObjectKey
{
Name
:
constants
.
NotificationSecretNamespace
},
&
ns
);
err
!=
nil
{
return
err
}
fedNs
:=
v1beta1
.
FederatedNamespace
{}
if
err
:=
c
.
Get
(
context
.
Background
(),
client
.
ObjectKey
{
Name
:
constants
.
NotificationSecretNamespace
,
Namespace
:
constants
.
NotificationSecretNamespace
},
&
fedNs
);
err
!=
nil
{
if
errors
.
IsAlreadyExists
(
err
)
{
return
nil
}
if
errors
.
IsNotFound
(
err
)
{
fedNs
=
v1beta1
.
FederatedNamespace
{
TypeMeta
:
metav1
.
TypeMeta
{
Kind
:
v1beta1
.
FederatedNamespaceKind
,
APIVersion
:
v1beta1
.
SchemeGroupVersion
.
String
(),
},
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
constants
.
NotificationSecretNamespace
,
Namespace
:
constants
.
NotificationSecretNamespace
,
},
Spec
:
v1beta1
.
FederatedNamespaceSpec
{
Placement
:
v1beta1
.
GenericPlacementFields
{
ClusterSelector
:
&
metav1
.
LabelSelector
{},
},
},
}
if
err
:=
controllerutil
.
SetControllerReference
(
&
ns
,
&
fedNs
,
scheme
.
Scheme
);
err
!=
nil
{
return
err
}
return
c
.
Create
(
context
.
Background
(),
&
fedNs
)
}
return
err
}
return
nil
}
func
(
c
*
Controller
)
ensureNotControlledByKubefed
(
ctx
context
.
Context
,
obj
runtime
.
Object
)
error
{
accessor
,
err
:=
meta
.
Accessor
(
obj
)
...
...
pkg/models/notification/notification.go
浏览文件 @
8e28925d
...
...
@@ -20,6 +20,10 @@ import (
"reflect"
)
const
(
Secret
=
"secrets"
)
type
Operator
interface
{
List
(
user
,
resource
,
subresource
string
,
query
*
query
.
Query
)
(
*
api
.
ListResult
,
error
)
Get
(
user
,
resource
,
name
,
subresource
string
)
(
runtime
.
Object
,
error
)
...
...
@@ -74,12 +78,17 @@ func (o *operator) List(user, resource, subresource string, q *query.Query) (*ap
q
.
LabelSelector
=
q
.
LabelSelector
+
filter
res
,
err
:=
o
.
resourceGetter
.
List
(
resource
,
constants
.
NotificationSecretNamespace
,
q
)
ns
:=
""
if
resource
==
Secret
{
ns
=
constants
.
NotificationSecretNamespace
}
res
,
err
:=
o
.
resourceGetter
.
List
(
resource
,
ns
,
q
)
if
err
!=
nil
{
return
nil
,
err
}
if
subresource
==
""
||
resource
==
"secrets"
{
if
subresource
==
""
||
resource
==
Secret
{
return
res
,
nil
}
...
...
@@ -98,7 +107,13 @@ func (o *operator) List(user, resource, subresource string, q *query.Query) (*ap
// Get the specified object, if you want to get a global object, the user must be nil.
// If you want to get a tenant object, the user must equal to the tenant specified in labels of the object.
func
(
o
*
operator
)
Get
(
user
,
resource
,
name
,
subresource
string
)
(
runtime
.
Object
,
error
)
{
obj
,
err
:=
o
.
resourceGetter
.
Get
(
resource
,
constants
.
NotificationSecretNamespace
,
name
)
ns
:=
""
if
resource
==
Secret
{
ns
=
constants
.
NotificationSecretNamespace
}
obj
,
err
:=
o
.
resourceGetter
.
Get
(
resource
,
ns
,
name
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -107,7 +122,7 @@ func (o *operator) Get(user, resource, name, subresource string) (runtime.Object
return
nil
,
err
}
if
subresource
==
""
||
resource
==
"secrets"
{
if
subresource
==
""
||
resource
==
Secret
{
return
obj
,
nil
}
...
...
@@ -198,7 +213,7 @@ func (o *operator) GetObject(resource string) runtime.Object {
return
&
v2beta1
.
Config
{}
case
v2beta1
.
ResourcesPluralReceiver
:
return
&
v2beta1
.
Receiver
{}
case
"secrets"
:
case
Secret
:
return
&
corev1
.
Secret
{}
default
:
return
nil
...
...
@@ -290,15 +305,20 @@ func appendLabel(user string, obj runtime.Object) error {
labels
=
make
(
map
[
string
]
string
)
}
if
user
==
""
{
if
isConfig
(
obj
)
{
labels
[
"type"
]
=
"default"
switch
obj
.
(
type
)
{
case
*
corev1
.
Secret
:
labels
[
constants
.
NotificationManagedLabel
]
=
"true"
default
:
if
user
==
""
{
if
isConfig
(
obj
)
{
labels
[
"type"
]
=
"default"
}
else
{
labels
[
"type"
]
=
"global"
}
}
else
{
labels
[
"type"
]
=
"global"
labels
[
"type"
]
=
"tenant"
labels
[
"user"
]
=
user
}
}
else
{
labels
[
"type"
]
=
"tenant"
labels
[
"user"
]
=
user
}
accessor
.
SetLabels
(
labels
)
...
...
pkg/models/notification/notification_test.go
浏览文件 @
8e28925d
...
...
@@ -111,7 +111,7 @@ func TestOperator_Create(t *testing.T) {
Name
:
"test"
,
Namespace
:
constants
.
NotificationSecretNamespace
,
Labels
:
map
[
string
]
string
{
"type"
:
"global
"
,
constants
.
NotificationManagedLabel
:
"true
"
,
},
},
},
...
...
@@ -119,7 +119,7 @@ func TestOperator_Create(t *testing.T) {
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"test"
,
Labels
:
map
[
string
]
string
{
"type"
:
"global
"
,
constants
.
NotificationManagedLabel
:
"true
"
,
},
},
},
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录