Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
水淹萌龙
kubesphere
提交
5dffb730
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看板
未验证
提交
5dffb730
编写于
3月 19, 2020
作者:
R
runzexia
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add code comments
Signed-off-by:
N
runzexia
<
runzexia@yunify.com
>
上级
e4f2cdc3
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
33 addition
and
11 deletion
+33
-11
pkg/controller/devopsproject/devopsproject_controller.go
pkg/controller/devopsproject/devopsproject_controller.go
+9
-0
pkg/controller/s2ibinary/s2ibinary_controller.go
pkg/controller/s2ibinary/s2ibinary_controller.go
+14
-10
pkg/controller/s2ibinary/s2ibinary_controller_test.go
pkg/controller/s2ibinary/s2ibinary_controller_test.go
+1
-1
pkg/controller/s2irun/s2irun_controller.go
pkg/controller/s2irun/s2irun_controller.go
+9
-0
未找到文件。
pkg/controller/devopsproject/devopsproject_controller.go
浏览文件 @
5dffb730
...
...
@@ -24,6 +24,10 @@ import (
devopslisters
"kubesphere.io/kubesphere/pkg/client/listers/devops/v1alpha3"
)
/**
DevOps project controller is used to maintain the state of the DevOps project.
*/
type
Controller
struct
{
client
clientset
.
Interface
kubesphereClient
kubesphereclient
.
Interface
...
...
@@ -171,7 +175,10 @@ func (c *Controller) syncHandler(key string) error {
klog
.
Error
(
err
,
fmt
.
Sprintf
(
"could not get devopsproject %s "
,
key
))
return
err
}
// DeletionTimestamp.IsZero() means DevOps project has not been deleted.
if
project
.
ObjectMeta
.
DeletionTimestamp
.
IsZero
()
{
// Use Finalizers to sync DevOps status when DevOps project was deleted
// https://kubernetes.io/docs/tasks/access-kubernetes-api/custom-resources/custom-resource-definitions/#finalizers
if
!
sliceutil
.
HasString
(
project
.
ObjectMeta
.
Finalizers
,
devopsv1alpha3
.
DevOpsProjectFinalizerName
)
{
project
.
ObjectMeta
.
Finalizers
=
append
(
project
.
ObjectMeta
.
Finalizers
,
devopsv1alpha3
.
DevOpsProjectFinalizerName
)
_
,
err
:=
c
.
kubesphereClient
.
DevopsV1alpha3
()
.
DevOpsProjects
()
.
Update
(
project
)
...
...
@@ -180,6 +187,7 @@ func (c *Controller) syncHandler(key string) error {
return
err
}
}
// Check project exists, otherwise we will create it.
_
,
err
:=
c
.
devopsClient
.
GetDevOpsProject
(
key
)
if
err
!=
nil
&&
devopsClient
.
GetDevOpsStatusCode
(
err
)
!=
http
.
StatusNotFound
{
klog
.
Error
(
err
,
fmt
.
Sprintf
(
"failed to get project %s "
,
key
))
...
...
@@ -192,6 +200,7 @@ func (c *Controller) syncHandler(key string) error {
}
}
}
else
{
// Finalizers processing logic
if
sliceutil
.
HasString
(
project
.
ObjectMeta
.
Finalizers
,
devopsv1alpha3
.
DevOpsProjectFinalizerName
)
{
_
,
err
:=
c
.
devopsClient
.
GetDevOpsProject
(
key
)
if
err
!=
nil
&&
devopsClient
.
GetDevOpsStatusCode
(
err
)
!=
http
.
StatusNotFound
{
...
...
pkg/controller/s2ibinary/s2ibinary_controller.go
浏览文件 @
5dffb730
...
...
@@ -23,7 +23,11 @@ import (
devopslisters
"kubesphere.io/kubesphere/pkg/client/listers/devops/v1alpha1"
)
type
S2iBinaryController
struct
{
/**
s2ibinary-controller used to handle s2ibinary's delete logic.
s2ibinary creation and file upload provided by kubesphere/kapis
*/
type
Controller
struct
{
client
clientset
.
Interface
devopsClient
devopsclient
.
Interface
...
...
@@ -43,7 +47,7 @@ type S2iBinaryController struct {
func
NewController
(
client
clientset
.
Interface
,
devopsclientset
devopsclient
.
Interface
,
s2ibinInformer
devopsinformers
.
S2iBinaryInformer
,
s3Client
s3
.
Interface
)
*
S2iBinary
Controller
{
s3Client
s3
.
Interface
)
*
Controller
{
broadcaster
:=
record
.
NewBroadcaster
()
broadcaster
.
StartLogging
(
func
(
format
string
,
args
...
interface
{})
{
...
...
@@ -52,7 +56,7 @@ func NewController(client clientset.Interface,
broadcaster
.
StartRecordingToSink
(
&
v1core
.
EventSinkImpl
{
Interface
:
client
.
CoreV1
()
.
Events
(
""
)})
recorder
:=
broadcaster
.
NewRecorder
(
scheme
.
Scheme
,
v1
.
EventSource
{
Component
:
"s2ibinary-controller"
})
v
:=
&
S2iBinary
Controller
{
v
:=
&
Controller
{
client
:
client
,
devopsClient
:
devopsclientset
,
workqueue
:
workqueue
.
NewNamedRateLimitingQueue
(
workqueue
.
DefaultControllerRateLimiter
(),
"s2ibinary"
),
...
...
@@ -83,7 +87,7 @@ func NewController(client clientset.Interface,
// enqueueS2iBinary takes a Foo resource and converts it into a namespace/name
// string which is then put onto the work workqueue. This method should *not* be
// passed resources of any type other than S2iBinary.
func
(
c
*
S2iBinary
Controller
)
enqueueS2iBinary
(
obj
interface
{})
{
func
(
c
*
Controller
)
enqueueS2iBinary
(
obj
interface
{})
{
var
key
string
var
err
error
if
key
,
err
=
cache
.
MetaNamespaceKeyFunc
(
obj
);
err
!=
nil
{
...
...
@@ -93,7 +97,7 @@ func (c *S2iBinaryController) enqueueS2iBinary(obj interface{}) {
c
.
workqueue
.
Add
(
key
)
}
func
(
c
*
S2iBinary
Controller
)
processNextWorkItem
()
bool
{
func
(
c
*
Controller
)
processNextWorkItem
()
bool
{
obj
,
shutdown
:=
c
.
workqueue
.
Get
()
if
shutdown
{
...
...
@@ -128,17 +132,17 @@ func (c *S2iBinaryController) processNextWorkItem() bool {
return
true
}
func
(
c
*
S2iBinary
Controller
)
worker
()
{
func
(
c
*
Controller
)
worker
()
{
for
c
.
processNextWorkItem
()
{
}
}
func
(
c
*
S2iBinary
Controller
)
Start
(
stopCh
<-
chan
struct
{})
error
{
func
(
c
*
Controller
)
Start
(
stopCh
<-
chan
struct
{})
error
{
return
c
.
Run
(
1
,
stopCh
)
}
func
(
c
*
S2iBinary
Controller
)
Run
(
workers
int
,
stopCh
<-
chan
struct
{})
error
{
func
(
c
*
Controller
)
Run
(
workers
int
,
stopCh
<-
chan
struct
{})
error
{
defer
utilruntime
.
HandleCrash
()
defer
c
.
workqueue
.
ShutDown
()
...
...
@@ -160,7 +164,7 @@ func (c *S2iBinaryController) Run(workers int, stopCh <-chan struct{}) error {
// syncHandler compares the actual state with the desired, and attempts to
// converge the two. It then updates the Status block of the Foo resource
// with the current status of the resource.
func
(
c
*
S2iBinary
Controller
)
syncHandler
(
key
string
)
error
{
func
(
c
*
Controller
)
syncHandler
(
key
string
)
error
{
namespace
,
name
,
err
:=
cache
.
SplitMetaNamespaceKey
(
key
)
if
err
!=
nil
{
klog
.
Error
(
err
,
fmt
.
Sprintf
(
"could not split s2ibin meta %s "
,
key
))
...
...
@@ -205,7 +209,7 @@ func (c *S2iBinaryController) syncHandler(key string) error {
return
nil
}
func
(
c
*
S2iBinary
Controller
)
deleteBinaryInS3
(
s2ibin
*
devopsv1alpha1
.
S2iBinary
)
error
{
func
(
c
*
Controller
)
deleteBinaryInS3
(
s2ibin
*
devopsv1alpha1
.
S2iBinary
)
error
{
key
:=
fmt
.
Sprintf
(
"%s-%s"
,
s2ibin
.
Namespace
,
s2ibin
.
Name
)
err
:=
c
.
s3Client
.
Delete
(
key
)
...
...
pkg/controller/s2ibinary/s2ibinary_controller_test.go
浏览文件 @
5dffb730
...
...
@@ -69,7 +69,7 @@ func newDeletingS2iBinary(name string) *s2i.S2iBinary {
}
}
func
(
f
*
fixture
)
newController
()
(
*
S2iBinary
Controller
,
informers
.
SharedInformerFactory
,
*
fakeS3
.
FakeS3
)
{
func
(
f
*
fixture
)
newController
()
(
*
Controller
,
informers
.
SharedInformerFactory
,
*
fakeS3
.
FakeS3
)
{
f
.
client
=
fake
.
NewSimpleClientset
(
f
.
objects
...
)
f
.
kubeclient
=
k8sfake
.
NewSimpleClientset
()
...
...
pkg/controller/s2irun/s2irun_controller.go
浏览文件 @
5dffb730
...
...
@@ -24,6 +24,10 @@ import (
devopslisters
"kubesphere.io/kubesphere/pkg/client/listers/devops/v1alpha1"
)
/**
s2irun-controller used to handle s2irun's delete logic.
s2irun creation and operation provided by s2ioperator
*/
type
Controller
struct
{
client
clientset
.
Interface
...
...
@@ -214,6 +218,11 @@ func (c Controller) syncHandler(key string) error {
return
nil
}
/**
DeleteS2iBinary mainly cleans up two parts of S2iBinary
1. s2ibinary bound to s2irun
2. s2ibinary that has been created for more than 24 hours but has not been used
*/
func
(
c
Controller
)
DeleteS2iBinary
(
s2irun
*
devopsv1alpha1
.
S2iRun
)
error
{
s2iBinName
:=
s2irun
.
Labels
[
devopsv1alpha1
.
S2iBinaryLabelKey
]
s2iBin
,
err
:=
c
.
s2iBinaryLister
.
S2iBinaries
(
s2irun
.
Namespace
)
.
Get
(
s2iBinName
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录