-
Notifications
You must be signed in to change notification settings - Fork 256
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
Conversation
8c7a54b
to
b2bb2cb
Compare
return nil | ||
} | ||
// Error reading the object - requeue the request. | ||
return actionError{errors.Wrap(err, "could not load dataImage")} |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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)
pkg/provisioner/ironic/ironic.go
Outdated
|
||
// Get DataImage Details | ||
// Fetches the VirtualMedia details of the BareMetalHost and updates DataImage. | ||
func (p *ironicProvisioner) GetDataImageStatus(dataImage *metal3api.DataImage) (err error) { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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"` |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
b2bb2cb
to
21d18b6
Compare
21d18b6
to
f6afc45
Compare
c53f0c8
to
cd843d0
Compare
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 | ||
} | ||
|
There was a problem hiding this comment.
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>
19d0515
to
397bc8b
Compare
/test metal3-bmo-e2e-test-pull metal3-centos-e2e-integration-test-main |
/approve |
[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 |
/lgtm |
/override Approve on ok-to-test |
@dtantsur: /override requires failed status contexts, check run or a prowjob name to operate on.
Only the following failed contexts/checkruns were expected:
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:
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. |
/override "Approve on ok-to-test" |
@dtantsur: /override requires failed status contexts, check run or a prowjob name to operate on.
Only the following failed contexts/checkruns were expected:
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:
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. |
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.