From 27114701bac69f19b80e8ab190976f1344cfef82 Mon Sep 17 00:00:00 2001 From: u5surf Date: Thu, 15 Nov 2018 00:58:13 +0900 Subject: [PATCH] fix golint fail #415 --- cmd/main.go | 8 ++++---- pkg/apis/acid.zalan.do/v1/const.go | 1 + pkg/apis/acid.zalan.do/v1/crds.go | 3 +++ pkg/apis/acid.zalan.do/v1/doc.go | 2 +- pkg/apis/acid.zalan.do/v1/marshal.go | 1 + .../v1/operator_configuration_type.go | 17 +++++++++++++++++ pkg/apis/acid.zalan.do/v1/postgresql_type.go | 4 +++- pkg/apis/acid.zalan.do/v1/register.go | 7 ++++++- pkg/apis/acid.zalan.do/v1/util.go | 2 ++ pkg/apiserver/apiserver.go | 2 +- pkg/cluster/cluster.go | 4 ++-- pkg/cluster/pod.go | 6 +----- pkg/cluster/types.go | 5 +++-- pkg/cluster/util.go | 1 + pkg/controller/logs_and_api.go | 2 +- pkg/spec/types.go | 1 + pkg/util/config/util.go | 4 ++++ pkg/util/retryutil/retry_util.go | 2 ++ pkg/util/teams/teams.go | 1 + 19 files changed, 55 insertions(+), 18 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index b400630f6..09ab40a87 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -47,14 +47,14 @@ func init() { log.Printf("Fully qualified configmap name: %v", config.ConfigMapName) } - if crd_interval := os.Getenv("CRD_READY_WAIT_INTERVAL"); crd_interval != "" { - config.CRDReadyWaitInterval = mustParseDuration(crd_interval) + if crdInterval := os.Getenv("CRD_READY_WAIT_INTERVAL"); crdInterval != "" { + config.CRDReadyWaitInterval = mustParseDuration(crdInterval) } else { config.CRDReadyWaitInterval = 4 * time.Second } - if crd_timeout := os.Getenv("CRD_READY_WAIT_TIMEOUT"); crd_timeout != "" { - config.CRDReadyWaitTimeout = mustParseDuration(crd_timeout) + if crdTimeout := os.Getenv("CRD_READY_WAIT_TIMEOUT"); crdTimeout != "" { + config.CRDReadyWaitTimeout = mustParseDuration(crdTimeout) } else { config.CRDReadyWaitTimeout = 30 * time.Second } diff --git a/pkg/apis/acid.zalan.do/v1/const.go b/pkg/apis/acid.zalan.do/v1/const.go index 4592a2d68..a9a790788 100644 --- a/pkg/apis/acid.zalan.do/v1/const.go +++ b/pkg/apis/acid.zalan.do/v1/const.go @@ -1,5 +1,6 @@ package v1 +//Cluster name, cluster status and service name setting const ( serviceNameMaxLength = 63 clusterNameMaxLength = serviceNameMaxLength - len("-repl") diff --git a/pkg/apis/acid.zalan.do/v1/crds.go b/pkg/apis/acid.zalan.do/v1/crds.go index 5cefa1c83..ec25d722f 100644 --- a/pkg/apis/acid.zalan.do/v1/crds.go +++ b/pkg/apis/acid.zalan.do/v1/crds.go @@ -6,6 +6,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) +// CRDResource const ( PostgresCRDResourceKind = "postgresql" PostgresCRDResourcePlural = "postgresqls" @@ -39,6 +40,7 @@ func buildCRD(name, kind, plural, short string) *apiextv1beta1.CustomResourceDef } } +// PostgresCRD returns CustomResourceDefinition built from PostgresCRDResource func PostgresCRD() *apiextv1beta1.CustomResourceDefinition { return buildCRD(PostgresCRDResouceName, PostgresCRDResourceKind, @@ -46,6 +48,7 @@ func PostgresCRD() *apiextv1beta1.CustomResourceDefinition { PostgresCRDResourceShort) } +// ConfigurationCRD returns CustomResourceDefinition built from OperatorConfigCRDResource func ConfigurationCRD() *apiextv1beta1.CustomResourceDefinition { return buildCRD(OperatorConfigCRDResourceName, OperatorConfigCRDResouceKind, diff --git a/pkg/apis/acid.zalan.do/v1/doc.go b/pkg/apis/acid.zalan.do/v1/doc.go index 5accd806d..159378752 100644 --- a/pkg/apis/acid.zalan.do/v1/doc.go +++ b/pkg/apis/acid.zalan.do/v1/doc.go @@ -1,6 +1,6 @@ +// Package v1 is the v1 version of the API. // +k8s:deepcopy-gen=package,register -// Package v1 is the v1 version of the API. // +groupName=acid.zalan.do package v1 diff --git a/pkg/apis/acid.zalan.do/v1/marshal.go b/pkg/apis/acid.zalan.do/v1/marshal.go index b24c4e49d..823ff0ef2 100644 --- a/pkg/apis/acid.zalan.do/v1/marshal.go +++ b/pkg/apis/acid.zalan.do/v1/marshal.go @@ -104,6 +104,7 @@ func (p *Postgresql) UnmarshalJSON(data []byte) error { return nil } +// UnmarshalJSON convert to Duration from byte slice of json func (d *Duration) UnmarshalJSON(b []byte) error { var ( v interface{} diff --git a/pkg/apis/acid.zalan.do/v1/operator_configuration_type.go b/pkg/apis/acid.zalan.do/v1/operator_configuration_type.go index de7681db4..e168a25ad 100644 --- a/pkg/apis/acid.zalan.do/v1/operator_configuration_type.go +++ b/pkg/apis/acid.zalan.do/v1/operator_configuration_type.go @@ -13,6 +13,8 @@ import ( // +genclient:onlyVerbs=get // +genclient:noStatus // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// OperatorConfiguration defines the specification for the OperatorConfigration. type OperatorConfiguration struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata"` @@ -21,6 +23,8 @@ type OperatorConfiguration struct { } // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// OperatorConfigurationList defines the list of the OperatorConfigration. type OperatorConfigurationList struct { metav1.TypeMeta `json:",inline"` metav1.ListMeta `json:"metadata"` @@ -28,11 +32,13 @@ type OperatorConfigurationList struct { Items []OperatorConfiguration `json:"items"` } +// PostgresUsersConfiguration defines the user of the Postgres. type PostgresUsersConfiguration struct { SuperUsername string `json:"super_username,omitempty"` ReplicationUsername string `json:"replication_username,omitempty"` } +// KubernetesMetaConfiguration defines the pod service account info type KubernetesMetaConfiguration struct { PodServiceAccountName string `json:"pod_service_account_name,omitempty"` // TODO: change it to the proper json @@ -55,6 +61,7 @@ type KubernetesMetaConfiguration struct { PodPriorityClassName string `json:"pod_priority_class_name,omitempty"` } +// PostgresPodResourcesDefaults defines the spec of default resources type PostgresPodResourcesDefaults struct { DefaultCPURequest string `json:"default_cpu_request,omitempty"` DefaultMemoryRequest string `json:"default_memory_request,omitempty"` @@ -62,6 +69,7 @@ type PostgresPodResourcesDefaults struct { DefaultMemoryLimit string `json:"default_memory_limit,omitempty"` } +// OperatorTimeouts defines the timeout of ResourceCheck, PodWait, ReadyWait type OperatorTimeouts struct { ResourceCheckInterval Duration `json:"resource_check_interval,omitempty"` ResourceCheckTimeout Duration `json:"resource_check_timeout,omitempty"` @@ -71,6 +79,7 @@ type OperatorTimeouts struct { ReadyWaitTimeout Duration `json:"ready_wait_timeout,omitempty"` } +// LoadBalancerConfiguration defines the LB DNS configration type LoadBalancerConfiguration struct { DbHostedZone string `json:"db_hosted_zone,omitempty"` EnableMasterLoadBalancer bool `json:"enable_master_load_balancer,omitempty"` @@ -79,6 +88,7 @@ type LoadBalancerConfiguration struct { ReplicaDNSNameFormat config.StringTemplate `json:"replica_dns_name_format,omitempty"` } +//AWSGCPConfiguration defines the configration of AWS s3 type AWSGCPConfiguration struct { WALES3Bucket string `json:"wal_s3_bucket,omitempty"` AWSRegion string `json:"aws_region,omitempty"` @@ -86,11 +96,13 @@ type AWSGCPConfiguration struct { KubeIAMRole string `json:"kube_iam_role,omitempty"` } +// OperatorDebugConfiguration defines the configration of debug type OperatorDebugConfiguration struct { DebugLogging bool `json:"debug_logging,omitempty"` EnableDBAccess bool `json:"enable_database_access,omitempty"` } +// TeamsAPIConfiguration defines the configration of TeamsAPI type TeamsAPIConfiguration struct { EnableTeamsAPI bool `json:"enable_teams_api,omitempty"` TeamsAPIUrl string `json:"teams_api_url,omitempty"` @@ -103,12 +115,14 @@ type TeamsAPIConfiguration struct { PostgresSuperuserTeams []string `json:"postgres_superuser_teams,omitempty"` } +// LoggingRESTAPIConfiguration defines Logging API conf type LoggingRESTAPIConfiguration struct { APIPort int `json:"api_port,omitempty"` RingLogLines int `json:"ring_log_lines,omitempty"` ClusterHistoryEntries int `json:"cluster_history_entries,omitempty"` } +// ScalyrConfiguration defines the configration of ScalyrAPI type ScalyrConfiguration struct { ScalyrAPIKey string `json:"scalyr_api_key,omitempty"` ScalyrImage string `json:"scalyr_image,omitempty"` @@ -119,6 +133,7 @@ type ScalyrConfiguration struct { ScalyrMemoryLimit string `json:"scalyr_memory_limit,omitempty"` } +// OperatorConfigurationData defines the operation config type OperatorConfigurationData struct { EtcdHost string `json:"etcd_host,omitempty"` DockerImage string `json:"docker_image,omitempty"` @@ -140,6 +155,7 @@ type OperatorConfigurationData struct { Scalyr ScalyrConfiguration `json:"scalyr"` } +// OperatorConfigurationUsers defines configration for super user type OperatorConfigurationUsers struct { SuperUserName string `json:"superuser_name,omitempty"` Replication string `json:"replication_user_name,omitempty"` @@ -147,4 +163,5 @@ type OperatorConfigurationUsers struct { TeamAPIRoleConfiguration map[string]string `json:"team_api_role_configuration,omitempty"` } +//Duration is time.Duration type Duration time.Duration diff --git a/pkg/apis/acid.zalan.do/v1/postgresql_type.go b/pkg/apis/acid.zalan.do/v1/postgresql_type.go index 380ba68d7..d56c19f47 100644 --- a/pkg/apis/acid.zalan.do/v1/postgresql_type.go +++ b/pkg/apis/acid.zalan.do/v1/postgresql_type.go @@ -9,7 +9,8 @@ import ( // +genclient // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -//Postgresql defines PostgreSQL Custom Resource Definition Object. + +// Postgresql defines PostgreSQL Custom Resource Definition Object. type Postgresql struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` @@ -54,6 +55,7 @@ type PostgresSpec struct { } // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + // PostgresqlList defines a list of PostgreSQL clusters. type PostgresqlList struct { metav1.TypeMeta `json:",inline"` diff --git a/pkg/apis/acid.zalan.do/v1/register.go b/pkg/apis/acid.zalan.do/v1/register.go index 7dd03fad1..f4f9a250a 100644 --- a/pkg/apis/acid.zalan.do/v1/register.go +++ b/pkg/apis/acid.zalan.do/v1/register.go @@ -8,15 +8,20 @@ import ( "github.com/zalando-incubator/postgres-operator/pkg/apis/acid.zalan.do" ) +// APIVersion refered API version const ( APIVersion = "v1" ) var ( // localSchemeBuilder and AddToScheme will stay in k8s.io/kubernetes. + + // SchemeBuilder is runtime.SchemeBuilder SchemeBuilder runtime.SchemeBuilder localSchemeBuilder = &SchemeBuilder - AddToScheme = localSchemeBuilder.AddToScheme + //AddToScheme is localSchemeBuilder.AddToScheme + AddToScheme = localSchemeBuilder.AddToScheme + //SchemeGroupVersion has GroupName and APIVersion SchemeGroupVersion = schema.GroupVersion{Group: acidzalando.GroupName, Version: APIVersion} ) diff --git a/pkg/apis/acid.zalan.do/v1/util.go b/pkg/apis/acid.zalan.do/v1/util.go index 2d3c90db8..ce3843f40 100644 --- a/pkg/apis/acid.zalan.do/v1/util.go +++ b/pkg/apis/acid.zalan.do/v1/util.go @@ -14,6 +14,7 @@ var ( serviceNameRegex = regexp.MustCompile(serviceNameRegexString) ) +// Clone returns Postgresql.DeepCopy func (p *Postgresql) Clone() *Postgresql { if p == nil { return nil @@ -83,6 +84,7 @@ func validateCloneClusterDescription(clone *CloneDescription) error { return nil } +// Success returns status ClusterFailed or not func (status PostgresStatus) Success() bool { return status != ClusterStatusAddFailed && status != ClusterStatusUpdateFailed && diff --git a/pkg/apiserver/apiserver.go b/pkg/apiserver/apiserver.go index a6f4e09ce..8056a7af1 100644 --- a/pkg/apiserver/apiserver.go +++ b/pkg/apiserver/apiserver.go @@ -31,7 +31,7 @@ type controllerInformer interface { GetOperatorConfig() *config.Config GetStatus() *spec.ControllerStatus TeamClusterList() map[string][]spec.NamespacedName - ClusterStatus(team, namespace, cluster string) (*cluster.ClusterStatus, error) + ClusterStatus(team, namespace, cluster string) (*cluster.Status, error) ClusterLogs(team, namespace, cluster string) ([]*spec.LogEntry, error) ClusterHistory(team, namespace, cluster string) ([]*spec.Diff, error) ClusterDatabasesMap() map[string][]string diff --git a/pkg/cluster/cluster.go b/pkg/cluster/cluster.go index b2208705a..aadaae481 100644 --- a/pkg/cluster/cluster.go +++ b/pkg/cluster/cluster.go @@ -849,8 +849,8 @@ func (c *Cluster) GetCurrentProcess() Process { } // GetStatus provides status of the cluster -func (c *Cluster) GetStatus() *ClusterStatus { - return &ClusterStatus{ +func (c *Cluster) GetStatus() *Status { + return &Status{ Cluster: c.Spec.ClusterName, Team: c.Spec.TeamID, Status: c.Status, diff --git a/pkg/cluster/pod.go b/pkg/cluster/pod.go index ab282b6b9..6256da6bf 100644 --- a/pkg/cluster/pod.go +++ b/pkg/cluster/pod.go @@ -77,11 +77,7 @@ func (c *Cluster) deletePod(podName spec.NamespacedName) error { return err } - if err := c.waitForPodDeletion(ch); err != nil { - return err - } - - return nil + return c.waitForPodDeletion(ch) } func (c *Cluster) unregisterPodSubscriber(podName spec.NamespacedName) { diff --git a/pkg/cluster/types.go b/pkg/cluster/types.go index 83b7e73fb..7f52778f6 100644 --- a/pkg/cluster/types.go +++ b/pkg/cluster/types.go @@ -20,6 +20,7 @@ const ( Replica PostgresRole = "replica" ) +// PodEventType describe value of event type type PodEventType string // Possible values for the EventType @@ -50,8 +51,8 @@ type WorkerStatus struct { CurrentProcess Process } -// ClusterStatus describes status of the cluster -type ClusterStatus struct { +// Status describes status of the cluster +type Status struct { Team string Cluster string MasterService *v1.Service diff --git a/pkg/cluster/util.go b/pkg/cluster/util.go index dbfda1c0e..8b5a867c2 100644 --- a/pkg/cluster/util.go +++ b/pkg/cluster/util.go @@ -460,6 +460,7 @@ func (c *Cluster) setSpec(newSpec *acidv1.Postgresql) { c.specMu.Unlock() } +// GetSpec returns cluster.Postgresql func (c *Cluster) GetSpec() (*acidv1.Postgresql, error) { c.specMu.RLock() defer c.specMu.RUnlock() diff --git a/pkg/controller/logs_and_api.go b/pkg/controller/logs_and_api.go index 3e5f20759..a6bba0c9d 100644 --- a/pkg/controller/logs_and_api.go +++ b/pkg/controller/logs_and_api.go @@ -15,7 +15,7 @@ import ( ) // ClusterStatus provides status of the cluster -func (c *Controller) ClusterStatus(team, namespace, cluster string) (*cluster.ClusterStatus, error) { +func (c *Controller) ClusterStatus(team, namespace, cluster string) (*cluster.Status, error) { clusterName := spec.NamespacedName{ Namespace: namespace, diff --git a/pkg/spec/types.go b/pkg/spec/types.go index e394462d4..360fd580d 100644 --- a/pkg/spec/types.go +++ b/pkg/spec/types.go @@ -125,6 +125,7 @@ func (n *NamespacedName) Decode(value string) error { return n.DecodeWorker(value, GetOperatorNamespace()) } +// UnmarshalJSON covert to NamespacedName from byte slice func (n *NamespacedName) UnmarshalJSON(data []byte) error { result := NamespacedName{} var tmp string diff --git a/pkg/util/config/util.go b/pkg/util/config/util.go index 498810bb7..894f087d2 100644 --- a/pkg/util/config/util.go +++ b/pkg/util/config/util.go @@ -19,6 +19,7 @@ type fieldInfo struct { Field reflect.Value } +// StringTemplate is string type StringTemplate string func decoderFrom(field reflect.Value) (d decoder) { @@ -221,12 +222,14 @@ func getMapPairsFromString(value string) (pairs []string, err error) { return } +// Decode cast value to StringTemplate func (f *StringTemplate) Decode(value string) error { *f = StringTemplate(value) return nil } +// Format formatted string from StringTemplate func (f *StringTemplate) Format(a ...string) string { res := string(*f) @@ -237,6 +240,7 @@ func (f *StringTemplate) Format(a ...string) string { return res } +// MarshalJSON returns json.Marshal(byte slice) from StringTemplate func (f StringTemplate) MarshalJSON() ([]byte, error) { return json.Marshal(string(f)) } diff --git a/pkg/util/retryutil/retry_util.go b/pkg/util/retryutil/retry_util.go index cbae3bb1b..18676b8a6 100644 --- a/pkg/util/retryutil/retry_util.go +++ b/pkg/util/retryutil/retry_util.go @@ -17,8 +17,10 @@ type Ticker struct { ticker *time.Ticker } +// Stop returns ticker.Stop func (t *Ticker) Stop() { t.ticker.Stop() } +// Tick returns ticker.C func (t *Ticker) Tick() { <-t.ticker.C } // Retry is a wrapper around RetryWorker that provides a real RetryTicker diff --git a/pkg/util/teams/teams.go b/pkg/util/teams/teams.go index 8afcd1a3b..f51ccbc94 100644 --- a/pkg/util/teams/teams.go +++ b/pkg/util/teams/teams.go @@ -43,6 +43,7 @@ type httpClient interface { Do(req *http.Request) (*http.Response, error) } +// Interface have to implement TeamInfo type Interface interface { TeamInfo(teamID, token string) (tm *Team, err error) }