Skip to content

Commit

Permalink
Merge pull request #476 from openinfradev/namespace_resources
Browse files Browse the repository at this point in the history
feature. add force deleting logic when the cluster status was invalid
  • Loading branch information
cho4036 authored May 7, 2024
2 parents 706b1aa + 40e40a6 commit 091c91f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
10 changes: 8 additions & 2 deletions internal/usecase/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,14 @@ func (u *StackUsecase) Delete(ctx context.Context, dto model.Stack) (err error)
return httpErrors.NewBadRequestError(errors.Wrap(err, "Failed to get cluster"), "S_FAILED_FETCH_CLUSTER", "")
}

// cluster 의 상태가 비정상 상태라면, DB 데이터만 삭제
if cluster.Status != domain.ClusterStatus_RUNNING &&
cluster.Status != domain.ClusterStatus_BOOTSTRAPPING &&
cluster.Status != domain.ClusterStatus_INSTALLING &&
cluster.Status != domain.ClusterStatus_DELETING {
return u.clusterRepo.Delete(ctx, domain.ClusterId(dto.ID))
}

// 지우려고 하는 stack 이 primary cluster 라면, organization 내에 cluster 가 자기 자신만 남아있을 경우이다.
organizations, err := u.organizationRepo.Fetch(ctx, nil)
if err != nil {
Expand Down Expand Up @@ -464,8 +472,6 @@ func (u *StackUsecase) Delete(ctx context.Context, dto model.Stack) (err error)
return httpErrors.NewBadRequestError(fmt.Errorf("existed appServeApps in %s", dto.OrganizationId), "S_FAILED_DELETE_EXISTED_ASA", "")
}

// Policy 삭제

workflow := "tks-stack-delete"
workflowId, err := u.argo.SumbitWorkflowFromWftpl(ctx, workflow, argowf.SubmitOptions{
Parameters: []string{
Expand Down
21 changes: 18 additions & 3 deletions internal/usecase/system-notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ func (u *SystemNotificationUsecase) Create(ctx context.Context, input domain.Cre
}
}

// [TODO] policy 일 경우 처리

dto := model.SystemNotification{
OrganizationId: organizationId,
Name: systemNotification.Labels.AlertName,
Expand All @@ -140,7 +142,6 @@ func (u *SystemNotificationUsecase) Create(ctx context.Context, input domain.Cre
continue
}

// 사용자가 생성한 알림
if systemNotificationRuleId != nil {
rule, err := u.systemNotificationRuleRepo.Get(ctx, *systemNotificationRuleId)
if err != nil {
Expand All @@ -150,9 +151,23 @@ func (u *SystemNotificationUsecase) Create(ctx context.Context, input domain.Cre

if rule.SystemNotificationCondition.EnableEmail {
to := []string{}
for _, user := range rule.TargetUsers {
to = append(to, user.Email)

// 아무것도 지정되어 있지 않다면, organization 전체 대상으로 발송한다.
if rule.TargetUsers == nil || len(rule.TargetUsers) == 0 {
users, err := u.userRepo.List(ctx, u.userRepo.OrganizationFilter(organizationId))
if err != nil || users == nil {
log.Error(ctx, "Failed to get users ", err)
continue
}
for _, user := range *users {
to = append(to, user.Email)
}
} else {
for _, user := range rule.TargetUsers {
to = append(to, user.Email)
}
}

message, err := mail.MakeSystemNotificationMessage(ctx, organizationId, systemNotification.Annotations.Message, systemNotification.Annotations.Description, to)
if err != nil {
log.Error(ctx, fmt.Sprintf("Failed to make email content. err : %s", err.Error()))
Expand Down

0 comments on commit 091c91f

Please sign in to comment.