Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .golangci.next.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ linters:
enable:
- contextcheck
- err113
- errchkjson
- gocritic
- godot
- godox
Expand All @@ -27,13 +26,16 @@ linters:
- wastedassign

issues:
exclude-rules:
# We call external linters when they are installed: Flake8, ShellCheck, etc.
- linters: [gosec]
path: '_test[.]go$'
text: 'G204: Subprocess launched with variable'

# https://github.com/golangci/golangci-lint/issues/2239
exclude-use-default: false

linters-settings:
errchkjson:
check-error-free-encoding: true

thelper:
# https://github.com/kulti/thelper/issues/27
tb: { begin: true, first: true }
Expand Down
4 changes: 3 additions & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
linters:
disable:
- contextcheck
- errchkjson
- gci
- gofumpt
enable:
Expand Down Expand Up @@ -41,6 +40,9 @@ linters-settings:
- pkg: github.com/crunchydata/postgres-operator/internal/testing/*
desc: The "internal/testing" packages should be used only in tests.

errchkjson:
check-error-free-encoding: true

exhaustive:
default-signifies-exhaustive: true

Expand Down
5 changes: 1 addition & 4 deletions internal/bridge/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -724,10 +724,7 @@ func (c *Client) UpdateCluster(
) (*ClusterApiResource, error) {
result := &ClusterApiResource{}

clusterbyte, err := json.Marshal(clusterRequestPayload)
if err != nil {
return result, err
}
clusterbyte, _ := json.Marshal(clusterRequestPayload)

response, err := c.doWithRetry(ctx, "PATCH", "/clusters/"+id, nil, clusterbyte, http.Header{
"Accept": []string{"application/json"},
Expand Down
10 changes: 5 additions & 5 deletions internal/controller/postgrescluster/patroni_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,17 +539,17 @@ func TestReconcilePatroniSwitchover(t *testing.T) {
switch {
case timelineCall:
timelineCall = false
stdout.Write([]byte(`[{"Cluster": "hippo-ha", "Member": "hippo-instance1-67mc-0", "Host": "hippo-instance1-67mc-0.hippo-pods", "Role": "Leader", "State": "running", "TL": 4}, {"Cluster": "hippo-ha", "Member": "hippo-instance1-ltcf-0", "Host": "hippo-instance1-ltcf-0.hippo-pods", "Role": "Replica", "State": "running", "TL": 4, "Lag in MB": 0}]`))
_, _ = stdout.Write([]byte(`[{"Cluster": "hippo-ha", "Member": "hippo-instance1-67mc-0", "Host": "hippo-instance1-67mc-0.hippo-pods", "Role": "Leader", "State": "running", "TL": 4}, {"Cluster": "hippo-ha", "Member": "hippo-instance1-ltcf-0", "Host": "hippo-instance1-ltcf-0.hippo-pods", "Role": "Replica", "State": "running", "TL": 4, "Lag in MB": 0}]`))
case timelineCallNoLeader:
stdout.Write([]byte(`[{"Cluster": "hippo-ha", "Member": "hippo-instance1-ltcf-0", "Host": "hippo-instance1-ltcf-0.hippo-pods", "Role": "Replica", "State": "running", "TL": 4, "Lag in MB": 0}]`))
_, _ = stdout.Write([]byte(`[{"Cluster": "hippo-ha", "Member": "hippo-instance1-ltcf-0", "Host": "hippo-instance1-ltcf-0.hippo-pods", "Role": "Replica", "State": "running", "TL": 4, "Lag in MB": 0}]`))
case callError:
return errors.New("boom")
case callFails:
stdout.Write([]byte("bang"))
_, _ = stdout.Write([]byte("bang"))
case failover:
stdout.Write([]byte("failed over"))
_, _ = stdout.Write([]byte("failed over"))
default:
stdout.Write([]byte("switched over"))
_, _ = stdout.Write([]byte("switched over"))
}
return nil
},
Expand Down
6 changes: 1 addition & 5 deletions internal/controller/standalone_pgadmin/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,7 @@ cd $PGADMIN_DIR
// to add a user, that user will not be in intentUsers. If errors occurred when attempting to
// update a user, the user will be in intentUsers as it existed before. We now want to marshal the
// intentUsers to json and write the users.json file to the secret.
usersJSON, err := json.Marshal(intentUsers)
if err != nil {
return err
}
intentUserSecret.Data["users.json"] = usersJSON
intentUserSecret.Data["users.json"], _ = json.Marshal(intentUsers)

err = errors.WithStack(r.setControllerReference(pgadmin, intentUserSecret))
if err == nil {
Expand Down
16 changes: 8 additions & 8 deletions internal/controller/standalone_pgadmin/users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func TestReconcilePGAdminUsers(t *testing.T) {

// Simulate a v7 version of pgAdmin by setting stdout to "7" for
// podexec call in reconcilePGAdminMajorVersion
stdout.Write([]byte("7"))
_, _ = stdout.Write([]byte("7"))
return nil
}

Expand Down Expand Up @@ -147,7 +147,7 @@ func TestReconcilePGAdminUsers(t *testing.T) {

// Simulate a v7 version of pgAdmin by setting stdout to "7" for
// podexec call in reconcilePGAdminMajorVersion
stdout.Write([]byte("7"))
_, _ = stdout.Write([]byte("7"))
return nil
}

Expand Down Expand Up @@ -182,7 +182,7 @@ func TestReconcilePGAdminMajorVersion(t *testing.T) {

// Simulate a v7 version of pgAdmin by setting stdout to "7" for
// podexec call in reconcilePGAdminMajorVersion
stdout.Write([]byte("7"))
_, _ = stdout.Write([]byte("7"))
return nil
}

Expand All @@ -197,7 +197,7 @@ func TestReconcilePGAdminMajorVersion(t *testing.T) {
stdin io.Reader, stdout, stderr io.Writer, command ...string,
) error {
// Simulate the python call giving bad data (not a version int)
stdout.Write([]byte("asdfjkl;"))
_, _ = stdout.Write([]byte("asdfjkl;"))
return nil
}

Expand Down Expand Up @@ -547,7 +547,7 @@ func TestWritePGAdminUsers(t *testing.T) {
) error {
calls++

stderr.Write([]byte("issue running setup.py update-user command"))
_, _ = stderr.Write([]byte("issue running setup.py update-user command"))

return nil
}
Expand Down Expand Up @@ -627,7 +627,7 @@ func TestWritePGAdminUsers(t *testing.T) {
) error {
calls++

stderr.Write([]byte("issue running setup.py add-user command"))
_, _ = stderr.Write([]byte("issue running setup.py add-user command"))

return nil
}
Expand Down Expand Up @@ -655,7 +655,7 @@ func TestWritePGAdminUsers(t *testing.T) {
) error {
calls++

stdout.Write([]byte("Invalid email address"))
_, _ = stdout.Write([]byte("Invalid email address"))

return nil
}
Expand Down Expand Up @@ -684,7 +684,7 @@ func TestWritePGAdminUsers(t *testing.T) {
) error {
calls++

stdout.Write([]byte("Password must be at least 6 characters long"))
_, _ = stdout.Write([]byte("Password must be at least 6 characters long"))

return nil
}
Expand Down
8 changes: 4 additions & 4 deletions internal/patroni/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func TestExecutorGetTimeline(t *testing.T) {
tl, actual := Executor(func(
_ context.Context, stdin io.Reader, stdout, stderr io.Writer, command ...string,
) error {
stderr.Write([]byte(`no luck`))
_, _ = stderr.Write([]byte(`no luck`))
return nil
}).GetTimeline(context.Background())

Expand All @@ -255,7 +255,7 @@ func TestExecutorGetTimeline(t *testing.T) {
tl, actual := Executor(func(
_ context.Context, stdin io.Reader, stdout, stderr io.Writer, command ...string,
) error {
stdout.Write([]byte(`no luck`))
_, _ = stdout.Write([]byte(`no luck`))
return nil
}).GetTimeline(context.Background())

Expand All @@ -267,7 +267,7 @@ func TestExecutorGetTimeline(t *testing.T) {
tl, actual := Executor(func(
_ context.Context, stdin io.Reader, stdout, stderr io.Writer, command ...string,
) error {
stdout.Write([]byte(`[{"Cluster": "hippo-ha", "Member": "hippo-instance1-ltcf-0", "Host": "hippo-instance1-ltcf-0.hippo-pods", "Role": "Replica", "State": "running", "TL": 4, "Lag in MB": 0}]`))
_, _ = stdout.Write([]byte(`[{"Cluster": "hippo-ha", "Member": "hippo-instance1-ltcf-0", "Host": "hippo-instance1-ltcf-0.hippo-pods", "Role": "Replica", "State": "running", "TL": 4, "Lag in MB": 0}]`))
return nil
}).GetTimeline(context.Background())

Expand All @@ -279,7 +279,7 @@ func TestExecutorGetTimeline(t *testing.T) {
tl, actual := Executor(func(
_ context.Context, stdin io.Reader, stdout, stderr io.Writer, command ...string,
) error {
stdout.Write([]byte(`[{"Cluster": "hippo-ha", "Member": "hippo-instance1-67mc-0", "Host": "hippo-instance1-67mc-0.hippo-pods", "Role": "Leader", "State": "running", "TL": 4}, {"Cluster": "hippo-ha", "Member": "hippo-instance1-ltcf-0", "Host": "hippo-instance1-ltcf-0.hippo-pods", "Role": "Replica", "State": "running", "TL": 4, "Lag in MB": 0}]`))
_, _ = stdout.Write([]byte(`[{"Cluster": "hippo-ha", "Member": "hippo-instance1-67mc-0", "Host": "hippo-instance1-67mc-0.hippo-pods", "Role": "Leader", "State": "running", "TL": 4}, {"Cluster": "hippo-ha", "Member": "hippo-instance1-ltcf-0", "Host": "hippo-instance1-ltcf-0.hippo-pods", "Role": "Replica", "State": "running", "TL": 4, "Lag in MB": 0}]`))
return nil
}).GetTimeline(context.Background())

Expand Down
11 changes: 4 additions & 7 deletions internal/upgradecheck/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,8 @@ func getServerVersion(ctx context.Context, cfg *rest.Config) string {
return versionInfo.String()
}

func addHeader(req *http.Request, upgradeInfo *clientUpgradeData) (*http.Request, error) {
marshaled, err := json.Marshal(upgradeInfo)
if err == nil {
upgradeInfoString := string(marshaled)
req.Header.Add(clientHeader, upgradeInfoString)
}
return req, err
func addHeader(req *http.Request, upgradeInfo *clientUpgradeData) *http.Request {
marshaled, _ := json.Marshal(upgradeInfo)
req.Header.Add(clientHeader, string(marshaled))
return req
}
5 changes: 2 additions & 3 deletions internal/upgradecheck/header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,12 +596,11 @@ func TestAddHeader(t *testing.T) {
PGOVersion: versionString,
}

result, err := addHeader(req, upgradeInfo)
assert.NilError(t, err)
result := addHeader(req, upgradeInfo)
header := result.Header[clientHeader]

passedThroughData := &clientUpgradeData{}
err = json.Unmarshal([]byte(header[0]), passedThroughData)
err := json.Unmarshal([]byte(header[0]), passedThroughData)
assert.NilError(t, err)

assert.Equal(t, passedThroughData.PGOVersion, "1.2.3")
Expand Down
2 changes: 1 addition & 1 deletion internal/upgradecheck/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func checkForUpgrades(ctx context.Context, url, versionString string, backoff wa
// in case some of the checks return errors
headerPayloadStruct = generateHeader(ctx, cfg, crclient,
versionString, isOpenShift, registrationToken)
req, err = addHeader(req, headerPayloadStruct)
req = addHeader(req, headerPayloadStruct)
}

// wait.ExponentialBackoff will retry the func according to the backoff object until
Expand Down