Skip to content

Commit

Permalink
Merge pull request #247 from stuggi/align_makefile
Browse files Browse the repository at this point in the history
Align Makefile and fix golangci errors
  • Loading branch information
openshift-merge-bot[bot] authored Jul 18, 2024
2 parents bdbac5d + 2db59c8 commit f46a2aa
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 24 deletions.
21 changes: 13 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 \
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion api/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions api/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
5 changes: 2 additions & 3 deletions api/test/helpers/harnesses.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -62,7 +62,6 @@ type MariaDBTestHarness struct {
mariaDBHelper *TestHelper
timeout time.Duration
interval time.Duration
runUpdate bool
}

func (harness *MariaDBTestHarness) Setup(
Expand Down
7 changes: 7 additions & 0 deletions api/v1beta1/galera_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
10 changes: 6 additions & 4 deletions api/v1beta1/mariadbdatabase_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion api/v1beta1/mariadbdatabase_funcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
4 changes: 2 additions & 2 deletions api/v1beta1/webhook_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions controllers/galera_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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,
Expand Down

0 comments on commit f46a2aa

Please sign in to comment.