@@ -3,11 +3,13 @@ package resolved
3
3
import (
4
4
"context"
5
5
"fmt"
6
- nais_io_v1 "github.com/nais/liberator/pkg/apis/nais.io/v1"
7
- "github.com/sethvargo/go-retry"
8
6
"strings"
9
7
"time"
10
8
9
+ nais_io_v1 "github.com/nais/liberator/pkg/apis/nais.io/v1"
10
+ "github.com/nais/liberator/pkg/namegen"
11
+ "github.com/sethvargo/go-retry"
12
+
11
13
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/clients/generated/apis/sql/v1beta1"
12
14
"github.com/nais/cloudsql-migrator/internal/pkg/common_main"
13
15
"github.com/nais/cloudsql-migrator/internal/pkg/config"
@@ -87,7 +89,18 @@ func MigrationName(sourceName, targetName string) (string, error) {
87
89
if len (sourceName ) == 0 || len (targetName ) == 0 {
88
90
return "" , fmt .Errorf ("source and target must be resolved" )
89
91
}
90
- return fmt .Sprintf ("%s-%s" , sourceName , targetName ), nil
92
+ name := fmt .Sprintf ("%s-%s" , sourceName , targetName )
93
+
94
+ const maxlen = 60 // Google allows a max length of 60 for migration job names
95
+ if len (name ) > maxlen {
96
+ var err error
97
+ name , err = namegen .ShortName (name , maxlen )
98
+ if err != nil {
99
+ return "" , fmt .Errorf ("generating migration name: %w" , err )
100
+ }
101
+ }
102
+
103
+ return name , nil
91
104
}
92
105
93
106
func (i * Instance ) resolveAppPassword (secret * v1.Secret ) error {
0 commit comments