Skip to content

Commit 167ee6a

Browse files
Test pd-extreme k8s integration
1 parent 3dd110c commit 167ee6a

File tree

4 files changed

+78
-1
lines changed

4 files changed

+78
-1
lines changed

pkg/common/utils.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,18 @@ func ValidateSnapshotType(snapshotType string) error {
259259
}
260260
}
261261

262+
// ParseMachineType returns an extracted machineType from a URL, or empty if not found.
263+
// machineTypeUrl: Full or partial URL of the machine type resource, in the format:
264+
//
265+
// zones/zone/machineTypes/machine-type
266+
func ParseMachineType(machineTypeUrl string) (string, error) {
267+
machineType := machineTypeRegex.FindStringSubmatch(machineTypeUrl)
268+
if machineType == nil {
269+
return "", fmt.Errorf("failed to parse machineTypeUrl. Expected suffix: zones/{zone}/machineTypes/{machine-type}. Got: %s", machineTypeUrl)
270+
}
271+
return machineType[1], nil
272+
}
273+
262274
// ConvertGiBStringToInt64 converts a GiB string to int64
263275
func ConvertGiBStringToInt64(str string) (int64, error) {
264276
// Verify regex before

pkg/common/utils_test.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,60 @@ func TestSnapshotStorageLocations(t *testing.T) {
578578
}
579579
}
580580

581+
func TestParseMachineType(t *testing.T) {
582+
tests := []struct {
583+
desc string
584+
inputMachineTypeUrl string
585+
expectedMachineType string
586+
expectError bool
587+
}{
588+
{
589+
desc: "full URL machine type",
590+
inputMachineTypeUrl: "https://www.googleapis.com/compute/v1/projects/my-project/zones/us-central1-c/machineTypes/c3-highcpu-4",
591+
expectedMachineType: "c3-highcpu-4",
592+
},
593+
{
594+
desc: "partial URL machine type",
595+
inputMachineTypeUrl: "zones/us-central1-c/machineTypes/n2-standard-4",
596+
expectedMachineType: "n2-standard-4",
597+
},
598+
{
599+
desc: "custom partial URL machine type",
600+
inputMachineTypeUrl: "zones/us-central1-c/machineTypes/e2-custom-2-4096",
601+
expectedMachineType: "e2-custom-2-4096",
602+
},
603+
{
604+
desc: "incorrect URL",
605+
inputMachineTypeUrl: "https://www.googleapis.com/compute/v1/projects/psch-gke-dev/zones/us-central1-c",
606+
expectError: true,
607+
},
608+
{
609+
desc: "incorrect partial URL",
610+
inputMachineTypeUrl: "zones/us-central1-c/machineTypes/",
611+
expectError: true,
612+
},
613+
{
614+
desc: "missing zone",
615+
inputMachineTypeUrl: "zones//machineTypes/n2-standard-4",
616+
expectError: true,
617+
},
618+
}
619+
for _, tc := range tests {
620+
t.Run(tc.desc, func(t *testing.T) {
621+
actualMachineFamily, err := ParseMachineType(tc.inputMachineTypeUrl)
622+
if err != nil && !tc.expectError {
623+
t.Errorf("Got error %v parsing machine type %s; expect no error", err, tc.inputMachineTypeUrl)
624+
}
625+
if err == nil && tc.expectError {
626+
t.Errorf("Got no error parsing machine type %s; expect an error", tc.inputMachineTypeUrl)
627+
}
628+
if err == nil && actualMachineFamily != tc.expectedMachineType {
629+
t.Errorf("Got %s parsing machine type; expect %s", actualMachineFamily, tc.expectedMachineType)
630+
}
631+
})
632+
}
633+
}
634+
581635
func TestConvertGiBStringToInt64(t *testing.T) {
582636
tests := []struct {
583637
desc string

test/k8s-integration/driver-config.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ func generateDriverConfigFile(testParams *testParameters) (string, error) {
127127
snapshotClassName = "no-volumesnapshotclass"
128128
}
129129

130-
caps = append(caps, "pvcDataSource")
130+
if !strings.Contains(testParams.storageClassFile, "sc-extreme") {
131+
caps = append(caps, "pvcDataSource")
132+
}
131133
minimumVolumeSize := "5Gi"
132134
numAllowedTopologies := 1
133135
if testParams.storageClassFile == regionalPDStorageClass {

test/k8s-integration/main.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,15 @@ func handle() error {
478478
return fmt.Errorf("Unknown deployment strategy %s", testParams.deploymentStrategy)
479479
}
480480

481+
<<<<<<< HEAD
482+
=======
483+
skipDiskImageSnapshots := false
484+
if mustParseVersion(testParams.clusterVersion).lessThan(mustParseVersion("1.22.0")) {
485+
// Disk image cloning in only supported from 1.22 on.
486+
skipDiskImageSnapshots = true
487+
}
488+
489+
>>>>>>> Test pd-extreme k8s integration
481490
// Run the tests using the k8sSourceDir kubernetes
482491
if len(*storageClassFiles) != 0 {
483492
applicableStorageClassFiles := []string{}

0 commit comments

Comments
 (0)