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