Skip to content

Commit

Permalink
fixing empty checksumType default behaviour
Browse files Browse the repository at this point in the history
Previously, if no checksum type was specified into the BMH CR, it automatically handled it as MD5, causing errors to whom used different hashing algorithms. This commit adds the appropriate checks.

chaning if chain to switch-case block

chaning if chain to switch-case block

Signed-off-by: fracappa <[email protected]>

changing switch chain to if else when image.ChecksumType is empty

fixing return values when empty fields in GetChecksum methods
  • Loading branch information
fracappa committed Jan 9, 2025
1 parent 9470bce commit 2f613a0
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions apis/metal3.io/v1alpha1/baremetalhost_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1115,34 +1115,43 @@ func (host *BareMetalHost) OperationMetricForState(operation ProvisioningState)
// GetChecksum method returns the checksum of an image.
func (image *Image) GetChecksum() (checksum, checksumType string, ok bool) {
if image == nil {
return
return "", "", false
}

if image.DiskFormat != nil && *image.DiskFormat == "live-iso" {
// Checksum is not required for live-iso
ok = true
return
return "", "", ok
}

if image.Checksum == "" {
// Return empty if checksum is not provided
return
return "", "", false
}

switch image.ChecksumType {
case "":
checksumType = string(MD5)
switch len(image.Checksum) {
case 32:
checksumType = string(MD5)
case 64:
checksumType = string(SHA256)
case 128:
checksumType = string(SHA512)
default:
return "", "", false
}
case MD5, SHA256, SHA512:
checksumType = string(image.ChecksumType)
case AutoChecksum:
// No type, let Ironic detect
default:
return
return "", "", false
}

checksum = image.Checksum
ok = true
return
return checksum, checksumType, ok
}

// +kubebuilder:object:root=true
Expand Down

0 comments on commit 2f613a0

Please sign in to comment.