Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
水淹萌龙
kubesphere
提交
df3ad797
K
kubesphere
项目概览
水淹萌龙
/
kubesphere
与 Fork 源项目一致
Fork自
KubeSphere / kubesphere
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
kubesphere
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
未验证
提交
df3ad797
编写于
4月 15, 2020
作者:
R
runzexia
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rm unused file
上级
052af227
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
0 addition
and
253 deletion
+0
-253
pkg/models/tenant/workspaces.go
pkg/models/tenant/workspaces.go
+0
-253
未找到文件。
pkg/models/tenant/workspaces.go
已删除
100644 → 0
浏览文件 @
052af227
/*
*
* 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
tenant
import
(
core
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"
"kubesphere.io/kubesphere/pkg/apis/tenant/v1alpha1"
"kubesphere.io/kubesphere/pkg/client/informers/externalversions"
"kubesphere.io/kubesphere/pkg/constants"
"kubesphere.io/kubesphere/pkg/models/iam/am"
"kubesphere.io/kubesphere/pkg/models/resources/v1alpha2"
"kubesphere.io/kubesphere/pkg/server/params"
"kubesphere.io/kubesphere/pkg/simple/client/mysql"
"kubesphere.io/kubesphere/pkg/utils/sliceutil"
"strings"
apierrors
"k8s.io/apimachinery/pkg/api/errors"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
iamapi
"kubesphere.io/kubesphere/pkg/api/iam"
)
type
InWorkspaceUser
struct
{
*
iamapi
.
User
WorkspaceRole
string
`json:"workspaceRole"`
}
type
WorkspaceInterface
interface
{
GetWorkspace
(
workspace
string
)
(
*
v1alpha1
.
Workspace
,
error
)
SearchWorkspace
(
username
string
,
conditions
*
params
.
Conditions
,
orderBy
string
,
reverse
bool
)
([]
*
v1alpha1
.
Workspace
,
error
)
ListNamespaces
(
workspace
string
)
([]
*
core
.
Namespace
,
error
)
DeleteNamespace
(
workspace
,
namespace
string
)
error
RemoveUser
(
user
,
workspace
string
)
error
AddUser
(
workspace
string
,
user
*
InWorkspaceUser
)
error
CountDevopsProjectsInWorkspace
(
workspace
string
)
(
int
,
error
)
CountUsersInWorkspace
(
workspace
string
)
(
int
,
error
)
CountOrgRoles
()
(
int
,
error
)
CountWorkspaces
()
(
int
,
error
)
CountNamespacesInWorkspace
(
workspace
string
)
(
int
,
error
)
}
type
workspaceOperator
struct
{
client
kubernetes
.
Interface
informers
informers
.
SharedInformerFactory
ksInformers
externalversions
.
SharedInformerFactory
am
am
.
AccessManagementInterface
// TODO: use db interface instead of mysql client
// we can refactor this after rewrite devops using crd
db
*
mysql
.
Database
}
func
newWorkspaceOperator
(
client
kubernetes
.
Interface
,
informers
informers
.
SharedInformerFactory
,
ksinformers
externalversions
.
SharedInformerFactory
,
am
am
.
AccessManagementInterface
,
db
*
mysql
.
Database
)
WorkspaceInterface
{
return
&
workspaceOperator
{
client
:
client
,
informers
:
informers
,
ksInformers
:
ksinformers
,
am
:
am
,
db
:
db
,
}
}
func
(
w
*
workspaceOperator
)
ListNamespaces
(
workspace
string
)
([]
*
core
.
Namespace
,
error
)
{
namespaces
,
err
:=
w
.
informers
.
Core
()
.
V1
()
.
Namespaces
()
.
Lister
()
.
List
(
labels
.
SelectorFromSet
(
labels
.
Set
{
constants
.
WorkspaceLabelKey
:
workspace
}))
if
err
!=
nil
{
return
nil
,
err
}
return
namespaces
,
nil
}
func
(
w
*
workspaceOperator
)
DeleteNamespace
(
workspace
string
,
namespace
string
)
error
{
ns
,
err
:=
w
.
informers
.
Core
()
.
V1
()
.
Namespaces
()
.
Lister
()
.
Get
(
namespace
)
if
err
!=
nil
{
return
err
}
if
ns
.
Labels
[
constants
.
WorkspaceLabelKey
]
==
workspace
{
deletePolicy
:=
metav1
.
DeletePropagationBackground
return
w
.
client
.
CoreV1
()
.
Namespaces
()
.
Delete
(
namespace
,
&
metav1
.
DeleteOptions
{
PropagationPolicy
:
&
deletePolicy
})
}
else
{
return
apierrors
.
NewNotFound
(
schema
.
GroupResource
{
Group
:
""
,
Resource
:
"workspace"
},
workspace
)
}
}
func
(
w
*
workspaceOperator
)
RemoveUser
(
workspace
string
,
username
string
)
error
{
panic
(
"implement me"
)
}
func
(
w
*
workspaceOperator
)
AddUser
(
workspaceName
string
,
user
*
InWorkspaceUser
)
error
{
panic
(
"implement me"
)
}
func
(
w
*
workspaceOperator
)
CountDevopsProjectsInWorkspace
(
workspaceName
string
)
(
int
,
error
)
{
//TODO:runzexia use informer to impl it
return
0
,
nil
}
func
(
w
*
workspaceOperator
)
CountUsersInWorkspace
(
workspace
string
)
(
int
,
error
)
{
count
,
err
:=
w
.
CountUsersInWorkspace
(
workspace
)
if
err
!=
nil
{
return
0
,
err
}
return
count
,
nil
}
func
(
w
*
workspaceOperator
)
CountOrgRoles
()
(
int
,
error
)
{
return
len
(
constants
.
WorkSpaceRoles
),
nil
}
func
(
w
*
workspaceOperator
)
CountNamespacesInWorkspace
(
workspace
string
)
(
int
,
error
)
{
ns
,
err
:=
w
.
ListNamespaces
(
workspace
)
if
err
!=
nil
{
return
0
,
err
}
return
len
(
ns
),
nil
}
func
(
*
workspaceOperator
)
match
(
match
map
[
string
]
string
,
item
*
v1alpha1
.
Workspace
)
bool
{
for
k
,
v
:=
range
match
{
switch
k
{
case
v1alpha2
.
Name
:
names
:=
strings
.
Split
(
v
,
"|"
)
if
!
sliceutil
.
HasString
(
names
,
item
.
Name
)
{
return
false
}
case
v1alpha2
.
Keyword
:
if
!
strings
.
Contains
(
item
.
Name
,
v
)
&&
!
contains
(
item
.
Labels
,
""
,
v
)
&&
!
contains
(
item
.
Annotations
,
""
,
v
)
{
return
false
}
default
:
// label not exist or value not equal
if
val
,
ok
:=
item
.
Labels
[
k
];
!
ok
||
val
!=
v
{
return
false
}
}
}
return
true
}
func
(
*
workspaceOperator
)
fuzzy
(
fuzzy
map
[
string
]
string
,
item
*
v1alpha1
.
Workspace
)
bool
{
for
k
,
v
:=
range
fuzzy
{
switch
k
{
case
v1alpha2
.
Name
:
if
!
strings
.
Contains
(
item
.
Name
,
v
)
&&
!
strings
.
Contains
(
item
.
Annotations
[
constants
.
DisplayNameAnnotationKey
],
v
)
{
return
false
}
default
:
return
false
}
}
return
true
}
func
(
*
workspaceOperator
)
compare
(
a
,
b
*
v1alpha1
.
Workspace
,
orderBy
string
)
bool
{
switch
orderBy
{
case
v1alpha2
.
CreateTime
:
return
a
.
CreationTimestamp
.
Time
.
Before
(
b
.
CreationTimestamp
.
Time
)
case
v1alpha2
.
Name
:
fallthrough
default
:
return
strings
.
Compare
(
a
.
Name
,
b
.
Name
)
<=
0
}
}
func
(
w
*
workspaceOperator
)
SearchWorkspace
(
username
string
,
conditions
*
params
.
Conditions
,
orderBy
string
,
reverse
bool
)
([]
*
v1alpha1
.
Workspace
,
error
)
{
panic
(
"implement me"
)
}
func
(
w
*
workspaceOperator
)
GetWorkspace
(
workspaceName
string
)
(
*
v1alpha1
.
Workspace
,
error
)
{
return
w
.
ksInformers
.
Tenant
()
.
V1alpha1
()
.
Workspaces
()
.
Lister
()
.
Get
(
workspaceName
)
}
func
contains
(
m
map
[
string
]
string
,
key
,
value
string
)
bool
{
for
k
,
v
:=
range
m
{
if
key
==
""
{
if
strings
.
Contains
(
k
,
value
)
||
strings
.
Contains
(
v
,
value
)
{
return
true
}
}
else
if
k
==
key
&&
strings
.
Contains
(
v
,
value
)
{
return
true
}
}
return
false
}
/*
// TODO: move to metrics package
func GetAllProjectNums() (int, error) {
namespaceLister := informers.SharedInformerFactory().Core().V1().Namespaces().Lister()
list, err := namespaceLister.List(labels.Everything())
if err != nil {
return 0, err
}
return len(list), nil
}
func GetAllDevOpsProjectsNums() (int, error) {
_, err := clientset.ClientSets().Devops()
if _, notEnabled := err.(clientset.ClientSetNotEnabledError); notEnabled {
return 0, err
}
dbconn, err := clientset.ClientSets().MySQL()
if err != nil {
return 0, err
}
query := dbconn.Select(devops.DevOpsProjectIdColumn).
From(devops.DevOpsProjectTableName).
Where(db.Eq(devops.StatusColumn, devops.StatusActive))
devOpsProjects := make([]string, 0)
if _, err := query.Load(&devOpsProjects); err != nil {
return 0, err
}
return len(devOpsProjects), nil
}
*/
func
(
w
*
workspaceOperator
)
CountWorkspaces
()
(
int
,
error
)
{
ws
,
err
:=
w
.
ksInformers
.
Tenant
()
.
V1alpha1
()
.
Workspaces
()
.
Lister
()
.
List
(
labels
.
Everything
())
if
err
!=
nil
{
return
0
,
err
}
return
len
(
ws
),
nil
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录