Skip to content

Commit

Permalink
move test functions per validate func
Browse files Browse the repository at this point in the history
  • Loading branch information
chrischdi committed Feb 8, 2024
1 parent e0e2cec commit 8dedbd9
Show file tree
Hide file tree
Showing 2 changed files with 369 additions and 127 deletions.
33 changes: 18 additions & 15 deletions internal/webhooks/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,9 @@ func (webhook *Cluster) validateTopology(ctx context.Context, oldCluster, newClu

if _, ok := newCluster.GetAnnotations()[clusterv1.ClusterTopologyUnsafeUpdateVersionAnnotation]; ok {
log := ctrl.LoggerFrom(ctx)
log.Info(fmt.Sprintf("Skipping version validation for object because annotation %q is set", clusterv1.ClusterTopologyUnsafeUpdateVersionAnnotation))
warningMsg := fmt.Sprintf("Skipping version validation for Cluster because annotation %q is exists.", clusterv1.ClusterTopologyUnsafeUpdateVersionAnnotation)
log.Info(warningMsg)
allWarnings = append(allWarnings, warningMsg)
} else {
if errs := webhook.validateTopologyVersion(ctx, fldPath.Child("version"), newCluster.Spec.Topology.Version, inVersion, oldVersion, oldCluster); len(errs) > 0 {
allErrs = append(allErrs, errs...)
Expand Down Expand Up @@ -465,36 +467,37 @@ func validateTopologyControlPlaneVersion(ctx context.Context, fldPath *field.Pat
if err != nil {
return field.InternalError(fldPath, err)
}
provisioning, err := contract.ControlPlane().IsProvisioning(cp)

cpVersionString, err := contract.ControlPlane().Version().Get(cp)
if err != nil {
return field.InternalError(fldPath, err)
}

if provisioning {
return errors.New("ControlPlane is currently provisioning")
cpVersion, err := semver.ParseTolerant(*cpVersionString)
if err != nil {
// NOTE: this should never happen. Nevertheless, handling this for extra caution.
return field.InternalError(fldPath, errors.New("unable to parse version of ControlPlane"))
}
if cpVersion.NE(oldVersion) {
return fmt.Errorf("ControlPlane version %q does not match the current version %q", cpVersion, oldVersion)
}

upgrading, err := contract.ControlPlane().IsUpgrading(cp)
provisioning, err := contract.ControlPlane().IsProvisioning(cp)
if err != nil {
return field.InternalError(fldPath, err)
}

if upgrading {
return errors.New("ControlPlane is currently upgrading")
if provisioning {
return errors.New("ControlPlane is currently provisioning")
}

cpVersionString, err := contract.ControlPlane().Version().Get(cp)
upgrading, err := contract.ControlPlane().IsUpgrading(cp)
if err != nil {
return field.InternalError(fldPath, err)
}

cpVersion, err := semver.ParseTolerant(*cpVersionString)
if err != nil {
// NOTE: this should never happen. Nevertheless, handling this for extra caution.
return field.InternalError(fldPath, errors.New("unable to parse version of ControlPlane"))
}
if cpVersion.NE(oldVersion) {
return fmt.Errorf("ControlPlane version %q does not match the current version %q", cpVersion, oldVersion)
if upgrading {
return errors.New("ControlPlane is currently upgrading")
}

return nil
Expand Down
Loading

0 comments on commit 8dedbd9

Please sign in to comment.