Skip to content
This repository was archived by the owner on Jan 16, 2023. It is now read-only.

Commit 3c2f6b0

Browse files
Make etcd token a full URL (#23)
1 parent 790ab7f commit 3c2f6b0

File tree

3 files changed

+11
-16
lines changed

3 files changed

+11
-16
lines changed

pkg/config/config.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package config
22

33
import (
44
"io/ioutil"
5-
"log"
65

76
"github.com/kelseyhightower/envconfig"
87
"github.com/logicmonitor/k8s-argus/pkg/constants"
@@ -45,7 +44,7 @@ func GetConfig() (*Config, error) {
4544

4645
err = envconfig.Process("argus", c)
4746
if err != nil {
48-
log.Fatal(err.Error())
47+
return nil, err
4948
}
5049

5150
return c, nil

pkg/etcd/etcd.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"io/ioutil"
66
"net/http"
77
"net/url"
8-
"path"
98
"strings"
109

1110
"github.com/logicmonitor/k8s-argus/pkg/types"
@@ -17,9 +16,6 @@ import (
1716
log "github.com/sirupsen/logrus"
1817
)
1918

20-
// PublicDiscoveryEndpoint is the official CoreOS discovery service.
21-
const PublicDiscoveryEndpoint = "discovery.etcd.io"
22-
2319
// Controller is the etcd controller for discovering etcd nodes.
2420
type Controller struct {
2521
*types.Base
@@ -34,7 +30,7 @@ type Member struct {
3430
// DiscoverByToken discovers the etcd node IP addresses using the etcd discovery service.
3531
func (c *Controller) DiscoverByToken() ([]*Member, error) {
3632
members := []*Member{}
37-
response, err := http.Get("https://" + path.Join(PublicDiscoveryEndpoint, c.Config.EtcdDiscoveryToken))
33+
response, err := http.Get(c.Config.EtcdDiscoveryToken)
3834
if err != nil {
3935
return nil, err
4036
}

pkg/watch/namespace/namespace.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"github.com/logicmonitor/k8s-argus/pkg/constants"
77
"github.com/logicmonitor/k8s-argus/pkg/types"
88
lm "github.com/logicmonitor/lm-sdk-go"
9-
"github.com/sirupsen/logrus"
9+
log "github.com/sirupsen/logrus"
1010
"k8s.io/client-go/pkg/api/v1"
1111
"k8s.io/client-go/pkg/runtime"
1212
)
@@ -48,18 +48,18 @@ func (w Watcher) AddFunc() func(obj interface{}) {
4848

4949
parentDeviceGroup, err := w.findDeviceGroup(parentID)
5050
if err != nil {
51-
logrus.Errorf("Failed to find namespace: %v", err)
51+
log.Errorf("Failed to find namespace: %v", err)
5252

5353
return
5454
}
5555
_, err = w.createDeviceGroup(namespace.Name, appliesTo, parentDeviceGroup.Id)
5656
if err != nil {
57-
logrus.Errorf("Failed to add namespace: %v", err)
57+
log.Errorf("Failed to add namespace: %v", err)
5858

5959
return
6060
}
6161

62-
logrus.Printf("Added namespace %s", namespace.Name)
62+
log.Printf("Added namespace %s", namespace.Name)
6363
}
6464
}
6565
}
@@ -79,15 +79,15 @@ func (w Watcher) DeleteFunc() func(obj interface{}) {
7979
for name, parentID := range w.DeviceGroups {
8080
deviceGroup, err := w.findDeviceGroup(parentID)
8181
if err != nil {
82-
logrus.Printf("Failed to find namespace %s: %v", name, err)
82+
log.Printf("Failed to find namespace %s: %v", name, err)
8383

8484
return
8585
}
8686
for _, subGroup := range deviceGroup.SubGroups {
8787
if subGroup.Name == namespace.Name {
8888
restResponse, apiResponse, err := w.LMClient.DeleteDeviceGroupById(subGroup.Id, true)
8989
if _err := utilities.CheckAllErrors(restResponse, apiResponse, err); _err != nil {
90-
logrus.Errorf("Failed to delete namespace %q: %v", subGroup.Name, _err)
90+
log.Errorf("Failed to delete namespace %q: %v", subGroup.Name, _err)
9191

9292
return
9393
}
@@ -100,13 +100,13 @@ func (w Watcher) DeleteFunc() func(obj interface{}) {
100100
func (w *Watcher) findDeviceGroup(parentID int32) (deviceGroup *lm.RestDeviceGroup, err error) {
101101
restResponse, apiResponse, err := w.LMClient.GetDeviceGroupById(parentID, "")
102102
if _err := utilities.CheckAllErrors(restResponse, apiResponse, err); _err != nil {
103-
logrus.Errorf("Failed to find namespace: %v", _err)
103+
log.Errorf("Failed to find namespace: %v", _err)
104104

105105
return
106106
}
107107

108108
deviceGroup = &restResponse.Data
109-
logrus.Debugf("%#v", restResponse)
109+
log.Debugf("%#v", restResponse)
110110

111111
return
112112
}
@@ -120,7 +120,7 @@ func (w *Watcher) createDeviceGroup(name, appliesTo string, parentID int32) (dev
120120
DisableAlerting: w.Config.DisableAlerting,
121121
})
122122
if _err := utilities.CheckAllErrors(restResponse, apiResponse, err); _err != nil {
123-
logrus.Errorf("Failed to add namespace %q: %v", name, _err)
123+
log.Errorf("Failed to add namespace %q: %v", name, _err)
124124

125125
return
126126
}

0 commit comments

Comments
 (0)