Skip to content

Commit

Permalink
Merge pull request #517 from sangkenlee/get-org-template-current-version
Browse files Browse the repository at this point in the history
템플릿 조회 시 현재 클러스터에 적용된 템플릿 버전이 표시되도록 수정
  • Loading branch information
ktkfree authored Jun 18, 2024
2 parents daa6db6 + 3b0a770 commit 41d0e59
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
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

0 comments on commit 41d0e59

Please sign in to comment.