Skip to content

Commit

Permalink
Make changes to run cli from the appscode/grafana-dashboards CI (#766)
Browse files Browse the repository at this point in the history
Signed-off-by: sayedppqq <[email protected]>
Signed-off-by: Arnob kumar saha <[email protected]>
  • Loading branch information
sayedppqq authored Jul 17, 2024
1 parent a0aab82 commit a82c4b2
Show file tree
Hide file tree
Showing 60 changed files with 322 additions and 246 deletions.
25 changes: 24 additions & 1 deletion pkg/cmds/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,22 @@ var alertExample = templates.Examples(`
--prom-svc-name=prometheus-kube-prometheus-prometheus --prom-svc-namespace=monitoring --prom-svc-port=9090
Valid resource types include:
* connectcluster
* druid
* elasticsearch
* kafka
* mariadb
* mongodb
* mysql
* perconaxtradb
* pgpool
* postgres
* proxysql
* rabbitmq
* redis
* singlestore
* solr
* zookeeper
`)

func AlertCMD(f cmdutil.Factory) *cobra.Command {
Expand Down Expand Up @@ -131,15 +138,22 @@ var dashboardExample = templates.Examples(`
--prom-svc-name=prometheus-kube-prometheus-prometheus --prom-svc-namespace=monitoring --prom-svc-port=9090
Valid dashboards include:
* connectcluster
* druid
* elasticsearch
* kafka
* mariadb
* mongodb
* mysql
* perconaxtradb
* pgpool
* postgres
* proxysql
* rabbitmq
* redis
* singlestore
* solr
* zookeeper
If --file is given, that is the local file. absolute or relative path both accepted.
If --url is given, that is the remote file. You have to specify the full raw url.
Expand All @@ -152,14 +166,15 @@ func DashboardCMD(f cmdutil.Factory) *cobra.Command {
branch string
file string
url string
isDB bool
)
cmd := &cobra.Command{
Use: "dashboard",
Short: i18n.T("Check availability of a grafana dashboard"),
Long: dashboardLong,

Run: func(cmd *cobra.Command, args []string) {
dashboard.Run(f, args, branch, file, url, prom)
dashboard.Run(f, args, branch, file, url, prom, isDB)
},
Example: dashboardExample,
DisableFlagsInUseLine: true,
Expand All @@ -169,6 +184,7 @@ func DashboardCMD(f cmdutil.Factory) *cobra.Command {
cmd.Flags().StringVarP(&file, "file", "f", "", "absolute or relative path of the file containing dashboard")
cmd.Flags().StringVarP(&url, "url", "u", "", "url of the raw file containing dashboard. "+
"For example: https://raw.githubusercontent.com/appscode/grafana-dashboards/master/mongodb/mongodb-summary-dashboard.json")
cmd.Flags().BoolVarP(&isDB, "isdb", "d", true, "for non db object's. just provide the url")
return cmd
}

Expand All @@ -186,15 +202,22 @@ var connectionExample = templates.Examples(`
--prom-svc-name=prometheus-kube-prometheus-prometheus --prom-svc-namespace=monitoring --prom-svc-port=9090
Valid resource types include:
* connectcluster
* druid
* elasticsearch
* kafka
* mariadb
* mongodb
* mysql
* perconaxtradb
* pgpool
* postgres
* proxysql
* rabbitmq
* redis
* singlestore
* solr
* zookeeper
`)

func ConnectionCMD(f cmdutil.Factory) *cobra.Command {
Expand Down
6 changes: 3 additions & 3 deletions pkg/common/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"context"
"fmt"

api "kubedb.dev/apimachinery/apis/kubedb/v1"
dbapi "kubedb.dev/apimachinery/apis/kubedb/v1"
cs "kubedb.dev/apimachinery/client/clientset/versioned"

cm "github.com/cert-manager/cert-manager/pkg/client/clientset/versioned"
Expand All @@ -34,7 +34,7 @@ import (
)

type MySQLOpts struct {
DB *api.MySQL
DB *dbapi.MySQL
DBImage string
Config *rest.Config
Client *kubernetes.Clientset
Expand Down Expand Up @@ -75,7 +75,7 @@ func NewMySQLOpts(f cmdutil.Factory, dbName, namespace string) (*MySQLOpts, erro
return nil, err
}

if db.Status.Phase != api.DatabasePhaseReady {
if db.Status.Phase != dbapi.DatabasePhaseReady {
return nil, fmt.Errorf("MySQL %s/%s is not ready", namespace, dbName)
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/common/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"context"
"fmt"

api "kubedb.dev/apimachinery/apis/kubedb/v1"
dbapi "kubedb.dev/apimachinery/apis/kubedb/v1"
cs "kubedb.dev/apimachinery/client/clientset/versioned"

cm "github.com/cert-manager/cert-manager/pkg/client/clientset/versioned"
Expand All @@ -34,7 +34,7 @@ import (
)

type PostgresOpts struct {
DB *api.Postgres
DB *dbapi.Postgres
DBImage string
Config *rest.Config
Client *kubernetes.Clientset
Expand Down Expand Up @@ -77,7 +77,7 @@ func NewPostgresOpts(f cmdutil.Factory, dbName, namespace string) (*PostgresOpts
return nil, err
}

if db.Status.Phase != api.DatabasePhaseReady {
if db.Status.Phase != dbapi.DatabasePhaseReady {
return nil, fmt.Errorf("postgres %s/%s is not ready", namespace, dbName)
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/connect/elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"os"

"kubedb.dev/apimachinery/apis/kubedb"
api "kubedb.dev/apimachinery/apis/kubedb/v1"
dbapi "kubedb.dev/apimachinery/apis/kubedb/v1"
cs "kubedb.dev/apimachinery/client/clientset/versioned"
"kubedb.dev/cli/pkg/lib"

Expand Down Expand Up @@ -103,7 +103,7 @@ Example curl commands:
}

type elasticsearchOpts struct {
db *api.Elasticsearch
db *dbapi.Elasticsearch
config *rest.Config
client *kubernetes.Clientset
dbClient *cs.Clientset
Expand Down Expand Up @@ -133,7 +133,7 @@ func newElasticsearchOpts(f cmdutil.Factory, dbName, namespace string) (*elastic
return nil, err
}

if db.Status.Phase != api.DatabasePhaseReady {
if db.Status.Phase != dbapi.DatabasePhaseReady {
return nil, fmt.Errorf("elasticsearch %s/%s is not ready", namespace, dbName)
}

Expand Down Expand Up @@ -165,7 +165,7 @@ func (opts *elasticsearchOpts) getDockerShellCommand(localPort int, dockerFlags,
dockerCommand = append(dockerCommand, dockerFlags...)

if db.Spec.EnableSSL {
secretName := db.CertificateName(api.ElasticsearchAdminCert)
secretName := db.CertificateName(dbapi.ElasticsearchAdminCert)
certSecret, err := opts.client.CoreV1().Secrets(db.Namespace).Get(context.TODO(), secretName, metav1.GetOptions{})
if err != nil {
return nil, err
Expand Down
8 changes: 4 additions & 4 deletions pkg/connect/mariadb.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"path/filepath"

"kubedb.dev/apimachinery/apis/kubedb"
api "kubedb.dev/apimachinery/apis/kubedb/v1"
dbapi "kubedb.dev/apimachinery/apis/kubedb/v1"
cs "kubedb.dev/apimachinery/client/clientset/versioned"
"kubedb.dev/cli/pkg/lib"

Expand Down Expand Up @@ -154,7 +154,7 @@ Examples:
}

type mariadbOpts struct {
db *api.MariaDB
db *dbapi.MariaDB
dbImage string
config *rest.Config
client *kubernetes.Clientset
Expand Down Expand Up @@ -185,7 +185,7 @@ func newmariadbOpts(f cmdutil.Factory, dbName, namespace string) (*mariadbOpts,
return nil, err
}

if db.Status.Phase != api.DatabasePhaseReady {
if db.Status.Phase != dbapi.DatabasePhaseReady {
return nil, fmt.Errorf("mariadb %s/%s is not ready", namespace, dbName)
}

Expand Down Expand Up @@ -228,7 +228,7 @@ func (opts *mariadbOpts) getDockerShellCommand(localPort int, dockerFlags, mysql
}

if db.Spec.TLS != nil {
secretName := db.CertificateName(api.MariaDBClientCert)
secretName := db.CertificateName(dbapi.MariaDBClientCert)
certSecret, err := opts.client.CoreV1().Secrets(db.Namespace).Get(context.TODO(), secretName, metav1.GetOptions{})
if err != nil {
return nil, err
Expand Down
6 changes: 3 additions & 3 deletions pkg/connect/memcached.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"strconv"

"kubedb.dev/apimachinery/apis/kubedb"
api "kubedb.dev/apimachinery/apis/kubedb/v1"
dbapi "kubedb.dev/apimachinery/apis/kubedb/v1"
cs "kubedb.dev/apimachinery/client/clientset/versioned"
"kubedb.dev/cli/pkg/lib"

Expand Down Expand Up @@ -81,7 +81,7 @@ func MemcachedConnectCMD(f cmdutil.Factory) *cobra.Command {
}

type memcachedOpts struct {
db *api.Memcached
db *dbapi.Memcached
config *rest.Config
client *kubernetes.Clientset
dbClient *cs.Clientset
Expand All @@ -108,7 +108,7 @@ func newMemcachedOpts(f cmdutil.Factory, dbName, namespace string) (*memcachedOp
return nil, err
}

if db.Status.Phase != api.DatabasePhaseReady {
if db.Status.Phase != dbapi.DatabasePhaseReady {
return nil, fmt.Errorf("memcached %s/%s is not ready", namespace, dbName)
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/connect/mongodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"path/filepath"

"kubedb.dev/apimachinery/apis/kubedb"
api "kubedb.dev/apimachinery/apis/kubedb/v1"
dbapi "kubedb.dev/apimachinery/apis/kubedb/v1"
cs "kubedb.dev/apimachinery/client/clientset/versioned"
"kubedb.dev/cli/pkg/lib"

Expand Down Expand Up @@ -159,7 +159,7 @@ Examples:
}

type mongodbOpts struct {
db *api.MongoDB
db *dbapi.MongoDB
dbImage string
config *rest.Config
client *kubernetes.Clientset
Expand Down Expand Up @@ -190,7 +190,7 @@ func newMongodbOpts(f cmdutil.Factory, dbName, namespace string) (*mongodbOpts,
return nil, err
}

if db.Status.Phase != api.DatabasePhaseReady {
if db.Status.Phase != dbapi.DatabasePhaseReady {
return nil, fmt.Errorf("mongodb %s/%s is not ready", namespace, dbName)
}

Expand Down Expand Up @@ -233,7 +233,7 @@ func (opts *mongodbOpts) getDockerShellCommand(localPort int, dockerFlags, mongo
}

if db.Spec.TLS != nil {
secretName := db.GetCertSecretName(api.MongoDBClientCert, "")
secretName := db.GetCertSecretName(dbapi.MongoDBClientCert, "")
certSecret, err := opts.client.CoreV1().Secrets(db.Namespace).Get(context.TODO(), secretName, metav1.GetOptions{})
if err != nil {
return nil, err
Expand Down
8 changes: 4 additions & 4 deletions pkg/connect/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"path/filepath"

"kubedb.dev/apimachinery/apis/kubedb"
api "kubedb.dev/apimachinery/apis/kubedb/v1"
dbapi "kubedb.dev/apimachinery/apis/kubedb/v1"
cs "kubedb.dev/apimachinery/client/clientset/versioned"
"kubedb.dev/cli/pkg/lib"

Expand Down Expand Up @@ -156,7 +156,7 @@ Examples:
}

type mysqlOpts struct {
db *api.MySQL
db *dbapi.MySQL
dbImage string
config *rest.Config
client *kubernetes.Clientset
Expand Down Expand Up @@ -187,7 +187,7 @@ func newmysqlOpts(f cmdutil.Factory, dbName, namespace string) (*mysqlOpts, erro
return nil, err
}

if db.Status.Phase != api.DatabasePhaseReady {
if db.Status.Phase != dbapi.DatabasePhaseReady {
return nil, fmt.Errorf("mysql %s/%s is not ready", namespace, dbName)
}

Expand Down Expand Up @@ -230,7 +230,7 @@ func (opts *mysqlOpts) getDockerShellCommand(localPort int, dockerFlags, mysqlEx
}

if db.Spec.TLS != nil {
secretName := db.CertificateName(api.MySQLClientCert)
secretName := db.CertificateName(dbapi.MySQLClientCert)
certSecret, err := opts.client.CoreV1().Secrets(db.Namespace).Get(context.TODO(), secretName, metav1.GetOptions{})
if err != nil {
return nil, err
Expand Down
8 changes: 4 additions & 4 deletions pkg/connect/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"path/filepath"

"kubedb.dev/apimachinery/apis/kubedb"
api "kubedb.dev/apimachinery/apis/kubedb/v1"
dbapi "kubedb.dev/apimachinery/apis/kubedb/v1"
cs "kubedb.dev/apimachinery/client/clientset/versioned"
"kubedb.dev/cli/pkg/lib"

Expand Down Expand Up @@ -164,7 +164,7 @@ Examples:
}

type postgresOpts struct {
db *api.Postgres
db *dbapi.Postgres
dbImage string
config *rest.Config
client *kubernetes.Clientset
Expand Down Expand Up @@ -199,7 +199,7 @@ func newPostgresOpts(f cmdutil.Factory, dbName, namespace, postgresDBName string
return nil, err
}

if db.Status.Phase != api.DatabasePhaseReady {
if db.Status.Phase != dbapi.DatabasePhaseReady {
return nil, fmt.Errorf("postgres %s/%s is not ready", namespace, dbName)
}

Expand Down Expand Up @@ -245,7 +245,7 @@ func (opts *postgresOpts) getDockerShellCommand(localPort int, dockerFlags, post
}

if db.Spec.TLS != nil {
secretName := db.CertificateName(api.PostgresClientCert)
secretName := db.CertificateName(dbapi.PostgresClientCert)
certSecret, err := opts.client.CoreV1().Secrets(db.Namespace).Get(context.TODO(), secretName, metav1.GetOptions{})
if err != nil {
return nil, err
Expand Down
6 changes: 3 additions & 3 deletions pkg/connect/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"strings"

"kubedb.dev/apimachinery/apis/kubedb"
api "kubedb.dev/apimachinery/apis/kubedb/v1"
dbapi "kubedb.dev/apimachinery/apis/kubedb/v1"
cs "kubedb.dev/apimachinery/client/clientset/versioned"
"kubedb.dev/cli/pkg/lib"

Expand Down Expand Up @@ -159,7 +159,7 @@ Examples:
}

type redisOpts struct {
db *api.Redis
db *dbapi.Redis
config *rest.Config
client *kubernetes.Clientset
dbClient *cs.Clientset
Expand Down Expand Up @@ -191,7 +191,7 @@ func newRedisOpts(f cmdutil.Factory, dbName, namespace string, keys, args []stri
return nil, err
}

if db.Status.Phase != api.DatabasePhaseReady {
if db.Status.Phase != dbapi.DatabasePhaseReady {
return nil, fmt.Errorf("redis %s/%s is not ready", namespace, dbName)
}

Expand Down
Loading

0 comments on commit a82c4b2

Please sign in to comment.