-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the ability to configure disk size and type for GCP clusters
This change adds the ability for GCP clusters to have custom sized disks and types.
- Loading branch information
Showing
14 changed files
with
316 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package google_test | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
compute "google.golang.org/api/compute/v1" | ||
"sigs.k8s.io/cluster-api/cloud/google" | ||
"sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
type GCEClientComputeServiceMock struct { | ||
mockImagesGet func(project string, image string) (*compute.Image, error) | ||
mockImagesGetFromFamily func(project string, family string) (*compute.Image, error) | ||
mockInstancesDelete func(project string, zone string, targetInstance string) (*compute.Operation, error) | ||
mockInstancesGet func(project string, zone string, instance string) (*compute.Instance, error) | ||
mockInstancesInsert func(project string, zone string, instance *compute.Instance) (*compute.Operation, error) | ||
mockZoneOperationsGet func(project string, zone string, operation string) (*compute.Operation, error) | ||
} | ||
|
||
func (c *GCEClientComputeServiceMock) ImagesGet(project string, image string) (*compute.Image, error) { | ||
if c.mockImagesGet == nil { | ||
return nil, nil | ||
} | ||
return c.mockImagesGet(project, image) | ||
} | ||
|
||
func (c *GCEClientComputeServiceMock) ImagesGetFromFamily(project string, family string) (*compute.Image, error) { | ||
if c.mockImagesGetFromFamily == nil { | ||
return nil, nil | ||
} | ||
return c.mockImagesGetFromFamily(project, family) | ||
} | ||
|
||
func (c *GCEClientComputeServiceMock) InstancesDelete(project string, zone string, targetInstance string) (*compute.Operation, error) { | ||
if c.mockInstancesDelete == nil { | ||
return nil, nil | ||
} | ||
return c.mockInstancesDelete(project, zone, targetInstance) | ||
} | ||
|
||
func (c *GCEClientComputeServiceMock) InstancesGet(project string, zone string, instance string) (*compute.Instance, error) { | ||
if c.mockInstancesGet == nil { | ||
return nil, nil | ||
} | ||
return c.mockInstancesGet(project, zone, instance) | ||
} | ||
|
||
func (c *GCEClientComputeServiceMock) InstancesInsert(project string, zone string, instance *compute.Instance) (*compute.Operation, error) { | ||
if c.mockInstancesInsert == nil { | ||
return nil, nil | ||
} | ||
return c.mockInstancesInsert(project, zone, instance) | ||
} | ||
|
||
func (c *GCEClientComputeServiceMock) ZoneOperationsGet(project string, zone string, operation string) (*compute.Operation, error) { | ||
if c.mockZoneOperationsGet == nil { | ||
return nil, nil | ||
} | ||
return c.mockZoneOperationsGet(project, zone, operation) | ||
} | ||
|
||
func TestOneDisk(t *testing.T) { | ||
receivedInstance, computeServiceMock := createInsertInstanceCapturingMock() | ||
err := createCluster("testdata/cluster.yaml", "testdata/machine-one.yaml", computeServiceMock) | ||
if err != nil { | ||
t.Errorf("unexpected error: %v", err) | ||
} | ||
if receivedInstance == nil { | ||
t.Error("expected a valid instance") | ||
} | ||
if len(receivedInstance.Disks) != 1 { | ||
t.Errorf("invalid disk count: expected %v got %v", 1, len(receivedInstance.Disks)) | ||
} | ||
checkDiskValues(t, receivedInstance.Disks[0], true, 17, "pd-ssd") | ||
} | ||
|
||
func TestTwoDisks(t *testing.T) { | ||
receivedInstance, computeServiceMock := createInsertInstanceCapturingMock() | ||
err := createCluster("testdata/cluster.yaml", "testdata/machine-two.yaml", computeServiceMock) | ||
if err != nil { | ||
t.Errorf("unexpected error: %v", err) | ||
} | ||
if receivedInstance == nil { | ||
t.Error("expected a valid instance") | ||
} | ||
if len(receivedInstance.Disks) != 2 { | ||
t.Errorf("invalid disk count: expected %v got %v", 2, len(receivedInstance.Disks)) | ||
} | ||
checkDiskValues(t, receivedInstance.Disks[0], true, 12, "pd-ssd") | ||
checkDiskValues(t, receivedInstance.Disks[1], false, 15, "pd-standard") | ||
} | ||
|
||
func checkDiskValues(t *testing.T, disk *compute.AttachedDisk, boot bool, sizeGb int64, diskType string) { | ||
assert.Equal(t, boot, disk.Boot) | ||
assert.Equal(t, sizeGb, disk.InitializeParams.DiskSizeGb) | ||
assert.True(t, strings.Contains(disk.InitializeParams.DiskType, diskType)) | ||
} | ||
|
||
func createCluster(clusterYamlFile string, machineYamlFile string, computeServiceMock *GCEClientComputeServiceMock) error { | ||
cluster, _ := v1alpha1.ParseClusterYaml(clusterYamlFile) | ||
machine, _ := v1alpha1.ParseMachineYaml(machineYamlFile) | ||
params := google.MachineActuatorParams{ComputeService: computeServiceMock} | ||
gce, _ := google.NewMachineActuator(params) | ||
return gce.Create(cluster, machine) | ||
} | ||
|
||
func createInsertInstanceCapturingMock() (*compute.Instance, *GCEClientComputeServiceMock) { | ||
var receivedInstance compute.Instance | ||
computeServiceMock := GCEClientComputeServiceMock{ | ||
mockInstancesInsert: func(project string, zone string, instance *compute.Instance) (*compute.Operation, error) { | ||
receivedInstance = *instance | ||
return &compute.Operation{ | ||
Status: "DONE", | ||
}, nil | ||
}, | ||
} | ||
return &receivedInstance, &computeServiceMock | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
apiVersion: "cluster.k8s.io/v1alpha1" | ||
kind: Cluster | ||
metadata: | ||
name: test10 | ||
spec: | ||
clusterNetwork: | ||
services: | ||
cidrBlocks: ["10.96.0.0/12"] | ||
pods: | ||
cidrBlocks: ["192.168.0.0/16"] | ||
serviceDomain: "cluster.local" | ||
providerConfig: | ||
value: | ||
apiVersion: "gceproviderconfig/v1alpha1" | ||
kind: "GCEProviderConfig" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
apiVersion: "cluster.k8s.io/v1alpha1" | ||
kind: Machine | ||
metadata: | ||
generateName: gce-master- | ||
labels: | ||
set: master | ||
spec: | ||
providerConfig: | ||
value: | ||
apiVersion: "gceproviderconfig/v1alpha1" | ||
kind: "GCEProviderConfig" | ||
project: "project-name-1000" | ||
zone: "us-west1-c" | ||
machineType: "n1-standard-2" | ||
image: "projects/ubuntu-os-cloud/global/images/family/ubuntu-1604-lts" | ||
disks: | ||
- initializeParams: | ||
diskSizeGb: 17 | ||
diskType: "pd-ssd" | ||
versions: | ||
kubelet: 1.8.3 | ||
controlPlane: 1.8.3 | ||
containerRuntime: | ||
name: docker | ||
version: 1.12.0 | ||
roles: | ||
- Master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
apiVersion: "cluster.k8s.io/v1alpha1" | ||
kind: Machine | ||
metadata: | ||
generateName: gce-master- | ||
labels: | ||
set: master | ||
spec: | ||
providerConfig: | ||
value: | ||
apiVersion: "gceproviderconfig/v1alpha1" | ||
kind: "GCEProviderConfig" | ||
project: "project-name-1000" | ||
zone: "us-west1-c" | ||
machineType: "n1-standard-2" | ||
image: "projects/ubuntu-os-cloud/global/images/family/ubuntu-1604-lts" | ||
disks: | ||
- initializeParams: | ||
diskSizeGb: 12 | ||
diskType: "pd-ssd" | ||
- initializeParams: | ||
diskSizeGb: 15 | ||
diskType: "pd-standard" | ||
versions: | ||
kubelet: 1.8.3 | ||
controlPlane: 1.8.3 | ||
containerRuntime: | ||
name: docker | ||
version: 1.12.0 | ||
roles: | ||
- Master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.