mirror of
https://github.com/zalando/postgres-operator.git
synced 2026-10-18 03:28:00 +02:00
Fix golint warnings
This commit is contained in:
@@ -8,12 +8,14 @@ import (
|
||||
"github.com/zalando-incubator/postgres-operator/pkg/spec"
|
||||
)
|
||||
|
||||
// TPR describes ThirdPartyResource specific configuration parameters
|
||||
type TPR struct {
|
||||
ReadyWaitInterval time.Duration `name:"ready_wait_interval" default:"4s"`
|
||||
ReadyWaitTimeout time.Duration `name:"ready_wait_timeout" default:"30s"`
|
||||
ResyncPeriod time.Duration `name:"resync_period" default:"5m"`
|
||||
}
|
||||
|
||||
// Resources describes kubernetes resource specific configuration parameters
|
||||
type Resources struct {
|
||||
ResourceCheckInterval time.Duration `name:"resource_check_interval" default:"3s"`
|
||||
ResourceCheckTimeout time.Duration `name:"resource_check_timeout" default:"10m"`
|
||||
@@ -28,6 +30,7 @@ type Resources struct {
|
||||
DefaultMemoryLimit string `name:"default_memory_limit" default:"1Gi"`
|
||||
}
|
||||
|
||||
// Auth describes authentication specific configuration parameters
|
||||
type Auth struct {
|
||||
PamRoleName string `name:"pam_rol_name" default:"zalandos"`
|
||||
PamConfiguration string `name:"pam_configuration" default:"https://info.example.com/oauth2/tokeninfo?access_token= uid realm=/employees"`
|
||||
@@ -38,6 +41,7 @@ type Auth struct {
|
||||
ReplicationUsername string `name:"replication_username" default:"replication"`
|
||||
}
|
||||
|
||||
// Config describes operator config
|
||||
type Config struct {
|
||||
TPR
|
||||
Resources
|
||||
@@ -59,6 +63,7 @@ type Config struct {
|
||||
Workers uint32 `name:"workers" default:"4"`
|
||||
}
|
||||
|
||||
// MustMarshal marshals the config or panics
|
||||
func (c Config) MustMarshal() string {
|
||||
b, err := json.MarshalIndent(c, "", "\t")
|
||||
if err != nil {
|
||||
@@ -68,6 +73,7 @@ func (c Config) MustMarshal() string {
|
||||
return string(b)
|
||||
}
|
||||
|
||||
// NewFromMap creates Config from the map
|
||||
func NewFromMap(m map[string]string) *Config {
|
||||
cfg := Config{}
|
||||
fields, _ := structFields(&cfg)
|
||||
@@ -91,6 +97,7 @@ func NewFromMap(m map[string]string) *Config {
|
||||
return &cfg
|
||||
}
|
||||
|
||||
// Copy creates a copy of the config
|
||||
func Copy(c *Config) Config {
|
||||
cfg := *c
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import "time"
|
||||
// AWS specific constants used by other modules
|
||||
const (
|
||||
// default region for AWS. TODO: move it to the operator configuration
|
||||
AWS_REGION = "eu-central-1"
|
||||
AWSRegion = "eu-central-1"
|
||||
// EBS related constants
|
||||
EBSVolumeIDStart = "/vol-"
|
||||
EBSProvisioner = "kubernetes.io/aws-ebs"
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package constants
|
||||
|
||||
// PostgreSQL specific constants
|
||||
const (
|
||||
DataVolumeName = "pgdata"
|
||||
PodRoleMaster = "master"
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package constants
|
||||
|
||||
// Roles specific constants
|
||||
const (
|
||||
PasswordLength = 64
|
||||
UserSecretTemplate = "%s.%s.credentials." + TPRKind + "." + TPRGroup // Username, ClusterName
|
||||
|
||||
@@ -17,7 +17,7 @@ const (
|
||||
resize2fs = "resize2fs"
|
||||
)
|
||||
|
||||
// Ext234Resize implements the FilesystemResizer interface for the ext4/3/2fs.
|
||||
//Ext234Resize implements the FilesystemResizer interface for the ext4/3/2fs.
|
||||
type Ext234Resize struct {
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package filesystems
|
||||
|
||||
// FilesystemResizer has methods to work with resizing of a filesystem
|
||||
type FilesystemResizer interface {
|
||||
CanResizeFilesystem(fstype string) bool
|
||||
ResizeFilesystem(deviceName string, commandExecutor func(string) (out string, err error)) error
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
"github.com/zalando-incubator/postgres-operator/pkg/util/retryutil"
|
||||
)
|
||||
|
||||
// KubernetesClient describes getters for Kubernetes objects
|
||||
type KubernetesClient struct {
|
||||
v1core.SecretsGetter
|
||||
v1core.ServicesGetter
|
||||
@@ -31,6 +32,7 @@ type KubernetesClient struct {
|
||||
RESTClient rest.Interface
|
||||
}
|
||||
|
||||
// NewFromKubernetesInterface creates KubernetesClient from kubernetes Interface
|
||||
func NewFromKubernetesInterface(src kubernetes.Interface) (c KubernetesClient) {
|
||||
c = KubernetesClient{}
|
||||
c.PodsGetter = src.CoreV1()
|
||||
@@ -46,6 +48,7 @@ func NewFromKubernetesInterface(src kubernetes.Interface) (c KubernetesClient) {
|
||||
return
|
||||
}
|
||||
|
||||
// RestConfig creates REST config
|
||||
func RestConfig(kubeConfig string, outOfCluster bool) (*rest.Config, error) {
|
||||
if outOfCluster {
|
||||
return clientcmd.BuildConfigFromFlags("", kubeConfig)
|
||||
@@ -54,18 +57,22 @@ func RestConfig(kubeConfig string, outOfCluster bool) (*rest.Config, error) {
|
||||
return rest.InClusterConfig()
|
||||
}
|
||||
|
||||
// ClientSet creates clientset using REST config
|
||||
func ClientSet(config *rest.Config) (client *kubernetes.Clientset, err error) {
|
||||
return kubernetes.NewForConfig(config)
|
||||
}
|
||||
|
||||
// ResourceAlreadyExists checks if error corresponds to Already exists error
|
||||
func ResourceAlreadyExists(err error) bool {
|
||||
return apierrors.IsAlreadyExists(err)
|
||||
}
|
||||
|
||||
// ResourceNotFound checks if error corresponds to Not found error
|
||||
func ResourceNotFound(err error) bool {
|
||||
return apierrors.IsNotFound(err)
|
||||
}
|
||||
|
||||
// KubernetesRestClient create kubernets Interface using REST config
|
||||
func KubernetesRestClient(cfg rest.Config) (rest.Interface, error) {
|
||||
cfg.GroupVersion = &schema.GroupVersion{
|
||||
Group: constants.TPRGroup,
|
||||
@@ -77,6 +84,7 @@ func KubernetesRestClient(cfg rest.Config) (rest.Interface, error) {
|
||||
return rest.RESTClientFor(&cfg)
|
||||
}
|
||||
|
||||
// WaitTPRReady waits until ThirdPartyResource is ready
|
||||
func WaitTPRReady(restclient rest.Interface, interval, timeout time.Duration, ns string) error {
|
||||
return retryutil.Retry(interval, timeout, func() (bool, error) {
|
||||
_, err := restclient.
|
||||
|
||||
@@ -5,10 +5,8 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type ConditionFunc func() (bool, error)
|
||||
|
||||
// Retry calls ConditionFunc until it returns boolean true, a timeout expires or an error occurs.
|
||||
func Retry(interval time.Duration, timeout time.Duration, f ConditionFunc) error {
|
||||
func Retry(interval time.Duration, timeout time.Duration, f func() (bool, error)) error {
|
||||
//TODO: make the retry exponential
|
||||
if timeout < interval {
|
||||
return fmt.Errorf("timout(%s) should be greater than interval(%v)", timeout, interval)
|
||||
|
||||
@@ -22,7 +22,7 @@ type infrastructureAccount struct {
|
||||
}
|
||||
|
||||
// Team defines informaiton for a single team, including the list of members and infrastructure accounts.
|
||||
type team struct {
|
||||
type Team struct {
|
||||
Dn string `json:"dn"`
|
||||
ID string `json:"id"`
|
||||
TeamName string `json:"id_name"`
|
||||
@@ -43,6 +43,7 @@ type httpClient interface {
|
||||
Do(req *http.Request) (*http.Response, error)
|
||||
}
|
||||
|
||||
// API describes teams API
|
||||
type API struct {
|
||||
httpClient
|
||||
url string
|
||||
@@ -61,7 +62,7 @@ func NewTeamsAPI(url string, log *logrus.Logger) *API {
|
||||
}
|
||||
|
||||
// TeamInfo returns information about a given team using its ID and a token to authenticate to the API service.
|
||||
func (t *API) TeamInfo(teamID, token string) (tm *team, err error) {
|
||||
func (t *API) TeamInfo(teamID, token string) (tm *Team, err error) {
|
||||
var (
|
||||
req *http.Request
|
||||
resp *http.Response
|
||||
@@ -103,7 +104,7 @@ func (t *API) TeamInfo(teamID, token string) (tm *team, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
tm = &team{}
|
||||
tm = &Team{}
|
||||
d := json.NewDecoder(resp.Body)
|
||||
err = d.Decode(tm)
|
||||
if err != nil {
|
||||
|
||||
@@ -18,7 +18,7 @@ var (
|
||||
var teamsAPItc = []struct {
|
||||
in string
|
||||
inCode int
|
||||
out *team
|
||||
out *Team
|
||||
err error
|
||||
}{
|
||||
{`{
|
||||
@@ -67,7 +67,7 @@ var teamsAPItc = []struct {
|
||||
"parent_team_id": "111221"
|
||||
}`,
|
||||
200,
|
||||
&team{
|
||||
&Team{
|
||||
Dn: "cn=100100,ou=official,ou=foobar,dc=zalando,dc=net",
|
||||
ID: "acid",
|
||||
TeamName: "ACID",
|
||||
@@ -169,7 +169,7 @@ func TestInfo(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
type mockHttpClient struct {
|
||||
type mockHTTPClient struct {
|
||||
}
|
||||
|
||||
type mockBody struct {
|
||||
@@ -183,7 +183,7 @@ func (b *mockBody) Close() error {
|
||||
return fmt.Errorf("close error")
|
||||
}
|
||||
|
||||
func (c *mockHttpClient) Do(req *http.Request) (*http.Response, error) {
|
||||
func (c *mockHTTPClient) Do(req *http.Request) (*http.Response, error) {
|
||||
resp := http.Response{
|
||||
Status: "200 OK",
|
||||
StatusCode: 200,
|
||||
@@ -200,7 +200,7 @@ func TestHttpClientClose(t *testing.T) {
|
||||
ts := httptest.NewServer(nil)
|
||||
|
||||
api := NewTeamsAPI(ts.URL, logger)
|
||||
api.httpClient = &mockHttpClient{}
|
||||
api.httpClient = &mockHTTPClient{}
|
||||
|
||||
_, err := api.TeamInfo("acid", token)
|
||||
expError := fmt.Errorf("error when closing response: close error")
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ const (
|
||||
var passwordChars = []byte("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
|
||||
|
||||
func init() {
|
||||
rand.Seed(int64(time.Now().Unix()))
|
||||
rand.Seed(time.Now().Unix())
|
||||
}
|
||||
|
||||
// RandomPassword generates random alphanumeric password of a given length.
|
||||
|
||||
+13
-12
@@ -7,10 +7,10 @@ import (
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/session"
|
||||
"github.com/aws/aws-sdk-go/service/ec2"
|
||||
"k8s.io/client-go/pkg/api/v1"
|
||||
|
||||
"github.com/zalando-incubator/postgres-operator/pkg/util/constants"
|
||||
"github.com/zalando-incubator/postgres-operator/pkg/util/retryutil"
|
||||
"k8s.io/client-go/pkg/api/v1"
|
||||
)
|
||||
|
||||
// EBSVolumeResizer implements volume resizing interface for AWS EBS volumes.
|
||||
@@ -20,7 +20,7 @@ type EBSVolumeResizer struct {
|
||||
|
||||
// ConnectToProvider connects to AWS.
|
||||
func (c *EBSVolumeResizer) ConnectToProvider() error {
|
||||
sess, err := session.NewSession(&aws.Config{Region: aws.String(constants.AWS_REGION)})
|
||||
sess, err := session.NewSession(&aws.Config{Region: aws.String(constants.AWSRegion)})
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not establish AWS session: %v", err)
|
||||
}
|
||||
@@ -52,21 +52,21 @@ func (c *EBSVolumeResizer) GetProviderVolumeID(pv *v1.PersistentVolume) (string,
|
||||
}
|
||||
|
||||
// ResizeVolume actually calls AWS API to resize the EBS volume if necessary.
|
||||
func (c *EBSVolumeResizer) ResizeVolume(volumeId string, newSize int64) error {
|
||||
func (c *EBSVolumeResizer) ResizeVolume(volumeID string, newSize int64) error {
|
||||
/* first check if the volume is already of a requested size */
|
||||
volumeOutput, err := c.connection.DescribeVolumes(&ec2.DescribeVolumesInput{VolumeIds: []*string{&volumeId}})
|
||||
volumeOutput, err := c.connection.DescribeVolumes(&ec2.DescribeVolumesInput{VolumeIds: []*string{&volumeID}})
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not get information about the volume: %v", err)
|
||||
}
|
||||
vol := volumeOutput.Volumes[0]
|
||||
if *vol.VolumeId != volumeId {
|
||||
return fmt.Errorf("describe volume %q returned information about a non-matching volume %q", volumeId, *vol.VolumeId)
|
||||
if *vol.VolumeId != volumeID {
|
||||
return fmt.Errorf("describe volume %q returned information about a non-matching volume %q", volumeID, *vol.VolumeId)
|
||||
}
|
||||
if *vol.Size == newSize {
|
||||
// nothing to do
|
||||
return nil
|
||||
}
|
||||
input := ec2.ModifyVolumeInput{Size: &newSize, VolumeId: &volumeId}
|
||||
input := ec2.ModifyVolumeInput{Size: &newSize, VolumeId: &volumeID}
|
||||
output, err := c.connection.ModifyVolume(&input)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not modify persistent volume: %v", err)
|
||||
@@ -74,7 +74,7 @@ func (c *EBSVolumeResizer) ResizeVolume(volumeId string, newSize int64) error {
|
||||
|
||||
state := *output.VolumeModification.ModificationState
|
||||
if state == constants.EBSVolumeStateFailed {
|
||||
return fmt.Errorf("could not modify persistent volume %q: modification state failed", volumeId)
|
||||
return fmt.Errorf("could not modify persistent volume %q: modification state failed", volumeID)
|
||||
}
|
||||
if state == "" {
|
||||
return fmt.Errorf("received empty modification status")
|
||||
@@ -83,7 +83,7 @@ func (c *EBSVolumeResizer) ResizeVolume(volumeId string, newSize int64) error {
|
||||
return nil
|
||||
}
|
||||
// wait until the volume reaches the "optimizing" or "completed" state
|
||||
in := ec2.DescribeVolumesModificationsInput{VolumeIds: []*string{&volumeId}}
|
||||
in := ec2.DescribeVolumesModificationsInput{VolumeIds: []*string{&volumeID}}
|
||||
return retryutil.Retry(constants.EBSVolumeResizeWaitInterval, constants.EBSVolumeResizeWaitTimeout,
|
||||
func() (bool, error) {
|
||||
out, err := c.connection.DescribeVolumesModifications(&in)
|
||||
@@ -91,16 +91,17 @@ func (c *EBSVolumeResizer) ResizeVolume(volumeId string, newSize int64) error {
|
||||
return false, fmt.Errorf("could not describe volume modification: %v", err)
|
||||
}
|
||||
if len(out.VolumesModifications) != 1 {
|
||||
return false, fmt.Errorf("describe volume modification didn't return one record for volume %q", volumeId)
|
||||
return false, fmt.Errorf("describe volume modification didn't return one record for volume %q", volumeID)
|
||||
}
|
||||
if *out.VolumesModifications[0].VolumeId != volumeId {
|
||||
if *out.VolumesModifications[0].VolumeId != volumeID {
|
||||
return false, fmt.Errorf("non-matching volume id when describing modifications: %q is different from %q",
|
||||
*out.VolumesModifications[0].VolumeId, volumeId)
|
||||
*out.VolumesModifications[0].VolumeId, volumeID)
|
||||
}
|
||||
return *out.VolumesModifications[0].ModificationState != constants.EBSVolumeStateModifying, nil
|
||||
})
|
||||
}
|
||||
|
||||
// DisconnectFromProvider closes connection to the EC2 instance
|
||||
func (c *EBSVolumeResizer) DisconnectFromProvider() error {
|
||||
c.connection = nil
|
||||
return nil
|
||||
|
||||
@@ -10,6 +10,6 @@ type VolumeResizer interface {
|
||||
IsConnectedToProvider() bool
|
||||
VolumeBelongsToProvider(pv *v1.PersistentVolume) bool
|
||||
GetProviderVolumeID(pv *v1.PersistentVolume) (string, error)
|
||||
ResizeVolume(providerVolumeId string, newSize int64) error
|
||||
ResizeVolume(providerVolumeID string, newSize int64) error
|
||||
DisconnectFromProvider() error
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user