Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
水淹萌龙
kubesphere
提交
3ff82c72
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看板
未验证
提交
3ff82c72
编写于
5月 06, 2020
作者:
K
KubeSphere CI Bot
提交者:
GitHub
5月 06, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2041 from duanjiong/networkpolicy-resource
add k8s networkpolicy resource
上级
98f44fac
7e0983ad
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
156 addition
and
0 deletion
+156
-0
pkg/apiserver/apiserver.go
pkg/apiserver/apiserver.go
+2
-0
pkg/models/resources/v1alpha3/networkpolicy/networkpolicies.go
...odels/resources/v1alpha3/networkpolicy/networkpolicies.go
+59
-0
pkg/models/resources/v1alpha3/networkpolicy/networkpolicies_test.go
.../resources/v1alpha3/networkpolicy/networkpolicies_test.go
+93
-0
pkg/models/resources/v1alpha3/resource/resource.go
pkg/models/resources/v1alpha3/resource/resource.go
+2
-0
未找到文件。
pkg/apiserver/apiserver.go
浏览文件 @
3ff82c72
...
...
@@ -300,6 +300,8 @@ func (s *APIServer) waitForResourceSync(stopCh <-chan struct{}) error {
{
Group
:
"extensions"
,
Version
:
"v1beta1"
,
Resource
:
"ingresses"
},
{
Group
:
"autoscaling"
,
Version
:
"v2beta2"
,
Resource
:
"horizontalpodautoscalers"
},
{
Group
:
"networking.k8s.io"
,
Version
:
"v1"
,
Resource
:
"networkpolicies"
},
}
for
_
,
gvr
:=
range
k8sGVRs
{
...
...
pkg/models/resources/v1alpha3/networkpolicy/networkpolicies.go
0 → 100644
浏览文件 @
3ff82c72
package
networkpolicy
import
(
v1
"k8s.io/api/networking/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/informers"
"kubesphere.io/kubesphere/pkg/api"
"kubesphere.io/kubesphere/pkg/apiserver/query"
"kubesphere.io/kubesphere/pkg/models/resources/v1alpha3"
)
type
networkpolicyGetter
struct
{
informers
informers
.
SharedInformerFactory
}
func
New
(
informers
informers
.
SharedInformerFactory
)
v1alpha3
.
Interface
{
return
&
networkpolicyGetter
{
informers
:
informers
}
}
func
(
n
networkpolicyGetter
)
Get
(
namespace
,
name
string
)
(
runtime
.
Object
,
error
)
{
return
n
.
informers
.
Networking
()
.
V1
()
.
NetworkPolicies
()
.
Lister
()
.
NetworkPolicies
(
namespace
)
.
Get
(
name
)
}
func
(
n
networkpolicyGetter
)
List
(
namespace
string
,
query
*
query
.
Query
)
(
*
api
.
ListResult
,
error
)
{
nps
,
err
:=
n
.
informers
.
Networking
()
.
V1
()
.
NetworkPolicies
()
.
Lister
()
.
NetworkPolicies
(
namespace
)
.
List
(
labels
.
Everything
())
if
err
!=
nil
{
return
nil
,
err
}
var
result
[]
runtime
.
Object
for
_
,
item
:=
range
nps
{
result
=
append
(
result
,
item
)
}
return
v1alpha3
.
DefaultList
(
result
,
query
,
n
.
compare
,
n
.
filter
),
nil
}
func
(
n
networkpolicyGetter
)
filter
(
item
runtime
.
Object
,
filter
query
.
Filter
)
bool
{
np
,
ok
:=
item
.
(
*
v1
.
NetworkPolicy
)
if
!
ok
{
return
false
}
return
v1alpha3
.
DefaultObjectMetaFilter
(
np
.
ObjectMeta
,
filter
)
}
func
(
n
networkpolicyGetter
)
compare
(
left
runtime
.
Object
,
right
runtime
.
Object
,
field
query
.
Field
)
bool
{
leftNP
,
ok
:=
left
.
(
*
v1
.
NetworkPolicy
)
if
!
ok
{
return
false
}
rightNP
,
ok
:=
right
.
(
*
v1
.
NetworkPolicy
)
if
!
ok
{
return
true
}
return
v1alpha3
.
DefaultObjectMetaCompare
(
leftNP
.
ObjectMeta
,
rightNP
.
ObjectMeta
,
field
)
}
pkg/models/resources/v1alpha3/networkpolicy/networkpolicies_test.go
0 → 100644
浏览文件 @
3ff82c72
package
networkpolicy
import
(
"github.com/google/go-cmp/cmp"
netv1
"k8s.io/api/networking/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes/fake"
"kubesphere.io/kubesphere/pkg/api"
"kubesphere.io/kubesphere/pkg/apiserver/query"
"kubesphere.io/kubesphere/pkg/models/resources/v1alpha3"
"testing"
)
func
TestListNetworkPolicies
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
description
string
namespace
string
query
*
query
.
Query
expected
*
api
.
ListResult
expectedErr
error
}{
{
"test name filter"
,
"default"
,
&
query
.
Query
{
Pagination
:
&
query
.
Pagination
{
Limit
:
10
,
Offset
:
0
,
},
SortBy
:
query
.
FieldName
,
Ascending
:
false
,
Filters
:
map
[
query
.
Field
]
query
.
Value
{
query
.
FieldNamespace
:
query
.
Value
(
"default"
),
},
},
&
api
.
ListResult
{
Items
:
[]
interface
{}{
foo3
,
foo2
,
foo1
},
TotalItems
:
len
(
networkpolicies
),
},
nil
,
},
}
getter
:=
prepare
()
for
_
,
test
:=
range
tests
{
got
,
err
:=
getter
.
List
(
test
.
namespace
,
test
.
query
)
if
test
.
expectedErr
!=
nil
&&
err
!=
test
.
expectedErr
{
t
.
Errorf
(
"expected error, got nothing"
)
}
else
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
diff
:=
cmp
.
Diff
(
got
,
test
.
expected
);
diff
!=
""
{
t
.
Errorf
(
"%T differ (-got, +want): %s"
,
test
.
expected
,
diff
)
}
}
}
var
(
foo1
=
&
netv1
.
NetworkPolicy
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"foo1"
,
Namespace
:
"default"
,
},
}
foo2
=
&
netv1
.
NetworkPolicy
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"foo2"
,
Namespace
:
"default"
,
},
}
foo3
=
&
netv1
.
NetworkPolicy
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"foo3"
,
Namespace
:
"default"
,
},
}
networkpolicies
=
[]
interface
{}{
foo1
,
foo2
,
foo3
}
)
func
prepare
()
v1alpha3
.
Interface
{
client
:=
fake
.
NewSimpleClientset
()
informer
:=
informers
.
NewSharedInformerFactory
(
client
,
0
)
for
_
,
networkpolicy
:=
range
networkpolicies
{
informer
.
Networking
()
.
V1
()
.
NetworkPolicies
()
.
Informer
()
.
GetIndexer
()
.
Add
(
networkpolicy
)
}
return
New
(
informer
)
}
pkg/models/resources/v1alpha3/resource/resource.go
浏览文件 @
3ff82c72
...
...
@@ -35,6 +35,7 @@ import (
"kubesphere.io/kubesphere/pkg/models/resources/v1alpha3/deployment"
"kubesphere.io/kubesphere/pkg/models/resources/v1alpha3/globalrole"
"kubesphere.io/kubesphere/pkg/models/resources/v1alpha3/namespace"
"kubesphere.io/kubesphere/pkg/models/resources/v1alpha3/networkpolicy"
"kubesphere.io/kubesphere/pkg/models/resources/v1alpha3/pod"
"kubesphere.io/kubesphere/pkg/models/resources/v1alpha3/role"
"kubesphere.io/kubesphere/pkg/models/resources/v1alpha3/user"
...
...
@@ -56,6 +57,7 @@ func NewResourceGetter(factory informers.InformerFactory) *ResourceGetter {
getters
[
schema
.
GroupVersionResource
{
Group
:
""
,
Version
:
"v1"
,
Resource
:
"configmaps"
}]
=
configmap
.
New
(
factory
.
KubernetesSharedInformerFactory
())
getters
[
schema
.
GroupVersionResource
{
Group
:
""
,
Version
:
"v1"
,
Resource
:
"pods"
}]
=
pod
.
New
(
factory
.
KubernetesSharedInformerFactory
())
getters
[
schema
.
GroupVersionResource
{
Group
:
"app.k8s.io"
,
Version
:
"v1beta1"
,
Resource
:
"applications"
}]
=
application
.
New
(
factory
.
ApplicationSharedInformerFactory
())
getters
[
schema
.
GroupVersionResource
{
Group
:
"networking.k8s.io"
,
Version
:
"v1"
,
Resource
:
"networkpolicies"
}]
=
networkpolicy
.
New
(
factory
.
KubernetesSharedInformerFactory
())
getters
[
tenantv1alpha1
.
SchemeGroupVersion
.
WithResource
(
tenantv1alpha1
.
ResourcePluralWorkspace
)]
=
workspace
.
New
(
factory
.
KubeSphereSharedInformerFactory
())
getters
[
iamv1alpha2
.
SchemeGroupVersion
.
WithResource
(
iamv1alpha2
.
ResourcesPluralGlobalRole
)]
=
globalrole
.
New
(
factory
.
KubeSphereSharedInformerFactory
())
getters
[
iamv1alpha2
.
SchemeGroupVersion
.
WithResource
(
iamv1alpha2
.
ResourcesPluralWorkspaceRole
)]
=
workspacerole
.
New
(
factory
.
KubeSphereSharedInformerFactory
())
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录