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 70426f8
Show file tree
Hide file tree
Showing 2 changed files with 491 additions and 251 deletions.
29 changes: 15 additions & 14 deletions internal/webhooks/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,36 +465,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 70426f8

Please sign in to comment.