MCPcopy Create free account
hub / github.com/cloudnative-pg/cloudnative-pg / ImportDatabasesMonolith

Function ImportDatabasesMonolith

tests/utils/importdb/import_db.go:124–198  ·  view source on GitHub ↗

ImportDatabasesMonolith creates a new cluster spec importing from a sourceCluster using the Monolith approach. Imports all the specified `databaseNames` and `roles` from the source cluster NOTE: enableSuperuserAccess needs to be enabled

(
	ctx context.Context,
	crudClient client.Client,
	namespace,
	sourceClusterName,
	importedClusterName,
	imageName string,
	databaseNames []string,
	roles []string,
)

Source from the content-addressed store, hash-verified

122// Imports all the specified `databaseNames` and `roles` from the source cluster
123// NOTE: enableSuperuserAccess needs to be enabled
124func ImportDatabasesMonolith(
125 ctx context.Context,
126 crudClient client.Client,
127 namespace,
128 sourceClusterName,
129 importedClusterName,
130 imageName string,
131 databaseNames []string,
132 roles []string,
133) (*apiv1.Cluster, error) {
134 if imageName == "" {
135 imageName = os.Getenv("POSTGRES_IMG")
136 }
137 storageClassName := os.Getenv("E2E_DEFAULT_STORAGE_CLASS")
138 host, err := services.GetHostName(ctx, crudClient, namespace, sourceClusterName)
139 if err != nil {
140 return nil, err
141 }
142 superUserSecretName := sourceClusterName + apiv1.SuperUserSecretSuffix
143 targetCluster := &apiv1.Cluster{
144 ObjectMeta: metav1.ObjectMeta{
145 Name: importedClusterName,
146 Namespace: namespace,
147 },
148 Spec: apiv1.ClusterSpec{
149 Instances: 3,
150 ImageName: imageName,
151 EnableSuperuserAccess: ptr.To(true),
152
153 StorageConfiguration: apiv1.StorageConfiguration{
154 Size: "1Gi",
155 StorageClass: &storageClassName,
156 },
157
158 Bootstrap: &apiv1.BootstrapConfiguration{
159 InitDB: &apiv1.BootstrapInitDB{
160 Import: &apiv1.Import{
161 Type: "monolith",
162 Databases: databaseNames,
163 Roles: roles,
164 Source: apiv1.ImportSource{
165 ExternalCluster: sourceClusterName,
166 },
167 },
168 },
169 },
170 ExternalClusters: []apiv1.ExternalCluster{
171 {
172 Name: sourceClusterName,
173 ConnectionParameters: map[string]string{
174 "host": host,
175 "user": postgres.PostgresUser,
176 "dbname": postgres.PostgresDBName,
177 },
178 Password: &corev1.SecretKeySelector{
179 LocalObjectReference: corev1.LocalObjectReference{
180 Name: superUserSecretName,
181 },

Callers 1

Calls 2

GetHostNameFunction · 0.92
CreateFunction · 0.92

Tested by

no test coverage detected