mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 04:08:16 +00:00 
			
		
		
		
	Merge pull request #84596 from akhinos/fix-statefulset-defaulting
UpdateStrategy.RollingUpdate.Partition is lost when UpdateStrategy.Type is not set
This commit is contained in:
		@@ -99,8 +99,10 @@ func SetDefaults_StatefulSet(obj *appsv1.StatefulSet) {
 | 
			
		||||
	if obj.Spec.UpdateStrategy.Type == "" {
 | 
			
		||||
		obj.Spec.UpdateStrategy.Type = appsv1.RollingUpdateStatefulSetStrategyType
 | 
			
		||||
 | 
			
		||||
		// UpdateStrategy.RollingUpdate will take default values below.
 | 
			
		||||
		obj.Spec.UpdateStrategy.RollingUpdate = &appsv1.RollingUpdateStatefulSetStrategy{}
 | 
			
		||||
		if obj.Spec.UpdateStrategy.RollingUpdate == nil {
 | 
			
		||||
			// UpdateStrategy.RollingUpdate will take default values below.
 | 
			
		||||
			obj.Spec.UpdateStrategy.RollingUpdate = &appsv1.RollingUpdateStatefulSetStrategy{}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if obj.Spec.UpdateStrategy.Type == appsv1.RollingUpdateStatefulSetStrategyType &&
 | 
			
		||||
 
 | 
			
		||||
@@ -173,6 +173,7 @@ func TestSetDefaultStatefulSet(t *testing.T) {
 | 
			
		||||
	defaultLabels := map[string]string{"foo": "bar"}
 | 
			
		||||
	var defaultPartition int32 = 0
 | 
			
		||||
	var defaultReplicas int32 = 1
 | 
			
		||||
	var notTheDefaultPartition int32 = 42
 | 
			
		||||
 | 
			
		||||
	period := int64(v1.DefaultTerminationGracePeriodSeconds)
 | 
			
		||||
	defaultTemplate := v1.PodTemplateSpec{
 | 
			
		||||
@@ -265,6 +266,35 @@ func TestSetDefaultStatefulSet(t *testing.T) {
 | 
			
		||||
				},
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
		{ // UpdateStrategy.RollingUpdate.Partition is not lost when UpdateStrategy.Type is not set
 | 
			
		||||
			original: &appsv1.StatefulSet{
 | 
			
		||||
				Spec: appsv1.StatefulSetSpec{
 | 
			
		||||
					Template: defaultTemplate,
 | 
			
		||||
					UpdateStrategy: appsv1.StatefulSetUpdateStrategy{
 | 
			
		||||
						RollingUpdate: &appsv1.RollingUpdateStatefulSetStrategy{
 | 
			
		||||
							Partition: ¬TheDefaultPartition,
 | 
			
		||||
						},
 | 
			
		||||
					},
 | 
			
		||||
				},
 | 
			
		||||
			},
 | 
			
		||||
			expected: &appsv1.StatefulSet{
 | 
			
		||||
				ObjectMeta: metav1.ObjectMeta{
 | 
			
		||||
					Labels: defaultLabels,
 | 
			
		||||
				},
 | 
			
		||||
				Spec: appsv1.StatefulSetSpec{
 | 
			
		||||
					Replicas:            &defaultReplicas,
 | 
			
		||||
					Template:            defaultTemplate,
 | 
			
		||||
					PodManagementPolicy: appsv1.OrderedReadyPodManagement,
 | 
			
		||||
					UpdateStrategy: appsv1.StatefulSetUpdateStrategy{
 | 
			
		||||
						Type: appsv1.RollingUpdateStatefulSetStrategyType,
 | 
			
		||||
						RollingUpdate: &appsv1.RollingUpdateStatefulSetStrategy{
 | 
			
		||||
							Partition: ¬TheDefaultPartition,
 | 
			
		||||
						},
 | 
			
		||||
					},
 | 
			
		||||
					RevisionHistoryLimit: utilpointer.Int32Ptr(10),
 | 
			
		||||
				},
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	for i, test := range tests {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user