Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
130646: drtprod: yaml config support r=sambhav-jain-16,vidit-bhat a=nameisbhaskar

This implementation of drtprod enables you to define the series of commands in a YAML file and execute the same. This way you can define a sequence of commands for a cluster.

You can find more details in https://cockroachlabs.atlassian.net/l/cp/0nxKZuyP.

With this the expectation is to decommission drtprod script and move all configurations to smaller scripts and yaml.

Fixes: cockroachdb#125381
Epic: None

Co-authored-by: Bhaskarjyoti Bora <[email protected]>
  • Loading branch information
craig[bot] and nameisbhaskar committed Sep 25, 2024
2 parents 8846663 + bae534f commit 59061df
Show file tree
Hide file tree
Showing 15 changed files with 821 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ ALL_TESTS = [
"//pkg/cmd/dev:dev_test",
"//pkg/cmd/docgen/extract:extract_test",
"//pkg/cmd/docs-issue-generation:docs-issue-generation_test",
"//pkg/cmd/drtprod/cli/commands:commands_test",
"//pkg/cmd/github-pull-request-make:github-pull-request-make_test",
"//pkg/cmd/label-merged-pr:label-merged-pr_test",
"//pkg/cmd/mirror/go:go_test",
Expand Down Expand Up @@ -1122,6 +1123,12 @@ GO_TARGETS = [
"//pkg/cmd/docs-issue-generation:docs-issue-generation_test",
"//pkg/cmd/drt-run:drt-run",
"//pkg/cmd/drt-run:drt_run_lib",
"//pkg/cmd/drtprod/cli/commands:commands",
"//pkg/cmd/drtprod/cli/commands:commands_test",
"//pkg/cmd/drtprod/cli:cli",
"//pkg/cmd/drtprod/helpers:helpers",
"//pkg/cmd/drtprod:drtprod",
"//pkg/cmd/drtprod:drtprod_lib",
"//pkg/cmd/fuzz:fuzz",
"//pkg/cmd/fuzz:fuzz_lib",
"//pkg/cmd/generate-acceptance-tests:generate-acceptance-tests",
Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/dev/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ var buildTargetMapping = map[string]string{
"optfmt": "//pkg/sql/opt/optgen/cmd/optfmt:optfmt",
"oss": cockroachTargetOss,
"reduce": "//pkg/cmd/reduce:reduce",
"drtprod": "//pkg/cmd/drtprod:drtprod",
"roachprod": "//pkg/cmd/roachprod:roachprod",
"roachprod-stress": "//pkg/cmd/roachprod-stress:roachprod-stress",
"roachprod-microbench": "//pkg/cmd/roachprod-microbench:roachprod-microbench",
Expand Down
15 changes: 15 additions & 0 deletions pkg/cmd/drtprod/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")

go_library(
name = "drtprod_lib",
srcs = ["main.go"],
importpath = "github.com/cockroachdb/cockroach/pkg/cmd/drtprod",
visibility = ["//visibility:private"],
deps = ["//pkg/cmd/drtprod/cli"],
)

go_binary(
name = "drtprod",
embed = [":drtprod_lib"],
visibility = ["//visibility:public"],
)
8 changes: 8 additions & 0 deletions pkg/cmd/drtprod/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# DRT Prod

drtprod is a tool for manipulating drt clusters using roachprod,
allowing easy creating, destruction, controls and configurations of clusters.

Commands include:<br/>
<b>execute</b>: executes the commands in the YAML<br/>
<b>*</b>: any other command is passed to roachprod, potentially with flags added
17 changes: 17 additions & 0 deletions pkg/cmd/drtprod/cli/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "cli",
srcs = [
"handlers.go",
"registry.go",
],
importpath = "github.com/cockroachdb/cockroach/pkg/cmd/drtprod/cli",
visibility = ["//visibility:public"],
deps = [
"//pkg/cmd/drtprod/cli/commands",
"//pkg/cmd/drtprod/helpers",
"//pkg/roachprod",
"@com_github_spf13_cobra//:cobra",
],
)
24 changes: 24 additions & 0 deletions pkg/cmd/drtprod/cli/commands/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
name = "commands",
srcs = [
"rootcmd.go",
"yamlprocessor.go",
],
importpath = "github.com/cockroachdb/cockroach/pkg/cmd/drtprod/cli/commands",
visibility = ["//visibility:public"],
deps = [
"//pkg/build",
"//pkg/cmd/drtprod/helpers",
"@com_github_spf13_cobra//:cobra",
"@in_gopkg_yaml_v2//:yaml_v2",
],
)

go_test(
name = "commands_test",
srcs = ["yamlprocessor_test.go"],
embed = [":commands"],
deps = ["@com_github_stretchr_testify//require"],
)
34 changes: 34 additions & 0 deletions pkg/cmd/drtprod/cli/commands/rootcmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2024 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package commands

import (
"context"

"github.com/cockroachdb/cockroach/pkg/build"
"github.com/spf13/cobra"
)

// GetRootCommand returns the root command
func GetRootCommand(_ context.Context) *cobra.Command {
return &cobra.Command{
Use: "drtprod [command] (flags)",
Short: "drtprod runs roachprod commands against DRT clusters",
Long: `drtprod is a tool for manipulating drt clusters using roachprod,
allowing easy creating, destruction, controls and configurations of clusters.
Commands include:
execute: executes the commands as per the YAML configuration. Refer to pkg/cmd/drtprod/configs/drt_test.yaml as an example
*: any other command is passed to roachprod, potentially with flags added
`,
Version: "details:\n" + build.GetInfo().Long(),
}
}
Loading

0 comments on commit 59061df

Please sign in to comment.