@@ -30,6 +30,7 @@ import (
3030
3131 corev1 "k8s.io/api/core/v1"
3232 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
33+ "k8s.io/apimachinery/pkg/util/intstr"
3334)
3435
3536func newFakeTAppController () (* Controller , * fakeInstanceClient ) {
@@ -491,12 +492,13 @@ func buildPods(tapp *tappv1.TApp) []*corev1.Pod {
491492}
492493
493494type RollUpdateTestUnit struct {
494- states []InstanceTestState
495- updates []int
495+ states []InstanceTestState
496+ updates []int
497+ maxUnavailable intstr.IntOrString
496498}
497499
498500func (u * RollUpdateTestUnit ) test (t * testing.T ) {
499- tapp , pods , updates , _ , err := createRollUpdateTestValues (u .states )
501+ tapp , pods , updates , _ , err := createRollUpdateTestValues (u .states , u . maxUnavailable )
500502 if err != nil {
501503 t .Errorf ("%+v" , err )
502504 }
@@ -541,7 +543,7 @@ const (
541543 emptyState InstanceTestState = "nil"
542544)
543545
544- func createTAppWithRollUpdate (replica int ) (* tappv1.TApp , string , string , error ) {
546+ func createTAppWithRollUpdate (replica int , maxUnavailable intstr. IntOrString ) (* tappv1.TApp , string , string , error ) {
545547 tapp := testutil .CreateValidTApp (replica )
546548 rollUpdateTemplate := "rollupdate"
547549 forceUpdateTemplate := "forceupdate"
@@ -557,8 +559,8 @@ func createTAppWithRollUpdate(replica int) (*tappv1.TApp, string, string, error)
557559 tapp .Annotations = make (map [string ]string )
558560 }
559561 tapp .Spec .UpdateStrategy .Template = rollUpdateTemplate
560- tapp .Spec .UpdateStrategy .MaxUnavailable = new (int32 )
561- * tapp .Spec .UpdateStrategy .MaxUnavailable = 1
562+ tapp .Spec .UpdateStrategy .MaxUnavailable = new (intstr. IntOrString )
563+ * tapp .Spec .UpdateStrategy .MaxUnavailable = maxUnavailable
562564
563565 template = testutil .CreateValidPodTemplate ()
564566 image = template .Spec .Containers [0 ].Image
@@ -608,9 +610,9 @@ func extractPodStatus(pods []*corev1.Pod) []InstanceTestState {
608610 return states
609611}
610612
611- func createRollUpdateTestValues (instances []InstanceTestState ) (* tappv1.TApp , []* corev1.Pod , []* Instance , []* Instance , error ) {
613+ func createRollUpdateTestValues (instances []InstanceTestState , maxUnavailable intstr. IntOrString ) (* tappv1.TApp , []* corev1.Pod , []* Instance , []* Instance , error ) {
612614 replica := len (instances )
613- tapp , rollUpdateId , forceUpdateId , err := createTAppWithRollUpdate (replica )
615+ tapp , rollUpdateId , forceUpdateId , err := createTAppWithRollUpdate (replica , maxUnavailable )
614616 if err != nil {
615617 return nil , nil , nil , nil , err
616618 }
@@ -663,93 +665,224 @@ func createRollUpdateTestValues(instances []InstanceTestState) (*tappv1.TApp, []
663665
664666func TestRollingUpdate (t * testing.T ) {
665667 tests := []RollUpdateTestUnit {
668+ // MaxUnavailable int
666669 // no effect to normal
667670 {
668671 []InstanceTestState {ready , ready , ready },
669672 []int {},
673+ intstr .FromInt (1 ),
670674 },
671675 {
672676 []InstanceTestState {ready , ready , notReady },
673677 []int {},
678+ intstr .FromInt (1 ),
674679 },
675680 {
676681 []InstanceTestState {ready , ready , update },
677682 []int {2 },
683+ intstr .FromInt (1 ),
678684 },
679685 {
680686 []InstanceTestState {ready , ready , deading },
681687 []int {},
688+ intstr .FromInt (1 ),
682689 },
683690 {
684691 []InstanceTestState {ready , ready , killed },
685692 []int {},
693+ intstr .FromInt (1 ),
686694 },
687695 {
688696 []InstanceTestState {ready , ready , complete },
689697 []int {},
698+ intstr .FromInt (1 ),
690699 },
691700 // add a rollupdate
692701 {
693702 []InstanceTestState {rollUpdate , ready , ready , ready },
694703 []int {0 },
704+ intstr .FromInt (1 ),
695705 },
696706 {
697707 []InstanceTestState {rollUpdate , ready , ready , notReady },
698708 []int {},
709+ intstr .FromInt (1 ),
699710 },
700711 {
701712 []InstanceTestState {rollUpdate , ready , ready , update },
702713 []int {3 },
714+ intstr .FromInt (1 ),
703715 },
704716 {
705717 []InstanceTestState {rollUpdate , ready , ready , deading },
706718 []int {},
719+ intstr .FromInt (1 ),
707720 },
708721 {
709722 []InstanceTestState {rollUpdate , ready , ready , killed },
710723 []int {0 },
724+ intstr .FromInt (1 ),
711725 },
712726 {
713727 []InstanceTestState {rollUpdate , ready , ready , complete },
714728 []int {},
729+ intstr .FromInt (1 ),
715730 },
716731 {
717732 []InstanceTestState {rollUpdate , rollupdateNotready , ready , complete },
718733 []int {1 },
734+ intstr .FromInt (1 ),
719735 },
720736 {
721737 []InstanceTestState {rollupdateNotready , rollupdateNotready , ready , ready },
722738 []int {0 , 1 },
739+ intstr .FromInt (1 ),
723740 },
724741 // add 2 rollupdate
725742 {
726743 []InstanceTestState {rollUpdate , rollUpdate , ready , ready , ready },
727744 []int {0 },
745+ intstr .FromInt (1 ),
728746 },
729747 {
730748 []InstanceTestState {rollUpdate , rollUpdate , ready , ready , notReady },
731749 []int {},
750+ intstr .FromInt (1 ),
732751 },
733752 {
734753 []InstanceTestState {rollUpdate , rollUpdate , ready , ready , update },
735754 []int {4 },
755+ intstr .FromInt (1 ),
736756 },
737757 {
738758 []InstanceTestState {rollUpdate , rollUpdate , ready , ready , deading },
739759 []int {},
760+ intstr .FromInt (1 ),
740761 },
741762 {
742763 []InstanceTestState {rollUpdate , rollUpdate , ready , ready , killed },
743764 []int {0 },
765+ intstr .FromInt (1 ),
744766 },
745767 {
746768 []InstanceTestState {rollUpdate , rollUpdate , ready , ready , complete },
747769 []int {},
770+ intstr .FromInt (1 ),
748771 },
749772 // more update
750773 {
751774 []InstanceTestState {rollUpdate , rollUpdate , ready , ready , update , update },
752775 []int {4 , 5 },
776+ intstr .FromInt (1 ),
777+ },
778+ //MaxUnavailable str
779+ {
780+ []InstanceTestState {ready , ready , ready },
781+ []int {},
782+ intstr .FromString ("25%" ),
783+ },
784+ {
785+ []InstanceTestState {ready , ready , notReady },
786+ []int {},
787+ intstr .FromString ("25%" ),
788+ },
789+ {
790+ []InstanceTestState {ready , ready , update },
791+ []int {2 },
792+ intstr .FromString ("25%" ),
793+ },
794+ {
795+ []InstanceTestState {ready , ready , deading },
796+ []int {},
797+ intstr .FromString ("25%" ),
798+ },
799+ {
800+ []InstanceTestState {ready , ready , killed },
801+ []int {},
802+ intstr .FromString ("25%" ),
803+ },
804+ {
805+ []InstanceTestState {ready , ready , complete },
806+ []int {},
807+ intstr .FromString ("25%" ),
808+ },
809+ // add a rollupdate
810+ {
811+ []InstanceTestState {rollUpdate , ready , ready , ready },
812+ []int {0 },
813+ intstr .FromString ("25%" ),
814+ },
815+ {
816+ []InstanceTestState {rollUpdate , ready , ready , notReady },
817+ []int {},
818+ intstr .FromString ("25%" ),
819+ },
820+ {
821+ []InstanceTestState {rollUpdate , ready , ready , update },
822+ []int {3 },
823+ intstr .FromString ("25%" ),
824+ },
825+ {
826+ []InstanceTestState {rollUpdate , ready , ready , deading },
827+ []int {},
828+ intstr .FromString ("25%" ),
829+ },
830+ {
831+ []InstanceTestState {rollUpdate , ready , ready , killed },
832+ []int {0 },
833+ intstr .FromString ("25%" ),
834+ },
835+ {
836+ []InstanceTestState {rollUpdate , ready , ready , complete },
837+ []int {},
838+ intstr .FromString ("25%" ),
839+ },
840+ {
841+ []InstanceTestState {rollUpdate , rollupdateNotready , ready , complete },
842+ []int {1 },
843+ intstr .FromString ("25%" ),
844+ },
845+ {
846+ []InstanceTestState {rollupdateNotready , rollupdateNotready , ready , ready },
847+ []int {0 , 1 },
848+ intstr .FromString ("25%" ),
849+ },
850+ // add 2 rollupdate
851+ {
852+ []InstanceTestState {rollUpdate , rollUpdate , ready , ready , ready },
853+ []int {0 , 1 },
854+ intstr .FromString ("25%" ),
855+ },
856+ {
857+ []InstanceTestState {rollUpdate , rollUpdate , ready , ready , notReady },
858+ []int {0 },
859+ intstr .FromString ("25%" ),
860+ },
861+ {
862+ []InstanceTestState {rollUpdate , rollUpdate , ready , ready , update },
863+ []int {0 , 4 },
864+ intstr .FromString ("25%" ),
865+ },
866+ {
867+ []InstanceTestState {rollUpdate , rollUpdate , ready , ready , deading },
868+ []int {0 },
869+ intstr .FromString ("25%" ),
870+ },
871+ {
872+ []InstanceTestState {rollUpdate , rollUpdate , ready , ready , killed },
873+ []int {0 },
874+ intstr .FromString ("25%" ),
875+ },
876+ {
877+ []InstanceTestState {rollUpdate , rollUpdate , ready , ready , complete },
878+ []int {0 },
879+ intstr .FromString ("25%" ),
880+ },
881+ // more update
882+ {
883+ []InstanceTestState {rollUpdate , rollUpdate , ready , ready , update , update },
884+ []int {4 , 5 },
885+ intstr .FromString ("25%" ),
753886 },
754887 }
755888
0 commit comments