From aad03f71eac123bdca2c03aa4b3aa7e364492dba Mon Sep 17 00:00:00 2001 From: fahed dorgaa Date: Wed, 14 Aug 2024 12:54:44 +0200 Subject: [PATCH] fix golangci-lint issues (#2715) Signed-off-by: fahed dorgaa Co-authored-by: fahed dorgaa Co-authored-by: Matthias Adler --- pkg/apis/acid.zalan.do/v1/postgresql_type.go | 4 ++-- pkg/cluster/cluster.go | 2 +- pkg/cluster/exec.go | 4 ++-- pkg/cluster/k8sres.go | 5 ----- pkg/cluster/util.go | 4 ---- pkg/controller/util.go | 2 +- pkg/util/util.go | 2 +- 7 files changed, 7 insertions(+), 16 deletions(-) diff --git a/pkg/apis/acid.zalan.do/v1/postgresql_type.go b/pkg/apis/acid.zalan.do/v1/postgresql_type.go index 612cf7041..3d731743f 100644 --- a/pkg/apis/acid.zalan.do/v1/postgresql_type.go +++ b/pkg/apis/acid.zalan.do/v1/postgresql_type.go @@ -133,7 +133,7 @@ type Volume struct { Size string `json:"size"` StorageClass string `json:"storageClass,omitempty"` SubPath string `json:"subPath,omitempty"` - IsSubPathExpr *bool `json:"isSubPathExpr,omitemtpy"` + IsSubPathExpr *bool `json:"isSubPathExpr,omitempty"` Iops *int64 `json:"iops,omitempty"` Throughput *int64 `json:"throughput,omitempty"` VolumeType string `json:"type,omitempty"` @@ -144,7 +144,7 @@ type AdditionalVolume struct { Name string `json:"name"` MountPath string `json:"mountPath"` SubPath string `json:"subPath,omitempty"` - IsSubPathExpr *bool `json:"isSubPathExpr,omitemtpy"` + IsSubPathExpr *bool `json:"isSubPathExpr,omitempty"` TargetContainers []string `json:"targetContainers"` VolumeSource v1.VolumeSource `json:"volumeSource"` } diff --git a/pkg/cluster/cluster.go b/pkg/cluster/cluster.go index f0f432753..d9997463a 100644 --- a/pkg/cluster/cluster.go +++ b/pkg/cluster/cluster.go @@ -668,7 +668,7 @@ func compareEnv(a, b []v1.EnvVar) bool { if len(a) != len(b) { return false } - equal := true + var equal bool for _, enva := range a { hasmatch := false for _, envb := range b { diff --git a/pkg/cluster/exec.go b/pkg/cluster/exec.go index 8b5089b4e..5605a70f6 100644 --- a/pkg/cluster/exec.go +++ b/pkg/cluster/exec.go @@ -15,7 +15,7 @@ import ( "github.com/zalando/postgres-operator/pkg/util/constants" ) -//ExecCommand executes arbitrary command inside the pod +// ExecCommand executes arbitrary command inside the pod func (c *Cluster) ExecCommand(podName *spec.NamespacedName, command ...string) (string, error) { c.setProcessName("executing command %q", strings.Join(command, " ")) @@ -59,7 +59,7 @@ func (c *Cluster) ExecCommand(podName *spec.NamespacedName, command ...string) ( return "", fmt.Errorf("failed to init executor: %v", err) } - err = exec.Stream(remotecommand.StreamOptions{ + err = exec.StreamWithContext(context.TODO(), remotecommand.StreamOptions{ Stdout: &execOut, Stderr: &execErr, Tty: false, diff --git a/pkg/cluster/k8sres.go b/pkg/cluster/k8sres.go index 89fb4b558..84da6affb 100644 --- a/pkg/cluster/k8sres.go +++ b/pkg/cluster/k8sres.go @@ -47,11 +47,6 @@ const ( operatorPort = 8080 ) -type pgUser struct { - Password string `json:"password"` - Options []string `json:"options"` -} - type patroniDCS struct { TTL uint32 `json:"ttl,omitempty"` LoopWait uint32 `json:"loop_wait,omitempty"` diff --git a/pkg/cluster/util.go b/pkg/cluster/util.go index cee537036..32f79a14b 100644 --- a/pkg/cluster/util.go +++ b/pkg/cluster/util.go @@ -449,10 +449,6 @@ func (c *Cluster) _waitPodLabelsReady(anyReplica bool) error { return err } -func (c *Cluster) waitForAnyReplicaLabelReady() error { - return c._waitPodLabelsReady(true) -} - func (c *Cluster) waitForAllPodsLabelReady() error { return c._waitPodLabelsReady(false) } diff --git a/pkg/controller/util.go b/pkg/controller/util.go index bd1e65d02..5a3b23edc 100644 --- a/pkg/controller/util.go +++ b/pkg/controller/util.go @@ -80,7 +80,7 @@ func (c *Controller) createOperatorCRD(desiredCrd *apiextv1.CustomResourceDefini c.logger.Infof("customResourceDefinition %q has been registered", crd.Name) } - return wait.Poll(c.config.CRDReadyWaitInterval, c.config.CRDReadyWaitTimeout, func() (bool, error) { + return wait.PollUntilContextTimeout(context.TODO(), c.config.CRDReadyWaitInterval, c.config.CRDReadyWaitTimeout, false, func(ctx context.Context) (bool, error) { c, err := c.KubeClient.CustomResourceDefinitions().Get(context.TODO(), desiredCrd.Name, metav1.GetOptions{}) if err != nil { return false, err diff --git a/pkg/util/util.go b/pkg/util/util.go index fb1217d1f..4b3aafc63 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -35,7 +35,7 @@ const ( var passwordChars = []byte("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") func init() { - rand.Seed(time.Now().Unix()) + rand.New(rand.NewSource(time.Now().Unix())) } // helper function to get bool pointers