diff --git a/extension/approval/approval_collector.go b/extension/approval/approval_collector.go index d2bc1ea6..db3f5648 100644 --- a/extension/approval/approval_collector.go +++ b/extension/approval/approval_collector.go @@ -47,10 +47,8 @@ type MainCollector struct { } // New - create new sender -func New(approvalsManager approvals.Manager) *MainCollector { - return &MainCollector{ - approvalsManager: approvalsManager, - } +func New() *MainCollector { + return &MainCollector{} } // Configure - configure is used to register multiple notification senders diff --git a/provider/kubernetes/approvals.go b/provider/kubernetes/approvals.go index f84e6458..898cf05d 100644 --- a/provider/kubernetes/approvals.go +++ b/provider/kubernetes/approvals.go @@ -67,7 +67,7 @@ func (p *Provider) isApproved(event *types.Event, plan *UpdatePlan) (bool, error identifier := getIdentifier(plan.Deployment.Namespace, plan.Deployment.Name, plan.NewVersion) // checking for existing approval - existing, err := p.approvalManager.Get(types.ProviderTypeKubernetes, identifier) + existing, err := p.approvalManager.Get(identifier) if err != nil { if err == cache.ErrNotFound { @@ -98,5 +98,5 @@ func (p *Provider) isApproved(event *types.Event, plan *UpdatePlan) (bool, error return false, err } - return existing.Approved(), nil + return existing.Status() == types.ApprovalStatusApproved, nil } diff --git a/provider/kubernetes/approvals_test.go b/provider/kubernetes/approvals_test.go index cf3cef39..ce8cf7fe 100644 --- a/provider/kubernetes/approvals_test.go +++ b/provider/kubernetes/approvals_test.go @@ -67,7 +67,7 @@ func TestCheckRequestedApproval(t *testing.T) { } // checking approvals - approval, err := provider.approvalManager.Get(types.ProviderTypeKubernetes, "xxxx/dep-1:1.1.2") + approval, err := provider.approvalManager.Get("xxxx/dep-1:1.1.2") if err != nil { t.Fatalf("failed to find approval, err: %s", err) } diff --git a/types/types.go b/types/types.go index 3050f28e..f4b37608 100644 --- a/types/types.go +++ b/types/types.go @@ -304,9 +304,39 @@ type Approval struct { UpdatedAt time.Time } -// Approved - checks if approval is approved -func (a *Approval) Approved() bool { - return !a.Rejected && a.VotesReceived >= a.VotesRequired +type ApprovalStatus int + +const ( + ApprovalStatusUnknown ApprovalStatus = iota + ApprovalStatusPending + ApprovalStatusApproved + ApprovalStatusRejected +) + +func (s ApprovalStatus) String() string { + switch s { + case ApprovalStatusPending: + return "pending" + case ApprovalStatusApproved: + return "approved" + case ApprovalStatusRejected: + return "rejected" + default: + return "unknown" + } +} + +// Status - returns current approval status +func (a *Approval) Status() ApprovalStatus { + if a.Rejected { + return ApprovalStatusRejected + } + + if a.VotesReceived >= a.VotesRequired { + return ApprovalStatusApproved + } + + return ApprovalStatusPending } // Delta of what's changed