diff --git a/go/cmd/vtctld/cli/cli.go b/go/cmd/vtctld/cli/cli.go new file mode 100644 index 00000000000..d8900e09f88 --- /dev/null +++ b/go/cmd/vtctld/cli/cli.go @@ -0,0 +1,74 @@ +/* +Copyright 2023 The Vitess Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreedto in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package cli + +import ( + "github.com/spf13/cobra" + + "vitess.io/vitess/go/acl" + "vitess.io/vitess/go/vt/servenv" + "vitess.io/vitess/go/vt/topo" + "vitess.io/vitess/go/vt/vtctld" +) + +var ( + ts *topo.Server + Main = &cobra.Command{ + Use: "vtctld", + Short: "The Vitess cluster management daemon.", + Args: cobra.NoArgs, + Version: servenv.AppVersion.String(), + PreRunE: servenv.CobraPreRunE, + RunE: run, + } +) + +func run(cmd *cobra.Command, args []string) error { + servenv.Init() + defer servenv.Close() + + ts = topo.Open() + defer ts.Close() + + // Init the vtctld core + if err := vtctld.InitVtctld(ts); err != nil { + return err + } + + // Register http debug/health + vtctld.RegisterDebugHealthHandler(ts) + + // Start schema manager service. + initSchema() + + // And run the server. + servenv.RunDefault() + + return nil +} + +func init() { + servenv.RegisterDefaultFlags() + servenv.RegisterFlags() + servenv.RegisterGRPCServerFlags() + servenv.RegisterGRPCServerAuthFlags() + servenv.RegisterServiceMapFlag() + + servenv.MoveFlagsToCobraCommand(Main) + + acl.RegisterFlags(Main.Flags()) +} diff --git a/go/cmd/vtctld/plugin_azblobbackupstorage.go b/go/cmd/vtctld/cli/plugin_azblobbackupstorage.go similarity index 97% rename from go/cmd/vtctld/plugin_azblobbackupstorage.go rename to go/cmd/vtctld/cli/plugin_azblobbackupstorage.go index a4ca64096a9..bdadc894aae 100644 --- a/go/cmd/vtctld/plugin_azblobbackupstorage.go +++ b/go/cmd/vtctld/cli/plugin_azblobbackupstorage.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package main +package cli import ( _ "vitess.io/vitess/go/vt/mysqlctl/azblobbackupstorage" diff --git a/go/cmd/vtctld/plugin_cephbackupstorage.go b/go/cmd/vtctld/cli/plugin_cephbackupstorage.go similarity index 97% rename from go/cmd/vtctld/plugin_cephbackupstorage.go rename to go/cmd/vtctld/cli/plugin_cephbackupstorage.go index 6cd2d5619d0..171198f5e29 100644 --- a/go/cmd/vtctld/plugin_cephbackupstorage.go +++ b/go/cmd/vtctld/cli/plugin_cephbackupstorage.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package main +package cli import ( _ "vitess.io/vitess/go/vt/mysqlctl/cephbackupstorage" diff --git a/go/cmd/vtctld/plugin_consultopo.go b/go/cmd/vtctld/cli/plugin_consultopo.go similarity index 98% rename from go/cmd/vtctld/plugin_consultopo.go rename to go/cmd/vtctld/cli/plugin_consultopo.go index a0c53abe5ea..4617d753953 100644 --- a/go/cmd/vtctld/plugin_consultopo.go +++ b/go/cmd/vtctld/cli/plugin_consultopo.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package main +package cli // Imports and register the 'consul' topo.Server. diff --git a/go/cmd/vtctld/plugin_etcd2topo.go b/go/cmd/vtctld/cli/plugin_etcd2topo.go similarity index 98% rename from go/cmd/vtctld/plugin_etcd2topo.go rename to go/cmd/vtctld/cli/plugin_etcd2topo.go index 6ec507f910d..06e014fc19f 100644 --- a/go/cmd/vtctld/plugin_etcd2topo.go +++ b/go/cmd/vtctld/cli/plugin_etcd2topo.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package main +package cli // Imports and register the 'etcd2' topo.Server. diff --git a/go/cmd/vtctld/plugin_filebackupstorage.go b/go/cmd/vtctld/cli/plugin_filebackupstorage.go similarity index 97% rename from go/cmd/vtctld/plugin_filebackupstorage.go rename to go/cmd/vtctld/cli/plugin_filebackupstorage.go index cf2ceb5150f..9edc82d6a1b 100644 --- a/go/cmd/vtctld/plugin_filebackupstorage.go +++ b/go/cmd/vtctld/cli/plugin_filebackupstorage.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package main +package cli import ( _ "vitess.io/vitess/go/vt/mysqlctl/filebackupstorage" diff --git a/go/cmd/vtctld/plugin_gcsbackupstorage.go b/go/cmd/vtctld/cli/plugin_gcsbackupstorage.go similarity index 97% rename from go/cmd/vtctld/plugin_gcsbackupstorage.go rename to go/cmd/vtctld/cli/plugin_gcsbackupstorage.go index 82a22cef1da..655583c8ca2 100644 --- a/go/cmd/vtctld/plugin_gcsbackupstorage.go +++ b/go/cmd/vtctld/cli/plugin_gcsbackupstorage.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package main +package cli import ( _ "vitess.io/vitess/go/vt/mysqlctl/gcsbackupstorage" diff --git a/go/cmd/vtctld/plugin_grpctabletconn.go b/go/cmd/vtctld/cli/plugin_grpctabletconn.go similarity index 98% rename from go/cmd/vtctld/plugin_grpctabletconn.go rename to go/cmd/vtctld/cli/plugin_grpctabletconn.go index 08291a7c916..4a97e36eec4 100644 --- a/go/cmd/vtctld/plugin_grpctabletconn.go +++ b/go/cmd/vtctld/cli/plugin_grpctabletconn.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package main +package cli // Imports and register the gRPC tabletconn client diff --git a/go/cmd/vtctld/plugin_grpctmclient.go b/go/cmd/vtctld/cli/plugin_grpctmclient.go similarity index 98% rename from go/cmd/vtctld/plugin_grpctmclient.go rename to go/cmd/vtctld/cli/plugin_grpctmclient.go index ce554da96df..8cd349c7f87 100644 --- a/go/cmd/vtctld/plugin_grpctmclient.go +++ b/go/cmd/vtctld/cli/plugin_grpctmclient.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package main +package cli // Imports and register the gRPC tabletmanager client diff --git a/go/cmd/vtctld/plugin_grpcvtctldserver.go b/go/cmd/vtctld/cli/plugin_grpcvtctldserver.go similarity index 98% rename from go/cmd/vtctld/plugin_grpcvtctldserver.go rename to go/cmd/vtctld/cli/plugin_grpcvtctldserver.go index ee5d0aba22a..ff283d91336 100644 --- a/go/cmd/vtctld/plugin_grpcvtctldserver.go +++ b/go/cmd/vtctld/cli/plugin_grpcvtctldserver.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package main +package cli import ( "vitess.io/vitess/go/vt/servenv" diff --git a/go/cmd/vtctld/plugin_grpcvtctlserver.go b/go/cmd/vtctld/cli/plugin_grpcvtctlserver.go similarity index 98% rename from go/cmd/vtctld/plugin_grpcvtctlserver.go rename to go/cmd/vtctld/cli/plugin_grpcvtctlserver.go index 4ec5323b075..8b7f918bc58 100644 --- a/go/cmd/vtctld/plugin_grpcvtctlserver.go +++ b/go/cmd/vtctld/cli/plugin_grpcvtctlserver.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package main +package cli import ( "vitess.io/vitess/go/vt/servenv" diff --git a/go/cmd/vtctld/plugin_grpcvtgateconn.go b/go/cmd/vtctld/cli/plugin_grpcvtgateconn.go similarity index 98% rename from go/cmd/vtctld/plugin_grpcvtgateconn.go rename to go/cmd/vtctld/cli/plugin_grpcvtgateconn.go index 87019ea4260..2f05e6d9a4e 100644 --- a/go/cmd/vtctld/plugin_grpcvtgateconn.go +++ b/go/cmd/vtctld/cli/plugin_grpcvtgateconn.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package main +package cli // Imports and register the gRPC vtgateconn client diff --git a/go/cmd/vtctld/plugin_opentracing.go b/go/cmd/vtctld/cli/plugin_opentracing.go similarity index 98% rename from go/cmd/vtctld/plugin_opentracing.go rename to go/cmd/vtctld/cli/plugin_opentracing.go index c35034d42a2..76423623493 100644 --- a/go/cmd/vtctld/plugin_opentracing.go +++ b/go/cmd/vtctld/cli/plugin_opentracing.go @@ -14,11 +14,10 @@ See the License for the specific language governing permissions and limitations under the License. */ -package main +package cli import ( "vitess.io/vitess/go/trace" - "vitess.io/vitess/go/vt/servenv" ) diff --git a/go/cmd/vtctld/plugin_opentsdb.go b/go/cmd/vtctld/cli/plugin_opentsdb.go similarity index 98% rename from go/cmd/vtctld/plugin_opentsdb.go rename to go/cmd/vtctld/cli/plugin_opentsdb.go index 38f464dd887..e4f76d29009 100644 --- a/go/cmd/vtctld/plugin_opentsdb.go +++ b/go/cmd/vtctld/cli/plugin_opentsdb.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package main +package cli // This plugin imports opentsdb to register the opentsdb stats backend. diff --git a/go/cmd/vtctld/plugin_prometheusbackend.go b/go/cmd/vtctld/cli/plugin_prometheusbackend.go similarity index 98% rename from go/cmd/vtctld/plugin_prometheusbackend.go rename to go/cmd/vtctld/cli/plugin_prometheusbackend.go index f3c33e5637b..3c66018fe75 100644 --- a/go/cmd/vtctld/plugin_prometheusbackend.go +++ b/go/cmd/vtctld/cli/plugin_prometheusbackend.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package main +package cli // This plugin imports Prometheus to allow for instrumentation // with the Prometheus client library diff --git a/go/cmd/vtctld/plugin_s3backupstorage.go b/go/cmd/vtctld/cli/plugin_s3backupstorage.go similarity index 97% rename from go/cmd/vtctld/plugin_s3backupstorage.go rename to go/cmd/vtctld/cli/plugin_s3backupstorage.go index a5b5c671ebb..4b3ecb33edb 100644 --- a/go/cmd/vtctld/plugin_s3backupstorage.go +++ b/go/cmd/vtctld/cli/plugin_s3backupstorage.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package main +package cli import ( _ "vitess.io/vitess/go/vt/mysqlctl/s3backupstorage" diff --git a/go/cmd/vtctld/plugin_zk2topo.go b/go/cmd/vtctld/cli/plugin_zk2topo.go similarity index 98% rename from go/cmd/vtctld/plugin_zk2topo.go rename to go/cmd/vtctld/cli/plugin_zk2topo.go index 531d92c4cdd..77f86d98d52 100644 --- a/go/cmd/vtctld/plugin_zk2topo.go +++ b/go/cmd/vtctld/cli/plugin_zk2topo.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package main +package cli // Imports and register the 'zk2' topo.Server. diff --git a/go/cmd/vtctld/schema.go b/go/cmd/vtctld/cli/schema.go similarity index 66% rename from go/cmd/vtctld/schema.go rename to go/cmd/vtctld/cli/schema.go index 561d9253818..480679a09e6 100644 --- a/go/cmd/vtctld/schema.go +++ b/go/cmd/vtctld/cli/schema.go @@ -14,14 +14,12 @@ See the License for the specific language governing permissions and limitations under the License. */ -package main +package cli import ( "context" "time" - "github.com/spf13/pflag" - "vitess.io/vitess/go/timer" "vitess.io/vitess/go/vt/log" "vitess.io/vitess/go/vt/logutil" @@ -41,14 +39,12 @@ var ( ) func init() { - servenv.OnParse(func(fs *pflag.FlagSet) { - fs.StringVar(&schemaChangeDir, "schema_change_dir", schemaChangeDir, "Directory containing schema changes for all keyspaces. Each keyspace has its own directory, and schema changes are expected to live in '$KEYSPACE/input' dir. (e.g. 'test_keyspace/input/*sql'). Each sql file represents a schema change.") - fs.StringVar(&schemaChangeController, "schema_change_controller", schemaChangeController, "Schema change controller is responsible for finding schema changes and responding to schema change events.") - fs.StringVar(&schemaChangeUser, "schema_change_user", schemaChangeUser, "The user who schema changes are submitted on behalf of.") + Main.Flags().StringVar(&schemaChangeDir, "schema_change_dir", schemaChangeDir, "Directory containing schema changes for all keyspaces. Each keyspace has its own directory, and schema changes are expected to live in '$KEYSPACE/input' dir. (e.g. 'test_keyspace/input/*sql'). Each sql file represents a schema change.") + Main.Flags().StringVar(&schemaChangeController, "schema_change_controller", schemaChangeController, "Schema change controller is responsible for finding schema changes and responding to schema change events.") + Main.Flags().StringVar(&schemaChangeUser, "schema_change_user", schemaChangeUser, "The user who schema changes are submitted on behalf of.") - fs.DurationVar(&schemaChangeCheckInterval, "schema_change_check_interval", schemaChangeCheckInterval, "How often the schema change dir is checked for schema changes. This value must be positive; if zero or lower, the default of 1m is used.") - fs.DurationVar(&schemaChangeReplicasTimeout, "schema_change_replicas_timeout", schemaChangeReplicasTimeout, "How long to wait for replicas to receive a schema change.") - }) + Main.Flags().DurationVar(&schemaChangeCheckInterval, "schema_change_check_interval", schemaChangeCheckInterval, "How often the schema change dir is checked for schema changes. This value must be positive; if zero or lower, the default of 1m is used.") + Main.Flags().DurationVar(&schemaChangeReplicasTimeout, "schema_change_replicas_timeout", schemaChangeReplicasTimeout, "How long to wait for replicas to receive a schema change.") } func initSchema() { diff --git a/go/cmd/vtctld/docgen/main.go b/go/cmd/vtctld/docgen/main.go new file mode 100644 index 00000000000..4243153859e --- /dev/null +++ b/go/cmd/vtctld/docgen/main.go @@ -0,0 +1,37 @@ +/* +Copyright 2023 The Vitess Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package main + +import ( + "github.com/spf13/cobra" + + "vitess.io/vitess/go/cmd/internal/docgen" + "vitess.io/vitess/go/cmd/vtctld/cli" +) + +func main() { + var dir string + cmd := cobra.Command{ + Use: "docgen [-d