Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
水淹萌龙
kubesphere
提交
64fc8921
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
64fc8921
编写于
3月 29, 2021
作者:
K
KubeSphere CI Bot
提交者:
GitHub
3月 29, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3590 from xyz-li/app-fix1
Fix: remove checks when delete release
上级
7d661e90
cac5daa4
变更
9
显示空白变更内容
内联
并排
Showing
9 changed file
with
43 addition
and
60 deletion
+43
-60
pkg/apis/application/v1alpha1/helmapplication_types.go
pkg/apis/application/v1alpha1/helmapplication_types.go
+4
-0
pkg/controller/openpitrix/helmapplication/helm_application_controller.go
...openpitrix/helmapplication/helm_application_controller.go
+17
-11
pkg/kapis/openpitrix/v1/handler.go
pkg/kapis/openpitrix/v1/handler.go
+6
-1
pkg/models/openpitrix/applications.go
pkg/models/openpitrix/applications.go
+2
-11
pkg/models/openpitrix/applicationversions.go
pkg/models/openpitrix/applicationversions.go
+0
-22
pkg/models/openpitrix/release.go
pkg/models/openpitrix/release.go
+6
-0
pkg/models/openpitrix/repos.go
pkg/models/openpitrix/repos.go
+4
-15
pkg/models/openpitrix/types.go
pkg/models/openpitrix/types.go
+3
-0
pkg/models/openpitrix/utils.go
pkg/models/openpitrix/utils.go
+1
-0
未找到文件。
pkg/apis/application/v1alpha1/helmapplication_types.go
浏览文件 @
64fc8921
...
@@ -126,3 +126,7 @@ func (in *HelmApplication) State() string {
...
@@ -126,3 +126,7 @@ func (in *HelmApplication) State() string {
}
}
return
in
.
Status
.
State
return
in
.
Status
.
State
}
}
func
(
in
*
HelmApplication
)
GetCreator
()
string
{
return
getValue
(
in
.
Annotations
,
constants
.
CreatorAnnotationKey
)
}
pkg/controller/openpitrix/helmapplication/helm_application_controller.go
浏览文件 @
64fc8921
...
@@ -69,7 +69,7 @@ func (r *ReconcileHelmApplication) Reconcile(request reconcile.Request) (reconci
...
@@ -69,7 +69,7 @@ func (r *ReconcileHelmApplication) Reconcile(request reconcile.Request) (reconci
if
!
sliceutil
.
HasString
(
app
.
ObjectMeta
.
Finalizers
,
appFinalizer
)
{
if
!
sliceutil
.
HasString
(
app
.
ObjectMeta
.
Finalizers
,
appFinalizer
)
{
app
.
ObjectMeta
.
Finalizers
=
append
(
app
.
ObjectMeta
.
Finalizers
,
appFinalizer
)
app
.
ObjectMeta
.
Finalizers
=
append
(
app
.
ObjectMeta
.
Finalizers
,
appFinalizer
)
if
err
:=
r
.
Update
(
rootCtx
,
app
);
err
!=
nil
{
if
err
:=
r
.
Update
(
rootCtx
,
app
);
err
!=
nil
{
return
ctrl
.
Result
{},
err
return
reconcile
.
Result
{},
err
}
}
// create app success
// create app success
appOperationTotal
.
WithLabelValues
(
"creation"
,
app
.
GetTrueName
(),
strconv
.
FormatBool
(
inAppStore
(
app
)))
.
Inc
()
appOperationTotal
.
WithLabelValues
(
"creation"
,
app
.
GetTrueName
(),
strconv
.
FormatBool
(
inAppStore
(
app
)))
.
Inc
()
...
@@ -78,7 +78,11 @@ func (r *ReconcileHelmApplication) Reconcile(request reconcile.Request) (reconci
...
@@ -78,7 +78,11 @@ func (r *ReconcileHelmApplication) Reconcile(request reconcile.Request) (reconci
if
!
inAppStore
(
app
)
{
if
!
inAppStore
(
app
)
{
if
app
.
Status
.
State
==
v1alpha1
.
StateActive
||
if
app
.
Status
.
State
==
v1alpha1
.
StateActive
||
app
.
Status
.
State
==
v1alpha1
.
StateSuspended
{
app
.
Status
.
State
==
v1alpha1
.
StateSuspended
{
return
reconcile
.
Result
{},
r
.
createAppCopyInAppStore
(
rootCtx
,
app
)
if
err
:=
r
.
createAppCopyInAppStore
(
rootCtx
,
app
);
err
!=
nil
{
klog
.
Errorf
(
"create app copy failed, error: %s"
,
err
)
return
reconcile
.
Result
{},
err
}
return
reconcile
.
Result
{},
nil
}
}
}
}
}
else
{
}
else
{
...
@@ -120,9 +124,9 @@ func (r *ReconcileHelmApplication) deleteAppCopyInAppStore(ctx context.Context,
...
@@ -120,9 +124,9 @@ func (r *ReconcileHelmApplication) deleteAppCopyInAppStore(ctx context.Context,
return
nil
return
nil
}
}
// create a application copy in app store
// create
AppCopyInAppStore create
a application copy in app store
func
(
r
*
ReconcileHelmApplication
)
createAppCopyInAppStore
(
ctx
context
.
Context
,
from
*
v1alpha1
.
HelmApplication
)
error
{
func
(
r
*
ReconcileHelmApplication
)
createAppCopyInAppStore
(
ctx
context
.
Context
,
originApp
*
v1alpha1
.
HelmApplication
)
error
{
name
:=
fmt
.
Sprintf
(
"%s%s"
,
from
.
Name
,
v1alpha1
.
HelmApplicationAppStoreSuffix
)
name
:=
fmt
.
Sprintf
(
"%s%s"
,
originApp
.
Name
,
v1alpha1
.
HelmApplicationAppStoreSuffix
)
app
:=
&
v1alpha1
.
HelmApplication
{}
app
:=
&
v1alpha1
.
HelmApplication
{}
err
:=
r
.
Get
(
ctx
,
types
.
NamespacedName
{
Name
:
name
},
app
)
err
:=
r
.
Get
(
ctx
,
types
.
NamespacedName
{
Name
:
name
},
app
)
...
@@ -132,23 +136,25 @@ func (r *ReconcileHelmApplication) createAppCopyInAppStore(ctx context.Context,
...
@@ -132,23 +136,25 @@ func (r *ReconcileHelmApplication) createAppCopyInAppStore(ctx context.Context,
if
app
.
Name
==
""
{
if
app
.
Name
==
""
{
app
.
Name
=
name
app
.
Name
=
name
labels
:=
from
.
Labels
labels
:=
originApp
.
Labels
if
len
(
labels
)
==
0
{
if
len
(
labels
)
==
0
{
labels
=
make
(
map
[
string
]
string
,
3
)
labels
=
make
(
map
[
string
]
string
,
3
)
}
}
labels
[
constants
.
ChartRepoIdLabelKey
]
=
v1alpha1
.
AppStoreRepoId
labels
[
constants
.
ChartRepoIdLabelKey
]
=
v1alpha1
.
AppStoreRepoId
// assign a category to app
// assign a
default
category to app
if
labels
[
constants
.
CategoryIdLabelKey
]
==
""
{
if
labels
[
constants
.
CategoryIdLabelKey
]
==
""
{
labels
[
constants
.
CategoryIdLabelKey
]
=
v1alpha1
.
UncategorizedId
labels
[
constants
.
CategoryIdLabelKey
]
=
v1alpha1
.
UncategorizedId
}
}
labels
[
v1alpha1
.
OriginWorkspaceLabelKey
]
=
from
.
GetWorkspace
()
// record the original workspace
labels
[
v1alpha1
.
OriginWorkspaceLabelKey
]
=
originApp
.
GetWorkspace
()
// apps in store are global resource.
// apps in store are global resource.
delete
(
labels
,
constants
.
WorkspaceLabelKey
)
delete
(
labels
,
constants
.
WorkspaceLabelKey
)
app
.
Annotations
=
originApp
.
Annotations
app
.
Labels
=
labels
app
.
Labels
=
labels
app
.
Spec
=
*
from
.
Spec
.
DeepCopy
()
app
.
Spec
=
*
originApp
.
Spec
.
DeepCopy
()
err
=
r
.
Create
(
context
.
TODO
(),
app
)
err
=
r
.
Create
(
context
.
TODO
(),
app
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -158,7 +164,7 @@ func (r *ReconcileHelmApplication) createAppCopyInAppStore(ctx context.Context,
...
@@ -158,7 +164,7 @@ func (r *ReconcileHelmApplication) createAppCopyInAppStore(ctx context.Context,
if
app
.
Status
.
State
==
""
{
if
app
.
Status
.
State
==
""
{
// update status if needed
// update status if needed
return
updateHelmApplicationStatus
(
r
.
Client
,
from
.
Name
,
true
)
return
updateHelmApplicationStatus
(
r
.
Client
,
originApp
.
Name
,
true
)
}
}
return
nil
return
nil
...
...
pkg/kapis/openpitrix/v1/handler.go
浏览文件 @
64fc8921
...
@@ -20,6 +20,7 @@ import (
...
@@ -20,6 +20,7 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/grpc/status"
"io/ioutil"
"io/ioutil"
apierrors
"k8s.io/apimachinery/pkg/api/errors"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/klog"
"k8s.io/klog"
"kubesphere.io/kubesphere/pkg/api"
"kubesphere.io/kubesphere/pkg/api"
...
@@ -595,7 +596,11 @@ func (h *openpitrixHandler) GetAppVersionFiles(req *restful.Request, resp *restf
...
@@ -595,7 +596,11 @@ func (h *openpitrixHandler) GetAppVersionFiles(req *restful.Request, resp *restf
if
err
!=
nil
{
if
err
!=
nil
{
klog
.
Errorln
(
err
)
klog
.
Errorln
(
err
)
handleOpenpitrixError
(
resp
,
err
)
if
apierrors
.
IsNotFound
(
err
)
{
api
.
HandleNotFound
(
resp
,
nil
,
err
)
}
else
{
api
.
HandleBadRequest
(
resp
,
nil
,
err
)
}
return
return
}
}
...
...
pkg/models/openpitrix/applications.go
浏览文件 @
64fc8921
...
@@ -324,25 +324,16 @@ func (c *applicationOperator) DeleteApp(id string) error {
...
@@ -324,25 +324,16 @@ func (c *applicationOperator) DeleteApp(id string) error {
app
,
err
:=
c
.
appLister
.
Get
(
id
)
app
,
err
:=
c
.
appLister
.
Get
(
id
)
if
err
!=
nil
{
if
err
!=
nil
{
if
apierrors
.
IsNotFound
(
err
)
{
if
apierrors
.
IsNotFound
(
err
)
{
klog
.
V
(
4
)
.
Infof
(
"app %s has been deleted"
,
id
)
return
nil
return
nil
}
else
{
}
else
{
klog
.
Error
(
err
)
klog
.
Error
f
(
"get app %s failed, error: %s"
,
id
,
err
)
return
nil
return
err
}
}
}
}
ls
:=
map
[
string
]
string
{
ls
:=
map
[
string
]
string
{
constants
.
ChartApplicationIdLabelKey
:
app
.
GetHelmApplicationId
(),
constants
.
ChartApplicationIdLabelKey
:
app
.
GetHelmApplicationId
(),
}
}
releases
,
err
:=
c
.
rlsLister
.
List
(
labels
.
SelectorFromSet
(
ls
))
if
err
!=
nil
&&
!
apierrors
.
IsNotFound
(
err
)
{
klog
.
Error
(
err
)
return
err
}
else
if
len
(
releases
)
>
0
{
return
fmt
.
Errorf
(
"app %s has releases not deleted"
,
id
)
}
list
,
err
:=
c
.
versionLister
.
List
(
labels
.
SelectorFromSet
(
ls
))
list
,
err
:=
c
.
versionLister
.
List
(
labels
.
SelectorFromSet
(
ls
))
if
err
!=
nil
{
if
err
!=
nil
{
...
...
pkg/models/openpitrix/applicationversions.go
浏览文件 @
64fc8921
...
@@ -114,28 +114,6 @@ func (c *applicationOperator) DeleteAppVersion(id string) error {
...
@@ -114,28 +114,6 @@ func (c *applicationOperator) DeleteAppVersion(id string) error {
return
actionNotPermitted
return
actionNotPermitted
}
}
// check release
rls
,
err
:=
c
.
rlsLister
.
List
(
labels
.
SelectorFromSet
(
map
[
string
]
string
{
constants
.
ChartApplicationVersionIdLabelKey
:
id
}))
if
err
!=
nil
&&
!
apierrors
.
IsNotFound
(
err
)
{
return
err
}
if
len
(
rls
)
>
0
{
klog
.
V
(
4
)
.
Infof
(
"There are releases use data from app version %s"
,
id
)
infoMap
:=
make
(
map
[
string
]
string
)
allString
:=
&
bytes
.
Buffer
{}
for
_
,
r
:=
range
rls
{
info
:=
fmt
.
Sprintf
(
"%s/%s"
,
r
.
GetWorkspace
(),
r
.
GetRlsNamespace
())
if
_
,
exists
:=
infoMap
[
info
];
!
exists
{
infoMap
[
info
]
=
""
allString
.
WriteString
(
info
)
if
len
(
infoMap
)
>
1
{
allString
.
WriteString
(
","
)
}
}
}
return
fmt
.
Errorf
(
"release exists: %s"
,
allString
.
String
())
}
// Delete data in storage
// Delete data in storage
err
=
c
.
backingStoreClient
.
Delete
(
dataKeyInStorage
(
appVersion
.
GetWorkspace
(),
id
))
err
=
c
.
backingStoreClient
.
Delete
(
dataKeyInStorage
(
appVersion
.
GetWorkspace
(),
id
))
if
err
!=
nil
{
if
err
!=
nil
{
...
...
pkg/models/openpitrix/release.go
浏览文件 @
64fc8921
...
@@ -171,6 +171,7 @@ func (c *releaseOperator) CreateApplication(workspace, clusterName, namespace st
...
@@ -171,6 +171,7 @@ func (c *releaseOperator) CreateApplication(workspace, clusterName, namespace st
},
},
Spec
:
v1alpha1
.
HelmReleaseSpec
{
Spec
:
v1alpha1
.
HelmReleaseSpec
{
Name
:
request
.
Name
,
Name
:
request
.
Name
,
Description
:
stringutils
.
ShortenString
(
request
.
Description
,
v1alpha1
.
MsgLen
),
Version
:
1
,
Version
:
1
,
Values
:
strfmt
.
Base64
(
request
.
Conf
),
Values
:
strfmt
.
Base64
(
request
.
Conf
),
ApplicationId
:
strings
.
TrimSuffix
(
request
.
AppId
,
v1alpha1
.
HelmApplicationAppStoreSuffix
),
ApplicationId
:
strings
.
TrimSuffix
(
request
.
AppId
,
v1alpha1
.
HelmApplicationAppStoreSuffix
),
...
@@ -267,6 +268,11 @@ func (c *releaseOperator) ListApplications(workspace, clusterName, namespace str
...
@@ -267,6 +268,11 @@ func (c *releaseOperator) ListApplications(workspace, clusterName, namespace str
ls
[
constants
.
ChartApplicationVersionIdLabelKey
]
=
versionId
ls
[
constants
.
ChartApplicationVersionIdLabelKey
]
=
versionId
}
}
repoId
:=
conditions
.
Match
[
RepoId
]
if
repoId
!=
""
{
ls
[
constants
.
ChartRepoIdLabelKey
]
=
repoId
}
if
workspace
!=
""
{
if
workspace
!=
""
{
ls
[
constants
.
WorkspaceLabelKey
]
=
workspace
ls
[
constants
.
WorkspaceLabelKey
]
=
workspace
}
}
...
...
pkg/models/openpitrix/repos.go
浏览文件 @
64fc8921
...
@@ -16,7 +16,6 @@ package openpitrix
...
@@ -16,7 +16,6 @@ package openpitrix
import
(
import
(
"context"
"context"
"encoding/json"
"encoding/json"
"fmt"
"github.com/go-openapi/strfmt"
"github.com/go-openapi/strfmt"
apierrors
"k8s.io/apimachinery/pkg/api/errors"
apierrors
"k8s.io/apimachinery/pkg/api/errors"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
...
@@ -126,7 +125,7 @@ func (c *repoOperator) CreateRepo(repo *v1alpha1.HelmRepo) (*CreateRepoResponse,
...
@@ -126,7 +125,7 @@ func (c *repoOperator) CreateRepo(repo *v1alpha1.HelmRepo) (*CreateRepoResponse,
repo
.
Spec
.
Description
=
stringutils
.
ShortenString
(
repo
.
Spec
.
Description
,
DescriptionLen
)
repo
.
Spec
.
Description
=
stringutils
.
ShortenString
(
repo
.
Spec
.
Description
,
DescriptionLen
)
_
,
err
=
c
.
repoClient
.
HelmRepos
()
.
Create
(
context
.
TODO
(),
repo
,
metav1
.
CreateOptions
{})
_
,
err
=
c
.
repoClient
.
HelmRepos
()
.
Create
(
context
.
TODO
(),
repo
,
metav1
.
CreateOptions
{})
if
err
!=
nil
{
if
err
!=
nil
{
klog
.
Errorf
(
"create helm repo failed, repo
d
_id: %s, error: %s"
,
repo
.
GetHelmRepoId
(),
err
)
klog
.
Errorf
(
"create helm repo failed, repo_id: %s, error: %s"
,
repo
.
GetHelmRepoId
(),
err
)
return
nil
,
err
return
nil
,
err
}
else
{
}
else
{
klog
.
V
(
4
)
.
Infof
(
"create helm repo success, repo_id: %s"
,
repo
.
GetHelmRepoId
())
klog
.
V
(
4
)
.
Infof
(
"create helm repo success, repo_id: %s"
,
repo
.
GetHelmRepoId
())
...
@@ -136,20 +135,10 @@ func (c *repoOperator) CreateRepo(repo *v1alpha1.HelmRepo) (*CreateRepoResponse,
...
@@ -136,20 +135,10 @@ func (c *repoOperator) CreateRepo(repo *v1alpha1.HelmRepo) (*CreateRepoResponse,
}
}
func
(
c
*
repoOperator
)
DeleteRepo
(
id
string
)
error
{
func
(
c
*
repoOperator
)
DeleteRepo
(
id
string
)
error
{
ls
:=
map
[
string
]
string
{
var
err
error
constants
.
ChartRepoIdLabelKey
:
id
,
}
releases
,
err
:=
c
.
rlsLister
.
List
(
labels
.
SelectorFromSet
(
ls
))
if
err
!=
nil
&&
apierrors
.
IsNotFound
(
err
)
{
return
err
}
else
if
len
(
releases
)
>
0
{
return
fmt
.
Errorf
(
"repo %s has releases not deleted"
,
id
)
}
err
=
c
.
repoClient
.
HelmRepos
()
.
Delete
(
context
.
TODO
(),
id
,
metav1
.
DeleteOptions
{})
err
=
c
.
repoClient
.
HelmRepos
()
.
Delete
(
context
.
TODO
(),
id
,
metav1
.
DeleteOptions
{})
if
err
!=
nil
&&
apierrors
.
IsNotFound
(
err
)
{
if
err
!=
nil
&&
!
apierrors
.
IsNotFound
(
err
)
{
klog
.
Error
(
err
)
klog
.
Error
f
(
"delete repo %s failed, error: %s"
,
id
,
err
)
return
err
return
err
}
}
klog
.
V
(
4
)
.
Infof
(
"repo %s deleted"
,
id
)
klog
.
V
(
4
)
.
Infof
(
"repo %s deleted"
,
id
)
...
...
pkg/models/openpitrix/types.go
浏览文件 @
64fc8921
...
@@ -738,6 +738,9 @@ type CreateClusterRequest struct {
...
@@ -738,6 +738,9 @@ type CreateClusterRequest struct {
// release name
// release name
Name
string
`json:"name"`
Name
string
`json:"name"`
// release install description
Description
string
`json:"description"`
// advanced param
// advanced param
AdvancedParam
[]
string
`json:"advanced_param"`
AdvancedParam
[]
string
`json:"advanced_param"`
...
...
pkg/models/openpitrix/utils.go
浏览文件 @
64fc8921
...
@@ -336,6 +336,7 @@ func convertApp(app *v1alpha1.HelmApplication, versions []*v1alpha1.HelmApplicat
...
@@ -336,6 +336,7 @@ func convertApp(app *v1alpha1.HelmApplication, versions []*v1alpha1.HelmApplicat
out
.
Isv
=
app
.
GetWorkspace
()
out
.
Isv
=
app
.
GetWorkspace
()
out
.
ClusterTotal
=
&
rlsCount
out
.
ClusterTotal
=
&
rlsCount
out
.
Owner
=
app
.
GetCreator
()
return
out
return
out
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录