Skip to content

Commit

Permalink
Merge pull request #5 from gkarthiks/feat/discover-pods
Browse files Browse the repository at this point in the history
feat: go modules for discovering pods
  • Loading branch information
gkarthiks authored Jul 27, 2020
2 parents c260213 + 3ae0cf6 commit d99d119
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions helper/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,25 @@ const (
func GetVaultIPsFromLabelSelectors(labelSelectors string) {
if len(labelSelectors) > 0 {
strings.Split(labelSelectors, ",")
pods, err := globals.K8s.Clientset.CoreV1().Pods(globals.Namespace).List(context.Background(), metaV1.ListOptions{
LabelSelector: strings.TrimSpace(labelSelectors),
})
if err != nil {
log.Fatalf("err while retrieving the pods: %v", err)
} else {
globals.VaultIPList = append(globals.VaultIPList, fetchIpAddress(pods)...)
go discoverIPs(labelSelectors)
}
}

func discoverIPs(labelSelectors string){
t := time.NewTicker(time.Second * 30)
for {
select {
case <-t.C:
log.Infof("Discovering pods with label selector...")
pods, err := globals.K8s.Clientset.CoreV1().Pods(globals.Namespace).List(context.Background(), metaV1.ListOptions{
LabelSelector: strings.TrimSpace(labelSelectors),
})
if err != nil {
log.Fatalf("err while retrieving the pods: %v", err)
} else {
globals.VaultIPList = append(globals.VaultIPList, fetchIpAddress(pods)...)
}
log.Infof("Finalized pods discovery process with label selector...")
}
}
}
Expand Down

0 comments on commit d99d119

Please sign in to comment.