Skip to content

Commit f46a2aa

Browse files
Merge pull request openstack-k8s-operators#247 from stuggi/align_makefile
Align Makefile and fix golangci errors
2 parents bdbac5d + 2db59c8 commit f46a2aa

File tree

9 files changed

+37
-24
lines changed

9 files changed

+37
-24
lines changed

Makefile

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,9 @@ fmt: ## Run go fmt against code.
107107
go fmt ./...
108108

109109
.PHONY: vet
110-
vet: ## Run go vet against code.
110+
vet: gowork ## Run go vet against code.
111111
go vet ./...
112+
go vet ./api/...
112113

113114
.PHONY: tidy
114115
tidy: ## Run go mod tidy on every mod file in the repo
@@ -124,7 +125,7 @@ PROCS?=$(shell expr $(shell nproc --ignore 2) / 2)
124125
PROC_CMD = --procs ${PROCS}
125126

126127
.PHONY: test
127-
test: manifests generate fmt vet envtest ## Run tests.
128+
test: manifests generate gowork fmt vet envtest ginkgo ## Run tests.
128129
for mod in $(shell find . -name go.mod -exec dirname {} \;); do \
129130
pushd ./$$mod ; \
130131
if [ -f test/functional/suite_test.go ]; then \
@@ -330,23 +331,26 @@ get-ci-tools:
330331

331332
# Run go fmt against code
332333
gofmt: get-ci-tools
333-
$(CI_TOOLS_REPO_DIR)/test-runner/gofmt.sh
334+
GOWORK=off $(CI_TOOLS_REPO_DIR)/test-runner/gofmt.sh
335+
GOWORK=off $(CI_TOOLS_REPO_DIR)/test-runner/gofmt.sh ./api
334336

335337
# Run go vet against code
336338
govet: get-ci-tools
337-
$(CI_TOOLS_REPO_DIR)/test-runner/govet.sh
339+
GOWORK=off $(CI_TOOLS_REPO_DIR)/test-runner/govet.sh
340+
GOWORK=off $(CI_TOOLS_REPO_DIR)/test-runner/govet.sh ./api
338341

339342
# Run go test against code
340-
gotest: get-ci-tools
341-
$(CI_TOOLS_REPO_DIR)/test-runner/gotest.sh
343+
gotest: test
342344

343345
# Run golangci-lint test against code
344346
golangci: get-ci-tools
345-
$(CI_TOOLS_REPO_DIR)/test-runner/golangci.sh
347+
GOWORK=off $(CI_TOOLS_REPO_DIR)/test-runner/golangci.sh
348+
GOWORK=off $(CI_TOOLS_REPO_DIR)/test-runner/golangci.sh ./api
346349

347350
# Run go lint against code
348351
golint: get-ci-tools
349-
PATH=$(GOBIN):$(PATH); $(CI_TOOLS_REPO_DIR)/test-runner/golint.sh
352+
GOWORK=off PATH=$(GOBIN):$(PATH); $(CI_TOOLS_REPO_DIR)/test-runner/golint.sh
353+
GOWORK=off PATH=$(GOBIN):$(PATH); $(CI_TOOLS_REPO_DIR)/test-runner/golint.sh ./api
350354

351355
.PHONY: operator-lint
352356
operator-lint: $(LOCALBIN) gowork ## Runs operator-lint
@@ -358,6 +362,7 @@ gowork: ## Generate go.work file
358362
test -f go.work || go work init
359363
go work use .
360364
go work use ./api
365+
go work sync
361366

362367
# Used for webhook testing
363368
# Please ensure the mariadb-controller-manager deployment and

