Skip to content
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

템플릿 조회 시 현재 클러스터에 적용된 템플릿 버전이 표시되도록 수정 #517

Merged
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
27 changes: 27 additions & 0 deletions internal/usecase/policy-template.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,33 @@ func (u *PolicyTemplateUsecase) Get(ctx context.Context, organizationId *string,
}
}

if organizationId != nil {
(*policyTemplate).LatestVersion = policyTemplate.Version

var primaryClusterId string

org, err := u.organizationRepo.Get(ctx, *organizationId)

if err != nil {
log.Errorf(ctx, "error is :%s(%T)", err.Error(), err)
} else {
// 에러 없이 primaryClusterId를 가져왔을 때만 처리
primaryClusterId = org.PrimaryClusterId

templateCR, err := policytemplate.GetTksPolicyTemplateCR(ctx, primaryClusterId, policyTemplate.ResoureName())

if err == nil && templateCR != nil {
(*policyTemplate).CurrentVersion = templateCR.Spec.Version
} else if errors.IsNotFound(err) || templateCR == nil {
// 템플릿이 존재하지 않으면 최신 버전으로 배포되므로
(*policyTemplate).CurrentVersion = policyTemplate.LatestVersion
} else {
// 통신 실패 등 기타 에러, 버전을 세팅하지 않아 에러임을 알수 있도록 로그를 남김
log.Errorf(ctx, "error is :%s(%T)", err.Error(), err)
}
}
}

return policyTemplate, nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/domain/policy-template.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ type CreatePolicyTemplateVersionResponse struct {
}

type GetPolicyTemplateResponse struct {
PolicyTemplate PolicyTemplateResponse `json:"policyTemplate"`
PolicyTemplate PolicyTemplateTwoVersionResponse `json:"policyTemplate"`
}

type ListPolicyTemplateResponse struct {
Expand Down
Loading