Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Volume minimum size fixes / improvements #2030

Merged
merged 7 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions frontend/src/components/ShootWorkers/GVolumeSizeInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ SPDX-License-Identifier: Apache-2.0
</template>

<script>
import { parseSize } from '@/utils'
import { convertToGi } from '@/utils'

export default {
props: {
Expand Down Expand Up @@ -75,7 +75,7 @@ export default {
innerValue: {
get () {
if (this.modelValue) {
return parseSize(this.modelValue)
return convertToGi(this.modelValue)
}
return undefined
},
Expand Down
10 changes: 5 additions & 5 deletions frontend/src/components/ShootWorkers/GWorkerInputGeneric.vue
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ import {
} from '@/utils/validators'
import {
getErrorMessages,
parseSize,
convertToGi,
} from '@/utils'

import {
Expand Down Expand Up @@ -297,14 +297,14 @@ export default {
})

const volumeSizeRules = {
minVolumeSize: withMessage(`Minimum size is ${this.minimumVolumeSize}`, value => {
minVolumeSize: withMessage(() => `Minimum size is ${this.minimumVolumeSize}`, value => {
if (!this.hasVolumeSize) {
return true
}
if (!value) {
return false
}
return this.minimumVolumeSize <= parseSize(value)
return this.minimumVolumeSize <= convertToGi(value)
}),
}
rules.volumeSize = withFieldName(() => `${this.workerGroupName} Volume Size`, volumeSizeRules)
Expand Down Expand Up @@ -342,11 +342,11 @@ export default {
return filter(machineImages, ({ isExpired, architectures }) => !isExpired && includes(architectures, this.machineArchitecture))
},
minimumVolumeSize () {
const minimumVolumeSize = parseSize(this.minimumVolumeSizeByMachineTypeAndVolumeType({
const minimumVolumeSize = convertToGi(this.minimumVolumeSizeByMachineTypeAndVolumeType({
machineType: this.selectedMachineType,
volumeType: this.selectedVolumeType,
}))
const defaultSize = parseSize(get(this.selectedMachineType, 'storage.size'))
const defaultSize = convertToGi(get(this.selectedMachineType, 'storage.size'))
if (defaultSize > 0 && defaultSize < minimumVolumeSize) {
return defaultSize
}
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/store/cloudProfile/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { useApi } from '@/composables/useApi'

import {
shortRandomString,
parseSize,
convertToGi,
defaultCriNameByKubernetesVersion,
isValidTerminationDate,
machineImageHasUpdate,
Expand Down Expand Up @@ -632,7 +632,7 @@ export const useCloudProfileStore = defineStore('cloudProfile', () => {
const machineImage = defaultMachineImageForCloudProfileNameAndMachineType(cloudProfileName, machineType)
const minVolumeSize = minimumVolumeSizeByMachineTypeAndVolumeType({ machineType, volumeType })

const defaultVolumeSize = parseSize(minVolumeSize) <= parseSize('50Gi') ? '50Gi' : minVolumeSize
const defaultVolumeSize = convertToGi(minVolumeSize) <= convertToGi('50Gi') ? '50Gi' : minVolumeSize
const worker = {
id,
name,
Expand Down
25 changes: 19 additions & 6 deletions frontend/src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,21 @@ import {
} from '@/lodash'

const serviceAccountRegex = /^system:serviceaccount:([^:]+):([^:]+)$/
const sizeRegex = /^(\d+)Gi$/
const emailRegex = /^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/
const colorCodeRegex = /^#([a-f0-9]{6}|[a-f0-9]{3})$/i
const magnitudeNumberSuffixRegex = /^(\d+(?:\.\d*)?)([kmbt]?)$/i
const versionRegex = /^(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:\.\d+)*([-+].+)?$/
const sizeRegex = /^(\d+)([GMKTi]{1,2})$/
grolu marked this conversation as resolved.
Show resolved Hide resolved
const sizeConversionFactors = {
Gi: 1,
G: 1 / 1.073741824, // 1 Gi = 1.073741824 G
Mi: 1 / 1024, // 1 Gi = 1024 Mi
M: 1 / (1024 * 1.073741824), // 1 Gi = 1073.741824 M
Ki: 1 / (1024 * 1024), // 1 Gi = 1024^2 Ki
K: 1 / (1024 * 1024 * 1.073741824), // 1 Gi = 1073741.824 K
Ti: 1024, // 1 Ti = 1024 Gi
T: 1024 / 1.073741824, // 1 Ti = 1073.741824 Gi
}

const logger = useLogger()

Expand Down Expand Up @@ -155,16 +165,19 @@ export function displayName (username) {
return username
}

export function parseSize (value) {
export function convertToGi (value) {
if (!value) {
return 0
}
const result = sizeRegex.exec(value)
if (result) {
const [, sizeValue] = result
return parseInt(sizeValue, 10)
const [, sizeValue, unit] = result
const conversionFactor = sizeConversionFactors[unit]
if (conversionFactor !== undefined) {
return parseInt(sizeValue, 10) * conversionFactor
}
}
logger.error(`Could not parse size ${value} as it does not match regex ^(\\d+)Gi$`)
logger.error(`Could not parse size ${value} as it does not match expected formats`)
return 0
}

Expand Down Expand Up @@ -648,7 +661,7 @@ export default {
setInputFocus,
fullDisplayName,
displayName,
parseSize,
convertToGi,
isEmail,
gravatarUrlGeneric,
gravatarUrlMp,
Expand Down