Skip to content

Commit 41a390a

Browse files
Make the debug cli common (#805)
Signed-off-by: Arnob kumar saha <arnob@appscode.com>
1 parent 1b87111 commit 41a390a

29 files changed

+2130
-1529
lines changed

pkg/cmds/debug.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,33 @@ func NewCmdDebug(f cmdutil.Factory) *cobra.Command {
5050
DisableAutoGenTag: true,
5151
}
5252

53+
// KubeDB v1 databases
5354
cmd.AddCommand(debug.ElasticsearchDebugCMD(f))
55+
cmd.AddCommand(debug.KafkaDebugCMD(f))
5456
cmd.AddCommand(debug.MariaDBDebugCMD(f))
57+
cmd.AddCommand(debug.MemcachedDebugCMD(f))
5558
cmd.AddCommand(debug.MongoDBDebugCMD(f))
5659
cmd.AddCommand(debug.MySQLDebugCMD(f))
60+
cmd.AddCommand(debug.PerconaXtraDBDebugCMD(f))
61+
cmd.AddCommand(debug.PgBouncerDebugCMD(f))
5762
cmd.AddCommand(debug.PostgresDebugCMD(f))
63+
cmd.AddCommand(debug.ProxySQLDebugCMD(f))
5864
cmd.AddCommand(debug.RedisDebugCMD(f))
5965

66+
// KubeDB v1alpha2 databases
67+
cmd.AddCommand(debug.CassandraDebugCMD(f))
68+
cmd.AddCommand(debug.ClickHouseDebugCMD(f))
69+
cmd.AddCommand(debug.DruidDebugCMD(f))
70+
cmd.AddCommand(debug.FerretDBDebugCMD(f))
71+
cmd.AddCommand(debug.HazelcastDebugCMD(f))
72+
cmd.AddCommand(debug.IgniteDebugCMD(f))
73+
cmd.AddCommand(debug.MSSQLServerDebugCMD(f))
74+
cmd.AddCommand(debug.OracleDebugCMD(f))
75+
cmd.AddCommand(debug.PgpoolDebugCMD(f))
76+
cmd.AddCommand(debug.RabbitMQDebugCMD(f))
77+
cmd.AddCommand(debug.SinglestoreDebugCMD(f))
78+
cmd.AddCommand(debug.SolrDebugCMD(f))
79+
cmd.AddCommand(debug.ZooKeeperDebugCMD(f))
80+
6081
return cmd
6182
}

pkg/debug/cassandra.go

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
Copyright AppsCode Inc. and Contributors
3+
4+
Licensed under the AppsCode Community License 1.0.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
https://github.com/appscode/licenses/raw/1.0.0/AppsCode-Community-1.0.0.md
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package debug
18+
19+
import (
20+
"context"
21+
"log"
22+
23+
olddbapi "kubedb.dev/apimachinery/apis/kubedb/v1alpha2"
24+
25+
"github.com/spf13/cobra"
26+
"k8s.io/apimachinery/pkg/runtime/schema"
27+
"k8s.io/apimachinery/pkg/types"
28+
_ "k8s.io/client-go/plugin/pkg/client/auth"
29+
"k8s.io/klog/v2"
30+
cmdutil "k8s.io/kubectl/pkg/cmd/util"
31+
)
32+
33+
func CassandraDebugCMD(f cmdutil.Factory) *cobra.Command {
34+
var (
35+
dbName string
36+
operatorNamespace string
37+
)
38+
39+
mdDebugCmd := &cobra.Command{
40+
Use: "cassandra",
41+
Aliases: []string{
42+
"cs",
43+
"cassandras",
44+
},
45+
Short: "Debug helper for Cassandra database",
46+
Example: `kubectl dba debug cassandra -n demo sample-cassandra --operator-namespace kubedb`,
47+
Run: func(cmd *cobra.Command, args []string) {
48+
if len(args) == 0 {
49+
log.Fatal("Enter cassandra object's name as an argument")
50+
}
51+
dbName = args[0]
52+
53+
namespace, _, err := f.ToRawKubeConfigLoader().Namespace()
54+
if err != nil {
55+
klog.Error(err, "failed to get current namespace")
56+
}
57+
58+
gvk := func() schema.GroupVersionKind {
59+
kind := olddbapi.ResourceKindCassandra
60+
return schema.GroupVersionKind{
61+
Group: olddbapi.SchemeGroupVersion.Group,
62+
Version: olddbapi.SchemeGroupVersion.Version,
63+
Kind: kind,
64+
}
65+
}()
66+
opts, err := newDBOpts(f, gvk, dbName, namespace, operatorNamespace)
67+
if err != nil {
68+
log.Fatalln(err)
69+
}
70+
71+
var db olddbapi.Cassandra
72+
err = opts.kc.Get(context.TODO(), types.NamespacedName{Name: dbName, Namespace: namespace}, &db)
73+
if err != nil {
74+
log.Fatalln(err)
75+
}
76+
77+
err = writeYaml(&db, getDir(db.GetName()))
78+
if err != nil {
79+
return
80+
}
81+
opts.selectors = db.OffshootSelectors()
82+
klog.Infof("db selectors: %v;\nDebug info has been generated in '%v' folder", opts.selectors, dbName)
83+
err = opts.collectALl()
84+
if err != nil {
85+
log.Fatalln(err)
86+
}
87+
},
88+
}
89+
mdDebugCmd.Flags().StringVarP(&operatorNamespace, "operator-namespace", "o", "kubedb", "the namespace where the kubedb operator is installed")
90+
91+
return mdDebugCmd
92+
}

