@@ -24,9 +24,11 @@ import (
2424 "github.com/argoproj/gitops-engine/pkg/health"
2525 blob_storage "github.com/devtron-labs/common-lib/blob-storage"
2626 gitSensorClient "github.com/devtron-labs/devtron/client/gitSensor"
27+ "github.com/devtron-labs/devtron/client/k8s/application"
2728 "github.com/devtron-labs/devtron/pkg/app/status"
2829 util4 "github.com/devtron-labs/devtron/util"
2930 "github.com/devtron-labs/devtron/util/argo"
31+ "github.com/devtron-labs/devtron/util/k8s"
3032 "go.opentelemetry.io/otel"
3133 "strconv"
3234 "strings"
@@ -71,6 +73,7 @@ type WorkflowDagExecutor interface {
7173 TriggerBulkDeploymentAsync (requests []* BulkTriggerRequest , UserId int32 ) (interface {}, error )
7274 StopStartApp (stopRequest * StopAppRequest , ctx context.Context ) (int , error )
7375 TriggerBulkHibernateAsync (request StopDeploymentGroupRequest , ctx context.Context ) (interface {}, error )
76+ RotatePods (ctx context.Context , podRotateRequest * PodRotateRequest ) (* k8s.RotatePodResponse , error )
7477}
7578
7679type WorkflowDagExecutorImpl struct {
@@ -105,6 +108,7 @@ type WorkflowDagExecutorImpl struct {
105108 ciWorkflowRepository pipelineConfig.CiWorkflowRepository
106109 appLabelRepository pipelineConfig.AppLabelRepository
107110 gitSensorGrpcClient gitSensorClient.Client
111+ k8sApplicationService k8s.K8sApplicationService
108112}
109113
110114const (
@@ -169,7 +173,8 @@ func NewWorkflowDagExecutorImpl(Logger *zap.SugaredLogger, pipelineRepository pi
169173 pipelineStatusTimelineService status.PipelineStatusTimelineService ,
170174 CiTemplateRepository pipelineConfig.CiTemplateRepository ,
171175 ciWorkflowRepository pipelineConfig.CiWorkflowRepository ,
172- appLabelRepository pipelineConfig.AppLabelRepository , gitSensorGrpcClient gitSensorClient.Client ) * WorkflowDagExecutorImpl {
176+ appLabelRepository pipelineConfig.AppLabelRepository , gitSensorGrpcClient gitSensorClient.Client ,
177+ k8sApplicationService k8s.K8sApplicationService ) * WorkflowDagExecutorImpl {
173178 wde := & WorkflowDagExecutorImpl {logger : Logger ,
174179 pipelineRepository : pipelineRepository ,
175180 cdWorkflowRepository : cdWorkflowRepository ,
@@ -201,6 +206,7 @@ func NewWorkflowDagExecutorImpl(Logger *zap.SugaredLogger, pipelineRepository pi
201206 ciWorkflowRepository : ciWorkflowRepository ,
202207 appLabelRepository : appLabelRepository ,
203208 gitSensorGrpcClient : gitSensorGrpcClient ,
209+ k8sApplicationService : k8sApplicationService ,
204210 }
205211 err := wde .Subscribe ()
206212 if err != nil {
@@ -1268,6 +1274,39 @@ type StopDeploymentGroupRequest struct {
12681274 RequestType RequestType `json:"requestType" validate:"oneof=START STOP"`
12691275}
12701276
1277+ type PodRotateRequest struct {
1278+ AppId int `json:"appId" validate:"required"`
1279+ EnvironmentId int `json:"environmentId" validate:"required"`
1280+ UserId int32 `json:"-"`
1281+ ResourceIdentifiers []application.ResourceIdentifier `json:"resources" validate:"required"`
1282+ }
1283+
1284+ func (impl * WorkflowDagExecutorImpl ) RotatePods (ctx context.Context , podRotateRequest * PodRotateRequest ) (* k8s.RotatePodResponse , error ) {
1285+ impl .logger .Infow ("rotate pod request" , "payload" , podRotateRequest )
1286+ //extract cluster id and namespace from env id
1287+ environmentId := podRotateRequest .EnvironmentId
1288+ environment , err := impl .envRepository .FindById (environmentId )
1289+ if err != nil {
1290+ impl .logger .Errorw ("error occurred while fetching env details" , "envId" , environmentId , "err" , err )
1291+ return nil , err
1292+ }
1293+ var resourceIdentifiers []application.ResourceIdentifier
1294+ for _ , resourceIdentifier := range podRotateRequest .ResourceIdentifiers {
1295+ resourceIdentifier .Namespace = environment .Namespace
1296+ resourceIdentifiers = append (resourceIdentifiers , resourceIdentifier )
1297+ }
1298+ rotatePodRequest := & k8s.RotatePodRequest {
1299+ ClusterId : environment .ClusterId ,
1300+ Resources : resourceIdentifiers ,
1301+ }
1302+ response , err := impl .k8sApplicationService .RotatePods (ctx , rotatePodRequest )
1303+ if err != nil {
1304+ return nil , err
1305+ }
1306+ //TODO KB: make entry in cd workflow runner
1307+ return response , nil
1308+ }
1309+
12711310func (impl * WorkflowDagExecutorImpl ) StopStartApp (stopRequest * StopAppRequest , ctx context.Context ) (int , error ) {
12721311 pipelines , err := impl .pipelineRepository .FindActiveByAppIdAndEnvironmentId (stopRequest .AppId , stopRequest .EnvironmentId )
12731312 if err != nil {
0 commit comments