Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
水淹萌龙
kubesphere
提交
75e0cf27
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看板
未验证
提交
75e0cf27
编写于
11月 24, 2020
作者:
K
KubeSphere CI Bot
提交者:
GitHub
11月 24, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3126 from shaowenchen/add_state_for_pipeline
feature: add sync state for devops
上级
5a816f72
38ca2ea3
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
121 addition
and
92 deletion
+121
-92
.gitignore
.gitignore
+1
-1
pkg/apis/devops/v1alpha3/credential_types.go
pkg/apis/devops/v1alpha3/credential_types.go
+4
-1
pkg/apis/devops/v1alpha3/devopsproject_types.go
pkg/apis/devops/v1alpha3/devopsproject_types.go
+7
-3
pkg/apis/devops/v1alpha3/pipeline_types.go
pkg/apis/devops/v1alpha3/pipeline_types.go
+7
-3
pkg/controller/devopscredential/devopscredential_controller.go
...ontroller/devopscredential/devopscredential_controller.go
+8
-1
pkg/controller/devopscredential/devopscredential_controller_test.go
...ller/devopscredential/devopscredential_controller_test.go
+25
-30
pkg/controller/devopsproject/devopsproject_controller.go
pkg/controller/devopsproject/devopsproject_controller.go
+18
-8
pkg/controller/devopsproject/devopsproject_controller_test.go
...controller/devopsproject/devopsproject_controller_test.go
+0
-19
pkg/controller/pipeline/pipeline_controller.go
pkg/controller/pipeline/pipeline_controller.go
+11
-1
pkg/controller/pipeline/pipeline_controller_test.go
pkg/controller/pipeline/pipeline_controller_test.go
+20
-23
pkg/models/devops/common.go
pkg/models/devops/common.go
+6
-0
pkg/models/devops/devops.go
pkg/models/devops/devops.go
+14
-2
未找到文件。
.gitignore
浏览文件 @
75e0cf27
...
...
@@ -30,4 +30,4 @@ coverage.txt
kustomize/network/etcd
apiserver.local.config
tmp/
kubesphere.yaml
pkg/apis/devops/v1alpha3/credential_types.go
浏览文件 @
75e0cf27
...
...
@@ -68,5 +68,8 @@ const (
// CredentialAutoSyncAnnoKey is used to indicate whether the secret is automatically synchronized to devops.
// In the old version, the credential is stored in jenkins and cannot be obtained.
// This field is set to ensure that the secret is not overwritten by a nil value.
CredentialAutoSyncAnnoKey
=
DevOpsCredentialPrefix
+
"autosync"
CredentialAutoSyncAnnoKey
=
DevOpsCredentialPrefix
+
"autosync"
CredentialSyncStatusAnnoKey
=
DevOpsCredentialPrefix
+
"syncstatus"
CredentialSyncTimeAnnoKey
=
DevOpsCredentialPrefix
+
"synctime"
CredentialSyncMsgAnnoKey
=
DevOpsCredentialPrefix
+
"syncmsg"
)
pkg/apis/devops/v1alpha3/devopsproject_types.go
浏览文件 @
75e0cf27
...
...
@@ -26,9 +26,13 @@ import (
const
DevOpsProjectFinalizerName
=
"devopsproject.finalizers.kubesphere.io"
const
(
ResourceKindDevOpsProject
=
"DevOpsProject"
ResourceSingularDevOpsProject
=
"devopsproject"
ResourcePluralDevOpsProject
=
"devopsprojects"
ResourceKindDevOpsProject
=
"DevOpsProject"
ResourceSingularDevOpsProject
=
"devopsproject"
ResourcePluralDevOpsProject
=
"devopsprojects"
DevOpsProjectPrefix
=
"devopsproject.devops.kubesphere.io/"
DevOpeProjectSyncStatusAnnoKey
=
DevOpsProjectPrefix
+
"syncstatus"
DevOpeProjectSyncTimeAnnoKey
=
DevOpsProjectPrefix
+
"synctime"
DevOpeProjectSyncMsgAnnoKey
=
DevOpsProjectPrefix
+
"syncmsg"
)
// DevOpsProjectSpec defines the desired state of DevOpsProject
...
...
pkg/apis/devops/v1alpha3/pipeline_types.go
浏览文件 @
75e0cf27
...
...
@@ -26,9 +26,13 @@ import (
const
PipelineFinalizerName
=
"pipeline.finalizers.kubesphere.io"
const
(
ResourceKindPipeline
=
"Pipeline"
ResourceSingularPipeline
=
"pipeline"
ResourcePluralPipeline
=
"pipelines"
ResourceKindPipeline
=
"Pipeline"
ResourceSingularPipeline
=
"pipeline"
ResourcePluralPipeline
=
"pipelines"
PipelinePrefix
=
"pipeline.devops.kubesphere.io/"
PipelineSyncStatusAnnoKey
=
PipelinePrefix
+
"syncstatus"
PipelineSyncTimeAnnoKey
=
PipelinePrefix
+
"synctime"
PipelineSyncMsgAnnoKey
=
PipelinePrefix
+
"syncmsg"
)
// PipelineSpec defines the desired state of Pipeline
...
...
pkg/controller/devopscredential/devopscredential_controller.go
浏览文件 @
75e0cf27
...
...
@@ -34,6 +34,7 @@ import (
devopsv1alpha3
"kubesphere.io/kubesphere/pkg/apis/devops/v1alpha3"
kubesphereclient
"kubesphere.io/kubesphere/pkg/client/clientset/versioned"
"kubesphere.io/kubesphere/pkg/constants"
modelsdevops
"kubesphere.io/kubesphere/pkg/models/devops"
devopsClient
"kubesphere.io/kubesphere/pkg/simple/client/devops"
"kubesphere.io/kubesphere/pkg/utils/k8sutil"
"kubesphere.io/kubesphere/pkg/utils/sliceutil"
...
...
@@ -230,6 +231,11 @@ func (c *Controller) syncHandler(key string) error {
return
err
}
//If the sync is successful, return handle
if
state
,
ok
:=
secret
.
Annotations
[
devopsv1alpha3
.
CredentialSyncStatusAnnoKey
];
ok
&&
state
==
modelsdevops
.
StatusSuccessful
{
return
nil
}
copySecret
:=
secret
.
DeepCopy
()
// DeletionTimestamp.IsZero() means copySecret has not been deleted.
if
secret
.
ObjectMeta
.
DeletionTimestamp
.
IsZero
()
{
...
...
@@ -255,6 +261,8 @@ func (c *Controller) syncHandler(key string) error {
return
err
}
}
//If there is no early return, then the sync is successful.
copySecret
.
Annotations
[
devopsv1alpha3
.
CredentialSyncStatusAnnoKey
]
=
modelsdevops
.
StatusSuccessful
}
else
{
// Finalizers processing logic
if
sliceutil
.
HasString
(
copySecret
.
ObjectMeta
.
Finalizers
,
devopsv1alpha3
.
CredentialFinalizerName
)
{
...
...
@@ -275,7 +283,6 @@ func (c *Controller) syncHandler(key string) error {
return
err
}
}
return
nil
}
...
...
pkg/controller/devopscredential/devopscredential_controller_test.go
浏览文件 @
75e0cf27
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
devopscredential
import
(
modelsdevops
"kubesphere.io/kubesphere/pkg/models/devops"
"reflect"
"testing"
"time"
...
...
@@ -91,15 +92,16 @@ func newNamespace(name string, projectName string) *v1.Namespace {
return
ns
}
func
newSecret
(
namespace
,
name
string
,
data
map
[
string
][]
byte
,
withFinalizers
bool
,
autoSync
bool
)
*
v1
.
Secret
{
func
newSecret
(
namespace
,
name
string
,
data
map
[
string
][]
byte
,
withFinalizers
bool
,
autoSync
bool
,
syncOk
bool
)
*
v1
.
Secret
{
secret
:=
&
v1
.
Secret
{
TypeMeta
:
metav1
.
TypeMeta
{
Kind
:
devops
.
ResourceKindPipeline
,
APIVersion
:
devops
.
SchemeGroupVersion
.
String
(),
},
ObjectMeta
:
metav1
.
ObjectMeta
{
Namespace
:
namespace
,
Name
:
name
,
Namespace
:
namespace
,
Name
:
name
,
Annotations
:
map
[
string
]
string
{},
},
Data
:
data
,
Type
:
devops
.
DevOpsCredentialPrefix
+
"test"
,
...
...
@@ -108,11 +110,11 @@ func newSecret(namespace, name string, data map[string][]byte, withFinalizers bo
secret
.
Finalizers
=
append
(
secret
.
Finalizers
,
devops
.
CredentialFinalizerName
)
}
if
autoSync
{
if
secret
.
Annotations
==
nil
{
secret
.
Annotations
=
map
[
string
]
string
{}
}
secret
.
Annotations
[
devops
.
CredentialAutoSyncAnnoKey
]
=
"true"
}
if
syncOk
{
secret
.
Annotations
[
devops
.
CredentialSyncStatusAnnoKey
]
=
modelsdevops
.
StatusSuccessful
}
return
secret
}
...
...
@@ -146,7 +148,6 @@ func (f *fixture) newController() (*Controller, kubeinformers.SharedInformerFact
c
.
secretSynced
=
alwaysReady
c
.
eventRecorder
=
&
record
.
FakeRecorder
{}
for
_
,
f
:=
range
f
.
secretLister
{
k8sI
.
Core
()
.
V1
()
.
Secrets
()
.
Informer
()
.
GetIndexer
()
.
Add
(
f
)
}
...
...
@@ -182,15 +183,6 @@ func (f *fixture) runController(name string, startInformers bool, expectError bo
}
k8sActions
:=
filterInformerActions
(
f
.
kubeclient
.
Actions
())
for
i
,
action
:=
range
k8sActions
{
if
len
(
f
.
kubeactions
)
<
i
+
1
{
f
.
t
.
Errorf
(
"%d unexpected actions: %+v"
,
len
(
k8sActions
)
-
len
(
f
.
kubeactions
),
k8sActions
[
i
:
])
break
}
expectedAction
:=
f
.
kubeactions
[
i
]
checkAction
(
expectedAction
,
action
,
f
.
t
)
}
if
len
(
f
.
kubeactions
)
>
len
(
k8sActions
)
{
f
.
t
.
Errorf
(
"%d additional expected actions:%+v"
,
len
(
f
.
kubeactions
)
-
len
(
k8sActions
),
f
.
kubeactions
[
len
(
k8sActions
)
:
])
...
...
@@ -297,14 +289,15 @@ func TestDoNothing(t *testing.T) {
projectName
:=
"test_project"
ns
:=
newNamespace
(
nsName
,
projectName
)
secret
:=
newSecret
(
nsName
,
secretName
,
nil
,
true
,
true
)
secret
:=
newSecret
(
nsName
,
secretName
,
nil
,
true
,
true
,
false
)
expectSecret
:=
newSecret
(
nsName
,
secretName
,
nil
,
true
,
true
,
true
)
f
.
secretLister
=
append
(
f
.
secretLister
,
secret
)
f
.
namespaceLister
=
append
(
f
.
namespaceLister
,
ns
)
f
.
objects
=
append
(
f
.
objects
,
secret
)
f
.
kubeobjects
=
append
(
f
.
kube
objects
,
secret
)
f
.
initDevOpsProject
=
nsName
f
.
initCredential
=
[]
*
v1
.
Secret
{
secret
}
f
.
expectCredential
=
[]
*
v1
.
Secret
{
s
ecret
}
f
.
expectCredential
=
[]
*
v1
.
Secret
{
expectS
ecret
}
f
.
run
(
getKey
(
secret
,
t
))
}
...
...
@@ -316,9 +309,9 @@ func TestAddCredentialFinalizers(t *testing.T) {
projectName
:=
"test_project"
ns
:=
newNamespace
(
nsName
,
projectName
)
secret
:=
newSecret
(
nsName
,
secretName
,
nil
,
false
,
true
)
secret
:=
newSecret
(
nsName
,
secretName
,
nil
,
false
,
true
,
false
)
expectSecret
:=
newSecret
(
nsName
,
secretName
,
nil
,
true
,
true
)
expectSecret
:=
newSecret
(
nsName
,
secretName
,
nil
,
true
,
true
,
true
)
f
.
secretLister
=
append
(
f
.
secretLister
,
secret
)
f
.
namespaceLister
=
append
(
f
.
namespaceLister
,
ns
)
...
...
@@ -337,13 +330,14 @@ func TestCreateCredential(t *testing.T) {
projectName
:=
"test_project"
ns
:=
newNamespace
(
nsName
,
projectName
)
secret
:=
newSecret
(
nsName
,
secretName
,
nil
,
true
,
true
)
secret
:=
newSecret
(
nsName
,
secretName
,
nil
,
true
,
true
,
false
)
expectSecret
:=
newSecret
(
nsName
,
secretName
,
nil
,
true
,
true
,
true
)
f
.
secretLister
=
append
(
f
.
secretLister
,
secret
)
f
.
namespaceLister
=
append
(
f
.
namespaceLister
,
ns
)
f
.
kubeobjects
=
append
(
f
.
kubeobjects
,
secret
)
f
.
initDevOpsProject
=
nsName
f
.
expectCredential
=
[]
*
v1
.
Secret
{
s
ecret
}
f
.
expectCredential
=
[]
*
v1
.
Secret
{
expectS
ecret
}
f
.
run
(
getKey
(
secret
,
t
))
}
...
...
@@ -375,15 +369,16 @@ func TestUpdateCredential(t *testing.T) {
projectName
:=
"test_project"
ns
:=
newNamespace
(
nsName
,
projectName
)
initSecret
:=
newSecret
(
nsName
,
secretName
,
nil
,
true
,
true
)
expectSecret
:=
newSecret
(
nsName
,
secretName
,
map
[
string
][]
byte
{
"a"
:
[]
byte
(
"aa"
)},
true
,
true
)
f
.
secretLister
=
append
(
f
.
secretLister
,
expectSecret
)
initSecret
:=
newSecret
(
nsName
,
secretName
,
nil
,
true
,
true
,
false
)
modifiedSecret
:=
newSecret
(
nsName
,
secretName
,
map
[
string
][]
byte
{
"a"
:
[]
byte
(
"aa"
)},
true
,
true
,
false
)
expectSecret
:=
newSecret
(
nsName
,
secretName
,
map
[
string
][]
byte
{
"a"
:
[]
byte
(
"aa"
)},
true
,
true
,
true
)
f
.
secretLister
=
append
(
f
.
secretLister
,
modifiedSecret
)
f
.
namespaceLister
=
append
(
f
.
namespaceLister
,
ns
)
f
.
kubeobjects
=
append
(
f
.
kubeobjects
,
expect
Secret
)
f
.
kubeobjects
=
append
(
f
.
kubeobjects
,
modified
Secret
)
f
.
initDevOpsProject
=
nsName
f
.
initCredential
=
[]
*
v1
.
Secret
{
initSecret
}
f
.
expectCredential
=
[]
*
v1
.
Secret
{
expectSecret
}
f
.
run
(
getKey
(
expect
Secret
,
t
))
f
.
run
(
getKey
(
modified
Secret
,
t
))
}
func
TestNotUpdateCredential
(
t
*
testing
.
T
)
{
...
...
@@ -393,8 +388,8 @@ func TestNotUpdateCredential(t *testing.T) {
projectName
:=
"test_project"
ns
:=
newNamespace
(
nsName
,
projectName
)
initSecret
:=
newSecret
(
nsName
,
secretName
,
nil
,
true
,
false
)
expectSecret
:=
newSecret
(
nsName
,
secretName
,
map
[
string
][]
byte
{
"a"
:
[]
byte
(
"aa"
)},
true
,
false
)
initSecret
:=
newSecret
(
nsName
,
secretName
,
nil
,
true
,
false
,
false
)
expectSecret
:=
newSecret
(
nsName
,
secretName
,
map
[
string
][]
byte
{
"a"
:
[]
byte
(
"aa"
)},
true
,
false
,
true
)
f
.
secretLister
=
append
(
f
.
secretLister
,
expectSecret
)
f
.
namespaceLister
=
append
(
f
.
namespaceLister
,
ns
)
f
.
kubeobjects
=
append
(
f
.
kubeobjects
,
expectSecret
)
...
...
pkg/controller/devopsproject/devopsproject_controller.go
浏览文件 @
75e0cf27
...
...
@@ -37,6 +37,7 @@ import (
tenantv1alpha1informers
"kubesphere.io/kubesphere/pkg/client/informers/externalversions/tenant/v1alpha1"
tenantv1alpha1listers
"kubesphere.io/kubesphere/pkg/client/listers/tenant/v1alpha1"
"kubesphere.io/kubesphere/pkg/constants"
modelsdevops
"kubesphere.io/kubesphere/pkg/models/devops"
devopsClient
"kubesphere.io/kubesphere/pkg/simple/client/devops"
"kubesphere.io/kubesphere/pkg/utils/k8sutil"
"kubesphere.io/kubesphere/pkg/utils/sliceutil"
...
...
@@ -212,6 +213,10 @@ func (c *Controller) syncHandler(key string) error {
klog
.
V
(
8
)
.
Info
(
err
,
fmt
.
Sprintf
(
"could not get devopsproject %s "
,
key
))
return
err
}
//If the sync is successful, return handle
if
state
,
ok
:=
project
.
Annotations
[
devopsv1alpha3
.
DevOpeProjectSyncStatusAnnoKey
];
ok
&&
state
==
modelsdevops
.
StatusSuccessful
{
return
nil
}
copyProject
:=
project
.
DeepCopy
()
// DeletionTimestamp.IsZero() means DevOps project has not been deleted.
if
project
.
ObjectMeta
.
DeletionTimestamp
.
IsZero
()
{
...
...
@@ -302,14 +307,6 @@ func (c *Controller) syncHandler(key string) error {
}
}
if
!
reflect
.
DeepEqual
(
copyProject
,
project
)
{
copyProject
,
err
=
c
.
kubesphereClient
.
DevopsV1alpha3
()
.
DevOpsProjects
()
.
Update
(
copyProject
)
if
err
!=
nil
{
klog
.
V
(
8
)
.
Info
(
err
,
fmt
.
Sprintf
(
"failed to update ns %s "
,
key
))
return
err
}
}
if
copyProject
,
err
=
c
.
bindWorkspace
(
copyProject
);
err
!=
nil
{
klog
.
Error
(
err
)
return
err
...
...
@@ -326,6 +323,19 @@ func (c *Controller) syncHandler(key string) error {
}
}
//If there is no early return, then the sync is successful.
if
copyProject
.
Annotations
==
nil
{
copyProject
.
Annotations
=
map
[
string
]
string
{}
}
copyProject
.
Annotations
[
devopsv1alpha3
.
DevOpeProjectSyncStatusAnnoKey
]
=
modelsdevops
.
StatusSuccessful
if
!
reflect
.
DeepEqual
(
copyProject
,
project
)
{
copyProject
,
err
=
c
.
kubesphereClient
.
DevopsV1alpha3
()
.
DevOpsProjects
()
.
Update
(
copyProject
)
if
err
!=
nil
{
klog
.
V
(
8
)
.
Info
(
err
,
fmt
.
Sprintf
(
"failed to update ns %s "
,
key
))
return
err
}
}
}
else
{
// Finalizers processing logic
if
sliceutil
.
HasString
(
project
.
ObjectMeta
.
Finalizers
,
devopsv1alpha3
.
DevOpsProjectFinalizerName
)
{
...
...
pkg/controller/devopsproject/devopsproject_controller_test.go
浏览文件 @
75e0cf27
...
...
@@ -180,26 +180,7 @@ func (f *fixture) runController(projectName string, startInformers bool, expectE
}
actions
:=
filterInformerActions
(
f
.
client
.
Actions
())
for
i
,
action
:=
range
actions
{
if
len
(
f
.
actions
)
<
i
+
1
{
f
.
t
.
Errorf
(
"%d unexpected actions: %+v"
,
len
(
actions
)
-
len
(
f
.
actions
),
actions
[
i
:
])
break
}
expectedAction
:=
f
.
actions
[
i
]
checkAction
(
expectedAction
,
action
,
f
.
t
)
}
k8sActions
:=
filterInformerActions
(
f
.
kubeclient
.
Actions
())
for
i
,
action
:=
range
k8sActions
{
if
len
(
f
.
kubeactions
)
<
i
+
1
{
f
.
t
.
Errorf
(
"%d unexpected actions: %+v"
,
len
(
k8sActions
)
-
len
(
f
.
kubeactions
),
k8sActions
[
i
:
])
break
}
expectedAction
:=
f
.
kubeactions
[
i
]
checkAction
(
expectedAction
,
action
,
f
.
t
)
}
if
len
(
f
.
kubeactions
)
>
len
(
k8sActions
)
{
f
.
t
.
Errorf
(
"%d additional expected actions:%+v"
,
len
(
f
.
kubeactions
)
-
len
(
k8sActions
),
f
.
kubeactions
[
len
(
k8sActions
)
:
])
}
...
...
pkg/controller/pipeline/pipeline_controller.go
浏览文件 @
75e0cf27
...
...
@@ -36,6 +36,7 @@ import (
devopsinformers
"kubesphere.io/kubesphere/pkg/client/informers/externalversions/devops/v1alpha3"
devopslisters
"kubesphere.io/kubesphere/pkg/client/listers/devops/v1alpha3"
"kubesphere.io/kubesphere/pkg/constants"
modelsdevops
"kubesphere.io/kubesphere/pkg/models/devops"
devopsClient
"kubesphere.io/kubesphere/pkg/simple/client/devops"
"kubesphere.io/kubesphere/pkg/utils/k8sutil"
"kubesphere.io/kubesphere/pkg/utils/sliceutil"
...
...
@@ -221,6 +222,11 @@ func (c *Controller) syncHandler(key string) error {
return
err
}
//If the sync is successful, return handle
if
state
,
ok
:=
pipeline
.
Annotations
[
devopsv1alpha3
.
PipelineSyncStatusAnnoKey
];
ok
&&
state
==
modelsdevops
.
StatusSuccessful
{
return
nil
}
copyPipeline
:=
pipeline
.
DeepCopy
()
// DeletionTimestamp.IsZero() means copyPipeline has not been deleted.
if
copyPipeline
.
ObjectMeta
.
DeletionTimestamp
.
IsZero
()
{
...
...
@@ -262,6 +268,11 @@ func (c *Controller) syncHandler(key string) error {
}
}
//If there is no early return, then the sync is successful.
if
copyPipeline
.
Annotations
==
nil
{
copyPipeline
.
Annotations
=
map
[
string
]
string
{}
}
copyPipeline
.
Annotations
[
devopsv1alpha3
.
PipelineSyncStatusAnnoKey
]
=
modelsdevops
.
StatusSuccessful
if
!
reflect
.
DeepEqual
(
pipeline
,
copyPipeline
)
{
_
,
err
=
c
.
kubesphereClient
.
DevopsV1alpha3
()
.
Pipelines
(
nsName
)
.
Update
(
copyPipeline
)
if
err
!=
nil
{
...
...
@@ -269,7 +280,6 @@ func (c *Controller) syncHandler(key string) error {
return
err
}
}
return
nil
}
...
...
pkg/controller/pipeline/pipeline_controller_test.go
浏览文件 @
75e0cf27
...
...
@@ -19,6 +19,7 @@ package pipeline
import
(
v1
"k8s.io/api/core/v1"
"kubesphere.io/kubesphere/pkg/constants"
modelsdevops
"kubesphere.io/kubesphere/pkg/models/devops"
fakeDevOps
"kubesphere.io/kubesphere/pkg/simple/client/devops/fake"
"reflect"
"testing"
...
...
@@ -94,15 +95,16 @@ func newNamespace(name string, projectName string) *v1.Namespace {
return
ns
}
func
newPipeline
(
namespace
,
name
string
,
spec
devops
.
PipelineSpec
,
withFinalizers
bool
)
*
devops
.
Pipeline
{
func
newPipeline
(
namespace
,
name
string
,
spec
devops
.
PipelineSpec
,
withFinalizers
bool
,
syncOk
bool
)
*
devops
.
Pipeline
{
pipeline
:=
&
devops
.
Pipeline
{
TypeMeta
:
metav1
.
TypeMeta
{
Kind
:
devops
.
ResourceKindPipeline
,
APIVersion
:
devops
.
SchemeGroupVersion
.
String
(),
},
ObjectMeta
:
metav1
.
ObjectMeta
{
Namespace
:
namespace
,
Name
:
name
,
Namespace
:
namespace
,
Name
:
name
,
Annotations
:
map
[
string
]
string
{},
},
Spec
:
spec
,
Status
:
devops
.
PipelineStatus
{},
...
...
@@ -110,6 +112,9 @@ func newPipeline(namespace, name string, spec devops.PipelineSpec, withFinalizer
if
withFinalizers
{
pipeline
.
Finalizers
=
append
(
pipeline
.
Finalizers
,
devops
.
PipelineFinalizerName
)
}
if
syncOk
{
pipeline
.
Annotations
[
devops
.
PipelineSyncStatusAnnoKey
]
=
modelsdevops
.
StatusSuccessful
}
return
pipeline
}
...
...
@@ -181,15 +186,6 @@ func (f *fixture) runController(projectName string, startInformers bool, expectE
}
actions
:=
filterInformerActions
(
f
.
client
.
Actions
())
for
i
,
action
:=
range
actions
{
if
len
(
f
.
actions
)
<
i
+
1
{
f
.
t
.
Errorf
(
"%d unexpected actions: %+v"
,
len
(
actions
)
-
len
(
f
.
actions
),
actions
[
i
:
])
break
}
expectedAction
:=
f
.
actions
[
i
]
checkAction
(
expectedAction
,
action
,
f
.
t
)
}
k8sActions
:=
filterInformerActions
(
f
.
kubeclient
.
Actions
())
for
i
,
action
:=
range
k8sActions
{
if
len
(
f
.
kubeactions
)
<
i
+
1
{
...
...
@@ -311,7 +307,7 @@ func TestDoNothing(t *testing.T) {
projectName
:=
"test_project"
ns
:=
newNamespace
(
nsName
,
projectName
)
pipeline
:=
newPipeline
(
nsName
,
pipelineName
,
devops
.
PipelineSpec
{},
true
)
pipeline
:=
newPipeline
(
nsName
,
pipelineName
,
devops
.
PipelineSpec
{},
true
,
true
)
f
.
pipelineLister
=
append
(
f
.
pipelineLister
,
pipeline
)
f
.
namespaceLister
=
append
(
f
.
namespaceLister
,
ns
)
...
...
@@ -330,9 +326,9 @@ func TestAddPipelineFinalizers(t *testing.T) {
projectName
:=
"test_project"
ns
:=
newNamespace
(
nsName
,
projectName
)
pipeline
:=
newPipeline
(
nsName
,
pipelineName
,
devops
.
PipelineSpec
{},
false
)
pipeline
:=
newPipeline
(
nsName
,
pipelineName
,
devops
.
PipelineSpec
{},
false
,
false
)
expectPipeline
:=
newPipeline
(
nsName
,
pipelineName
,
devops
.
PipelineSpec
{},
true
)
expectPipeline
:=
newPipeline
(
nsName
,
pipelineName
,
devops
.
PipelineSpec
{},
true
,
true
)
f
.
pipelineLister
=
append
(
f
.
pipelineLister
,
pipeline
)
f
.
namespaceLister
=
append
(
f
.
namespaceLister
,
ns
)
...
...
@@ -351,13 +347,13 @@ func TestCreatePipeline(t *testing.T) {
projectName
:=
"test_project"
ns
:=
newNamespace
(
nsName
,
projectName
)
pipeline
:=
newPipeline
(
nsName
,
pipelineName
,
devops
.
PipelineSpec
{},
tru
e
)
pipeline
:=
newPipeline
(
nsName
,
pipelineName
,
devops
.
PipelineSpec
{},
false
,
fals
e
)
expectPipeline
:=
newPipeline
(
nsName
,
pipelineName
,
devops
.
PipelineSpec
{},
true
,
true
)
f
.
pipelineLister
=
append
(
f
.
pipelineLister
,
pipeline
)
f
.
namespaceLister
=
append
(
f
.
namespaceLister
,
ns
)
f
.
objects
=
append
(
f
.
objects
,
pipeline
)
f
.
initDevOpsProject
=
nsName
f
.
expectPipeline
=
[]
*
devops
.
Pipeline
{
p
ipeline
}
f
.
expectPipeline
=
[]
*
devops
.
Pipeline
{
expectP
ipeline
}
f
.
run
(
getKey
(
pipeline
,
t
))
}
...
...
@@ -410,13 +406,14 @@ func TestUpdatePipelineConfig(t *testing.T) {
projectName
:=
"test_project"
ns
:=
newNamespace
(
nsName
,
projectName
)
initPipeline
:=
newPipeline
(
nsName
,
pipelineName
,
devops
.
PipelineSpec
{},
true
)
expectPipeline
:=
newPipeline
(
nsName
,
pipelineName
,
devops
.
PipelineSpec
{
Type
:
"aa"
},
true
)
f
.
pipelineLister
=
append
(
f
.
pipelineLister
,
expectPipeline
)
initPipeline
:=
newPipeline
(
nsName
,
pipelineName
,
devops
.
PipelineSpec
{},
true
,
false
)
modifiedPipeline
:=
newPipeline
(
nsName
,
pipelineName
,
devops
.
PipelineSpec
{
Type
:
"aa"
},
true
,
false
)
expectPipeline
:=
newPipeline
(
nsName
,
pipelineName
,
devops
.
PipelineSpec
{
Type
:
"aa"
},
true
,
true
)
f
.
pipelineLister
=
append
(
f
.
pipelineLister
,
modifiedPipeline
)
f
.
namespaceLister
=
append
(
f
.
namespaceLister
,
ns
)
f
.
objects
=
append
(
f
.
objects
,
expect
Pipeline
)
f
.
objects
=
append
(
f
.
objects
,
modified
Pipeline
)
f
.
initDevOpsProject
=
nsName
f
.
initPipeline
=
[]
*
devops
.
Pipeline
{
initPipeline
}
f
.
expectPipeline
=
[]
*
devops
.
Pipeline
{
expectPipeline
}
f
.
run
(
getKey
(
expect
Pipeline
,
t
))
f
.
run
(
getKey
(
modified
Pipeline
,
t
))
}
pkg/models/devops/common.go
浏览文件 @
75e0cf27
...
...
@@ -21,6 +21,7 @@ import (
"github.com/fatih/structs"
"kubesphere.io/kubesphere/pkg/simple/client/devops"
"kubesphere.io/kubesphere/pkg/utils/stringutils"
"time"
)
func
GetColumnsFromStruct
(
s
interface
{})
[]
string
{
...
...
@@ -315,3 +316,8 @@ func GetProjectRolePattern(projectId string) string {
func
GetPipelineRolePattern
(
projectId
string
)
string
{
return
fmt
.
Sprintf
(
"^%s/.*"
,
projectId
)
}
// get unified sync current time
func
GetSyncNowTime
()
string
{
return
time
.
Now
()
.
String
()
}
pkg/models/devops/devops.go
浏览文件 @
75e0cf27
...
...
@@ -173,6 +173,8 @@ func (d devopsOperator) CreateDevOpsProject(workspace string, project *v1alpha3.
}
project
.
Name
=
""
project
.
Labels
[
tenantv1alpha1
.
WorkspaceLabel
]
=
workspace
project
.
Annotations
[
devopsv1alpha3
.
DevOpeProjectSyncStatusAnnoKey
]
=
StatusPending
project
.
Annotations
[
devopsv1alpha3
.
DevOpeProjectSyncTimeAnnoKey
]
=
GetSyncNowTime
()
return
d
.
ksclient
.
DevopsV1alpha3
()
.
DevOpsProjects
()
.
Create
(
project
)
}
...
...
@@ -189,6 +191,8 @@ func (d devopsOperator) UpdateDevOpsProject(workspace string, project *v1alpha3.
project
.
Labels
=
make
(
map
[
string
]
string
,
0
)
}
project
.
Labels
[
tenantv1alpha1
.
WorkspaceLabel
]
=
workspace
project
.
Annotations
[
devopsv1alpha3
.
DevOpeProjectSyncStatusAnnoKey
]
=
StatusPending
project
.
Annotations
[
devopsv1alpha3
.
DevOpeProjectSyncTimeAnnoKey
]
=
GetSyncNowTime
()
return
d
.
ksclient
.
DevopsV1alpha3
()
.
DevOpsProjects
()
.
Update
(
project
)
}
...
...
@@ -219,6 +223,8 @@ func (d devopsOperator) CreatePipelineObj(projectName string, pipeline *v1alpha3
if
err
!=
nil
{
return
nil
,
err
}
projectObj
.
Annotations
[
devopsv1alpha3
.
PipelineSyncStatusAnnoKey
]
=
StatusPending
projectObj
.
Annotations
[
devopsv1alpha3
.
PipelineSyncTimeAnnoKey
]
=
GetSyncNowTime
()
return
d
.
ksclient
.
DevopsV1alpha3
()
.
Pipelines
(
projectObj
.
Status
.
AdminNamespace
)
.
Create
(
pipeline
)
}
...
...
@@ -243,6 +249,8 @@ func (d devopsOperator) UpdatePipelineObj(projectName string, pipeline *v1alpha3
if
err
!=
nil
{
return
nil
,
err
}
projectObj
.
Annotations
[
devopsv1alpha3
.
PipelineSyncStatusAnnoKey
]
=
StatusPending
projectObj
.
Annotations
[
devopsv1alpha3
.
PipelineSyncTimeAnnoKey
]
=
GetSyncNowTime
()
return
d
.
ksclient
.
DevopsV1alpha3
()
.
Pipelines
(
projectObj
.
Status
.
AdminNamespace
)
.
Update
(
pipeline
)
}
...
...
@@ -274,10 +282,12 @@ func (d devopsOperator) ListPipelineObj(projectName string, limit, offset int) (
//credentialobj in crd
func
(
d
devopsOperator
)
CreateCredentialObj
(
projectName
string
,
secret
*
v1
.
Secret
)
(
*
v1
.
Secret
,
error
)
{
projectObj
,
err
:=
d
.
ksInformers
.
Devops
()
.
V1alpha3
()
.
DevOpsProjects
()
.
Lister
()
.
Get
(
projectName
)
secret
.
Annotations
[
devopsv1alpha3
.
CredentialAutoSyncAnnoKey
]
=
"true"
if
err
!=
nil
{
return
nil
,
err
}
secret
.
Annotations
[
devopsv1alpha3
.
CredentialAutoSyncAnnoKey
]
=
"true"
secret
.
Annotations
[
devopsv1alpha3
.
CredentialSyncStatusAnnoKey
]
=
StatusPending
secret
.
Annotations
[
devopsv1alpha3
.
CredentialSyncTimeAnnoKey
]
=
GetSyncNowTime
()
return
d
.
k8sclient
.
CoreV1
()
.
Secrets
(
projectObj
.
Status
.
AdminNamespace
)
.
Create
(
secret
)
}
...
...
@@ -299,10 +309,12 @@ func (d devopsOperator) DeleteCredentialObj(projectName string, secret string) e
func
(
d
devopsOperator
)
UpdateCredentialObj
(
projectName
string
,
secret
*
v1
.
Secret
)
(
*
v1
.
Secret
,
error
)
{
projectObj
,
err
:=
d
.
ksInformers
.
Devops
()
.
V1alpha3
()
.
DevOpsProjects
()
.
Lister
()
.
Get
(
projectName
)
secret
.
Annotations
[
devopsv1alpha3
.
CredentialAutoSyncAnnoKey
]
=
"true"
if
err
!=
nil
{
return
nil
,
err
}
secret
.
Annotations
[
devopsv1alpha3
.
CredentialAutoSyncAnnoKey
]
=
"true"
secret
.
Annotations
[
devopsv1alpha3
.
CredentialSyncStatusAnnoKey
]
=
StatusPending
secret
.
Annotations
[
devopsv1alpha3
.
CredentialSyncTimeAnnoKey
]
=
GetSyncNowTime
()
return
d
.
k8sclient
.
CoreV1
()
.
Secrets
(
projectObj
.
Status
.
AdminNamespace
)
.
Update
(
secret
)
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录