pkg/debug/clickhouse.go

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
Copyright AppsCode Inc. and Contributors
3+
4+
Licensed under the AppsCode Community License 1.0.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
https://github.com/appscode/licenses/raw/1.0.0/AppsCode-Community-1.0.0.md
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package debug
18+
19+
import (
20+
"context"
21+
"log"
22+
23+
olddbapi "kubedb.dev/apimachinery/apis/kubedb/v1alpha2"
24+
25+
"github.com/spf13/cobra"
26+
"k8s.io/apimachinery/pkg/runtime/schema"
27+
"k8s.io/apimachinery/pkg/types"
28+
_ "k8s.io/client-go/plugin/pkg/client/auth"
29+
"k8s.io/klog/v2"
30+
cmdutil "k8s.io/kubectl/pkg/cmd/util"
31+
)
32+
33+
func ClickHouseDebugCMD(f cmdutil.Factory) *cobra.Command {
34+
var (
35+
dbName string
36+
operatorNamespace string
37+
)
38+
39+
mdDebugCmd := &cobra.Command{
40+
Use: "clickhouse",
41+
Aliases: []string{
42+
"cl",
43+
"clickhouses",
44+
},
45+
Short: "Debug helper for ClickHouse database",
46+
Example: `kubectl dba debug clickhouse -n demo sample-clickhouse --operator-namespace kubedb`,
47+
Run: func(cmd *cobra.Command, args []string) {
48+
if len(args) == 0 {
49+
log.Fatal("Enter clickhouse object's name as an argument")
50+
}
51+
dbName = args[0]
52+
53+
namespace, _, err := f.ToRawKubeConfigLoader().Namespace()
54+
if err != nil {
55+
klog.Error(err, "failed to get current namespace")
56+
}
57+
58+
gvk := func() schema.GroupVersionKind {
59+
kind := olddbapi.ResourceKindClickHouse
60+
return schema.GroupVersionKind{
61+
Group: olddbapi.SchemeGroupVersion.Group,
62+
Version: olddbapi.SchemeGroupVersion.Version,
63+
Kind: kind,
64+
}
65+
}()
66+
opts, err := newDBOpts(f, gvk, dbName, namespace, operatorNamespace)
67+
if err != nil {
68+
log.Fatalln(err)
69+
}
70+
71+
var db olddbapi.ClickHouse
72+
err = opts.kc.Get(context.TODO(), types.NamespacedName{Name: dbName, Namespace: namespace}, &db)
73+
if err != nil {
74+
log.Fatalln(err)
75+
}
76+
77+
err = writeYaml(&db, getDir(db.GetName()))
78+
if err != nil {
79+
return
80+
}
81+
opts.selectors = db.OffshootSelectors()
82+
klog.Infof("db selectors: %v;\nDebug info has been generated in '%v' folder", opts.selectors, dbName)
83+
err = opts.collectALl()
84+
if err != nil {
85+
log.Fatalln(err)
86+
}
87+
},
88+
}
89+
mdDebugCmd.Flags().StringVarP(&operatorNamespace, "operator-namespace", "o", "kubedb", "the namespace where the kubedb operator is installed")
90+
91+
return mdDebugCmd
92+
}

0 commit comments

Comments
 (0)