Skip to content

Commit

Permalink
Add gcp local ssd disk support (#414)
Browse files Browse the repository at this point in the history
* add gcp local ssd disk support

* set gcp disk AutoDelete default value to true

* address comment
  • Loading branch information
tennix authored Apr 14, 2020
1 parent b6ab9df commit ec6f466
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 17 deletions.
3 changes: 2 additions & 1 deletion pkg/apis/machine/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1019,10 +1019,11 @@ type GCPMachineClassSpec struct {

// GCPDisk describes disks for GCP.
type GCPDisk struct {
AutoDelete bool
AutoDelete *bool
Boot bool
SizeGb int64
Type string
Interface string
Image string
Labels map[string]string
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/apis/machine/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1107,10 +1107,11 @@ type GCPMachineClassSpec struct {

// GCPDisk describes disks for GCP.
type GCPDisk struct {
AutoDelete bool `json:"autoDelete"`
AutoDelete *bool `json:"autoDelete"`
Boot bool `json:"boot"`
SizeGb int64 `json:"sizeGb"`
Type string `json:"type"`
Interface string `json:"interface"`
Image string `json:"image"`
Labels map[string]string `json:"labels"`
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/apis/machine/v1alpha1/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions pkg/apis/machine/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions pkg/apis/machine/validation/gcpmachineclass.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,11 @@ func validateGCPDisks(disks []*machine.GCPDisk, fldPath *field.Path) field.Error
if disk.SizeGb < 20 {
allErrs = append(allErrs, field.Invalid(idxPath.Child("sizeGb"), disk.SizeGb, "disk size must be at least 20 GB"))
}
if disk.Type != "pd-standard" && disk.Type != "pd-ssd" {
allErrs = append(allErrs, field.NotSupported(idxPath.Child("type"), disk.Type, []string{"pd-standard", "pd-ssd"}))
if disk.Type != "pd-standard" && disk.Type != "pd-ssd" && disk.Type != "SCRATCH" {
allErrs = append(allErrs, field.NotSupported(idxPath.Child("type"), disk.Type, []string{"pd-standard", "pd-ssd", "SCRATCH"}))
}
if disk.Type == "SCRATCH" && (disk.Interface != "NVME" && disk.Interface != "SCSI") {
allErrs = append(allErrs, field.NotSupported(idxPath.Child("interface"), disk.Interface, []string{"NVME", "SCSI"}))
}
if disk.Boot && "" == disk.Image {
allErrs = append(allErrs, field.Required(idxPath.Child("image"), "image is required for boot disk"))
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/machine/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 27 additions & 10 deletions pkg/driver/driver_gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,33 @@ func (d *GCPDriver) Create() (string, string, error) {

var disks = []*compute.AttachedDisk{}
for _, disk := range d.GCPMachineClass.Spec.Disks {
disks = append(disks, &compute.AttachedDisk{
AutoDelete: disk.AutoDelete,
Boot: disk.Boot,
InitializeParams: &compute.AttachedDiskInitializeParams{
DiskSizeGb: disk.SizeGb,
DiskType: fmt.Sprintf("zones/%s/diskTypes/%s", zone, disk.Type),
Labels: disk.Labels,
SourceImage: disk.Image,
},
})
var attachedDisk compute.AttachedDisk
autoDelete := false
if disk.AutoDelete == nil || *disk.AutoDelete == true {
autoDelete = true
}
if disk.Type == "SCRATCH" {
attachedDisk = compute.AttachedDisk{
AutoDelete: autoDelete,
Type: disk.Type,
Interface: disk.Interface,
InitializeParams: &compute.AttachedDiskInitializeParams{
DiskType: fmt.Sprintf("zones/%s/diskTypes/%s", zone, "local-ssd"),
},
}
} else {
attachedDisk = compute.AttachedDisk{
AutoDelete: autoDelete,
Boot: disk.Boot,
InitializeParams: &compute.AttachedDiskInitializeParams{
DiskSizeGb: disk.SizeGb,
DiskType: fmt.Sprintf("zones/%s/diskTypes/%s", zone, disk.Type),
Labels: disk.Labels,
SourceImage: disk.Image,
},
}
}
disks = append(disks, &attachedDisk)
}
instance.Disks = disks

Expand Down
8 changes: 7 additions & 1 deletion pkg/openapi/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ec6f466

Please sign in to comment.