Skip to content

Commit

Permalink
Add possibility to provider the desired size of the instance volume
Browse files Browse the repository at this point in the history
It possible the situation when 16Gb is not enough, to run all needed workloads,
in this situatution the node will have DiskPressure condition and will start
to evict pods from it. We want to prevent such situations and make instance volume
size configurable.
  • Loading branch information
Artyom Lukianov committed Sep 10, 2019
1 parent 4ccff3b commit d016338
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v1beta1

import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -50,9 +51,10 @@ type CloudInit struct {

// Volume contains the info for the actuator to create a volume
type Volume struct {
PoolName string `json:"poolName"`
BaseVolumeID string `json:"baseVolumeID"`
VolumeName string `json:"volumeName"`
PoolName string `json:"poolName"`
BaseVolumeID string `json:"baseVolumeID"`
VolumeName string `json:"volumeName"`
VolumeSize *resource.Quantity `json:"volumeSize,omitempty"`
}

// LibvirtClusterProviderConfig is the type that will be embedded in a Cluster.Spec.ProviderSpec field.
Expand Down
1 change: 1 addition & 0 deletions pkg/cloud/libvirt/actuators/machine/actuator.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ func (a *Actuator) createVolumeAndDomain(machine *machinev1.Machine, machineProv
VolumeName: domainName,
BaseVolumeName: machineProviderConfig.Volume.BaseVolumeID,
VolumeFormat: "qcow2",
VolumeSize: machineProviderConfig.Volume.VolumeSize,
}); err != nil {
return nil, a.handleMachineError(machine, apierrors.CreateMachine("error creating volume %v", err), createEventAction)
}
Expand Down
19 changes: 17 additions & 2 deletions pkg/cloud/libvirt/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
libvirt "github.com/libvirt/libvirt-go"
libvirtxml "github.com/libvirt/libvirt-go-xml"
providerconfigv1 "github.com/openshift/cluster-api-provider-libvirt/pkg/apis/libvirtproviderconfig/v1beta1"

"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/client-go/kubernetes"
)

Expand Down Expand Up @@ -77,6 +79,9 @@ type CreateVolumeInput struct {

// VolumeFormat as volume format
VolumeFormat string

// VolumeSize contains the size of the volume
VolumeSize *resource.Quantity
}

// LibvirtClientBuilderFuncType is function type for building aws client
Expand Down Expand Up @@ -404,11 +409,21 @@ func (client *libvirtClient) CreateVolume(input CreateVolumeInput) error {
if err != nil {
return fmt.Errorf("Can't retrieve volume info %s", input.BaseVolumeName)
}
if baseVolumeInfo.Capacity > uint64(defaultSize) {

var volumeSize uint64
if input.VolumeSize != nil {
size, _ := input.VolumeSize.AsInt64()
volumeSize = uint64(size)
} else {
volumeSize = uint64(defaultSize)
}

if baseVolumeInfo.Capacity > volumeSize {
volumeDef.Capacity.Value = baseVolumeInfo.Capacity
} else {
volumeDef.Capacity.Value = uint64(defaultSize)
volumeDef.Capacity.Value = volumeSize
}

backingStoreDef, err := newDefBackingStoreFromLibvirt(baseVolume)
if err != nil {
return fmt.Errorf("Could not retrieve backing store %s", input.BaseVolumeName)
Expand Down
3 changes: 1 addition & 2 deletions pkg/cloud/libvirt/client/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@ import (
"encoding/xml"
"errors"
"fmt"
"github.com/golang/glog"
"io"
"strconv"
"strings"
"time"

"github.com/golang/glog"
libvirt "github.com/libvirt/libvirt-go"
libvirtxml "github.com/libvirt/libvirt-go-xml"
)

const (
// TODO: support size in the API
defaultSize = 17706254336
)

Expand Down

0 comments on commit d016338

Please sign in to comment.