-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: marcolan018 <[email protected]>
- Loading branch information
1 parent
560af39
commit 88e7b83
Showing
4 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package validations | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
semver "github.com/hashicorp/go-version" | ||
) | ||
|
||
const ( | ||
machinePoolRootAWSVolumeSizeMin = 128 | ||
// The following constants are in the helper file because putting them in the models creates | ||
// a circular dependency between the models and the helpers | ||
// machinePoolRootVolumeSizeMaxBefore414 is the maximum size of the root volume before 4.14 | ||
// 1 TiB - limit before 4.14 due to some filesystem growing issues | ||
machinePoolRootVolumeSizeMaxBefore414 = 1024 | ||
// machinePoolRootVolumeSizeMaxAsOf414 is the maximum size of the root volume as of 4.14 | ||
// 16 TiB - limit as of 4.14 | ||
machinePoolRootVolumeSizeMaxAsOf414 = 16384 | ||
) | ||
|
||
// ValidateMachinePoolRootDiskSize validates the root volume size for a machine pool in AWS. | ||
func ValidateMachinePoolRootDiskSize(version string, machinePoolRootVolumeSize int) error { | ||
machinePoolRootVolumeSizeMax, err := getAWSVolumeMaxSize(version) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if machinePoolRootVolumeSize < machinePoolRootAWSVolumeSizeMin || | ||
machinePoolRootVolumeSize > machinePoolRootVolumeSizeMax { | ||
return fmt.Errorf("Invalid root disk size: %d GiB. Must be between %d GiB and %d GiB.", | ||
machinePoolRootVolumeSize, | ||
machinePoolRootAWSVolumeSizeMin, | ||
machinePoolRootVolumeSizeMax) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// getAWSVolumeMaxSize returns the maximum size of the root volume for a machine pool in AWS. | ||
func getAWSVolumeMaxSize(version string) (int, error) { | ||
version414, _ := semver.NewVersion("4.14.0") | ||
currentVersion, err := semver.NewVersion(strings.Replace(version, "openshift-v", "", 1)) | ||
if err != nil { | ||
return 0, err | ||
} | ||
|
||
if currentVersion.GreaterThanOrEqual(version414) { | ||
return machinePoolRootVolumeSizeMaxAsOf414, nil | ||
} | ||
|
||
return machinePoolRootVolumeSizeMaxBefore414, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package validations | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo/v2/dsl/table" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = DescribeTable("getAWSVolumeMaxSize", | ||
func(testSpec struct { | ||
name string | ||
args string | ||
want int | ||
err error | ||
}) { | ||
got, err := getAWSVolumeMaxSize(testSpec.args) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(got).To(Equal(testSpec.want), "got %v, want %v", got, testSpec.want) | ||
}, | ||
Entry("valid version for 4.11", struct { | ||
name string | ||
args string | ||
want int | ||
err error | ||
}{"valid version for 4.11", "4.11", 1024, nil}), | ||
Entry("valid version for 4.13", struct { | ||
name string | ||
args string | ||
want int | ||
err error | ||
}{"valid version for 4.13", "4.13", 1024, nil}), | ||
Entry("invalid version for 4.14", struct { | ||
name string | ||
args string | ||
want int | ||
err error | ||
}{"invalid version for 4.14", "4.14", 16384, nil}), | ||
Entry("invalid version for 4.15", struct { | ||
name string | ||
args string | ||
want int | ||
err error | ||
}{"invalid version for 4.15", "4.15", 16384, nil}), | ||
) |