-
Notifications
You must be signed in to change notification settings - Fork 303
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
k8s: override PodManagementPolicy to Parallel on deploy. Fixes issue #…
- Loading branch information
Showing
3 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |