Skip to content

Commit

Permalink
🐛 enhanced ud verification of cloneset
Browse files Browse the repository at this point in the history
Signed-off-by: acejilam <[email protected]>
  • Loading branch information
ls-2018 committed May 4, 2024
1 parent 879777b commit 7caf56d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/controller/uniteddeployment/revision.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ func (r *ReconcileUnitedDeployment) newRevision(ud *appsalphav1.UnitedDeployment
selectedLabels = ud.Spec.Template.AdvancedStatefulSetTemplate.Labels
} else if ud.Spec.Template.DeploymentTemplate != nil {
selectedLabels = ud.Spec.Template.DeploymentTemplate.Labels
} else if ud.Spec.Template.CloneSetTemplate != nil {
selectedLabels = ud.Spec.Template.CloneSetTemplate.Labels
}

cr, err := history.NewControllerRevision(ud,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@ func validateSubsetTemplateUpdate(template, oldTemplate *appsv1alpha1.SubsetTemp
allErrs = append(allErrs, validateAdvancedStatefulSetUpdate(template.AdvancedStatefulSetTemplate, oldTemplate.AdvancedStatefulSetTemplate, fldPath.Child("advancedStatefulSetTemplate"))...)
} else if template.DeploymentTemplate != nil && oldTemplate.DeploymentTemplate != nil {
allErrs = append(allErrs, validateDeploymentUpdate(template.DeploymentTemplate, oldTemplate.DeploymentTemplate, fldPath.Child("deploymentTemplate"))...)
} else if template.CloneSetTemplate != nil && oldTemplate.CloneSetTemplate != nil {
allErrs = append(allErrs, validateCloneSetUpdate(template.CloneSetTemplate, oldTemplate.CloneSetTemplate, fldPath.Child("cloneSetTemplate"))...)

Check warning on line 278 in pkg/webhook/uniteddeployment/validating/uniteddeployment_validation.go

View check run for this annotation

Codecov / codecov/patch

pkg/webhook/uniteddeployment/validating/uniteddeployment_validation.go#L278

Added line #L278 was not covered by tests
}

return allErrs
Expand Down Expand Up @@ -340,6 +342,19 @@ func validateSubsetTemplate(template *appsv1alpha1.SubsetTemplate, selector labe
return allErrs
}
allErrs = append(allErrs, appsvalidation.ValidatePodTemplateSpecForReplicaSet(coreTemplate, selector, 0, fldPath.Child("deploymentTemplate", "spec", "template"), webhookutil.DefaultPodValidationOptions)...)
} else if template.CloneSetTemplate != nil {
labels := labels.Set(template.CloneSetTemplate.Labels)
if !selector.Matches(labels) {
allErrs = append(allErrs, field.Invalid(fldPath.Child("cloneSetTemplate", "metadata", "labels"), template.CloneSetTemplate.Labels, "`selector` does not match template `labels`"))

Check warning on line 348 in pkg/webhook/uniteddeployment/validating/uniteddeployment_validation.go

View check run for this annotation

Codecov / codecov/patch

pkg/webhook/uniteddeployment/validating/uniteddeployment_validation.go#L346-L348

Added lines #L346 - L348 were not covered by tests
}
allErrs = append(allErrs, validateCloneSet(template.CloneSetTemplate, fldPath.Child("cloneSetTemplate"))...)
template := template.CloneSetTemplate.Spec.Template
coreTemplate, err := convertor.ConvertPodTemplateSpec(&template)
if err != nil {
allErrs = append(allErrs, field.Invalid(fldPath.Root(), template, fmt.Sprintf("Convert_v1_PodTemplateSpec_To_core_PodTemplateSpec failed: %v", err)))
return allErrs

Check warning on line 355 in pkg/webhook/uniteddeployment/validating/uniteddeployment_validation.go

View check run for this annotation

Codecov / codecov/patch

pkg/webhook/uniteddeployment/validating/uniteddeployment_validation.go#L350-L355

Added lines #L350 - L355 were not covered by tests
}
allErrs = append(allErrs, appsvalidation.ValidatePodTemplateSpecForReplicaSet(coreTemplate, selector, 0, fldPath.Child("cloneSetTemplate", "spec", "template"), webhookutil.DefaultPodValidationOptions)...)

Check warning on line 357 in pkg/webhook/uniteddeployment/validating/uniteddeployment_validation.go

View check run for this annotation

Codecov / codecov/patch

pkg/webhook/uniteddeployment/validating/uniteddeployment_validation.go#L357

Added line #L357 was not covered by tests
}

return allErrs
Expand Down Expand Up @@ -380,6 +395,14 @@ func validateDeployment(deployment *appsv1alpha1.DeploymentTemplateSpec, fldPath

return allErrs
}
func validateCloneSet(cs *appsv1alpha1.CloneSetTemplateSpec, fldPath *field.Path) field.ErrorList {
allErrs := field.ErrorList{}
if cs.Spec.Replicas != nil {
allErrs = append(allErrs, field.Invalid(fldPath.Child("spec", "replicas"), *cs.Spec.Replicas, "replicas in cloneSetTemplate will not be used"))

Check warning on line 401 in pkg/webhook/uniteddeployment/validating/uniteddeployment_validation.go

View check run for this annotation

Codecov / codecov/patch

pkg/webhook/uniteddeployment/validating/uniteddeployment_validation.go#L398-L401

Added lines #L398 - L401 were not covered by tests
}

return allErrs

Check warning on line 404 in pkg/webhook/uniteddeployment/validating/uniteddeployment_validation.go

View check run for this annotation

Codecov / codecov/patch

pkg/webhook/uniteddeployment/validating/uniteddeployment_validation.go#L404

Added line #L404 was not covered by tests
}

func validateStatefulSetUpdate(statefulSet, oldStatefulSet *appsv1alpha1.StatefulSetTemplateSpec, fldPath *field.Path) field.ErrorList {
allErrs := field.ErrorList{}
Expand Down Expand Up @@ -438,3 +461,12 @@ func validateDeploymentUpdate(deployment, oldDeployment *appsv1alpha1.Deployment

return allErrs
}
func validateCloneSetUpdate(cloneSet, oldCloneSet *appsv1alpha1.CloneSetTemplateSpec, fldPath *field.Path) field.ErrorList {
allErrs := field.ErrorList{}

Check warning on line 465 in pkg/webhook/uniteddeployment/validating/uniteddeployment_validation.go

View check run for this annotation

Codecov / codecov/patch

pkg/webhook/uniteddeployment/validating/uniteddeployment_validation.go#L464-L465

Added lines #L464 - L465 were not covered by tests

if cloneSet.Spec.Replicas != nil {
allErrs = append(allErrs, apivalidation.ValidateNonnegativeField(int64(*cloneSet.Spec.Replicas), fldPath.Child("spec", "replicas"))...)

Check warning on line 468 in pkg/webhook/uniteddeployment/validating/uniteddeployment_validation.go

View check run for this annotation

Codecov / codecov/patch

pkg/webhook/uniteddeployment/validating/uniteddeployment_validation.go#L467-L468

Added lines #L467 - L468 were not covered by tests
}

return allErrs

Check warning on line 471 in pkg/webhook/uniteddeployment/validating/uniteddeployment_validation.go

View check run for this annotation

Codecov / codecov/patch

pkg/webhook/uniteddeployment/validating/uniteddeployment_validation.go#L471

Added line #L471 was not covered by tests
}

0 comments on commit 7caf56d

Please sign in to comment.