Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
水淹萌龙
kubesphere
提交
ad38e692
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看板
未验证
提交
ad38e692
编写于
3月 12, 2021
作者:
H
hongming
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix unauthorized resource access
Signed-off-by:
N
hongming
<
talonwan@yunify.com
>
上级
147f5022
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
89 addition
and
77 deletion
+89
-77
pkg/kapis/resources/v1alpha3/handler.go
pkg/kapis/resources/v1alpha3/handler.go
+11
-12
pkg/models/resources/v1alpha2/resource/resources.go
pkg/models/resources/v1alpha2/resource/resources.go
+12
-11
pkg/models/resources/v1alpha3/resource/resource.go
pkg/models/resources/v1alpha3/resource/resource.go
+66
-54
未找到文件。
pkg/kapis/resources/v1alpha3/handler.go
浏览文件 @
ad38e692
...
...
@@ -63,10 +63,13 @@ func (h *Handler) handleGetResources(request *restful.Request, response *restful
// fallback to v1alpha2
resultV1alpha2
,
err
:=
h
.
resourcesGetterV1alpha2
.
GetResource
(
namespace
,
resourceType
,
name
)
if
err
!=
nil
{
if
err
==
resourcev1alpha2
.
ErrResourceNotSupported
{
api
.
HandleNotFound
(
response
,
request
,
err
)
return
}
klog
.
Error
(
err
)
api
.
Handle
InternalError
(
response
,
nil
,
err
)
api
.
Handle
Error
(
response
,
request
,
err
)
return
}
...
...
@@ -81,7 +84,6 @@ func (h *Handler) handleListResources(request *restful.Request, response *restfu
namespace
:=
request
.
PathParameter
(
"namespace"
)
result
,
err
:=
h
.
resourceGetterV1alpha3
.
List
(
resourceType
,
namespace
,
query
)
if
err
==
nil
{
response
.
WriteEntity
(
result
)
return
...
...
@@ -89,16 +91,19 @@ func (h *Handler) handleListResources(request *restful.Request, response *restfu
if
err
!=
resourcev1alpha3
.
ErrResourceNotSupported
{
klog
.
Error
(
err
,
resourceType
)
api
.
HandleInternalError
(
response
,
nil
,
err
)
api
.
HandleInternalError
(
response
,
request
,
err
)
return
}
// fallback to v1alpha2
result
,
err
=
h
.
fallback
(
resourceType
,
namespace
,
query
)
if
err
!=
nil
{
if
err
==
resourcev1alpha2
.
ErrResourceNotSupported
{
api
.
HandleNotFound
(
response
,
request
,
err
)
return
}
klog
.
Error
(
err
)
api
.
Handle
InternalError
(
response
,
nil
,
err
)
api
.
Handle
Error
(
response
,
request
,
err
)
return
}
response
.
WriteEntity
(
result
)
...
...
@@ -152,7 +157,6 @@ func (h *Handler) fallback(resourceType string, namespace string, q *query.Query
}
result
,
err
:=
h
.
resourcesGetterV1alpha2
.
ListResources
(
namespace
,
resourceType
,
conditions
,
orderBy
,
reverse
,
limit
,
offset
)
if
err
!=
nil
{
klog
.
Error
(
err
)
return
nil
,
err
...
...
@@ -167,19 +171,16 @@ func (h *Handler) fallback(resourceType string, namespace string, q *query.Query
func
(
h
*
Handler
)
handleGetComponentStatus
(
request
*
restful
.
Request
,
response
*
restful
.
Response
)
{
component
:=
request
.
PathParameter
(
"component"
)
result
,
err
:=
h
.
componentsGetter
.
GetComponentStatus
(
component
)
if
err
!=
nil
{
klog
.
Error
(
err
)
api
.
HandleInternalError
(
response
,
nil
,
err
)
return
}
response
.
WriteEntity
(
result
)
}
func
(
h
*
Handler
)
handleGetSystemHealthStatus
(
request
*
restful
.
Request
,
response
*
restful
.
Response
)
{
result
,
err
:=
h
.
componentsGetter
.
GetSystemHealthStatus
()
if
err
!=
nil
{
klog
.
Error
(
err
)
api
.
HandleInternalError
(
response
,
nil
,
err
)
...
...
@@ -191,9 +192,7 @@ func (h *Handler) handleGetSystemHealthStatus(request *restful.Request, response
// get all componentsHandler
func
(
h
*
Handler
)
handleGetComponents
(
request
*
restful
.
Request
,
response
*
restful
.
Response
)
{
result
,
err
:=
h
.
componentsGetter
.
GetAllComponentsStatus
()
if
err
!=
nil
{
klog
.
Error
(
err
)
api
.
HandleInternalError
(
response
,
nil
,
err
)
...
...
pkg/models/resources/v1alpha2/resource/resources.go
浏览文件 @
ad38e692
...
...
@@ -17,7 +17,7 @@ limitations under the License.
package
resource
import
(
"
fmt
"
"
errors
"
"k8s.io/klog"
"kubesphere.io/kubesphere/pkg/informers"
"kubesphere.io/kubesphere/pkg/models"
...
...
@@ -47,6 +47,8 @@ import (
"kubesphere.io/kubesphere/pkg/utils/sliceutil"
)
var
ErrResourceNotSupported
=
errors
.
New
(
"resource is not supported"
)
type
ResourceGetter
struct
{
resourcesGetters
map
[
string
]
v1alpha2
.
Interface
}
...
...
@@ -89,20 +91,23 @@ func NewResourceGetter(factory informers.InformerFactory) *ResourceGetter {
}
var
(
//injector = v1alpha2.extraAnnotationInjector{}
clusterResources
=
[]
string
{
v1alpha2
.
Nodes
,
v1alpha2
.
Workspaces
,
v1alpha2
.
Namespaces
,
v1alpha2
.
ClusterRoles
,
v1alpha2
.
StorageClasses
,
v1alpha2
.
S2iBuilderTemplates
}
)
func
(
r
*
ResourceGetter
)
GetResource
(
namespace
,
resource
,
name
string
)
(
interface
{},
error
)
{
// none namespace resource
if
namespace
!=
""
&&
sliceutil
.
HasString
(
clusterResources
,
resource
)
{
return
nil
,
ErrResourceNotSupported
}
if
searcher
,
ok
:=
r
.
resourcesGetters
[
resource
];
ok
{
resource
,
err
:=
searcher
.
Get
(
namespace
,
name
)
if
err
!=
nil
{
klog
.
Error
f
(
"resource %s.%s.%s not found: %s"
,
namespace
,
resource
,
name
,
err
)
klog
.
Error
(
err
)
return
nil
,
err
}
return
resource
,
nil
}
return
nil
,
fmt
.
Errorf
(
"resource %s.%s.%s not found"
,
namespace
,
resource
,
name
)
return
nil
,
ErrResourceNotSupported
}
func
(
r
*
ResourceGetter
)
ListResources
(
namespace
,
resource
string
,
conditions
*
params
.
Conditions
,
orderBy
string
,
reverse
bool
,
limit
,
offset
int
)
(
*
models
.
PageableResponse
,
error
)
{
...
...
@@ -112,21 +117,17 @@ func (r *ResourceGetter) ListResources(namespace, resource string, conditions *p
// none namespace resource
if
namespace
!=
""
&&
sliceutil
.
HasString
(
clusterResources
,
resource
)
{
err
=
fmt
.
Errorf
(
"resource %s is not supported"
,
resource
)
klog
.
Errorln
(
err
)
return
nil
,
err
return
nil
,
ErrResourceNotSupported
}
if
searcher
,
ok
:=
r
.
resourcesGetters
[
resource
];
ok
{
result
,
err
=
searcher
.
Search
(
namespace
,
conditions
,
orderBy
,
reverse
)
}
else
{
err
=
fmt
.
Errorf
(
"resource %s is not supported"
,
resource
)
klog
.
Errorln
(
err
)
return
nil
,
err
return
nil
,
ErrResourceNotSupported
}
if
err
!=
nil
{
klog
.
Error
ln
(
err
)
klog
.
Error
(
err
)
return
nil
,
err
}
...
...
pkg/models/resources/v1alpha3/resource/resource.go
浏览文件 @
ad38e692
...
...
@@ -23,6 +23,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"kubesphere.io/kubesphere/pkg/api"
clusterv1alpha1
"kubesphere.io/kubesphere/pkg/apis/cluster/v1alpha1"
devopsv1alpha3
"kubesphere.io/kubesphere/pkg/apis/devops/v1alpha3"
iamv1alpha2
"kubesphere.io/kubesphere/pkg/apis/iam/v1alpha2"
networkv1alpha1
"kubesphere.io/kubesphere/pkg/apis/network/v1alpha1"
...
...
@@ -83,72 +84,81 @@ import (
var
ErrResourceNotSupported
=
errors
.
New
(
"resource is not supported"
)
type
ResourceGetter
struct
{
getters
map
[
schema
.
GroupVersionResource
]
v1alpha3
.
Interface
clusterResourceGetters
map
[
schema
.
GroupVersionResource
]
v1alpha3
.
Interface
namespacedResourceGetters
map
[
schema
.
GroupVersionResource
]
v1alpha3
.
Interface
}
func
NewResourceGetter
(
factory
informers
.
InformerFactory
,
cache
cache
.
Cache
)
*
ResourceGetter
{
getters
:=
make
(
map
[
schema
.
GroupVersionResource
]
v1alpha3
.
Interface
)
getters
[
schema
.
GroupVersionResource
{
Group
:
"apps"
,
Version
:
"v1"
,
Resource
:
"deployments"
}]
=
deployment
.
New
(
factory
.
KubernetesSharedInformerFactory
())
getters
[
schema
.
GroupVersionResource
{
Group
:
"apps"
,
Version
:
"v1"
,
Resource
:
"daemonsets"
}]
=
daemonset
.
New
(
factory
.
KubernetesSharedInformerFactory
())
getters
[
schema
.
GroupVersionResource
{
Group
:
"apps"
,
Version
:
"v1"
,
Resource
:
"statefulsets"
}]
=
statefulset
.
New
(
factory
.
KubernetesSharedInformerFactory
())
getters
[
schema
.
GroupVersionResource
{
Group
:
""
,
Version
:
"v1"
,
Resource
:
"services"
}]
=
service
.
New
(
factory
.
KubernetesSharedInformerFactory
())
getters
[
schema
.
GroupVersionResource
{
Group
:
""
,
Version
:
"v1"
,
Resource
:
"namespaces"
}]
=
namespace
.
New
(
factory
.
KubernetesSharedInformerFactory
())
getters
[
schema
.
GroupVersionResource
{
Group
:
""
,
Version
:
"v1"
,
Resource
:
"configmaps"
}]
=
configmap
.
New
(
factory
.
KubernetesSharedInformerFactory
())
getters
[
schema
.
GroupVersionResource
{
Group
:
""
,
Version
:
"v1"
,
Resource
:
"secrets"
}]
=
secret
.
New
(
factory
.
KubernetesSharedInformerFactory
())
getters
[
schema
.
GroupVersionResource
{
Group
:
""
,
Version
:
"v1"
,
Resource
:
"pods"
}]
=
pod
.
New
(
factory
.
KubernetesSharedInformerFactory
())
getters
[
schema
.
GroupVersionResource
{
Group
:
""
,
Version
:
"v1"
,
Resource
:
"nodes"
}]
=
node
.
New
(
factory
.
KubernetesSharedInformerFactory
())
getters
[
schema
.
GroupVersionResource
{
Group
:
""
,
Version
:
"v1"
,
Resource
:
"serviceaccounts"
}]
=
serviceaccount
.
New
(
factory
.
KubernetesSharedInformerFactory
())
getters
[
schema
.
GroupVersionResource
{
Group
:
"extensions"
,
Version
:
"v1beta1"
,
Resource
:
"ingresses"
}]
=
ingress
.
New
(
factory
.
KubernetesSharedInformerFactory
())
getters
[
schema
.
GroupVersionResource
{
Group
:
"networking.k8s.io"
,
Version
:
"v1"
,
Resource
:
"networkpolicies"
}]
=
networkpolicy
.
New
(
factory
.
KubernetesSharedInformerFactory
())
getters
[
schema
.
GroupVersionResource
{
Group
:
"batch"
,
Version
:
"v1"
,
Resource
:
"jobs"
}]
=
job
.
New
(
factory
.
KubernetesSharedInformerFactory
())
getters
[
schema
.
GroupVersionResource
{
Group
:
"app.k8s.io"
,
Version
:
"v1beta1"
,
Resource
:
"applications"
}]
=
application
.
New
(
cache
)
namespacedResourceGetters
:=
make
(
map
[
schema
.
GroupVersionResource
]
v1alpha3
.
Interface
)
clusterResourceGetters
:=
make
(
map
[
schema
.
GroupVersionResource
]
v1alpha3
.
Interface
)
namespacedResourceGetters
[
schema
.
GroupVersionResource
{
Group
:
"apps"
,
Version
:
"v1"
,
Resource
:
"deployments"
}]
=
deployment
.
New
(
factory
.
KubernetesSharedInformerFactory
())
namespacedResourceGetters
[
schema
.
GroupVersionResource
{
Group
:
"apps"
,
Version
:
"v1"
,
Resource
:
"daemonsets"
}]
=
daemonset
.
New
(
factory
.
KubernetesSharedInformerFactory
())
namespacedResourceGetters
[
schema
.
GroupVersionResource
{
Group
:
"apps"
,
Version
:
"v1"
,
Resource
:
"statefulsets"
}]
=
statefulset
.
New
(
factory
.
KubernetesSharedInformerFactory
())
namespacedResourceGetters
[
schema
.
GroupVersionResource
{
Group
:
""
,
Version
:
"v1"
,
Resource
:
"services"
}]
=
service
.
New
(
factory
.
KubernetesSharedInformerFactory
())
namespacedResourceGetters
[
schema
.
GroupVersionResource
{
Group
:
""
,
Version
:
"v1"
,
Resource
:
"namespaces"
}]
=
namespace
.
New
(
factory
.
KubernetesSharedInformerFactory
())
namespacedResourceGetters
[
schema
.
GroupVersionResource
{
Group
:
""
,
Version
:
"v1"
,
Resource
:
"configmaps"
}]
=
configmap
.
New
(
factory
.
KubernetesSharedInformerFactory
())
namespacedResourceGetters
[
schema
.
GroupVersionResource
{
Group
:
""
,
Version
:
"v1"
,
Resource
:
"secrets"
}]
=
secret
.
New
(
factory
.
KubernetesSharedInformerFactory
())
namespacedResourceGetters
[
schema
.
GroupVersionResource
{
Group
:
""
,
Version
:
"v1"
,
Resource
:
"pods"
}]
=
pod
.
New
(
factory
.
KubernetesSharedInformerFactory
())
namespacedResourceGetters
[
schema
.
GroupVersionResource
{
Group
:
""
,
Version
:
"v1"
,
Resource
:
"nodes"
}]
=
node
.
New
(
factory
.
KubernetesSharedInformerFactory
())
namespacedResourceGetters
[
schema
.
GroupVersionResource
{
Group
:
""
,
Version
:
"v1"
,
Resource
:
"serviceaccounts"
}]
=
serviceaccount
.
New
(
factory
.
KubernetesSharedInformerFactory
())
namespacedResourceGetters
[
schema
.
GroupVersionResource
{
Group
:
"extensions"
,
Version
:
"v1beta1"
,
Resource
:
"ingresses"
}]
=
ingress
.
New
(
factory
.
KubernetesSharedInformerFactory
())
namespacedResourceGetters
[
schema
.
GroupVersionResource
{
Group
:
"networking.k8s.io"
,
Version
:
"v1"
,
Resource
:
"networkpolicies"
}]
=
networkpolicy
.
New
(
factory
.
KubernetesSharedInformerFactory
())
namespacedResourceGetters
[
schema
.
GroupVersionResource
{
Group
:
"batch"
,
Version
:
"v1"
,
Resource
:
"jobs"
}]
=
job
.
New
(
factory
.
KubernetesSharedInformerFactory
())
namespacedResourceGetters
[
schema
.
GroupVersionResource
{
Group
:
"app.k8s.io"
,
Version
:
"v1beta1"
,
Resource
:
"applications"
}]
=
application
.
New
(
cache
)
namespacedResourceGetters
[
schema
.
GroupVersionResource
{
Group
:
""
,
Version
:
"v1"
,
Resource
:
"persistentvolumeclaims"
}]
=
persistentvolumeclaim
.
New
(
factory
.
KubernetesSharedInformerFactory
(),
factory
.
SnapshotSharedInformerFactory
())
namespacedResourceGetters
[
snapshotv1beta1
.
SchemeGroupVersion
.
WithResource
(
"volumesnapshots"
)]
=
volumesnapshot
.
New
(
factory
.
SnapshotSharedInformerFactory
())
namespacedResourceGetters
[
rbacv1
.
SchemeGroupVersion
.
WithResource
(
iamv1alpha2
.
ResourcesPluralRoleBinding
)]
=
rolebinding
.
New
(
factory
.
KubernetesSharedInformerFactory
())
namespacedResourceGetters
[
rbacv1
.
SchemeGroupVersion
.
WithResource
(
iamv1alpha2
.
ResourcesPluralRole
)]
=
role
.
New
(
factory
.
KubernetesSharedInformerFactory
())
clusterResourceGetters
[
schema
.
GroupVersionResource
{
Group
:
"apiextensions.k8s.io"
,
Version
:
"v1"
,
Resource
:
"customresourcedefinitions"
}]
=
customresourcedefinition
.
New
(
factory
.
ApiExtensionSharedInformerFactory
())
// kubesphere resources
getters
[
devopsv1alpha3
.
SchemeGroupVersion
.
WithResource
(
devopsv1alpha3
.
ResourcePluralDevOpsProject
)]
=
devops
.
New
(
factory
.
KubeSphereSharedInformerFactory
())
getters
[
tenantv1alpha1
.
SchemeGroupVersion
.
WithResource
(
tenantv1alpha1
.
ResourcePluralWorkspace
)]
=
workspace
.
New
(
factory
.
KubeSphereSharedInformerFactory
())
getters
[
networkv1alpha1
.
SchemeGroupVersion
.
WithResource
(
networkv1alpha1
.
ResourcePluralIPPool
)]
=
ippool
.
New
(
factory
.
KubeSphereSharedInformerFactory
(),
factory
.
KubernetesSharedInformerFactory
())
getters
[
tenantv1alpha1
.
SchemeGroupVersion
.
WithResource
(
tenantv1alpha2
.
ResourcePluralWorkspaceTemplate
)]
=
workspacetemplate
.
New
(
factory
.
KubeSphereSharedInformerFactory
())
getters
[
iamv1alpha2
.
SchemeGroupVersion
.
WithResource
(
iamv1alpha2
.
ResourcesPluralGlobalRole
)]
=
globalrole
.
New
(
factory
.
KubeSphereSharedInformerFactory
())
getters
[
iamv1alpha2
.
SchemeGroupVersion
.
WithResource
(
iamv1alpha2
.
ResourcesPluralWorkspaceRole
)]
=
workspacerole
.
New
(
factory
.
KubeSphereSharedInformerFactory
())
getters
[
iamv1alpha2
.
SchemeGroupVersion
.
WithResource
(
iamv1alpha2
.
ResourcesPluralUser
)]
=
user
.
New
(
factory
.
KubeSphereSharedInformerFactory
(),
factory
.
KubernetesSharedInformerFactory
())
getters
[
iamv1alpha2
.
SchemeGroupVersion
.
WithResource
(
iamv1alpha2
.
ResourcesPluralGlobalRoleBinding
)]
=
globalrolebinding
.
New
(
factory
.
KubeSphereSharedInformerFactory
())
getters
[
iamv1alpha2
.
SchemeGroupVersion
.
WithResource
(
iamv1alpha2
.
ResourcesPluralWorkspaceRoleBinding
)]
=
workspacerolebinding
.
New
(
factory
.
KubeSphereSharedInformerFactory
())
getters
[
iamv1alpha2
.
SchemeGroupVersion
.
WithResource
(
iamv1alpha2
.
ResourcesPluralLoginRecord
)]
=
loginrecord
.
New
(
factory
.
KubeSphereSharedInformerFactory
())
getters
[
iamv1alpha2
.
SchemeGroupVersion
.
WithResource
(
iamv1alpha2
.
ResourcePluralGroup
)]
=
group
.
New
(
factory
.
KubeSphereSharedInformerFactory
())
getters
[
iamv1alpha2
.
SchemeGroupVersion
.
WithResource
(
iamv1alpha2
.
ResourcePluralGroupBinding
)]
=
groupbinding
.
New
(
factory
.
KubeSphereSharedInformerFactory
())
getters
[
rbacv1
.
SchemeGroupVersion
.
WithResource
(
iamv1alpha2
.
ResourcesPluralRole
)]
=
role
.
New
(
factory
.
KubernetesSharedInformerFactory
())
getters
[
rbacv1
.
SchemeGroupVersion
.
WithResource
(
iamv1alpha2
.
ResourcesPluralClusterRole
)]
=
clusterrole
.
New
(
factory
.
KubernetesSharedInformerFactory
())
getters
[
rbacv1
.
SchemeGroupVersion
.
WithResource
(
iamv1alpha2
.
ResourcesPluralRoleBinding
)]
=
rolebinding
.
New
(
factory
.
KubernetesSharedInformerFactory
())
getters
[
rbacv1
.
SchemeGroupVersion
.
WithResource
(
iamv1alpha2
.
ResourcesPluralClusterRoleBinding
)]
=
clusterrolebinding
.
New
(
factory
.
KubernetesSharedInformerFactory
())
getters
[
schema
.
GroupVersionResource
{
Group
:
""
,
Version
:
"v1"
,
Resource
:
"persistentvolumeclaims"
}]
=
persistentvolumeclaim
.
New
(
factory
.
KubernetesSharedInformerFactory
(),
factory
.
SnapshotSharedInformerFactory
())
getters
[
snapshotv1beta1
.
SchemeGroupVersion
.
WithResource
(
"volumesnapshots"
)]
=
volumesnapshot
.
New
(
factory
.
SnapshotSharedInformerFactory
())
getters
[
schema
.
GroupVersionResource
{
Group
:
"cluster.kubesphere.io"
,
Version
:
"v1alpha1"
,
Resource
:
"clusters"
}]
=
cluster
.
New
(
factory
.
KubeSphereSharedInformerFactory
())
getters
[
schema
.
GroupVersionResource
{
Group
:
"apiextensions.k8s.io"
,
Version
:
"v1"
,
Resource
:
"customresourcedefinitions"
}]
=
customresourcedefinition
.
New
(
factory
.
ApiExtensionSharedInformerFactory
())
getters
[
notificationv2beta1
.
SchemeGroupVersion
.
WithResource
(
notificationv2beta1
.
ResourcesPluralConfig
)]
=
notification
.
NewNotificationConfigGetter
(
factory
.
KubeSphereSharedInformerFactory
())
getters
[
notificationv2beta1
.
SchemeGroupVersion
.
WithResource
(
notificationv2beta1
.
ResourcesPluralReceiver
)]
=
notification
.
NewNotificationReceiverGetter
(
factory
.
KubeSphereSharedInformerFactory
())
clusterResourceGetters
[
devopsv1alpha3
.
SchemeGroupVersion
.
WithResource
(
devopsv1alpha3
.
ResourcePluralDevOpsProject
)]
=
devops
.
New
(
factory
.
KubeSphereSharedInformerFactory
())
clusterResourceGetters
[
tenantv1alpha1
.
SchemeGroupVersion
.
WithResource
(
tenantv1alpha1
.
ResourcePluralWorkspace
)]
=
workspace
.
New
(
factory
.
KubeSphereSharedInformerFactory
())
clusterResourceGetters
[
networkv1alpha1
.
SchemeGroupVersion
.
WithResource
(
networkv1alpha1
.
ResourcePluralIPPool
)]
=
ippool
.
New
(
factory
.
KubeSphereSharedInformerFactory
(),
factory
.
KubernetesSharedInformerFactory
())
clusterResourceGetters
[
tenantv1alpha1
.
SchemeGroupVersion
.
WithResource
(
tenantv1alpha2
.
ResourcePluralWorkspaceTemplate
)]
=
workspacetemplate
.
New
(
factory
.
KubeSphereSharedInformerFactory
())
clusterResourceGetters
[
iamv1alpha2
.
SchemeGroupVersion
.
WithResource
(
iamv1alpha2
.
ResourcesPluralGlobalRole
)]
=
globalrole
.
New
(
factory
.
KubeSphereSharedInformerFactory
())
clusterResourceGetters
[
iamv1alpha2
.
SchemeGroupVersion
.
WithResource
(
iamv1alpha2
.
ResourcesPluralWorkspaceRole
)]
=
workspacerole
.
New
(
factory
.
KubeSphereSharedInformerFactory
())
clusterResourceGetters
[
iamv1alpha2
.
SchemeGroupVersion
.
WithResource
(
iamv1alpha2
.
ResourcesPluralUser
)]
=
user
.
New
(
factory
.
KubeSphereSharedInformerFactory
(),
factory
.
KubernetesSharedInformerFactory
())
clusterResourceGetters
[
iamv1alpha2
.
SchemeGroupVersion
.
WithResource
(
iamv1alpha2
.
ResourcesPluralGlobalRoleBinding
)]
=
globalrolebinding
.
New
(
factory
.
KubeSphereSharedInformerFactory
())
clusterResourceGetters
[
iamv1alpha2
.
SchemeGroupVersion
.
WithResource
(
iamv1alpha2
.
ResourcesPluralWorkspaceRoleBinding
)]
=
workspacerolebinding
.
New
(
factory
.
KubeSphereSharedInformerFactory
())
clusterResourceGetters
[
iamv1alpha2
.
SchemeGroupVersion
.
WithResource
(
iamv1alpha2
.
ResourcesPluralLoginRecord
)]
=
loginrecord
.
New
(
factory
.
KubeSphereSharedInformerFactory
())
clusterResourceGetters
[
iamv1alpha2
.
SchemeGroupVersion
.
WithResource
(
iamv1alpha2
.
ResourcePluralGroup
)]
=
group
.
New
(
factory
.
KubeSphereSharedInformerFactory
())
clusterResourceGetters
[
iamv1alpha2
.
SchemeGroupVersion
.
WithResource
(
iamv1alpha2
.
ResourcePluralGroupBinding
)]
=
groupbinding
.
New
(
factory
.
KubeSphereSharedInformerFactory
())
clusterResourceGetters
[
rbacv1
.
SchemeGroupVersion
.
WithResource
(
iamv1alpha2
.
ResourcesPluralClusterRole
)]
=
clusterrole
.
New
(
factory
.
KubernetesSharedInformerFactory
())
clusterResourceGetters
[
rbacv1
.
SchemeGroupVersion
.
WithResource
(
iamv1alpha2
.
ResourcesPluralClusterRoleBinding
)]
=
clusterrolebinding
.
New
(
factory
.
KubernetesSharedInformerFactory
())
clusterResourceGetters
[
clusterv1alpha1
.
SchemeGroupVersion
.
WithResource
(
clusterv1alpha1
.
ResourcesPluralCluster
)]
=
cluster
.
New
(
factory
.
KubeSphereSharedInformerFactory
())
clusterResourceGetters
[
notificationv2beta1
.
SchemeGroupVersion
.
WithResource
(
notificationv2beta1
.
ResourcesPluralConfig
)]
=
notification
.
NewNotificationConfigGetter
(
factory
.
KubeSphereSharedInformerFactory
())
clusterResourceGetters
[
notificationv2beta1
.
SchemeGroupVersion
.
WithResource
(
notificationv2beta1
.
ResourcesPluralReceiver
)]
=
notification
.
NewNotificationReceiverGetter
(
factory
.
KubeSphereSharedInformerFactory
())
// federated resources
g
etters
[
typesv1beta1
.
SchemeGroupVersion
.
WithResource
(
typesv1beta1
.
ResourcePluralFederatedNamespace
)]
=
federatednamespace
.
New
(
factory
.
KubeSphereSharedInformerFactory
())
g
etters
[
typesv1beta1
.
SchemeGroupVersion
.
WithResource
(
typesv1beta1
.
ResourcePluralFederatedDeployment
)]
=
federateddeployment
.
New
(
factory
.
KubeSphereSharedInformerFactory
())
g
etters
[
typesv1beta1
.
SchemeGroupVersion
.
WithResource
(
typesv1beta1
.
ResourcePluralFederatedSecret
)]
=
federatedsecret
.
New
(
factory
.
KubeSphereSharedInformerFactory
())
g
etters
[
typesv1beta1
.
SchemeGroupVersion
.
WithResource
(
typesv1beta1
.
ResourcePluralFederatedConfigmap
)]
=
federatedconfigmap
.
New
(
factory
.
KubeSphereSharedInformerFactory
())
g
etters
[
typesv1beta1
.
SchemeGroupVersion
.
WithResource
(
typesv1beta1
.
ResourcePluralFederatedService
)]
=
federatedservice
.
New
(
factory
.
KubeSphereSharedInformerFactory
())
g
etters
[
typesv1beta1
.
SchemeGroupVersion
.
WithResource
(
typesv1beta1
.
ResourcePluralFederatedApplication
)]
=
federatedapplication
.
New
(
factory
.
KubeSphereSharedInformerFactory
())
g
etters
[
typesv1beta1
.
SchemeGroupVersion
.
WithResource
(
typesv1beta1
.
ResourcePluralFederatedPersistentVolumeClaim
)]
=
federatedpersistentvolumeclaim
.
New
(
factory
.
KubeSphereSharedInformerFactory
())
g
etters
[
typesv1beta1
.
SchemeGroupVersion
.
WithResource
(
typesv1beta1
.
ResourcePluralFederatedStatefulSet
)]
=
federatedstatefulset
.
New
(
factory
.
KubeSphereSharedInformerFactory
())
g
etters
[
typesv1beta1
.
SchemeGroupVersion
.
WithResource
(
typesv1beta1
.
ResourcePluralFederatedIngress
)]
=
federatedingress
.
New
(
factory
.
KubeSphereSharedInformerFactory
())
namespacedResourceG
etters
[
typesv1beta1
.
SchemeGroupVersion
.
WithResource
(
typesv1beta1
.
ResourcePluralFederatedNamespace
)]
=
federatednamespace
.
New
(
factory
.
KubeSphereSharedInformerFactory
())
namespacedResourceG
etters
[
typesv1beta1
.
SchemeGroupVersion
.
WithResource
(
typesv1beta1
.
ResourcePluralFederatedDeployment
)]
=
federateddeployment
.
New
(
factory
.
KubeSphereSharedInformerFactory
())
namespacedResourceG
etters
[
typesv1beta1
.
SchemeGroupVersion
.
WithResource
(
typesv1beta1
.
ResourcePluralFederatedSecret
)]
=
federatedsecret
.
New
(
factory
.
KubeSphereSharedInformerFactory
())
namespacedResourceG
etters
[
typesv1beta1
.
SchemeGroupVersion
.
WithResource
(
typesv1beta1
.
ResourcePluralFederatedConfigmap
)]
=
federatedconfigmap
.
New
(
factory
.
KubeSphereSharedInformerFactory
())
namespacedResourceG
etters
[
typesv1beta1
.
SchemeGroupVersion
.
WithResource
(
typesv1beta1
.
ResourcePluralFederatedService
)]
=
federatedservice
.
New
(
factory
.
KubeSphereSharedInformerFactory
())
namespacedResourceG
etters
[
typesv1beta1
.
SchemeGroupVersion
.
WithResource
(
typesv1beta1
.
ResourcePluralFederatedApplication
)]
=
federatedapplication
.
New
(
factory
.
KubeSphereSharedInformerFactory
())
namespacedResourceG
etters
[
typesv1beta1
.
SchemeGroupVersion
.
WithResource
(
typesv1beta1
.
ResourcePluralFederatedPersistentVolumeClaim
)]
=
federatedpersistentvolumeclaim
.
New
(
factory
.
KubeSphereSharedInformerFactory
())
namespacedResourceG
etters
[
typesv1beta1
.
SchemeGroupVersion
.
WithResource
(
typesv1beta1
.
ResourcePluralFederatedStatefulSet
)]
=
federatedstatefulset
.
New
(
factory
.
KubeSphereSharedInformerFactory
())
namespacedResourceG
etters
[
typesv1beta1
.
SchemeGroupVersion
.
WithResource
(
typesv1beta1
.
ResourcePluralFederatedIngress
)]
=
federatedingress
.
New
(
factory
.
KubeSphereSharedInformerFactory
())
return
&
ResourceGetter
{
getters
:
getters
,
namespacedResourceGetters
:
namespacedResourceGetters
,
clusterResourceGetters
:
clusterResourceGetters
,
}
}
// TryResource will retrieve a getter with resource name, it doesn't guarantee find resource with correct group version
// need to refactor this use schema.GroupVersionResource
func
(
r
*
ResourceGetter
)
TryResource
(
resource
string
)
v1alpha3
.
Interface
{
for
k
,
v
:=
range
r
.
getters
{
func
(
r
*
ResourceGetter
)
TryResource
(
clusterScope
bool
,
resource
string
)
v1alpha3
.
Interface
{
if
clusterScope
{
for
k
,
v
:=
range
r
.
clusterResourceGetters
{
if
k
.
Resource
==
resource
{
return
v
}
}
}
for
k
,
v
:=
range
r
.
namespacedResourceGetters
{
if
k
.
Resource
==
resource
{
return
v
}
...
...
@@ -157,7 +167,8 @@ func (r *ResourceGetter) TryResource(resource string) v1alpha3.Interface {
}
func
(
r
*
ResourceGetter
)
Get
(
resource
,
namespace
,
name
string
)
(
runtime
.
Object
,
error
)
{
getter
:=
r
.
TryResource
(
resource
)
clusterScope
:=
namespace
==
""
getter
:=
r
.
TryResource
(
clusterScope
,
resource
)
if
getter
==
nil
{
return
nil
,
ErrResourceNotSupported
}
...
...
@@ -165,7 +176,8 @@ func (r *ResourceGetter) Get(resource, namespace, name string) (runtime.Object,
}
func
(
r
*
ResourceGetter
)
List
(
resource
,
namespace
string
,
query
*
query
.
Query
)
(
*
api
.
ListResult
,
error
)
{
getter
:=
r
.
TryResource
(
resource
)
clusterScope
:=
namespace
==
""
getter
:=
r
.
TryResource
(
clusterScope
,
resource
)
if
getter
==
nil
{
return
nil
,
ErrResourceNotSupported
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录