Skip to content

Commit a87e46c

Browse files
committed
chore: add test for issue 4207
1 parent d03945d commit a87e46c

File tree

5 files changed

+583
-0
lines changed

5 files changed

+583
-0
lines changed

pkg/controller/direct/sql/sqlinstance_controller.go

+8
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ func (a *sqlInstanceAdapter) Find(ctx context.Context) (bool, error) {
112112
return false, nil
113113
}
114114

115+
fmt.Printf("[debug] finding SQLInstance %s\n", a.resourceID)
116+
115117
instance, err := a.sqlInstancesClient.Get(a.projectID, a.resourceID).Context(ctx).Do()
116118
if err != nil {
117119
return false, nil
@@ -180,6 +182,8 @@ func (a *sqlInstanceAdapter) insertInstance(ctx context.Context, u *unstructured
180182
return err
181183
}
182184

185+
fmt.Printf("[debug] inserting SQLInstance %+v\n", desiredGCP)
186+
183187
op, err := a.sqlInstancesClient.Insert(a.projectID, desiredGCP).Context(ctx).Do()
184188
if err != nil {
185189
return fmt.Errorf("creating SQLInstance %s failed: %w", a.desired.Name, err)
@@ -287,9 +291,13 @@ func (a *sqlInstanceAdapter) Update(ctx context.Context, updateOp *directbase.Up
287291
return err
288292
}
289293

294+
fmt.Printf("[debug] desiredGCP: %+v\n", desiredGCP)
295+
fmt.Printf("[debug] a.actual: %+v\n", a.actual)
296+
fmt.Printf("[debug] InstancesMatch(desiredGCP, a.actual): %+v\n", InstancesMatch(desiredGCP, a.actual))
290297
if !InstancesMatch(desiredGCP, a.actual) {
291298
updateOp.RecordUpdatingEvent()
292299

300+
fmt.Printf("[debug] making a GCP call to update %s\n", desiredGCP.Name)
293301
op, err := a.sqlInstancesClient.Update(a.projectID, desiredGCP.Name, desiredGCP).Context(ctx).Do()
294302
if err != nil {
295303
return fmt.Errorf("updating SQLInstance %s failed: %w", desiredGCP.Name, err)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
apiVersion: sql.cnrm.cloud.google.com/v1beta1
2+
kind: SQLInstance
3+
metadata:
4+
annotations:
5+
cnrm.cloud.google.com/deletion-policy: abandon
6+
cnrm.cloud.google.com/management-conflict-prevention-policy: none
7+
cnrm.cloud.google.com/mutable-but-unreadable-fields: '{}'
8+
cnrm.cloud.google.com/observed-secret-versions: (removed)
9+
cnrm.cloud.google.com/project-id: ${projectId}
10+
cnrm.cloud.google.com/state-into-spec: absent
11+
finalizers:
12+
- cnrm.cloud.google.com/finalizer
13+
- cnrm.cloud.google.com/deletion-defender
14+
generation: 1
15+
labels:
16+
cnrm-test: "true"
17+
name: test-${uniqueId}
18+
namespace: ${uniqueId}
19+
spec:
20+
databaseVersion: POSTGRES_13
21+
region: europe-west3
22+
resourceID: test-${uniqueId}
23+
settings:
24+
availabilityType: REGIONAL
25+
backupConfiguration:
26+
backupRetentionSettings:
27+
retainedBackups: 30
28+
enabled: true
29+
pointInTimeRecoveryEnabled: true
30+
databaseFlags:
31+
- name: temp_file_limit
32+
value: "3145728"
33+
deletionProtectionEnabled: true
34+
diskSize: 10
35+
insightsConfig:
36+
queryInsightsEnabled: true
37+
ipConfiguration:
38+
requireSsl: true
39+
tier: db-g1-small
40+
status:
41+
conditions:
42+
- lastTransitionTime: "1970-01-01T00:00:00Z"
43+
message: The resource is up to date
44+
reason: UpToDate
45+
status: "True"
46+
type: Ready
47+
connectionName: ${projectId}:europe-west3:test-${uniqueId}
48+
firstIpAddress: 10.1.2.3
49+
instanceType: CLOUD_SQL_INSTANCE
50+
ipAddress: 10.1.2.3
51+
observedGeneration: 1
52+
publicIpAddress: 10.1.2.3
53+
selfLink: https://sqladmin.googleapis.com/sql/v1beta4/projects/${projectId}/instances/test-${uniqueId}
54+
serverCaCert:
55+
cert: |
56+
-----BEGIN CERTIFICATE-----
57+
-----END CERTIFICATE-----
58+
commonName: common-name
59+
createTime: "1970-01-01T00:00:00Z"
60+
expirationTime: "1970-01-01T00:00:00Z"
61+
sha1Fingerprint: "12345678"
62+
serviceAccountEmailAddress: p${projectNumber}[email protected]

0 commit comments

Comments
 (0)