Skip to content

feature. add workflowId to updateCluster(AppGroup)Status for tks-batch #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/deploy-image-with-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
pull_request:
branches:
- main
- 'release**'
jobs:
build-and-push-image:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
push:
branches:
- main

- 'release**'
jobs:
build-and-push-image:
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/golangcic-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
- v*
branches:
- main
- 'release**'
pull_request:
jobs:
golangci:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ on:
push:
branches:
- main
- 'release**'
pull_request:
branches:
- main


- 'release**'
jobs:
unittest:
runs-on: ubuntu-latest
Expand Down
87 changes: 43 additions & 44 deletions cmd/server/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,28 +252,6 @@ func (s *server) CreateCluster(ctx context.Context, in *pb.CreateClusterRequest)
}
}

// check cluster
// Exactly one of those must be provided
/*
res, err := clusterInfoClient.GetClusters(ctx, &pb.GetClustersRequest{
ContractId : in.GetContractId(),
CspId : "",
})
if err == nil {
for _, cluster := range res.GetClusters() {
if cluster.GetStatus() == pb.ClusterStatus_INSTALLING {
log.Info( "Already existed installing workflow. cluster : ", cluster )
return &pb.IDResponse{
Code: pb.Code_ALREADY_EXISTS,
Error: &pb.Error{
Msg: fmt.Sprintf("Already existed installing workflow. : %s", cluster.GetName()),
},
}, nil
}
}
}
*/

/***************************
* Pre-process cluster conf *
***************************/
Expand Down Expand Up @@ -327,7 +305,7 @@ func (s *server) CreateCluster(ctx context.Context, in *pb.CreateClusterRequest)

log.Info("Submitting workflow: ", workflow)

workflowName, err := argowfClient.SumbitWorkflowFromWftpl(ctx, workflow, nameSpace, parameters)
workflowId, err := argowfClient.SumbitWorkflowFromWftpl(ctx, workflow, nameSpace, parameters)
if err != nil {
log.Error("failed to submit argo workflow template. err : ", err)
return &pb.IDResponse{
Expand All @@ -337,10 +315,10 @@ func (s *server) CreateCluster(ctx context.Context, in *pb.CreateClusterRequest)
},
}, err
}
log.Info("Successfully submited workflow: ", workflowName)
log.Info("Successfully submited workflow: ", workflowId)

