mirror of
https://github.com/zalando/postgres-operator.git
synced 2026-09-30 21:50:01 +02:00
Better logging for teams api calls
This commit is contained in:
+4
-1
@@ -137,11 +137,14 @@ func (c *Cluster) logPodChanges(pod *v1.Pod, statefulset *v1beta1.StatefulSet, r
|
||||
}
|
||||
|
||||
func (c *Cluster) getTeamMembers() ([]string, error) {
|
||||
if c.Spec.TeamId == "" {
|
||||
return nil, fmt.Errorf("No teamId specified")
|
||||
}
|
||||
teamInfo, err := c.TeamsAPIClient.TeamInfo(c.Spec.TeamId)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Can't get team info: %s", err)
|
||||
}
|
||||
c.logger.Debugf("Got from the Team API: %v", teamInfo)
|
||||
c.logger.Debugf("Got from the Team API: %+v", *teamInfo)
|
||||
|
||||
return teamInfo.Members, nil
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ func New(controllerConfig *Config, operatorConfig *config.Config) *Controller {
|
||||
logger.Level = logrus.DebugLevel
|
||||
}
|
||||
|
||||
controllerConfig.TeamsAPIClient = teams.NewTeamsAPI(operatorConfig.TeamsAPIUrl, logger)
|
||||
return &Controller{
|
||||
Config: *controllerConfig,
|
||||
opConfig: operatorConfig,
|
||||
|
||||
@@ -27,6 +27,7 @@ func (c *Controller) getOAuthToken() (string, error) {
|
||||
credentialsSecret, err := c.KubeClient.Secrets(api.NamespaceDefault).Get(c.opConfig.OAuthTokenSecretName)
|
||||
|
||||
if err != nil {
|
||||
c.logger.Debugf("Oauth token secret name: %s", c.opConfig.OAuthTokenSecretName)
|
||||
return "", fmt.Errorf("Can't get credentials Secret: %s", err)
|
||||
}
|
||||
data := credentialsSecret.Data
|
||||
|
||||
+21
-4
@@ -1,10 +1,12 @@
|
||||
package teams
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
)
|
||||
|
||||
type InfrastructureAccount struct {
|
||||
@@ -38,13 +40,15 @@ type Team struct {
|
||||
type TeamsAPI struct {
|
||||
url string
|
||||
httpClient *http.Client
|
||||
logger *logrus.Entry
|
||||
RefreshTokenAction func() (string, error)
|
||||
}
|
||||
|
||||
func NewTeamsAPI(url string) *TeamsAPI {
|
||||
func NewTeamsAPI(url string, log *logrus.Logger) *TeamsAPI {
|
||||
t := TeamsAPI{
|
||||
url: strings.TrimRight(url, "/"),
|
||||
httpClient: &http.Client{},
|
||||
logger: log.WithField("pkg", "teamsapi"),
|
||||
}
|
||||
|
||||
return &t
|
||||
@@ -57,6 +61,7 @@ func (t *TeamsAPI) TeamInfo(teamId string) (*Team, error) {
|
||||
return nil, err
|
||||
}
|
||||
url := fmt.Sprintf("%s/teams/%s", t.url, teamId)
|
||||
t.logger.Debugf("Request url: %s", url)
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -67,9 +72,21 @@ func (t *TeamsAPI) TeamInfo(teamId string) (*Team, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode != 200 {
|
||||
var raw map[string]json.RawMessage
|
||||
d := json.NewDecoder(resp.Body)
|
||||
err = d.Decode(&raw)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if errMessage, ok := raw["error"]; ok {
|
||||
return nil, fmt.Errorf("Team API query failed with status code %d and message: '%s'", resp.StatusCode, string(errMessage))
|
||||
} else {
|
||||
return nil, fmt.Errorf("Team API query failed with status code %d", resp.StatusCode)
|
||||
}
|
||||
}
|
||||
teamInfo := &Team{}
|
||||
d := json.NewDecoder(resp.Body)
|
||||
err = d.Decode(teamInfo)
|
||||
|
||||
Reference in New Issue
Block a user