Skip to content

Commit 858b9f5

Browse files
committed
Merge branch 'main' into manifest-template-fix
2 parents 2c734ee + bc91c10 commit 858b9f5

File tree

19 files changed

+156
-109
lines changed

19 files changed

+156
-109
lines changed

api/k8s/application/k8sApplicationRestHandler.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,15 @@ func (handler *K8sApplicationRestHandlerImpl) GetResourceList(w http.ResponseWri
964964
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
965965
return
966966
}
967-
response, err := handler.k8sApplicationService.GetResourceList(r.Context(), token, &request, handler.verifyRbacForCluster)
967+
isSuperAdmin := false
968+
if ok := handler.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionGet, "*"); ok {
969+
isSuperAdmin = true
970+
}
971+
clusterRbacFunc := handler.verifyRbacForCluster
972+
if isSuperAdmin {
973+
clusterRbacFunc = nil
974+
}
975+
response, err := handler.k8sApplicationService.GetResourceList(r.Context(), token, &request, clusterRbacFunc)
968976
if err != nil {
969977
handler.logger.Errorw("error in getting resource list", "err", err)
970978
if statusErr, ok := err.(*errors3.StatusError); ok && statusErr.Status().Code == 404 {

client/argocdServer/ArgoClientWrapperService.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ type ArgoClientWrapperService interface {
9393

9494
// GetGitOpsRepoName returns the GitOps repository name, configured for the argoCd app
9595
GetGitOpsRepoName(ctx context.Context, appName string) (gitOpsRepoName string, err error)
96+
97+
GetGitOpsRepoURL(ctx context.Context, appName string) (gitOpsRepoURL string, err error)
9698
}
9799

98100
type ArgoClientWrapperServiceImpl struct {
@@ -290,6 +292,20 @@ func (impl *ArgoClientWrapperServiceImpl) GetGitOpsRepoName(ctx context.Context,
290292
return gitOpsRepoName, fmt.Errorf("unable to get any ArgoCd application '%s'", appName)
291293
}
292294

295+
func (impl *ArgoClientWrapperServiceImpl) GetGitOpsRepoURL(ctx context.Context, appName string) (gitOpsRepoName string, err error) {
296+
acdApplication, err := impl.acdClient.Get(ctx, &application2.ApplicationQuery{Name: &appName})
297+
if err != nil {
298+
impl.logger.Errorw("no argo app exists", "acdAppName", appName, "err", err)
299+
return gitOpsRepoName, err
300+
}
301+
// safety checks nil pointers
302+
if acdApplication != nil && acdApplication.Spec.Source != nil {
303+
gitOpsRepoUrl := acdApplication.Spec.Source.RepoURL
304+
return gitOpsRepoUrl, nil
305+
}
306+
return "", fmt.Errorf("unable to get any ArgoCd application '%s'", appName)
307+
}
308+
293309
// createRepoInArgoCd is the wrapper function to Create Repository in ArgoCd
294310
func (impl *ArgoClientWrapperServiceImpl) createRepoInArgoCd(ctx context.Context, gitOpsRepoUrl string) error {
295311
repo := &v1alpha1.Repository{

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ require (
1717
github.com/casbin/casbin v1.9.1
1818
github.com/casbin/casbin/v2 v2.97.0
1919
github.com/casbin/xorm-adapter v1.0.1-0.20190716004226-a317737a1007
20+
github.com/casbin/xorm-adapter/v2 v2.5.1
2021
github.com/coreos/go-oidc v2.2.1+incompatible
2122
github.com/davecgh/go-spew v1.1.1
2223
github.com/deckarep/golang-set v1.8.0
2324
github.com/devtron-labs/authenticator v0.4.35-0.20240607135426-c86e868ecee1
24-
github.com/devtron-labs/common-lib v0.0.21-0.20240628105542-603b4f777e00
25+
github.com/devtron-labs/common-lib v0.0.22-0.20240705073412-32e32c499160
2526
github.com/devtron-labs/go-bitbucket v0.9.60-beta
2627
github.com/devtron-labs/protos v0.0.3-0.20240527113333-08a3be5ec6c1
2728
github.com/evanphx/json-patch v5.7.0+incompatible
@@ -130,7 +131,6 @@ require (
130131
github.com/bombsimon/logrusr/v2 v2.0.1 // indirect
131132
github.com/bradleyfalzon/ghinstallation/v2 v2.5.0 // indirect
132133
github.com/casbin/govaluate v1.1.0 // indirect
133-
github.com/casbin/xorm-adapter/v2 v2.5.1 // indirect
134134
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
135135
github.com/cespare/xxhash/v2 v2.2.0 // indirect
136136
github.com/chai2010/gettext-go v1.0.2 // indirect

go.sum

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ cloud.google.com/go/storage v1.30.1 h1:uOdMxAs8HExqBlnLtnQyP0YkvbiDpdGShGKtx6U/o
1414
cloud.google.com/go/storage v1.30.1/go.mod h1:NfxhC0UJE1aXSx7CIIbCf7y9HKT7BiccwkR7+P7gN8E=
1515
dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
1616
dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
17+
gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a h1:lSA0F4e9A2NcQSqGqTOXqu2aRi/XEQxDCBwM8yJtE6s=
1718
gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a/go.mod h1:EXuID2Zs0pAQhH8yz+DNjUbjppKQzKFAn28TMYPB6IU=
1819
github.com/Azure/azure-pipeline-go v0.2.3 h1:7U9HBg1JFK3jHl5qmo4CTZKFTVgMwdFHMVtCdfBE21U=
1920
github.com/Azure/azure-pipeline-go v0.2.3/go.mod h1:x841ezTBIMG6O3lAcl8ATHnsOPVl2bqk7S3ta6S6u4k=
@@ -191,13 +192,13 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
191192
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
192193
github.com/deckarep/golang-set v1.8.0 h1:sk9/l/KqpunDwP7pSjUg0keiOOLEnOBHzykLrsPppp4=
193194
github.com/deckarep/golang-set v1.8.0/go.mod h1:5nI87KwE7wgsBU1F4GKAw2Qod7p5kyS383rP6+o6qqo=
194-
github.com/denisenkom/go-mssqldb v0.0.0-20190707035753-2be1aa521ff4 h1:YcpmyvADGYw5LqMnHqSkyIELsHCGF6PkrmM31V8rF7o=
195195
github.com/denisenkom/go-mssqldb v0.0.0-20190707035753-2be1aa521ff4/go.mod h1:zAg7JM8CkOJ43xKXIj7eRO9kmWm/TW578qo+oDO6tuM=
196+
github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc h1:VRRKCwnzqk8QCaRC4os14xoKDdbHqqlJtJA0oc1ZAjg=
196197
github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
197198
github.com/devtron-labs/authenticator v0.4.35-0.20240607135426-c86e868ecee1 h1:qdkpTAo2Kr0ZicZIVXfNwsGSshpc9OB9j9RzmKYdIwY=
198199
github.com/devtron-labs/authenticator v0.4.35-0.20240607135426-c86e868ecee1/go.mod h1:IkKPPEfgLCMR29he5yv2OCC6iM2R7K5/0AA3k8b9XNc=
199-
github.com/devtron-labs/common-lib v0.0.21-0.20240628105542-603b4f777e00 h1:xSZulEz0PaTA7tL4Es/uNFUmgjD6oAv8gxJV49GPWHk=
200-
github.com/devtron-labs/common-lib v0.0.21-0.20240628105542-603b4f777e00/go.mod h1:UZGPt1ep9Tnd9Ak2sibGSiLr7p3ijO2/JLT+h+pqBuU=
200+
github.com/devtron-labs/common-lib v0.0.22-0.20240705073412-32e32c499160 h1:9iumIJmRId91aUcyPkxPb6nvjhHuYDoAgomNSG6OIdE=
201+
github.com/devtron-labs/common-lib v0.0.22-0.20240705073412-32e32c499160/go.mod h1:UZGPt1ep9Tnd9Ak2sibGSiLr7p3ijO2/JLT+h+pqBuU=
201202
github.com/devtron-labs/go-bitbucket v0.9.60-beta h1:VEx1jvDgdtDPS6A1uUFoaEi0l1/oLhbr+90xOwr6sDU=
202203
github.com/devtron-labs/go-bitbucket v0.9.60-beta/go.mod h1:GnuiCesvh8xyHeMCb+twm8lBR/kQzJYSKL28ZfObp1Y=
203204
github.com/devtron-labs/protos v0.0.3-0.20240527113333-08a3be5ec6c1 h1:R6qVeFaayqstBSu4w+ipWQqJyMKDqBVV3a11qoA2IaM=
@@ -317,7 +318,6 @@ github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/me
317318
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
318319
github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68=
319320
github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
320-
github.com/go-xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a h1:9wScpmSP5A3Bk8V3XHWUcJmYTh+ZnlHVyc+A4oZYS3Y=
321321
github.com/go-xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a/go.mod h1:56xuuqnHyryaerycW3BfssRdxQstACi0Epw/yC5E2xM=
322322
github.com/go-xorm/xorm v0.7.9 h1:LZze6n1UvRmM5gpL9/U9Gucwqo6aWlFVlfcHKH10qA0=
323323
github.com/go-xorm/xorm v0.7.9/go.mod h1:XiVxrMMIhFkwSkh96BW7PACl7UhLtx2iJIHMdmjh5sQ=
@@ -331,6 +331,7 @@ github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69
331331
github.com/golang-jwt/jwt/v4 v4.0.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg=
332332
github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg=
333333
github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
334+
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe h1:lXe2qZdvpiX5WZkZR4hgp4KJVfY3nMkvmwbVkpv1rVY=
334335
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
335336
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
336337
github.com/golang/glog v1.1.2 h1:DVjP2PbBOzHyzA+dn3WhHIq4NdVu3Q+pvivFICf/7fo=
@@ -593,8 +594,8 @@ github.com/mattn/go-ieproxy v0.0.1 h1:qiyop7gCflfhwCzGyeT0gro3sF9AIg9HU98JORTkqf
593594
github.com/mattn/go-ieproxy v0.0.1/go.mod h1:pYabZ6IHcRpFh7vIaLfK7rdcWgFEb3SFJ6/gNWuh88E=
594595
github.com/mattn/go-isatty v0.0.0-20160806122752-66b8e73f3f5c/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
595596
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
596-
github.com/mattn/go-sqlite3 v1.10.0 h1:jbhqpg7tQe4SupckyijYiy0mJJ/pRyHvXf7JdWK860o=
597597
github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
598+
github.com/mattn/go-sqlite3 v1.14.0 h1:mLyGNKR8+Vv9CAU7PphKa2hkEqxxhn8i32J6FPj1/QA=
598599
github.com/mattn/go-sqlite3 v1.14.0/go.mod h1:JIl7NbARA7phWnGvh0LKTyg7S9BA+6gx71ShQilpsus=
599600
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
600601
github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo=
@@ -1303,7 +1304,6 @@ sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
13031304
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=
13041305
upper.io/db.v3 v3.8.0+incompatible h1:XNeEO2vQRVqq70M98ghzq6M30F5Bzo+99ess5v+eVYw=
13051306
upper.io/db.v3 v3.8.0+incompatible/go.mod h1:FgTdD24eBjJAbPKsQSiHUNgXjOR4Lub3u1UMHSIh82Y=
1306-
xorm.io/builder v0.3.6 h1:ha28mQ2M+TFx96Hxo+iq6tQgnkC9IZkM6D8w9sKHHF8=
13071307
xorm.io/builder v0.3.6/go.mod h1:LEFAPISnRzG+zxaxj2vPicRwz67BdhFreKg8yv8/TgU=
13081308
xorm.io/builder v0.3.7 h1:2pETdKRK+2QG4mLX4oODHEhn5Z8j1m8sXa7jfu+/SZI=
13091309
xorm.io/builder v0.3.7/go.mod h1:aUW0S9eb9VCaPohFCH3j7czOx1PMW3i1HrSzbLYGBSE=

pkg/appStore/installedApp/service/AppStoreDeploymentService.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -607,15 +607,14 @@ func (impl *AppStoreDeploymentServiceImpl) UpdateInstalledApp(ctx context.Contex
607607
installedAppDeploymentAction := adapter.NewInstalledAppDeploymentAction(installedApp.DeploymentAppType)
608608
// migrate installedApp.GitOpsRepoName to installedApp.GitOpsRepoUrl
609609
if util.IsAcdApp(installedApp.DeploymentAppType) &&
610-
len(installedApp.GitOpsRepoName) != 0 &&
611610
len(installedApp.GitOpsRepoUrl) == 0 {
612-
//as the installedApp.GitOpsRepoName is not an empty string; migrate installedApp.GitOpsRepoName to installedApp.GitOpsRepoUrl
613-
gitRepoUrl, err := impl.fullModeDeploymentService.GetGitRepoUrl(installedApp.GitOpsRepoName)
611+
gitRepoUrl, err := impl.fullModeDeploymentService.GetAcdAppGitOpsRepoURL(installedApp.App.AppName, installedApp.Environment.Name)
614612
if err != nil {
615613
impl.logger.Errorw("error in GitOps repository url migration", "err", err)
616614
return nil, err
617615
}
618616
installedApp.GitOpsRepoUrl = gitRepoUrl
617+
installedApp.GitOpsRepoName = impl.gitOpsConfigReadService.GetGitOpsRepoNameFromUrl(gitRepoUrl)
619618
}
620619
// migration ends
621620

pkg/appStore/installedApp/service/EAMode/InstalledAppDBService.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,17 @@ func (impl *InstalledAppDBServiceImpl) CreateNewAppEntryForAllInstalledApps(inst
372372
// Rollback tx on error.
373373
defer tx.Rollback()
374374
for _, installedApp := range installedApps {
375+
//check if for this unique identifier name an app already exists, if yes then continue
376+
appMetadata, err := impl.AppRepository.FindActiveByName(installedApp.GetUniqueAppNameIdentifier())
377+
if err != nil && !util.IsErrNoRows(err) {
378+
impl.Logger.Errorw("error in fetching app by unique app identifier", "appNameUniqueIdentifier", installedApp.GetUniqueAppNameIdentifier(), "err", err)
379+
return err
380+
}
381+
if appMetadata != nil && appMetadata.Id > 0 {
382+
//app already exists for this unique identifier hence not creating new app entry for this
383+
continue
384+
}
385+
375386
appModel := &app.App{
376387
Active: true,
377388
AppName: installedApp.GetUniqueAppNameIdentifier(),
@@ -381,7 +392,7 @@ func (impl *InstalledAppDBServiceImpl) CreateNewAppEntryForAllInstalledApps(inst
381392
DisplayName: installedApp.App.AppName,
382393
}
383394
appModel.CreateAuditLog(bean3.SystemUserId)
384-
err := impl.AppRepository.SaveWithTxn(appModel, tx)
395+
err = impl.AppRepository.SaveWithTxn(appModel, tx)
385396
if err != nil {
386397
impl.Logger.Errorw("error saving appModel", "err", err)
387398
return err

pkg/appStore/installedApp/service/FullMode/deployment/InstalledAppArgoCdService.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ type InstalledAppArgoCdService interface {
4646
// UpdateAndSyncACDApps this will update chart info in acd app if required in case of mono repo migration and will refresh argo app
4747
UpdateAndSyncACDApps(installAppVersionRequest *appStoreBean.InstallAppVersionDTO, ChartGitAttribute *commonBean.ChartGitAttribute, isMonoRepoMigrationRequired bool, ctx context.Context, tx *pg.Tx) error
4848
DeleteACD(acdAppName string, ctx context.Context, isNonCascade bool) error
49+
GetAcdAppGitOpsRepoURL(appName string, environmentName string) (string, error)
4950
}
5051

5152
func (impl *FullModeDeploymentServiceImpl) GetAcdAppGitOpsRepoName(appName string, environmentName string) (string, error) {
@@ -230,3 +231,15 @@ func (impl *FullModeDeploymentServiceImpl) patchAcdApp(ctx context.Context, inst
230231
}
231232
return nil
232233
}
234+
235+
func (impl *FullModeDeploymentServiceImpl) GetAcdAppGitOpsRepoURL(appName string, environmentName string) (string, error) {
236+
acdToken, err := impl.argoUserService.GetLatestDevtronArgoCdUserToken()
237+
if err != nil {
238+
impl.Logger.Errorw("error in getting acd token", "err", err)
239+
return "", err
240+
}
241+
ctx := context.Background()
242+
ctx = context.WithValue(ctx, "token", acdToken)
243+
acdAppName := fmt.Sprintf("%s-%s", appName, environmentName)
244+
return impl.argoClientWrapperService.GetGitOpsRepoURL(ctx, acdAppName)
245+
}

pkg/k8s/application/k8sApplicationService.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,9 @@ func (impl *K8sApplicationServiceImpl) GetResourceList(ctx context.Context, toke
674674
return resourceList, err
675675
}
676676
checkForResourceCallback := func(namespace, group, kind, resourceName string) bool {
677+
if validateResourceAccess == nil { // if resource validate rbac func is nil then allow
678+
return true
679+
}
677680
resourceIdentifier := resourceIdentifierCloned
678681
resourceIdentifier.Name = resourceName
679682
resourceIdentifier.Namespace = namespace
@@ -688,13 +691,15 @@ func (impl *K8sApplicationServiceImpl) GetResourceList(ctx context.Context, toke
688691
impl.logger.Errorw("error on parsing for k8s resource", "err", err)
689692
return resourceList, err
690693
}
691-
k8sServerVersion, err := impl.k8sCommonService.GetK8sServerVersion(clusterId)
692-
if err != nil {
693-
impl.logger.Errorw("error in getting k8s server version", "clusterId", clusterId, "err", err)
694-
// return nil, err
695-
} else {
696-
resourceList.ServerVersion = k8sServerVersion.String()
697-
}
694+
// Not used in FE side
695+
696+
//k8sServerVersion, err := impl.k8sCommonService.GetK8sServerVersion(clusterId)
697+
//if err != nil {
698+
// impl.logger.Errorw("error in getting k8s server version", "clusterId", clusterId, "err", err)
699+
// // return nil, err
700+
//} else {
701+
// resourceList.ServerVersion = k8sServerVersion.String()
702+
//}
698703
return resourceList, nil
699704
}
700705

pkg/terminal/terminalSesion.go

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ func startProcess(ctx context.Context, k8sClient kubernetes.Interface, cfg *rest
308308
exec, err := getExecutor(k8sClient, cfg, podName, namespace, containerName, cmd, true, true)
309309

310310
if err != nil {
311+
log.Println("error in getting terminal executor ", "err: ", err)
311312
return err
312313
}
313314

@@ -323,6 +324,7 @@ func startProcess(ctx context.Context, k8sClient kubernetes.Interface, cfg *rest
323324
terminalSessions.SetTerminalSessionStartTime(sessionRequest.SessionId)
324325
err = execWithStreamOptions(ctx, exec, streamOptions)
325326
if err != nil {
327+
log.Println("error in terminal exec with stream opts: ", "err: ", err)
326328
return err
327329
}
328330
return nil
@@ -506,7 +508,7 @@ func (impl *TerminalSessionHandlerImpl) GetTerminalSession(req *TerminalSessionR
506508
namespace: req.Namespace,
507509
clusterId: strconv.Itoa(req.ClusterId),
508510
})
509-
config, client, err := impl.getClientConfig(req)
511+
config, client, err := impl.getClientSetAndRestConfigForTerminalConn(req)
510512

511513
go func() {
512514
err := impl.saveEphemeralContainerTerminalAccessAudit(req)
@@ -523,7 +525,7 @@ func (impl *TerminalSessionHandlerImpl) GetTerminalSession(req *TerminalSessionR
523525
return http.StatusOK, &TerminalMessage{SessionID: sessionID}, nil
524526
}
525527

526-
func (impl *TerminalSessionHandlerImpl) getClientConfig(req *TerminalSessionRequest) (*rest.Config, *kubernetes.Clientset, error) {
528+
func (impl *TerminalSessionHandlerImpl) getClientSetAndRestConfigForTerminalConn(req *TerminalSessionRequest) (*rest.Config, *kubernetes.Clientset, error) {
527529
var clusterBean *cluster.ClusterBean
528530
var clusterConfig *k8s.ClusterConfig
529531
var restConfig *rest.Config
@@ -534,6 +536,13 @@ func (impl *TerminalSessionHandlerImpl) getClientConfig(req *TerminalSessionRequ
534536
impl.logger.Errorw("error in getting rest config", "err", err, "clusterId", req.ClusterId, "externalArgoApplicationName", req.ExternalArgoApplicationName)
535537
return nil, nil, err
536538
}
539+
540+
_, clientSet, err := impl.k8sUtil.GetK8sConfigAndClientsByRestConfig(restConfig)
541+
if err != nil {
542+
impl.logger.Errorw("error in clientSet", "err", err)
543+
return nil, nil, err
544+
}
545+
return restConfig, clientSet, nil
537546
} else {
538547
if req.ClusterId != 0 {
539548
clusterBean, err = impl.clusterService.FindById(req.ClusterId)
@@ -561,14 +570,22 @@ func (impl *TerminalSessionHandlerImpl) getClientConfig(req *TerminalSessionRequ
561570
impl.logger.Errorw("error in getting rest config by cluster", "err", err, "clusterName", clusterConfig.ClusterName)
562571
return nil, nil, err
563572
}
573+
574+
_, clientSet, err := impl.k8sUtil.GetK8sConfigAndClientsByRestConfig(restConfig)
575+
if err != nil {
576+
impl.logger.Errorw("error in clientSet", "err", err)
577+
return nil, nil, err
578+
}
579+
580+
// we have to get the clientSet before setting the custom transport to nil
581+
// we need re populate the tls config in the restConfig.
582+
// rest config with custom transport will break spdy client
583+
clusterConfig.PopulateTlsConfigurationsInto(restConfig)
584+
restConfig.Transport = nil
585+
return restConfig, clientSet, nil
564586
}
565-
_, clientSet, err := impl.k8sUtil.GetK8sConfigAndClientsByRestConfig(restConfig)
566-
if err != nil {
567-
impl.logger.Errorw("error in clientSet", "err", err)
568-
return nil, nil, err
569-
}
570-
return restConfig, clientSet, nil
571587
}
588+
572589
func (impl *TerminalSessionHandlerImpl) AutoSelectShell(req *TerminalSessionRequest) (string, error) {
573590
var err1 error
574591
for _, testShell := range validShells {
@@ -614,7 +631,7 @@ func getErrorMsg(err string) error {
614631
}
615632

616633
func (impl *TerminalSessionHandlerImpl) RunCmdInRemotePod(req *TerminalSessionRequest, cmds []string) (*bytes.Buffer, *bytes.Buffer, error) {
617-
config, client, err := impl.getClientConfig(req)
634+
config, client, err := impl.getClientSetAndRestConfigForTerminalConn(req)
618635
if err != nil {
619636
impl.logger.Errorw("error in fetching config", "err", err)
620637
return nil, nil, err
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1 @@
1-
DELETE FROM plugin_step_variable WHERE plugin_step_id =(SELECT ps.id FROM plugin_metadata p inner JOIN plugin_step ps on ps.plugin_id=p.id WHERE p.name='Code Scan' and ps."index"=1 and ps.deleted=false);
2-
DELETE FROM plugin_step WHERE plugin_id = (SELECT id FROM plugin_metadata WHERE name='Code Scan');
3-
DELETE FROM plugin_stage_mapping WHERE plugin_id =(SELECT id FROM plugin_metadata WHERE name='Code Scan');
4-
DELETE FROM plugin_tag_relation WHERE plugin_id =(SELECT id FROM plugin_metadata WHERE name='Code Scan');
5-
DELETE FROM pipeline_stage_step where ref_plugin_id in (SELECT id from plugin_metadata WHERE name ='Code Scan');
6-
DELETE from plugin_pipeline_script where id = (SELECT script_id from plugin_step WHERE plugin_id=(SELECT id FROM plugin_metadata WHERE name='Code Scan'));
7-
DELETE FROM plugin_metadata WHERE name ='Code Scan';
1+
-- empty script to keep script number common across repo

0 commit comments

Comments
 (0)