Skip to content

Commit

Permalink
chore: Compare sqlinstance-locationpreference mockgcp
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonvigil committed Sep 9, 2024
1 parent 6c804b7 commit e8594ae
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 39 deletions.
25 changes: 10 additions & 15 deletions mockgcp/mocksql/sqlinstance.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,9 @@ func (s *sqlInstancesService) Insert(ctx context.Context, req *pb.SqlInstancesIn
fqn := name.String()
now := time.Now()

region := "us-central1"
zone := "us-central1-a"

obj := proto.Clone(req.GetBody()).(*pb.DatabaseInstance)
obj.Name = name.InstanceName
obj.Project = name.Project.ID
obj.Region = region

obj.SelfLink = fmt.Sprintf("https://sqladmin.googleapis.com/sql/v1beta4/projects/%s/instances/%s",
name.Project.ID, name.InstanceName)
Expand All @@ -112,8 +108,6 @@ func (s *sqlInstancesService) Insert(ctx context.Context, req *pb.SqlInstancesIn
return nil, err
}

obj.GceZone = zone

// By default, allocate a public IP for the instance.
shouldAllocatePublicIP := true
// By default, do not allocate a private IP for the instance.
Expand Down Expand Up @@ -172,7 +166,9 @@ func (s *sqlInstancesService) Insert(ctx context.Context, req *pb.SqlInstancesIn

obj.ServiceAccountEmailAddress = fmt.Sprintf("p%[email protected]", name.Project.Number)

populateDefaults(obj, zone)
populateDefaults(obj)

obj.GceZone = obj.Settings.LocationPreference.Zone

obj.Settings.SettingsVersion = wrapperspb.Int64(1)

Expand Down Expand Up @@ -510,7 +506,7 @@ func setDatabaseVersionDefaults(obj *pb.DatabaseInstance) error {
return nil
}

func populateDefaults(obj *pb.DatabaseInstance, zone string) {
func populateDefaults(obj *pb.DatabaseInstance) {
if obj.InstanceType == pb.SqlInstanceType_SQL_INSTANCE_TYPE_UNSPECIFIED {
obj.InstanceType = pb.SqlInstanceType_CLOUD_SQL_INSTANCE
}
Expand Down Expand Up @@ -571,13 +567,12 @@ func populateDefaults(obj *pb.DatabaseInstance, zone string) {
ipConfiguration.SslMode = pb.IpConfiguration_ALLOW_UNENCRYPTED_AND_ENCRYPTED
}

locationPreference := settings.LocationPreference
if locationPreference == nil {
locationPreference = &pb.LocationPreference{}
settings.LocationPreference = locationPreference
if settings.LocationPreference == nil {
settings.LocationPreference = &pb.LocationPreference{
Kind: "sql#locationPreference",
Zone: obj.Region + "-a",
}
}
locationPreference.Kind = "sql#locationPreference"
locationPreference.Zone = zone

backupConfiguration := settings.BackupConfiguration
if backupConfiguration == nil {
Expand Down Expand Up @@ -735,7 +730,7 @@ func (s *sqlInstancesService) Update(ctx context.Context, req *pb.SqlInstancesUp
obj.State = existing.State
obj.UpgradableDatabaseVersions = existing.UpgradableDatabaseVersions

populateDefaults(obj, existing.GetSettings().GetLocationPreference().GetZone())
populateDefaults(obj)

obj.Settings.SettingsVersion = wrapperspb.Int64(existing.GetSettings().GetSettingsVersion().GetValue() + 1)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ User-Agent: kcc/controller-manager
]
},
"locationPreference": {
"kind": "sql#locationPreference",
"zone": "us-central1-a"
},
"pricingPlan": "PER_USE",
Expand Down Expand Up @@ -407,6 +408,7 @@ User-Agent: kcc/controller-manager
]
},
"locationPreference": {
"kind": "sql#locationPreference",
"zone": "us-central1-a"
},
"pricingPlan": "PER_USE",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ User-Agent: kcc/controller-manager
"dataDiskType": "PD_SSD",
"edition": "ENTERPRISE",
"locationPreference": {
"kind": "sql#locationPreference",
"zone": "us-central1-a"
},
"pricingPlan": "PER_USE",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,7 @@ User-Agent: kcc/controller-manager
"requireSsl": true
},
"locationPreference": {
"kind": "sql#locationPreference",
"zone": "us-central1-b"
},
"maintenanceWindow": {
Expand Down Expand Up @@ -1182,7 +1183,7 @@ X-Xss-Protection: 0
"kind": "sql#settings",
"locationPreference": {
"kind": "sql#locationPreference",
"zone": "us-central1-a"
"zone": "us-central1-b"
},
"maintenanceWindow": {
"day": 6,
Expand Down Expand Up @@ -1346,7 +1347,7 @@ X-Xss-Protection: 0
"kind": "sql#settings",
"locationPreference": {
"kind": "sql#locationPreference",
"zone": "us-central1-a"
"zone": "us-central1-b"
},
"maintenanceWindow": {
"day": 6,
Expand Down Expand Up @@ -1429,6 +1430,7 @@ User-Agent: kcc/controller-manager
"requireSsl": true
},
"locationPreference": {
"kind": "sql#locationPreference",
"zone": "us-central1-b"
},
"maintenanceWindow": {
Expand Down Expand Up @@ -1607,7 +1609,7 @@ X-Xss-Protection: 0
"kind": "sql#settings",
"locationPreference": {
"kind": "sql#locationPreference",
"zone": "us-central1-a"
"zone": "us-central1-b"
},
"maintenanceWindow": {
"day": 6,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ X-Xss-Protection: 0
"name": "${operationID}",
"operationType": "CREATE",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/${projectId}/operations/${operationID}",
"startTime": "2024-04-01T12:34:56.123456Z",
"status": "DONE",
"targetId": "sqlinstance-locationpreference-${uniqueId}",
"targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/${projectId}/instances/sqlinstance-locationpreference-${uniqueId}",
Expand Down Expand Up @@ -154,11 +153,10 @@ X-Xss-Protection: 0
}
],
"kind": "sql#instance",
"maintenanceVersion": "POSTGRES_16_3.R20240527.01_12",
"maintenanceVersion": "POSTGRES_16_3.R20240527.01_10",
"name": "sqlinstance-locationpreference-${uniqueId}",
"project": "${projectId}",
"region": "us-central1",
"satisfiesPzi": true,
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/${projectId}/instances/sqlinstance-locationpreference-${uniqueId}",
"serverCaCert": {
"cert": "-----BEGIN CERTIFICATE-----\n-----END CERTIFICATE-----\n",
Expand Down Expand Up @@ -200,6 +198,7 @@ X-Xss-Protection: 0
"kind": "sql#settings",
"locationPreference": {
"kind": "sql#locationPreference",
"secondaryZone": "us-central1-b",
"zone": "us-central1-a"
},
"pricingPlan": "PER_USE",
Expand Down Expand Up @@ -290,11 +289,10 @@ X-Xss-Protection: 0
}
],
"kind": "sql#instance",
"maintenanceVersion": "POSTGRES_16_3.R20240527.01_12",
"maintenanceVersion": "POSTGRES_16_3.R20240527.01_10",
"name": "sqlinstance-locationpreference-${uniqueId}",
"project": "${projectId}",
"region": "us-central1",
"satisfiesPzi": true,
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/${projectId}/instances/sqlinstance-locationpreference-${uniqueId}",
"serverCaCert": {
"cert": "-----BEGIN CERTIFICATE-----\n-----END CERTIFICATE-----\n",
Expand Down Expand Up @@ -336,6 +334,7 @@ X-Xss-Protection: 0
"kind": "sql#settings",
"locationPreference": {
"kind": "sql#locationPreference",
"secondaryZone": "us-central1-b",
"zone": "us-central1-a"
},
"pricingPlan": "PER_USE",
Expand All @@ -362,7 +361,7 @@ User-Agent: kcc/controller-manager
{
"databaseVersion": "POSTGRES_16",
"instanceType": "CLOUD_SQL_INSTANCE",
"maintenanceVersion": "POSTGRES_16_3.R20240527.01_12",
"maintenanceVersion": "POSTGRES_16_3.R20240527.01_10",
"name": "sqlinstance-locationpreference-${uniqueId}",
"region": "us-central1",
"settings": {
Expand Down Expand Up @@ -449,7 +448,6 @@ X-Xss-Protection: 0
"name": "${operationID}",
"operationType": "UPDATE",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/${projectId}/operations/${operationID}",
"startTime": "2024-04-01T12:34:56.123456Z",
"status": "DONE",
"targetId": "sqlinstance-locationpreference-${uniqueId}",
"targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/${projectId}/instances/sqlinstance-locationpreference-${uniqueId}",
Expand Down Expand Up @@ -500,11 +498,10 @@ X-Xss-Protection: 0
}
],
"kind": "sql#instance",
"maintenanceVersion": "POSTGRES_16_3.R20240527.01_12",
"maintenanceVersion": "POSTGRES_16_3.R20240527.01_10",
"name": "sqlinstance-locationpreference-${uniqueId}",
"project": "${projectId}",
"region": "us-central1",
"satisfiesPzi": true,
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/${projectId}/instances/sqlinstance-locationpreference-${uniqueId}",
"serverCaCert": {
"cert": "-----BEGIN CERTIFICATE-----\n-----END CERTIFICATE-----\n",
Expand Down Expand Up @@ -548,6 +545,7 @@ X-Xss-Protection: 0
"kind": "sql#settings",
"locationPreference": {
"kind": "sql#locationPreference",
"secondaryZone": "us-central1-f",
"zone": "us-central1-c"
},
"pricingPlan": "PER_USE",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ User-Agent: kcc/controller-manager
"dataDiskType": "PD_SSD",
"edition": "ENTERPRISE",
"locationPreference": {
"kind": "sql#locationPreference",
"zone": "us-central1-a"
},
"pricingPlan": "PER_USE",
Expand Down Expand Up @@ -797,6 +798,7 @@ User-Agent: kcc/controller-manager
"dataDiskType": "PD_SSD",
"edition": "ENTERPRISE",
"locationPreference": {
"kind": "sql#locationPreference",
"zone": "us-central1-a"
},
"pricingPlan": "PER_USE",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -573,10 +573,6 @@ User-Agent: kcc/controller-manager
"dataDiskSizeGb": "20",
"dataDiskType": "PD_SSD",
"edition": "ENTERPRISE",
"locationPreference": {
"kind": "sql#locationPreference",
"zone": "us-central1-a"
},
"pricingPlan": "PER_USE",
"replicationType": "SYNCHRONOUS",
"settingsVersion": "123",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ User-Agent: kcc/controller-manager
"dataDiskType": "PD_SSD",
"edition": "ENTERPRISE",
"locationPreference": {
"kind": "sql#locationPreference",
"zone": "us-central1-a"
},
"pricingPlan": "PER_USE",
Expand Down Expand Up @@ -564,6 +565,7 @@ User-Agent: kcc/controller-manager
"dataDiskType": "PD_SSD",
"edition": "ENTERPRISE",
"locationPreference": {
"kind": "sql#locationPreference",
"zone": "us-central1-a"
},
"pricingPlan": "PER_USE",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -954,10 +954,6 @@ User-Agent: kcc/controller-manager
"requireSsl": false,
"sslMode": "ENCRYPTED_ONLY"
},
"locationPreference": {
"kind": "sql#locationPreference",
"zone": "us-central1-a"
},
"pricingPlan": "PER_USE",
"replicationType": "SYNCHRONOUS",
"settingsVersion": "123",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1312,6 +1312,7 @@ User-Agent: kcc/controller-manager
"privateNetwork": "projects/${projectId}/global/networks/computenetwork-${uniqueId}"
},
"locationPreference": {
"kind": "sql#locationPreference",
"zone": "us-central1-a"
},
"pricingPlan": "PER_USE",
Expand Down Expand Up @@ -1655,6 +1656,7 @@ User-Agent: kcc/controller-manager
"privateNetwork": "projects/${projectId}/global/networks/computenetwork2-${uniqueId}"
},
"locationPreference": {
"kind": "sql#locationPreference",
"zone": "us-central1-a"
},
"pricingPlan": "PER_USE",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ User-Agent: kcc/controller-manager
"dataDiskType": "PD_SSD",
"edition": "ENTERPRISE",
"locationPreference": {
"kind": "sql#locationPreference",
"zone": "us-central1-a"
},
"pricingPlan": "PER_USE",
Expand Down Expand Up @@ -637,6 +638,7 @@ User-Agent: kcc/controller-manager
"dataDiskType": "PD_SSD",
"edition": "ENTERPRISE",
"locationPreference": {
"kind": "sql#locationPreference",
"zone": "us-central1-a"
},
"pricingPlan": "PER_USE",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -539,10 +539,6 @@ User-Agent: kcc/controller-manager
"dataDiskSizeGb": "20",
"dataDiskType": "PD_SSD",
"edition": "ENTERPRISE",
"locationPreference": {
"kind": "sql#locationPreference",
"zone": "us-central1-a"
},
"pricingPlan": "PER_USE",
"replicationType": "SYNCHRONOUS",
"settingsVersion": "123",
Expand Down

0 comments on commit e8594ae

Please sign in to comment.