[BUGFIX] Do not attempt to clear approvals when there are none

pull/826/head
David 2025-06-16 15:35:33 +02:00 committed by GitHub
parent ce7a4aa161
commit 4d5eb50176
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 1 deletions

View File

@ -36,6 +36,9 @@ type Manager interface {
// Rejects Approval
Reject(identifier string) (*types.Approval, error)
// If the approval exists
Exists(identifier string) bool
Get(identifier string) (*types.Approval, error)
List() ([]*types.Approval, error)
Delete(*types.Approval) error
@ -372,6 +375,14 @@ func (m *DefaultManager) Delete(approval *types.Approval) error {
return m.store.DeleteApproval(existing)
}
func (m *DefaultManager) Exists(identifier string) bool {
_, err := m.Get(identifier)
if err != nil {
return false
}
return true
}
func (m *DefaultManager) Archive(identifier string) error {
existing, err := m.Get(identifier)
if err != nil {

View File

@ -37,7 +37,12 @@ func (p *Provider) checkForApprovals(event *types.Event, plans []*UpdatePlan) (a
// updateComplete is called after we successfully update resource
func (p *Provider) updateComplete(plan *UpdatePlan) error {
return p.approvalManager.Archive(getApprovalIdentifier(plan.Resource.Identifier, plan.NewVersion))
approvalIdentifier := getApprovalIdentifier(plan.Resource.Identifier, plan.NewVersion)
// There might be no approvals for this plan
if p.approvalManager.Exists(approvalIdentifier) {
return p.approvalManager.Archive(approvalIdentifier)
}
return nil
}
func getInt(key string, labels map[string]string, annotations map[string]string) (int, error) {