Skip to content

Commit

Permalink
use const
Browse files Browse the repository at this point in the history
Signed-off-by: Arnob kumar saha <[email protected]>
  • Loading branch information
ArnobKumarSaha committed Nov 2, 2023
1 parent d577de2 commit 8e5dd71
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions pkg/alerts/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ type dbOpts struct {
resource string
}

const (
kubeDBGroup = "kubedb.com"
kubeDBVersion = "v1alpha2"
)

func Run(f cmdutil.Factory, args []string, prom PromSvc) {
if len(args) < 2 {
log.Fatal("Enter db object's name as an argument")
Expand All @@ -71,7 +76,10 @@ func Run(f cmdutil.Factory, args []string, prom PromSvc) {
if err != nil {
log.Fatalln(err)
}
opts.work(p)
err = opts.work(p)
if err != nil {
log.Fatalln(err)
}
}

func convertedResource(resource string) string {
Expand Down Expand Up @@ -104,10 +112,10 @@ func newDBOpts(f cmdutil.Factory, dbName, namespace, resource string) (*dbOpts,

dc, err := dynamic.NewForConfig(config)
if err != nil {
panic(err)
return nil, err
}

dbRes := schema.GroupVersionResource{Group: "kubedb.com", Version: "v1alpha2", Resource: resource}
dbRes := schema.GroupVersionResource{Group: kubeDBGroup, Version: kubeDBVersion, Resource: resource}
db, err := dc.Resource(dbRes).Namespace(namespace).Get(context.TODO(), dbName, metav1.GetOptions{})
if err != nil {
return nil, err
Expand Down Expand Up @@ -143,12 +151,12 @@ func (opts *dbOpts) ForwardPort(resource string, prom PromSvc) (*portforward.Tun
return tunnel, nil
}

func (opts *dbOpts) work(p *portforward.Tunnel) {
func (opts *dbOpts) work(p *portforward.Tunnel) error {
pc, err := promapi.NewClient(promapi.Config{
Address: fmt.Sprintf("http://localhost:%d", p.Local),
})
if err != nil {
panic(err)
return err
}

promAPI := promv1.NewAPI(pc)
Expand All @@ -160,7 +168,7 @@ func (opts *dbOpts) work(p *portforward.Tunnel) {
Step: time.Minute * 2,
})
if err != nil {
panic(err)
return err
}
if len(warnings) > 0 {
fmt.Println("Warnings:", warnings)
Expand All @@ -175,4 +183,5 @@ func (opts *dbOpts) work(p *portforward.Tunnel) {
labels := sample.Metric
fmt.Printf("Alert Name: %s, Value: %s, Labels: %s\n", alertName, alertValue, labels)
}
return nil
}

0 comments on commit 8e5dd71

Please sign in to comment.