force update by terminating pods

pull/154/head
Karolis Rusenas 2018-03-04 12:10:49 +00:00
parent 5a88981087
commit dc7c1e18f8
1 changed files with 58 additions and 0 deletions

View File

@ -0,0 +1,58 @@
package kubernetes
import (
"fmt"
"k8s.io/api/extensions/v1beta1"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/keel-hq/keel/types"
log "github.com/sirupsen/logrus"
)
func (p *Provider) forceUpdate(deployment *v1beta1.Deployment) (err error) {
gracePeriod := types.ParsePodTerminationGracePeriod(deployment.Annotations)
selector := meta_v1.FormatLabelSelector(deployment.Spec.Selector)
// image tag didn't change, need to terminate pods
podList, err := p.implementer.Pods(deployment.Namespace, selector)
if err != nil {
log.WithFields(log.Fields{
"error": err,
"selector": selector,
"namespace": deployment.Namespace,
"deployment": deployment.Name,
}).Error("provider.kubernetes: got error while looking for deployment pods")
return err
}
for _, pod := range podList.Items {
log.WithFields(log.Fields{
"selector": selector,
"pod": pod.Name,
"namespace": deployment.Namespace,
"deployment": deployment.Name,
"grace_period": fmt.Sprint(gracePeriod),
}).Info("provider.kubernetes: deleting pod to force pull...")
err = p.implementer.DeletePod(deployment.Namespace, pod.Name, &meta_v1.DeleteOptions{
GracePeriodSeconds: &gracePeriod,
})
if err != nil {
log.WithFields(log.Fields{
"error": err,
"selector": selector,
"pod": pod.Name,
"namespace": deployment.Namespace,
"deployment": deployment.Name,
}).Error("provider.kubernetes: got error while deleting a pod")
continue
}
}
return nil
}