@@ -4,6 +4,13 @@ import (
4
4
"context"
5
5
"errors"
6
6
"fmt"
7
+ "io"
8
+ "net/http"
9
+ "os"
10
+ "os/user"
11
+ "strings"
12
+ "time"
13
+
7
14
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/clients/generated/apis/sql/v1beta1"
8
15
_ "github.com/lib/pq"
9
16
"github.com/nais/cloudsql-migrator/internal/pkg/common_main"
@@ -12,15 +19,9 @@ import (
12
19
nais_io_v1 "github.com/nais/liberator/pkg/apis/nais.io/v1"
13
20
nais_io_v1alpha1 "github.com/nais/liberator/pkg/apis/nais.io/v1alpha1"
14
21
"google.golang.org/api/googleapi"
15
- "io"
16
22
k8s_errors "k8s.io/apimachinery/pkg/api/errors"
17
23
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
18
24
"k8s.io/utils/ptr"
19
- "net/http"
20
- "os"
21
- "os/user"
22
- "strings"
23
- "time"
24
25
)
25
26
26
27
const (
@@ -30,6 +31,7 @@ const (
30
31
)
31
32
32
33
func CreateInstance (ctx context.Context , cfg * config.Config , source * resolved.Instance , gcpProject * resolved.GcpProject , databaseName string , mgr * common_main.Manager ) (* resolved.Instance , error ) {
34
+ mgr .Logger .Info ("getting source application" , "name" , cfg .ApplicationName )
33
35
app , err := mgr .AppClient .Get (ctx , cfg .ApplicationName )
34
36
if err != nil {
35
37
return nil , err
@@ -42,6 +44,7 @@ func CreateInstance(ctx context.Context, cfg *config.Config, source *resolved.In
42
44
return nil , err
43
45
}
44
46
47
+ mgr .Logger .Info ("get helper application" , "name" , helperName )
45
48
dummyApp , err := mgr .AppClient .Get (ctx , helperName )
46
49
if k8s_errors .IsNotFound (err ) {
47
50
dummyApp = & nais_io_v1alpha1.Application {
@@ -71,6 +74,7 @@ func CreateInstance(ctx context.Context, cfg *config.Config, source *resolved.In
71
74
},
72
75
}
73
76
77
+ mgr .Logger .Info ("creating helper application" , "name" , helperName )
74
78
app , err = mgr .AppClient .Create (ctx , dummyApp )
75
79
}
76
80
if err != nil {
@@ -213,15 +217,15 @@ func PrepareTargetInstance(ctx context.Context, cfg *config.Config, target *reso
213
217
}
214
218
215
219
func prepareTargetInstanceWithRetries (ctx context.Context , cfg * config.Config , target * resolved.Instance , mgr * common_main.Manager , retries int ) error {
220
+ mgr .Logger .Info ("preparing target instance for migration" )
221
+
216
222
targetSqlInstance , err := mgr .SqlInstanceClient .Get (ctx , target .Name )
217
223
if err != nil {
218
224
if ! k8s_errors .IsNotFound (err ) {
219
225
return err
220
226
}
221
227
}
222
228
223
- mgr .Logger .Info ("preparing target instance for migration" )
224
-
225
229
targetSqlInstance .Spec .Settings .BackupConfiguration .Enabled = ptr .To (false )
226
230
227
231
var authNetwork v1beta1.InstanceAuthorizedNetworks
@@ -232,6 +236,7 @@ func prepareTargetInstanceWithRetries(ctx context.Context, cfg *config.Config, t
232
236
233
237
targetSqlInstance .Spec .Settings .IpConfiguration .AuthorizedNetworks = appendAuthNetIfNotExists (targetSqlInstance , authNetwork )
234
238
239
+ mgr .Logger .Info ("updating target instance" , "name" , target .Name )
235
240
_ , err = mgr .SqlInstanceClient .Update (ctx , targetSqlInstance )
236
241
if err != nil {
237
242
if k8s_errors .IsConflict (err ) && retries > 0 {
@@ -291,7 +296,7 @@ func updateTargetInstanceAfterPromotionWithRetries(ctx context.Context, target *
291
296
func DeleteInstance (ctx context.Context , instanceName string , gcpProject * resolved.GcpProject , mgr * common_main.Manager ) error {
292
297
instancesService := mgr .SqlAdminService .Instances
293
298
294
- mgr .Logger .Debug ("checking for existence before deletion" )
299
+ mgr .Logger .Info ("checking for instance existence before deletion" , "name" , instanceName )
295
300
_ , err := instancesService .Get (gcpProject .Id , instanceName ).Context (ctx ).Do ()
296
301
if err != nil {
297
302
var ae * googleapi.Error
@@ -315,6 +320,7 @@ func CleanupAuthNetworks(ctx context.Context, target *resolved.Instance, mgr *co
315
320
}
316
321
317
322
func cleanupAuthNetworksWithRetries (ctx context.Context , target * resolved.Instance , mgr * common_main.Manager , retries int ) error {
323
+ mgr .Logger .Info ("deleting authorized networks" )
318
324
targetSqlInstance , err := mgr .SqlInstanceClient .Get (ctx , target .Name )
319
325
if err != nil {
320
326
return fmt .Errorf ("failed to get target instance: %w" , err )
0 commit comments