api/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ require (
5252
github.com/spf13/pflag v1.0.5 // indirect
5353
go.uber.org/multierr v1.11.0 // indirect
5454
go.uber.org/zap v1.27.0 // indirect
55-
golang.org/x/exp v0.0.0-20240119083558-1b970713d09a // indirect
55+
golang.org/x/exp v0.0.0-20240205201215-2c58cdc269a3 // indirect
5656
golang.org/x/net v0.25.0 // indirect
5757
golang.org/x/oauth2 v0.8.0 // indirect
5858
golang.org/x/sys v0.20.0 // indirect

api/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
125125
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
126126
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
127127
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
128-
golang.org/x/exp v0.0.0-20240119083558-1b970713d09a h1:Q8/wZp0KX97QFTc2ywcOE0YRjZPVIx+MXInMzdvQqcA=
129-
golang.org/x/exp v0.0.0-20240119083558-1b970713d09a/go.mod h1:idGWGoKP1toJGkd5/ig9ZLuPcZBC3ewk7SzmH0uou08=
128+
golang.org/x/exp v0.0.0-20240205201215-2c58cdc269a3 h1:/RIbNt/Zr7rVhIkQhooTxCxFcdWLGIKnZA4IXNFSrvo=
129+
golang.org/x/exp v0.0.0-20240205201215-2c58cdc269a3/go.mod h1:idGWGoKP1toJGkd5/ig9ZLuPcZBC3ewk7SzmH0uou08=
130130
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
131131
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
132132
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=

api/test/helpers/harnesses.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import (
1717
"fmt"
1818
"time"
1919

20-
. "github.com/onsi/ginkgo/v2"
21-
. "github.com/onsi/gomega"
20+
. "github.com/onsi/ginkgo/v2" //revive:disable:dot-imports
21+
. "github.com/onsi/gomega" //revive:disable:dot-imports
2222
mariadbv1 "github.com/openstack-k8s-operators/mariadb-operator/api/v1beta1"
2323
"k8s.io/apimachinery/pkg/types"
2424
)
@@ -62,7 +62,6 @@ type MariaDBTestHarness struct {
6262
mariaDBHelper *TestHelper
6363
timeout time.Duration
6464
interval time.Duration
65-
runUpdate bool
6665
}
6766

6867
func (harness *MariaDBTestHarness) Setup(

api/v1beta1/galera_webhook.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ limitations under the License.
1717
package v1beta1
1818

1919
import (
20+
"fmt"
21+
2022
apierrors "k8s.io/apimachinery/pkg/api/errors"
2123
"k8s.io/apimachinery/pkg/runtime"
2224
"k8s.io/apimachinery/pkg/util/validation/field"
@@ -121,6 +123,11 @@ func (spec *GaleraSpecCore) ValidateCreate(basePath *field.Path) (admission.Warn
121123
func (r *Galera) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
122124
galeralog.Info("validate update", "name", r.Name)
123125

126+
oldGalera, ok := old.(*Galera)
127+
if !ok || oldGalera == nil {
128+
return nil, apierrors.NewInternalError(fmt.Errorf("unable to convert existing object"))
129+
}
130+
124131
// TODO(user): fill in your validation logic upon object update.
125132
return nil, nil
126133
}

api/v1beta1/mariadbdatabase_funcs.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -420,10 +420,9 @@ func (d *Database) loadDatabaseAndAccountCRs(
420420
h.GetBeforeObject(),
421421
err,
422422
)
423-
} else {
424-
d.account = mariaDBAccount
425-
d.secretObj = secretObj
426423
}
424+
d.account = mariaDBAccount
425+
d.secretObj = secretObj
427426

428427
return nil
429428
}
@@ -475,9 +474,12 @@ func (d *Database) DeleteFinalizer(
475474

476475
// also do a delete for "unused" MariaDBAccounts, associated with
477476
// this MariaDBDatabase.
478-
DeleteUnusedMariaDBAccountFinalizers(
477+
err = DeleteUnusedMariaDBAccountFinalizers(
479478
ctx, h, d.database.Name, d.account.Name, d.account.Namespace,
480479
)
480+
if err != nil && !k8s_errors.IsNotFound(err) {
481+
return err
482+
}
481483
}
482484
if controllerutil.RemoveFinalizer(d.database, h.GetFinalizer()) {
483485
err := h.GetClient().Update(ctx, d.database)

api/v1beta1/mariadbdatabase_funcs_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package v1beta1
1919
import (
2020
"testing"
2121

22-
. "github.com/onsi/gomega"
22+
. "github.com/onsi/gomega" //revive:disable:dot-imports
2323
"github.com/openstack-k8s-operators/lib-common/modules/common/tls"
2424
"k8s.io/utils/ptr"
2525
)

api/v1beta1/webhook_suite_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ import (
2525
"testing"
2626
"time"
2727

28-
. "github.com/onsi/ginkgo/v2"
29-
. "github.com/onsi/gomega"
28+
. "github.com/onsi/ginkgo/v2" //revive:disable:dot-imports
29+
. "github.com/onsi/gomega" //revive:disable:dot-imports
3030

3131
admissionv1beta1 "k8s.io/api/admission/v1beta1"
3232
//+kubebuilder:scaffold:imports

controllers/galera_controller.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ func isGaleraContainerStartedAndWaiting(ctx context.Context, pod *corev1.Pod, in
202202
waiting := false
203203
err := mariadb.ExecInPod(ctx, h, config, instance.Namespace, pod.Name, "galera",
204204
[]string{"/bin/bash", "-c", "test ! -f /var/lib/mysql/gcomm_uri && pgrep -aP1 | grep -o detect_gcomm_and_start.sh"},
205-
func(stdout *bytes.Buffer, stderr *bytes.Buffer) error {
205+
func(stdout *bytes.Buffer, _ *bytes.Buffer) error {
206206
predicate := strings.TrimSuffix(stdout.String(), "\n")
207207
waiting = (predicate == "detect_gcomm_and_start.sh")
208208
return nil
@@ -219,7 +219,7 @@ func isGaleraContainerStartedAndWaiting(ctx context.Context, pod *corev1.Pod, in
219219
func injectGcommURI(ctx context.Context, h *helper.Helper, config *rest.Config, instance *mariadbv1.Galera, pod *corev1.Pod, uri string) error {
220220
err := mariadb.ExecInPod(ctx, h, config, instance.Namespace, pod.Name, "galera",
221221
[]string{"/bin/bash", "-c", "echo '" + uri + "' > /var/lib/mysql/gcomm_uri"},
222-
func(stdout *bytes.Buffer, stderr *bytes.Buffer) error {
222+
func(_ *bytes.Buffer, _ *bytes.Buffer) error {
223223
attr := instance.Status.Attributes[pod.Name]
224224
attr.Gcomm = uri
225225
attr.ContainerID = pod.Status.ContainerStatuses[0].ContainerID
@@ -233,7 +233,7 @@ func injectGcommURI(ctx context.Context, h *helper.Helper, config *rest.Config,
233233
func retrieveSequenceNumber(ctx context.Context, helper *helper.Helper, config *rest.Config, instance *mariadbv1.Galera, pod *corev1.Pod) error {
234234
err := mariadb.ExecInPod(ctx, helper, config, instance.Namespace, pod.Name, "galera",
235235
[]string{"/bin/bash", "/var/lib/operator-scripts/detect_last_commit.sh"},
236-
func(stdout *bytes.Buffer, stderr *bytes.Buffer) error {
236+
func(stdout *bytes.Buffer, _ *bytes.Buffer) error {
237237
seqno := strings.TrimSuffix(stdout.String(), "\n")
238238
attr := mariadbv1.GaleraAttributes{
239239
Seqno: seqno,

0 commit comments

Comments
 (0)