From b802ec5b51c378c185699e2655434c2344dc08ad Mon Sep 17 00:00:00 2001 From: sangkenlee Date: Tue, 16 Apr 2024 13:14:24 +0900 Subject: [PATCH] =?UTF-8?q?spec.clusters:=20Required=20value=20=EB=B2=84?= =?UTF-8?q?=EA=B7=B8=20=ED=94=BD=EC=8A=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/policy-template/policy-operator.go | 8 +++++++- internal/usecase/policy.go | 18 +++++++++--------- pkg/domain/policy.go | 20 ++++++++++---------- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/internal/policy-template/policy-operator.go b/internal/policy-template/policy-operator.go index 84831e1f..ad192c00 100644 --- a/internal/policy-template/policy-operator.go +++ b/internal/policy-template/policy-operator.go @@ -50,6 +50,12 @@ func PolicyToTksPolicyCR(policy *model.Policy) *TKSPolicy { } } + targetClusterIds := make([]string, 0) + + if policy.TargetClusterIds != nil { + targetClusterIds = policy.TargetClusterIds + } + return &TKSPolicy{ TypeMeta: metav1.TypeMeta{ APIVersion: "tkspolicy.openinfradev.github.io/v1", @@ -63,7 +69,7 @@ func PolicyToTksPolicyCR(policy *model.Policy) *TKSPolicy { Spec: TKSPolicySpec{ EnforcementAction: policy.EnforcementAction, - Clusters: policy.TargetClusterIds, + Clusters: targetClusterIds, Template: policy.PolicyTemplate.Kind, Match: policy.Match, Params: params, diff --git a/internal/usecase/policy.go b/internal/usecase/policy.go index d2566032..c417d67d 100644 --- a/internal/usecase/policy.go +++ b/internal/usecase/policy.go @@ -572,7 +572,7 @@ func (u *PolicyUsecase) ListStackPolicyStatus(ctx context.Context, clusterId str // result[i].TemplateCurrentVersion = version // } - result[i].TemplateLatestVerson = latestVersion + result[i].TemplateLatestVersion = latestVersion result[i].TemplateDescription = policy.PolicyTemplate.Description } @@ -711,14 +711,14 @@ func (u *PolicyUsecase) GetStackPolicyTemplateStatus(ctx context.Context, cluste } result := domain.GetStackPolicyTemplateStatusResponse{ - TemplateName: currentTemplate.TemplateName, - TemplateId: policyTemplateId.String(), - TemplateDescription: currentTemplate.Description, - TemplateLatestVerson: latestTemplate.Version, - TemplateCurrentVersion: currentTemplate.Version, - TemplateLatestVersonReleaseDate: latestTemplate.CreatedAt, - AffectedPolicies: affectedPolicies, - UpdatedPolicyParameters: updatedPolicyParameters, + TemplateName: currentTemplate.TemplateName, + TemplateId: policyTemplateId.String(), + TemplateDescription: currentTemplate.Description, + TemplateLatestVersion: latestTemplate.Version, + TemplateCurrentVersion: currentTemplate.Version, + TemplateLatestVersionReleaseDate: latestTemplate.CreatedAt, + AffectedPolicies: affectedPolicies, + UpdatedPolicyParameters: updatedPolicyParameters, } return &result, nil diff --git a/pkg/domain/policy.go b/pkg/domain/policy.go index a147bfc4..411da352 100644 --- a/pkg/domain/policy.go +++ b/pkg/domain/policy.go @@ -134,7 +134,7 @@ type StackPolicyStatusResponse struct { TemplateId string `json:"templateId" example:"708d1e5b-4e6f-40e9-87a3-329e2fd051a5"` TemplateDescription string `json:"templateDescription" example:"파라미터로 설정된 레이블 검사"` TemplateCurrentVersion string `json:"templateCurrentVersion" example:"v1.0.1"` - TemplateLatestVerson string `json:"templateLatestVerson" example:"v1.0.3"` + TemplateLatestVersion string `json:"templateLatestVersion" example:"v1.0.3"` } type ListStackPolicyStatusResponse struct { @@ -142,15 +142,15 @@ type ListStackPolicyStatusResponse struct { } type GetStackPolicyTemplateStatusResponse struct { - TemplateName string `json:"templateName" example:"레이블 요구"` - TemplateId string `json:"templateId" example:"708d1e5b-4e6f-40e9-87a3-329e2fd051a5"` - TemplateDescription string `json:"templateDescription" example:"파라미터로 설정된 레이블 검사"` - TemplateMandatory bool `json:"templateMandatory"` - TemplateCurrentVersion string `json:"templateCurrentVersion" example:"v1.0.1"` - TemplateLatestVerson string `json:"templateLatestVerson" example:"v1.0.3"` - TemplateLatestVersonReleaseDate time.Time `json:"templateLatestVersonReleaseDate" format:"date-time"` - UpdatedPolicyParameters []UpdatedPolicyTemplateParameter `json:"updatedPolicyParameters"` - AffectedPolicies []PolicyStatus `json:"affectedPolicies"` + TemplateName string `json:"templateName" example:"레이블 요구"` + TemplateId string `json:"templateId" example:"708d1e5b-4e6f-40e9-87a3-329e2fd051a5"` + TemplateDescription string `json:"templateDescription" example:"파라미터로 설정된 레이블 검사"` + TemplateMandatory bool `json:"templateMandatory"` + TemplateCurrentVersion string `json:"templateCurrentVersion" example:"v1.0.1"` + TemplateLatestVersion string `json:"templateLatestVersion" example:"v1.0.3"` + TemplateLatestVersionReleaseDate time.Time `json:"templateLatestVersionReleaseDate" format:"date-time"` + UpdatedPolicyParameters []UpdatedPolicyTemplateParameter `json:"updatedPolicyParameters"` + AffectedPolicies []PolicyStatus `json:"affectedPolicies"` } type PolicyStatus struct {