k8s客户端获取从kubeconfig迁移到token
This commit is contained in:
@@ -257,8 +257,8 @@ func AppStoreInstall(ctx *context.Context) {
|
||||
appID := ctx.FormString("app_id")
|
||||
configJSON := ctx.FormString("config")
|
||||
installTarget := ctx.FormString("install_target")
|
||||
kubeconfig := ctx.FormString("kubeconfig")
|
||||
kubeconfigContext := ctx.FormString("kubeconfig_context")
|
||||
k8sURL := ctx.FormString("k8s_url")
|
||||
token := ctx.FormString("k8s_token")
|
||||
|
||||
if appID == "" {
|
||||
ctx.JSON(400, map[string]string{"error": "应用ID不能为空"})
|
||||
@@ -273,7 +273,7 @@ func AppStoreInstall(ctx *context.Context) {
|
||||
|
||||
// 创建 manager 并执行安装
|
||||
manager := appstore.NewManager(ctx, ctx.Doer.ID)
|
||||
if err := manager.InstallApp(appID, configJSON, installTarget, kubeconfig, kubeconfigContext); err != nil {
|
||||
if err := manager.InstallApp(appID, configJSON, installTarget, k8sURL, token); err != nil {
|
||||
// 根据错误类型返回相应的状态码和消息
|
||||
if appErr, ok := err.(*appstore.AppStoreError); ok {
|
||||
switch appErr.Code {
|
||||
@@ -293,7 +293,7 @@ func AppStoreInstall(ctx *context.Context) {
|
||||
}
|
||||
|
||||
// 安装成功
|
||||
if installTarget == "kubeconfig" && kubeconfig != "" {
|
||||
if installTarget == "kubeconfig" && k8sURL != "" && token != "" {
|
||||
ctx.Flash.Success("应用已成功安装到自定义位置")
|
||||
} else {
|
||||
ctx.Flash.Success("应用已成功安装到默认位置")
|
||||
@@ -324,8 +324,8 @@ func AppStoreUpdate(ctx *context.Context) {
|
||||
appID := ctx.FormString("app_id")
|
||||
configJSON := ctx.FormString("config")
|
||||
installTarget := ctx.FormString("install_target")
|
||||
kubeconfig := ctx.FormString("kubeconfig")
|
||||
kubeconfigContext := ctx.FormString("kubeconfig_context")
|
||||
k8sURL := ctx.FormString("k8s_url")
|
||||
token := ctx.FormString("k8s_token")
|
||||
|
||||
if appID == "" {
|
||||
ctx.JSON(400, map[string]string{"error": "应用ID不能为空"})
|
||||
@@ -340,7 +340,7 @@ func AppStoreUpdate(ctx *context.Context) {
|
||||
|
||||
// 创建 manager 并执行更新
|
||||
manager := appstore.NewManager(ctx, ctx.Doer.ID)
|
||||
if err := manager.UpdateInstalledApp(appID, configJSON, installTarget, kubeconfig, kubeconfigContext); err != nil {
|
||||
if err := manager.UpdateInstalledApp(appID, configJSON, installTarget, k8sURL, token); err != nil {
|
||||
// 根据错误类型返回相应的状态码和消息
|
||||
if appErr, ok := err.(*appstore.AppStoreError); ok {
|
||||
switch appErr.Code {
|
||||
@@ -360,7 +360,7 @@ func AppStoreUpdate(ctx *context.Context) {
|
||||
}
|
||||
|
||||
// 更新成功
|
||||
if installTarget == "kubeconfig" && kubeconfig != "" {
|
||||
if installTarget == "kubeconfig" && k8sURL != "" && token != "" {
|
||||
ctx.Flash.Success("应用已成功更新到自定义位置")
|
||||
} else {
|
||||
ctx.Flash.Success("应用已成功更新到默认位置")
|
||||
@@ -396,7 +396,7 @@ func AppStoreUninstall(ctx *context.Context) {
|
||||
}
|
||||
|
||||
// 创建 manager 并执行卸载
|
||||
// UninstallApp 会自动从数据库读取 kubeconfig 判断是外部集群还是本地集群
|
||||
// UninstallApp 会自动从数据库读取保存的 Kubernetes 凭据判断是外部集群还是本地集群
|
||||
manager := appstore.NewManager(ctx, ctx.Doer.ID)
|
||||
if err := manager.UninstallApp(appID); err != nil {
|
||||
// 根据错误类型返回相应的状态码和消息
|
||||
@@ -445,8 +445,8 @@ func AppStoreResume(ctx *context.Context) {
|
||||
// 解析表单数据
|
||||
appID := ctx.FormString("app_id")
|
||||
installTarget := ctx.FormString("install_target")
|
||||
kubeconfig := ctx.FormString("kubeconfig")
|
||||
kubeconfigContext := ctx.FormString("kubeconfig_context")
|
||||
k8sURL := ctx.FormString("k8s_url")
|
||||
token := ctx.FormString("k8s_token")
|
||||
|
||||
if appID == "" {
|
||||
ctx.JSON(400, map[string]string{"error": "应用ID不能为空"})
|
||||
@@ -455,7 +455,7 @@ func AppStoreResume(ctx *context.Context) {
|
||||
|
||||
// 创建 manager 并执行恢复
|
||||
manager := appstore.NewManager(ctx, ctx.Doer.ID)
|
||||
if err := manager.ResumeApp(appID, installTarget, []byte(kubeconfig), kubeconfigContext); err != nil {
|
||||
if err := manager.ResumeApp(appID, installTarget, k8sURL, token); err != nil {
|
||||
// 根据错误类型返回相应的状态码和消息
|
||||
if appErr, ok := err.(*appstore.AppStoreError); ok {
|
||||
switch appErr.Code {
|
||||
@@ -475,7 +475,7 @@ func AppStoreResume(ctx *context.Context) {
|
||||
}
|
||||
|
||||
// 恢复成功
|
||||
if installTarget == "kubeconfig" && kubeconfig != "" {
|
||||
if installTarget == "kubeconfig" && k8sURL != "" && token != "" {
|
||||
ctx.Flash.Success("应用已成功在指定位置恢复")
|
||||
} else {
|
||||
ctx.Flash.Success("应用已成功恢复")
|
||||
@@ -506,8 +506,8 @@ func AppStoreStop(ctx *context.Context) {
|
||||
// 解析表单数据
|
||||
appID := ctx.FormString("app_id")
|
||||
installTarget := ctx.FormString("install_target")
|
||||
kubeconfig := ctx.FormString("kubeconfig")
|
||||
kubeconfigContext := ctx.FormString("kubeconfig_context")
|
||||
k8sURL := ctx.FormString("k8s_url")
|
||||
token := ctx.FormString("k8s_token")
|
||||
|
||||
if appID == "" {
|
||||
ctx.JSON(400, map[string]string{"error": "应用ID不能为空"})
|
||||
@@ -516,7 +516,7 @@ func AppStoreStop(ctx *context.Context) {
|
||||
|
||||
// 创建 manager 并执行暂停
|
||||
manager := appstore.NewManager(ctx, ctx.Doer.ID)
|
||||
if err := manager.StopApp(appID, installTarget, []byte(kubeconfig), kubeconfigContext); err != nil {
|
||||
if err := manager.StopApp(appID, installTarget, k8sURL, token); err != nil {
|
||||
// 根据错误类型返回相应的状态码和消息
|
||||
if appErr, ok := err.(*appstore.AppStoreError); ok {
|
||||
switch appErr.Code {
|
||||
@@ -536,7 +536,7 @@ func AppStoreStop(ctx *context.Context) {
|
||||
}
|
||||
|
||||
// 暂停成功
|
||||
if installTarget == "kubeconfig" && kubeconfig != "" {
|
||||
if installTarget == "kubeconfig" && k8sURL != "" && token != "" {
|
||||
ctx.Flash.Success("应用已成功在指定位置暂停")
|
||||
} else {
|
||||
ctx.Flash.Success("应用已成功暂停")
|
||||
|
||||
Reference in New Issue
Block a user