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

Function joinSubCommand

internal/cmd/manager/instance/join/cmd.go:97–133  ·  view source on GitHub ↗
(ctx context.Context, instance *postgres.Instance, info postgres.InitInfo)

Source from the content-addressed store, hash-verified

95}
96
97func joinSubCommand(ctx context.Context, instance *postgres.Instance, info postgres.InitInfo) error {
98 contextLogger := log.FromContext(ctx)
99
100 if err := info.EnsureTargetDirectoriesDoNotExist(ctx); err != nil {
101 return err
102 }
103
104 client, err := management.NewControllerRuntimeClient()
105 if err != nil {
106 contextLogger.Error(err, "Error creating Kubernetes client")
107 return err
108 }
109
110 // Download the cluster definition from the API server
111 var cluster apiv1.Cluster
112 if err := client.Get(ctx,
113 ctrl.ObjectKey{Namespace: instance.GetNamespaceName(), Name: instance.GetClusterName()},
114 &cluster,
115 ); err != nil {
116 contextLogger.Error(err, "Error while getting cluster")
117 return err
118 }
119 instance.SetCluster(&cluster)
120
121 if _, err := instancecertificate.NewReconciler(client, instance).RefreshSecrets(ctx, &cluster); err != nil {
122 contextLogger.Error(err, "Error while refreshing secrets")
123 return err
124 }
125
126 // Run "pg_basebackup" to download the data directory from the primary
127 if err := info.Join(ctx, &cluster); err != nil {
128 contextLogger.Error(err, "Error joining node")
129 return err
130 }
131
132 return nil
133}

Callers 1

NewCmdFunction · 0.85

Calls 9

SetClusterMethod · 0.80
RefreshSecretsMethod · 0.80
JoinMethod · 0.80
GetNamespaceNameMethod · 0.65
GetClusterNameMethod · 0.65
ErrorMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected