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

✨ Attach non-bootable iso to BareMetalHost #1594

Merged
merged 10 commits into from
Apr 24, 2024

Conversation

hroyrh
Copy link
Member

@hroyrh hroyrh commented Mar 5, 2024

What this PR does / why we need it:
Add new DataImage CRD which allows attachment/detachment of non-bootable iso to BareMetalHost, based on this proposal.

@metal3-io-bot metal3-io-bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Mar 5, 2024
@hroyrh hroyrh changed the title ✨ Attach non-bootable iso to BareMetalHost ✨ [WIP] Attach non-bootable iso to BareMetalHost Mar 5, 2024
@hroyrh hroyrh force-pushed the non-bootable-iso branch from 8c7a54b to b2bb2cb Compare March 12, 2024 12:47
return nil
}
// Error reading the object - requeue the request.
return actionError{errors.Wrap(err, "could not load dataImage")}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: avoid deprecated errors.Wrap (use fmt.Errorf with %w)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(same below)

if err := r.Update(info.ctx, dataImage); err != nil {
return actionError{errors.Wrap(err, "failure creating dataImage resource")}
}
// Should we requeue at this point
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm never sure myself...


// Fetch the latest status of DataImage from node
if err := prov.GetDataImageStatus(dataImage); err != nil {
info.log.Info("Failed to get current status : ", "ErrorIs", err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Please remove " : ", there is no guarantee how exactly the fields are logged (also s/ErrorIs/Error/ for the same reason)

deleteDataImage = true
}

diSpecURL := dataImage.Spec.URL
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the "di" prefix is not very useful in the context of this function, I'd rather do something like requestedURL vs attachedURL

}
}
if diSpecURL != "" {
info.log.Info("Attaching DataImage")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: log the image URL

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably worth log that and more info in case of failure below

return actionError{errors.Wrap(err, "Failed to detach")}
}

if err := r.Status().Update(info.ctx, dataImage); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are you trying to update here? Did you mean to remove the finalizer first?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I wanted to update the attachedURL here so that the dataimage reconciler can remove the finalizer. But given your previous comment ( requeuing after detach ) I think the more appropriate option will be to update the status here in case detach return an error, and then requeue.

