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

Function NewCmd

internal/cmd/manager/instance/restore/cmd.go:46–130  ·  view source on GitHub ↗

NewCmd creates the "restore" subcommand

()

Source from the content-addressed store, hash-verified

44
45// NewCmd creates the "restore" subcommand
46func NewCmd() *cobra.Command {
47 var (
48 clusterName string
49 namespace string
50 pgData string
51 pgWal string
52 )
53
54 cmd := &cobra.Command{
55 Use: "restore [flags]",
56 SilenceErrors: true,
57 RunE: func(cmd *cobra.Command, _ []string) error {
58 contextLogger := log.FromContext(cmd.Context())
59
60 // Canceling this context
61 ctx, cancel := context.WithCancel(cmd.Context())
62 defer cancel()
63
64 // Step 1: build the manager
65 mgr, err := buildManager(clusterName, namespace)
66 if err != nil {
67 contextLogger.Error(err, "while building the manager")
68 return err
69 }
70
71 // Step 1.1: add the local webserver to the manager
72 localSrv, err := webserver.NewLocalWebServer(
73 postgres.NewInstance().WithClusterName(clusterName).WithNamespace(namespace),
74 mgr.GetClient(),
75 mgr.GetEventRecorderFor("local-webserver"), //nolint:staticcheck
76 )
77 if err != nil {
78 return err
79 }
80 if err = mgr.Add(localSrv); err != nil {
81 contextLogger.Error(err, "unable to add local webserver runnable")
82 return err
83 }
84
85 // Step 2: add the restore process to the manager
86 restoreProcess := restoreRunnable{
87 cli: mgr.GetClient(),
88 clusterName: clusterName,
89 namespace: namespace,
90 pgData: pgData,
91 pgWal: pgWal,
92 cancel: cancel,
93 }
94 if mgr.Add(&restoreProcess) != nil {
95 contextLogger.Error(err, "while building the restore process")
96 return err
97 }
98
99 // Step 3: start everything
100 if err := mgr.Start(ctx); err != nil {
101 contextLogger.Error(err, "restore error")
102 return err
103 }

Callers 1

NewCmdFunction · 0.92

Calls 11

NewLocalWebServerFunction · 0.92
NewInstanceFunction · 0.92
TryInvokeQuitEndpointFunction · 0.92
WithNamespaceMethod · 0.80
WithClusterNameMethod · 0.80
buildManagerFunction · 0.70
StartMethod · 0.65
ErrorMethod · 0.45
GetClientMethod · 0.45
ErrMethod · 0.45

Tested by

no test coverage detected