Skip to content

Commit d833e67

Browse files
committed
etcd: enable retrieving all services
Signed-off-by: Elis Lulja <[email protected]>
1 parent 1beea42 commit d833e67

File tree

3 files changed

+4
-19
lines changed

3 files changed

+4
-19
lines changed

pkg/cmd/watch/etcd/utils.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,8 @@ import (
3232

3333
func sanitizeLocalhost(host string, mode string) (string, error) {
3434
_host := host
35-
if strings.HasPrefix(_host, "https://") {
36-
_host = _host[len("https://"):]
37-
}
38-
if strings.HasPrefix(_host, "http://") {
39-
_host = _host[len("http://"):]
40-
}
41-
35+
_host = strings.TrimPrefix(_host, "https:")
36+
_host = strings.TrimPrefix(_host, "http:")
4237
_host = strings.Trim(_host, "/")
4338

4439
if len(_host) == 0 {
@@ -107,7 +102,7 @@ func parseFlags(cmd *cobra.Command) (*Options, error) {
107102
_keys, _ := cmd.Flags().GetStringSlice("metadata-keys")
108103
switch l := len(_keys); {
109104
case l == 0:
110-
return nil, fmt.Errorf("no metadata keys provided")
105+
// nothing to do... allow to take all metadata
111106
case l > 1:
112107
log.Warn().Msg("multiple metadata keys are not supported yet, only the first one will be used")
113108
fallthrough
@@ -210,9 +205,6 @@ func createOpenapiEvent(endp *opsr.Endpoint, srv *opsr.Service, eventType string
210205
}
211206

212207
func mapContainsKeys(subject map[string]string, targets []string) bool {
213-
// TODO: this will be useful for other commands as well, so it will be
214-
// put in a sort of utils package
215-
216208
foundKeys := 0
217209
for _, targetKey := range targets {
218210
if _, exists := subject[targetKey]; exists {

pkg/cmd/watch/etcd/utils_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,6 @@ func TestParseFlags(t *testing.T) {
126126
expRes *Options
127127
expErr error
128128
}{
129-
{
130-
cmd: func() *cobra.Command {
131-
return GetEtcdCommand()
132-
}(),
133-
expErr: fmt.Errorf("no metadata keys provided"),
134-
},
135129
{
136130
cmd: func() *cobra.Command {
137131
c := GetEtcdCommand()

pkg/cmd/watch/etcd/watcher.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import (
3232

3333
type etcdWatcher struct {
3434
options *Options
35-
keys []string
3635
cli *clientv3.Client
3736
kv clientv3.KV
3837
watcher clientv3.Watcher
@@ -104,7 +103,7 @@ func (e *etcdWatcher) parseEndpointAndCreateEvent(kvpair *mvccpb.KeyValue, event
104103
return nil, err
105104
}
106105

107-
if !mapContainsKeys(srv.Metadata, e.options.targetKeys) {
106+
if len(e.options.targetKeys) > 0 && !mapContainsKeys(srv.Metadata, e.options.targetKeys) {
108107
l.Info().Msg("endpoint's parent service doesn't have target metadata keys: skipping...")
109108
return nil, nil
110109
}

0 commit comments

Comments
 (0)