Skip to content

Commit

Permalink
Compare normalized infraenv and preprov image architectures (#5816)
Browse files Browse the repository at this point in the history
Before this change a user would get an error if, for example, arm64
was provided in the infraenv, but aarch64 was provided in the BMH when in
reality those should match.

Resolves https://issues.redhat.com/browse/MGMT-16047
  • Loading branch information
carbonin committed Dec 17, 2023
1 parent fd8eb19 commit df5c8d3
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 5 deletions.
Expand Up @@ -126,9 +126,11 @@ func (r *PreprovisioningImageReconciler) Reconcile(origCtx context.Context, req
return ctrl.Result{}, nil
}

if infraEnv.Spec.CpuArchitecture != image.Spec.Architecture {
log.Infof("Image arch %s does not match infraEnv arch %s", image.Spec.Architecture, infraEnv.Spec.CpuArchitecture)
setMismatchedArchCondition(image, infraEnv.Spec.CpuArchitecture)
imageArch := common.NormalizeCPUArchitecture(image.Spec.Architecture)
infraArch := common.NormalizeCPUArchitecture(infraEnv.Spec.CpuArchitecture)
if infraArch != imageArch {
log.Infof("Image arch %s does not match infraEnv arch %s", imageArch, infraArch)
setMismatchedArchCondition(image, imageArch, infraArch)
err = r.Status().Update(ctx, image)
if err != nil {
log.WithError(err).Error("failed to update status")
Expand Down Expand Up @@ -281,8 +283,8 @@ func setUnsupportedFormatCondition(image *metal3_v1alpha1.PreprovisioningImage)
reason, message)
}

func setMismatchedArchCondition(image *metal3_v1alpha1.PreprovisioningImage, infraArch string) {
message := fmt.Sprintf("PreprovisioningImage CPU architecture (%s) does not match InfraEnv CPU architecture (%s)", image.Spec.Architecture, infraArch)
func setMismatchedArchCondition(image *metal3_v1alpha1.PreprovisioningImage, imageArch, infraArch string) {
message := fmt.Sprintf("PreprovisioningImage CPU architecture (%s) does not match InfraEnv CPU architecture (%s)", imageArch, infraArch)
reason := imageConditionReason(archMismatchReason)
setImageCondition(image.GetGeneration(), &image.Status,
metal3_v1alpha1.ConditionImageReady, metav1.ConditionFalse,
Expand Down
Expand Up @@ -537,6 +537,48 @@ var _ = Describe("PreprovisioningImage reconcile", func() {
checkImageConditionFailed(c, ppi, archMismatchReason, "does not match InfraEnv CPU architecture")
})

It("doesn't fail when the normalized preprovisioning architecture matches the infraenv architecture", func() {
infraEnv.Spec.CpuArchitecture = "arm64"
Expect(c.Create(ctx, infraEnv)).To(BeNil())

ppi.Spec.Architecture = "aarch64"
Expect(c.Update(ctx, ppi)).To(Succeed())

setInfraEnvIronicConfig()

res, err := pr.Reconcile(ctx, newPreprovisioningImageRequest(ppi))
Expect(err).To(BeNil())
Expect(res).To(Equal(ctrl.Result{}))

ppiKey := types.NamespacedName{Namespace: ppi.Namespace, Name: ppi.Name}
Expect(c.Get(ctx, ppiKey, ppi)).To(Succeed())
readyCondition := meta.FindStatusCondition(ppi.Status.Conditions, string(metal3_v1alpha1.ConditionImageReady))
Expect(readyCondition.Status).To(Equal(metav1.ConditionTrue))
errorCondition := meta.FindStatusCondition(ppi.Status.Conditions, string(metal3_v1alpha1.ConditionImageError))
Expect(errorCondition.Status).To(Equal(metav1.ConditionFalse))
})

It("doesn't fail when the normalized infraenv architecture matches the preprovisioning architecture", func() {
infraEnv.Spec.CpuArchitecture = "aarch64"
Expect(c.Create(ctx, infraEnv)).To(BeNil())

ppi.Spec.Architecture = "arm64"
Expect(c.Update(ctx, ppi)).To(Succeed())

setInfraEnvIronicConfig()

res, err := pr.Reconcile(ctx, newPreprovisioningImageRequest(ppi))
Expect(err).To(BeNil())
Expect(res).To(Equal(ctrl.Result{}))

ppiKey := types.NamespacedName{Namespace: ppi.Namespace, Name: ppi.Name}
Expect(c.Get(ctx, ppiKey, ppi)).To(Succeed())
readyCondition := meta.FindStatusCondition(ppi.Status.Conditions, string(metal3_v1alpha1.ConditionImageReady))
Expect(readyCondition.Status).To(Equal(metav1.ConditionTrue))
errorCondition := meta.FindStatusCondition(ppi.Status.Conditions, string(metal3_v1alpha1.ConditionImageError))
Expect(errorCondition.Status).To(Equal(metav1.ConditionFalse))
})

It("doesn't fail when the infraEnv image has not been created yet", func() {
infraEnv.Status = aiv1beta1.InfraEnvStatus{}
Expect(c.Create(ctx, infraEnv)).To(BeNil())
Expand Down

0 comments on commit df5c8d3

Please sign in to comment.