Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Redis CMD for data insert #709

Merged
merged 17 commits into from
Aug 18, 2023
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
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@ require (
kmodules.xyz/custom-resources v0.25.2
kmodules.xyz/monitoring-agent-api v0.25.1
kubedb.dev/apimachinery v0.34.1-0.20230814034200-4ce21bc51a16
kubedb.dev/db-client-go v0.0.7
stash.appscode.dev/apimachinery v0.30.1-0.20230814025143-fcb8a9106d3c
)

require (
github.com/onsi/gomega v1.24.2 // indirect
github.com/rogpeppe/go-internal v1.8.1 // indirect
)
require github.com/onsi/gomega v1.24.2 // indirect

require (
cloud.google.com/go v0.99.0 // indirect
Expand All @@ -49,6 +47,7 @@ require (
github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
Expand Down Expand Up @@ -93,6 +92,7 @@ require (
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/redis/go-redis/v9 v9.0.5 // indirect
github.com/russross/blackfriday v1.5.2 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sergi/go-diff v1.2.0 // indirect
Expand Down
10 changes: 8 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJm
github.com/bketelsen/crypt v0.0.4/go.mod h1:aI6NrJ0pMGgvZKL1iVgXLnfIFJtfV+bKCoqOes/6LfM=
github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=
github.com/bsm/ginkgo/v2 v2.7.0 h1:ItPMPH90RbmZJt5GtkcNvIRuGEdwlBItdNVoyzaNQao=
github.com/bsm/gomega v1.26.0 h1:LhQm+AFcgV2M0WyKroMASzAzCAJVpAxQXv4SaI9a69Y=
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/cert-manager/cert-manager v1.9.1 h1:bNIsQyfWdIMSEwxgO4sVUEyAn6xuSgNwdt9m92OBACc=
Expand Down Expand Up @@ -161,6 +163,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
Expand Down Expand Up @@ -525,7 +529,6 @@ github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/9
github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
github.com/peterbourgon/diskv v2.0.1+incompatible h1:UBdAOUP5p4RWqPBg048CAvpKN+vxiaj6gdUUzhl4XmI=
github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
Expand Down Expand Up @@ -570,11 +573,12 @@ github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1
github.com/prometheus/procfs v0.8.0 h1:ODq8ZFEaYeCaZOJlZZdJA2AbQR98dSHSM1KW/You5mo=
github.com/prometheus/procfs v0.8.0/go.mod h1:z7EfXMXOkbkqb9IINtpCn86r/to3BnA0uaxHdg830/4=
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/redis/go-redis/v9 v9.0.5 h1:CuQcn5HIEeK7BgElubPP8CGtE0KakrnbBSTLjathl5o=
github.com/redis/go-redis/v9 v9.0.5/go.mod h1:WqMKv5vnQbRuZstUwxQI195wHy+t4PuXDOjzMvcuQHk=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.8.1 h1:geMPLpDpQOgVyCg5z5GoRwLHepNdb71NXb67XFkP+Eg=
github.com/rogpeppe/go-internal v1.8.1/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4nPKWu0nJ5d+o=
github.com/russross/blackfriday v1.5.2 h1:HyvC0ARfnZBqnXwABFeSZHpKvJHJJfPz81GNueLj0oo=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
Expand Down Expand Up @@ -1312,6 +1316,8 @@ kmodules.xyz/prober v0.25.0 h1:R5uRLHJEvEtEoogj+vaTAob0Btph6+PX5IlS6hPh8PA=
kmodules.xyz/prober v0.25.0/go.mod h1:z4RTnjaajNQa/vPltsiOnO3xI716I/ziD2ac2Exm+1M=
kubedb.dev/apimachinery v0.34.1-0.20230814034200-4ce21bc51a16 h1:eQPrw1YyUHAsptlSd3lf3FtOWqq27vyCd9dy0wd3Z2Q=
kubedb.dev/apimachinery v0.34.1-0.20230814034200-4ce21bc51a16/go.mod h1:K4tmJODPLOBgYGA/4N8Cx4ZwX1ZtZF8E+O1NIRWwyzA=
kubedb.dev/db-client-go v0.0.7 h1:IQeN4OsCaZ5ScT28gtuMRITBNoBnfbJ+gytY3KHsZKA=
kubedb.dev/db-client-go v0.0.7/go.mod h1:Em2g9xhNCboWlN2aBsrjFfHYajkMO3RyAipJvobbdds=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
Expand Down
178 changes: 178 additions & 0 deletions pkg/cmds/data.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
/*
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 cmds

import (
"kubedb.dev/cli/pkg/data"

"github.com/spf13/cobra"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/util/i18n"
"k8s.io/kubectl/pkg/util/templates"
)

var (
dataLong = templates.LongDesc(`
Insert random data or verify data in a database.
`)
dataExample = templates.Examples(`
# Insert 100 rows in mysql table
kubectl dba data insert mysql mysql-demo -n demo --rows=100

# Verify that postgres has at least 100 rows data
kubectl dba data verify postgres sample-postgres -n demo --rows=100

# Drop all the CLI inserted data from mongodb
kubectl dba data drop mg -n demo sample-mg


Valid resource types include:
* elasticsearch
* mongodb
* mariadb
* mysql
* postgres
* redis
`)
)

func NewCmdData(f cmdutil.Factory) *cobra.Command {
cmd := &cobra.Command{
Use: "data",
Short: i18n.T("Insert, Drop or Verify data in a database"),
Long: dataLong,
Example: dataExample,
Run: func(cmd *cobra.Command, args []string) {},
DisableFlagsInUseLine: true,
DisableAutoGenTag: true,
}

cmd.AddCommand(InsertDataCMD(f))
cmd.AddCommand(VerifyDataCMD(f))
cmd.AddCommand(DropDataCMD(f))

return cmd
}

var insertLong = templates.LongDesc(`
Insert random data in a database.
`)

var insertExample = templates.Examples(`
# Insert 100 rows in mysql table
kubectl dba data insert mysql mysql-demo -n demo --rows=100

#Insert 100 keys in redis
kubectl dba data insert rd sample-redis -n demo --rows=100

Valid resource types include:
* elasticsearch
* mongodb
* mariadb
* mysql
* postgres
* redis
`)

func InsertDataCMD(f cmdutil.Factory) *cobra.Command {
cmd := &cobra.Command{
Use: "insert",
Short: i18n.T("Insert random data in a database"),
Long: insertLong,

Run: func(cmd *cobra.Command, args []string) {},
Example: insertExample,
DisableFlagsInUseLine: true,
DisableAutoGenTag: true,
}

cmd.AddCommand(data.InsertRedisDataCMD(f))

return cmd
}

var verifyLong = templates.LongDesc(`
Verify data in a database.
`)

var verifyExample = templates.Examples(`
# Verify if there is 100 rows a postgres table
kubectl dba data verify postgres sample-pg -n demo --rows=100

# Verify if there is 100 rows in a mongodb database
kubectl dba data verify mongodb -n demo mg-shard --rows=100

Valid resource types include:
* elasticsearch
* mongodb
* mariadb
* mysql
* postgres
* redis
`)

func VerifyDataCMD(f cmdutil.Factory) *cobra.Command {
cmd := &cobra.Command{
Use: "verify",
Short: i18n.T("Verify data in a database"),
Long: verifyLong,
Example: verifyExample,
Run: func(cmd *cobra.Command, args []string) {},
DisableFlagsInUseLine: true,
DisableAutoGenTag: true,
}

cmd.AddCommand(data.VerifyRedisDataCMD(f))

return cmd
}

var dropLong = templates.LongDesc(`
Drop data in a database.
`)

var dropExample = templates.Examples(`
# Drop all the cli inserted data from mariadb
kubectl dba data drop mariadb -n demo sample-maria

# Drop all the cli inserted data from elasticsearch
kubectl dba data drop es -n demo

Valid resource types include:
* elasticsearch
* mongodb
* mariadb
* mysql
* postgres
* redis
`)

func DropDataCMD(f cmdutil.Factory) *cobra.Command {
cmd := &cobra.Command{
Use: "drop",
Short: i18n.T("Drop data from a database"),
Long: dropLong,
Example: dropExample,
Run: func(cmd *cobra.Command, args []string) {},
DisableFlagsInUseLine: true,
DisableAutoGenTag: true,
}

cmd.AddCommand(data.DropRedisDataCMD(f))

return cmd
}
6 changes: 6 additions & 0 deletions pkg/cmds/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ func NewKubeDBCommand(in io.Reader, out, err io.Writer) *cobra.Command {
NewCmdExec(f),
},
},
{
Message: "Insert and Verify data in Database",
Commands: []*cobra.Command{
NewCmdData(f),
},
},
}

filters := []string{"options"}
Expand Down
2 changes: 1 addition & 1 deletion pkg/connect/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func (opts *redisOpts) getShellCommand(kubectlFlags, redisExtraFlags []interface
db := opts.db
svcName := fmt.Sprintf("svc/%s", db.Name)
kubectlCommand := []interface{}{
"exec", "-n", db.Namespace, svcName,
"exec", "-n", db.Namespace, svcName, "-c", "redis",
}
kubectlCommand = append(kubectlCommand, kubectlFlags...)

Expand Down
17 changes: 17 additions & 0 deletions pkg/data/elasticsearch.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
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 data
17 changes: 17 additions & 0 deletions pkg/data/mysql.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
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 data
17 changes: 17 additions & 0 deletions pkg/data/postgres.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
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 data
Loading
Loading