Skip to content

Commit

Permalink
fix: slow volume attach to server (#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
cristiGuranIonos authored Oct 31, 2024
1 parent d240f9d commit 029aac6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [1.1.4]
- **Fixes**:
- Volume should populate the status ID from the bootvolume of the server, because it cannot store it on create. This can cause larger wait times for volume attach.

## [1.1.3]
- **Features**:
- Enable `publishConnectionDetails` option for s3 key, compute user and k8s clusters
Expand Down
10 changes: 5 additions & 5 deletions internal/controller/compute/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package server
import (
"context"
"fmt"
"reflect"

sdkgo "github.com/ionos-cloud/sdk-go/v6"

Expand Down Expand Up @@ -135,6 +134,9 @@ func (c *externalServer) Observe(ctx context.Context, mg resource.Managed) (mana
cr.Status.AtProvider.State = clients.GetCoreResourceState(&observed)
if observed.Properties != nil {
cr.Status.AtProvider.Name = *observed.Properties.Name
if observed.Properties.BootVolume != nil && observed.Properties.BootVolume.Id != nil {
cr.Status.AtProvider.VolumeID = *observed.Properties.BootVolume.Id
}
}
c.log.Debug(fmt.Sprintf("Observing state: %v", cr.Status.AtProvider.State))
clients.UpdateCondition(cr, cr.Status.AtProvider.State)
Expand Down Expand Up @@ -191,7 +193,7 @@ func (c *externalServer) Create(ctx context.Context, mg resource.Managed) (manag
// Set External Name
cr.Status.AtProvider.ServerID = *newInstance.Id
meta.SetExternalName(cr, *newInstance.Id)
if !utils.IsEmptyValue(reflect.ValueOf(cr.Spec.ForProvider.VolumeCfg.VolumeID)) {
if cr.Spec.ForProvider.VolumeCfg.VolumeID != "" {
c.log.Debug("Attaching Volume...", "volume", cr.Spec.ForProvider.VolumeCfg.VolumeID)
_, apiResponse, err = c.service.AttachVolume(ctx, cr.Spec.ForProvider.DatacenterCfg.DatacenterID,
cr.Status.AtProvider.ServerID, sdkgo.Volume{Id: &cr.Spec.ForProvider.VolumeCfg.VolumeID})
Expand All @@ -202,8 +204,6 @@ func (c *externalServer) Create(ctx context.Context, mg resource.Managed) (manag
if err = compute.WaitForRequest(ctx, c.service.GetAPIClient(), apiResponse); err != nil {
return creation, err
}
// Set Boot Volume ID
cr.Status.AtProvider.VolumeID = cr.Spec.ForProvider.VolumeCfg.VolumeID
}
return creation, nil
}
Expand All @@ -218,7 +218,7 @@ func (c *externalServer) Update(ctx context.Context, mg resource.Managed) (manag
return managed.ExternalUpdate{}, nil
}
// Attach or Detach Volume
if !utils.IsEmptyValue(reflect.ValueOf(cr.Spec.ForProvider.VolumeCfg.VolumeID)) {
if cr.Spec.ForProvider.VolumeCfg.VolumeID != "" {
c.log.Debug("Update, attaching Volume", "volume", cr.Spec.ForProvider.VolumeCfg.VolumeID)
_, apiResponse, err := c.service.AttachVolume(ctx, cr.Spec.ForProvider.DatacenterCfg.DatacenterID, cr.Status.AtProvider.ServerID,
sdkgo.Volume{Id: &cr.Spec.ForProvider.VolumeCfg.VolumeID})
Expand Down

0 comments on commit 029aac6

Please sign in to comment.