// Attach the DataImage to the BareMetalHost.
func (r *BareMetalHostReconciler) attachDataImage(prov provisioner.Provisioner, info *reconcileInfo, dataImage *metal3api.DataImage) error {
if err := prov.AttachDataImage(dataImage.Spec.URL); err != nil {
info.log.Info("Called the IronicProvisioner.AttachDataImage function")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant in the final version of the patch (same for detach)

"time"

"github.com/go-logr/logr"
"github.com/pkg/errors"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid the deprecated package (use errors.New or fmt.Errorf with %w)


// Get DataImage Details
// Fetches the VirtualMedia details of the BareMetalHost and updates DataImage.
func (p *ironicProvisioner) GetDataImageStatus(dataImage *metal3api.DataImage) (err error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Provisioners should not handle API objects directly, it's the responsibility of controllers.


// DataImageSpec defines the desired state of DataImage.
type DataImageSpec struct {
// Important: Run "make" to regenerate code after modifying this file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can be removed

// imageUrl is the URL from which the built image can be downloaded.
AttachedImage *AttachedImageReference `json:"attachedImage,omitempty"`

Error *DataImageError `json:"error,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: documentation

}

//+kubebuilder:object:root=true
//+kubebuilder:resource:shortName=dimg
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's going to be a very rarely used resource, let's maybe not have a short name for it?

@hroyrh hroyrh force-pushed the non-bootable-iso branch from b2bb2cb to 21d18b6 Compare March 25, 2024 09:04
@metal3-io-bot metal3-io-bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Mar 25, 2024
@metal3-io-bot metal3-io-bot added the needs-rebase Indicates that a PR cannot be merged because it has merge conflicts with HEAD. label Apr 5, 2024
@hroyrh hroyrh force-pushed the non-bootable-iso branch from 21d18b6 to f6afc45 Compare April 15, 2024 11:32
@metal3-io-bot metal3-io-bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed needs-rebase Indicates that a PR cannot be merged because it has merge conflicts with HEAD. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Apr 15, 2024
@hroyrh hroyrh force-pushed the non-bootable-iso branch from c53f0c8 to cd843d0 Compare April 15, 2024 12:08
@metal3-io-bot metal3-io-bot added the needs-rebase Indicates that a PR cannot be merged because it has merge conflicts with HEAD. label Apr 16, 2024
hroyrh added 7 commits April 24, 2024 15:43
Signed-off-by: Himanshu Roy <hroy@redhat.com>
… for BMH and DataImage controllers

Signed-off-by: Himanshu Roy <hroy@redhat.com>
Signed-off-by: Himanshu Roy <hroy@redhat.com>
Signed-off-by: Himanshu Roy <hroy@redhat.com>
…, minor fixes

Signed-off-by: Himanshu Roy <hroy@redhat.com>
…ling

Signed-off-by: Himanshu Roy <hroy@redhat.com>
lastReconciled status field

Signed-off-by: Himanshu Roy <hroy@redhat.com>
// TODO(hroyrh) : Should we fail after the error count exceeds a
// given constant ?
dataImageRetryBackoff := max(dataImageUpdateDelay, calculateBackoff(dataImage.Status.Error.Count))
info.log.Info("Current dataImage reconcile delay", "dataImageRetryBackoff", dataImageRetryBackoff)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this is not very useful IMO

return fmt.Errorf("failed to attach dataImage, %w", err)
}

info.log.Info("Attach dataImage initiated", "DataImage", dataImage.Name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this is probably excessive: you have logging on line 1553

return fmt.Errorf("failed to detach dataImage, %w", err)
}

info.log.Info("Detach dataImage initiated", "DataImage", dataImage.Name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

// Attach the DataImage to the BareMetalHost.
func (r *BareMetalHostReconciler) attachDataImage(prov provisioner.Provisioner, info *reconcileInfo, dataImage *metal3api.DataImage) error {
if err := prov.AttachDataImage(dataImage.Spec.URL); err != nil {
info.log.Info("Error while attaching DataImage", "DataImage", dataImage.Name, "Error", err.Error())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: data image name matches the host name, better log the URL

// move the current state of the cluster closer to the desired state.
//
// For more details, check Reconcile and its Result here:
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.14.4/pkg/reconcile
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: boilerplate, can be removed

// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.14.4/pkg/reconcile
func (r *DataImageReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
reqLogger := r.Log.WithValues("dataimage", req.NamespacedName)
reqLogger.Info("start dataImage reconciliation V1")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: not sure what V1 means here


// If the reconciliation is paused, requeue
annotations := bmh.GetAnnotations()
if annotations != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: not needed, you can read from a nil map

}

// Add finalizer for newly created DataImage
if di.DeletionTimestamp.IsZero() && !utils.StringInList(di.Finalizers, metal3api.DataImageFinalizer) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this should happen before initializing the provisioner

main.go Outdated
@@ -177,7 +177,7 @@ func main() {
logOpts.Development = true
logOpts.TimeEncoder = zapcore.ISO8601TimeEncoder
} else {
logOpts.TimeEncoder = zapcore.EpochTimeEncoder
logOpts.TimeEncoder = zapcore.ISO8601TimeEncoder // zapcore.EpochTimeEncoder
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it intended? I think we used different encoders on purpose.

}
return ctrl.Result{Requeue: true}, nil
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: here you can use the newly introduced HasDataImage to provide a better error message when Ironic is too old

Signed-off-by: Himanshu Roy <hroy@redhat.com>
@hroyrh hroyrh force-pushed the non-bootable-iso branch from 19d0515 to 397bc8b Compare April 24, 2024 13:10
@hroyrh
Copy link
Member Author

hroyrh commented Apr 24, 2024

/test metal3-bmo-e2e-test-pull metal3-centos-e2e-integration-test-main

@dtantsur
Copy link
Member

/approve

@metal3-io-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dtantsur

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@metal3-io-bot metal3-io-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 24, 2024
@elfosardo
Copy link
Member

/lgtm

@metal3-io-bot metal3-io-bot added the lgtm Indicates that a PR is ready to be merged. label Apr 24, 2024
@dtantsur
Copy link
Member

/override Approve on ok-to-test

@metal3-io-bot
Copy link
Contributor

@dtantsur: /override requires failed status contexts, check run or a prowjob name to operate on.
The following unknown contexts/checkruns were given:

  • Approve
  • ok-to-test
  • on

Only the following failed contexts/checkruns were expected:

  • generate
  • gomod
  • manifestlint
  • metal3-bmo-e2e-test-pull
  • metal3-centos-e2e-integration-test-main
  • tide
  • unit

If you are trying to override a checkrun that has a space in it, you must put a double quote on the context.

In response to this:

/override Approve on ok-to-test

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@dtantsur
Copy link
Member

/override "Approve on ok-to-test"

@metal3-io-bot
Copy link
Contributor

@dtantsur: /override requires failed status contexts, check run or a prowjob name to operate on.
The following unknown contexts/checkruns were given:

  • Approve on ok-to-test

Only the following failed contexts/checkruns were expected:

  • generate
  • gomod
  • manifestlint
  • metal3-bmo-e2e-test-pull
  • metal3-centos-e2e-integration-test-main
  • tide
  • unit

If you are trying to override a checkrun that has a space in it, you must put a double quote on the context.

In response to this:

/override "Approve on ok-to-test"

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@dtantsur dtantsur merged commit 98c7c1a into metal3-io:main Apr 24, 2024
16 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants