Skip to content

Commit

Permalink
[MM-51581] Upgrade dependencies and cleanup (#347)
Browse files Browse the repository at this point in the history
* removed mysql-operator as a code dependency

* deps: testify to 1.8.2

* deps: golang.org/x/net v0.8.0

* deps: banzaicloud/k8s-objectmatcher v1.8.0

* deps: k8s.io and dependants

k8s.io/api v0.26.3
k8s.io/apimachinery v0.26.3
k8s.io/client-go v0.26.3
k8s.io/code-generator v0.26.3
k8s.io/kube-openapi v0.0.0-20230308215209-15aac26d736a
sigs.k8s.io/controller-runtime v0.14.5

Updated controller-gen code
Ignore modifications to mysql_operator files

* refactor: lint fixes

* tests: ineffassign false positive

* added trivy command to makefile

* github.com/go-logr/logr v1.2.3

* github.com/mattn/goveralls v0.0.12

* golang.org/x/net v0.10.0

* github.com/sirupsen/logrus v1.9.2

* github.com/stretchr/testify v1.8.3
  • Loading branch information
fmartingr authored May 23, 2023
1 parent 5835818 commit 51ca1a9
Show file tree
Hide file tree
Showing 1,765 changed files with 146,077 additions and 61,707 deletions.
16 changes: 14 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ BASE_IMAGE = gcr.io/distroless/static:nonroot
GO ?= $(shell command -v go 2> /dev/null)
PACKAGES=$(shell go list ./... | grep -v vendor)
TEST_PACKAGES=$(shell go list ./...| grep -v test/e2e)
TEST_FLAGS ?= -v

OPERATOR_IMAGE_NAME ?= mattermost/mattermost-operator
OPERATOR_IMAGE_TAG ?= test
Expand All @@ -31,6 +32,10 @@ BUILD_HASH := $(shell git rev-parse HEAD)
BUNDLE_IMG ?= controller-bundle:$(VERSION) # Default bundle image tag
CRD_OPTIONS ?= "crd" # Image URL to use all building/pushing image targets

TRIVY_SEVERITY := CRITICAL
TRIVY_EXIT_CODE := 1
TRIVY_VULN_TYPE := os,library

################################################################################

# Options for 'bundle-build'
Expand Down Expand Up @@ -104,7 +109,7 @@ KUSTOMIZE := $(TOOLS_BIN_DIR)/$(KUSTOMIZE_BIN)
all: generate check-style unittest build

unittest: ## Runs unit tests
$(GO) test -mod=vendor $(GO_LINKER_FLAGS) $(TEST_PACKAGES) -v -covermode=count -coverprofile=coverage.out
$(GO) test -mod=vendor $(GO_LINKER_FLAGS) $(TEST_PACKAGES) ${TEST_FLAGS} -covermode=count -coverprofile=coverage.out

e2e-local:
./test/e2e_local.sh
Expand Down Expand Up @@ -190,7 +195,7 @@ mysql-minio-operators: ## Deploys MinIO and MySQL Operators to the active cluste
./scripts/install-mysql-minio.sh

manifests: $(CONTROLLER_GEN) ## Runs CRD generator
$(CONTROLLER_GEN) $(CRD_OPTIONS) paths="./..." output:crd:artifacts:config=config/crd/bases
$(CONTROLLER_GEN) $(CRD_OPTIONS) paths="./apis/..." output:crd:artifacts:config=config/crd/bases

fmt: ## Run go fmt against code
go fmt ./...
Expand All @@ -204,6 +209,9 @@ vet: ## Run go vet against against all packages.
generate: $(OPENAPI_GEN) $(CONTROLLER_GEN) ## Runs the kubernetes code-generators and openapi
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."

# Revert any modification to the mysql-operator files
git checkout pkg/database/mysql_operator/*

## Grant permissions to execute generation script
chmod +x vendor/k8s.io/code-generator/generate-groups.sh

Expand Down Expand Up @@ -242,6 +250,10 @@ bundle: operator-sdk manifests ## Generate bundle manifests and metadata, then v
bundle-build: ## Build the bundle image.
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .

## Checks for vulnerabilities
trivy: build-image
@echo running trivy
@trivy image --format table --exit-code $(TRIVY_EXIT_CODE) --ignore-unfixed --vuln-type $(TRIVY_VULN_TYPE) --severity $(TRIVY_SEVERITY) $(OPERATOR_IMAGE)

## --------------------------------------
## Tooling Binaries
Expand Down
8 changes: 3 additions & 5 deletions apis/mattermost/v1beta1/patch_apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package v1beta1

import (
"bytes"

jsonpatch "github.com/evanphx/json-patch"
"github.com/pkg/errors"
appsv1 "k8s.io/api/apps/v1"
Expand Down Expand Up @@ -93,12 +94,9 @@ func (s *MattermostStatus) ClearServicePatchStatus() {
s.ResourcePatch.ServicePatch = nil
}

func (p Patch) applyPatch(resource runtime.Object,
destination runtime.Object,
gvk *schema.GroupVersionKind) error {

func (p Patch) applyPatch(resource, destination runtime.Object, gvk *schema.GroupVersionKind) error {
if p.Disable || len(p.Patch) == 0 {
destination = resource
destination = resource //nolint:staticcheck,ineffassign
return nil
}

Expand Down
38 changes: 35 additions & 3 deletions apis/mattermost/v1beta1/patch_apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ package v1beta1

import (
"fmt"
"os"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"io/ioutil"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"testing"
)

// TODO: tests can be extended to common patches and requests.
Expand Down Expand Up @@ -336,8 +337,39 @@ func Test_SetPatchStatus(t *testing.T) {
})
}

func TestPatch(t *testing.T) {
t.Run("replace type=NodePort", func(t *testing.T) {
p := Patch{
Disable: false,
Patch: `[{"op":"replace","path":"/spec/type", "value": "NodePort"}]`,
}

obj1 := &corev1.Service{}
obj2 := &corev1.Service{}
gvk := obj1.GroupVersionKind()
err := p.applyPatch(obj1, obj2, &gvk)
assert.NoError(t, err)
assert.NotEqual(t, &obj1, &obj2)
assert.NotEqual(t, obj1.Spec.Type, obj2.Spec.Type)
})

t.Run("empty patch, replace pointer", func(t *testing.T) {
p := Patch{
Disable: true,
}

obj1 := &corev1.Service{}
obj2 := &corev1.Service{}
gvk := obj1.GroupVersionKind()
err := p.applyPatch(obj1, obj2, &gvk)
assert.NoError(t, err)
assert.Equal(t, obj1.Spec.Type, obj2.Spec.Type)
assert.Equal(t, &obj1, &obj2)
})
}

func loadFile(t *testing.T, path string) string {
b, err := ioutil.ReadFile(path)
b, err := os.ReadFile(path)
require.NoError(t, err)
return string(b)
}
Expand Down
Loading

0 comments on commit 51ca1a9

Please sign in to comment.