Skip to content

Commit

Permalink
[vtctld] more cobra binaries (#13930)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Mason authored Sep 8, 2023
1 parent ee77f54 commit 26a97d8
Show file tree
Hide file tree
Showing 24 changed files with 189 additions and 103 deletions.
74 changes: 74 additions & 0 deletions go/cmd/vtctld/cli/cli.go
Original file line number Diff line number Diff line change
@@ -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())
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
16 changes: 6 additions & 10 deletions go/cmd/vtctld/schema.go → go/cmd/vtctld/cli/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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() {
Expand Down
37 changes: 37 additions & 0 deletions go/cmd/vtctld/docgen/main.go
Original file line number Diff line number Diff line change
@@ -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 <dir>]",
RunE: func(cmd *cobra.Command, args []string) error {
return docgen.GenerateMarkdownTree(cli.Main, dir)
},
}

cmd.Flags().StringVarP(&dir, "dir", "d", "doc", "output directory to write documentation")
_ = cmd.Execute()
}
48 changes: 4 additions & 44 deletions go/cmd/vtctld/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,52 +17,12 @@ limitations under the License.
package main

import (
"github.com/spf13/pflag"

"vitess.io/vitess/go/acl"
"vitess.io/vitess/go/exit"
"vitess.io/vitess/go/vt/servenv"
"vitess.io/vitess/go/vt/topo"
"vitess.io/vitess/go/vt/vtctld"
)

func init() {
servenv.RegisterDefaultFlags()
servenv.RegisterFlags()
servenv.RegisterGRPCServerFlags()
servenv.RegisterGRPCServerAuthFlags()
servenv.RegisterServiceMapFlag()

servenv.OnParse(func(fs *pflag.FlagSet) {
acl.RegisterFlags(fs)
})
}

// used at runtime by plug-ins
var (
ts *topo.Server
"vitess.io/vitess/go/cmd/vtctld/cli"
"vitess.io/vitess/go/vt/log"
)

func main() {
servenv.ParseFlags("vtctld")
servenv.Init()
defer servenv.Close()

ts = topo.Open()
defer ts.Close()

// Init the vtctld core
err := vtctld.InitVtctld(ts)
if err != nil {
exit.Return(1)
if err := cli.Main.Execute(); err != nil {
log.Fatal(err)
}

// Register http debug/health
vtctld.RegisterDebugHealthHandler(ts)

// Start schema manager service.
initSchema()

// And run the server.
servenv.RunDefault()
}
Loading

0 comments on commit 26a97d8

Please sign in to comment.