diff --git a/apis/metal3.io/v1alpha1/baremetalhost_types.go b/apis/metal3.io/v1alpha1/baremetalhost_types.go index 89525d4373..5961e5035b 100644 --- a/apis/metal3.io/v1alpha1/baremetalhost_types.go +++ b/apis/metal3.io/v1alpha1/baremetalhost_types.go @@ -1098,13 +1098,14 @@ func (image *Image) GetChecksum() (checksum, checksumType string, err error) { return "", "", errors.New("image is not provided") } - if image.DiskFormat != nil && *image.DiskFormat == "live-iso" { - // Checksum is not required for live-iso + if image.IsOCI() { + if image.Checksum != "" { + return "", "", errors.New("spec.image.checksum must be empty for OCI images (oci:// images have embedded checksums)") + } return "", "", nil } - // Checksum is not required for OCI images as they have embedded checksums - if image.IsOCI() && image.Checksum == "" { + if image.DiskFormat != nil && *image.DiskFormat == "live-iso" { return "", "", nil } diff --git a/apis/metal3.io/v1alpha1/baremetalhost_types_test.go b/apis/metal3.io/v1alpha1/baremetalhost_types_test.go index f7f118e0f3..ece8764de6 100644 --- a/apis/metal3.io/v1alpha1/baremetalhost_types_test.go +++ b/apis/metal3.io/v1alpha1/baremetalhost_types_test.go @@ -492,7 +492,25 @@ func TestGetImageChecksum(t *testing.T) { }, }, }, - Expected: true, + Expected: false, + ExpectedType: "", + }, + { + Scenario: "OCI image with live-iso format and checksum", + Host: BareMetalHost{ + ObjectMeta: metav1.ObjectMeta{ + Name: "myhost", + Namespace: "myns", + }, + Spec: BareMetalHostSpec{ + Image: &Image{ + URL: "oci://example.com/image:latest", + Checksum: "sha256hash", + DiskFormat: ptr.To("live-iso"), + }, + }, + }, + Expected: false, ExpectedType: "", }, {