handle errors when working with rancher
This commit is contained in:
parent
6ea9c4dd3f
commit
06905cb14a
1 changed files with 40 additions and 21 deletions
|
@ -71,9 +71,18 @@ func (p *Provider) apiProvide(configurationChan chan<- types.ConfigMessage, pool
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
var stacks = listRancherStacks(rancherClient)
|
stacks, err := listRancherStacks(rancherClient)
|
||||||
var services = listRancherServices(rancherClient)
|
if err != nil {
|
||||||
var container = listRancherContainer(rancherClient)
|
return err
|
||||||
|
}
|
||||||
|
services, err := listRancherServices(rancherClient)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
container, err := listRancherContainer(rancherClient)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
var rancherData = parseAPISourcedRancherData(stacks, services, container)
|
var rancherData = parseAPISourcedRancherData(stacks, services, container)
|
||||||
|
|
||||||
|
@ -94,11 +103,21 @@ func (p *Provider) apiProvide(configurationChan chan<- types.ConfigMessage, pool
|
||||||
|
|
||||||
if errAPI != nil {
|
if errAPI != nil {
|
||||||
log.Errorf("Cannot establish connection: %+v, Rancher API return: %+v; Skipping refresh Data from Rancher API.", errAPI, checkAPI)
|
log.Errorf("Cannot establish connection: %+v, Rancher API return: %+v; Skipping refresh Data from Rancher API.", errAPI, checkAPI)
|
||||||
} else {
|
continue
|
||||||
|
}
|
||||||
log.Debugf("Refreshing new Data from Rancher API")
|
log.Debugf("Refreshing new Data from Rancher API")
|
||||||
stacks := listRancherStacks(rancherClient)
|
stacks, err = listRancherStacks(rancherClient)
|
||||||
services := listRancherServices(rancherClient)
|
if err != nil {
|
||||||
container := listRancherContainer(rancherClient)
|
continue
|
||||||
|
}
|
||||||
|
services, err = listRancherServices(rancherClient)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
container, err = listRancherContainer(rancherClient)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
rancherData := parseAPISourcedRancherData(stacks, services, container)
|
rancherData := parseAPISourcedRancherData(stacks, services, container)
|
||||||
|
|
||||||
|
@ -109,7 +128,6 @@ func (p *Provider) apiProvide(configurationChan chan<- types.ConfigMessage, pool
|
||||||
Configuration: configuration,
|
Configuration: configuration,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
case <-stop:
|
case <-stop:
|
||||||
ticker.Stop()
|
ticker.Stop()
|
||||||
cancel()
|
cancel()
|
||||||
|
@ -133,7 +151,7 @@ func (p *Provider) apiProvide(configurationChan chan<- types.ConfigMessage, pool
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func listRancherStacks(client *rancher.RancherClient) []*rancher.Stack {
|
func listRancherStacks(client *rancher.RancherClient) ([]*rancher.Stack, error) {
|
||||||
|
|
||||||
var stackList []*rancher.Stack
|
var stackList []*rancher.Stack
|
||||||
|
|
||||||
|
@ -147,10 +165,10 @@ func listRancherStacks(client *rancher.RancherClient) []*rancher.Stack {
|
||||||
stackList = append(stackList, &stacks.Data[k])
|
stackList = append(stackList, &stacks.Data[k])
|
||||||
}
|
}
|
||||||
|
|
||||||
return stackList
|
return stackList, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func listRancherServices(client *rancher.RancherClient) []*rancher.Service {
|
func listRancherServices(client *rancher.RancherClient) ([]*rancher.Service, error) {
|
||||||
|
|
||||||
var servicesList []*rancher.Service
|
var servicesList []*rancher.Service
|
||||||
|
|
||||||
|
@ -164,10 +182,10 @@ func listRancherServices(client *rancher.RancherClient) []*rancher.Service {
|
||||||
servicesList = append(servicesList, &services.Data[k])
|
servicesList = append(servicesList, &services.Data[k])
|
||||||
}
|
}
|
||||||
|
|
||||||
return servicesList
|
return servicesList, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func listRancherContainer(client *rancher.RancherClient) []*rancher.Container {
|
func listRancherContainer(client *rancher.RancherClient) ([]*rancher.Container, error) {
|
||||||
|
|
||||||
var containerList []*rancher.Container
|
var containerList []*rancher.Container
|
||||||
|
|
||||||
|
@ -175,6 +193,7 @@ func listRancherContainer(client *rancher.RancherClient) []*rancher.Container {
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Cannot get Provider Services %+v", err)
|
log.Errorf("Cannot get Provider Services %+v", err)
|
||||||
|
return containerList, err
|
||||||
}
|
}
|
||||||
|
|
||||||
valid := true
|
valid := true
|
||||||
|
@ -195,7 +214,7 @@ func listRancherContainer(client *rancher.RancherClient) []*rancher.Container {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return containerList
|
return containerList, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseAPISourcedRancherData(stacks []*rancher.Stack, services []*rancher.Service, containers []*rancher.Container) []rancherData {
|
func parseAPISourcedRancherData(stacks []*rancher.Stack, services []*rancher.Service, containers []*rancher.Container) []rancherData {
|
||||||
|
|
Loading…
Reference in a new issue