mirror of
https://github.com/zalando/postgres-operator.git
synced 2026-10-04 19:30:07 +02:00
Fix the golint, gosimple warnings
This commit is contained in:
@@ -23,9 +23,9 @@ type Resources struct {
|
||||
ClusterLabels map[string]string `name:"cluster_labels" default:"application:spilo"`
|
||||
ClusterNameLabel string `name:"cluster_name_label" default:"cluster-name"`
|
||||
PodRoleLabel string `name:"pod_role_label" default:"spilo-role"`
|
||||
DefaultCpuRequest string `name:"default_cpu_request" default:"100m"`
|
||||
DefaultCPURequest string `name:"default_cpu_request" default:"100m"`
|
||||
DefaultMemoryRequest string `name:"default_memory_request" default:"100Mi"`
|
||||
DefaultCpuLimit string `name:"default_cpu_limit" default:"3"`
|
||||
DefaultCPULimit string `name:"default_cpu_limit" default:"3"`
|
||||
DefaultMemoryLimit string `name:"default_memory_limit" default:"1Gi"`
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ package constants
|
||||
import "time"
|
||||
|
||||
const (
|
||||
//Constants
|
||||
TPRName = "postgresql"
|
||||
TPRVendor = "acid.zalan.do"
|
||||
TPRDescription = "Managed PostgreSQL clusters"
|
||||
@@ -11,11 +10,11 @@ const (
|
||||
ListClustersURITemplate = "/apis/" + TPRVendor + "/" + TPRApiVersion + "/namespaces/%s/" + ResourceName // Namespace
|
||||
WatchClustersURITemplate = "/apis/" + TPRVendor + "/" + TPRApiVersion + "/watch/namespaces/%s/" + ResourceName // Namespace
|
||||
K8sVersion = "v1"
|
||||
K8sApiPath = "/api"
|
||||
K8sAPIPath = "/api"
|
||||
DataVolumeName = "pgdata"
|
||||
PasswordLength = 64
|
||||
UserSecretTemplate = "%s.%s.credentials." + TPRName + "." + TPRVendor // Username, ClusterName
|
||||
ZalandoDnsNameAnnotation = "external-dns.alpha.kubernetes.io/hostname"
|
||||
ZalandoDNSNameAnnotation = "external-dns.alpha.kubernetes.io/hostname"
|
||||
ElbTimeoutAnnotationName = "service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout"
|
||||
ElbTimeoutAnnotationValue = "3600"
|
||||
KubeIAmAnnotation = "iam.amazonaws.com/role"
|
||||
|
||||
@@ -39,7 +39,7 @@ func ResourceNotFound(err error) bool {
|
||||
|
||||
func KubernetesRestClient(c *rest.Config) (*rest.RESTClient, error) {
|
||||
c.GroupVersion = &unversioned.GroupVersion{Version: constants.K8sVersion}
|
||||
c.APIPath = constants.K8sApiPath
|
||||
c.APIPath = constants.K8sAPIPath
|
||||
c.NegotiatedSerializer = serializer.DirectCodecFactory{CodecFactory: api.Codecs}
|
||||
|
||||
schemeBuilder := runtime.NewSchemeBuilder(
|
||||
|
||||
+11
-11
@@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
type InfrastructureAccount struct {
|
||||
Id string `json:"id"`
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Provider string `json:"provider"`
|
||||
Type string `json:"type"`
|
||||
@@ -22,9 +22,9 @@ type InfrastructureAccount struct {
|
||||
|
||||
type Team struct {
|
||||
Dn string `json:"dn"`
|
||||
Id string `json:"id"`
|
||||
ID string `json:"id"`
|
||||
TeamName string `json:"id_name"`
|
||||
TeamId string `json:"team_id"`
|
||||
TeamID string `json:"team_id"`
|
||||
Type string `json:"type"`
|
||||
FullName string `json:"name"`
|
||||
Aliases []string `json:"alias"`
|
||||
@@ -32,12 +32,12 @@ type Team struct {
|
||||
Members []string `json:"member"`
|
||||
CostCenter string `json:"cost_center"`
|
||||
DeliveryLead string `json:"delivery_lead"`
|
||||
ParentTeamId string `json:"parent_team_id"`
|
||||
ParentTeamID string `json:"parent_team_id"`
|
||||
|
||||
InfrastructureAccounts []InfrastructureAccount `json:"infrastructure-accounts"`
|
||||
}
|
||||
|
||||
type TeamsAPI struct {
|
||||
type API struct {
|
||||
url string
|
||||
httpClient *http.Client
|
||||
logger *logrus.Entry
|
||||
@@ -45,8 +45,8 @@ type TeamsAPI struct {
|
||||
enabled bool
|
||||
}
|
||||
|
||||
func NewTeamsAPI(url string, log *logrus.Logger, enabled bool) *TeamsAPI {
|
||||
t := TeamsAPI{
|
||||
func NewTeamsAPI(url string, log *logrus.Logger, enabled bool) *API {
|
||||
t := API{
|
||||
url: strings.TrimRight(url, "/"),
|
||||
httpClient: &http.Client{},
|
||||
logger: log.WithField("pkg", "teamsapi"),
|
||||
@@ -56,7 +56,7 @@ func NewTeamsAPI(url string, log *logrus.Logger, enabled bool) *TeamsAPI {
|
||||
return &t
|
||||
}
|
||||
|
||||
func (t *TeamsAPI) TeamInfo(teamId string) (*Team, error) {
|
||||
func (t *API) TeamInfo(teamID string) (*Team, error) {
|
||||
// TODO: avoid getting a new token on every call to the Teams API.
|
||||
if !t.enabled {
|
||||
t.logger.Debug("Team API is disabled, returning empty list of members")
|
||||
@@ -66,7 +66,7 @@ func (t *TeamsAPI) TeamInfo(teamId string) (*Team, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
url := fmt.Sprintf("%s/teams/%s", t.url, teamId)
|
||||
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 {
|
||||
@@ -89,9 +89,9 @@ func (t *TeamsAPI) TeamInfo(teamId string) (*Team, error) {
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("Team API query failed with status code %d", resp.StatusCode)
|
||||
}
|
||||
teamInfo := &Team{}
|
||||
d := json.NewDecoder(resp.Body)
|
||||
|
||||
@@ -28,7 +28,7 @@ func (s DefaultUserSyncStrategy) ProduceSyncRequests(dbUsers spec.PgUserMap,
|
||||
for name, newUser := range newUsers {
|
||||
dbUser, exists := dbUsers[name]
|
||||
if !exists {
|
||||
reqs = append(reqs, spec.PgSyncUserRequest{spec.PGSyncUserAdd, newUser})
|
||||
reqs = append(reqs, spec.PgSyncUserRequest{Kind: spec.PGSyncUserAdd, User: newUser})
|
||||
} else {
|
||||
r := spec.PgSyncUserRequest{}
|
||||
newMD5Password := util.PGUserPassword(newUser)
|
||||
@@ -67,7 +67,7 @@ func (s DefaultUserSyncStrategy) ExecuteSyncRequests(reqs []spec.PgSyncUserReque
|
||||
return fmt.Errorf("Can't alter user '%s': %s", r.User.Name, err)
|
||||
}
|
||||
default:
|
||||
return fmt.Errorf("Unrecognized operation: %s", r.Kind)
|
||||
return fmt.Errorf("Unrecognized operation: %v", r.Kind)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+3
-3
@@ -15,7 +15,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
MD5Prefix = "md5"
|
||||
md5prefix = "md5"
|
||||
)
|
||||
|
||||
var passwordChars = []byte("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
|
||||
@@ -41,12 +41,12 @@ func NameFromMeta(meta v1.ObjectMeta) spec.NamespacedName {
|
||||
}
|
||||
|
||||
func PGUserPassword(user spec.PgUser) string {
|
||||
if (len(user.Password) == md5.Size && user.Password[:3] == MD5Prefix) || user.Password == "" {
|
||||
if (len(user.Password) == md5.Size && user.Password[:3] == md5prefix) || user.Password == "" {
|
||||
// Avoid processing already encrypted or empty passwords
|
||||
return user.Password
|
||||
}
|
||||
s := md5.Sum([]byte(user.Password + user.Name))
|
||||
return MD5Prefix + hex.EncodeToString(s[:])
|
||||
return md5prefix + hex.EncodeToString(s[:])
|
||||
}
|
||||
|
||||
func Pretty(x interface{}) (f fmt.Formatter) {
|
||||
|
||||
Reference in New Issue
Block a user