// update status : INSTALLING
if err := s.updateClusterStatus(ctx, clusterId, pb.ClusterStatus_INSTALLING); err != nil {
if err := s.updateClusterStatusWithWorkflowId(ctx, clusterId, pb.ClusterStatus_INSTALLING, workflowId); err != nil {
log.Error("Failed to update cluster status to 'INSTALLING'")
}

Expand All @@ -365,6 +343,7 @@ func (s *server) ScaleCluster(ctx context.Context, in *pb.ScaleClusterRequest) (
func (s *server) DeleteCluster(ctx context.Context, in *pb.IDRequest) (*pb.SimpleResponse, error) {
log.Info("Request 'DeleteCluster' for clusterId : ", in.GetId())

// Validation : check request
if err := validateDeleteClusterRequest(in); err != nil {
return &pb.SimpleResponse{
Code: pb.Code_INVALID_ARGUMENT,
Expand All @@ -375,6 +354,8 @@ func (s *server) DeleteCluster(ctx context.Context, in *pb.IDRequest) (*pb.Simpl
}
clusterId := in.GetId()

// Validation : check cluster status
// The cluster status must be (RUNNING|ERROR).
res, err := clusterInfoClient.GetCluster(ctx, &pb.GetClusterRequest{ClusterId: clusterId})
if err != nil {
log.Error("Failed to get cluster info err : ", err)
Expand All @@ -385,15 +366,31 @@ func (s *server) DeleteCluster(ctx context.Context, in *pb.IDRequest) (*pb.Simpl
},
}, err
}

if res.GetCluster().GetStatus() == pb.ClusterStatus_DELETING || res.GetCluster().GetStatus() == pb.ClusterStatus_DELETED {
log.Error("The cluster has been already deleted. status : ", res.GetCluster().GetStatus())
if res.GetCluster().GetStatus() != pb.ClusterStatus_RUNNING &&
res.GetCluster().GetStatus() != pb.ClusterStatus_ERROR {
return &pb.SimpleResponse{
Code: pb.Code_NOT_FOUND,
Code: pb.Code_INVALID_ARGUMENT,
Error: &pb.Error{
Msg: fmt.Sprintf("Could not find cluster with ID. %s", clusterId),
Msg: fmt.Sprintf("The cluster can not be deleted. cluster status : %s", res.GetCluster().GetStatus()),
},
}, fmt.Errorf("Could not find cluster with ID. %s", clusterId)
}, fmt.Errorf("The cluster can not be deleted. cluster status : %s", res.GetCluster().GetStatus())
}

// Validation : check appgroup status
resAppGroups, err := appInfoClient.GetAppGroupsByClusterID(ctx, &pb.IDRequest{
Id: clusterId,
})
if err == nil && resAppGroups.Code == pb.Code_OK_UNSPECIFIED {
for _, resAppGroup := range resAppGroups.GetAppGroups() {
if resAppGroup.GetStatus() != pb.AppGroupStatus_APP_GROUP_DELETED {
return &pb.SimpleResponse{
Code: pb.Code_INVALID_ARGUMENT,
Error: &pb.Error{
Msg: fmt.Sprintf("Undeleted services remain. %s", resAppGroup.GetAppGroupId()),
},
}, fmt.Errorf("Undeleted services remain. %s", resAppGroup.GetAppGroupId())
}
}
}

nameSpace := "argo"
Expand All @@ -404,7 +401,7 @@ func (s *server) DeleteCluster(ctx context.Context, in *pb.IDRequest) (*pb.Simpl
"cluster_id=" + clusterId,
}

workflowName, err := argowfClient.SumbitWorkflowFromWftpl(ctx, workflow, nameSpace, parameters)
workflowId, err := argowfClient.SumbitWorkflowFromWftpl(ctx, workflow, nameSpace, parameters)
if err != nil {
log.Error("failed to submit argo workflow template. err : ", err)
return &pb.SimpleResponse{
Expand All @@ -414,9 +411,9 @@ func (s *server) DeleteCluster(ctx context.Context, in *pb.IDRequest) (*pb.Simpl
},
}, err
}
log.Debug("submited workflow name : ", workflowName)
log.Debug("submited workflow name : ", workflowId)

if err := s.updateClusterStatus(ctx, clusterId, pb.ClusterStatus_DELETING); err != nil {
if err := s.updateClusterStatusWithWorkflowId(ctx, clusterId, pb.ClusterStatus_DELETING, workflowId); err != nil {
log.Error("Failed to update cluster status to 'DELETING'")
}

Expand Down Expand Up @@ -520,14 +517,14 @@ func (s *server) InstallAppGroups(ctx context.Context, in *pb.InstallAppGroupsRe
}
log.Debug("workflowTemplate : ", workflowTemplate)

workflowName, err := argowfClient.SumbitWorkflowFromWftpl(ctx, workflowTemplate, "argo", parameters)
workflowId, err := argowfClient.SumbitWorkflowFromWftpl(ctx, workflowTemplate, "argo", parameters)
if err != nil {
log.Error("failed to submit argo workflow template. err : ", err)
continue
}
log.Debug("submited workflow name :", workflowName)
log.Debug("submited workflow name :", workflowId)

if err := s.updateAppGroupStatus(ctx, appGroupId, pb.AppGroupStatus_APP_GROUP_INSTALLING); err != nil {
if err := s.updateAppGroupStatusWithWorkflowId(ctx, appGroupId, pb.AppGroupStatus_APP_GROUP_INSTALLING, workflowId); err != nil {
log.Error("Failed to update appgroup status to 'APP_GROUP_INSTALLING'")
}

Expand Down Expand Up @@ -597,15 +594,15 @@ func (s *server) UninstallAppGroups(ctx context.Context, in *pb.UninstallAppGrou
"app_group_id=" + appGroupId,
}

workflowName, err := argowfClient.SumbitWorkflowFromWftpl(ctx, workflowTemplate, "argo", parameters)
workflowId, err := argowfClient.SumbitWorkflowFromWftpl(ctx, workflowTemplate, "argo", parameters)
if err != nil {
log.Error("failed to submit argo workflow template. err : ", err)
continue
}
log.Debug("submited workflow name :", workflowName)
log.Debug("submited workflow name :", workflowId)

resAppGroupIds = append(resAppGroupIds, appGroupId)
if err := s.updateAppGroupStatus(ctx, appGroupId, pb.AppGroupStatus_APP_GROUP_DELETING); err != nil {
if err := s.updateAppGroupStatusWithWorkflowId(ctx, appGroupId, pb.AppGroupStatus_APP_GROUP_DELETING, workflowId); err != nil {
log.Error("Failed to update appgroup status to 'APP_GROUP_DELETING'")
}
}
Expand All @@ -617,10 +614,11 @@ func (s *server) UninstallAppGroups(ctx context.Context, in *pb.UninstallAppGrou
}, nil
}

func (s *server) updateClusterStatus(ctx context.Context, clusterId string, status pb.ClusterStatus) error {
func (s *server) updateClusterStatusWithWorkflowId(ctx context.Context, clusterId string, status pb.ClusterStatus, workflowId string) error {
_, err := clusterInfoClient.UpdateClusterStatus(ctx, &pb.UpdateClusterStatusRequest{
ClusterId: clusterId,
Status: status,
ClusterId: clusterId,
Status: status,
WorkflowId: workflowId,
})
if err != nil {
log.Error("Failed to update cluster status err : ", err)
Expand All @@ -630,10 +628,11 @@ func (s *server) updateClusterStatus(ctx context.Context, clusterId string, stat
return nil
}

func (s *server) updateAppGroupStatus(ctx context.Context, appGroupId string, status pb.AppGroupStatus) error {
func (s *server) updateAppGroupStatusWithWorkflowId(ctx context.Context, appGroupId string, status pb.AppGroupStatus, workflowId string) error {
_, err := appInfoClient.UpdateAppGroupStatus(ctx, &pb.UpdateAppGroupStatusRequest{
AppGroupId: appGroupId,
Status: status,
WorkflowId: workflowId,
})
if err != nil {
log.Error("Failed to update appgroup status err : ", err)
Expand Down
Loading