Skip to content

Commit

Permalink
few fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ophum committed Mar 3, 2021
1 parent 8598e16 commit 001979a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pkg/agents/system/blockstorage/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func (a *BlockStorageAgent) Run(pollingDuration time.Duration) {
err = a.syncCephBlockStorage(bs)
if err != nil {
a.logger.Error(
"sync local blockstorage",
"sync ceph blockstorage",
zap.String("msg", err.Error()),
zap.Time("time", time.Now()),
)
Expand Down
17 changes: 10 additions & 7 deletions pkg/agents/system/blockstorage/agent_ceph.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os/exec"
"path/filepath"
"strconv"
"strings"

"github.com/ceph/go-ceph/rados"
"github.com/ceph/go-ceph/rbd"
Expand Down Expand Up @@ -360,24 +361,26 @@ func (a *BlockStorageAgent) syncCephBlockStorage(bs *system.BlockStorage) error
imageName := imageEntity.Annotations["imageentityv0/ceph-imagename"]
cephImage, err := rbd.OpenImageReadOnly(ioctx, imageName, rbd.NoSnapshot)
if err != nil {
return err
return errors.Wrapf(err, "Failed to open image read only `%s`", imageName)
}
defer cephImage.Close()
rbd.CloneFromImage(cephImage, snapName, ioctx, imageNameWithGroupAndNS, rbd.NewRbdImageOptions())
if err := rbd.CloneFromImage(cephImage, snapName, ioctx, imageNameWithGroupAndNS, rbd.NewRbdImageOptions()); err != nil {
return errors.Wrapf(err, "Failed to clone from image `%s` from `%s@%s`", imageNameWithGroupAndNS, cephImage, snapName)
}
// ceph image のリサイズ
if image, err := rbd.OpenImage(ioctx, imageNameWithGroupAndNS, ""); err != nil {
return err
return errors.Wrapf(err, "Failed to open image `%s`", imageNameWithGroupAndNS)
} else {
defer image.Close()
size, err := strconv.ParseUint(withUnitToWithoutUnit(bs.Spec.LimitSize), 10, 64)
if err != nil {
if err := a.setStateError(bs); err != nil {
return err
}
return err
return errors.Wrapf(err, "Failed to parse uint limit size`%s`", bs.Spec.LimitSize)
}
if err := image.Resize(size); err != nil {
return err
return errors.Wrapf(err, "Failed to resize rbd image `%s`", bs.ID)
}
}
// ceph image内のqcow2リサイズ
Expand All @@ -391,9 +394,9 @@ func (a *BlockStorageAgent) syncCephBlockStorage(bs *system.BlockStorage) error
cmd := exec.Command(command, args...)
if _, err := cmd.CombinedOutput(); err != nil {
if err := a.setStateError(bs); err != nil {
return err
return errors.Wrapf(err, "Failed to exec `%s %s` but cannot update state", command, strings.Join(args, " "))
}
return err
return errors.Wrapf(err, "Failed to exec `%s %s`", command, strings.Join(args, " "))
}

}
Expand Down
8 changes: 5 additions & 3 deletions pkg/agents/system/virtualmachine/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,11 @@ func (a *VirtualMachineAgent) powerOnVirtualMachine(
return nil
}

vm.Status.State = system.VirtualMachineStatePending
if _, err = a.client.SystemV0().VirtualMachine().Update(vm); err != nil {
return err
if vm.Status.State != system.VirtualMachineStatePending {
vm.Status.State = system.VirtualMachineStatePending
if _, err = a.client.SystemV0().VirtualMachine().Update(vm); err != nil {
return err
}
}

disks := []string{}
Expand Down

0 comments on commit 001979a

Please sign in to comment.