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

Function NewCmd

internal/cmd/manager/instance/initdb/cmd.go:39–152  ·  view source on GitHub ↗

NewCmd generates the "init" subcommand

()

Source from the content-addressed store, hash-verified

37
38// NewCmd generates the "init" subcommand
39func NewCmd() *cobra.Command {
40 var appDBName string
41 var appUser string
42 var clusterName string
43 var initDBFlagsString string
44 var namespace string
45 var parentNode string
46 var pgData string
47 var pgWal string
48 var podName string
49 var postInitSQLStr string
50 var postInitApplicationSQLStr string
51 var postInitTemplateSQLStr string
52 var postInitSQLRefsFolder string
53 var postInitApplicationSQLRefsFolder string
54 var postInitTemplateSQLRefsFolder string
55
56 cmd := &cobra.Command{
57 Use: "init [options]",
58 PreRunE: func(cmd *cobra.Command, _ []string) error {
59 return management.WaitForGetCluster(cmd.Context(), ctrl.ObjectKey{
60 Name: clusterName,
61 Namespace: namespace,
62 })
63 },
64 RunE: func(cmd *cobra.Command, _ []string) error {
65 ctx := cmd.Context()
66 contextLogger := log.FromContext(ctx)
67
68 initDBFlags, err := shellquote.Split(initDBFlagsString)
69 if err != nil {
70 contextLogger.Error(err, "Error while parsing initdb flags")
71 return err
72 }
73
74 postInitSQL, err := shellquote.Split(postInitSQLStr)
75 if err != nil {
76 contextLogger.Error(err, "Error while parsing post init SQL queries")
77 return err
78 }
79
80 postInitApplicationSQL, err := shellquote.Split(postInitApplicationSQLStr)
81 if err != nil {
82 contextLogger.Error(err, "Error while parsing post init template SQL queries")
83 return err
84 }
85
86 postInitTemplateSQL, err := shellquote.Split(postInitTemplateSQLStr)
87 if err != nil {
88 contextLogger.Error(err, "Error while parsing post init template SQL queries")
89 return err
90 }
91
92 info := postgres.InitInfo{
93 ApplicationDatabase: appDBName,
94 ApplicationUser: appUser,
95 ClusterName: clusterName,
96 InitDBOptions: initDBFlags,

Callers 1

NewCmdFunction · 0.92

Calls 5

WaitForGetClusterFunction · 0.92
TryInvokeQuitEndpointFunction · 0.92
initSubCommandFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected