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

Method Bootstrap

pkg/management/postgres/initdb.go:474–570  ·  view source on GitHub ↗

Bootstrap creates and configures this new PostgreSQL instance

(ctx context.Context)

Source from the content-addressed store, hash-verified

472
473// Bootstrap creates and configures this new PostgreSQL instance
474func (info InitInfo) Bootstrap(ctx context.Context) error {
475 typedClient, err := management.NewControllerRuntimeClient()
476 if err != nil {
477 return err
478 }
479
480 cluster, err := info.loadCluster(ctx, typedClient)
481 if err != nil {
482 return err
483 }
484
485 enabledPluginNamesSet := stringset.From(cluster.GetJobEnabledPluginNames())
486 pluginCli, err := pluginClient.NewClient(ctx, enabledPluginNamesSet)
487 if err != nil {
488 return fmt.Errorf("error while creating the plugin client: %w", err)
489 }
490 defer pluginCli.Close(ctx)
491 ctx = pluginClient.SetPluginClientInContext(ctx, pluginCli)
492 ctx = cluster.SetInContext(ctx)
493
494 coredumpFilter := cluster.GetCoredumpFilter()
495 if err := system.SetCoredumpFilter(coredumpFilter); err != nil {
496 return err
497 }
498
499 err = info.CreateDataDirectory()
500 if err != nil {
501 return err
502 }
503
504 instance := info.GetInstance(cluster)
505
506 // Detect an initdb bootstrap with import
507 isImportBootstrap := cluster.Spec.Bootstrap != nil &&
508 cluster.Spec.Bootstrap.InitDB != nil &&
509 cluster.Spec.Bootstrap.InitDB.Import != nil
510
511 if applied, err := instance.RefreshConfigurationFilesFromCluster(
512 ctx,
513 cluster,
514 true,
515 postgres.OperationType_TYPE_INIT,
516 ); err != nil {
517 return fmt.Errorf("while writing the config: %w", err)
518 } else if !applied {
519 return fmt.Errorf("could not apply the config")
520 }
521
522 // Prepare the managed configuration file (override.conf)
523 primaryConnInfo := info.GetPrimaryConnInfo()
524
525 if isImportBootstrap {
526 // Write a special configuration for the import phase
527 if _, err := configurePostgresForImport(ctx, info.PgData); err != nil {
528 return fmt.Errorf("while configuring Postgres for import: %w", err)
529 }
530 } else {
531 // Write standard replication configuration

Callers 1

initSubCommandFunction · 0.80

Calls 15

loadClusterMethod · 0.95
CreateDataDirectoryMethod · 0.95
GetInstanceMethod · 0.95
GetPrimaryConnInfoMethod · 0.95
ConfigureNewInstanceMethod · 0.95
initdbSyncOnlyMethod · 0.95
SetCoredumpFilterFunction · 0.92
executeLogicalImportFunction · 0.85

Tested by

no test coverage detected