Skip to content

Commit

Permalink
k8s: override PodManagementPolicy to Parallel on deploy. Fixes issue #…
Browse files Browse the repository at this point in the history
  • Loading branch information
nicks committed Aug 6, 2019
1 parent f46efc6 commit 12de45e
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/engine/image_build_and_deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ func (ibd *ImageBuildAndDeployer) deploy(ctx context.Context, st store.RStore, p
return err
}

// StatefulSet pods should be managed in parallel. See:
// https://github.com/windmilleng/tilt/issues/1962
e = k8s.InjectParallelPodManagementPolicy(e)

// When working with a local k8s cluster, we set the pull policy to Never,
// to ensure that k8s fails hard if the image is missing from docker.
policy := v1.PullIfNotPresent
Expand Down
33 changes: 33 additions & 0 deletions internal/k8s/statefulset.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package k8s

import (
v1 "k8s.io/api/apps/v1"
"k8s.io/api/apps/v1beta1"
"k8s.io/api/apps/v1beta2"
)

// By default, StatefulSets use OrderedPodManagement.
//
// This is a bad policy for development. If the pod goes into a crash loop,
// the StatefulSet operator will get wedged and require manual invervention.
// See:
// https://github.com/windmilleng/tilt/issues/1962
//
// Tilt should change all statefulsets to use a parallel policy.
func InjectParallelPodManagementPolicy(entity K8sEntity) K8sEntity {
switch entity.Obj.(type) {
case *v1.StatefulSet:
entity = entity.DeepCopy()
entity.Obj.(*v1.StatefulSet).Spec.PodManagementPolicy = v1.ParallelPodManagement
return entity
case *v1beta1.StatefulSet:
entity = entity.DeepCopy()
entity.Obj.(*v1beta1.StatefulSet).Spec.PodManagementPolicy = v1beta1.ParallelPodManagement
return entity
case *v1beta2.StatefulSet:
entity = entity.DeepCopy()
entity.Obj.(*v1beta2.StatefulSet).Spec.PodManagementPolicy = v1beta2.ParallelPodManagement
return entity
}
return entity
}
20 changes: 20 additions & 0 deletions internal/k8s/statefulset_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package k8s

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/windmilleng/tilt/internal/k8s/testyaml"
)

func TestStatefulsetPodManagementPolicy(t *testing.T) {
ss, err := ParseYAMLFromString(testyaml.RedisStatefulSetYAML)
assert.Nil(t, err)

newEntity := InjectParallelPodManagementPolicy(ss[0])
result, err := SerializeSpecYAML([]K8sEntity{newEntity})
if err != nil {
t.Fatal(err)
}
assert.Contains(t, result, "podManagementPolicy: Parallel")
}

0 comments on commit 12de45e

Please sign in to comment.