diff --git a/Makefile b/Makefile index 0bed6c80..7e52ff0b 100644 --- a/Makefile +++ b/Makefile @@ -107,8 +107,9 @@ fmt: ## Run go fmt against code. go fmt ./... .PHONY: vet -vet: ## Run go vet against code. +vet: gowork ## Run go vet against code. go vet ./... + go vet ./api/... .PHONY: tidy tidy: ## Run go mod tidy on every mod file in the repo @@ -124,7 +125,7 @@ PROCS?=$(shell expr $(shell nproc --ignore 2) / 2) PROC_CMD = --procs ${PROCS} .PHONY: test -test: manifests generate fmt vet envtest ## Run tests. +test: manifests generate gowork fmt vet envtest ginkgo ## Run tests. for mod in $(shell find . -name go.mod -exec dirname {} \;); do \ pushd ./$$mod ; \ if [ -f test/functional/suite_test.go ]; then \ @@ -330,23 +331,26 @@ get-ci-tools: # Run go fmt against code gofmt: get-ci-tools - $(CI_TOOLS_REPO_DIR)/test-runner/gofmt.sh + GOWORK=off $(CI_TOOLS_REPO_DIR)/test-runner/gofmt.sh + GOWORK=off $(CI_TOOLS_REPO_DIR)/test-runner/gofmt.sh ./api # Run go vet against code govet: get-ci-tools - $(CI_TOOLS_REPO_DIR)/test-runner/govet.sh + GOWORK=off $(CI_TOOLS_REPO_DIR)/test-runner/govet.sh + GOWORK=off $(CI_TOOLS_REPO_DIR)/test-runner/govet.sh ./api # Run go test against code -gotest: get-ci-tools - $(CI_TOOLS_REPO_DIR)/test-runner/gotest.sh +gotest: test # Run golangci-lint test against code golangci: get-ci-tools - $(CI_TOOLS_REPO_DIR)/test-runner/golangci.sh + GOWORK=off $(CI_TOOLS_REPO_DIR)/test-runner/golangci.sh + GOWORK=off $(CI_TOOLS_REPO_DIR)/test-runner/golangci.sh ./api # Run go lint against code golint: get-ci-tools - PATH=$(GOBIN):$(PATH); $(CI_TOOLS_REPO_DIR)/test-runner/golint.sh + GOWORK=off PATH=$(GOBIN):$(PATH); $(CI_TOOLS_REPO_DIR)/test-runner/golint.sh + GOWORK=off PATH=$(GOBIN):$(PATH); $(CI_TOOLS_REPO_DIR)/test-runner/golint.sh ./api .PHONY: operator-lint operator-lint: $(LOCALBIN) gowork ## Runs operator-lint @@ -358,6 +362,7 @@ gowork: ## Generate go.work file test -f go.work || go work init go work use . go work use ./api + go work sync # Used for webhook testing # Please ensure the mariadb-controller-manager deployment and diff --git a/api/go.mod b/api/go.mod index 9e13b86a..c5bf28db 100644 --- a/api/go.mod +++ b/api/go.mod @@ -52,7 +52,7 @@ require ( github.com/spf13/pflag v1.0.5 // indirect go.uber.org/multierr v1.11.0 // indirect go.uber.org/zap v1.27.0 // indirect - golang.org/x/exp v0.0.0-20240119083558-1b970713d09a // indirect + golang.org/x/exp v0.0.0-20240205201215-2c58cdc269a3 // indirect golang.org/x/net v0.25.0 // indirect golang.org/x/oauth2 v0.8.0 // indirect golang.org/x/sys v0.20.0 // indirect diff --git a/api/go.sum b/api/go.sum index 68d73c65..a59e4345 100644 --- a/api/go.sum +++ b/api/go.sum @@ -125,8 +125,8 @@ go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/exp v0.0.0-20240119083558-1b970713d09a h1:Q8/wZp0KX97QFTc2ywcOE0YRjZPVIx+MXInMzdvQqcA= -golang.org/x/exp v0.0.0-20240119083558-1b970713d09a/go.mod h1:idGWGoKP1toJGkd5/ig9ZLuPcZBC3ewk7SzmH0uou08= +golang.org/x/exp v0.0.0-20240205201215-2c58cdc269a3 h1:/RIbNt/Zr7rVhIkQhooTxCxFcdWLGIKnZA4IXNFSrvo= +golang.org/x/exp v0.0.0-20240205201215-2c58cdc269a3/go.mod h1:idGWGoKP1toJGkd5/ig9ZLuPcZBC3ewk7SzmH0uou08= golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= diff --git a/api/test/helpers/harnesses.go b/api/test/helpers/harnesses.go index cd848f60..7d2a46ac 100644 --- a/api/test/helpers/harnesses.go +++ b/api/test/helpers/harnesses.go @@ -17,8 +17,8 @@ import ( "fmt" "time" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" + . "github.com/onsi/ginkgo/v2" //revive:disable:dot-imports + . "github.com/onsi/gomega" //revive:disable:dot-imports mariadbv1 "github.com/openstack-k8s-operators/mariadb-operator/api/v1beta1" "k8s.io/apimachinery/pkg/types" ) @@ -62,7 +62,6 @@ type MariaDBTestHarness struct { mariaDBHelper *TestHelper timeout time.Duration interval time.Duration - runUpdate bool } func (harness *MariaDBTestHarness) Setup( diff --git a/api/v1beta1/galera_webhook.go b/api/v1beta1/galera_webhook.go index ed3706bb..faa65d6d 100644 --- a/api/v1beta1/galera_webhook.go +++ b/api/v1beta1/galera_webhook.go @@ -17,6 +17,8 @@ limitations under the License. package v1beta1 import ( + "fmt" + apierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/validation/field" @@ -121,6 +123,11 @@ func (spec *GaleraSpecCore) ValidateCreate(basePath *field.Path) (admission.Warn func (r *Galera) ValidateUpdate(old runtime.Object) (admission.Warnings, error) { galeralog.Info("validate update", "name", r.Name) + oldGalera, ok := old.(*Galera) + if !ok || oldGalera == nil { + return nil, apierrors.NewInternalError(fmt.Errorf("unable to convert existing object")) + } + // TODO(user): fill in your validation logic upon object update. return nil, nil } diff --git a/api/v1beta1/mariadbdatabase_funcs.go b/api/v1beta1/mariadbdatabase_funcs.go index 15b5c36a..02f07570 100644 --- a/api/v1beta1/mariadbdatabase_funcs.go +++ b/api/v1beta1/mariadbdatabase_funcs.go @@ -420,10 +420,9 @@ func (d *Database) loadDatabaseAndAccountCRs( h.GetBeforeObject(), err, ) - } else { - d.account = mariaDBAccount - d.secretObj = secretObj } + d.account = mariaDBAccount + d.secretObj = secretObj return nil } @@ -475,9 +474,12 @@ func (d *Database) DeleteFinalizer( // also do a delete for "unused" MariaDBAccounts, associated with // this MariaDBDatabase. - DeleteUnusedMariaDBAccountFinalizers( + err = DeleteUnusedMariaDBAccountFinalizers( ctx, h, d.database.Name, d.account.Name, d.account.Namespace, ) + if err != nil && !k8s_errors.IsNotFound(err) { + return err + } } if controllerutil.RemoveFinalizer(d.database, h.GetFinalizer()) { err := h.GetClient().Update(ctx, d.database) diff --git a/api/v1beta1/mariadbdatabase_funcs_test.go b/api/v1beta1/mariadbdatabase_funcs_test.go index c9f98ca5..dcf783ec 100644 --- a/api/v1beta1/mariadbdatabase_funcs_test.go +++ b/api/v1beta1/mariadbdatabase_funcs_test.go @@ -19,7 +19,7 @@ package v1beta1 import ( "testing" - . "github.com/onsi/gomega" + . "github.com/onsi/gomega" //revive:disable:dot-imports "github.com/openstack-k8s-operators/lib-common/modules/common/tls" "k8s.io/utils/ptr" ) diff --git a/api/v1beta1/webhook_suite_test.go b/api/v1beta1/webhook_suite_test.go index ae2ca89f..7a920d02 100644 --- a/api/v1beta1/webhook_suite_test.go +++ b/api/v1beta1/webhook_suite_test.go @@ -25,8 +25,8 @@ import ( "testing" "time" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" + . "github.com/onsi/ginkgo/v2" //revive:disable:dot-imports + . "github.com/onsi/gomega" //revive:disable:dot-imports admissionv1beta1 "k8s.io/api/admission/v1beta1" //+kubebuilder:scaffold:imports diff --git a/controllers/galera_controller.go b/controllers/galera_controller.go index 4ca3fbd3..abac7c0c 100644 --- a/controllers/galera_controller.go +++ b/controllers/galera_controller.go @@ -202,7 +202,7 @@ func isGaleraContainerStartedAndWaiting(ctx context.Context, pod *corev1.Pod, in waiting := false err := mariadb.ExecInPod(ctx, h, config, instance.Namespace, pod.Name, "galera", []string{"/bin/bash", "-c", "test ! -f /var/lib/mysql/gcomm_uri && pgrep -aP1 | grep -o detect_gcomm_and_start.sh"}, - func(stdout *bytes.Buffer, stderr *bytes.Buffer) error { + func(stdout *bytes.Buffer, _ *bytes.Buffer) error { predicate := strings.TrimSuffix(stdout.String(), "\n") waiting = (predicate == "detect_gcomm_and_start.sh") return nil @@ -219,7 +219,7 @@ func isGaleraContainerStartedAndWaiting(ctx context.Context, pod *corev1.Pod, in func injectGcommURI(ctx context.Context, h *helper.Helper, config *rest.Config, instance *mariadbv1.Galera, pod *corev1.Pod, uri string) error { err := mariadb.ExecInPod(ctx, h, config, instance.Namespace, pod.Name, "galera", []string{"/bin/bash", "-c", "echo '" + uri + "' > /var/lib/mysql/gcomm_uri"}, - func(stdout *bytes.Buffer, stderr *bytes.Buffer) error { + func(_ *bytes.Buffer, _ *bytes.Buffer) error { attr := instance.Status.Attributes[pod.Name] attr.Gcomm = uri attr.ContainerID = pod.Status.ContainerStatuses[0].ContainerID @@ -233,7 +233,7 @@ func injectGcommURI(ctx context.Context, h *helper.Helper, config *rest.Config, func retrieveSequenceNumber(ctx context.Context, helper *helper.Helper, config *rest.Config, instance *mariadbv1.Galera, pod *corev1.Pod) error { err := mariadb.ExecInPod(ctx, helper, config, instance.Namespace, pod.Name, "galera", []string{"/bin/bash", "/var/lib/operator-scripts/detect_last_commit.sh"}, - func(stdout *bytes.Buffer, stderr *bytes.Buffer) error { + func(stdout *bytes.Buffer, _ *bytes.Buffer) error { seqno := strings.TrimSuffix(stdout.String(), "\n") attr := mariadbv1.GaleraAttributes{ Seqno: seqno,