initial stab at delay between deleting pods, keel/forceDelay annotation

pull/181/head
Jordan Brant Baker 2018-04-03 22:13:40 -07:00
parent 6b3a72b87d
commit 64228dfe56
2 changed files with 30 additions and 1 deletions

View File

@ -2,6 +2,7 @@ package kubernetes
import (
"fmt"
"time"
"k8s.io/api/extensions/v1beta1"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@ -15,6 +16,7 @@ func (p *Provider) forceUpdate(deployment *v1beta1.Deployment) (err error) {
gracePeriod := types.ParsePodTerminationGracePeriod(deployment.Annotations)
selector := meta_v1.FormatLabelSelector(deployment.Spec.Selector)
podDeleteDelay := types.ParsePodDeleteDelay(deployment.Annotations)
// image tag didn't change, need to terminate pods
podList, err := p.implementer.Pods(deployment.Namespace, selector)
@ -49,9 +51,9 @@ func (p *Provider) forceUpdate(deployment *v1beta1.Deployment) (err error) {
"namespace": deployment.Namespace,
"deployment": deployment.Name,
}).Error("provider.kubernetes: got error while deleting a pod")
continue
}
time.Sleep(podDeleteDelay)
}
return nil

View File

@ -47,6 +47,10 @@ const KeelApprovalDeadlineLabel = "keel.sh/approvalDeadline"
// KeelApprovalDeadlineDefault - default deadline in hours
const KeelApprovalDeadlineDefault = 24
// KeelPodDeleteDelay - optional delay betwen killing pods
// during force deploy
const KeelPodDeleteDelay = "keel.sh/forceDelay"
// KeelPodTerminationGracePeriod - optional grace period during
// pod termination
const KeelPodTerminationGracePeriod = "keel.sh/gracePeriod"
@ -206,6 +210,29 @@ func ParseEventNotificationChannels(annotations map[string]string) []string {
return channels
}
// ParsePodDeleteDelay - parses pod delete delay time in seconds
// from a given map of annotations
func ParsePodDeleteDelay(annotations map[string]string) int64 {
delay := int64(0)
if annotations == nil {
return delay
}
delayStr, ok := annotations[KeelPodDeleteDelay]
if ok {
g, err := strconv.Atoi(delayStr)
if err != nil {
return delay
}
if g > 0 && g < 600 {
return int64(g)
}
}
return delay
}
// ParsePodTerminationGracePeriod - parses pod termination time in seconds
// from a given map of annotations
func ParsePodTerminationGracePeriod(annotations map[string]string) int64 {