|
2 | 2 | package main |
3 | 3 |
|
4 | 4 | import ( |
5 | | - "context" |
6 | 5 | "fmt" |
7 | 6 | "os" |
8 | 7 |
|
9 | 8 | "github.com/cloudnative-pg/machinery/pkg/log" |
10 | | - "github.com/sourcegraph/conc/pool" |
11 | 9 | "github.com/spf13/cobra" |
12 | 10 | "github.com/spf13/viper" |
13 | 11 |
|
14 | 12 | "github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/operator" |
15 | | - "github.com/cloudnative-pg/plugin-barman-cloud/internal/operator/manager" |
16 | 13 | ) |
17 | 14 |
|
18 | 15 | func main() { |
19 | 16 | cobra.EnableTraverseRunHooks = true |
20 | 17 |
|
21 | 18 | logFlags := &log.Flags{} |
22 | 19 | rootCmd := &cobra.Command{ |
23 | | - Use: "plugin-barman-cloud", |
| 20 | + Use: "plugin-barman-cloud", |
| 21 | + Short: "Starts the BarmanObjectStore reconciler and the Barman Cloud CNPG-i plugin", |
| 22 | + RunE: func(cmd *cobra.Command, _ []string) error { |
| 23 | + if len(viper.GetString("sidecar-image")) == 0 { |
| 24 | + return fmt.Errorf("missing required SIDECAR_IMAGE environment variable") |
| 25 | + } |
| 26 | + |
| 27 | + return operator.Start(cmd.Context()) |
| 28 | + }, |
24 | 29 | PersistentPreRunE: func(_ *cobra.Command, _ []string) error { |
25 | 30 | logFlags.ConfigureLogging() |
26 | 31 | return nil |
27 | 32 | }, |
28 | 33 | } |
29 | 34 |
|
30 | 35 | logFlags.AddFlags(rootCmd.PersistentFlags()) |
31 | | - rootCmd.AddCommand(newOperatorCommand()) |
32 | | - |
33 | | - if err := rootCmd.Execute(); err != nil { |
34 | | - fmt.Println(err) |
35 | | - os.Exit(1) |
36 | | - } |
37 | | -} |
38 | 36 |
|
39 | | -func newOperatorCommand() *cobra.Command { |
40 | | - cmd := operator.NewCommand() |
41 | | - cmd.Use = "operator" |
42 | | - cmd.Short = "Starts the BarmanObjectStore reconciler and the Barman Cloud CNPG-i plugin" |
43 | | - grpcServer := cmd.RunE |
44 | | - |
45 | | - cmd.RunE = func(cmd *cobra.Command, args []string) error { |
46 | | - operatorPool := pool. |
47 | | - New(). |
48 | | - WithContext(cmd.Context()). |
49 | | - WithCancelOnError(). |
50 | | - WithFirstError() |
51 | | - operatorPool.Go(func(ctx context.Context) error { |
52 | | - cmd.SetContext(ctx) |
53 | | - |
54 | | - if len(viper.GetString("sidecar-image")) == 0 { |
55 | | - return fmt.Errorf("missing required SIDECAR_IMAGE environment variable") |
56 | | - } |
57 | | - |
58 | | - err := grpcServer(cmd, args) |
59 | | - return err |
60 | | - }) |
61 | | - operatorPool.Go(manager.Start) |
62 | | - return operatorPool.Wait() |
63 | | - } |
64 | | - |
65 | | - cmd.Flags().String("metrics-bind-address", "0", "The address the metrics endpoint binds to. "+ |
| 37 | + rootCmd.Flags().String("metrics-bind-address", "0", "The address the metrics endpoint binds to. "+ |
66 | 38 | "Use :8443 for HTTPS or :8080 for HTTP, or leave as 0 to disable the metrics service.") |
67 | | - _ = viper.BindPFlag("metrics-bind-address", cmd.Flags().Lookup("metrics-bind-address")) |
| 39 | + _ = viper.BindPFlag("metrics-bind-address", rootCmd.Flags().Lookup("metrics-bind-address")) |
68 | 40 |
|
69 | | - cmd.Flags().String("health-probe-bind-address", ":8081", "The address the probe endpoint binds to.") |
70 | | - _ = viper.BindPFlag("health-probe-bind-address", cmd.Flags().Lookup("health-probe-bind-address")) |
| 41 | + rootCmd.Flags().String("health-probe-bind-address", ":8081", "The address the probe endpoint binds to.") |
| 42 | + _ = viper.BindPFlag("health-probe-bind-address", rootCmd.Flags().Lookup("health-probe-bind-address")) |
71 | 43 |
|
72 | | - cmd.Flags().Bool("leader-elect", false, |
| 44 | + rootCmd.Flags().Bool("leader-elect", false, |
73 | 45 | "Enable leader election for controller manager. "+ |
74 | 46 | "Enabling this will ensure there is only one active controller manager.") |
75 | | - _ = viper.BindPFlag("leader-elect", cmd.Flags().Lookup("leader-elect")) |
| 47 | + _ = viper.BindPFlag("leader-elect", rootCmd.Flags().Lookup("leader-elect")) |
76 | 48 |
|
77 | | - cmd.Flags().Bool("metrics-secure", true, |
| 49 | + rootCmd.Flags().Bool("metrics-secure", true, |
78 | 50 | "If set, the metrics endpoint is served securely via HTTPS. Use --metrics-secure=false to use HTTP instead.") |
79 | | - _ = viper.BindPFlag("metrics-secure", cmd.Flags().Lookup("metrics-secure")) |
| 51 | + _ = viper.BindPFlag("metrics-secure", rootCmd.Flags().Lookup("metrics-secure")) |
80 | 52 |
|
81 | | - cmd.Flags().Bool("enable-http2", false, |
| 53 | + rootCmd.Flags().Bool("enable-http2", false, |
82 | 54 | "If set, HTTP/2 will be enabled for the metrics and webhook servers") |
83 | | - _ = viper.BindPFlag("enable-http2", cmd.Flags().Lookup("enable-http2")) |
| 55 | + _ = viper.BindPFlag("enable-http2", rootCmd.Flags().Lookup("enable-http2")) |
| 56 | + |
| 57 | + rootCmd.Flags().String( |
| 58 | + "plugin-path", |
| 59 | + "", |
| 60 | + "The plugins socket path", |
| 61 | + ) |
| 62 | + _ = viper.BindPFlag("plugin-path", rootCmd.Flags().Lookup("plugin-path")) |
| 63 | + |
| 64 | + rootCmd.Flags().String( |
| 65 | + "server-cert", |
| 66 | + "", |
| 67 | + "The public key to be used for the server process", |
| 68 | + ) |
| 69 | + _ = viper.BindPFlag("server-cert", rootCmd.Flags().Lookup("server-cert")) |
| 70 | + |
| 71 | + rootCmd.Flags().String( |
| 72 | + "server-key", |
| 73 | + "", |
| 74 | + "The key to be used for the server process", |
| 75 | + ) |
| 76 | + _ = viper.BindPFlag("server-key", rootCmd.Flags().Lookup("server-key")) |
| 77 | + |
| 78 | + rootCmd.Flags().String( |
| 79 | + "client-cert", |
| 80 | + "", |
| 81 | + "The client public key to verify the connection", |
| 82 | + ) |
| 83 | + _ = viper.BindPFlag("client-cert", rootCmd.Flags().Lookup("client-cert")) |
| 84 | + |
| 85 | + rootCmd.Flags().String( |
| 86 | + "server-address", |
| 87 | + "", |
| 88 | + "The address where to listen (i.e. 0:9090)", |
| 89 | + ) |
| 90 | + _ = viper.BindPFlag("server-address", rootCmd.Flags().Lookup("server-address")) |
84 | 91 |
|
85 | 92 | _ = viper.BindEnv("sidecar-image", "SIDECAR_IMAGE") |
86 | 93 |
|
87 | | - return cmd |
| 94 | + if err := rootCmd.Execute(); err != nil { |
| 95 | + fmt.Println(err) |
| 96 | + os.Exit(1) |
| 97 | + } |
88 | 98 | } |
0 commit comments