Skip to content

Commit dd29c16

Browse files
committed
external argo fixes
1 parent 4e0df6d commit dd29c16

File tree

8 files changed

+42
-25
lines changed

8 files changed

+42
-25
lines changed

api/k8s/application/k8sApplicationRestHandler.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,8 @@ func (handler *K8sApplicationRestHandlerImpl) CreateEphemeralContainer(w http.Re
10251025
return
10261026
}
10271027
request.UserId = userId
1028+
request.ExternalArgoAppIdentifier = resourceRequestBean.ExternalArgoAppIdentifier
1029+
10281030
err = handler.k8sApplicationService.CreatePodEphemeralContainers(&request)
10291031
if err != nil {
10301032
handler.logger.Errorw("error occurred in creating ephemeral container", "err", err, "requestPayload", request)
@@ -1073,6 +1075,7 @@ func (handler *K8sApplicationRestHandlerImpl) DeleteEphemeralContainer(w http.Re
10731075
return
10741076
}
10751077
request.UserId = userId
1078+
request.ExternalArgoAppIdentifier = resourceRequestBean.ExternalArgoAppIdentifier
10761079
_, err = handler.k8sApplicationService.TerminatePodEphemeralContainer(request)
10771080
if err != nil {
10781081
handler.logger.Errorw("error occurred in terminating ephemeral container", "err", err, "requestPayload", request)
@@ -1156,6 +1159,7 @@ func (handler *K8sApplicationRestHandlerImpl) verifyRbacForAppRequests(token str
11561159
handler.logger.Errorw("error in decoding appId", "err", err, "appId", request.AppId)
11571160
return false, err
11581161
}
1162+
request.ExternalArgoAppIdentifier = argoAppIdentifier
11591163
request.ClusterId = argoAppIdentifier.ClusterId
11601164
request.ExternalArgoApplicationName = argoAppIdentifier.AppName
11611165
valid, err := handler.argoApplicationReadService.ValidateArgoResourceRequest(r.Context(), argoAppIdentifier, request.K8sRequest)

cmd/external-app/wire_gen.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/argoApplication/read/config/ArgoApplicationConfigService.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type ArgoApplicationConfigServiceImpl struct {
2323
}
2424

2525
type ArgoApplicationConfigService interface {
26-
GetRestConfigForExternalArgo(ctx context.Context, clusterId int, externalArgoApplicationName string) (*rest.Config, error)
26+
GetRestConfigForExternalArgo(ctx context.Context, clusterId int, externalArgoAppIdentifier *bean.ArgoAppIdentifier) (*rest.Config, error)
2727
GetClusterConfigFromAllClusters(clusterId int) (*k8s.ClusterConfig, clusterRepository.Cluster, map[string]int, error)
2828
}
2929

@@ -59,20 +59,20 @@ func (impl *ArgoApplicationConfigServiceImpl) GetClusterConfigFromAllClusters(cl
5959
return clusterConfig, clusterWithApplicationObject, clusterServerUrlIdMap, err
6060
}
6161

62-
func (impl *ArgoApplicationConfigServiceImpl) GetRestConfigForExternalArgo(ctx context.Context, clusterId int, externalArgoApplicationName string) (*rest.Config, error) {
63-
clusterConfig, clusterWithApplicationObject, clusterServerUrlIdMap, err := impl.GetClusterConfigFromAllClusters(clusterId)
62+
func (impl *ArgoApplicationConfigServiceImpl) GetRestConfigForExternalArgo(ctx context.Context, clusterId int, externalArgoAppIdentifier *bean.ArgoAppIdentifier) (*rest.Config, error) {
63+
clusterConfig, clusterWithApplicationObject, clusterServerUrlIdMap, err := impl.GetClusterConfigFromAllClusters(externalArgoAppIdentifier.ClusterId)
6464
if err != nil {
65-
impl.logger.Errorw("error in getting cluster config", "err", err, "clusterId", clusterId)
65+
impl.logger.Errorw("error in getting cluster config", "err", err, "clusterId", externalArgoAppIdentifier.ClusterId)
6666
return nil, err
6767
}
6868
restConfig, err := impl.k8sUtil.GetRestConfigByCluster(clusterConfig)
6969
if err != nil {
70-
impl.logger.Errorw("error in getting rest config", "err", err, "clusterId", clusterId)
70+
impl.logger.Errorw("error in getting rest config", "err", err, "clusterId", externalArgoAppIdentifier.ClusterId)
7171
return nil, err
7272
}
73-
resourceResp, err := impl.k8sUtil.GetResource(ctx, bean.DevtronCDNamespae, externalArgoApplicationName, bean.GvkForArgoApplication, restConfig)
73+
resourceResp, err := impl.k8sUtil.GetResource(ctx, externalArgoAppIdentifier.Namespace, externalArgoAppIdentifier.AppName, bean.GvkForArgoApplication, restConfig)
7474
if err != nil {
75-
impl.logger.Errorw("not on external cluster", "err", err, "externalArgoApplicationName", externalArgoApplicationName)
75+
impl.logger.Errorw("not on external cluster", "err", err, "externalArgoApplicationName", externalArgoAppIdentifier.AppName, "externalArgoApplicationNamespace", externalArgoAppIdentifier.Namespace)
7676
return nil, err
7777
}
7878
restConfig, err = impl.GetServerConfigIfClusterIsNotAddedOnDevtron(resourceResp, restConfig, clusterWithApplicationObject, clusterServerUrlIdMap)

pkg/cluster/environment/bean/ephemeralContainerBean.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
package bean
22

3-
import "github.com/devtron-labs/devtron/pkg/cluster/repository"
3+
import (
4+
"github.com/devtron-labs/devtron/pkg/argoApplication/bean"
5+
"github.com/devtron-labs/devtron/pkg/cluster/repository"
6+
)
47

58
type EphemeralContainerRequest struct {
6-
BasicData *EphemeralContainerBasicData `json:"basicData"`
7-
AdvancedData *EphemeralContainerAdvancedData `json:"advancedData"`
8-
Namespace string `json:"namespace" validate:"required"`
9-
ClusterId int `json:"clusterId" validate:"gt=0"`
10-
PodName string `json:"podName" validate:"required"`
11-
ExternalArgoApplicationName string `json:"externalArgoApplicationName,omitempty"`
12-
UserId int32 `json:"-"`
9+
BasicData *EphemeralContainerBasicData `json:"basicData"`
10+
AdvancedData *EphemeralContainerAdvancedData `json:"advancedData"`
11+
Namespace string `json:"namespace" validate:"required"`
12+
ClusterId int `json:"clusterId" validate:"gt=0"`
13+
PodName string `json:"podName" validate:"required"`
14+
ExternalArgoApplicationName string `json:"externalArgoApplicationName,omitempty"`
15+
ExternalArgoApplicationNamespace string `json:"externalArgoApplicationNamespace,omitempty"`
16+
ExternalArgoAppIdentifier *bean.ArgoAppIdentifier `json:"externalArgoAppIdentifier"`
17+
UserId int32 `json:"-"`
1318
}
1419

1520
type EphemeralContainerAdvancedData struct {

pkg/k8s/K8sCommonService.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,10 @@ func (impl *K8sCommonServiceImpl) UpdateResource(ctx context.Context, request *b
192192
func (impl *K8sCommonServiceImpl) GetRestConfigOfCluster(ctx context.Context, request *bean5.ResourceRequestBean) (*rest.Config, error) {
193193
//getting rest config by clusterId
194194
clusterId := request.ClusterId
195-
if len(request.ExternalArgoApplicationName) > 0 {
196-
restConfig, err := impl.argoApplicationConfigService.GetRestConfigForExternalArgo(ctx, clusterId, request.ExternalArgoApplicationName)
195+
if request.ExternalArgoAppIdentifier != nil && len(request.ExternalArgoAppIdentifier.AppName) > 0 {
196+
restConfig, err := impl.argoApplicationConfigService.GetRestConfigForExternalArgo(ctx, clusterId, request.ExternalArgoAppIdentifier)
197197
if err != nil {
198-
impl.logger.Errorw("error in getting rest config", "err", err, "clusterId", clusterId, "externalArgoApplicationName", request.ExternalArgoApplicationName)
198+
impl.logger.Errorw("error in getting rest config", "err", err, "clusterId", clusterId, "externalArgoApplicationName", request.ExternalArgoAppIdentifier.AppName)
199199
return nil, err
200200
}
201201
return restConfig, nil
@@ -460,7 +460,7 @@ func (impl *K8sCommonServiceImpl) GetCoreClientByClusterId(clusterId int) (*kube
460460
}
461461

462462
func (impl *K8sCommonServiceImpl) GetCoreClientByClusterIdForExternalArgoApps(req *bean4.EphemeralContainerRequest) (*kubernetes.Clientset, *clientV1.CoreV1Client, error) {
463-
restConfig, err := impl.argoApplicationConfigService.GetRestConfigForExternalArgo(context.Background(), req.ClusterId, req.ExternalArgoApplicationName)
463+
restConfig, err := impl.argoApplicationConfigService.GetRestConfigForExternalArgo(context.Background(), req.ClusterId, req.ExternalArgoAppIdentifier)
464464
if err != nil {
465465
impl.logger.Errorw("error in getting rest config", "err", err, "clusterId", req.ClusterId, "externalArgoApplicationName", req.ExternalArgoApplicationName)
466466
}

pkg/k8s/application/k8sApplicationService.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ func (impl *K8sApplicationServiceImpl) ValidatePodLogsRequestQuery(r *http.Reque
263263
request.ClusterId = appIdentifier.ClusterId
264264
request.K8sRequest.ResourceIdentifier.Namespace = namespace
265265
request.AppId = appId
266+
request.ExternalArgoAppIdentifier = appIdentifier
266267
} else if request.AppType == bean3.HelmAppType {
267268
// For Helm App resources
268269
appIdentifier, err := impl.helmAppService.DecodeAppId(appId)
@@ -370,6 +371,8 @@ func (impl *K8sApplicationServiceImpl) ValidateTerminalRequestQuery(r *http.Requ
370371
resourceRequestBean.ClusterId = appIdentifier.ClusterId
371372
request.ClusterId = appIdentifier.ClusterId
372373
request.ExternalArgoApplicationName = appIdentifier.AppName
374+
request.ExternalArgoApplicationNamespace = appIdentifier.Namespace
375+
request.ExternalArgoAppIdentifier = appIdentifier
373376
}
374377
} else {
375378
// Validate Cluster Id

pkg/k8s/bean/bean.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package bean
1919
import (
2020
"github.com/devtron-labs/common-lib/utils/k8s"
2121
helmBean "github.com/devtron-labs/devtron/api/helm-app/service/bean"
22+
bean3 "github.com/devtron-labs/devtron/pkg/argoApplication/bean"
2223
bean2 "github.com/devtron-labs/devtron/pkg/fluxApplication/bean"
2324
"github.com/devtron-labs/devtron/pkg/k8s/application/bean"
2425
)
@@ -33,6 +34,7 @@ type ResourceRequestBean struct {
3334
ClusterId int `json:"clusterId"` // clusterId is used when request is for direct cluster (not for helm release)
3435
ExternalArgoApplicationName string `json:"externalArgoApplicationName,omitempty"`
3536
ExternalFluxAppIdentifier *bean2.FluxAppIdentifier `json: "-"`
37+
ExternalArgoAppIdentifier *bean3.ArgoAppIdentifier `json:"-"`
3638
}
3739

3840
func (r *ResourceRequestBean) IsValidAppType() bool {

pkg/terminal/terminalSesion.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"github.com/caarlos0/env"
2727
"github.com/devtron-labs/common-lib/utils/k8s"
2828
"github.com/devtron-labs/devtron/internal/middleware"
29+
bean3 "github.com/devtron-labs/devtron/pkg/argoApplication/bean"
2930
"github.com/devtron-labs/devtron/pkg/argoApplication/read/config"
3031
"github.com/devtron-labs/devtron/pkg/cluster"
3132
"github.com/devtron-labs/devtron/pkg/cluster/bean"
@@ -393,9 +394,11 @@ type TerminalSessionRequest struct {
393394
EnvironmentId int
394395
AppId int
395396
//ClusterId is optional
396-
ClusterId int
397-
UserId int32
398-
ExternalArgoApplicationName string
397+
ClusterId int
398+
UserId int32
399+
ExternalArgoApplicationName string
400+
ExternalArgoApplicationNamespace string
401+
ExternalArgoAppIdentifier *bean3.ArgoAppIdentifier
399402
}
400403

401404
const CommandExecutionFailed = "Failed to Execute Command"
@@ -536,7 +539,7 @@ func (impl *TerminalSessionHandlerImpl) getClientSetAndRestConfigForTerminalConn
536539
var restConfig *rest.Config
537540
var err error
538541
if len(req.ExternalArgoApplicationName) > 0 {
539-
restConfig, err = impl.argoApplicationConfigService.GetRestConfigForExternalArgo(context.Background(), req.ClusterId, req.ExternalArgoApplicationName)
542+
restConfig, err = impl.argoApplicationConfigService.GetRestConfigForExternalArgo(context.Background(), req.ClusterId, req.ExternalArgoAppIdentifier)
540543
if err != nil {
541544
impl.logger.Errorw("error in getting rest config", "err", err, "clusterId", req.ClusterId, "externalArgoApplicationName", req.ExternalArgoApplicationName)
542545
return nil, nil, err
@@ -657,7 +660,7 @@ func (impl *TerminalSessionHandlerImpl) saveEphemeralContainerTerminalAccessAudi
657660
var restConfig *rest.Config
658661
var err error
659662
if len(req.ExternalArgoApplicationName) > 0 {
660-
restConfig, err = impl.argoApplicationConfigService.GetRestConfigForExternalArgo(context.Background(), req.ClusterId, req.ExternalArgoApplicationName)
663+
restConfig, err = impl.argoApplicationConfigService.GetRestConfigForExternalArgo(context.Background(), req.ClusterId, req.ExternalArgoAppIdentifier)
661664
if err != nil {
662665
impl.logger.Errorw("error in getting rest config", "err", err, "clusterId", req.ClusterId, "externalArgoApplicationName", req.ExternalArgoApplicationName)
663666
return err

0 commit comments

Comments
 (0)