eudit
parent
041e524785
commit
786975b002
|
@ -4,7 +4,7 @@ import (
|
|||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/keel-hq/keel/cache"
|
||||
"github.com/keel-hq/keel/pkg/store"
|
||||
"github.com/keel-hq/keel/types"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
@ -36,7 +36,7 @@ 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.Delete(getIdentifier(plan.Namespace, plan.Name, plan.NewVersion))
|
||||
return p.approvalManager.Archive(getIdentifier(plan.Namespace, plan.Name, plan.NewVersion))
|
||||
}
|
||||
|
||||
func (p *Provider) isApproved(event *types.Event, plan *UpdatePlan) (bool, error) {
|
||||
|
@ -49,7 +49,7 @@ func (p *Provider) isApproved(event *types.Event, plan *UpdatePlan) (bool, error
|
|||
// checking for existing approval
|
||||
existing, err := p.approvalManager.Get(identifier)
|
||||
if err != nil {
|
||||
if err == cache.ErrNotFound {
|
||||
if err == store.ErrRecordNotFound {
|
||||
|
||||
if plan.Config.ApprovalDeadline == 0 {
|
||||
plan.Config.ApprovalDeadline = types.KeelApprovalDeadlineDefault
|
||||
|
|
|
@ -297,12 +297,19 @@ func (p *Provider) applyPlans(plans []*UpdatePlan) error {
|
|||
for _, plan := range plans {
|
||||
|
||||
p.sender.Send(types.EventNotification{
|
||||
Name: "update release",
|
||||
Message: fmt.Sprintf("Preparing to update release %s/%s %s->%s (%s)", plan.Namespace, plan.Name, plan.CurrentVersion, plan.NewVersion, strings.Join(mapToSlice(plan.Values), ", ")),
|
||||
CreatedAt: time.Now(),
|
||||
Type: types.NotificationPreReleaseUpdate,
|
||||
Level: types.LevelDebug,
|
||||
Channels: plan.Config.NotificationChannels,
|
||||
ResourceKind: "chart",
|
||||
Identifier: fmt.Sprintf("%s/%s/%s", "chart", plan.Namespace, plan.Name),
|
||||
Name: "update release",
|
||||
Message: fmt.Sprintf("Preparing to update release %s/%s %s->%s (%s)", plan.Namespace, plan.Name, plan.CurrentVersion, plan.NewVersion, strings.Join(mapToSlice(plan.Values), ", ")),
|
||||
CreatedAt: time.Now(),
|
||||
Type: types.NotificationPreReleaseUpdate,
|
||||
Level: types.LevelDebug,
|
||||
Channels: plan.Config.NotificationChannels,
|
||||
Metadata: map[string]string{
|
||||
"provider": p.GetName(),
|
||||
"namespace": plan.Namespace,
|
||||
"name": plan.Name,
|
||||
},
|
||||
})
|
||||
|
||||
err := updateHelmRelease(p.implementer, plan.Name, plan.Chart, plan.Values)
|
||||
|
@ -314,12 +321,19 @@ func (p *Provider) applyPlans(plans []*UpdatePlan) error {
|
|||
}).Error("provider.helm: failed to apply plan")
|
||||
|
||||
p.sender.Send(types.EventNotification{
|
||||
Name: "update release",
|
||||
Message: fmt.Sprintf("Release update failed %s/%s %s->%s (%s), error: %s", plan.Namespace, plan.Name, plan.CurrentVersion, plan.NewVersion, strings.Join(mapToSlice(plan.Values), ", "), err),
|
||||
CreatedAt: time.Now(),
|
||||
Type: types.NotificationReleaseUpdate,
|
||||
Level: types.LevelError,
|
||||
Channels: plan.Config.NotificationChannels,
|
||||
ResourceKind: "chart",
|
||||
Identifier: fmt.Sprintf("%s/%s/%s", "chart", plan.Namespace, plan.Name),
|
||||
Name: "update release",
|
||||
Message: fmt.Sprintf("Release update failed %s/%s %s->%s (%s), error: %s", plan.Namespace, plan.Name, plan.CurrentVersion, plan.NewVersion, strings.Join(mapToSlice(plan.Values), ", "), err),
|
||||
CreatedAt: time.Now(),
|
||||
Type: types.NotificationReleaseUpdate,
|
||||
Level: types.LevelError,
|
||||
Channels: plan.Config.NotificationChannels,
|
||||
Metadata: map[string]string{
|
||||
"provider": p.GetName(),
|
||||
"namespace": plan.Namespace,
|
||||
"name": plan.Name,
|
||||
},
|
||||
})
|
||||
continue
|
||||
}
|
||||
|
@ -341,12 +355,19 @@ func (p *Provider) applyPlans(plans []*UpdatePlan) error {
|
|||
}
|
||||
|
||||
p.sender.Send(types.EventNotification{
|
||||
Name: "update release",
|
||||
Message: msg,
|
||||
CreatedAt: time.Now(),
|
||||
Type: types.NotificationReleaseUpdate,
|
||||
Level: types.LevelSuccess,
|
||||
Channels: plan.Config.NotificationChannels,
|
||||
ResourceKind: "chart",
|
||||
Identifier: fmt.Sprintf("%s/%s/%s", "chart", plan.Namespace, plan.Name),
|
||||
Name: "update release",
|
||||
Message: msg,
|
||||
CreatedAt: time.Now(),
|
||||
Type: types.NotificationReleaseUpdate,
|
||||
Level: types.LevelSuccess,
|
||||
Channels: plan.Config.NotificationChannels,
|
||||
Metadata: map[string]string{
|
||||
"provider": p.GetName(),
|
||||
"namespace": plan.Namespace,
|
||||
"name": plan.Name,
|
||||
},
|
||||
})
|
||||
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/keel-hq/keel/cache"
|
||||
"github.com/keel-hq/keel/pkg/store"
|
||||
"github.com/keel-hq/keel/types"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
@ -37,7 +37,7 @@ 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.Delete(getApprovalIdentifier(plan.Resource.Identifier, plan.NewVersion))
|
||||
return p.approvalManager.Archive(getApprovalIdentifier(plan.Resource.Identifier, plan.NewVersion))
|
||||
}
|
||||
|
||||
func getInt(key string, labels map[string]string, annotations map[string]string) (int, error) {
|
||||
|
@ -96,7 +96,7 @@ func (p *Provider) isApproved(event *types.Event, plan *UpdatePlan) (bool, error
|
|||
// checking for existing approval
|
||||
existing, err := p.approvalManager.Get(identifier)
|
||||
if err != nil {
|
||||
if err == cache.ErrNotFound {
|
||||
if err == store.ErrRecordNotFound {
|
||||
|
||||
// creating new one
|
||||
approval := &types.Approval{
|
||||
|
|
|
@ -275,12 +275,19 @@ func (p *Provider) updateDeployments(plans []*UpdatePlan) (updated []*k8s.Generi
|
|||
notificationChannels := types.ParseEventNotificationChannels(annotations)
|
||||
|
||||
p.sender.Send(types.EventNotification{
|
||||
Name: "preparing to update resource",
|
||||
Message: fmt.Sprintf("Preparing to update %s %s/%s %s->%s (%s)", resource.Kind(), resource.Namespace, resource.Name, plan.CurrentVersion, plan.NewVersion, strings.Join(resource.GetImages(), ", ")),
|
||||
CreatedAt: time.Now(),
|
||||
Type: types.NotificationPreDeploymentUpdate,
|
||||
Level: types.LevelDebug,
|
||||
Channels: notificationChannels,
|
||||
ResourceKind: resource.Kind(),
|
||||
Identifier: resource.Identifier,
|
||||
Name: "preparing to update resource",
|
||||
Message: fmt.Sprintf("Preparing to update %s %s/%s %s->%s (%s)", resource.Kind(), resource.Namespace, resource.Name, plan.CurrentVersion, plan.NewVersion, strings.Join(resource.GetImages(), ", ")),
|
||||
CreatedAt: time.Now(),
|
||||
Type: types.NotificationPreDeploymentUpdate,
|
||||
Level: types.LevelDebug,
|
||||
Channels: notificationChannels,
|
||||
Metadata: map[string]string{
|
||||
"provider": p.GetName(),
|
||||
"namespace": resource.GetNamespace(),
|
||||
"name": resource.GetName(),
|
||||
},
|
||||
})
|
||||
|
||||
var err error
|
||||
|
@ -302,12 +309,19 @@ func (p *Provider) updateDeployments(plans []*UpdatePlan) (updated []*k8s.Generi
|
|||
}).Error("provider.kubernetes: got error while updating resource")
|
||||
|
||||
p.sender.Send(types.EventNotification{
|
||||
Name: "update resource",
|
||||
Message: fmt.Sprintf("%s %s/%s update %s->%s failed, error: %s", resource.Kind(), resource.Namespace, resource.Name, plan.CurrentVersion, plan.NewVersion, err),
|
||||
CreatedAt: time.Now(),
|
||||
Type: types.NotificationDeploymentUpdate,
|
||||
Level: types.LevelError,
|
||||
Channels: notificationChannels,
|
||||
Name: "update resource",
|
||||
ResourceKind: resource.Kind(),
|
||||
Identifier: resource.Identifier,
|
||||
Message: fmt.Sprintf("%s %s/%s update %s->%s failed, error: %s", resource.Kind(), resource.Namespace, resource.Name, plan.CurrentVersion, plan.NewVersion, err),
|
||||
CreatedAt: time.Now(),
|
||||
Type: types.NotificationDeploymentUpdate,
|
||||
Level: types.LevelError,
|
||||
Channels: notificationChannels,
|
||||
Metadata: map[string]string{
|
||||
"provider": p.GetName(),
|
||||
"namespace": resource.GetNamespace(),
|
||||
"name": resource.GetName(),
|
||||
},
|
||||
})
|
||||
|
||||
continue
|
||||
|
@ -332,12 +346,19 @@ func (p *Provider) updateDeployments(plans []*UpdatePlan) (updated []*k8s.Generi
|
|||
}
|
||||
|
||||
p.sender.Send(types.EventNotification{
|
||||
Name: "update resource",
|
||||
Message: msg,
|
||||
CreatedAt: time.Now(),
|
||||
Type: types.NotificationDeploymentUpdate,
|
||||
Level: types.LevelSuccess,
|
||||
Channels: notificationChannels,
|
||||
ResourceKind: resource.Kind(),
|
||||
Identifier: resource.Identifier,
|
||||
Name: "update resource",
|
||||
Message: msg,
|
||||
CreatedAt: time.Now(),
|
||||
Type: types.NotificationDeploymentUpdate,
|
||||
Level: types.LevelSuccess,
|
||||
Channels: notificationChannels,
|
||||
Metadata: map[string]string{
|
||||
"provider": p.GetName(),
|
||||
"namespace": resource.GetNamespace(),
|
||||
"name": resource.GetName(),
|
||||
},
|
||||
})
|
||||
|
||||
log.WithFields(log.Fields{
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
)
|
||||
|
||||
type GetApprovalQuery struct {
|
||||
ID string
|
||||
Identifier string
|
||||
// Rejected bool
|
||||
Archived bool
|
||||
|
|
|
@ -13,6 +13,7 @@ const (
|
|||
AuditActionApprovalApproved = "approved"
|
||||
AuditActionApprovalRejected = "rejected"
|
||||
AuditActionApprovalExpired = "expired"
|
||||
AuditActionApprovalArchived = "archived"
|
||||
|
||||
// audit specific resource kinds (others are set by
|
||||
// providers, ie: deployment, daemonset, helm chart)
|
||||
|
|
Loading…
Reference in New Issue