Skip to content

Commit

Permalink
Ignore vips suffixed with digit
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaz committed Mar 27, 2019
1 parent b3f4dbb commit f022f8f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
11 changes: 9 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"os/signal"
"path/filepath"
"regexp"
"strings"
"sync"
"syscall"
Expand Down Expand Up @@ -133,7 +134,7 @@ func runDiscovery(parentCtx context.Context, config *Config, networks []string)
if network == "" {
continue
}
i = i + discoverNetwork(network, job, exporter)
i += discoverNetwork(network, job, exporter)
}
count <- i
}()
Expand Down Expand Up @@ -177,6 +178,12 @@ func runDiscovery(parentCtx context.Context, config *Config, networks []string)
//func calculateIps(network string) []string{
//}

var vipRegexp = regexp.MustCompile(`^.+-vip(\d+)?\.`)

func isVip(name string) bool {
return vipRegexp.MatchString(name)
}

func discoverNetwork(network string, queue chan func(), exporter chan *Address) int64 {
networkip, ipnet, err := net.ParseCIDR(network)
if err != nil {
Expand Down Expand Up @@ -205,7 +212,7 @@ func discoverNetwork(network string, queue chan func(), exporter chan *Address)
exporter <- nil
return
}
if strings.Contains(hostname, "-vip.") {
if isVip(hostname) {
logrus.Info("skipping vip ", hostname, ip)
exporter <- nil
return
Expand Down
16 changes: 16 additions & 0 deletions vip_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package main

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestIsVipMatch(t *testing.T) {

assert.Equal(t, true, isVip("asdf-internal-vip.asdf.com"))
assert.Equal(t, true, isVip("dev-ssl-vip2.asdf.com"))
assert.Equal(t, false, isVip("dev-ssl-vipp01.asdf.com"))
assert.Equal(t, false, isVip("dev-ssl-vipp.asdf.com"))

}

0 comments on commit f022f8f

Please sign in to comment.