Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions pkg/cmds/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,33 @@ func NewCmdDebug(f cmdutil.Factory) *cobra.Command {
DisableAutoGenTag: true,
}

// KubeDB v1 databases
cmd.AddCommand(debug.ElasticsearchDebugCMD(f))
cmd.AddCommand(debug.KafkaDebugCMD(f))
cmd.AddCommand(debug.MariaDBDebugCMD(f))
cmd.AddCommand(debug.MemcachedDebugCMD(f))
cmd.AddCommand(debug.MongoDBDebugCMD(f))
cmd.AddCommand(debug.MySQLDebugCMD(f))
cmd.AddCommand(debug.PerconaXtraDBDebugCMD(f))
cmd.AddCommand(debug.PgBouncerDebugCMD(f))
cmd.AddCommand(debug.PostgresDebugCMD(f))
cmd.AddCommand(debug.ProxySQLDebugCMD(f))
cmd.AddCommand(debug.RedisDebugCMD(f))

// KubeDB v1alpha2 databases
cmd.AddCommand(debug.CassandraDebugCMD(f))
cmd.AddCommand(debug.ClickHouseDebugCMD(f))
cmd.AddCommand(debug.DruidDebugCMD(f))
cmd.AddCommand(debug.FerretDBDebugCMD(f))
cmd.AddCommand(debug.HazelcastDebugCMD(f))
cmd.AddCommand(debug.IgniteDebugCMD(f))
cmd.AddCommand(debug.MSSQLServerDebugCMD(f))
cmd.AddCommand(debug.OracleDebugCMD(f))
cmd.AddCommand(debug.PgpoolDebugCMD(f))
cmd.AddCommand(debug.RabbitMQDebugCMD(f))
cmd.AddCommand(debug.SinglestoreDebugCMD(f))
cmd.AddCommand(debug.SolrDebugCMD(f))
cmd.AddCommand(debug.ZooKeeperDebugCMD(f))

return cmd
}
92 changes: 92 additions & 0 deletions pkg/debug/cassandra.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
Copyright AppsCode Inc. and Contributors

Licensed under the AppsCode Community License 1.0.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

https://github.com/appscode/licenses/raw/1.0.0/AppsCode-Community-1.0.0.md

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 debug

import (
"context"
"log"

olddbapi "kubedb.dev/apimachinery/apis/kubedb/v1alpha2"

"github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
_ "k8s.io/client-go/plugin/pkg/client/auth"
"k8s.io/klog/v2"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
)

func CassandraDebugCMD(f cmdutil.Factory) *cobra.Command {
var (
dbName string
operatorNamespace string
)

mdDebugCmd := &cobra.Command{
Use: "cassandra",
Aliases: []string{
"cs",
"cassandras",
},
Short: "Debug helper for Cassandra database",
Example: `kubectl dba debug cassandra -n demo sample-cassandra --operator-namespace kubedb`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
log.Fatal("Enter cassandra object's name as an argument")
}
dbName = args[0]

namespace, _, err := f.ToRawKubeConfigLoader().Namespace()
if err != nil {
klog.Error(err, "failed to get current namespace")
}

gvk := func() schema.GroupVersionKind {
kind := olddbapi.ResourceKindCassandra
return schema.GroupVersionKind{
Group: olddbapi.SchemeGroupVersion.Group,
Version: olddbapi.SchemeGroupVersion.Version,
Kind: kind,
}
}()
opts, err := newDBOpts(f, gvk, dbName, namespace, operatorNamespace)
if err != nil {
log.Fatalln(err)
}

var db olddbapi.Cassandra
err = opts.kc.Get(context.TODO(), types.NamespacedName{Name: dbName, Namespace: namespace}, &db)
if err != nil {
log.Fatalln(err)
}

err = writeYaml(&db, getDir(db.GetName()))
if err != nil {
return
}
opts.selectors = db.OffshootSelectors()
klog.Infof("db selectors: %v;\nDebug info has been generated in '%v' folder", opts.selectors, dbName)
err = opts.collectALl()
if err != nil {
log.Fatalln(err)
}
},
}
mdDebugCmd.Flags().StringVarP(&operatorNamespace, "operator-namespace", "o", "kubedb", "the namespace where the kubedb operator is installed")

return mdDebugCmd
}
92 changes: 92 additions & 0 deletions pkg/debug/clickhouse.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
Copyright AppsCode Inc. and Contributors

Licensed under the AppsCode Community License 1.0.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

https://github.com/appscode/licenses/raw/1.0.0/AppsCode-Community-1.0.0.md

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 debug

import (
"context"
"log"

olddbapi "kubedb.dev/apimachinery/apis/kubedb/v1alpha2"

"github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
_ "k8s.io/client-go/plugin/pkg/client/auth"
"k8s.io/klog/v2"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
)

func ClickHouseDebugCMD(f cmdutil.Factory) *cobra.Command {
var (
dbName string
operatorNamespace string
)

mdDebugCmd := &cobra.Command{
Use: "clickhouse",
Aliases: []string{
"cl",
"clickhouses",
},
Short: "Debug helper for ClickHouse database",
Example: `kubectl dba debug clickhouse -n demo sample-clickhouse --operator-namespace kubedb`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
log.Fatal("Enter clickhouse object's name as an argument")
}
dbName = args[0]

namespace, _, err := f.ToRawKubeConfigLoader().Namespace()
if err != nil {
klog.Error(err, "failed to get current namespace")
}

gvk := func() schema.GroupVersionKind {
kind := olddbapi.ResourceKindClickHouse
return schema.GroupVersionKind{
Group: olddbapi.SchemeGroupVersion.Group,
Version: olddbapi.SchemeGroupVersion.Version,
Kind: kind,
}
}()
opts, err := newDBOpts(f, gvk, dbName, namespace, operatorNamespace)
if err != nil {
log.Fatalln(err)
}

var db olddbapi.ClickHouse
err = opts.kc.Get(context.TODO(), types.NamespacedName{Name: dbName, Namespace: namespace}, &db)
if err != nil {
log.Fatalln(err)
}

err = writeYaml(&db, getDir(db.GetName()))
if err != nil {
return
}
opts.selectors = db.OffshootSelectors()
klog.Infof("db selectors: %v;\nDebug info has been generated in '%v' folder", opts.selectors, dbName)
err = opts.collectALl()
if err != nil {
log.Fatalln(err)
}
},
}
mdDebugCmd.Flags().StringVarP(&operatorNamespace, "operator-namespace", "o", "kubedb", "the namespace where the kubedb operator is installed")

return mdDebugCmd
}
Loading
Loading