From aa46b5b8ffc39a33f8175a861641a9a4f23d1533 Mon Sep 17 00:00:00 2001 From: Tibor Kiss <32801432+the1bit@users.noreply.github.com> Date: Thu, 22 Feb 2024 16:06:36 +0100 Subject: [PATCH] chore: Linter configuration - Importas (#340) * Makefile * loggercheck * importas: metav1 * kcorev1 "k8s.io/api/core/v1" * kutilruntime "k8s.io/apimachinery/pkg/util/runtime" * kscheme "k8s.io/client-go/kubernetes/scheme" * kappsv1 "k8s.io/api/apps/v1" * kcontrollerruntime "sigs.k8s.io/controller-runtime" * k8s.io/api/apps/v1 * ktypes "k8s.io/apimachinery/pkg/types" * kapierrors "k8s.io/apimachinery/pkg/api/errors" * klogzap "sigs.k8s.io/controller-runtime/pkg/log/zap" * nmkmocks "github.com/kyma-project/nats-manager/pkg/k8s/mocks" * kapiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" * onsigomegatypes "github.com/onsi/gomega/types" * kapiextclientset "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset" * nmcontroller "github.com/kyma-project/nats-manager/internal/controller/nats" * nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" * kapipolicyv1 "k8s.io/api/policy/v1" * nmkchartmocks "github.com/kyma-project/nats-manager/pkg/k8s/chart/mocks" * kapiextclientsetfake "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/fake" * kutilyaml "k8s.io/apimachinery/pkg/util/yaml" * nmmanagermocks "github.com/kyma-project/nats-manager/pkg/manager/mocks" * nmctrlmocks "github.com/kyma-project/nats-manager/internal/controller/nats/mocks" * nmctrl * nmmgr "github.com/kyma-project/nats-manager/pkg/manager" * nmmgrmocks * nmctrlurl "github.com/kyma-project/nats-manager/internal/controller/nats/url" * nmmgrmocks * nmtsmatchers "github.com/kyma-project/nats-manager/testutils/matchers/nats" * keventsv1 "k8s.io/api/events/v1" * keventsv1 "k8s.io/api/events/v1" * natsgo "github.com/kyma-project/nats-manager/pkg/nats" * nmtsmatchers * nmnats "github.com/kyma-project/nats-manager/pkg/nats" * natsgo "github.com/nats-io/nats.go" * krbacv1 "k8s.io/api/rbac/v1" * kautoscalingv1 "k8s.io/api/autoscaling/v1" * nmctrlcache "github.com/kyma-project/nats-manager/internal/controller/cache" * nmlabels "github.com/kyma-project/nats-manager/pkg/labels" * Linter config --- .gitignore | 5 + .golangci.yaml | 487 +++++----- Makefile | 36 +- api/v1alpha1/nats_status.go | 42 +- api/v1alpha1/nats_status_test.go | 78 +- api/v1alpha1/nats_types.go | 22 +- api/v1alpha1/utils.go | 8 +- api/v1alpha1/utils_test.go | 92 +- cmd/main.go | 46 +- .../bases/operator.kyma-project.io_nats.yaml | 2 +- docs/user/02-configuration.md | 2 +- e2e/cleanup/cleanup_test.go | 20 +- e2e/common/fixtures/fixtures.go | 32 +- e2e/common/k8s.go | 8 +- e2e/setup/setup_test.go | 52 +- internal/controller/cache/cache.go | 34 +- internal/controller/cache/cache_test.go | 64 +- internal/controller/nats/controller.go | 80 +- internal/controller/nats/controller_test.go | 36 +- internal/controller/nats/deprovisioner.go | 54 +- .../controller/nats/deprovisioner_test.go | 128 +-- .../controller/integration_test.go | 111 +-- .../controllersinglecr/integration_test.go | 34 +- .../validation/integration_test.go | 92 +- internal/controller/nats/mocks/js.go | 836 +++++++++--------- internal/controller/nats/mocks/natsconn.go | 28 +- internal/controller/nats/provisioner.go | 46 +- internal/controller/nats/provisioner_test.go | 124 +-- internal/controller/nats/status.go | 22 +- internal/controller/nats/status_test.go | 84 +- internal/controller/nats/unit_test.go | 44 +- internal/controller/nats/utils.go | 18 +- internal/controller/nats/utils_test.go | 4 +- pkg/events/events.go | 12 +- pkg/k8s/chart/utils.go | 4 +- pkg/k8s/client.go | 40 +- pkg/k8s/client_test.go | 26 +- pkg/k8s/mocks/client.go | 48 +- pkg/manager/mocks/manager.go | 34 +- pkg/manager/nats.go | 4 +- pkg/manager/nats_test.go | 24 +- pkg/manager/options.go | 4 +- pkg/manager/options_test.go | 10 +- pkg/manager/overrides.go | 4 +- pkg/manager/overrides_test.go | 16 +- pkg/nats/client_unit_test.go | 32 +- pkg/nats/mocks/client.go | 16 +- testutils/integration/integration.go | 156 ++-- testutils/matchers/nats/matchers.go | 162 ++-- testutils/options.go | 70 +- testutils/utils.go | 78 +- 51 files changed, 1750 insertions(+), 1761 deletions(-) diff --git a/.gitignore b/.gitignore index 082e7f4c..1c7a4a01 100644 --- a/.gitignore +++ b/.gitignore @@ -42,3 +42,8 @@ nats-manager.yaml module-config.yaml .env.dev + + +.golangci.yaml +.golangci.yaml_old +lint-report.json \ No newline at end of file diff --git a/.golangci.yaml b/.golangci.yaml index 98406f50..52ddea41 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -1,19 +1,59 @@ -# This code is licensed under the terms of the MIT license. - -## Golden config for golangci-lint v1.49.0 -# -# This is the best config for golangci-lint based on my experience and opinion. -# It is very strict, but not extremely strict. -# Feel free to adopt and change it for your needs. - -run: - # Timeout for analysis, e.g. 30s, 5m. - # Default: 1m - timeout: 3m +linters: + enable-all: true + disable: + - contextcheck # too many false positives + - deadcode # deprecated (since v1.49.0) and replaced by 'unused' + - depguard # checks if package imports are whitelisted + - exhaustivestruct # deprecated (since v1.46.0) and replaced by 'exhaustruct' + - exhaustruct # TODO enable and fix, use regex to exclude certain cases + - golint # deprecated (since v1.41.0) and replaced by 'revive' + - ifshort # deprecated (since v1.48.0) + - interfacer # deprecated (since v1.38.0) + - lll + - maligned # deprecated (since v1.38.0) + - nlreturn # too strict and mostly code is not more readable + - nosnakecase # deprecated (since v1.48.1) and replaced by 'revive' + - scopelint # deprecated (since v1.39.0) and replaced by 'exportloopref' + - structcheck # deprecated (since v1.49.0) and replaced by 'unused' + - sqlclosecheck # not needed for this project + - varcheck # deprecated (since v1.49.0) and replaced by 'unused' + - wsl # too strict and mostly code is not more readable + - dupl + - forcetypeassert + - gosec + - inamedparam + - ireturn + - maintidx + - nolintlint + - paralleltest + - prealloc + - testpackage + - tparallel + - unconvert + - varnamelen + - wrapcheck + - gci + - tagalign + - dupword + - gomoddirectives + - gofumpt + - goerr113 + - funlen + - testifylint + - bodyclose + - containedctx + - thelper + - tagliatelle + - errchkjson + - perfsprint + - noctx + - godox + - goconst -# This file contains only configs which differ from defaults. -# All possible options can be found here https://github.com/golangci/golangci-lint/blob/master/.golangci.reference.yml linters-settings: + gomoddirectives: + replace-allow-list: + - github.com/prometheus/client_golang stylecheck: dot-import-whitelist: - github.com/onsi/ginkgo/v2 @@ -31,263 +71,176 @@ linters-settings: severity: warning disabled: true arguments: [120] - cyclop: - # The maximal code complexity to report. - # Default: 10 - max-complexity: 30 - # The maximal average package complexity. - # If it's higher than 0.0 (float) the check is enabled - # Default: 0.0 - package-average: 10.0 - - errcheck: - # Report about not checking of errors in type assertions: `a := b.(MyStruct)`. - # Such cases aren't reported by default. - # Default: false - check-type-assertions: true - funlen: - # Checks the number of lines in a function. - # If lower than 0, disable the check. - # Default: 60 lines: 100 - # Checks the number of statements in a function. - # If lower than 0, disable the check. - # Default: 40 - statements: 50 - - gocognit: - # Minimal code complexity to report - # Default: 30 (but we recommend 10-20) - min-complexity: 20 - - gocritic: - # Settings passed to gocritic. - # The settings key is the name of a supported gocritic checker. - # The list of supported checkers can be find in https://go-critic.github.io/overview. - settings: - captLocal: - # Whether to restrict checker to params only. - # Default: true - paramsOnly: false - underef: - # Whether to skip (*x).method() calls where x is a pointer receiver. - # Default: true - skipRecvDeref: false - - gomnd: - # List of function patterns to exclude from analysis. - # Values always ignored: `time.Date` - # Default: [] - ignored-functions: - - os.Chmod - - os.Mkdir - - os.MkdirAll - - os.OpenFile - - os.WriteFile - - prometheus.ExponentialBuckets - - prometheus.ExponentialBucketsRange - - prometheus.LinearBuckets - - strconv.FormatFloat - - strconv.FormatInt - - strconv.FormatUint - - strconv.ParseFloat - - strconv.ParseInt - - strconv.ParseUint - - gomodguard: - blocked: - # List of blocked modules. - # Default: [] - modules: - - github.com/golang/protobuf: - recommendations: - - google.golang.org/protobuf - reason: "see https://developers.google.com/protocol-buffers/docs/reference/go/faq#modules" - - github.com/satori/go.uuid: - recommendations: - - github.com/google/uuid - reason: "satori's package is not maintained" - - github.com/gofrs/uuid: - recommendations: - - github.com/google/uuid - reason: "see recommendation from dev-infra team: https://confluence.gtforge.com/x/gQI6Aw" - - govet: - # Enable all analyzers. - # Default: false - enable-all: true - # Disable analyzers by name. - # Run `go tool vet help` to see all analyzers. - # Default: [] - disable: - - fieldalignment # too strict - # Settings per analyzer. - settings: - shadow: - # Whether to be strict about shadowing; can be noisy. - # Default: false - strict: false - - nakedret: - # Make an issue if func has more lines of code than this setting, and it has naked returns. - # Default: 30 - max-func-lines: 0 - - nolintlint: - # Exclude following linters from requiring an explanation. - # Default: [] - allow-no-explanation: [funlen, gocognit, lll] - # Enable to require an explanation of nonzero length after each nolint directive. - # Default: false - require-explanation: true - # Enable to require nolint directives to mention the specific linter being suppressed. - # Default: false - require-specific: true - - rowserrcheck: - # database/sql is always checked - # Default: [] - packages: - - github.com/jmoiron/sqlx - - tenv: - # The option `all` will run against whole test files (`_test.go`) regardless of method/function signatures. - # Otherwise, only methods that take `*testing.T`, `*testing.B`, and `testing.TB` as arguments are checked. - # Default: false - all: true - -linters: - disable-all: true - enable: - ## enabled by default - - errcheck # checking for unchecked errors, these unchecked errors can be critical bugs in some cases - - gosimple # specializes in simplifying a code - - govet # reports suspicious constructs, such as Printf calls whose arguments do not align with the format string - - ineffassign # detects when assignments to existing variables are not used - - staticcheck # is a go vet on steroids, applying a ton of static analysis checks - - typecheck # like the front-end of a Go compiler, parses and type-checks Go code - - unused # checks for unused constants, variables, functions and types - ## disabled by default - - asasalint # checks for pass []any as any in variadic func(...any) - - asciicheck # checks that your code does not contain non-ASCII identifiers - - bidichk # checks for dangerous unicode character sequences - - bodyclose # checks whether HTTP response body is closed successfully - #- contextcheck # checks the function whether use a non-inherited context # TODO: enable after golangci-lint uses https://github.com/sylvia7788/contextcheck/releases/tag/v1.0.7 - - cyclop # checks function and package cyclomatic complexity - - dupl # tool for code clone detection - - durationcheck # checks for two durations multiplied together - - errname # checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error - - errorlint # finds code that will cause problems with the error wrapping scheme introduced in Go 1.13 - - execinquery # checks query string in Query function which reads your Go src files and warning it finds - - exhaustive # checks exhaustiveness of enum switch statements - - exportloopref # checks for pointers to enclosing loop variables - - forbidigo # forbids identifiers - - funlen # tool for detection of long functions - - gochecknoglobals # checks that no global variables exist - - gochecknoinits # checks that no init functions are present in Go code - - gocognit # computes and checks the cognitive complexity of functions - - goconst # finds repeated strings that could be replaced by a constant - - gocritic # provides diagnostics that check for bugs, performance and style issues - - gocyclo # computes and checks the cyclomatic complexity of functions - - godot # checks if comments end in a period - - goimports # in addition to fixing imports, goimports also formats your code in the same style as gofmt - - gomnd # detects magic numbers - ## - gomoddirectives # manages the use of 'replace', 'retract', and 'excludes' directives in go.mod - - gomodguard # allow and block lists linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations - - goprintffuncname # checks that printf-like functions are named with f at the end - - gosec # inspects source code for security problems - - lll # reports long lines - - makezero # finds slice declarations with non-zero initial length - - nakedret # finds naked returns in functions greater than a specified function length - - nestif # reports deeply nested if statements - - nilerr # finds the code that returns nil even if it checks that the error is not nil - - nilnil # checks that there is no simultaneous return of nil error and an invalid value - - noctx # finds sending http request without context.Context - - nolintlint # reports ill-formed or insufficient nolint directives - - nonamedreturns # reports all named returns - - nosprintfhostport # checks for misuse of Sprintf to construct a host with port in a URL - - predeclared # finds code that shadows one of Go's predeclared identifiers - - promlinter # checks Prometheus metrics naming via promlint - - reassign # checks that package variables are not reassigned - - revive # fast, configurable, extensible, flexible, and beautiful linter for Go, drop-in replacement of golint - - rowserrcheck # checks whether Err of rows is checked successfully - - sqlclosecheck # checks that sql.Rows and sql.Stmt are closed - - stylecheck # is a replacement for golint - - tenv # detects using os.Setenv instead of t.Setenv since Go1.17 - # - testpackage # makes you use a separate _test package - - tparallel # detects inappropriate usage of t.Parallel() method in your Go test codes - - unconvert # removes unnecessary type conversions - - unparam # reports unused function parameters - - usestdlibvars # detects the possibility to use variables/constants from the Go standard library - - wastedassign # finds wasted assignment statements - - whitespace # detects leading and trailing whitespace - - ## you may want to enable - #- decorder # checks declaration order and count of types, constants, variables and functions - #- exhaustruct # checks if all structure fields are initialized - #- gci # controls golang package import order and makes it always deterministic - #- godox # detects FIXME, TODO and other comment keywords - #- goheader # checks is file header matches to pattern - #- interfacebloat # checks the number of methods inside an interface - #- ireturn # accept interfaces, return concrete types - #- prealloc # [premature optimization, but can be used in some cases] finds slice declarations that could potentially be preallocated - #- varnamelen # [great idea, but too many false positives] checks that the length of a variable's name matches its scope - #- wrapcheck # checks that errors returned from external packages are wrapped - - ## disabled - #- containedctx # detects struct contained context.Context field - #- depguard # [replaced by gomodguard] checks if package imports are in a list of acceptable packages - #- dogsled # checks assignments with too many blank identifiers (e.g. x, _, _, _, := f()) - #- errchkjson # [don't see profit + I'm against of omitting errors like in the first example https://github.com/breml/errchkjson] checks types passed to the json encoding functions. Reports unsupported types and optionally reports occasions, where the check for the returned error can be omitted - #- forcetypeassert # [replaced by errcheck] finds forced type assertions - #- goerr113 # [too strict] checks the errors handling expressions - #- gofmt # [replaced by goimports] checks whether code was gofmt-ed - #- gofumpt # [replaced by goimports, gofumports is not available yet] checks whether code was gofumpt-ed - #- grouper # analyzes expression groups - #- importas # enforces consistent import aliases - #- logrlint # [owner archived repository] checks logr arguments - #- maintidx # measures the maintainability index of each function - #- misspell # [useless] finds commonly misspelled English words in comments - #- nlreturn # [too strict and mostly code is not more readable] checks for a new line before return and branch statements to increase code clarity - #- paralleltest # [too many false positives] detects missing usage of t.Parallel() method in your Go test - #- tagliatelle # checks the struct tags - #- thelper # detects golang test helpers without t.Helper() call and checks the consistency of test helpers - #- wsl # [too strict and mostly code is not more readable] whitespace linter forces you to use empty lines - - ## deprecated - #- deadcode # [deprecated, replaced by unused] finds unused code - #- exhaustivestruct # [deprecated, replaced by exhaustruct] checks if all struct's fields are initialized - #- golint # [deprecated, replaced by revive] golint differs from gofmt. Gofmt reformats Go source code, whereas golint prints out style mistakes - #- ifshort # [deprecated] checks that your code uses short syntax for if-statements whenever possible - #- interfacer # [deprecated] suggests narrower interface types - #- maligned # [deprecated, replaced by govet fieldalignment] detects Go structs that would take less memory if their fields were sorted - #- nosnakecase # [deprecated, replaced by revive var-naming] detects snake case of variable naming and function name - #- scopelint # [deprecated, replaced by exportloopref] checks for unpinned variables in go programs - #- structcheck # [deprecated, replaced by unused] finds unused struct fields - #- varcheck # [deprecated, replaced by unused] finds unused global variables and constants - + cyclop: + max-complexity: 20 + nestif: + min-complexity: 6 + gci: + sections: + - standard # Standard packages. + - default # Imports that could not be matched to another section type. + - prefix(github.com/kyma-project/eventing-manager) # Imports with the specified prefix. + - blank # Blank imports. + - dot # Dot imports. + custom-order: true + skip-generated: true + importas: + no-unaliased: false + no-extra-aliases: true + ## Version number must be added as suffix to the package name. As an example check `k8s.io/api/core/v1` + ## kubernetes APIs get the prefix `k`. As an example check `kcorev1` + ## Eventing Manager APIs get the prefix `em`. As an example check `emeventingv1alpha1` + ## Eventing Publisher Proxy APIs get the prefix `epp`. As an example check `eppapi` + ## Cloud Events APIs get the prefix `ce`. As an example check `ce` + ## Eventing Auth Manager APIs get the prefix `eam`. + ## Kyma Metrics Collector APIs get the prefix `kmc`. + ## NATS Manager APIs get the prefix `nm`. + + alias: + - pkg: "log" + alias: log + - pkg: k8s.io/api/core/v1 + alias: kcorev1 + - pkg: k8s.io/apimachinery/pkg/apis/meta/v1 + alias: kmetav1 + - pkg: k8s.io/client-go/dynamic/fake + alias: kdynamicfake + - pkg: github.com/nats-io/nats.go + alias: natsgo + - pkg: go.opencensus.io/trace/propagation + alias: ocpropagation + - pkg: github.com/kyma-project/eventing-publisher-proxy/testing + alias: epptestingutils + - pkg: github.com/kyma-project/eventing-publisher-proxy/pkg/legacy/api + alias: eppapi + - pkg: github.com/kyma-project/eventing-publisher-proxy/pkg/nats + alias: eppnats + - pkg: github.com/kyma-project/eventing-manager/pkg/logger + alias: emlogger + - pkg: github.com/kyma-project/eventing-manager/api/eventing/v1alpha1 + alias: emeventingv1alpha1 + - pkg: github.com/kyma-project/eventing-manager/api/eventing/v1alpha2 + alias: emeventingv2alpha1 + - pkg: github.com/cloudevents/sdk-go/v2 + alias: ce + - pkg: github.com/cloudevents/sdk-go/v2/protocol/http + alias: cehttp + - pkg: github.com/cloudevents/sdk-go/v2/event + alias: ceevent + - pkg: github.com/cloudevents/sdk-go/v2/client + alias: ceclient + - pkg: github.com/kyma-project/kyma/components/central-application-gateway/pkg/apis/applicationconnector/v1alpha1 + alias: kymaappconnv1alpha1 + + ###### + ### The following imports are used by github.com/kyma-project/eventing-auth-manager repository. + ###### + - pkg: github.com/kyma-project/eventing-auth-manager/internal/ias + alias: eamias + - pkg: github.com/kyma-project/eventing-auth-manager/controllers + alias: eamcontrollers + - pkg: github.com/kyma-project/eventing-auth-manager/api/v1alpha1 + alias: eamapiv1alpha1 + - pkg: github.com/kyma-project/eventing-auth-manager/internal/ias/internal/oidc/mocks + alias: eamoidcmocks + - pkg: github.com/kyma-project/lifecycle-manager/api/v1beta1 + alias: klmapiv1beta1 + - pkg: github.com/kyma-project/lifecycle-manager/api/v1beta2 + alias: klmapiv1beta2 + - pkg: k8s.io/apimachinery/pkg/api/errors + alias: kapierrors + - pkg: sigs.k8s.io/controller-runtime/pkg/client + alias: kpkgclient + - pkg: k8s.io/apimachinery/pkg/util/runtime + alias: kutilruntime + - pkg: k8s.io/client-go/kubernetes/scheme + alias: kscheme + - pkg: sigs.k8s.io/controller-runtime + alias: kcontrollerruntime + - pkg: github.com/onsi/gomega/types + alias: onsigomegatypes + - pkg: sigs.k8s.io/controller-runtime/pkg/log + alias: kpkglog + + ###### + ### The following imports are used by github.com/kyma-project/nats-manager repository. + ###### + - pkg: k8s.io/api/apps/v1 + alias: kappsv1 + - pkg: k8s.io/apimachinery/pkg/types + alias: ktypes + - pkg: sigs.k8s.io/controller-runtime/pkg/log/zap + alias: klogzap + - pkg: github.com/kyma-project/nats-manager/pkg/k8s/mocks + alias: nmkmocks + - pkg: k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1 + alias: kapiextv1 + - pkg: k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset + alias: kapiextclientset + - pkg: github.com/kyma-project/nats-manager/internal/controller/nats + alias: nmctrl + - pkg: github.com/kyma-project/nats-manager/api/v1alpha1 + alias: nmapiv1alpha1 + - pkg: k8s.io/api/policy/v1 + alias: kapipolicyv1 + - pkg: github.com/kyma-project/nats-manager/pkg/k8s/chart/mocks + alias: nmkchartmocks + - pkg: k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/fake + alias: kapiextclientsetfake + - pkg: k8s.io/apimachinery/pkg/util/yaml + alias: kutilyaml + - pkg: github.com/kyma-project/nats-manager/pkg/manager/mocks + alias: nmmgrmocks + - pkg: github.com/kyma-project/nats-manager/internal/controller/nats/mocks + alias: nmctrlmocks + - pkg: github.com/kyma-project/nats-manager/pkg/manager + alias: nmmgr + - pkg: github.com/kyma-project/nats-manager/internal/controller/nats/url + alias: nmctrlurl + - pkg: github.com/kyma-project/nats-manager/testutils/matchers/nats + alias: nmtsmatchers + - pkg: k8s.io/api/events/v1 + alias: keventsv1 + - pkg: github.com/kyma-project/nats-manager/pkg/nats + alias: nmnats + - pkg: k8s.io/api/rbac/v1 + alias: krbacv1 + - pkg: k8s.io/api/autoscaling/v1 + alias: kautoscalingv1 + - pkg: github.com/kyma-project/nats-manager/internal/controller/cache + alias: nmctrlcache + - pkg: github.com/kyma-project/nats-manager/pkg/labels + alias: nmlabels + + ireturn: + allow: + - anon + - error + - empty + - stdlib + - Client + - client.Object + - (or|er)$ + wrapcheck: + ignorePackageGlobs: issues: - # Maximum count of issues with the same text. - # Set to 0 to disable. - # Default: 3 - max-same-issues: 30 - exclude-rules: - - source: "^//\\s*go:generate\\s" - linters: [lll] - - source: "(noinspection|TODO)" - linters: [godot] - - source: "//noinspection" - linters: [gocritic] - - source: "^\\s+if _, ok := err\\.\\([^.]+\\.InternalError\\); ok {" - linters: [errorlint] - path: "_test\\.go" linters: - - bodyclose - - dupl - - funlen - - goconst - - gosec - - noctx - wrapcheck + - gochecknoglobals + - funlen # Table driven unit and integration tests exceed function length by design + - maintidx # Table driven unit and integration tests exceed maintainability index by design + - linters: + - importas + text: has alias "" which is not part of config # Ignore false positives that emerged due to https://github.com/julz/importas/issues/15. + max-issues-per-linter: 0 + max-same-issues: 0 +output: + sort-results: true +run: + timeout: 15m + skip-files: + - zz_generated.deepcopy.go diff --git a/Makefile b/Makefile index af2c3e6a..0351d788 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,9 @@ endif # Module Name used for bundling the OCI Image and later on for referencing in the Kyma Modules MODULE_NAME ?= nats +# Lint issue category +CATEGORY = "default" + # Operating system architecture OS_ARCH ?= $(shell uname -m) @@ -104,6 +107,36 @@ generate-and-test: vendor manifests generate fmt imports vet lint test; test: envtest ## Run only tests. KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out +.PHONY: lint +lint: ## Check lint issues using `golangci-lint` + golangci-lint run --timeout 5m --config=./.golangci.yaml + +.PHONY: lint-compact +lint-compact: ## Check lint issues using `golangci-lint` in compact result format + golangci-lint run --timeout 5m --config=./.golangci.yaml --print-issued-lines=false + +.PHONY: lint-fix +lint-fix: ## Check and fix lint issues using `golangci-lint` + golangci-lint run --fix --timeout 5m --config=./.golangci.yaml + +.PHONY: lint-report +lint-report: ## Check lint issues using `golangci-lint` then export them to a file, then print the list of linters used + golangci-lint run --timeout 5m --config=./.golangci.yaml --issues-exit-code 0 --out-format json > ./lint-report.json + +.PHONY: lint-report-issue-category +lint-report-issue-category: ## Get lint issues categories + make lint-report-clean + make lint-report + cat ./lint-report.json | jq '.Issues[].FromLinter' | jq -s 'map({(.):1})|add|keys_unsorted' + +.PHONY: lint-report-get-category +lint-report-get-category: ## Get lint issues by category + cat ./lint-report.json | jq --arg CATEGORY $$CATEGORY '.Issues[] | select(.FromLinter==$$CATEGORY)' + +.PHONY: lint-report-clean +lint-report-clean: ## Clean lint report + rm -f ./lint-report.json + ##@ Build .PHONY: build @@ -226,9 +259,6 @@ envtest: $(ENVTEST) ## Download envtest-setup locally if necessary. $(ENVTEST): $(LOCALBIN) test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest -lint: - golangci-lint run --fix - go-gen: go generate ./... diff --git a/api/v1alpha1/nats_status.go b/api/v1alpha1/nats_status.go index c28a4d65..75dbe0ef 100644 --- a/api/v1alpha1/nats_status.go +++ b/api/v1alpha1/nats_status.go @@ -4,7 +4,7 @@ import ( "reflect" "k8s.io/apimachinery/pkg/api/meta" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) func (ns *NATSStatus) IsEqual(status NATSStatus) bool { @@ -12,14 +12,14 @@ func (ns *NATSStatus) IsEqual(status NATSStatus) bool { statusWithoutCond := status.DeepCopy() // remove conditions, so that we don't compare them - thisWithoutCond.Conditions = []metav1.Condition{} - statusWithoutCond.Conditions = []metav1.Condition{} + thisWithoutCond.Conditions = []kmetav1.Condition{} + statusWithoutCond.Conditions = []kmetav1.Condition{} return reflect.DeepEqual(thisWithoutCond, statusWithoutCond) && ConditionsEquals(ns.Conditions, status.Conditions) } -func (ns *NATSStatus) FindCondition(conditionType ConditionType) *metav1.Condition { +func (ns *NATSStatus) FindCondition(conditionType ConditionType) *kmetav1.Condition { for _, condition := range ns.Conditions { if string(conditionType) == condition.Type { return &condition @@ -28,24 +28,24 @@ func (ns *NATSStatus) FindCondition(conditionType ConditionType) *metav1.Conditi return nil } -func (ns *NATSStatus) UpdateConditionStatefulSet(status metav1.ConditionStatus, reason ConditionReason, +func (ns *NATSStatus) UpdateConditionStatefulSet(status kmetav1.ConditionStatus, reason ConditionReason, message string) { - condition := metav1.Condition{ + condition := kmetav1.Condition{ Type: string(ConditionStatefulSet), Status: status, - LastTransitionTime: metav1.Now(), + LastTransitionTime: kmetav1.Now(), Reason: string(reason), Message: message, } meta.SetStatusCondition(&ns.Conditions, condition) } -func (ns *NATSStatus) UpdateConditionAvailable(status metav1.ConditionStatus, reason ConditionReason, +func (ns *NATSStatus) UpdateConditionAvailable(status kmetav1.ConditionStatus, reason ConditionReason, message string) { - condition := metav1.Condition{ + condition := kmetav1.Condition{ Type: string(ConditionAvailable), Status: status, - LastTransitionTime: metav1.Now(), + LastTransitionTime: kmetav1.Now(), Reason: string(reason), Message: message, } @@ -54,9 +54,9 @@ func (ns *NATSStatus) UpdateConditionAvailable(status metav1.ConditionStatus, re func (ns *NATSStatus) SetStateReady() { ns.State = StateReady - ns.UpdateConditionStatefulSet(metav1.ConditionTrue, + ns.UpdateConditionStatefulSet(kmetav1.ConditionTrue, ConditionReasonStatefulSetAvailable, "StatefulSet is ready") - ns.UpdateConditionAvailable(metav1.ConditionTrue, ConditionReasonDeployed, "NATS is deployed") + ns.UpdateConditionAvailable(kmetav1.ConditionTrue, ConditionReasonDeployed, "NATS is deployed") } func (ns *NATSStatus) SetStateProcessing() { @@ -69,27 +69,27 @@ func (ns *NATSStatus) SetStateWarning() { func (ns *NATSStatus) SetWaitingStateForStatefulSet() { ns.SetStateProcessing() - ns.UpdateConditionStatefulSet(metav1.ConditionFalse, + ns.UpdateConditionStatefulSet(kmetav1.ConditionFalse, ConditionReasonStatefulSetPending, "") - ns.UpdateConditionAvailable(metav1.ConditionFalse, ConditionReasonDeploying, "") + ns.UpdateConditionAvailable(kmetav1.ConditionFalse, ConditionReasonDeploying, "") } func (ns *NATSStatus) SetStateError() { ns.State = StateError - ns.UpdateConditionStatefulSet(metav1.ConditionFalse, ConditionReasonSyncFailError, "") - ns.UpdateConditionAvailable(metav1.ConditionFalse, ConditionReasonProcessingError, "") + ns.UpdateConditionStatefulSet(kmetav1.ConditionFalse, ConditionReasonSyncFailError, "") + ns.UpdateConditionAvailable(kmetav1.ConditionFalse, ConditionReasonProcessingError, "") } func (ns *NATSStatus) SetStateDeleting() { ns.State = StateDeleting } -func (ns *NATSStatus) UpdateConditionDeletion(status metav1.ConditionStatus, reason ConditionReason, +func (ns *NATSStatus) UpdateConditionDeletion(status kmetav1.ConditionStatus, reason ConditionReason, message string) { - condition := metav1.Condition{ + condition := kmetav1.Condition{ Type: string(ConditionDeleted), Status: status, - LastTransitionTime: metav1.Now(), + LastTransitionTime: kmetav1.Now(), Reason: string(reason), Message: message, } @@ -98,8 +98,8 @@ func (ns *NATSStatus) UpdateConditionDeletion(status metav1.ConditionStatus, rea func (ns *NATSStatus) Initialize() { ns.SetStateProcessing() - ns.UpdateConditionStatefulSet(metav1.ConditionFalse, ConditionReasonProcessing, "") - ns.UpdateConditionAvailable(metav1.ConditionFalse, ConditionReasonProcessing, "") + ns.UpdateConditionStatefulSet(kmetav1.ConditionFalse, ConditionReasonProcessing, "") + ns.UpdateConditionAvailable(kmetav1.ConditionFalse, ConditionReasonProcessing, "") } // ClearURL clears the url. diff --git a/api/v1alpha1/nats_status_test.go b/api/v1alpha1/nats_status_test.go index 9d28d4a6..58b7e669 100644 --- a/api/v1alpha1/nats_status_test.go +++ b/api/v1alpha1/nats_status_test.go @@ -6,7 +6,7 @@ import ( "time" "github.com/stretchr/testify/require" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) func Test_IsEqual(t *testing.T) { @@ -20,14 +20,14 @@ func Test_IsEqual(t *testing.T) { { name: "should not be equal if the conditions are not equal", natsStatus1: NATSStatus{ - Conditions: []metav1.Condition{ - {Type: string(ConditionAvailable), Status: metav1.ConditionTrue}, + Conditions: []kmetav1.Condition{ + {Type: string(ConditionAvailable), Status: kmetav1.ConditionTrue}, }, State: StateReady, }, natsStatus2: NATSStatus{ - Conditions: []metav1.Condition{ - {Type: string(ConditionAvailable), Status: metav1.ConditionFalse}, + Conditions: []kmetav1.Condition{ + {Type: string(ConditionAvailable), Status: kmetav1.ConditionFalse}, }, State: StateReady, }, @@ -36,14 +36,14 @@ func Test_IsEqual(t *testing.T) { { name: "should not be equal if the ready status is not equal", natsStatus1: NATSStatus{ - Conditions: []metav1.Condition{ - {Type: string(ConditionAvailable), Status: metav1.ConditionTrue}, + Conditions: []kmetav1.Condition{ + {Type: string(ConditionAvailable), Status: kmetav1.ConditionTrue}, }, State: StateReady, }, natsStatus2: NATSStatus{ - Conditions: []metav1.Condition{ - {Type: string(ConditionAvailable), Status: metav1.ConditionTrue}, + Conditions: []kmetav1.Condition{ + {Type: string(ConditionAvailable), Status: kmetav1.ConditionTrue}, }, State: StateProcessing, }, @@ -52,14 +52,14 @@ func Test_IsEqual(t *testing.T) { { name: "should be equal if all the fields are equal", natsStatus1: NATSStatus{ - Conditions: []metav1.Condition{ - {Type: string(ConditionAvailable), Status: metav1.ConditionTrue}, + Conditions: []kmetav1.Condition{ + {Type: string(ConditionAvailable), Status: kmetav1.ConditionTrue}, }, State: StateReady, }, natsStatus2: NATSStatus{ - Conditions: []metav1.Condition{ - {Type: string(ConditionAvailable), Status: metav1.ConditionTrue}, + Conditions: []kmetav1.Condition{ + {Type: string(ConditionAvailable), Status: kmetav1.ConditionTrue}, }, State: StateReady, }, @@ -77,40 +77,40 @@ func Test_IsEqual(t *testing.T) { } func Test_FindCondition(t *testing.T) { - currentTime := metav1.NewTime(time.Now()) + currentTime := kmetav1.NewTime(time.Now()) testCases := []struct { name string - givenConditions []metav1.Condition + givenConditions []kmetav1.Condition findConditionType ConditionType - wantCondition *metav1.Condition + wantCondition *kmetav1.Condition }{ { name: "should be able to find the present condition", - givenConditions: []metav1.Condition{ + givenConditions: []kmetav1.Condition{ { Type: string(ConditionAvailable), - Status: metav1.ConditionTrue, + Status: kmetav1.ConditionTrue, LastTransitionTime: currentTime, }, { Type: string(ConditionStatefulSet), - Status: metav1.ConditionTrue, + Status: kmetav1.ConditionTrue, LastTransitionTime: currentTime, }, }, findConditionType: ConditionAvailable, - wantCondition: &metav1.Condition{ + wantCondition: &kmetav1.Condition{ Type: string(ConditionAvailable), - Status: metav1.ConditionTrue, + Status: kmetav1.ConditionTrue, LastTransitionTime: currentTime, }, }, { name: "should not be able to find the non-present condition", - givenConditions: []metav1.Condition{ + givenConditions: []kmetav1.Condition{ { Type: string(ConditionStatefulSet), - Status: metav1.ConditionTrue, + Status: kmetav1.ConditionTrue, LastTransitionTime: currentTime, }, }, @@ -140,10 +140,10 @@ func Test_UpdateConditionStatefulSet(t *testing.T) { // given natsStatus1 := &NATSStatus{ - Conditions: []metav1.Condition{ + Conditions: []kmetav1.Condition{ { Type: string(ConditionStatefulSet), - Status: metav1.ConditionFalse, + Status: kmetav1.ConditionFalse, Reason: "", Message: "", }, @@ -151,7 +151,7 @@ func Test_UpdateConditionStatefulSet(t *testing.T) { State: StateReady, } - givenStatus := metav1.ConditionTrue + givenStatus := kmetav1.ConditionTrue givenReason := ConditionReasonProcessing givenMessage := "test123" @@ -175,10 +175,10 @@ func Test_UpdateConditionAvailable(t *testing.T) { // given natsStatus1 := &NATSStatus{ - Conditions: []metav1.Condition{ + Conditions: []kmetav1.Condition{ { Type: string(ConditionAvailable), - Status: metav1.ConditionFalse, + Status: kmetav1.ConditionFalse, Reason: "", Message: "", }, @@ -186,7 +186,7 @@ func Test_UpdateConditionAvailable(t *testing.T) { State: StateReady, } - givenStatus := metav1.ConditionTrue + givenStatus := kmetav1.ConditionTrue givenReason := ConditionReasonProcessing givenMessage := "test123" @@ -284,24 +284,24 @@ func Test_SetWaitingStateForStatefulSet(t *testing.T) { t.Run("should update the condition", func(t *testing.T) { t.Parallel() - currentTime := metav1.NewTime(time.Now()) + currentTime := kmetav1.NewTime(time.Now()) // given natsStatus1 := &NATSStatus{ State: StateError, } - expectedSTSCondition := &metav1.Condition{ + expectedSTSCondition := &kmetav1.Condition{ Type: string(ConditionStatefulSet), - Status: metav1.ConditionFalse, + Status: kmetav1.ConditionFalse, Reason: string(ConditionReasonStatefulSetPending), Message: "", LastTransitionTime: currentTime, } - expectedAvailableCondition := &metav1.Condition{ + expectedAvailableCondition := &kmetav1.Condition{ Type: string(ConditionAvailable), - Status: metav1.ConditionFalse, + Status: kmetav1.ConditionFalse, Reason: string(ConditionReasonDeploying), Message: "", LastTransitionTime: currentTime, @@ -332,24 +332,24 @@ func Test_Initialize(t *testing.T) { t.Run("should update the condition", func(t *testing.T) { t.Parallel() - currentTime := metav1.NewTime(time.Now()) + currentTime := kmetav1.NewTime(time.Now()) // given natsStatus1 := &NATSStatus{ State: StateError, } - expectedSTSCondition := &metav1.Condition{ + expectedSTSCondition := &kmetav1.Condition{ Type: string(ConditionStatefulSet), - Status: metav1.ConditionFalse, + Status: kmetav1.ConditionFalse, Reason: string(ConditionReasonProcessing), Message: "", LastTransitionTime: currentTime, } - expectedAvailableCondition := &metav1.Condition{ + expectedAvailableCondition := &kmetav1.Condition{ Type: string(ConditionAvailable), - Status: metav1.ConditionFalse, + Status: kmetav1.ConditionFalse, Reason: string(ConditionReasonProcessing), Message: "", LastTransitionTime: currentTime, diff --git a/api/v1alpha1/nats_types.go b/api/v1alpha1/nats_types.go index 3d51249c..19fc2147 100644 --- a/api/v1alpha1/nats_types.go +++ b/api/v1alpha1/nats_types.go @@ -20,9 +20,9 @@ limitations under the License. package v1alpha1 import ( - corev1 "k8s.io/api/core/v1" + kcorev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) type ConditionReason string @@ -79,8 +79,8 @@ undefined they will be interpreted as "" and result in 0 instead of being replac // +kubebuilder:printcolumn:name="State",type="string",JSONPath=".status.state",description="State of NATS deployment" // +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="Age of the resource" type NATS struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` + kmetav1.TypeMeta `json:",inline"` + kmetav1.ObjectMeta `json:"metadata,omitempty"` // +kubebuilder:default:={jetStream:{fileStorage:{storageClassName:"default", size:"1Gi"},memStorage:{size:"1Gi",enabled:true}}, cluster:{size:3},logging:{trace:false,debug:false}, resources:{limits:{cpu:"500m",memory:"1Gi"}, requests:{cpu:"40m",memory:"64Mi"}}} Spec NATSSpec `json:"spec,omitempty"` @@ -89,9 +89,9 @@ type NATS struct { // NATSStatus defines the observed state of NATS. type NATSStatus struct { - State string `json:"state"` - URL string `json:"url,omitempty"` - Conditions []metav1.Condition `json:"conditions,omitempty"` + State string `json:"state"` + URL string `json:"url,omitempty"` + Conditions []kmetav1.Condition `json:"conditions,omitempty"` } // NATSSpec defines the desired state of NATS. @@ -111,7 +111,7 @@ type NATSSpec struct { // Resources defines resources for NATS. // +kubebuilder:default:={limits:{cpu:"500m",memory:"1Gi"}, requests:{cpu:"40m",memory:"64Mi"}} - Resources corev1.ResourceRequirements `json:"resources,omitempty"` + Resources kcorev1.ResourceRequirements `json:"resources,omitempty"` // Annotations allows to add annotations to NATS. Annotations map[string]string `json:"annotations,omitempty"` @@ -182,9 +182,9 @@ type Logging struct { // NATSList contains a list of NATS. type NATSList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata,omitempty"` - Items []NATS `json:"items"` + kmetav1.TypeMeta `json:",inline"` + kmetav1.ListMeta `json:"metadata,omitempty"` + Items []NATS `json:"items"` } func (n *NATS) IsInDeletion() bool { diff --git a/api/v1alpha1/utils.go b/api/v1alpha1/utils.go index 886ecfd3..9a4366c3 100644 --- a/api/v1alpha1/utils.go +++ b/api/v1alpha1/utils.go @@ -1,18 +1,18 @@ package v1alpha1 import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) // ConditionsEquals checks if two list of conditions are equal. -func ConditionsEquals(existing, expected []metav1.Condition) bool { +func ConditionsEquals(existing, expected []kmetav1.Condition) bool { // not equal if length is different if len(existing) != len(expected) { return false } // compile map of Conditions per ConditionType - existingMap := make(map[ConditionType]metav1.Condition, len(existing)) + existingMap := make(map[ConditionType]kmetav1.Condition, len(existing)) for _, value := range existing { existingMap[ConditionType(value.Type)] = value } @@ -27,7 +27,7 @@ func ConditionsEquals(existing, expected []metav1.Condition) bool { } // ConditionEquals checks if two conditions are equal. -func ConditionEquals(existing, expected metav1.Condition) bool { +func ConditionEquals(existing, expected kmetav1.Condition) bool { isTypeEqual := existing.Type == expected.Type isStatusEqual := existing.Status == expected.Status isReasonEqual := existing.Reason == expected.Reason diff --git a/api/v1alpha1/utils_test.go b/api/v1alpha1/utils_test.go index 274e3dbb..530380bc 100644 --- a/api/v1alpha1/utils_test.go +++ b/api/v1alpha1/utils_test.go @@ -3,75 +3,75 @@ package v1alpha1 import ( "testing" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) func Test_conditionEquals(t *testing.T) { testCases := []struct { name string - condition1 metav1.Condition - condition2 metav1.Condition + condition1 kmetav1.Condition + condition2 kmetav1.Condition wantEqualStatus bool }{ { name: "should not be equal if the types are the same but the status is different", - condition1: metav1.Condition{ - Type: string(ConditionAvailable), Status: metav1.ConditionTrue, + condition1: kmetav1.Condition{ + Type: string(ConditionAvailable), Status: kmetav1.ConditionTrue, }, - condition2: metav1.Condition{ - Type: string(ConditionAvailable), Status: metav1.ConditionUnknown, + condition2: kmetav1.Condition{ + Type: string(ConditionAvailable), Status: kmetav1.ConditionUnknown, }, wantEqualStatus: false, }, { name: "should not be equal if the types are different but the status is the same", - condition1: metav1.Condition{ - Type: string(ConditionAvailable), Status: metav1.ConditionTrue, + condition1: kmetav1.Condition{ + Type: string(ConditionAvailable), Status: kmetav1.ConditionTrue, }, - condition2: metav1.Condition{ - Type: string(ConditionStatefulSet), Status: metav1.ConditionTrue, + condition2: kmetav1.Condition{ + Type: string(ConditionStatefulSet), Status: kmetav1.ConditionTrue, }, wantEqualStatus: false, }, { name: "should not be equal if the message fields are different", - condition1: metav1.Condition{ - Type: string(ConditionAvailable), Status: metav1.ConditionTrue, Message: "", + condition1: kmetav1.Condition{ + Type: string(ConditionAvailable), Status: kmetav1.ConditionTrue, Message: "", }, - condition2: metav1.Condition{ - Type: string(ConditionAvailable), Status: metav1.ConditionTrue, Message: "some message", + condition2: kmetav1.Condition{ + Type: string(ConditionAvailable), Status: kmetav1.ConditionTrue, Message: "some message", }, wantEqualStatus: false, }, { name: "should not be equal if the reason fields are different", - condition1: metav1.Condition{ + condition1: kmetav1.Condition{ Type: string(ConditionAvailable), - Status: metav1.ConditionTrue, + Status: kmetav1.ConditionTrue, Reason: string(ConditionReasonProcessing), }, - condition2: metav1.Condition{ + condition2: kmetav1.Condition{ Type: string(ConditionAvailable), - Status: metav1.ConditionTrue, + Status: kmetav1.ConditionTrue, Reason: string(ConditionReasonProcessingError), }, wantEqualStatus: false, }, { name: "should be equal if all the fields are the same", - condition1: metav1.Condition{ + condition1: kmetav1.Condition{ Type: string(ConditionAvailable), - Status: metav1.ConditionFalse, + Status: kmetav1.ConditionFalse, Reason: string(ConditionReasonProcessing), Message: "nats is not ready", }, - condition2: metav1.Condition{ + condition2: kmetav1.Condition{ Type: string(ConditionAvailable), - Status: metav1.ConditionFalse, + Status: kmetav1.ConditionFalse, Reason: string(ConditionReasonProcessing), Message: "nats is not ready", }, @@ -92,57 +92,57 @@ func Test_conditionEquals(t *testing.T) { func Test_conditionsEquals(t *testing.T) { testCases := []struct { name string - conditionsSet1 []metav1.Condition - conditionsSet2 []metav1.Condition + conditionsSet1 []kmetav1.Condition + conditionsSet2 []kmetav1.Condition wantEqualStatus bool }{ { name: "should not be equal if the number of conditions are not equal", - conditionsSet1: []metav1.Condition{ - {Type: string(ConditionAvailable), Status: metav1.ConditionTrue}, + conditionsSet1: []kmetav1.Condition{ + {Type: string(ConditionAvailable), Status: kmetav1.ConditionTrue}, }, - conditionsSet2: []metav1.Condition{}, + conditionsSet2: []kmetav1.Condition{}, wantEqualStatus: false, }, { name: "should be equal if the conditions are the same", - conditionsSet1: []metav1.Condition{ - {Type: string(ConditionAvailable), Status: metav1.ConditionTrue}, - {Type: string(ConditionStatefulSet), Status: metav1.ConditionTrue}, + conditionsSet1: []kmetav1.Condition{ + {Type: string(ConditionAvailable), Status: kmetav1.ConditionTrue}, + {Type: string(ConditionStatefulSet), Status: kmetav1.ConditionTrue}, }, - conditionsSet2: []metav1.Condition{ - {Type: string(ConditionAvailable), Status: metav1.ConditionTrue}, - {Type: string(ConditionStatefulSet), Status: metav1.ConditionTrue}, + conditionsSet2: []kmetav1.Condition{ + {Type: string(ConditionAvailable), Status: kmetav1.ConditionTrue}, + {Type: string(ConditionStatefulSet), Status: kmetav1.ConditionTrue}, }, wantEqualStatus: true, }, { name: "should not be equal if the condition types are different", - conditionsSet1: []metav1.Condition{ - {Type: string(ConditionAvailable), Status: metav1.ConditionTrue}, + conditionsSet1: []kmetav1.Condition{ + {Type: string(ConditionAvailable), Status: kmetav1.ConditionTrue}, }, - conditionsSet2: []metav1.Condition{ - {Type: string(ConditionStatefulSet), Status: metav1.ConditionTrue}, + conditionsSet2: []kmetav1.Condition{ + {Type: string(ConditionStatefulSet), Status: kmetav1.ConditionTrue}, }, wantEqualStatus: false, }, { name: "should not be equal if the condition types are the same but the status is different", - conditionsSet1: []metav1.Condition{ - {Type: string(ConditionAvailable), Status: metav1.ConditionTrue}, + conditionsSet1: []kmetav1.Condition{ + {Type: string(ConditionAvailable), Status: kmetav1.ConditionTrue}, }, - conditionsSet2: []metav1.Condition{ - {Type: string(ConditionAvailable), Status: metav1.ConditionFalse}, + conditionsSet2: []kmetav1.Condition{ + {Type: string(ConditionAvailable), Status: kmetav1.ConditionFalse}, }, wantEqualStatus: false, }, { name: "should not be equal if the condition types are different but the status is the same", - conditionsSet1: []metav1.Condition{ - {Type: string(ConditionAvailable), Status: metav1.ConditionTrue}, + conditionsSet1: []kmetav1.Condition{ + {Type: string(ConditionAvailable), Status: kmetav1.ConditionTrue}, }, - conditionsSet2: []metav1.Condition{ - {Type: string(ConditionStatefulSet), Status: metav1.ConditionTrue}, + conditionsSet2: []kmetav1.Condition{ + {Type: string(ConditionStatefulSet), Status: kmetav1.ConditionTrue}, }, wantEqualStatus: false, }, diff --git a/cmd/main.go b/cmd/main.go index 6a4f66ff..dc3805dc 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -26,33 +26,33 @@ import ( "go.uber.org/zap" "go.uber.org/zap/zapcore" - apiclientset "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + kapiextclientset "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset" + kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" - utilruntime "k8s.io/apimachinery/pkg/util/runtime" - clientgoscheme "k8s.io/client-go/kubernetes/scheme" - ctrl "sigs.k8s.io/controller-runtime" + kutilruntime "k8s.io/apimachinery/pkg/util/runtime" + kscheme "k8s.io/client-go/kubernetes/scheme" + kcontrollerruntime "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/healthz" - k8szap "sigs.k8s.io/controller-runtime/pkg/log/zap" + klogzap "sigs.k8s.io/controller-runtime/pkg/log/zap" "sigs.k8s.io/controller-runtime/pkg/metrics/server" "sigs.k8s.io/controller-runtime/pkg/webhook" - natsv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" - controllercache "github.com/kyma-project/nats-manager/internal/controller/cache" - natscontroller "github.com/kyma-project/nats-manager/internal/controller/nats" + nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" + nmctrlcache "github.com/kyma-project/nats-manager/internal/controller/cache" + nmctrl "github.com/kyma-project/nats-manager/internal/controller/nats" "github.com/kyma-project/nats-manager/pkg/env" "github.com/kyma-project/nats-manager/pkg/k8s" "github.com/kyma-project/nats-manager/pkg/k8s/chart" - "github.com/kyma-project/nats-manager/pkg/manager" + nmmgr "github.com/kyma-project/nats-manager/pkg/manager" ) const defaultMetricsPort = 9443 func main() { //nolint:funlen // main function needs to initialize many objects scheme := runtime.NewScheme() - setupLog := ctrl.Log.WithName("setup") - utilruntime.Must(clientgoscheme.AddToScheme(scheme)) - utilruntime.Must(natsv1alpha1.AddToScheme(scheme)) + setupLog := kcontrollerruntime.Log.WithName("setup") + kutilruntime.Must(kscheme.AddToScheme(scheme)) + kutilruntime.Must(nmapiv1alpha1.AddToScheme(scheme)) // get configs from ENV envConfigs, err := env.GetConfig() @@ -84,14 +84,14 @@ func main() { //nolint:funlen // main function needs to initialize many objects setupLog.Error(err, "unable to parse log level") os.Exit(1) } - opts := k8szap.Options{ + opts := klogzap.Options{ Development: false, Level: logLevel, } opts.BindFlags(flag.CommandLine) flag.Parse() - ctrl.SetLogger(k8szap.New(k8szap.UseFlagOptions(&opts))) + kcontrollerruntime.SetLogger(klogzap.New(klogzap.UseFlagOptions(&opts))) // setup logger loggerConfig := zap.NewProductionConfig() @@ -108,7 +108,7 @@ func main() { //nolint:funlen // main function needs to initialize many objects sugaredLogger := logger.Sugar() // setup ctrl manager - mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{ + mgr, err := kcontrollerruntime.NewManager(kcontrollerruntime.GetConfigOrDie(), kcontrollerruntime.Options{ Scheme: scheme, HealthProbeBindAddress: probeAddr, LeaderElection: enableLeaderElection, @@ -126,7 +126,7 @@ func main() { //nolint:funlen // main function needs to initialize many objects // LeaderElectionReleaseOnCancel: true, Metrics: server.Options{BindAddress: metricsAddr}, WebhookServer: webhook.NewServer(webhook.Options{Port: metricsPort}), - NewCache: controllercache.New, + NewCache: nmctrlcache.New, }) if err != nil { setupLog.Error(err, "unable to start manager") @@ -141,7 +141,7 @@ func main() { //nolint:funlen // main function needs to initialize many objects } // init custom kube client wrapper - apiClientSet, err := apiclientset.NewForConfig(mgr.GetConfig()) + apiClientSet, err := kapiextclientset.NewForConfig(mgr.GetConfig()) if err != nil { setupLog.Error(err, "failed to create new k8s clientset") os.Exit(1) @@ -149,10 +149,10 @@ func main() { //nolint:funlen // main function needs to initialize many objects kubeClient := k8s.NewKubeClient(mgr.GetClient(), apiClientSet, "nats-manager") - natsManager := manager.NewNATSManger(kubeClient, helmRenderer, sugaredLogger) + natsManager := nmmgr.NewNATSManger(kubeClient, helmRenderer, sugaredLogger) // create NATS reconciler instance - natsReconciler := natscontroller.NewReconciler( + natsReconciler := nmctrl.NewReconciler( mgr.GetClient(), kubeClient, helmRenderer, @@ -160,8 +160,8 @@ func main() { //nolint:funlen // main function needs to initialize many objects sugaredLogger, mgr.GetEventRecorderFor("nats-manager"), natsManager, - &natsv1alpha1.NATS{ - ObjectMeta: metav1.ObjectMeta{ + &nmapiv1alpha1.NATS{ + ObjectMeta: kmetav1.ObjectMeta{ Name: envConfigs.NATSCRName, Namespace: envConfigs.NATSCRNamespace, }, @@ -184,7 +184,7 @@ func main() { //nolint:funlen // main function needs to initialize many objects } setupLog.Info("starting manager") - if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil { + if err := mgr.Start(kcontrollerruntime.SetupSignalHandler()); err != nil { setupLog.Error(err, "problem running manager") os.Exit(1) } diff --git a/config/crd/bases/operator.kyma-project.io_nats.yaml b/config/crd/bases/operator.kyma-project.io_nats.yaml index 0cf200de..3bb1eb95 100644 --- a/config/crd/bases/operator.kyma-project.io_nats.yaml +++ b/config/crd/bases/operator.kyma-project.io_nats.yaml @@ -242,7 +242,7 @@ spec: \n type FooStatus struct{ // Represents the observations of a foo's current state. // Known .status.conditions.type are: \"Available\", \"Progressing\", and \"Degraded\" // +patchMergeKey=type // +patchStrategy=merge - // +listType=map // +listMapKey=type Conditions []metav1.Condition + // +listType=map // +listMapKey=type Conditions []kmetav1.Condition `json:\"conditions,omitempty\" patchStrategy:\"merge\" patchMergeKey:\"type\" protobuf:\"bytes,1,rep,name=conditions\"` \n // other fields }" properties: diff --git a/docs/user/02-configuration.md b/docs/user/02-configuration.md index 21b57698..f88a26c9 100644 --- a/docs/user/02-configuration.md +++ b/docs/user/02-configuration.md @@ -62,7 +62,7 @@ Use the following sample CRs as guidance. Each can be applied immediately when y | Parameter | Type | Description | |------------------------------------------------------|------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| **conditions** | \[\]object | Condition contains details for one aspect of the current state of this API Resource. --- This struct is intended for direct use as an array at the field path .status.conditions. For example, type FooStatus struct{ // Represents the observations of a foo's current state. // Known .status.conditions.type are: "Available", "Progressing", and "Degraded" // +patchMergeKey=type // +patchStrategy=merge // +listType=map // +listMapKey=type Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"` // other fields } | +| **conditions** | \[\]object | Condition contains details for one aspect of the current state of this API Resource. --- This struct is intended for direct use as an array at the field path .status.conditions. For example, type FooStatus struct{ // Represents the observations of a foo's current state. // Known .status.conditions.type are: "Available", "Progressing", and "Degraded" // +patchMergeKey=type // +patchStrategy=merge // +listType=map // +listMapKey=type Conditions []kmetav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"` // other fields } | | **conditions.​lastTransitionTime** (required) | string | lastTransitionTime is the last time the condition transitioned from one status to another. This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable. | | **conditions.​message** (required) | string | message is a human readable message indicating details about the transition. This may be an empty string. | | **conditions.​observedGeneration** | integer | observedGeneration represents the .metadata.generation that the condition was set based upon. For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date with respect to the current state of the instance. | diff --git a/e2e/cleanup/cleanup_test.go b/e2e/cleanup/cleanup_test.go index 40e58973..56e27971 100644 --- a/e2e/cleanup/cleanup_test.go +++ b/e2e/cleanup/cleanup_test.go @@ -17,14 +17,14 @@ import ( "github.com/stretchr/testify/require" "go.uber.org/zap" - k8serrors "k8s.io/apimachinery/pkg/api/errors" + kapierrors "k8s.io/apimachinery/pkg/api/errors" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - k8stypes "k8s.io/apimachinery/pkg/types" + ktypes "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/kubernetes" "sigs.k8s.io/controller-runtime/pkg/client" - natsv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" + nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" . "github.com/kyma-project/nats-manager/e2e/common" . "github.com/kyma-project/nats-manager/e2e/common/fixtures" ) @@ -62,7 +62,7 @@ func TestMain(m *testing.M) { err = Retry(attempts, interval, func() error { errDel := k8sClient.Delete(ctx, NATSCR()) // If it is gone already, that's fine too. - if k8serrors.IsNotFound(errDel) { + if kapierrors.IsNotFound(errDel) { return nil } return errDel @@ -127,7 +127,7 @@ func Test_NoSTSExists(t *testing.T) { // Try to get the STS. _, stsErr := clientSet.AppsV1().StatefulSets(NamespaceName).Get(ctx, STSName, v1.GetOptions{}) // This is what we want here. - if k8serrors.IsNotFound(stsErr) { + if kapierrors.IsNotFound(stsErr) { return nil } // All other errors are unexpected here. @@ -147,7 +147,7 @@ func Test_NoNATSSecretExists(t *testing.T) { err := Retry(attempts, interval, func() error { _, secErr := clientSet.CoreV1().Secrets(NamespaceName).Get(ctx, SecretName, v1.GetOptions{}) // This is what we want here. - if k8serrors.IsNotFound(secErr) { + if kapierrors.IsNotFound(secErr) { return nil } // All other errors are unexpected here. @@ -167,7 +167,7 @@ func Test_NoNATSCRExists(t *testing.T) { err := Retry(attempts, interval, func() error { _, crErr := getNATSCR(ctx, CRName, NamespaceName) // This is what we want here. - if k8serrors.IsNotFound(crErr) { + if kapierrors.IsNotFound(crErr) { return nil } // All other errors are unexpected here. @@ -180,9 +180,9 @@ func Test_NoNATSCRExists(t *testing.T) { require.NoError(t, err) } -func getNATSCR(ctx context.Context, name, namespace string) (*natsv1alpha1.NATS, error) { - var natsCR natsv1alpha1.NATS - err := k8sClient.Get(ctx, k8stypes.NamespacedName{ +func getNATSCR(ctx context.Context, name, namespace string) (*nmapiv1alpha1.NATS, error) { + var natsCR nmapiv1alpha1.NATS + err := k8sClient.Get(ctx, ktypes.NamespacedName{ Name: name, Namespace: namespace, }, &natsCR) diff --git a/e2e/common/fixtures/fixtures.go b/e2e/common/fixtures/fixtures.go index a3e77e64..e455dad6 100644 --- a/e2e/common/fixtures/fixtures.go +++ b/e2e/common/fixtures/fixtures.go @@ -1,11 +1,11 @@ package fixtures import ( - corev1 "k8s.io/api/core/v1" + kcorev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - natsv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" + nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" "github.com/kyma-project/nats-manager/testutils" ) @@ -26,25 +26,25 @@ const ( PriorityClassName = "nats-manager-priority-class" ) -func NATSCR() *natsv1alpha1.NATS { +func NATSCR() *nmapiv1alpha1.NATS { return testutils.NewNATSCR( testutils.WithNATSCRName(CRName), testutils.WithNATSCRNamespace(NamespaceName), testutils.WithNATSClusterSize(ClusterSize), - testutils.WithNATSFileStorage(natsv1alpha1.FileStorage{ + testutils.WithNATSFileStorage(nmapiv1alpha1.FileStorage{ StorageClassName: "default", Size: resource.MustParse(FileStorageSize), }), - testutils.WithNATSMemStorage(natsv1alpha1.MemStorage{ + testutils.WithNATSMemStorage(nmapiv1alpha1.MemStorage{ Enabled: true, Size: resource.MustParse(MemStorageSize), }), - testutils.WithNATSResources(corev1.ResourceRequirements{ - Limits: corev1.ResourceList{ + testutils.WithNATSResources(kcorev1.ResourceRequirements{ + Limits: kcorev1.ResourceList{ "cpu": resource.MustParse("20m"), "memory": resource.MustParse("2Gi"), }, - Requests: corev1.ResourceList{ + Requests: kcorev1.ResourceList{ "cpu": resource.MustParse("5m"), "memory": resource.MustParse("2Gi"), }, @@ -56,18 +56,18 @@ func NATSCR() *natsv1alpha1.NATS { ) } -func Namespace() *corev1.Namespace { - return &corev1.Namespace{ - ObjectMeta: metav1.ObjectMeta{ +func Namespace() *kcorev1.Namespace { + return &kcorev1.Namespace{ + ObjectMeta: kmetav1.ObjectMeta{ Name: NamespaceName, }, } } -func PodListOpts() metav1.ListOptions { - return metav1.ListOptions{LabelSelector: podLabel} +func PodListOpts() kmetav1.ListOptions { + return kmetav1.ListOptions{LabelSelector: podLabel} } -func PVCListOpts() metav1.ListOptions { - return metav1.ListOptions{LabelSelector: pvcLabel} +func PVCListOpts() kmetav1.ListOptions { + return kmetav1.ListOptions{LabelSelector: pvcLabel} } diff --git a/e2e/common/k8s.go b/e2e/common/k8s.go index 332d19ee..0dd542ee 100644 --- a/e2e/common/k8s.go +++ b/e2e/common/k8s.go @@ -5,12 +5,12 @@ import ( "path/filepath" "k8s.io/client-go/kubernetes" - "k8s.io/client-go/kubernetes/scheme" + kscheme "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" "sigs.k8s.io/controller-runtime/pkg/client" - natsv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" + nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" ) func GetK8sClients() (*kubernetes.Clientset, client.Client, error) { @@ -34,7 +34,7 @@ func GetK8sClients() (*kubernetes.Clientset, client.Client, error) { } // We need to add the NATS CRD to the scheme, so we can create a client that can access NATS objects. - err = natsv1alpha1.AddToScheme(scheme.Scheme) + err = nmapiv1alpha1.AddToScheme(kscheme.Scheme) if err != nil { return nil, nil, err } @@ -42,7 +42,7 @@ func GetK8sClients() (*kubernetes.Clientset, client.Client, error) { // Set up the k8s client, so we can access NATS CR-objects. // +kubebuilder:scaffold:scheme var k8sClient client.Client - k8sClient, err = client.New(kubeConfig, client.Options{Scheme: scheme.Scheme}) + k8sClient, err = client.New(kubeConfig, client.Options{Scheme: kscheme.Scheme}) if err != nil { return nil, nil, err } diff --git a/e2e/setup/setup_test.go b/e2e/setup/setup_test.go index 9b51b266..367c8209 100644 --- a/e2e/setup/setup_test.go +++ b/e2e/setup/setup_test.go @@ -18,15 +18,15 @@ import ( "github.com/stretchr/testify/require" "go.uber.org/zap" - appsv1 "k8s.io/api/apps/v1" - v1 "k8s.io/api/core/v1" - k8serrors "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - k8stypes "k8s.io/apimachinery/pkg/types" + kappsv1 "k8s.io/api/apps/v1" + kcorev1 "k8s.io/api/core/v1" + kapierrors "k8s.io/apimachinery/pkg/api/errors" + kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + ktypes "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/kubernetes" "sigs.k8s.io/controller-runtime/pkg/client" - natsv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" + nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" . "github.com/kyma-project/nats-manager/e2e/common" . "github.com/kyma-project/nats-manager/e2e/common/fixtures" ) @@ -86,7 +86,7 @@ func TestMain(m *testing.M) { // Create the NATS CR used for testing. err = Retry(attempts, interval, func() error { errNATS := k8sClient.Create(ctx, NATSCR()) - if k8serrors.IsAlreadyExists(errNATS) { + if kapierrors.IsAlreadyExists(errNATS) { logger.Warn( "error while creating NATS CR, resource already exist; test will continue with existing NATS CR", ) @@ -117,7 +117,7 @@ func Test_CR(t *testing.T) { ctx := context.TODO() // Get the NATS CR from the cluster. - actual, err := RetryGet(attempts, interval, func() (*natsv1alpha1.NATS, error) { + actual, err := RetryGet(attempts, interval, func() (*nmapiv1alpha1.NATS, error) { return getNATSCR(ctx, want.Name, want.Namespace) }) require.NoError(t, err) @@ -134,7 +134,7 @@ func Test_PriorityClass(t *testing.T) { ctx := context.TODO() err := Retry(attempts, interval, func() error { - sts, stsErr := clientSet.AppsV1().StatefulSets(NamespaceName).Get(ctx, STSName, metav1.GetOptions{}) + sts, stsErr := clientSet.AppsV1().StatefulSets(NamespaceName).Get(ctx, STSName, kmetav1.GetOptions{}) if stsErr != nil { return stsErr } @@ -149,7 +149,7 @@ func Test_PriorityClass(t *testing.T) { return fmt.Errorf("PriorityClassName was expected to be %s but was %s", PriorityClassName, pcName) } - _, pcErr := clientSet.SchedulingV1().PriorityClasses().Get(ctx, pcName, metav1.GetOptions{}) + _, pcErr := clientSet.SchedulingV1().PriorityClasses().Get(ctx, pcName, kmetav1.GetOptions{}) return pcErr }) @@ -161,7 +161,7 @@ func Test_ConfigMap(t *testing.T) { ctx := context.TODO() err := Retry(attempts, interval, func() error { - cm, cmErr := clientSet.CoreV1().ConfigMaps(NamespaceName).Get(ctx, CMName, metav1.GetOptions{}) + cm, cmErr := clientSet.CoreV1().ConfigMaps(NamespaceName).Get(ctx, CMName, kmetav1.GetOptions{}) if cmErr != nil { return cmErr } @@ -183,7 +183,7 @@ func Test_ConfigMap(t *testing.T) { // To check the correct key in configMap, // fetch the NATS statefulSet and get the NATS server version. // And then based on the version, check the expected key. - sts, stsErr := clientSet.AppsV1().StatefulSets(NamespaceName).Get(ctx, STSName, metav1.GetOptions{}) + sts, stsErr := clientSet.AppsV1().StatefulSets(NamespaceName).Get(ctx, STSName, kmetav1.GetOptions{}) if stsErr != nil { return stsErr } @@ -283,14 +283,14 @@ func Test_PodsReady(t *testing.T) { ctx := context.TODO() // RetryGet the NATS CR. It will tell us how many Pods we should expect. - natsCR, err := RetryGet(attempts, interval, func() (*natsv1alpha1.NATS, error) { + natsCR, err := RetryGet(attempts, interval, func() (*nmapiv1alpha1.NATS, error) { return getNATSCR(ctx, CRName, NamespaceName) }) require.NoError(t, err) // RetryGet the NATS Pods and test them. err = Retry(attempts, interval, func() error { - var pods *v1.PodList + var pods *kcorev1.PodList // RetryGet the NATS Pods via labels. pods, err = clientSet.CoreV1().Pods(NamespaceName).List(ctx, PodListOpts()) if err != nil { @@ -337,11 +337,11 @@ func Test_PVCs(t *testing.T) { // Get the PersistentVolumeClaims --PVCs-- and test them. ctx := context.TODO() - var pvcs *v1.PersistentVolumeClaimList + var pvcs *kcorev1.PersistentVolumeClaimList err := Retry(attempts, interval, func() error { // RetryGet PVCs via a label. var err error - pvcs, err = RetryGet(attempts, interval, func() (*v1.PersistentVolumeClaimList, error) { + pvcs, err = RetryGet(attempts, interval, func() (*kcorev1.PersistentVolumeClaimList, error) { return clientSet.CoreV1().PersistentVolumeClaims(NamespaceName).List(ctx, PVCListOpts()) }) if err != nil { @@ -362,7 +362,7 @@ func Test_PVCs(t *testing.T) { // Compare the PVC's sizes with the definition in the CRD. for _, pvc := range pvcs.Items { - size := pvc.Spec.Resources.Requests[v1.ResourceStorage] + size := pvc.Spec.Resources.Requests[kcorev1.ResourceStorage] require.True(t, size.Equal(NATSCR().Spec.FileStorage.Size)) } } @@ -372,7 +372,7 @@ func Test_Secret(t *testing.T) { t.Parallel() ctx := context.TODO() err := Retry(attempts, interval, func() error { - _, secErr := clientSet.CoreV1().Secrets(NamespaceName).Get(ctx, SecretName, metav1.GetOptions{}) + _, secErr := clientSet.CoreV1().Secrets(NamespaceName).Get(ctx, SecretName, kmetav1.GetOptions{}) if secErr != nil { return secErr } @@ -381,17 +381,17 @@ func Test_Secret(t *testing.T) { require.NoError(t, err) } -func getNATSCR(ctx context.Context, name, namespace string) (*natsv1alpha1.NATS, error) { - var natsCR natsv1alpha1.NATS - err := k8sClient.Get(ctx, k8stypes.NamespacedName{ +func getNATSCR(ctx context.Context, name, namespace string) (*nmapiv1alpha1.NATS, error) { + var natsCR nmapiv1alpha1.NATS + err := k8sClient.Get(ctx, ktypes.NamespacedName{ Name: name, Namespace: namespace, }, &natsCR) return &natsCR, err } -func getDeployment(ctx context.Context, name, namespace string) (*appsv1.Deployment, error) { - return clientSet.AppsV1().Deployments(namespace).Get(ctx, name, metav1.GetOptions{}) +func getDeployment(ctx context.Context, name, namespace string) (*kappsv1.Deployment, error) { + return clientSet.AppsV1().Deployments(namespace).Get(ctx, name, kmetav1.GetOptions{}) } func cmToMap(cm string) map[string]string { @@ -434,14 +434,14 @@ func waitForNATSCRReady() error { ctx := context.TODO() // Get the NATS CR from the cluster. - gotNATSCR, err := RetryGet(attempts, interval, func() (*natsv1alpha1.NATS, error) { + gotNATSCR, err := RetryGet(attempts, interval, func() (*nmapiv1alpha1.NATS, error) { return getNATSCR(ctx, want.Name, want.Namespace) }) if err != nil { return err } - if gotNATSCR.Status.State != natsv1alpha1.StateReady { + if gotNATSCR.Status.State != nmapiv1alpha1.StateReady { err := fmt.Errorf("waiting for NATS CR to get ready state") logger.Debug(err.Error()) return err @@ -461,7 +461,7 @@ func waitForNATSManagerDeploymentReady(image string) error { logger.Debug(fmt.Sprintf("waiting for nats-manager deployment to get ready with image: %s", image)) ctx := context.TODO() // Get the NATS-manager deployment from the cluster. - gotDeployment, err := RetryGet(attempts, interval, func() (*appsv1.Deployment, error) { + gotDeployment, err := RetryGet(attempts, interval, func() (*kappsv1.Deployment, error) { return getDeployment(ctx, ManagerDeploymentName, NamespaceName) }) if err != nil { diff --git a/internal/controller/cache/cache.go b/internal/controller/cache/cache.go index 3df6033b..a5188ec6 100644 --- a/internal/controller/cache/cache.go +++ b/internal/controller/cache/cache.go @@ -1,17 +1,17 @@ package cache import ( - appsv1 "k8s.io/api/apps/v1" - autoscalingv1 "k8s.io/api/autoscaling/v1" - corev1 "k8s.io/api/core/v1" - policyv1 "k8s.io/api/policy/v1" - rbacv1 "k8s.io/api/rbac/v1" + kappsv1 "k8s.io/api/apps/v1" + kautoscalingv1 "k8s.io/api/autoscaling/v1" + kcorev1 "k8s.io/api/core/v1" + kapipolicyv1 "k8s.io/api/policy/v1" + krbacv1 "k8s.io/api/rbac/v1" "k8s.io/apimachinery/pkg/labels" "k8s.io/client-go/rest" "sigs.k8s.io/controller-runtime/pkg/cache" "sigs.k8s.io/controller-runtime/pkg/client" - natslabels "github.com/kyma-project/nats-manager/pkg/labels" + nmlabels "github.com/kyma-project/nats-manager/pkg/labels" ) // New returns a cache with the cache-options applied, generade form the rest-config. @@ -21,20 +21,20 @@ func New(config *rest.Config, options cache.Options) (cache.Cache, error) { func applySelectors(options cache.Options) cache.Options { // The only objects we allow are the ones with the 'managed-by: nats-manager' label applied. - managedByNATS := fromLabelSelector(natslabels.SelectorManagedByNATS()) + managedByNATS := fromLabelSelector(nmlabels.SelectorManagedByNATS()) // Apply the label selector to all relevant objects. options.ByObject = map[client.Object]cache.ByObject{ - &appsv1.Deployment{}: managedByNATS, - &appsv1.StatefulSet{}: managedByNATS, - &corev1.ServiceAccount{}: managedByNATS, - &corev1.Secret{}: managedByNATS, - &corev1.Service{}: managedByNATS, - &corev1.ConfigMap{}: managedByNATS, - &rbacv1.ClusterRole{}: managedByNATS, - &rbacv1.ClusterRoleBinding{}: managedByNATS, - &autoscalingv1.HorizontalPodAutoscaler{}: managedByNATS, - &policyv1.PodDisruptionBudget{}: managedByNATS, + &kappsv1.Deployment{}: managedByNATS, + &kappsv1.StatefulSet{}: managedByNATS, + &kcorev1.ServiceAccount{}: managedByNATS, + &kcorev1.Secret{}: managedByNATS, + &kcorev1.Service{}: managedByNATS, + &kcorev1.ConfigMap{}: managedByNATS, + &krbacv1.ClusterRole{}: managedByNATS, + &krbacv1.ClusterRoleBinding{}: managedByNATS, + &kautoscalingv1.HorizontalPodAutoscaler{}: managedByNATS, + &kapipolicyv1.PodDisruptionBudget{}: managedByNATS, } return options } diff --git a/internal/controller/cache/cache_test.go b/internal/controller/cache/cache_test.go index 367b2abe..d3ffd26d 100644 --- a/internal/controller/cache/cache_test.go +++ b/internal/controller/cache/cache_test.go @@ -6,13 +6,13 @@ import ( "testing" "time" - natslabels "github.com/kyma-project/nats-manager/pkg/labels" + nmlabels "github.com/kyma-project/nats-manager/pkg/labels" "github.com/stretchr/testify/require" - appsv1 "k8s.io/api/apps/v1" - autoscalingv1 "k8s.io/api/autoscaling/v1" - corev1 "k8s.io/api/core/v1" - policyv1 "k8s.io/api/policy/v1" - rbacv1 "k8s.io/api/rbac/v1" + kappsv1 "k8s.io/api/apps/v1" + kautoscalingv1 "k8s.io/api/autoscaling/v1" + kcorev1 "k8s.io/api/core/v1" + kapipolicyv1 "k8s.io/api/policy/v1" + krbacv1 "k8s.io/api/rbac/v1" "k8s.io/apimachinery/pkg/labels" "sigs.k8s.io/controller-runtime/pkg/cache" "sigs.k8s.io/controller-runtime/pkg/client" @@ -24,7 +24,7 @@ func Test_applySelectors(t *testing.T) { selector := cache.ByObject{ Label: labels.SelectorFromSet( map[string]string{ - natslabels.KeyManagedBy: natslabels.ValueNATSManager, + nmlabels.KeyManagedBy: nmlabels.ValueNATSManager, }, ), } @@ -44,16 +44,16 @@ func Test_applySelectors(t *testing.T) { }, want: cache.Options{ ByObject: map[client.Object]cache.ByObject{ - &appsv1.Deployment{}: selector, - &appsv1.StatefulSet{}: selector, - &corev1.ServiceAccount{}: selector, - &corev1.Secret{}: selector, - &corev1.Service{}: selector, - &corev1.ConfigMap{}: selector, - &rbacv1.ClusterRole{}: selector, - &rbacv1.ClusterRoleBinding{}: selector, - &autoscalingv1.HorizontalPodAutoscaler{}: selector, - &policyv1.PodDisruptionBudget{}: selector, + &kappsv1.Deployment{}: selector, + &kappsv1.StatefulSet{}: selector, + &kcorev1.ServiceAccount{}: selector, + &kcorev1.Secret{}: selector, + &kcorev1.Service{}: selector, + &kcorev1.ConfigMap{}: selector, + &krbacv1.ClusterRole{}: selector, + &krbacv1.ClusterRoleBinding{}: selector, + &kautoscalingv1.HorizontalPodAutoscaler{}: selector, + &kapipolicyv1.PodDisruptionBudget{}: selector, }, }, }, @@ -67,16 +67,16 @@ func Test_applySelectors(t *testing.T) { want: cache.Options{ SyncPeriod: &syncPeriod, ByObject: map[client.Object]cache.ByObject{ - &appsv1.Deployment{}: selector, - &appsv1.StatefulSet{}: selector, - &corev1.ServiceAccount{}: selector, - &corev1.Secret{}: selector, - &corev1.Service{}: selector, - &corev1.ConfigMap{}: selector, - &rbacv1.ClusterRole{}: selector, - &rbacv1.ClusterRoleBinding{}: selector, - &autoscalingv1.HorizontalPodAutoscaler{}: selector, - &policyv1.PodDisruptionBudget{}: selector, + &kappsv1.Deployment{}: selector, + &kappsv1.StatefulSet{}: selector, + &kcorev1.ServiceAccount{}: selector, + &kcorev1.Secret{}: selector, + &kcorev1.Service{}: selector, + &kcorev1.ConfigMap{}: selector, + &krbacv1.ClusterRole{}: selector, + &krbacv1.ClusterRoleBinding{}: selector, + &kautoscalingv1.HorizontalPodAutoscaler{}: selector, + &kapipolicyv1.PodDisruptionBudget{}: selector, }, }, }, @@ -114,23 +114,23 @@ func deepEqualByObject(a, b map[client.Object]cache.ByObject) bool { func computeTypeMap(byObjectMap map[client.Object]cache.ByObject, typeMap map[string]cache.ByObject) { keyOf := func(i interface{}) string { return fmt.Sprintf(">>> %T", i) } for k, v := range byObjectMap { - if obj, ok := k.(*appsv1.Deployment); ok { + if obj, ok := k.(*kappsv1.Deployment); ok { key := keyOf(obj) typeMap[key] = v } - if obj, ok := k.(*corev1.ServiceAccount); ok { + if obj, ok := k.(*kcorev1.ServiceAccount); ok { key := keyOf(obj) typeMap[key] = v } - if obj, ok := k.(*rbacv1.ClusterRole); ok { + if obj, ok := k.(*krbacv1.ClusterRole); ok { key := keyOf(obj) typeMap[key] = v } - if obj, ok := k.(*rbacv1.ClusterRoleBinding); ok { + if obj, ok := k.(*krbacv1.ClusterRoleBinding); ok { key := keyOf(obj) typeMap[key] = v } - if obj, ok := k.(*autoscalingv1.HorizontalPodAutoscaler); ok { + if obj, ok := k.(*kautoscalingv1.HorizontalPodAutoscaler); ok { key := keyOf(obj) typeMap[key] = v } diff --git a/internal/controller/nats/controller.go b/internal/controller/nats/controller.go index 5d8a3913..a230ce28 100644 --- a/internal/controller/nats/controller.go +++ b/internal/controller/nats/controller.go @@ -21,24 +21,24 @@ import ( "fmt" "github.com/kyma-project/nats-manager/pkg/events" - "github.com/kyma-project/nats-manager/pkg/nats" + nmnats "github.com/kyma-project/nats-manager/pkg/nats" "go.uber.org/zap" - appsv1 "k8s.io/api/apps/v1" - apiv1 "k8s.io/api/core/v1" - policyv1 "k8s.io/api/policy/v1" - "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + kappsv1 "k8s.io/api/apps/v1" + kcorev1 "k8s.io/api/core/v1" + kapipolicyv1 "k8s.io/api/policy/v1" + kapierrors "k8s.io/apimachinery/pkg/api/errors" + kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/tools/record" - ctrl "sigs.k8s.io/controller-runtime" + kcontrollerruntime "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller" - natsv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" + nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" "github.com/kyma-project/nats-manager/pkg/k8s" "github.com/kyma-project/nats-manager/pkg/k8s/chart" - "github.com/kyma-project/nats-manager/pkg/manager" + nmmgr "github.com/kyma-project/nats-manager/pkg/manager" ) const ( @@ -58,15 +58,15 @@ type Reconciler struct { client.Client controller controller.Controller kubeClient k8s.Client - natsClients map[string]nats.Client + natsClients map[string]nmnats.Client chartRenderer chart.Renderer scheme *runtime.Scheme recorder record.EventRecorder logger *zap.SugaredLogger - natsManager manager.Manager - ctrlManager ctrl.Manager + natsManager nmmgr.Manager + ctrlManager kcontrollerruntime.Manager destinationRuleWatchStarted bool - allowedNATSCR *natsv1alpha1.NATS + allowedNATSCR *nmapiv1alpha1.NATS } func NewReconciler( @@ -76,13 +76,13 @@ func NewReconciler( scheme *runtime.Scheme, logger *zap.SugaredLogger, recorder record.EventRecorder, - natsManager manager.Manager, - allowedNATSCR *natsv1alpha1.NATS, + natsManager nmmgr.Manager, + allowedNATSCR *nmapiv1alpha1.NATS, ) *Reconciler { return &Reconciler{ Client: client, kubeClient: kubeClient, - natsClients: make(map[string]nats.Client), + natsClients: make(map[string]nmnats.Client), chartRenderer: chartRenderer, scheme: scheme, recorder: recorder, @@ -119,12 +119,12 @@ func NewReconciler( //+kubebuilder:rbac:groups=operator.kyma-project.io,resources=nats/status,verbs=get;update;patch //+kubebuilder:rbac:groups=operator.kyma-project.io,resources=nats/finalizers,verbs=update -func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { +func (r *Reconciler) Reconcile(ctx context.Context, req kcontrollerruntime.Request) (kcontrollerruntime.Result, error) { r.logger.Info("Reconciliation triggered") // fetch latest subscription object - currentNats := &natsv1alpha1.NATS{} + currentNats := &nmapiv1alpha1.NATS{} if err := r.Get(ctx, req.NamespacedName, currentNats); err != nil { - return ctrl.Result{}, client.IgnoreNotFound(err) + return kcontrollerruntime.Result{}, client.IgnoreNotFound(err) } // Copy the object, so we don't modify the source object. @@ -141,7 +141,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu // Check if the NATS CR is allowed to be created. if r.allowedNATSCR != nil { if result, err := r.handleNATSCRAllowedCheck(ctx, nats, log); !result || err != nil { - return ctrl.Result{}, err + return kcontrollerruntime.Result{}, err } } @@ -151,7 +151,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu // handleNATSCRAllowedCheck checks if NATS CR is allowed to be created or not. // returns true if the NATS CR is allowed. -func (r *Reconciler) handleNATSCRAllowedCheck(ctx context.Context, nats *natsv1alpha1.NATS, +func (r *Reconciler) handleNATSCRAllowedCheck(ctx context.Context, nats *nmapiv1alpha1.NATS, log *zap.SugaredLogger, ) (bool, error) { // If the name and namespace matches with allowed NATS CR then allow the CR to be reconciled. @@ -162,24 +162,24 @@ func (r *Reconciler) handleNATSCRAllowedCheck(ctx context.Context, nats *natsv1a // Set error state in status. nats.Status.SetStateError() // Update conditions in status. - nats.Status.UpdateConditionStatefulSet(metav1.ConditionFalse, - natsv1alpha1.ConditionReasonForbidden, "") + nats.Status.UpdateConditionStatefulSet(kmetav1.ConditionFalse, + nmapiv1alpha1.ConditionReasonForbidden, "") errorMessage := fmt.Sprintf(CreationNotAllowedMsg, r.allowedNATSCR.Name, r.allowedNATSCR.Namespace) - nats.Status.UpdateConditionAvailable(metav1.ConditionFalse, - natsv1alpha1.ConditionReasonForbidden, errorMessage) - events.Warn(r.recorder, nats, natsv1alpha1.ConditionReasonForbidden, errorMessage) + nats.Status.UpdateConditionAvailable(kmetav1.ConditionFalse, + nmapiv1alpha1.ConditionReasonForbidden, errorMessage) + events.Warn(r.recorder, nats, nmapiv1alpha1.ConditionReasonForbidden, errorMessage) return false, r.syncNATSStatus(ctx, nats, log) } // generateNatsResources renders the NATS chart with provided overrides. // It puts results into ReleaseInstance. -func (r *Reconciler) generateNatsResources(nats *natsv1alpha1.NATS, instance *chart.ReleaseInstance) error { +func (r *Reconciler) generateNatsResources(nats *nmapiv1alpha1.NATS, instance *chart.ReleaseInstance) error { // Generate Nats resources from chart. natsResources, err := r.natsManager.GenerateNATSResources( instance, - manager.WithOwnerReference(*nats), // add owner references to all resources - manager.WithLabel(ManagedByLabelKey, ManagedByLabelValue), + nmmgr.WithOwnerReference(*nats), // add owner references to all resources + nmmgr.WithLabel(ManagedByLabelKey, ManagedByLabelValue), ) if err != nil { return err @@ -191,7 +191,7 @@ func (r *Reconciler) generateNatsResources(nats *natsv1alpha1.NATS, instance *ch } // initNATSInstance initializes a new NATS release instance based on NATS CR. -func (r *Reconciler) initNATSInstance(ctx context.Context, nats *natsv1alpha1.NATS, +func (r *Reconciler) initNATSInstance(ctx context.Context, nats *nmapiv1alpha1.NATS, log *zap.SugaredLogger, ) (*chart.ReleaseInstance, error) { // Check if istio is enabled in cluster. @@ -204,7 +204,7 @@ func (r *Reconciler) initNATSInstance(ctx context.Context, nats *natsv1alpha1.NA // Check if NATS account secret exists. accountSecretName := fmt.Sprintf("%s-secret", nats.Name) accountSecret, err := r.kubeClient.GetSecret(ctx, accountSecretName, nats.Namespace) - if err != nil && !errors.IsNotFound(err) { + if err != nil && !kapierrors.IsNotFound(err) { log.Errorf("Failed to fetch secret: %s", accountSecretName) log.Error(err) return nil, err @@ -226,23 +226,23 @@ func (r *Reconciler) initNATSInstance(ctx context.Context, nats *natsv1alpha1.NA } // SetupWithManager sets up the controller with the Manager. -func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error { +func (r *Reconciler) SetupWithManager(mgr kcontrollerruntime.Manager) error { r.ctrlManager = mgr var err error - r.controller, err = ctrl.NewControllerManagedBy(mgr). - For(&natsv1alpha1.NATS{}). - Owns(&appsv1.StatefulSet{}). // watch for StatefulSets. - Owns(&apiv1.Service{}). // watch for Services. - Owns(&apiv1.ConfigMap{}). // watch for ConfigMaps. - Owns(&apiv1.Secret{}). // watch for Secrets. - Owns(&policyv1.PodDisruptionBudget{}). // watch for PodDisruptionBudgets. + r.controller, err = kcontrollerruntime.NewControllerManagedBy(mgr). + For(&nmapiv1alpha1.NATS{}). + Owns(&kappsv1.StatefulSet{}). // watch for StatefulSets. + Owns(&kcorev1.Service{}). // watch for Services. + Owns(&kcorev1.ConfigMap{}). // watch for ConfigMaps. + Owns(&kcorev1.Secret{}). // watch for Secrets. + Owns(&kapipolicyv1.PodDisruptionBudget{}). // watch for PodDisruptionBudgets. Build(r) return err } // loggerWithNATS returns a logger with the given NATS CR details. -func (r *Reconciler) loggerWithNATS(nats *natsv1alpha1.NATS) *zap.SugaredLogger { +func (r *Reconciler) loggerWithNATS(nats *nmapiv1alpha1.NATS) *zap.SugaredLogger { return r.logger.With( "kind", nats.GetObjectKind().GroupVersionKind().Kind, "resourceVersion", nats.GetResourceVersion(), diff --git a/internal/controller/nats/controller_test.go b/internal/controller/nats/controller_test.go index 9f604f0b..a2bc08f2 100644 --- a/internal/controller/nats/controller_test.go +++ b/internal/controller/nats/controller_test.go @@ -4,13 +4,13 @@ import ( "fmt" "testing" - natsv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" + nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" "github.com/kyma-project/nats-manager/pkg/k8s/chart" - natsmanager "github.com/kyma-project/nats-manager/pkg/manager" + nmmgr "github.com/kyma-project/nats-manager/pkg/manager" "github.com/kyma-project/nats-manager/testutils" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" ) @@ -54,7 +54,7 @@ func Test_initNATSInstance(t *testing.T) { // define test cases testCases := []struct { name string - givenNATS *natsv1alpha1.NATS + givenNATS *nmapiv1alpha1.NATS wantIstioEnabled bool wantRotatePassword bool }{ @@ -107,8 +107,8 @@ func Test_initNATSInstance(t *testing.T) { testEnv.natsManager.On("GenerateOverrides", mock.Anything, mock.Anything, mock.Anything).Return( map[string]interface{}{ - natsmanager.IstioEnabledKey: tc.wantIstioEnabled, - natsmanager.RotatePasswordKey: tc.wantRotatePassword, // do not recreate secret if it exists + nmmgr.IstioEnabledKey: tc.wantIstioEnabled, + nmmgr.RotatePasswordKey: tc.wantRotatePassword, // do not recreate secret if it exists }, ) @@ -136,7 +136,7 @@ func Test_handleNATSCRAllowedCheck(t *testing.T) { // define test cases testCases := []struct { name string - givenNATS *natsv1alpha1.NATS + givenNATS *nmapiv1alpha1.NATS wantCheckResult bool }{ { @@ -195,26 +195,26 @@ func Test_handleNATSCRAllowedCheck(t *testing.T) { require.NoError(t, err) if !tc.wantCheckResult { // check nats.status.state - require.Equal(t, natsv1alpha1.StateError, gotNATS.Status.State) + require.Equal(t, nmapiv1alpha1.StateError, gotNATS.Status.State) // check nats.status.conditions - wantConditions := []metav1.Condition{ + wantConditions := []kmetav1.Condition{ { - Type: string(natsv1alpha1.ConditionStatefulSet), - Status: metav1.ConditionFalse, - LastTransitionTime: metav1.Now(), - Reason: string(natsv1alpha1.ConditionReasonForbidden), + Type: string(nmapiv1alpha1.ConditionStatefulSet), + Status: kmetav1.ConditionFalse, + LastTransitionTime: kmetav1.Now(), + Reason: string(nmapiv1alpha1.ConditionReasonForbidden), Message: "", }, { - Type: string(natsv1alpha1.ConditionAvailable), - Status: metav1.ConditionFalse, - LastTransitionTime: metav1.Now(), - Reason: string(natsv1alpha1.ConditionReasonForbidden), + Type: string(nmapiv1alpha1.ConditionAvailable), + Status: kmetav1.ConditionFalse, + LastTransitionTime: kmetav1.Now(), + Reason: string(nmapiv1alpha1.ConditionReasonForbidden), Message: fmt.Sprintf(CreationNotAllowedMsg, givenAllowedNATS.Name, givenAllowedNATS.Namespace), }, } - require.True(t, natsv1alpha1.ConditionsEquals(wantConditions, gotNATS.Status.Conditions)) + require.True(t, nmapiv1alpha1.ConditionsEquals(wantConditions, gotNATS.Status.Conditions)) wantK8sEventMsg := fmt.Sprintf("Warning Forbidden %s", CreationNotAllowedMsg) wantK8sEvent := []string{ diff --git a/internal/controller/nats/deprovisioner.go b/internal/controller/nats/deprovisioner.go index 84d25e2d..64999264 100644 --- a/internal/controller/nats/deprovisioner.go +++ b/internal/controller/nats/deprovisioner.go @@ -5,14 +5,14 @@ import ( "fmt" "go.uber.org/zap" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - ctrl "sigs.k8s.io/controller-runtime" + kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + kcontrollerruntime "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" - natsv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" - natsurl "github.com/kyma-project/nats-manager/internal/controller/nats/url" + nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" + nmctrlurl "github.com/kyma-project/nats-manager/internal/controller/nats/url" "github.com/kyma-project/nats-manager/pkg/events" - natspkg "github.com/kyma-project/nats-manager/pkg/nats" + nmnats "github.com/kyma-project/nats-manager/pkg/nats" ) const ( @@ -22,17 +22,17 @@ const ( SapStreamName = "sap" ) -func (r *Reconciler) handleNATSDeletion(ctx context.Context, nats *natsv1alpha1.NATS, - log *zap.SugaredLogger) (ctrl.Result, error) { +func (r *Reconciler) handleNATSDeletion(ctx context.Context, nats *nmapiv1alpha1.NATS, + log *zap.SugaredLogger) (kcontrollerruntime.Result, error) { // skip reconciliation for deletion if the finalizer is not set. if !r.containsFinalizer(nats) { log.Debugf("skipped reconciliation for deletion as finalizer is not set.") - return ctrl.Result{}, nil + return kcontrollerruntime.Result{}, nil } r.logger.Info("Deleting the NATS") nats.Status.SetStateDeleting() - events.Normal(r.recorder, nats, natsv1alpha1.ConditionReasonDeleting, "Deleting the NATS cluster.") + events.Normal(r.recorder, nats, nmapiv1alpha1.ConditionReasonDeleting, "Deleting the NATS cluster.") // create a new NATS client instance. if err := r.createAndConnectNatsClient(nats); err != nil { @@ -46,10 +46,10 @@ func (r *Reconciler) handleNATSDeletion(ctx context.Context, nats *natsv1alpha1. // if any streams exists except for 'sap' stream, block the deletion. if customerStreamExists { nats.Status.SetStateWarning() - nats.Status.UpdateConditionDeletion(metav1.ConditionFalse, - natsv1alpha1.ConditionReasonDeletionError, StreamExistsErrorMsg) - events.Warn(r.recorder, nats, natsv1alpha1.ConditionReasonDeletionError, StreamExistsErrorMsg) - return ctrl.Result{Requeue: true}, r.syncNATSStatus(ctx, nats, log) + nats.Status.UpdateConditionDeletion(kmetav1.ConditionFalse, + nmapiv1alpha1.ConditionReasonDeletionError, StreamExistsErrorMsg) + events.Warn(r.recorder, nats, nmapiv1alpha1.ConditionReasonDeletionError, StreamExistsErrorMsg) + return kcontrollerruntime.Result{Requeue: true}, r.syncNATSStatus(ctx, nats, log) } sapStreamConsumerExists, err := r.sapStreamConsumerExists(nats) @@ -59,17 +59,17 @@ func (r *Reconciler) handleNATSDeletion(ctx context.Context, nats *natsv1alpha1. // if any 'sap' stream consumer exists, block the deletion. if sapStreamConsumerExists { nats.Status.SetStateWarning() - nats.Status.UpdateConditionDeletion(metav1.ConditionFalse, - natsv1alpha1.ConditionReasonDeletionError, ConsumerExistsErrorMsg) - events.Warn(r.recorder, nats, natsv1alpha1.ConditionReasonDeletionError, ConsumerExistsErrorMsg) - return ctrl.Result{Requeue: true}, r.syncNATSStatus(ctx, nats, log) + nats.Status.UpdateConditionDeletion(kmetav1.ConditionFalse, + nmapiv1alpha1.ConditionReasonDeletionError, ConsumerExistsErrorMsg) + events.Warn(r.recorder, nats, nmapiv1alpha1.ConditionReasonDeletionError, ConsumerExistsErrorMsg) + return kcontrollerruntime.Result{Requeue: true}, r.syncNATSStatus(ctx, nats, log) } return r.deletePVCsAndRemoveFinalizer(ctx, nats, r.logger) } // check if any other stream exists except for 'sap' stream. -func (r *Reconciler) customerStreamExists(nats *natsv1alpha1.NATS) (bool, error) { +func (r *Reconciler) customerStreamExists(nats *nmapiv1alpha1.NATS) (bool, error) { // check if any other stream exists except for 'sap' stream. streams, err := r.getNatsClient(nats).GetStreams() if err != nil { @@ -83,7 +83,7 @@ func (r *Reconciler) customerStreamExists(nats *natsv1alpha1.NATS) (bool, error) return false, nil } -func (r *Reconciler) sapStreamConsumerExists(nats *natsv1alpha1.NATS) (bool, error) { +func (r *Reconciler) sapStreamConsumerExists(nats *nmapiv1alpha1.NATS) (bool, error) { // check if 'sap' stream exists. streams, err := r.getNatsClient(nats).GetStreams() if err != nil { @@ -105,18 +105,18 @@ func (r *Reconciler) sapStreamConsumerExists(nats *natsv1alpha1.NATS) (bool, err } // create a new NATS client instance and connect to the NATS server. -func (r *Reconciler) createAndConnectNatsClient(nats *natsv1alpha1.NATS) error { +func (r *Reconciler) createAndConnectNatsClient(nats *nmapiv1alpha1.NATS) error { // create a new instance if it does not exist. if r.getNatsClient(nats) == nil { - r.setNatsClient(nats, natspkg.NewNatsClient(&natspkg.Config{ - URL: natsurl.Format(nats.Name, nats.Namespace), + r.setNatsClient(nats, nmnats.NewNatsClient(&nmnats.Config{ + URL: nmctrlurl.Format(nats.Name, nats.Namespace), })) } return r.getNatsClient(nats).Init() } func (r *Reconciler) deletePVCsAndRemoveFinalizer(ctx context.Context, - nats *natsv1alpha1.NATS, log *zap.SugaredLogger) (ctrl.Result, error) { + nats *nmapiv1alpha1.NATS, log *zap.SugaredLogger) (kcontrollerruntime.Result, error) { labelValue := nats.Name // TODO: delete the following logic after migrating to modular Kyma if nats.Name == "eventing-nats" { @@ -125,7 +125,7 @@ func (r *Reconciler) deletePVCsAndRemoveFinalizer(ctx context.Context, // delete PVCs with the label selector. labelSelector := fmt.Sprintf("%s=%s", InstanceLabelKey, labelValue) if err := r.kubeClient.DeletePVCsWithLabel(ctx, labelSelector, nats.Name, nats.Namespace); err != nil { - return ctrl.Result{}, client.IgnoreNotFound(err) + return kcontrollerruntime.Result{}, client.IgnoreNotFound(err) } // close the nats connection and remove the client instance. r.closeNatsClient(nats) @@ -134,18 +134,18 @@ func (r *Reconciler) deletePVCsAndRemoveFinalizer(ctx context.Context, return r.removeFinalizer(ctx, nats) } -func (r *Reconciler) getNatsClient(nats *natsv1alpha1.NATS) natspkg.Client { +func (r *Reconciler) getNatsClient(nats *nmapiv1alpha1.NATS) nmnats.Client { crKey := nats.Namespace + "/" + nats.Name return r.natsClients[crKey] } -func (r *Reconciler) setNatsClient(nats *natsv1alpha1.NATS, newNatsClient natspkg.Client) { +func (r *Reconciler) setNatsClient(nats *nmapiv1alpha1.NATS, newNatsClient nmnats.Client) { crKey := nats.Namespace + "/" + nats.Name r.natsClients[crKey] = newNatsClient } // close the nats connection and remove the client instance. -func (r *Reconciler) closeNatsClient(nats *natsv1alpha1.NATS) { +func (r *Reconciler) closeNatsClient(nats *nmapiv1alpha1.NATS) { // check if nats client exists. if r.getNatsClient(nats) != nil { r.getNatsClient(nats).Close() diff --git a/internal/controller/nats/deprovisioner_test.go b/internal/controller/nats/deprovisioner_test.go index 399e7c88..6c61d929 100644 --- a/internal/controller/nats/deprovisioner_test.go +++ b/internal/controller/nats/deprovisioner_test.go @@ -6,22 +6,22 @@ import ( "fmt" "testing" - "github.com/kyma-project/nats-manager/pkg/nats" + nmnats "github.com/kyma-project/nats-manager/pkg/nats" "go.uber.org/zap" - natsmanager "github.com/kyma-project/nats-manager/pkg/manager" + nmmgr "github.com/kyma-project/nats-manager/pkg/manager" "github.com/kyma-project/nats-manager/pkg/nats/mocks" - natsv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" + nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" "github.com/kyma-project/nats-manager/pkg/k8s/chart" - k8smocks "github.com/kyma-project/nats-manager/pkg/k8s/mocks" + nmkmocks "github.com/kyma-project/nats-manager/pkg/k8s/mocks" "github.com/kyma-project/nats-manager/testutils" - natssdk "github.com/nats-io/nats.go" + natsgo "github.com/nats-io/nats.go" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - ctrl "sigs.k8s.io/controller-runtime" + kcontrollerruntime "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" ) @@ -34,39 +34,39 @@ func Test_handleNATSDeletion(t *testing.T) { name string givenWithNATSCreated bool natsCrWithoutFinalizer bool - mockNatsClientFunc func() nats.Client - wantCondition *metav1.Condition + mockNatsClientFunc func() nmnats.Client + wantCondition *kmetav1.Condition wantNATSStatusState string wantFinalizerExists bool wantK8sEvents []string - wantResult ctrl.Result + wantResult kcontrollerruntime.Result }{ { name: "should not do anything if finalizer is not set", givenWithNATSCreated: false, natsCrWithoutFinalizer: true, - wantNATSStatusState: natsv1alpha1.StateReady, + wantNATSStatusState: nmapiv1alpha1.StateReady, wantK8sEvents: []string{}, - wantResult: ctrl.Result{}, + wantResult: kcontrollerruntime.Result{}, }, { name: "should delete resources if connection to NATS server is not established", givenWithNATSCreated: true, - mockNatsClientFunc: func() nats.Client { + mockNatsClientFunc: func() nmnats.Client { natsClient := new(mocks.Client) natsClient.On("Init").Return(errors.New("connection cannot be established")) natsClient.On("Close").Return() return natsClient }, - wantNATSStatusState: natsv1alpha1.StateDeleting, + wantNATSStatusState: nmapiv1alpha1.StateDeleting, wantK8sEvents: []string{"Normal Deleting Deleting the NATS cluster."}, - wantResult: ctrl.Result{}, + wantResult: kcontrollerruntime.Result{}, }, { name: "should delete resources if natsClients GetStreams returns unexpected error", givenWithNATSCreated: true, - wantNATSStatusState: natsv1alpha1.StateDeleting, - mockNatsClientFunc: func() nats.Client { + wantNATSStatusState: nmapiv1alpha1.StateDeleting, + mockNatsClientFunc: func() nmnats.Client { natsClient := new(mocks.Client) natsClient.On("Init").Return(nil) natsClient.On("GetStreams").Return(nil, errors.New("unexpected error")) @@ -74,18 +74,18 @@ func Test_handleNATSDeletion(t *testing.T) { return natsClient }, wantK8sEvents: []string{"Normal Deleting Deleting the NATS cluster."}, - wantResult: ctrl.Result{}, + wantResult: kcontrollerruntime.Result{}, }, { name: "should delete resources if natsClients ConsumersExist returns unexpected error", givenWithNATSCreated: true, - wantNATSStatusState: natsv1alpha1.StateDeleting, - mockNatsClientFunc: func() nats.Client { + wantNATSStatusState: nmapiv1alpha1.StateDeleting, + mockNatsClientFunc: func() nmnats.Client { natsClient := new(mocks.Client) natsClient.On("Init").Return(nil) - natsClient.On("GetStreams").Return([]*natssdk.StreamInfo{ + natsClient.On("GetStreams").Return([]*natsgo.StreamInfo{ { - Config: natssdk.StreamConfig{ + Config: natsgo.StreamConfig{ Name: SapStreamName, }, }, @@ -95,25 +95,25 @@ func Test_handleNATSDeletion(t *testing.T) { return natsClient }, wantK8sEvents: []string{"Normal Deleting Deleting the NATS cluster."}, - wantResult: ctrl.Result{}, + wantResult: kcontrollerruntime.Result{}, }, { name: "should block deletion if non 'sap' stream exists", givenWithNATSCreated: true, - wantNATSStatusState: natsv1alpha1.StateWarning, - wantCondition: &metav1.Condition{ - Type: string(natsv1alpha1.ConditionDeleted), - Status: metav1.ConditionFalse, - LastTransitionTime: metav1.Now(), - Reason: string(natsv1alpha1.ConditionReasonDeletionError), + wantNATSStatusState: nmapiv1alpha1.StateWarning, + wantCondition: &kmetav1.Condition{ + Type: string(nmapiv1alpha1.ConditionDeleted), + Status: kmetav1.ConditionFalse, + LastTransitionTime: kmetav1.Now(), + Reason: string(nmapiv1alpha1.ConditionReasonDeletionError), Message: StreamExistsErrorMsg, }, - mockNatsClientFunc: func() nats.Client { + mockNatsClientFunc: func() nmnats.Client { natsClient := new(mocks.Client) natsClient.On("Init").Return(nil) - natsClient.On("GetStreams").Return([]*natssdk.StreamInfo{ + natsClient.On("GetStreams").Return([]*natsgo.StreamInfo{ { - Config: natssdk.StreamConfig{ + Config: natsgo.StreamConfig{ Name: "non-sap", }, }, @@ -126,25 +126,25 @@ func Test_handleNATSDeletion(t *testing.T) { "Normal Deleting Deleting the NATS cluster.", "Warning DeletionError " + StreamExistsErrorMsg, }, - wantResult: ctrl.Result{Requeue: true}, + wantResult: kcontrollerruntime.Result{Requeue: true}, }, { name: "should block deletion if 'sap' stream consumer exists", givenWithNATSCreated: true, - wantNATSStatusState: natsv1alpha1.StateWarning, - wantCondition: &metav1.Condition{ - Type: string(natsv1alpha1.ConditionDeleted), - Status: metav1.ConditionFalse, - LastTransitionTime: metav1.Now(), - Reason: string(natsv1alpha1.ConditionReasonDeletionError), + wantNATSStatusState: nmapiv1alpha1.StateWarning, + wantCondition: &kmetav1.Condition{ + Type: string(nmapiv1alpha1.ConditionDeleted), + Status: kmetav1.ConditionFalse, + LastTransitionTime: kmetav1.Now(), + Reason: string(nmapiv1alpha1.ConditionReasonDeletionError), Message: ConsumerExistsErrorMsg, }, - mockNatsClientFunc: func() nats.Client { + mockNatsClientFunc: func() nmnats.Client { natsClient := new(mocks.Client) natsClient.On("Init").Return(nil) - natsClient.On("GetStreams").Return([]*natssdk.StreamInfo{ + natsClient.On("GetStreams").Return([]*natsgo.StreamInfo{ { - Config: natssdk.StreamConfig{ + Config: natsgo.StreamConfig{ Name: SapStreamName, }, }, @@ -158,18 +158,18 @@ func Test_handleNATSDeletion(t *testing.T) { "Normal Deleting Deleting the NATS cluster.", "Warning DeletionError " + ConsumerExistsErrorMsg, }, - wantResult: ctrl.Result{Requeue: true}, + wantResult: kcontrollerruntime.Result{Requeue: true}, }, { name: "should delete resources if neither consumer stream nor 'sap' stream exists", givenWithNATSCreated: true, - wantNATSStatusState: natsv1alpha1.StateDeleting, - mockNatsClientFunc: func() nats.Client { + wantNATSStatusState: nmapiv1alpha1.StateDeleting, + mockNatsClientFunc: func() nmnats.Client { natsClient := new(mocks.Client) natsClient.On("Init").Return(nil) - natsClient.On("GetStreams").Return([]*natssdk.StreamInfo{ + natsClient.On("GetStreams").Return([]*natsgo.StreamInfo{ { - Config: natssdk.StreamConfig{ + Config: natsgo.StreamConfig{ Name: SapStreamName, }, }, @@ -181,7 +181,7 @@ func Test_handleNATSDeletion(t *testing.T) { wantK8sEvents: []string{ "Normal Deleting Deleting the NATS cluster.", }, - wantResult: ctrl.Result{}, + wantResult: kcontrollerruntime.Result{}, }, } @@ -192,7 +192,7 @@ func Test_handleNATSDeletion(t *testing.T) { t.Parallel() // given - var givenNats *natsv1alpha1.NATS + var givenNats *nmapiv1alpha1.NATS if tc.natsCrWithoutFinalizer { givenNats = testutils.NewNATSCR( testutils.WithNATSCRStatusInitialized(), @@ -236,8 +236,8 @@ func Test_handleNATSDeletion(t *testing.T) { testEnv.natsManager.On("GenerateOverrides", mock.Anything, mock.Anything, mock.Anything).Return( map[string]interface{}{ - natsmanager.IstioEnabledKey: false, - natsmanager.RotatePasswordKey: true, // do not recreate secret if it exists + nmmgr.IstioEnabledKey: false, + nmmgr.RotatePasswordKey: true, // do not recreate secret if it exists }, ) @@ -256,9 +256,9 @@ func Test_handleNATSDeletion(t *testing.T) { } if tc.wantCondition != nil { - gotCondition := nats.Status.FindCondition(natsv1alpha1.ConditionType(tc.wantCondition.Type)) + gotCondition := nats.Status.FindCondition(nmapiv1alpha1.ConditionType(tc.wantCondition.Type)) require.NotNil(t, gotCondition) - require.True(t, natsv1alpha1.ConditionEquals(*gotCondition, *tc.wantCondition)) + require.True(t, nmapiv1alpha1.ConditionEquals(*gotCondition, *tc.wantCondition)) } // check k8s events @@ -273,10 +273,10 @@ func Test_handleNATSDeletion(t *testing.T) { func Test_DeletePVCsAndRemoveFinalizer(t *testing.T) { tests := []struct { name string - nats *natsv1alpha1.NATS + nats *nmapiv1alpha1.NATS labelValue string deleteErr error - expectedResult ctrl.Result + expectedResult kcontrollerruntime.Result expectedErr error }{ { @@ -288,7 +288,7 @@ func Test_DeletePVCsAndRemoveFinalizer(t *testing.T) { ), labelValue: "test-nats", deleteErr: nil, - expectedResult: ctrl.Result{}, + expectedResult: kcontrollerruntime.Result{}, expectedErr: nil, }, { @@ -300,7 +300,7 @@ func Test_DeletePVCsAndRemoveFinalizer(t *testing.T) { ), labelValue: "eventing", deleteErr: nil, - expectedResult: ctrl.Result{}, + expectedResult: kcontrollerruntime.Result{}, expectedErr: nil, }, { @@ -312,7 +312,7 @@ func Test_DeletePVCsAndRemoveFinalizer(t *testing.T) { ), labelValue: "test-nats", deleteErr: errors.New("delete error"), - expectedResult: ctrl.Result{}, + expectedResult: kcontrollerruntime.Result{}, expectedErr: errors.New("delete error"), }, } @@ -327,7 +327,7 @@ func Test_DeletePVCsAndRemoveFinalizer(t *testing.T) { testEnv := NewMockedUnitTestEnvironment(t, objs...) r := testEnv.Reconciler - r.kubeClient.(*k8smocks.Client).On("DeletePVCsWithLabel", mock.Anything, mock.Anything, + r.kubeClient.(*nmkmocks.Client).On("DeletePVCsWithLabel", mock.Anything, mock.Anything, tt.nats.Name, tt.nats.Namespace).Return(tt.deleteErr) natsClient := new(mocks.Client) r.setNatsClient(tt.nats, natsClient) @@ -342,7 +342,7 @@ func Test_DeletePVCsAndRemoveFinalizer(t *testing.T) { } labelSelector := fmt.Sprintf("%s=%s", InstanceLabelKey, tt.labelValue) - r.kubeClient.(*k8smocks.Client).EXPECT().DeletePVCsWithLabel(mock.Anything, labelSelector, + r.kubeClient.(*nmkmocks.Client).EXPECT().DeletePVCsWithLabel(mock.Anything, labelSelector, tt.nats.Name, tt.nats.Namespace).Times(1) }) } @@ -351,7 +351,7 @@ func Test_DeletePVCsAndRemoveFinalizer(t *testing.T) { func Test_CreateAndConnectNatsClient(t *testing.T) { tests := []struct { name string - nats *natsv1alpha1.NATS + nats *nmapiv1alpha1.NATS initErr error expectedErr error }{ @@ -378,7 +378,7 @@ func Test_CreateAndConnectNatsClient(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { r := &Reconciler{} - r.natsClients = make(map[string]nats.Client) + r.natsClients = make(map[string]nmnats.Client) r.setNatsClient(tt.nats, new(mocks.Client)) r.getNatsClient(tt.nats).(*mocks.Client).On("Init").Return(tt.initErr) @@ -395,7 +395,7 @@ func Test_CreateAndConnectNatsClient(t *testing.T) { func Test_CloseNatsClient(t *testing.T) { tests := []struct { name string - nats *natsv1alpha1.NATS + nats *nmapiv1alpha1.NATS existingClient *mocks.Client }{ { @@ -419,7 +419,7 @@ func Test_CloseNatsClient(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { r := &Reconciler{} - r.natsClients = make(map[string]nats.Client) + r.natsClients = make(map[string]nmnats.Client) if tt.existingClient != nil { tt.existingClient.On("Close").Return(nil) r.setNatsClient(tt.nats, tt.existingClient) diff --git a/internal/controller/nats/integrationtests/controller/integration_test.go b/internal/controller/nats/integrationtests/controller/integration_test.go index a850fe55..27f45c0c 100644 --- a/internal/controller/nats/integrationtests/controller/integration_test.go +++ b/internal/controller/nats/integrationtests/controller/integration_test.go @@ -7,19 +7,20 @@ import ( "testing" "time" - v1 "k8s.io/api/events/v1" + keventsv1 "k8s.io/api/events/v1" "github.com/onsi/gomega" - gomegatypes "github.com/onsi/gomega/types" + + onsigomegatypes "github.com/onsi/gomega/types" "github.com/stretchr/testify/require" - corev1 "k8s.io/api/core/v1" + kcorev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" - "github.com/kyma-project/nats-manager/api/v1alpha1" - "github.com/kyma-project/nats-manager/internal/controller/nats" + nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" + nmctrl "github.com/kyma-project/nats-manager/internal/controller/nats" "github.com/kyma-project/nats-manager/testutils" "github.com/kyma-project/nats-manager/testutils/integration" - natsmatchers "github.com/kyma-project/nats-manager/testutils/matchers/nats" + nmtsmatchers "github.com/kyma-project/nats-manager/testutils/matchers/nats" ) const projectRootDir = "../../../../../" @@ -54,11 +55,11 @@ func Test_CreateNATSCR(t *testing.T) { testCases := []struct { name string - givenNATS *v1alpha1.NATS - givenK8sEvents v1.EventList + givenNATS *nmapiv1alpha1.NATS + givenK8sEvents keventsv1.EventList givenStatefulSetReady bool - wantMatches gomegatypes.GomegaMatcher - wantEventMatches gomegatypes.GomegaMatcher + wantMatches onsigomegatypes.GomegaMatcher + wantEventMatches onsigomegatypes.GomegaMatcher wantEnsureK8sObjects bool }{ { @@ -68,12 +69,12 @@ func Test_CreateNATSCR(t *testing.T) { ), givenStatefulSetReady: false, wantMatches: gomega.And( - natsmatchers.HaveStatusProcessing(), - natsmatchers.HavePendingConditionStatefulSet(), - natsmatchers.HaveDeployingConditionAvailable(), + nmtsmatchers.HaveStatusProcessing(), + nmtsmatchers.HavePendingConditionStatefulSet(), + nmtsmatchers.HaveDeployingConditionAvailable(), ), wantEventMatches: gomega.And( - natsmatchers.HaveProcessingEvent(), + nmtsmatchers.HaveProcessingEvent(), ), }, { @@ -83,13 +84,13 @@ func Test_CreateNATSCR(t *testing.T) { ), givenStatefulSetReady: true, wantMatches: gomega.And( - natsmatchers.HaveStatusReady(), - natsmatchers.HaveReadyConditionStatefulSet(), - natsmatchers.HaveReadyConditionAvailable(), + nmtsmatchers.HaveStatusReady(), + nmtsmatchers.HaveReadyConditionStatefulSet(), + nmtsmatchers.HaveReadyConditionAvailable(), ), wantEventMatches: gomega.And( - natsmatchers.HaveProcessingEvent(), - natsmatchers.HaveDeployingEvent(), + nmtsmatchers.HaveProcessingEvent(), + nmtsmatchers.HaveDeployingEvent(), ), }, { @@ -97,12 +98,12 @@ func Test_CreateNATSCR(t *testing.T) { givenNATS: testutils.NewNATSCR( testutils.WithNATSCRDefaults(), testutils.WithNATSLogging(true, true), - testutils.WithNATSResources(corev1.ResourceRequirements{ - Limits: corev1.ResourceList{ + testutils.WithNATSResources(kcorev1.ResourceRequirements{ + Limits: kcorev1.ResourceList{ "cpu": resource.MustParse("199m"), "memory": resource.MustParse("199Mi"), }, - Requests: corev1.ResourceList{ + Requests: kcorev1.ResourceList{ "cpu": resource.MustParse("99m"), "memory": resource.MustParse("99Mi"), }, @@ -113,25 +114,25 @@ func Test_CreateNATSCR(t *testing.T) { testutils.WithNATSAnnotations(map[string]string{ "test-key2": "value2", }), - testutils.WithNATSFileStorage(v1alpha1.FileStorage{ + testutils.WithNATSFileStorage(nmapiv1alpha1.FileStorage{ StorageClassName: "test-sc1", Size: resource.MustParse("66Gi"), }), - testutils.WithNATSMemStorage(v1alpha1.MemStorage{ + testutils.WithNATSMemStorage(nmapiv1alpha1.MemStorage{ Enabled: true, Size: resource.MustParse("66Gi"), }), ), givenStatefulSetReady: true, wantMatches: gomega.And( - natsmatchers.HaveStatusReady(), - natsmatchers.HaveReadyConditionStatefulSet(), - natsmatchers.HaveReadyConditionAvailable(), + nmtsmatchers.HaveStatusReady(), + nmtsmatchers.HaveReadyConditionStatefulSet(), + nmtsmatchers.HaveReadyConditionAvailable(), ), wantEnsureK8sObjects: true, wantEventMatches: gomega.And( - natsmatchers.HaveProcessingEvent(), - natsmatchers.HaveDeployingEvent(), + nmtsmatchers.HaveProcessingEvent(), + nmtsmatchers.HaveDeployingEvent(), ), }, } @@ -195,8 +196,8 @@ func Test_UpdateNATSCR(t *testing.T) { t.Parallel() testCases := []struct { name string - givenNATS *v1alpha1.NATS - givenUpdateNATS *v1alpha1.NATS + givenNATS *nmapiv1alpha1.NATS + givenUpdateNATS *nmapiv1alpha1.NATS }{ { name: "NATS CR should have ready status when StatefulSet is ready", @@ -210,12 +211,12 @@ func Test_UpdateNATSCR(t *testing.T) { testutils.WithNATSCRName("name-stays-the-same-1"), testutils.WithNATSCRNamespace("namespace-stays-the-same-1"), testutils.WithNATSLogging(true, true), - testutils.WithNATSResources(corev1.ResourceRequirements{ - Limits: corev1.ResourceList{ + testutils.WithNATSResources(kcorev1.ResourceRequirements{ + Limits: kcorev1.ResourceList{ "cpu": resource.MustParse("199m"), "memory": resource.MustParse("199Mi"), }, - Requests: corev1.ResourceList{ + Requests: kcorev1.ResourceList{ "cpu": resource.MustParse("99m"), "memory": resource.MustParse("99Mi"), }, @@ -226,7 +227,7 @@ func Test_UpdateNATSCR(t *testing.T) { testutils.WithNATSAnnotations(map[string]string{ "test-key2": "value2", }), - testutils.WithNATSMemStorage(v1alpha1.MemStorage{ + testutils.WithNATSMemStorage(nmapiv1alpha1.MemStorage{ Enabled: true, Size: resource.MustParse("66Gi"), }), @@ -279,7 +280,7 @@ func Test_DeleteNATSCR(t *testing.T) { testCases := []struct { name string - givenNATS *v1alpha1.NATS + givenNATS *nmapiv1alpha1.NATS }{ { name: "should delete all k8s objects", @@ -292,12 +293,12 @@ func Test_DeleteNATSCR(t *testing.T) { givenNATS: testutils.NewNATSCR( testutils.WithNATSCRDefaults(), testutils.WithNATSLogging(true, true), - testutils.WithNATSResources(corev1.ResourceRequirements{ - Limits: corev1.ResourceList{ + testutils.WithNATSResources(kcorev1.ResourceRequirements{ + Limits: kcorev1.ResourceList{ "cpu": resource.MustParse("199m"), "memory": resource.MustParse("199Mi"), }, - Requests: corev1.ResourceList{ + Requests: kcorev1.ResourceList{ "cpu": resource.MustParse("99m"), "memory": resource.MustParse("99Mi"), }, @@ -308,11 +309,11 @@ func Test_DeleteNATSCR(t *testing.T) { testutils.WithNATSAnnotations(map[string]string{ "test-key2": "value2", }), - testutils.WithNATSFileStorage(v1alpha1.FileStorage{ + testutils.WithNATSFileStorage(nmapiv1alpha1.FileStorage{ StorageClassName: "test-sc1", Size: resource.MustParse("66Gi"), }), - testutils.WithNATSMemStorage(v1alpha1.MemStorage{ + testutils.WithNATSMemStorage(nmapiv1alpha1.MemStorage{ Enabled: true, Size: resource.MustParse("66Gi"), }), @@ -344,7 +345,7 @@ func Test_DeleteNATSCR(t *testing.T) { if !*testEnvironment.EnvTestInstance.UseExistingCluster { // create a PVC as local envtest cluster cannot create PVCs. pvc := testutils.NewPVC(tc.givenNATS.Name, givenNamespace, - map[string]string{nats.InstanceLabelKey: tc.givenNATS.Name}) + map[string]string{nmctrl.InstanceLabelKey: tc.givenNATS.Name}) testEnvironment.EnsureK8sResourceCreated(t, pvc) } @@ -371,7 +372,7 @@ func Test_WatcherNATSCRK8sObjects(t *testing.T) { testCases := []struct { name string - givenNATS *v1alpha1.NATS + givenNATS *nmapiv1alpha1.NATS wantResourceDeletion []deletionFunc }{ { @@ -489,8 +490,8 @@ func Test_DoubleReconcileNATSCR(t *testing.T) { testCases := []struct { name string - givenNATS *v1alpha1.NATS - wantMatchers gomegatypes.GomegaMatcher + givenNATS *nmapiv1alpha1.NATS + wantMatchers onsigomegatypes.GomegaMatcher }{ { name: "should have reconciled again without problems", @@ -498,12 +499,12 @@ func Test_DoubleReconcileNATSCR(t *testing.T) { testutils.WithNATSCRDefaults(), testutils.WithNATSCRName("test1"), testutils.WithNATSLogging(true, true), - testutils.WithNATSResources(corev1.ResourceRequirements{ - Limits: corev1.ResourceList{ + testutils.WithNATSResources(kcorev1.ResourceRequirements{ + Limits: kcorev1.ResourceList{ "cpu": resource.MustParse("199m"), "memory": resource.MustParse("199Mi"), }, - Requests: corev1.ResourceList{ + Requests: kcorev1.ResourceList{ "cpu": resource.MustParse("99m"), "memory": resource.MustParse("99Mi"), }, @@ -514,19 +515,19 @@ func Test_DoubleReconcileNATSCR(t *testing.T) { testutils.WithNATSAnnotations(map[string]string{ "test-key2": "value2", }), - testutils.WithNATSFileStorage(v1alpha1.FileStorage{ + testutils.WithNATSFileStorage(nmapiv1alpha1.FileStorage{ StorageClassName: "test-sc1", Size: resource.MustParse("66Gi"), }), - testutils.WithNATSMemStorage(v1alpha1.MemStorage{ + testutils.WithNATSMemStorage(nmapiv1alpha1.MemStorage{ Enabled: true, Size: resource.MustParse("66Gi"), }), ), wantMatchers: gomega.And( - natsmatchers.HaveStatusReady(), - natsmatchers.HaveReadyConditionStatefulSet(), - natsmatchers.HaveReadyConditionAvailable(), + nmtsmatchers.HaveStatusReady(), + nmtsmatchers.HaveReadyConditionStatefulSet(), + nmtsmatchers.HaveReadyConditionAvailable(), ), }, } @@ -607,7 +608,7 @@ func makeStatefulSetReady(t *testing.T, name, namespace string) { require.Eventually(t, func() bool { sts, err := testEnvironment.GetStatefulSetFromK8s(name, namespace) if err != nil { - testEnvironment.Logger.Errorw("failed to get statefulSet", err) + testEnvironment.Logger.Errorw("failed to get statefulSet", "error", err) return false } @@ -619,7 +620,7 @@ func makeStatefulSetReady(t *testing.T, name, namespace string) { err = testEnvironment.UpdateStatefulSetStatusOnK8s(*sts) if err != nil { - testEnvironment.Logger.Errorw("failed to update statefulSet status", err) + testEnvironment.Logger.Errorw("failed to update statefulSet status", "error", err) return false } return true diff --git a/internal/controller/nats/integrationtests/controllersinglecr/integration_test.go b/internal/controller/nats/integrationtests/controllersinglecr/integration_test.go index 51f590e4..7eb9a43d 100644 --- a/internal/controller/nats/integrationtests/controllersinglecr/integration_test.go +++ b/internal/controller/nats/integrationtests/controllersinglecr/integration_test.go @@ -6,12 +6,12 @@ import ( "os" "testing" - "github.com/kyma-project/nats-manager/api/v1alpha1" + nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" "github.com/kyma-project/nats-manager/testutils" "github.com/kyma-project/nats-manager/testutils/integration" - natsmatchers "github.com/kyma-project/nats-manager/testutils/matchers/nats" + nmtsmatchers "github.com/kyma-project/nats-manager/testutils/matchers/nats" "github.com/onsi/gomega" - gomegatypes "github.com/onsi/gomega/types" + onsigomegatypes "github.com/onsi/gomega/types" ) const projectRootDir = "../../../../../" @@ -59,8 +59,8 @@ func Test_PreventMultipleNATSCRs(t *testing.T) { testCases := []struct { name string - givenNATS *v1alpha1.NATS - wantMatches gomegatypes.GomegaMatcher + givenNATS *nmapiv1alpha1.NATS + wantMatches onsigomegatypes.GomegaMatcher }{ { name: "should allow NATS CR if name and namespace is correct", @@ -70,9 +70,9 @@ func Test_PreventMultipleNATSCRs(t *testing.T) { testutils.WithNATSCRNamespace(givenAllowedNATS.Namespace), ), wantMatches: gomega.And( - natsmatchers.HaveStatusProcessing(), - natsmatchers.HavePendingConditionStatefulSet(), - natsmatchers.HaveDeployingConditionAvailable(), + nmtsmatchers.HaveStatusProcessing(), + nmtsmatchers.HavePendingConditionStatefulSet(), + nmtsmatchers.HaveDeployingConditionAvailable(), ), }, { @@ -83,9 +83,9 @@ func Test_PreventMultipleNATSCRs(t *testing.T) { testutils.WithNATSCRNamespace("kyma-system"), ), wantMatches: gomega.And( - natsmatchers.HaveStatusError(), - natsmatchers.HaveForbiddenConditionStatefulSet(), - natsmatchers.HaveForbiddenConditionAvailableWithMsg(errMsg), + nmtsmatchers.HaveStatusError(), + nmtsmatchers.HaveForbiddenConditionStatefulSet(), + nmtsmatchers.HaveForbiddenConditionAvailableWithMsg(errMsg), ), }, { @@ -96,9 +96,9 @@ func Test_PreventMultipleNATSCRs(t *testing.T) { testutils.WithNATSCRNamespace("not-allowed-namespace"), ), wantMatches: gomega.And( - natsmatchers.HaveStatusError(), - natsmatchers.HaveForbiddenConditionStatefulSet(), - natsmatchers.HaveForbiddenConditionAvailableWithMsg(errMsg), + nmtsmatchers.HaveStatusError(), + nmtsmatchers.HaveForbiddenConditionStatefulSet(), + nmtsmatchers.HaveForbiddenConditionAvailableWithMsg(errMsg), ), }, { @@ -109,9 +109,9 @@ func Test_PreventMultipleNATSCRs(t *testing.T) { testutils.WithNATSCRNamespace("not-allowed-namespace"), ), wantMatches: gomega.And( - natsmatchers.HaveStatusError(), - natsmatchers.HaveForbiddenConditionStatefulSet(), - natsmatchers.HaveForbiddenConditionAvailableWithMsg(errMsg), + nmtsmatchers.HaveStatusError(), + nmtsmatchers.HaveForbiddenConditionStatefulSet(), + nmtsmatchers.HaveForbiddenConditionAvailableWithMsg(errMsg), ), }, } diff --git a/internal/controller/nats/integrationtests/validation/integration_test.go b/internal/controller/nats/integrationtests/validation/integration_test.go index 8749f06c..27b77162 100644 --- a/internal/controller/nats/integrationtests/validation/integration_test.go +++ b/internal/controller/nats/integrationtests/validation/integration_test.go @@ -6,16 +6,16 @@ import ( "testing" "github.com/onsi/gomega" - gomegatypes "github.com/onsi/gomega/types" + onsigomegatypes "github.com/onsi/gomega/types" "github.com/stretchr/testify/require" - corev1 "k8s.io/api/core/v1" + kcorev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - "github.com/kyma-project/nats-manager/api/v1alpha1" + nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" "github.com/kyma-project/nats-manager/testutils" - natsmatchers "github.com/kyma-project/nats-manager/testutils/matchers/nats" + nmtsmatchers "github.com/kyma-project/nats-manager/testutils/matchers/nats" "github.com/kyma-project/nats-manager/testutils/integration" ) @@ -228,8 +228,8 @@ func Test_Validate_CreateNATS(t *testing.T) { func Test_Validate_UpdateNATS(t *testing.T) { testCases := []struct { name string - givenNATS *v1alpha1.NATS - wantMatches gomegatypes.GomegaMatcher + givenNATS *nmapiv1alpha1.NATS + wantMatches onsigomegatypes.GomegaMatcher givenUpdates []testutils.NATSOption wantErrMsg string }{ @@ -239,10 +239,10 @@ func Test_Validate_UpdateNATS(t *testing.T) { testutils.WithNATSFileStorage(defaultFileStorage()), ), wantMatches: gomega.And( - natsmatchers.HaveSpecJetStreamFileStorage(defaultFileStorage()), + nmtsmatchers.HaveSpecJetStreamFileStorage(defaultFileStorage()), ), givenUpdates: []testutils.NATSOption{ - testutils.WithNATSFileStorage(v1alpha1.FileStorage{ + testutils.WithNATSFileStorage(nmapiv1alpha1.FileStorage{ StorageClassName: defaultFileStorage().StorageClassName, Size: resource.MustParse("2Gi"), }), @@ -255,10 +255,10 @@ func Test_Validate_UpdateNATS(t *testing.T) { testutils.WithNATSFileStorage(defaultFileStorage()), ), wantMatches: gomega.And( - natsmatchers.HaveSpecJetStreamFileStorage(defaultFileStorage()), + nmtsmatchers.HaveSpecJetStreamFileStorage(defaultFileStorage()), ), givenUpdates: []testutils.NATSOption{ - testutils.WithNATSFileStorage(v1alpha1.FileStorage{ + testutils.WithNATSFileStorage(nmapiv1alpha1.FileStorage{ StorageClassName: "not-standard", Size: defaultFileStorage().Size, }), @@ -271,10 +271,10 @@ func Test_Validate_UpdateNATS(t *testing.T) { testutils.WithNATSCluster(defaultCluster()), ), wantMatches: gomega.And( - natsmatchers.HaveSpecCluster(defaultCluster()), + nmtsmatchers.HaveSpecCluster(defaultCluster()), ), givenUpdates: []testutils.NATSOption{ - testutils.WithNATSCluster(v1alpha1.Cluster{ + testutils.WithNATSCluster(nmapiv1alpha1.Cluster{ Size: 1, }), }, @@ -287,10 +287,10 @@ func Test_Validate_UpdateNATS(t *testing.T) { testutils.WithNATSCluster(defaultCluster()), ), wantMatches: gomega.And( - natsmatchers.HaveSpecCluster(defaultCluster()), + nmtsmatchers.HaveSpecCluster(defaultCluster()), ), givenUpdates: []testutils.NATSOption{ - testutils.WithNATSCluster(v1alpha1.Cluster{ + testutils.WithNATSCluster(nmapiv1alpha1.Cluster{ Size: 5, }), }, @@ -332,7 +332,7 @@ func Test_NATS_Defaulting(t *testing.T) { name string // We use Unstructured instead of NATS to ensure that all undefined properties are nil and not Go defaults. givenUnstructuredNATS unstructured.Unstructured - wantMatches gomegatypes.GomegaMatcher + wantMatches onsigomegatypes.GomegaMatcher }{ { name: "defaulting with bare minimum NATS", @@ -347,11 +347,11 @@ func Test_NATS_Defaulting(t *testing.T) { }, }, wantMatches: gomega.And( - natsmatchers.HaveSpecCluster(defaultCluster()), - natsmatchers.HaveSpecResources(defaultResources()), - natsmatchers.HaveSpecLogging(defaultLogging()), - natsmatchers.HaveSpecJetsStreamMemStorage(defaultMemStorage()), - natsmatchers.HaveSpecJetStreamFileStorage(defaultFileStorage()), + nmtsmatchers.HaveSpecCluster(defaultCluster()), + nmtsmatchers.HaveSpecResources(defaultResources()), + nmtsmatchers.HaveSpecLogging(defaultLogging()), + nmtsmatchers.HaveSpecJetsStreamMemStorage(defaultMemStorage()), + nmtsmatchers.HaveSpecJetStreamFileStorage(defaultFileStorage()), ), }, { @@ -368,11 +368,11 @@ func Test_NATS_Defaulting(t *testing.T) { }, }, wantMatches: gomega.And( - natsmatchers.HaveSpecCluster(defaultCluster()), - natsmatchers.HaveSpecResources(defaultResources()), - natsmatchers.HaveSpecLogging(defaultLogging()), - natsmatchers.HaveSpecJetsStreamMemStorage(defaultMemStorage()), - natsmatchers.HaveSpecJetStreamFileStorage(defaultFileStorage()), + nmtsmatchers.HaveSpecCluster(defaultCluster()), + nmtsmatchers.HaveSpecResources(defaultResources()), + nmtsmatchers.HaveSpecLogging(defaultLogging()), + nmtsmatchers.HaveSpecJetsStreamMemStorage(defaultMemStorage()), + nmtsmatchers.HaveSpecJetStreamFileStorage(defaultFileStorage()), ), }, { @@ -391,7 +391,7 @@ func Test_NATS_Defaulting(t *testing.T) { }, }, wantMatches: gomega.And( - natsmatchers.HaveSpecCluster(defaultCluster()), + nmtsmatchers.HaveSpecCluster(defaultCluster()), ), }, { @@ -410,8 +410,8 @@ func Test_NATS_Defaulting(t *testing.T) { }, }, wantMatches: gomega.And( - natsmatchers.HaveSpecJetsStreamMemStorage(defaultMemStorage()), - natsmatchers.HaveSpecJetStreamFileStorage(defaultFileStorage()), + nmtsmatchers.HaveSpecJetsStreamMemStorage(defaultMemStorage()), + nmtsmatchers.HaveSpecJetStreamFileStorage(defaultFileStorage()), ), }, { @@ -433,8 +433,8 @@ func Test_NATS_Defaulting(t *testing.T) { }, }, wantMatches: gomega.And( - natsmatchers.HaveSpecJetsStreamMemStorage(defaultMemStorage()), - natsmatchers.HaveSpecJetStreamFileStorage(defaultFileStorage()), + nmtsmatchers.HaveSpecJetsStreamMemStorage(defaultMemStorage()), + nmtsmatchers.HaveSpecJetStreamFileStorage(defaultFileStorage()), ), }, { @@ -453,7 +453,7 @@ func Test_NATS_Defaulting(t *testing.T) { }, }, wantMatches: gomega.And( - natsmatchers.HaveSpecLogging(defaultLogging()), + nmtsmatchers.HaveSpecLogging(defaultLogging()), ), }, } @@ -471,8 +471,8 @@ func Test_NATS_Defaulting(t *testing.T) { testEnvironment.EnsureK8sUnStructResourceCreated(t, &tc.givenUnstructuredNATS) // then - testEnvironment.GetNATSAssert(g, &v1alpha1.NATS{ - ObjectMeta: metav1.ObjectMeta{ + testEnvironment.GetNATSAssert(g, &nmapiv1alpha1.NATS{ + ObjectMeta: kmetav1.ObjectMeta{ Name: tc.givenUnstructuredNATS.GetName(), Namespace: tc.givenUnstructuredNATS.GetNamespace(), }, @@ -481,40 +481,40 @@ func Test_NATS_Defaulting(t *testing.T) { } } -func defaultResources() corev1.ResourceRequirements { - return corev1.ResourceRequirements{ - Limits: corev1.ResourceList{ +func defaultResources() kcorev1.ResourceRequirements { + return kcorev1.ResourceRequirements{ + Limits: kcorev1.ResourceList{ "cpu": resource.MustParse("500m"), "memory": resource.MustParse("1Gi"), }, - Requests: corev1.ResourceList{ + Requests: kcorev1.ResourceList{ "cpu": resource.MustParse("40m"), "memory": resource.MustParse("64Mi"), }, } } -func defaultMemStorage() v1alpha1.MemStorage { - return v1alpha1.MemStorage{ +func defaultMemStorage() nmapiv1alpha1.MemStorage { + return nmapiv1alpha1.MemStorage{ Enabled: true, Size: resource.MustParse("1Gi"), } } -func defaultFileStorage() v1alpha1.FileStorage { - return v1alpha1.FileStorage{ +func defaultFileStorage() nmapiv1alpha1.FileStorage { + return nmapiv1alpha1.FileStorage{ StorageClassName: "default", Size: resource.MustParse("1Gi"), } } -func defaultLogging() v1alpha1.Logging { - return v1alpha1.Logging{ +func defaultLogging() nmapiv1alpha1.Logging { + return nmapiv1alpha1.Logging{ Debug: false, Trace: false, } } -func defaultCluster() v1alpha1.Cluster { - return v1alpha1.Cluster{Size: 3} +func defaultCluster() nmapiv1alpha1.Cluster { + return nmapiv1alpha1.Cluster{Size: 3} } diff --git a/internal/controller/nats/mocks/js.go b/internal/controller/nats/mocks/js.go index e3cda65a..f4652337 100644 --- a/internal/controller/nats/mocks/js.go +++ b/internal/controller/nats/mocks/js.go @@ -3,7 +3,7 @@ package mocks import ( - nats "github.com/nats-io/nats.go" + natsgo "github.com/nats-io/nats.go" mock "github.com/stretchr/testify/mock" ) @@ -21,7 +21,7 @@ func (_m *JetStreamContext) EXPECT() *JetStreamContext_Expecter { } // AccountInfo provides a mock function with given fields: opts -func (_m *JetStreamContext) AccountInfo(opts ...nats.JSOpt) (*nats.AccountInfo, error) { +func (_m *JetStreamContext) AccountInfo(opts ...natsgo.JSOpt) (*natsgo.AccountInfo, error) { _va := make([]interface{}, len(opts)) for _i := range opts { _va[_i] = opts[_i] @@ -30,20 +30,20 @@ func (_m *JetStreamContext) AccountInfo(opts ...nats.JSOpt) (*nats.AccountInfo, _ca = append(_ca, _va...) ret := _m.Called(_ca...) - var r0 *nats.AccountInfo + var r0 *natsgo.AccountInfo var r1 error - if rf, ok := ret.Get(0).(func(...nats.JSOpt) (*nats.AccountInfo, error)); ok { + if rf, ok := ret.Get(0).(func(...natsgo.JSOpt) (*natsgo.AccountInfo, error)); ok { return rf(opts...) } - if rf, ok := ret.Get(0).(func(...nats.JSOpt) *nats.AccountInfo); ok { + if rf, ok := ret.Get(0).(func(...natsgo.JSOpt) *natsgo.AccountInfo); ok { r0 = rf(opts...) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*nats.AccountInfo) + r0 = ret.Get(0).(*natsgo.AccountInfo) } } - if rf, ok := ret.Get(1).(func(...nats.JSOpt) error); ok { + if rf, ok := ret.Get(1).(func(...natsgo.JSOpt) error); ok { r1 = rf(opts...) } else { r1 = ret.Error(1) @@ -58,18 +58,18 @@ type JetStreamContext_AccountInfo_Call struct { } // AccountInfo is a helper method to define mock.On call -// - opts ...nats.JSOpt +// - opts ...natsgo.JSOpt func (_e *JetStreamContext_Expecter) AccountInfo(opts ...interface{}) *JetStreamContext_AccountInfo_Call { return &JetStreamContext_AccountInfo_Call{Call: _e.mock.On("AccountInfo", append([]interface{}{}, opts...)...)} } -func (_c *JetStreamContext_AccountInfo_Call) Run(run func(opts ...nats.JSOpt)) *JetStreamContext_AccountInfo_Call { +func (_c *JetStreamContext_AccountInfo_Call) Run(run func(opts ...natsgo.JSOpt)) *JetStreamContext_AccountInfo_Call { _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]nats.JSOpt, len(args)-0) + variadicArgs := make([]natsgo.JSOpt, len(args)-0) for i, a := range args[0:] { if a != nil { - variadicArgs[i] = a.(nats.JSOpt) + variadicArgs[i] = a.(natsgo.JSOpt) } } run(variadicArgs...) @@ -77,18 +77,18 @@ func (_c *JetStreamContext_AccountInfo_Call) Run(run func(opts ...nats.JSOpt)) * return _c } -func (_c *JetStreamContext_AccountInfo_Call) Return(_a0 *nats.AccountInfo, _a1 error) *JetStreamContext_AccountInfo_Call { +func (_c *JetStreamContext_AccountInfo_Call) Return(_a0 *natsgo.AccountInfo, _a1 error) *JetStreamContext_AccountInfo_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *JetStreamContext_AccountInfo_Call) RunAndReturn(run func(...nats.JSOpt) (*nats.AccountInfo, error)) *JetStreamContext_AccountInfo_Call { +func (_c *JetStreamContext_AccountInfo_Call) RunAndReturn(run func(...natsgo.JSOpt) (*natsgo.AccountInfo, error)) *JetStreamContext_AccountInfo_Call { _c.Call.Return(run) return _c } // AddConsumer provides a mock function with given fields: stream, cfg, opts -func (_m *JetStreamContext) AddConsumer(stream string, cfg *nats.ConsumerConfig, opts ...nats.JSOpt) (*nats.ConsumerInfo, error) { +func (_m *JetStreamContext) AddConsumer(stream string, cfg *natsgo.ConsumerConfig, opts ...natsgo.JSOpt) (*natsgo.ConsumerInfo, error) { _va := make([]interface{}, len(opts)) for _i := range opts { _va[_i] = opts[_i] @@ -98,20 +98,20 @@ func (_m *JetStreamContext) AddConsumer(stream string, cfg *nats.ConsumerConfig, _ca = append(_ca, _va...) ret := _m.Called(_ca...) - var r0 *nats.ConsumerInfo + var r0 *natsgo.ConsumerInfo var r1 error - if rf, ok := ret.Get(0).(func(string, *nats.ConsumerConfig, ...nats.JSOpt) (*nats.ConsumerInfo, error)); ok { + if rf, ok := ret.Get(0).(func(string, *natsgo.ConsumerConfig, ...natsgo.JSOpt) (*natsgo.ConsumerInfo, error)); ok { return rf(stream, cfg, opts...) } - if rf, ok := ret.Get(0).(func(string, *nats.ConsumerConfig, ...nats.JSOpt) *nats.ConsumerInfo); ok { + if rf, ok := ret.Get(0).(func(string, *natsgo.ConsumerConfig, ...natsgo.JSOpt) *natsgo.ConsumerInfo); ok { r0 = rf(stream, cfg, opts...) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*nats.ConsumerInfo) + r0 = ret.Get(0).(*natsgo.ConsumerInfo) } } - if rf, ok := ret.Get(1).(func(string, *nats.ConsumerConfig, ...nats.JSOpt) error); ok { + if rf, ok := ret.Get(1).(func(string, *natsgo.ConsumerConfig, ...natsgo.JSOpt) error); ok { r1 = rf(stream, cfg, opts...) } else { r1 = ret.Error(1) @@ -127,38 +127,38 @@ type JetStreamContext_AddConsumer_Call struct { // AddConsumer is a helper method to define mock.On call // - stream string -// - cfg *nats.ConsumerConfig -// - opts ...nats.JSOpt +// - cfg *natsgo.ConsumerConfig +// - opts ...natsgo.JSOpt func (_e *JetStreamContext_Expecter) AddConsumer(stream interface{}, cfg interface{}, opts ...interface{}) *JetStreamContext_AddConsumer_Call { return &JetStreamContext_AddConsumer_Call{Call: _e.mock.On("AddConsumer", append([]interface{}{stream, cfg}, opts...)...)} } -func (_c *JetStreamContext_AddConsumer_Call) Run(run func(stream string, cfg *nats.ConsumerConfig, opts ...nats.JSOpt)) *JetStreamContext_AddConsumer_Call { +func (_c *JetStreamContext_AddConsumer_Call) Run(run func(stream string, cfg *natsgo.ConsumerConfig, opts ...natsgo.JSOpt)) *JetStreamContext_AddConsumer_Call { _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]nats.JSOpt, len(args)-2) + variadicArgs := make([]natsgo.JSOpt, len(args)-2) for i, a := range args[2:] { if a != nil { - variadicArgs[i] = a.(nats.JSOpt) + variadicArgs[i] = a.(natsgo.JSOpt) } } - run(args[0].(string), args[1].(*nats.ConsumerConfig), variadicArgs...) + run(args[0].(string), args[1].(*natsgo.ConsumerConfig), variadicArgs...) }) return _c } -func (_c *JetStreamContext_AddConsumer_Call) Return(_a0 *nats.ConsumerInfo, _a1 error) *JetStreamContext_AddConsumer_Call { +func (_c *JetStreamContext_AddConsumer_Call) Return(_a0 *natsgo.ConsumerInfo, _a1 error) *JetStreamContext_AddConsumer_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *JetStreamContext_AddConsumer_Call) RunAndReturn(run func(string, *nats.ConsumerConfig, ...nats.JSOpt) (*nats.ConsumerInfo, error)) *JetStreamContext_AddConsumer_Call { +func (_c *JetStreamContext_AddConsumer_Call) RunAndReturn(run func(string, *natsgo.ConsumerConfig, ...natsgo.JSOpt) (*natsgo.ConsumerInfo, error)) *JetStreamContext_AddConsumer_Call { _c.Call.Return(run) return _c } // AddStream provides a mock function with given fields: cfg, opts -func (_m *JetStreamContext) AddStream(cfg *nats.StreamConfig, opts ...nats.JSOpt) (*nats.StreamInfo, error) { +func (_m *JetStreamContext) AddStream(cfg *natsgo.StreamConfig, opts ...natsgo.JSOpt) (*natsgo.StreamInfo, error) { _va := make([]interface{}, len(opts)) for _i := range opts { _va[_i] = opts[_i] @@ -168,20 +168,20 @@ func (_m *JetStreamContext) AddStream(cfg *nats.StreamConfig, opts ...nats.JSOpt _ca = append(_ca, _va...) ret := _m.Called(_ca...) - var r0 *nats.StreamInfo + var r0 *natsgo.StreamInfo var r1 error - if rf, ok := ret.Get(0).(func(*nats.StreamConfig, ...nats.JSOpt) (*nats.StreamInfo, error)); ok { + if rf, ok := ret.Get(0).(func(*natsgo.StreamConfig, ...natsgo.JSOpt) (*natsgo.StreamInfo, error)); ok { return rf(cfg, opts...) } - if rf, ok := ret.Get(0).(func(*nats.StreamConfig, ...nats.JSOpt) *nats.StreamInfo); ok { + if rf, ok := ret.Get(0).(func(*natsgo.StreamConfig, ...natsgo.JSOpt) *natsgo.StreamInfo); ok { r0 = rf(cfg, opts...) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*nats.StreamInfo) + r0 = ret.Get(0).(*natsgo.StreamInfo) } } - if rf, ok := ret.Get(1).(func(*nats.StreamConfig, ...nats.JSOpt) error); ok { + if rf, ok := ret.Get(1).(func(*natsgo.StreamConfig, ...natsgo.JSOpt) error); ok { r1 = rf(cfg, opts...) } else { r1 = ret.Error(1) @@ -196,38 +196,38 @@ type JetStreamContext_AddStream_Call struct { } // AddStream is a helper method to define mock.On call -// - cfg *nats.StreamConfig -// - opts ...nats.JSOpt +// - cfg *natsgo.StreamConfig +// - opts ...natsgo.JSOpt func (_e *JetStreamContext_Expecter) AddStream(cfg interface{}, opts ...interface{}) *JetStreamContext_AddStream_Call { return &JetStreamContext_AddStream_Call{Call: _e.mock.On("AddStream", append([]interface{}{cfg}, opts...)...)} } -func (_c *JetStreamContext_AddStream_Call) Run(run func(cfg *nats.StreamConfig, opts ...nats.JSOpt)) *JetStreamContext_AddStream_Call { +func (_c *JetStreamContext_AddStream_Call) Run(run func(cfg *natsgo.StreamConfig, opts ...natsgo.JSOpt)) *JetStreamContext_AddStream_Call { _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]nats.JSOpt, len(args)-1) + variadicArgs := make([]natsgo.JSOpt, len(args)-1) for i, a := range args[1:] { if a != nil { - variadicArgs[i] = a.(nats.JSOpt) + variadicArgs[i] = a.(natsgo.JSOpt) } } - run(args[0].(*nats.StreamConfig), variadicArgs...) + run(args[0].(*natsgo.StreamConfig), variadicArgs...) }) return _c } -func (_c *JetStreamContext_AddStream_Call) Return(_a0 *nats.StreamInfo, _a1 error) *JetStreamContext_AddStream_Call { +func (_c *JetStreamContext_AddStream_Call) Return(_a0 *natsgo.StreamInfo, _a1 error) *JetStreamContext_AddStream_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *JetStreamContext_AddStream_Call) RunAndReturn(run func(*nats.StreamConfig, ...nats.JSOpt) (*nats.StreamInfo, error)) *JetStreamContext_AddStream_Call { +func (_c *JetStreamContext_AddStream_Call) RunAndReturn(run func(*natsgo.StreamConfig, ...natsgo.JSOpt) (*natsgo.StreamInfo, error)) *JetStreamContext_AddStream_Call { _c.Call.Return(run) return _c } // ChanQueueSubscribe provides a mock function with given fields: subj, queue, ch, opts -func (_m *JetStreamContext) ChanQueueSubscribe(subj string, queue string, ch chan *nats.Msg, opts ...nats.SubOpt) (*nats.Subscription, error) { +func (_m *JetStreamContext) ChanQueueSubscribe(subj string, queue string, ch chan *natsgo.Msg, opts ...natsgo.SubOpt) (*natsgo.Subscription, error) { _va := make([]interface{}, len(opts)) for _i := range opts { _va[_i] = opts[_i] @@ -237,20 +237,20 @@ func (_m *JetStreamContext) ChanQueueSubscribe(subj string, queue string, ch cha _ca = append(_ca, _va...) ret := _m.Called(_ca...) - var r0 *nats.Subscription + var r0 *natsgo.Subscription var r1 error - if rf, ok := ret.Get(0).(func(string, string, chan *nats.Msg, ...nats.SubOpt) (*nats.Subscription, error)); ok { + if rf, ok := ret.Get(0).(func(string, string, chan *natsgo.Msg, ...natsgo.SubOpt) (*natsgo.Subscription, error)); ok { return rf(subj, queue, ch, opts...) } - if rf, ok := ret.Get(0).(func(string, string, chan *nats.Msg, ...nats.SubOpt) *nats.Subscription); ok { + if rf, ok := ret.Get(0).(func(string, string, chan *natsgo.Msg, ...natsgo.SubOpt) *natsgo.Subscription); ok { r0 = rf(subj, queue, ch, opts...) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*nats.Subscription) + r0 = ret.Get(0).(*natsgo.Subscription) } } - if rf, ok := ret.Get(1).(func(string, string, chan *nats.Msg, ...nats.SubOpt) error); ok { + if rf, ok := ret.Get(1).(func(string, string, chan *natsgo.Msg, ...natsgo.SubOpt) error); ok { r1 = rf(subj, queue, ch, opts...) } else { r1 = ret.Error(1) @@ -267,38 +267,38 @@ type JetStreamContext_ChanQueueSubscribe_Call struct { // ChanQueueSubscribe is a helper method to define mock.On call // - subj string // - queue string -// - ch chan *nats.Msg -// - opts ...nats.SubOpt +// - ch chan *natsgo.Msg +// - opts ...natsgo.SubOpt func (_e *JetStreamContext_Expecter) ChanQueueSubscribe(subj interface{}, queue interface{}, ch interface{}, opts ...interface{}) *JetStreamContext_ChanQueueSubscribe_Call { return &JetStreamContext_ChanQueueSubscribe_Call{Call: _e.mock.On("ChanQueueSubscribe", append([]interface{}{subj, queue, ch}, opts...)...)} } -func (_c *JetStreamContext_ChanQueueSubscribe_Call) Run(run func(subj string, queue string, ch chan *nats.Msg, opts ...nats.SubOpt)) *JetStreamContext_ChanQueueSubscribe_Call { +func (_c *JetStreamContext_ChanQueueSubscribe_Call) Run(run func(subj string, queue string, ch chan *natsgo.Msg, opts ...natsgo.SubOpt)) *JetStreamContext_ChanQueueSubscribe_Call { _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]nats.SubOpt, len(args)-3) + variadicArgs := make([]natsgo.SubOpt, len(args)-3) for i, a := range args[3:] { if a != nil { - variadicArgs[i] = a.(nats.SubOpt) + variadicArgs[i] = a.(natsgo.SubOpt) } } - run(args[0].(string), args[1].(string), args[2].(chan *nats.Msg), variadicArgs...) + run(args[0].(string), args[1].(string), args[2].(chan *natsgo.Msg), variadicArgs...) }) return _c } -func (_c *JetStreamContext_ChanQueueSubscribe_Call) Return(_a0 *nats.Subscription, _a1 error) *JetStreamContext_ChanQueueSubscribe_Call { +func (_c *JetStreamContext_ChanQueueSubscribe_Call) Return(_a0 *natsgo.Subscription, _a1 error) *JetStreamContext_ChanQueueSubscribe_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *JetStreamContext_ChanQueueSubscribe_Call) RunAndReturn(run func(string, string, chan *nats.Msg, ...nats.SubOpt) (*nats.Subscription, error)) *JetStreamContext_ChanQueueSubscribe_Call { +func (_c *JetStreamContext_ChanQueueSubscribe_Call) RunAndReturn(run func(string, string, chan *natsgo.Msg, ...natsgo.SubOpt) (*natsgo.Subscription, error)) *JetStreamContext_ChanQueueSubscribe_Call { _c.Call.Return(run) return _c } // ChanSubscribe provides a mock function with given fields: subj, ch, opts -func (_m *JetStreamContext) ChanSubscribe(subj string, ch chan *nats.Msg, opts ...nats.SubOpt) (*nats.Subscription, error) { +func (_m *JetStreamContext) ChanSubscribe(subj string, ch chan *natsgo.Msg, opts ...natsgo.SubOpt) (*natsgo.Subscription, error) { _va := make([]interface{}, len(opts)) for _i := range opts { _va[_i] = opts[_i] @@ -308,20 +308,20 @@ func (_m *JetStreamContext) ChanSubscribe(subj string, ch chan *nats.Msg, opts . _ca = append(_ca, _va...) ret := _m.Called(_ca...) - var r0 *nats.Subscription + var r0 *natsgo.Subscription var r1 error - if rf, ok := ret.Get(0).(func(string, chan *nats.Msg, ...nats.SubOpt) (*nats.Subscription, error)); ok { + if rf, ok := ret.Get(0).(func(string, chan *natsgo.Msg, ...natsgo.SubOpt) (*natsgo.Subscription, error)); ok { return rf(subj, ch, opts...) } - if rf, ok := ret.Get(0).(func(string, chan *nats.Msg, ...nats.SubOpt) *nats.Subscription); ok { + if rf, ok := ret.Get(0).(func(string, chan *natsgo.Msg, ...natsgo.SubOpt) *natsgo.Subscription); ok { r0 = rf(subj, ch, opts...) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*nats.Subscription) + r0 = ret.Get(0).(*natsgo.Subscription) } } - if rf, ok := ret.Get(1).(func(string, chan *nats.Msg, ...nats.SubOpt) error); ok { + if rf, ok := ret.Get(1).(func(string, chan *natsgo.Msg, ...natsgo.SubOpt) error); ok { r1 = rf(subj, ch, opts...) } else { r1 = ret.Error(1) @@ -337,38 +337,38 @@ type JetStreamContext_ChanSubscribe_Call struct { // ChanSubscribe is a helper method to define mock.On call // - subj string -// - ch chan *nats.Msg -// - opts ...nats.SubOpt +// - ch chan *natsgo.Msg +// - opts ...natsgo.SubOpt func (_e *JetStreamContext_Expecter) ChanSubscribe(subj interface{}, ch interface{}, opts ...interface{}) *JetStreamContext_ChanSubscribe_Call { return &JetStreamContext_ChanSubscribe_Call{Call: _e.mock.On("ChanSubscribe", append([]interface{}{subj, ch}, opts...)...)} } -func (_c *JetStreamContext_ChanSubscribe_Call) Run(run func(subj string, ch chan *nats.Msg, opts ...nats.SubOpt)) *JetStreamContext_ChanSubscribe_Call { +func (_c *JetStreamContext_ChanSubscribe_Call) Run(run func(subj string, ch chan *natsgo.Msg, opts ...natsgo.SubOpt)) *JetStreamContext_ChanSubscribe_Call { _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]nats.SubOpt, len(args)-2) + variadicArgs := make([]natsgo.SubOpt, len(args)-2) for i, a := range args[2:] { if a != nil { - variadicArgs[i] = a.(nats.SubOpt) + variadicArgs[i] = a.(natsgo.SubOpt) } } - run(args[0].(string), args[1].(chan *nats.Msg), variadicArgs...) + run(args[0].(string), args[1].(chan *natsgo.Msg), variadicArgs...) }) return _c } -func (_c *JetStreamContext_ChanSubscribe_Call) Return(_a0 *nats.Subscription, _a1 error) *JetStreamContext_ChanSubscribe_Call { +func (_c *JetStreamContext_ChanSubscribe_Call) Return(_a0 *natsgo.Subscription, _a1 error) *JetStreamContext_ChanSubscribe_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *JetStreamContext_ChanSubscribe_Call) RunAndReturn(run func(string, chan *nats.Msg, ...nats.SubOpt) (*nats.Subscription, error)) *JetStreamContext_ChanSubscribe_Call { +func (_c *JetStreamContext_ChanSubscribe_Call) RunAndReturn(run func(string, chan *natsgo.Msg, ...natsgo.SubOpt) (*natsgo.Subscription, error)) *JetStreamContext_ChanSubscribe_Call { _c.Call.Return(run) return _c } // ConsumerInfo provides a mock function with given fields: stream, name, opts -func (_m *JetStreamContext) ConsumerInfo(stream string, name string, opts ...nats.JSOpt) (*nats.ConsumerInfo, error) { +func (_m *JetStreamContext) ConsumerInfo(stream string, name string, opts ...natsgo.JSOpt) (*natsgo.ConsumerInfo, error) { _va := make([]interface{}, len(opts)) for _i := range opts { _va[_i] = opts[_i] @@ -378,20 +378,20 @@ func (_m *JetStreamContext) ConsumerInfo(stream string, name string, opts ...nat _ca = append(_ca, _va...) ret := _m.Called(_ca...) - var r0 *nats.ConsumerInfo + var r0 *natsgo.ConsumerInfo var r1 error - if rf, ok := ret.Get(0).(func(string, string, ...nats.JSOpt) (*nats.ConsumerInfo, error)); ok { + if rf, ok := ret.Get(0).(func(string, string, ...natsgo.JSOpt) (*natsgo.ConsumerInfo, error)); ok { return rf(stream, name, opts...) } - if rf, ok := ret.Get(0).(func(string, string, ...nats.JSOpt) *nats.ConsumerInfo); ok { + if rf, ok := ret.Get(0).(func(string, string, ...natsgo.JSOpt) *natsgo.ConsumerInfo); ok { r0 = rf(stream, name, opts...) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*nats.ConsumerInfo) + r0 = ret.Get(0).(*natsgo.ConsumerInfo) } } - if rf, ok := ret.Get(1).(func(string, string, ...nats.JSOpt) error); ok { + if rf, ok := ret.Get(1).(func(string, string, ...natsgo.JSOpt) error); ok { r1 = rf(stream, name, opts...) } else { r1 = ret.Error(1) @@ -408,18 +408,18 @@ type JetStreamContext_ConsumerInfo_Call struct { // ConsumerInfo is a helper method to define mock.On call // - stream string // - name string -// - opts ...nats.JSOpt +// - opts ...natsgo.JSOpt func (_e *JetStreamContext_Expecter) ConsumerInfo(stream interface{}, name interface{}, opts ...interface{}) *JetStreamContext_ConsumerInfo_Call { return &JetStreamContext_ConsumerInfo_Call{Call: _e.mock.On("ConsumerInfo", append([]interface{}{stream, name}, opts...)...)} } -func (_c *JetStreamContext_ConsumerInfo_Call) Run(run func(stream string, name string, opts ...nats.JSOpt)) *JetStreamContext_ConsumerInfo_Call { +func (_c *JetStreamContext_ConsumerInfo_Call) Run(run func(stream string, name string, opts ...natsgo.JSOpt)) *JetStreamContext_ConsumerInfo_Call { _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]nats.JSOpt, len(args)-2) + variadicArgs := make([]natsgo.JSOpt, len(args)-2) for i, a := range args[2:] { if a != nil { - variadicArgs[i] = a.(nats.JSOpt) + variadicArgs[i] = a.(natsgo.JSOpt) } } run(args[0].(string), args[1].(string), variadicArgs...) @@ -427,18 +427,18 @@ func (_c *JetStreamContext_ConsumerInfo_Call) Run(run func(stream string, name s return _c } -func (_c *JetStreamContext_ConsumerInfo_Call) Return(_a0 *nats.ConsumerInfo, _a1 error) *JetStreamContext_ConsumerInfo_Call { +func (_c *JetStreamContext_ConsumerInfo_Call) Return(_a0 *natsgo.ConsumerInfo, _a1 error) *JetStreamContext_ConsumerInfo_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *JetStreamContext_ConsumerInfo_Call) RunAndReturn(run func(string, string, ...nats.JSOpt) (*nats.ConsumerInfo, error)) *JetStreamContext_ConsumerInfo_Call { +func (_c *JetStreamContext_ConsumerInfo_Call) RunAndReturn(run func(string, string, ...natsgo.JSOpt) (*natsgo.ConsumerInfo, error)) *JetStreamContext_ConsumerInfo_Call { _c.Call.Return(run) return _c } // ConsumerNames provides a mock function with given fields: stream, opts -func (_m *JetStreamContext) ConsumerNames(stream string, opts ...nats.JSOpt) <-chan string { +func (_m *JetStreamContext) ConsumerNames(stream string, opts ...natsgo.JSOpt) <-chan string { _va := make([]interface{}, len(opts)) for _i := range opts { _va[_i] = opts[_i] @@ -449,7 +449,7 @@ func (_m *JetStreamContext) ConsumerNames(stream string, opts ...nats.JSOpt) <-c ret := _m.Called(_ca...) var r0 <-chan string - if rf, ok := ret.Get(0).(func(string, ...nats.JSOpt) <-chan string); ok { + if rf, ok := ret.Get(0).(func(string, ...natsgo.JSOpt) <-chan string); ok { r0 = rf(stream, opts...) } else { if ret.Get(0) != nil { @@ -467,18 +467,18 @@ type JetStreamContext_ConsumerNames_Call struct { // ConsumerNames is a helper method to define mock.On call // - stream string -// - opts ...nats.JSOpt +// - opts ...natsgo.JSOpt func (_e *JetStreamContext_Expecter) ConsumerNames(stream interface{}, opts ...interface{}) *JetStreamContext_ConsumerNames_Call { return &JetStreamContext_ConsumerNames_Call{Call: _e.mock.On("ConsumerNames", append([]interface{}{stream}, opts...)...)} } -func (_c *JetStreamContext_ConsumerNames_Call) Run(run func(stream string, opts ...nats.JSOpt)) *JetStreamContext_ConsumerNames_Call { +func (_c *JetStreamContext_ConsumerNames_Call) Run(run func(stream string, opts ...natsgo.JSOpt)) *JetStreamContext_ConsumerNames_Call { _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]nats.JSOpt, len(args)-1) + variadicArgs := make([]natsgo.JSOpt, len(args)-1) for i, a := range args[1:] { if a != nil { - variadicArgs[i] = a.(nats.JSOpt) + variadicArgs[i] = a.(natsgo.JSOpt) } } run(args[0].(string), variadicArgs...) @@ -491,13 +491,13 @@ func (_c *JetStreamContext_ConsumerNames_Call) Return(_a0 <-chan string) *JetStr return _c } -func (_c *JetStreamContext_ConsumerNames_Call) RunAndReturn(run func(string, ...nats.JSOpt) <-chan string) *JetStreamContext_ConsumerNames_Call { +func (_c *JetStreamContext_ConsumerNames_Call) RunAndReturn(run func(string, ...natsgo.JSOpt) <-chan string) *JetStreamContext_ConsumerNames_Call { _c.Call.Return(run) return _c } // Consumers provides a mock function with given fields: stream, opts -func (_m *JetStreamContext) Consumers(stream string, opts ...nats.JSOpt) <-chan *nats.ConsumerInfo { +func (_m *JetStreamContext) Consumers(stream string, opts ...natsgo.JSOpt) <-chan *natsgo.ConsumerInfo { _va := make([]interface{}, len(opts)) for _i := range opts { _va[_i] = opts[_i] @@ -507,12 +507,12 @@ func (_m *JetStreamContext) Consumers(stream string, opts ...nats.JSOpt) <-chan _ca = append(_ca, _va...) ret := _m.Called(_ca...) - var r0 <-chan *nats.ConsumerInfo - if rf, ok := ret.Get(0).(func(string, ...nats.JSOpt) <-chan *nats.ConsumerInfo); ok { + var r0 <-chan *natsgo.ConsumerInfo + if rf, ok := ret.Get(0).(func(string, ...natsgo.JSOpt) <-chan *natsgo.ConsumerInfo); ok { r0 = rf(stream, opts...) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(<-chan *nats.ConsumerInfo) + r0 = ret.Get(0).(<-chan *natsgo.ConsumerInfo) } } @@ -526,18 +526,18 @@ type JetStreamContext_Consumers_Call struct { // Consumers is a helper method to define mock.On call // - stream string -// - opts ...nats.JSOpt +// - opts ...natsgo.JSOpt func (_e *JetStreamContext_Expecter) Consumers(stream interface{}, opts ...interface{}) *JetStreamContext_Consumers_Call { return &JetStreamContext_Consumers_Call{Call: _e.mock.On("Consumers", append([]interface{}{stream}, opts...)...)} } -func (_c *JetStreamContext_Consumers_Call) Run(run func(stream string, opts ...nats.JSOpt)) *JetStreamContext_Consumers_Call { +func (_c *JetStreamContext_Consumers_Call) Run(run func(stream string, opts ...natsgo.JSOpt)) *JetStreamContext_Consumers_Call { _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]nats.JSOpt, len(args)-1) + variadicArgs := make([]natsgo.JSOpt, len(args)-1) for i, a := range args[1:] { if a != nil { - variadicArgs[i] = a.(nats.JSOpt) + variadicArgs[i] = a.(natsgo.JSOpt) } } run(args[0].(string), variadicArgs...) @@ -545,18 +545,18 @@ func (_c *JetStreamContext_Consumers_Call) Run(run func(stream string, opts ...n return _c } -func (_c *JetStreamContext_Consumers_Call) Return(_a0 <-chan *nats.ConsumerInfo) *JetStreamContext_Consumers_Call { +func (_c *JetStreamContext_Consumers_Call) Return(_a0 <-chan *natsgo.ConsumerInfo) *JetStreamContext_Consumers_Call { _c.Call.Return(_a0) return _c } -func (_c *JetStreamContext_Consumers_Call) RunAndReturn(run func(string, ...nats.JSOpt) <-chan *nats.ConsumerInfo) *JetStreamContext_Consumers_Call { +func (_c *JetStreamContext_Consumers_Call) RunAndReturn(run func(string, ...natsgo.JSOpt) <-chan *natsgo.ConsumerInfo) *JetStreamContext_Consumers_Call { _c.Call.Return(run) return _c } // ConsumersInfo provides a mock function with given fields: stream, opts -func (_m *JetStreamContext) ConsumersInfo(stream string, opts ...nats.JSOpt) <-chan *nats.ConsumerInfo { +func (_m *JetStreamContext) ConsumersInfo(stream string, opts ...natsgo.JSOpt) <-chan *natsgo.ConsumerInfo { _va := make([]interface{}, len(opts)) for _i := range opts { _va[_i] = opts[_i] @@ -566,12 +566,12 @@ func (_m *JetStreamContext) ConsumersInfo(stream string, opts ...nats.JSOpt) <-c _ca = append(_ca, _va...) ret := _m.Called(_ca...) - var r0 <-chan *nats.ConsumerInfo - if rf, ok := ret.Get(0).(func(string, ...nats.JSOpt) <-chan *nats.ConsumerInfo); ok { + var r0 <-chan *natsgo.ConsumerInfo + if rf, ok := ret.Get(0).(func(string, ...natsgo.JSOpt) <-chan *natsgo.ConsumerInfo); ok { r0 = rf(stream, opts...) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(<-chan *nats.ConsumerInfo) + r0 = ret.Get(0).(<-chan *natsgo.ConsumerInfo) } } @@ -585,18 +585,18 @@ type JetStreamContext_ConsumersInfo_Call struct { // ConsumersInfo is a helper method to define mock.On call // - stream string -// - opts ...nats.JSOpt +// - opts ...natsgo.JSOpt func (_e *JetStreamContext_Expecter) ConsumersInfo(stream interface{}, opts ...interface{}) *JetStreamContext_ConsumersInfo_Call { return &JetStreamContext_ConsumersInfo_Call{Call: _e.mock.On("ConsumersInfo", append([]interface{}{stream}, opts...)...)} } -func (_c *JetStreamContext_ConsumersInfo_Call) Run(run func(stream string, opts ...nats.JSOpt)) *JetStreamContext_ConsumersInfo_Call { +func (_c *JetStreamContext_ConsumersInfo_Call) Run(run func(stream string, opts ...natsgo.JSOpt)) *JetStreamContext_ConsumersInfo_Call { _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]nats.JSOpt, len(args)-1) + variadicArgs := make([]natsgo.JSOpt, len(args)-1) for i, a := range args[1:] { if a != nil { - variadicArgs[i] = a.(nats.JSOpt) + variadicArgs[i] = a.(natsgo.JSOpt) } } run(args[0].(string), variadicArgs...) @@ -604,34 +604,34 @@ func (_c *JetStreamContext_ConsumersInfo_Call) Run(run func(stream string, opts return _c } -func (_c *JetStreamContext_ConsumersInfo_Call) Return(_a0 <-chan *nats.ConsumerInfo) *JetStreamContext_ConsumersInfo_Call { +func (_c *JetStreamContext_ConsumersInfo_Call) Return(_a0 <-chan *natsgo.ConsumerInfo) *JetStreamContext_ConsumersInfo_Call { _c.Call.Return(_a0) return _c } -func (_c *JetStreamContext_ConsumersInfo_Call) RunAndReturn(run func(string, ...nats.JSOpt) <-chan *nats.ConsumerInfo) *JetStreamContext_ConsumersInfo_Call { +func (_c *JetStreamContext_ConsumersInfo_Call) RunAndReturn(run func(string, ...natsgo.JSOpt) <-chan *natsgo.ConsumerInfo) *JetStreamContext_ConsumersInfo_Call { _c.Call.Return(run) return _c } // CreateKeyValue provides a mock function with given fields: cfg -func (_m *JetStreamContext) CreateKeyValue(cfg *nats.KeyValueConfig) (nats.KeyValue, error) { +func (_m *JetStreamContext) CreateKeyValue(cfg *natsgo.KeyValueConfig) (natsgo.KeyValue, error) { ret := _m.Called(cfg) - var r0 nats.KeyValue + var r0 natsgo.KeyValue var r1 error - if rf, ok := ret.Get(0).(func(*nats.KeyValueConfig) (nats.KeyValue, error)); ok { + if rf, ok := ret.Get(0).(func(*natsgo.KeyValueConfig) (natsgo.KeyValue, error)); ok { return rf(cfg) } - if rf, ok := ret.Get(0).(func(*nats.KeyValueConfig) nats.KeyValue); ok { + if rf, ok := ret.Get(0).(func(*natsgo.KeyValueConfig) natsgo.KeyValue); ok { r0 = rf(cfg) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(nats.KeyValue) + r0 = ret.Get(0).(natsgo.KeyValue) } } - if rf, ok := ret.Get(1).(func(*nats.KeyValueConfig) error); ok { + if rf, ok := ret.Get(1).(func(*natsgo.KeyValueConfig) error); ok { r1 = rf(cfg) } else { r1 = ret.Error(1) @@ -646,46 +646,46 @@ type JetStreamContext_CreateKeyValue_Call struct { } // CreateKeyValue is a helper method to define mock.On call -// - cfg *nats.KeyValueConfig +// - cfg *natsgo.KeyValueConfig func (_e *JetStreamContext_Expecter) CreateKeyValue(cfg interface{}) *JetStreamContext_CreateKeyValue_Call { return &JetStreamContext_CreateKeyValue_Call{Call: _e.mock.On("CreateKeyValue", cfg)} } -func (_c *JetStreamContext_CreateKeyValue_Call) Run(run func(cfg *nats.KeyValueConfig)) *JetStreamContext_CreateKeyValue_Call { +func (_c *JetStreamContext_CreateKeyValue_Call) Run(run func(cfg *natsgo.KeyValueConfig)) *JetStreamContext_CreateKeyValue_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(*nats.KeyValueConfig)) + run(args[0].(*natsgo.KeyValueConfig)) }) return _c } -func (_c *JetStreamContext_CreateKeyValue_Call) Return(_a0 nats.KeyValue, _a1 error) *JetStreamContext_CreateKeyValue_Call { +func (_c *JetStreamContext_CreateKeyValue_Call) Return(_a0 natsgo.KeyValue, _a1 error) *JetStreamContext_CreateKeyValue_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *JetStreamContext_CreateKeyValue_Call) RunAndReturn(run func(*nats.KeyValueConfig) (nats.KeyValue, error)) *JetStreamContext_CreateKeyValue_Call { +func (_c *JetStreamContext_CreateKeyValue_Call) RunAndReturn(run func(*natsgo.KeyValueConfig) (natsgo.KeyValue, error)) *JetStreamContext_CreateKeyValue_Call { _c.Call.Return(run) return _c } // CreateObjectStore provides a mock function with given fields: cfg -func (_m *JetStreamContext) CreateObjectStore(cfg *nats.ObjectStoreConfig) (nats.ObjectStore, error) { +func (_m *JetStreamContext) CreateObjectStore(cfg *natsgo.ObjectStoreConfig) (natsgo.ObjectStore, error) { ret := _m.Called(cfg) - var r0 nats.ObjectStore + var r0 natsgo.ObjectStore var r1 error - if rf, ok := ret.Get(0).(func(*nats.ObjectStoreConfig) (nats.ObjectStore, error)); ok { + if rf, ok := ret.Get(0).(func(*natsgo.ObjectStoreConfig) (natsgo.ObjectStore, error)); ok { return rf(cfg) } - if rf, ok := ret.Get(0).(func(*nats.ObjectStoreConfig) nats.ObjectStore); ok { + if rf, ok := ret.Get(0).(func(*natsgo.ObjectStoreConfig) natsgo.ObjectStore); ok { r0 = rf(cfg) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(nats.ObjectStore) + r0 = ret.Get(0).(natsgo.ObjectStore) } } - if rf, ok := ret.Get(1).(func(*nats.ObjectStoreConfig) error); ok { + if rf, ok := ret.Get(1).(func(*natsgo.ObjectStoreConfig) error); ok { r1 = rf(cfg) } else { r1 = ret.Error(1) @@ -700,30 +700,30 @@ type JetStreamContext_CreateObjectStore_Call struct { } // CreateObjectStore is a helper method to define mock.On call -// - cfg *nats.ObjectStoreConfig +// - cfg *natsgo.ObjectStoreConfig func (_e *JetStreamContext_Expecter) CreateObjectStore(cfg interface{}) *JetStreamContext_CreateObjectStore_Call { return &JetStreamContext_CreateObjectStore_Call{Call: _e.mock.On("CreateObjectStore", cfg)} } -func (_c *JetStreamContext_CreateObjectStore_Call) Run(run func(cfg *nats.ObjectStoreConfig)) *JetStreamContext_CreateObjectStore_Call { +func (_c *JetStreamContext_CreateObjectStore_Call) Run(run func(cfg *natsgo.ObjectStoreConfig)) *JetStreamContext_CreateObjectStore_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(*nats.ObjectStoreConfig)) + run(args[0].(*natsgo.ObjectStoreConfig)) }) return _c } -func (_c *JetStreamContext_CreateObjectStore_Call) Return(_a0 nats.ObjectStore, _a1 error) *JetStreamContext_CreateObjectStore_Call { +func (_c *JetStreamContext_CreateObjectStore_Call) Return(_a0 natsgo.ObjectStore, _a1 error) *JetStreamContext_CreateObjectStore_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *JetStreamContext_CreateObjectStore_Call) RunAndReturn(run func(*nats.ObjectStoreConfig) (nats.ObjectStore, error)) *JetStreamContext_CreateObjectStore_Call { +func (_c *JetStreamContext_CreateObjectStore_Call) RunAndReturn(run func(*natsgo.ObjectStoreConfig) (natsgo.ObjectStore, error)) *JetStreamContext_CreateObjectStore_Call { _c.Call.Return(run) return _c } // DeleteConsumer provides a mock function with given fields: stream, consumer, opts -func (_m *JetStreamContext) DeleteConsumer(stream string, consumer string, opts ...nats.JSOpt) error { +func (_m *JetStreamContext) DeleteConsumer(stream string, consumer string, opts ...natsgo.JSOpt) error { _va := make([]interface{}, len(opts)) for _i := range opts { _va[_i] = opts[_i] @@ -734,7 +734,7 @@ func (_m *JetStreamContext) DeleteConsumer(stream string, consumer string, opts ret := _m.Called(_ca...) var r0 error - if rf, ok := ret.Get(0).(func(string, string, ...nats.JSOpt) error); ok { + if rf, ok := ret.Get(0).(func(string, string, ...natsgo.JSOpt) error); ok { r0 = rf(stream, consumer, opts...) } else { r0 = ret.Error(0) @@ -751,18 +751,18 @@ type JetStreamContext_DeleteConsumer_Call struct { // DeleteConsumer is a helper method to define mock.On call // - stream string // - consumer string -// - opts ...nats.JSOpt +// - opts ...natsgo.JSOpt func (_e *JetStreamContext_Expecter) DeleteConsumer(stream interface{}, consumer interface{}, opts ...interface{}) *JetStreamContext_DeleteConsumer_Call { return &JetStreamContext_DeleteConsumer_Call{Call: _e.mock.On("DeleteConsumer", append([]interface{}{stream, consumer}, opts...)...)} } -func (_c *JetStreamContext_DeleteConsumer_Call) Run(run func(stream string, consumer string, opts ...nats.JSOpt)) *JetStreamContext_DeleteConsumer_Call { +func (_c *JetStreamContext_DeleteConsumer_Call) Run(run func(stream string, consumer string, opts ...natsgo.JSOpt)) *JetStreamContext_DeleteConsumer_Call { _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]nats.JSOpt, len(args)-2) + variadicArgs := make([]natsgo.JSOpt, len(args)-2) for i, a := range args[2:] { if a != nil { - variadicArgs[i] = a.(nats.JSOpt) + variadicArgs[i] = a.(natsgo.JSOpt) } } run(args[0].(string), args[1].(string), variadicArgs...) @@ -775,7 +775,7 @@ func (_c *JetStreamContext_DeleteConsumer_Call) Return(_a0 error) *JetStreamCont return _c } -func (_c *JetStreamContext_DeleteConsumer_Call) RunAndReturn(run func(string, string, ...nats.JSOpt) error) *JetStreamContext_DeleteConsumer_Call { +func (_c *JetStreamContext_DeleteConsumer_Call) RunAndReturn(run func(string, string, ...natsgo.JSOpt) error) *JetStreamContext_DeleteConsumer_Call { _c.Call.Return(run) return _c } @@ -823,7 +823,7 @@ func (_c *JetStreamContext_DeleteKeyValue_Call) RunAndReturn(run func(string) er } // DeleteMsg provides a mock function with given fields: name, seq, opts -func (_m *JetStreamContext) DeleteMsg(name string, seq uint64, opts ...nats.JSOpt) error { +func (_m *JetStreamContext) DeleteMsg(name string, seq uint64, opts ...natsgo.JSOpt) error { _va := make([]interface{}, len(opts)) for _i := range opts { _va[_i] = opts[_i] @@ -834,7 +834,7 @@ func (_m *JetStreamContext) DeleteMsg(name string, seq uint64, opts ...nats.JSOp ret := _m.Called(_ca...) var r0 error - if rf, ok := ret.Get(0).(func(string, uint64, ...nats.JSOpt) error); ok { + if rf, ok := ret.Get(0).(func(string, uint64, ...natsgo.JSOpt) error); ok { r0 = rf(name, seq, opts...) } else { r0 = ret.Error(0) @@ -851,18 +851,18 @@ type JetStreamContext_DeleteMsg_Call struct { // DeleteMsg is a helper method to define mock.On call // - name string // - seq uint64 -// - opts ...nats.JSOpt +// - opts ...natsgo.JSOpt func (_e *JetStreamContext_Expecter) DeleteMsg(name interface{}, seq interface{}, opts ...interface{}) *JetStreamContext_DeleteMsg_Call { return &JetStreamContext_DeleteMsg_Call{Call: _e.mock.On("DeleteMsg", append([]interface{}{name, seq}, opts...)...)} } -func (_c *JetStreamContext_DeleteMsg_Call) Run(run func(name string, seq uint64, opts ...nats.JSOpt)) *JetStreamContext_DeleteMsg_Call { +func (_c *JetStreamContext_DeleteMsg_Call) Run(run func(name string, seq uint64, opts ...natsgo.JSOpt)) *JetStreamContext_DeleteMsg_Call { _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]nats.JSOpt, len(args)-2) + variadicArgs := make([]natsgo.JSOpt, len(args)-2) for i, a := range args[2:] { if a != nil { - variadicArgs[i] = a.(nats.JSOpt) + variadicArgs[i] = a.(natsgo.JSOpt) } } run(args[0].(string), args[1].(uint64), variadicArgs...) @@ -875,7 +875,7 @@ func (_c *JetStreamContext_DeleteMsg_Call) Return(_a0 error) *JetStreamContext_D return _c } -func (_c *JetStreamContext_DeleteMsg_Call) RunAndReturn(run func(string, uint64, ...nats.JSOpt) error) *JetStreamContext_DeleteMsg_Call { +func (_c *JetStreamContext_DeleteMsg_Call) RunAndReturn(run func(string, uint64, ...natsgo.JSOpt) error) *JetStreamContext_DeleteMsg_Call { _c.Call.Return(run) return _c } @@ -923,7 +923,7 @@ func (_c *JetStreamContext_DeleteObjectStore_Call) RunAndReturn(run func(string) } // DeleteStream provides a mock function with given fields: name, opts -func (_m *JetStreamContext) DeleteStream(name string, opts ...nats.JSOpt) error { +func (_m *JetStreamContext) DeleteStream(name string, opts ...natsgo.JSOpt) error { _va := make([]interface{}, len(opts)) for _i := range opts { _va[_i] = opts[_i] @@ -934,7 +934,7 @@ func (_m *JetStreamContext) DeleteStream(name string, opts ...nats.JSOpt) error ret := _m.Called(_ca...) var r0 error - if rf, ok := ret.Get(0).(func(string, ...nats.JSOpt) error); ok { + if rf, ok := ret.Get(0).(func(string, ...natsgo.JSOpt) error); ok { r0 = rf(name, opts...) } else { r0 = ret.Error(0) @@ -950,18 +950,18 @@ type JetStreamContext_DeleteStream_Call struct { // DeleteStream is a helper method to define mock.On call // - name string -// - opts ...nats.JSOpt +// - opts ...natsgo.JSOpt func (_e *JetStreamContext_Expecter) DeleteStream(name interface{}, opts ...interface{}) *JetStreamContext_DeleteStream_Call { return &JetStreamContext_DeleteStream_Call{Call: _e.mock.On("DeleteStream", append([]interface{}{name}, opts...)...)} } -func (_c *JetStreamContext_DeleteStream_Call) Run(run func(name string, opts ...nats.JSOpt)) *JetStreamContext_DeleteStream_Call { +func (_c *JetStreamContext_DeleteStream_Call) Run(run func(name string, opts ...natsgo.JSOpt)) *JetStreamContext_DeleteStream_Call { _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]nats.JSOpt, len(args)-1) + variadicArgs := make([]natsgo.JSOpt, len(args)-1) for i, a := range args[1:] { if a != nil { - variadicArgs[i] = a.(nats.JSOpt) + variadicArgs[i] = a.(natsgo.JSOpt) } } run(args[0].(string), variadicArgs...) @@ -974,13 +974,13 @@ func (_c *JetStreamContext_DeleteStream_Call) Return(_a0 error) *JetStreamContex return _c } -func (_c *JetStreamContext_DeleteStream_Call) RunAndReturn(run func(string, ...nats.JSOpt) error) *JetStreamContext_DeleteStream_Call { +func (_c *JetStreamContext_DeleteStream_Call) RunAndReturn(run func(string, ...natsgo.JSOpt) error) *JetStreamContext_DeleteStream_Call { _c.Call.Return(run) return _c } // GetLastMsg provides a mock function with given fields: name, subject, opts -func (_m *JetStreamContext) GetLastMsg(name string, subject string, opts ...nats.JSOpt) (*nats.RawStreamMsg, error) { +func (_m *JetStreamContext) GetLastMsg(name string, subject string, opts ...natsgo.JSOpt) (*natsgo.RawStreamMsg, error) { _va := make([]interface{}, len(opts)) for _i := range opts { _va[_i] = opts[_i] @@ -990,20 +990,20 @@ func (_m *JetStreamContext) GetLastMsg(name string, subject string, opts ...nats _ca = append(_ca, _va...) ret := _m.Called(_ca...) - var r0 *nats.RawStreamMsg + var r0 *natsgo.RawStreamMsg var r1 error - if rf, ok := ret.Get(0).(func(string, string, ...nats.JSOpt) (*nats.RawStreamMsg, error)); ok { + if rf, ok := ret.Get(0).(func(string, string, ...natsgo.JSOpt) (*natsgo.RawStreamMsg, error)); ok { return rf(name, subject, opts...) } - if rf, ok := ret.Get(0).(func(string, string, ...nats.JSOpt) *nats.RawStreamMsg); ok { + if rf, ok := ret.Get(0).(func(string, string, ...natsgo.JSOpt) *natsgo.RawStreamMsg); ok { r0 = rf(name, subject, opts...) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*nats.RawStreamMsg) + r0 = ret.Get(0).(*natsgo.RawStreamMsg) } } - if rf, ok := ret.Get(1).(func(string, string, ...nats.JSOpt) error); ok { + if rf, ok := ret.Get(1).(func(string, string, ...natsgo.JSOpt) error); ok { r1 = rf(name, subject, opts...) } else { r1 = ret.Error(1) @@ -1020,18 +1020,18 @@ type JetStreamContext_GetLastMsg_Call struct { // GetLastMsg is a helper method to define mock.On call // - name string // - subject string -// - opts ...nats.JSOpt +// - opts ...natsgo.JSOpt func (_e *JetStreamContext_Expecter) GetLastMsg(name interface{}, subject interface{}, opts ...interface{}) *JetStreamContext_GetLastMsg_Call { return &JetStreamContext_GetLastMsg_Call{Call: _e.mock.On("GetLastMsg", append([]interface{}{name, subject}, opts...)...)} } -func (_c *JetStreamContext_GetLastMsg_Call) Run(run func(name string, subject string, opts ...nats.JSOpt)) *JetStreamContext_GetLastMsg_Call { +func (_c *JetStreamContext_GetLastMsg_Call) Run(run func(name string, subject string, opts ...natsgo.JSOpt)) *JetStreamContext_GetLastMsg_Call { _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]nats.JSOpt, len(args)-2) + variadicArgs := make([]natsgo.JSOpt, len(args)-2) for i, a := range args[2:] { if a != nil { - variadicArgs[i] = a.(nats.JSOpt) + variadicArgs[i] = a.(natsgo.JSOpt) } } run(args[0].(string), args[1].(string), variadicArgs...) @@ -1039,18 +1039,18 @@ func (_c *JetStreamContext_GetLastMsg_Call) Run(run func(name string, subject st return _c } -func (_c *JetStreamContext_GetLastMsg_Call) Return(_a0 *nats.RawStreamMsg, _a1 error) *JetStreamContext_GetLastMsg_Call { +func (_c *JetStreamContext_GetLastMsg_Call) Return(_a0 *natsgo.RawStreamMsg, _a1 error) *JetStreamContext_GetLastMsg_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *JetStreamContext_GetLastMsg_Call) RunAndReturn(run func(string, string, ...nats.JSOpt) (*nats.RawStreamMsg, error)) *JetStreamContext_GetLastMsg_Call { +func (_c *JetStreamContext_GetLastMsg_Call) RunAndReturn(run func(string, string, ...natsgo.JSOpt) (*natsgo.RawStreamMsg, error)) *JetStreamContext_GetLastMsg_Call { _c.Call.Return(run) return _c } // GetMsg provides a mock function with given fields: name, seq, opts -func (_m *JetStreamContext) GetMsg(name string, seq uint64, opts ...nats.JSOpt) (*nats.RawStreamMsg, error) { +func (_m *JetStreamContext) GetMsg(name string, seq uint64, opts ...natsgo.JSOpt) (*natsgo.RawStreamMsg, error) { _va := make([]interface{}, len(opts)) for _i := range opts { _va[_i] = opts[_i] @@ -1060,20 +1060,20 @@ func (_m *JetStreamContext) GetMsg(name string, seq uint64, opts ...nats.JSOpt) _ca = append(_ca, _va...) ret := _m.Called(_ca...) - var r0 *nats.RawStreamMsg + var r0 *natsgo.RawStreamMsg var r1 error - if rf, ok := ret.Get(0).(func(string, uint64, ...nats.JSOpt) (*nats.RawStreamMsg, error)); ok { + if rf, ok := ret.Get(0).(func(string, uint64, ...natsgo.JSOpt) (*natsgo.RawStreamMsg, error)); ok { return rf(name, seq, opts...) } - if rf, ok := ret.Get(0).(func(string, uint64, ...nats.JSOpt) *nats.RawStreamMsg); ok { + if rf, ok := ret.Get(0).(func(string, uint64, ...natsgo.JSOpt) *natsgo.RawStreamMsg); ok { r0 = rf(name, seq, opts...) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*nats.RawStreamMsg) + r0 = ret.Get(0).(*natsgo.RawStreamMsg) } } - if rf, ok := ret.Get(1).(func(string, uint64, ...nats.JSOpt) error); ok { + if rf, ok := ret.Get(1).(func(string, uint64, ...natsgo.JSOpt) error); ok { r1 = rf(name, seq, opts...) } else { r1 = ret.Error(1) @@ -1090,18 +1090,18 @@ type JetStreamContext_GetMsg_Call struct { // GetMsg is a helper method to define mock.On call // - name string // - seq uint64 -// - opts ...nats.JSOpt +// - opts ...natsgo.JSOpt func (_e *JetStreamContext_Expecter) GetMsg(name interface{}, seq interface{}, opts ...interface{}) *JetStreamContext_GetMsg_Call { return &JetStreamContext_GetMsg_Call{Call: _e.mock.On("GetMsg", append([]interface{}{name, seq}, opts...)...)} } -func (_c *JetStreamContext_GetMsg_Call) Run(run func(name string, seq uint64, opts ...nats.JSOpt)) *JetStreamContext_GetMsg_Call { +func (_c *JetStreamContext_GetMsg_Call) Run(run func(name string, seq uint64, opts ...natsgo.JSOpt)) *JetStreamContext_GetMsg_Call { _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]nats.JSOpt, len(args)-2) + variadicArgs := make([]natsgo.JSOpt, len(args)-2) for i, a := range args[2:] { if a != nil { - variadicArgs[i] = a.(nats.JSOpt) + variadicArgs[i] = a.(natsgo.JSOpt) } } run(args[0].(string), args[1].(uint64), variadicArgs...) @@ -1109,30 +1109,30 @@ func (_c *JetStreamContext_GetMsg_Call) Run(run func(name string, seq uint64, op return _c } -func (_c *JetStreamContext_GetMsg_Call) Return(_a0 *nats.RawStreamMsg, _a1 error) *JetStreamContext_GetMsg_Call { +func (_c *JetStreamContext_GetMsg_Call) Return(_a0 *natsgo.RawStreamMsg, _a1 error) *JetStreamContext_GetMsg_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *JetStreamContext_GetMsg_Call) RunAndReturn(run func(string, uint64, ...nats.JSOpt) (*nats.RawStreamMsg, error)) *JetStreamContext_GetMsg_Call { +func (_c *JetStreamContext_GetMsg_Call) RunAndReturn(run func(string, uint64, ...natsgo.JSOpt) (*natsgo.RawStreamMsg, error)) *JetStreamContext_GetMsg_Call { _c.Call.Return(run) return _c } // KeyValue provides a mock function with given fields: bucket -func (_m *JetStreamContext) KeyValue(bucket string) (nats.KeyValue, error) { +func (_m *JetStreamContext) KeyValue(bucket string) (natsgo.KeyValue, error) { ret := _m.Called(bucket) - var r0 nats.KeyValue + var r0 natsgo.KeyValue var r1 error - if rf, ok := ret.Get(0).(func(string) (nats.KeyValue, error)); ok { + if rf, ok := ret.Get(0).(func(string) (natsgo.KeyValue, error)); ok { return rf(bucket) } - if rf, ok := ret.Get(0).(func(string) nats.KeyValue); ok { + if rf, ok := ret.Get(0).(func(string) natsgo.KeyValue); ok { r0 = rf(bucket) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(nats.KeyValue) + r0 = ret.Get(0).(natsgo.KeyValue) } } @@ -1163,12 +1163,12 @@ func (_c *JetStreamContext_KeyValue_Call) Run(run func(bucket string)) *JetStrea return _c } -func (_c *JetStreamContext_KeyValue_Call) Return(_a0 nats.KeyValue, _a1 error) *JetStreamContext_KeyValue_Call { +func (_c *JetStreamContext_KeyValue_Call) Return(_a0 natsgo.KeyValue, _a1 error) *JetStreamContext_KeyValue_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *JetStreamContext_KeyValue_Call) RunAndReturn(run func(string) (nats.KeyValue, error)) *JetStreamContext_KeyValue_Call { +func (_c *JetStreamContext_KeyValue_Call) RunAndReturn(run func(string) (natsgo.KeyValue, error)) *JetStreamContext_KeyValue_Call { _c.Call.Return(run) return _c } @@ -1217,15 +1217,15 @@ func (_c *JetStreamContext_KeyValueStoreNames_Call) RunAndReturn(run func() <-ch } // KeyValueStores provides a mock function with given fields: -func (_m *JetStreamContext) KeyValueStores() <-chan nats.KeyValueStatus { +func (_m *JetStreamContext) KeyValueStores() <-chan natsgo.KeyValueStatus { ret := _m.Called() - var r0 <-chan nats.KeyValueStatus - if rf, ok := ret.Get(0).(func() <-chan nats.KeyValueStatus); ok { + var r0 <-chan natsgo.KeyValueStatus + if rf, ok := ret.Get(0).(func() <-chan natsgo.KeyValueStatus); ok { r0 = rf() } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(<-chan nats.KeyValueStatus) + r0 = ret.Get(0).(<-chan natsgo.KeyValueStatus) } } @@ -1249,30 +1249,30 @@ func (_c *JetStreamContext_KeyValueStores_Call) Run(run func()) *JetStreamContex return _c } -func (_c *JetStreamContext_KeyValueStores_Call) Return(_a0 <-chan nats.KeyValueStatus) *JetStreamContext_KeyValueStores_Call { +func (_c *JetStreamContext_KeyValueStores_Call) Return(_a0 <-chan natsgo.KeyValueStatus) *JetStreamContext_KeyValueStores_Call { _c.Call.Return(_a0) return _c } -func (_c *JetStreamContext_KeyValueStores_Call) RunAndReturn(run func() <-chan nats.KeyValueStatus) *JetStreamContext_KeyValueStores_Call { +func (_c *JetStreamContext_KeyValueStores_Call) RunAndReturn(run func() <-chan natsgo.KeyValueStatus) *JetStreamContext_KeyValueStores_Call { _c.Call.Return(run) return _c } // ObjectStore provides a mock function with given fields: bucket -func (_m *JetStreamContext) ObjectStore(bucket string) (nats.ObjectStore, error) { +func (_m *JetStreamContext) ObjectStore(bucket string) (natsgo.ObjectStore, error) { ret := _m.Called(bucket) - var r0 nats.ObjectStore + var r0 natsgo.ObjectStore var r1 error - if rf, ok := ret.Get(0).(func(string) (nats.ObjectStore, error)); ok { + if rf, ok := ret.Get(0).(func(string) (natsgo.ObjectStore, error)); ok { return rf(bucket) } - if rf, ok := ret.Get(0).(func(string) nats.ObjectStore); ok { + if rf, ok := ret.Get(0).(func(string) natsgo.ObjectStore); ok { r0 = rf(bucket) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(nats.ObjectStore) + r0 = ret.Get(0).(natsgo.ObjectStore) } } @@ -1303,18 +1303,18 @@ func (_c *JetStreamContext_ObjectStore_Call) Run(run func(bucket string)) *JetSt return _c } -func (_c *JetStreamContext_ObjectStore_Call) Return(_a0 nats.ObjectStore, _a1 error) *JetStreamContext_ObjectStore_Call { +func (_c *JetStreamContext_ObjectStore_Call) Return(_a0 natsgo.ObjectStore, _a1 error) *JetStreamContext_ObjectStore_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *JetStreamContext_ObjectStore_Call) RunAndReturn(run func(string) (nats.ObjectStore, error)) *JetStreamContext_ObjectStore_Call { +func (_c *JetStreamContext_ObjectStore_Call) RunAndReturn(run func(string) (natsgo.ObjectStore, error)) *JetStreamContext_ObjectStore_Call { _c.Call.Return(run) return _c } // ObjectStoreNames provides a mock function with given fields: opts -func (_m *JetStreamContext) ObjectStoreNames(opts ...nats.ObjectOpt) <-chan string { +func (_m *JetStreamContext) ObjectStoreNames(opts ...natsgo.ObjectOpt) <-chan string { _va := make([]interface{}, len(opts)) for _i := range opts { _va[_i] = opts[_i] @@ -1324,7 +1324,7 @@ func (_m *JetStreamContext) ObjectStoreNames(opts ...nats.ObjectOpt) <-chan stri ret := _m.Called(_ca...) var r0 <-chan string - if rf, ok := ret.Get(0).(func(...nats.ObjectOpt) <-chan string); ok { + if rf, ok := ret.Get(0).(func(...natsgo.ObjectOpt) <-chan string); ok { r0 = rf(opts...) } else { if ret.Get(0) != nil { @@ -1341,18 +1341,18 @@ type JetStreamContext_ObjectStoreNames_Call struct { } // ObjectStoreNames is a helper method to define mock.On call -// - opts ...nats.ObjectOpt +// - opts ...natsgo.ObjectOpt func (_e *JetStreamContext_Expecter) ObjectStoreNames(opts ...interface{}) *JetStreamContext_ObjectStoreNames_Call { return &JetStreamContext_ObjectStoreNames_Call{Call: _e.mock.On("ObjectStoreNames", append([]interface{}{}, opts...)...)} } -func (_c *JetStreamContext_ObjectStoreNames_Call) Run(run func(opts ...nats.ObjectOpt)) *JetStreamContext_ObjectStoreNames_Call { +func (_c *JetStreamContext_ObjectStoreNames_Call) Run(run func(opts ...natsgo.ObjectOpt)) *JetStreamContext_ObjectStoreNames_Call { _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]nats.ObjectOpt, len(args)-0) + variadicArgs := make([]natsgo.ObjectOpt, len(args)-0) for i, a := range args[0:] { if a != nil { - variadicArgs[i] = a.(nats.ObjectOpt) + variadicArgs[i] = a.(natsgo.ObjectOpt) } } run(variadicArgs...) @@ -1365,13 +1365,13 @@ func (_c *JetStreamContext_ObjectStoreNames_Call) Return(_a0 <-chan string) *Jet return _c } -func (_c *JetStreamContext_ObjectStoreNames_Call) RunAndReturn(run func(...nats.ObjectOpt) <-chan string) *JetStreamContext_ObjectStoreNames_Call { +func (_c *JetStreamContext_ObjectStoreNames_Call) RunAndReturn(run func(...natsgo.ObjectOpt) <-chan string) *JetStreamContext_ObjectStoreNames_Call { _c.Call.Return(run) return _c } // ObjectStores provides a mock function with given fields: opts -func (_m *JetStreamContext) ObjectStores(opts ...nats.ObjectOpt) <-chan nats.ObjectStoreStatus { +func (_m *JetStreamContext) ObjectStores(opts ...natsgo.ObjectOpt) <-chan natsgo.ObjectStoreStatus { _va := make([]interface{}, len(opts)) for _i := range opts { _va[_i] = opts[_i] @@ -1380,12 +1380,12 @@ func (_m *JetStreamContext) ObjectStores(opts ...nats.ObjectOpt) <-chan nats.Obj _ca = append(_ca, _va...) ret := _m.Called(_ca...) - var r0 <-chan nats.ObjectStoreStatus - if rf, ok := ret.Get(0).(func(...nats.ObjectOpt) <-chan nats.ObjectStoreStatus); ok { + var r0 <-chan natsgo.ObjectStoreStatus + if rf, ok := ret.Get(0).(func(...natsgo.ObjectOpt) <-chan natsgo.ObjectStoreStatus); ok { r0 = rf(opts...) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(<-chan nats.ObjectStoreStatus) + r0 = ret.Get(0).(<-chan natsgo.ObjectStoreStatus) } } @@ -1398,18 +1398,18 @@ type JetStreamContext_ObjectStores_Call struct { } // ObjectStores is a helper method to define mock.On call -// - opts ...nats.ObjectOpt +// - opts ...natsgo.ObjectOpt func (_e *JetStreamContext_Expecter) ObjectStores(opts ...interface{}) *JetStreamContext_ObjectStores_Call { return &JetStreamContext_ObjectStores_Call{Call: _e.mock.On("ObjectStores", append([]interface{}{}, opts...)...)} } -func (_c *JetStreamContext_ObjectStores_Call) Run(run func(opts ...nats.ObjectOpt)) *JetStreamContext_ObjectStores_Call { +func (_c *JetStreamContext_ObjectStores_Call) Run(run func(opts ...natsgo.ObjectOpt)) *JetStreamContext_ObjectStores_Call { _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]nats.ObjectOpt, len(args)-0) + variadicArgs := make([]natsgo.ObjectOpt, len(args)-0) for i, a := range args[0:] { if a != nil { - variadicArgs[i] = a.(nats.ObjectOpt) + variadicArgs[i] = a.(natsgo.ObjectOpt) } } run(variadicArgs...) @@ -1417,18 +1417,18 @@ func (_c *JetStreamContext_ObjectStores_Call) Run(run func(opts ...nats.ObjectOp return _c } -func (_c *JetStreamContext_ObjectStores_Call) Return(_a0 <-chan nats.ObjectStoreStatus) *JetStreamContext_ObjectStores_Call { +func (_c *JetStreamContext_ObjectStores_Call) Return(_a0 <-chan natsgo.ObjectStoreStatus) *JetStreamContext_ObjectStores_Call { _c.Call.Return(_a0) return _c } -func (_c *JetStreamContext_ObjectStores_Call) RunAndReturn(run func(...nats.ObjectOpt) <-chan nats.ObjectStoreStatus) *JetStreamContext_ObjectStores_Call { +func (_c *JetStreamContext_ObjectStores_Call) RunAndReturn(run func(...natsgo.ObjectOpt) <-chan natsgo.ObjectStoreStatus) *JetStreamContext_ObjectStores_Call { _c.Call.Return(run) return _c } // Publish provides a mock function with given fields: subj, data, opts -func (_m *JetStreamContext) Publish(subj string, data []byte, opts ...nats.PubOpt) (*nats.PubAck, error) { +func (_m *JetStreamContext) Publish(subj string, data []byte, opts ...natsgo.PubOpt) (*natsgo.PubAck, error) { _va := make([]interface{}, len(opts)) for _i := range opts { _va[_i] = opts[_i] @@ -1438,20 +1438,20 @@ func (_m *JetStreamContext) Publish(subj string, data []byte, opts ...nats.PubOp _ca = append(_ca, _va...) ret := _m.Called(_ca...) - var r0 *nats.PubAck + var r0 *natsgo.PubAck var r1 error - if rf, ok := ret.Get(0).(func(string, []byte, ...nats.PubOpt) (*nats.PubAck, error)); ok { + if rf, ok := ret.Get(0).(func(string, []byte, ...natsgo.PubOpt) (*natsgo.PubAck, error)); ok { return rf(subj, data, opts...) } - if rf, ok := ret.Get(0).(func(string, []byte, ...nats.PubOpt) *nats.PubAck); ok { + if rf, ok := ret.Get(0).(func(string, []byte, ...natsgo.PubOpt) *natsgo.PubAck); ok { r0 = rf(subj, data, opts...) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*nats.PubAck) + r0 = ret.Get(0).(*natsgo.PubAck) } } - if rf, ok := ret.Get(1).(func(string, []byte, ...nats.PubOpt) error); ok { + if rf, ok := ret.Get(1).(func(string, []byte, ...natsgo.PubOpt) error); ok { r1 = rf(subj, data, opts...) } else { r1 = ret.Error(1) @@ -1468,18 +1468,18 @@ type JetStreamContext_Publish_Call struct { // Publish is a helper method to define mock.On call // - subj string // - data []byte -// - opts ...nats.PubOpt +// - opts ...natsgo.PubOpt func (_e *JetStreamContext_Expecter) Publish(subj interface{}, data interface{}, opts ...interface{}) *JetStreamContext_Publish_Call { return &JetStreamContext_Publish_Call{Call: _e.mock.On("Publish", append([]interface{}{subj, data}, opts...)...)} } -func (_c *JetStreamContext_Publish_Call) Run(run func(subj string, data []byte, opts ...nats.PubOpt)) *JetStreamContext_Publish_Call { +func (_c *JetStreamContext_Publish_Call) Run(run func(subj string, data []byte, opts ...natsgo.PubOpt)) *JetStreamContext_Publish_Call { _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]nats.PubOpt, len(args)-2) + variadicArgs := make([]natsgo.PubOpt, len(args)-2) for i, a := range args[2:] { if a != nil { - variadicArgs[i] = a.(nats.PubOpt) + variadicArgs[i] = a.(natsgo.PubOpt) } } run(args[0].(string), args[1].([]byte), variadicArgs...) @@ -1487,18 +1487,18 @@ func (_c *JetStreamContext_Publish_Call) Run(run func(subj string, data []byte, return _c } -func (_c *JetStreamContext_Publish_Call) Return(_a0 *nats.PubAck, _a1 error) *JetStreamContext_Publish_Call { +func (_c *JetStreamContext_Publish_Call) Return(_a0 *natsgo.PubAck, _a1 error) *JetStreamContext_Publish_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *JetStreamContext_Publish_Call) RunAndReturn(run func(string, []byte, ...nats.PubOpt) (*nats.PubAck, error)) *JetStreamContext_Publish_Call { +func (_c *JetStreamContext_Publish_Call) RunAndReturn(run func(string, []byte, ...natsgo.PubOpt) (*natsgo.PubAck, error)) *JetStreamContext_Publish_Call { _c.Call.Return(run) return _c } // PublishAsync provides a mock function with given fields: subj, data, opts -func (_m *JetStreamContext) PublishAsync(subj string, data []byte, opts ...nats.PubOpt) (nats.PubAckFuture, error) { +func (_m *JetStreamContext) PublishAsync(subj string, data []byte, opts ...natsgo.PubOpt) (natsgo.PubAckFuture, error) { _va := make([]interface{}, len(opts)) for _i := range opts { _va[_i] = opts[_i] @@ -1508,20 +1508,20 @@ func (_m *JetStreamContext) PublishAsync(subj string, data []byte, opts ...nats. _ca = append(_ca, _va...) ret := _m.Called(_ca...) - var r0 nats.PubAckFuture + var r0 natsgo.PubAckFuture var r1 error - if rf, ok := ret.Get(0).(func(string, []byte, ...nats.PubOpt) (nats.PubAckFuture, error)); ok { + if rf, ok := ret.Get(0).(func(string, []byte, ...natsgo.PubOpt) (natsgo.PubAckFuture, error)); ok { return rf(subj, data, opts...) } - if rf, ok := ret.Get(0).(func(string, []byte, ...nats.PubOpt) nats.PubAckFuture); ok { + if rf, ok := ret.Get(0).(func(string, []byte, ...natsgo.PubOpt) natsgo.PubAckFuture); ok { r0 = rf(subj, data, opts...) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(nats.PubAckFuture) + r0 = ret.Get(0).(natsgo.PubAckFuture) } } - if rf, ok := ret.Get(1).(func(string, []byte, ...nats.PubOpt) error); ok { + if rf, ok := ret.Get(1).(func(string, []byte, ...natsgo.PubOpt) error); ok { r1 = rf(subj, data, opts...) } else { r1 = ret.Error(1) @@ -1538,18 +1538,18 @@ type JetStreamContext_PublishAsync_Call struct { // PublishAsync is a helper method to define mock.On call // - subj string // - data []byte -// - opts ...nats.PubOpt +// - opts ...natsgo.PubOpt func (_e *JetStreamContext_Expecter) PublishAsync(subj interface{}, data interface{}, opts ...interface{}) *JetStreamContext_PublishAsync_Call { return &JetStreamContext_PublishAsync_Call{Call: _e.mock.On("PublishAsync", append([]interface{}{subj, data}, opts...)...)} } -func (_c *JetStreamContext_PublishAsync_Call) Run(run func(subj string, data []byte, opts ...nats.PubOpt)) *JetStreamContext_PublishAsync_Call { +func (_c *JetStreamContext_PublishAsync_Call) Run(run func(subj string, data []byte, opts ...natsgo.PubOpt)) *JetStreamContext_PublishAsync_Call { _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]nats.PubOpt, len(args)-2) + variadicArgs := make([]natsgo.PubOpt, len(args)-2) for i, a := range args[2:] { if a != nil { - variadicArgs[i] = a.(nats.PubOpt) + variadicArgs[i] = a.(natsgo.PubOpt) } } run(args[0].(string), args[1].([]byte), variadicArgs...) @@ -1557,12 +1557,12 @@ func (_c *JetStreamContext_PublishAsync_Call) Run(run func(subj string, data []b return _c } -func (_c *JetStreamContext_PublishAsync_Call) Return(_a0 nats.PubAckFuture, _a1 error) *JetStreamContext_PublishAsync_Call { +func (_c *JetStreamContext_PublishAsync_Call) Return(_a0 natsgo.PubAckFuture, _a1 error) *JetStreamContext_PublishAsync_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *JetStreamContext_PublishAsync_Call) RunAndReturn(run func(string, []byte, ...nats.PubOpt) (nats.PubAckFuture, error)) *JetStreamContext_PublishAsync_Call { +func (_c *JetStreamContext_PublishAsync_Call) RunAndReturn(run func(string, []byte, ...natsgo.PubOpt) (natsgo.PubAckFuture, error)) *JetStreamContext_PublishAsync_Call { _c.Call.Return(run) return _c } @@ -1652,7 +1652,7 @@ func (_c *JetStreamContext_PublishAsyncPending_Call) RunAndReturn(run func() int } // PublishMsg provides a mock function with given fields: m, opts -func (_m *JetStreamContext) PublishMsg(m *nats.Msg, opts ...nats.PubOpt) (*nats.PubAck, error) { +func (_m *JetStreamContext) PublishMsg(m *natsgo.Msg, opts ...natsgo.PubOpt) (*natsgo.PubAck, error) { _va := make([]interface{}, len(opts)) for _i := range opts { _va[_i] = opts[_i] @@ -1662,20 +1662,20 @@ func (_m *JetStreamContext) PublishMsg(m *nats.Msg, opts ...nats.PubOpt) (*nats. _ca = append(_ca, _va...) ret := _m.Called(_ca...) - var r0 *nats.PubAck + var r0 *natsgo.PubAck var r1 error - if rf, ok := ret.Get(0).(func(*nats.Msg, ...nats.PubOpt) (*nats.PubAck, error)); ok { + if rf, ok := ret.Get(0).(func(*natsgo.Msg, ...natsgo.PubOpt) (*natsgo.PubAck, error)); ok { return rf(m, opts...) } - if rf, ok := ret.Get(0).(func(*nats.Msg, ...nats.PubOpt) *nats.PubAck); ok { + if rf, ok := ret.Get(0).(func(*natsgo.Msg, ...natsgo.PubOpt) *natsgo.PubAck); ok { r0 = rf(m, opts...) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*nats.PubAck) + r0 = ret.Get(0).(*natsgo.PubAck) } } - if rf, ok := ret.Get(1).(func(*nats.Msg, ...nats.PubOpt) error); ok { + if rf, ok := ret.Get(1).(func(*natsgo.Msg, ...natsgo.PubOpt) error); ok { r1 = rf(m, opts...) } else { r1 = ret.Error(1) @@ -1690,38 +1690,38 @@ type JetStreamContext_PublishMsg_Call struct { } // PublishMsg is a helper method to define mock.On call -// - m *nats.Msg -// - opts ...nats.PubOpt +// - m *natsgo.Msg +// - opts ...natsgo.PubOpt func (_e *JetStreamContext_Expecter) PublishMsg(m interface{}, opts ...interface{}) *JetStreamContext_PublishMsg_Call { return &JetStreamContext_PublishMsg_Call{Call: _e.mock.On("PublishMsg", append([]interface{}{m}, opts...)...)} } -func (_c *JetStreamContext_PublishMsg_Call) Run(run func(m *nats.Msg, opts ...nats.PubOpt)) *JetStreamContext_PublishMsg_Call { +func (_c *JetStreamContext_PublishMsg_Call) Run(run func(m *natsgo.Msg, opts ...natsgo.PubOpt)) *JetStreamContext_PublishMsg_Call { _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]nats.PubOpt, len(args)-1) + variadicArgs := make([]natsgo.PubOpt, len(args)-1) for i, a := range args[1:] { if a != nil { - variadicArgs[i] = a.(nats.PubOpt) + variadicArgs[i] = a.(natsgo.PubOpt) } } - run(args[0].(*nats.Msg), variadicArgs...) + run(args[0].(*natsgo.Msg), variadicArgs...) }) return _c } -func (_c *JetStreamContext_PublishMsg_Call) Return(_a0 *nats.PubAck, _a1 error) *JetStreamContext_PublishMsg_Call { +func (_c *JetStreamContext_PublishMsg_Call) Return(_a0 *natsgo.PubAck, _a1 error) *JetStreamContext_PublishMsg_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *JetStreamContext_PublishMsg_Call) RunAndReturn(run func(*nats.Msg, ...nats.PubOpt) (*nats.PubAck, error)) *JetStreamContext_PublishMsg_Call { +func (_c *JetStreamContext_PublishMsg_Call) RunAndReturn(run func(*natsgo.Msg, ...natsgo.PubOpt) (*natsgo.PubAck, error)) *JetStreamContext_PublishMsg_Call { _c.Call.Return(run) return _c } // PublishMsgAsync provides a mock function with given fields: m, opts -func (_m *JetStreamContext) PublishMsgAsync(m *nats.Msg, opts ...nats.PubOpt) (nats.PubAckFuture, error) { +func (_m *JetStreamContext) PublishMsgAsync(m *natsgo.Msg, opts ...natsgo.PubOpt) (natsgo.PubAckFuture, error) { _va := make([]interface{}, len(opts)) for _i := range opts { _va[_i] = opts[_i] @@ -1731,20 +1731,20 @@ func (_m *JetStreamContext) PublishMsgAsync(m *nats.Msg, opts ...nats.PubOpt) (n _ca = append(_ca, _va...) ret := _m.Called(_ca...) - var r0 nats.PubAckFuture + var r0 natsgo.PubAckFuture var r1 error - if rf, ok := ret.Get(0).(func(*nats.Msg, ...nats.PubOpt) (nats.PubAckFuture, error)); ok { + if rf, ok := ret.Get(0).(func(*natsgo.Msg, ...natsgo.PubOpt) (natsgo.PubAckFuture, error)); ok { return rf(m, opts...) } - if rf, ok := ret.Get(0).(func(*nats.Msg, ...nats.PubOpt) nats.PubAckFuture); ok { + if rf, ok := ret.Get(0).(func(*natsgo.Msg, ...natsgo.PubOpt) natsgo.PubAckFuture); ok { r0 = rf(m, opts...) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(nats.PubAckFuture) + r0 = ret.Get(0).(natsgo.PubAckFuture) } } - if rf, ok := ret.Get(1).(func(*nats.Msg, ...nats.PubOpt) error); ok { + if rf, ok := ret.Get(1).(func(*natsgo.Msg, ...natsgo.PubOpt) error); ok { r1 = rf(m, opts...) } else { r1 = ret.Error(1) @@ -1759,38 +1759,38 @@ type JetStreamContext_PublishMsgAsync_Call struct { } // PublishMsgAsync is a helper method to define mock.On call -// - m *nats.Msg -// - opts ...nats.PubOpt +// - m *natsgo.Msg +// - opts ...natsgo.PubOpt func (_e *JetStreamContext_Expecter) PublishMsgAsync(m interface{}, opts ...interface{}) *JetStreamContext_PublishMsgAsync_Call { return &JetStreamContext_PublishMsgAsync_Call{Call: _e.mock.On("PublishMsgAsync", append([]interface{}{m}, opts...)...)} } -func (_c *JetStreamContext_PublishMsgAsync_Call) Run(run func(m *nats.Msg, opts ...nats.PubOpt)) *JetStreamContext_PublishMsgAsync_Call { +func (_c *JetStreamContext_PublishMsgAsync_Call) Run(run func(m *natsgo.Msg, opts ...natsgo.PubOpt)) *JetStreamContext_PublishMsgAsync_Call { _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]nats.PubOpt, len(args)-1) + variadicArgs := make([]natsgo.PubOpt, len(args)-1) for i, a := range args[1:] { if a != nil { - variadicArgs[i] = a.(nats.PubOpt) + variadicArgs[i] = a.(natsgo.PubOpt) } } - run(args[0].(*nats.Msg), variadicArgs...) + run(args[0].(*natsgo.Msg), variadicArgs...) }) return _c } -func (_c *JetStreamContext_PublishMsgAsync_Call) Return(_a0 nats.PubAckFuture, _a1 error) *JetStreamContext_PublishMsgAsync_Call { +func (_c *JetStreamContext_PublishMsgAsync_Call) Return(_a0 natsgo.PubAckFuture, _a1 error) *JetStreamContext_PublishMsgAsync_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *JetStreamContext_PublishMsgAsync_Call) RunAndReturn(run func(*nats.Msg, ...nats.PubOpt) (nats.PubAckFuture, error)) *JetStreamContext_PublishMsgAsync_Call { +func (_c *JetStreamContext_PublishMsgAsync_Call) RunAndReturn(run func(*natsgo.Msg, ...natsgo.PubOpt) (natsgo.PubAckFuture, error)) *JetStreamContext_PublishMsgAsync_Call { _c.Call.Return(run) return _c } // PullSubscribe provides a mock function with given fields: subj, durable, opts -func (_m *JetStreamContext) PullSubscribe(subj string, durable string, opts ...nats.SubOpt) (*nats.Subscription, error) { +func (_m *JetStreamContext) PullSubscribe(subj string, durable string, opts ...natsgo.SubOpt) (*natsgo.Subscription, error) { _va := make([]interface{}, len(opts)) for _i := range opts { _va[_i] = opts[_i] @@ -1800,20 +1800,20 @@ func (_m *JetStreamContext) PullSubscribe(subj string, durable string, opts ...n _ca = append(_ca, _va...) ret := _m.Called(_ca...) - var r0 *nats.Subscription + var r0 *natsgo.Subscription var r1 error - if rf, ok := ret.Get(0).(func(string, string, ...nats.SubOpt) (*nats.Subscription, error)); ok { + if rf, ok := ret.Get(0).(func(string, string, ...natsgo.SubOpt) (*natsgo.Subscription, error)); ok { return rf(subj, durable, opts...) } - if rf, ok := ret.Get(0).(func(string, string, ...nats.SubOpt) *nats.Subscription); ok { + if rf, ok := ret.Get(0).(func(string, string, ...natsgo.SubOpt) *natsgo.Subscription); ok { r0 = rf(subj, durable, opts...) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*nats.Subscription) + r0 = ret.Get(0).(*natsgo.Subscription) } } - if rf, ok := ret.Get(1).(func(string, string, ...nats.SubOpt) error); ok { + if rf, ok := ret.Get(1).(func(string, string, ...natsgo.SubOpt) error); ok { r1 = rf(subj, durable, opts...) } else { r1 = ret.Error(1) @@ -1830,18 +1830,18 @@ type JetStreamContext_PullSubscribe_Call struct { // PullSubscribe is a helper method to define mock.On call // - subj string // - durable string -// - opts ...nats.SubOpt +// - opts ...natsgo.SubOpt func (_e *JetStreamContext_Expecter) PullSubscribe(subj interface{}, durable interface{}, opts ...interface{}) *JetStreamContext_PullSubscribe_Call { return &JetStreamContext_PullSubscribe_Call{Call: _e.mock.On("PullSubscribe", append([]interface{}{subj, durable}, opts...)...)} } -func (_c *JetStreamContext_PullSubscribe_Call) Run(run func(subj string, durable string, opts ...nats.SubOpt)) *JetStreamContext_PullSubscribe_Call { +func (_c *JetStreamContext_PullSubscribe_Call) Run(run func(subj string, durable string, opts ...natsgo.SubOpt)) *JetStreamContext_PullSubscribe_Call { _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]nats.SubOpt, len(args)-2) + variadicArgs := make([]natsgo.SubOpt, len(args)-2) for i, a := range args[2:] { if a != nil { - variadicArgs[i] = a.(nats.SubOpt) + variadicArgs[i] = a.(natsgo.SubOpt) } } run(args[0].(string), args[1].(string), variadicArgs...) @@ -1849,18 +1849,18 @@ func (_c *JetStreamContext_PullSubscribe_Call) Run(run func(subj string, durable return _c } -func (_c *JetStreamContext_PullSubscribe_Call) Return(_a0 *nats.Subscription, _a1 error) *JetStreamContext_PullSubscribe_Call { +func (_c *JetStreamContext_PullSubscribe_Call) Return(_a0 *natsgo.Subscription, _a1 error) *JetStreamContext_PullSubscribe_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *JetStreamContext_PullSubscribe_Call) RunAndReturn(run func(string, string, ...nats.SubOpt) (*nats.Subscription, error)) *JetStreamContext_PullSubscribe_Call { +func (_c *JetStreamContext_PullSubscribe_Call) RunAndReturn(run func(string, string, ...natsgo.SubOpt) (*natsgo.Subscription, error)) *JetStreamContext_PullSubscribe_Call { _c.Call.Return(run) return _c } // PurgeStream provides a mock function with given fields: name, opts -func (_m *JetStreamContext) PurgeStream(name string, opts ...nats.JSOpt) error { +func (_m *JetStreamContext) PurgeStream(name string, opts ...natsgo.JSOpt) error { _va := make([]interface{}, len(opts)) for _i := range opts { _va[_i] = opts[_i] @@ -1871,7 +1871,7 @@ func (_m *JetStreamContext) PurgeStream(name string, opts ...nats.JSOpt) error { ret := _m.Called(_ca...) var r0 error - if rf, ok := ret.Get(0).(func(string, ...nats.JSOpt) error); ok { + if rf, ok := ret.Get(0).(func(string, ...natsgo.JSOpt) error); ok { r0 = rf(name, opts...) } else { r0 = ret.Error(0) @@ -1887,18 +1887,18 @@ type JetStreamContext_PurgeStream_Call struct { // PurgeStream is a helper method to define mock.On call // - name string -// - opts ...nats.JSOpt +// - opts ...natsgo.JSOpt func (_e *JetStreamContext_Expecter) PurgeStream(name interface{}, opts ...interface{}) *JetStreamContext_PurgeStream_Call { return &JetStreamContext_PurgeStream_Call{Call: _e.mock.On("PurgeStream", append([]interface{}{name}, opts...)...)} } -func (_c *JetStreamContext_PurgeStream_Call) Run(run func(name string, opts ...nats.JSOpt)) *JetStreamContext_PurgeStream_Call { +func (_c *JetStreamContext_PurgeStream_Call) Run(run func(name string, opts ...natsgo.JSOpt)) *JetStreamContext_PurgeStream_Call { _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]nats.JSOpt, len(args)-1) + variadicArgs := make([]natsgo.JSOpt, len(args)-1) for i, a := range args[1:] { if a != nil { - variadicArgs[i] = a.(nats.JSOpt) + variadicArgs[i] = a.(natsgo.JSOpt) } } run(args[0].(string), variadicArgs...) @@ -1911,13 +1911,13 @@ func (_c *JetStreamContext_PurgeStream_Call) Return(_a0 error) *JetStreamContext return _c } -func (_c *JetStreamContext_PurgeStream_Call) RunAndReturn(run func(string, ...nats.JSOpt) error) *JetStreamContext_PurgeStream_Call { +func (_c *JetStreamContext_PurgeStream_Call) RunAndReturn(run func(string, ...natsgo.JSOpt) error) *JetStreamContext_PurgeStream_Call { _c.Call.Return(run) return _c } // QueueSubscribe provides a mock function with given fields: subj, queue, cb, opts -func (_m *JetStreamContext) QueueSubscribe(subj string, queue string, cb nats.MsgHandler, opts ...nats.SubOpt) (*nats.Subscription, error) { +func (_m *JetStreamContext) QueueSubscribe(subj string, queue string, cb natsgo.MsgHandler, opts ...natsgo.SubOpt) (*natsgo.Subscription, error) { _va := make([]interface{}, len(opts)) for _i := range opts { _va[_i] = opts[_i] @@ -1927,20 +1927,20 @@ func (_m *JetStreamContext) QueueSubscribe(subj string, queue string, cb nats.Ms _ca = append(_ca, _va...) ret := _m.Called(_ca...) - var r0 *nats.Subscription + var r0 *natsgo.Subscription var r1 error - if rf, ok := ret.Get(0).(func(string, string, nats.MsgHandler, ...nats.SubOpt) (*nats.Subscription, error)); ok { + if rf, ok := ret.Get(0).(func(string, string, natsgo.MsgHandler, ...natsgo.SubOpt) (*natsgo.Subscription, error)); ok { return rf(subj, queue, cb, opts...) } - if rf, ok := ret.Get(0).(func(string, string, nats.MsgHandler, ...nats.SubOpt) *nats.Subscription); ok { + if rf, ok := ret.Get(0).(func(string, string, natsgo.MsgHandler, ...natsgo.SubOpt) *natsgo.Subscription); ok { r0 = rf(subj, queue, cb, opts...) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*nats.Subscription) + r0 = ret.Get(0).(*natsgo.Subscription) } } - if rf, ok := ret.Get(1).(func(string, string, nats.MsgHandler, ...nats.SubOpt) error); ok { + if rf, ok := ret.Get(1).(func(string, string, natsgo.MsgHandler, ...natsgo.SubOpt) error); ok { r1 = rf(subj, queue, cb, opts...) } else { r1 = ret.Error(1) @@ -1957,38 +1957,38 @@ type JetStreamContext_QueueSubscribe_Call struct { // QueueSubscribe is a helper method to define mock.On call // - subj string // - queue string -// - cb nats.MsgHandler -// - opts ...nats.SubOpt +// - cb natsgo.MsgHandler +// - opts ...natsgo.SubOpt func (_e *JetStreamContext_Expecter) QueueSubscribe(subj interface{}, queue interface{}, cb interface{}, opts ...interface{}) *JetStreamContext_QueueSubscribe_Call { return &JetStreamContext_QueueSubscribe_Call{Call: _e.mock.On("QueueSubscribe", append([]interface{}{subj, queue, cb}, opts...)...)} } -func (_c *JetStreamContext_QueueSubscribe_Call) Run(run func(subj string, queue string, cb nats.MsgHandler, opts ...nats.SubOpt)) *JetStreamContext_QueueSubscribe_Call { +func (_c *JetStreamContext_QueueSubscribe_Call) Run(run func(subj string, queue string, cb natsgo.MsgHandler, opts ...natsgo.SubOpt)) *JetStreamContext_QueueSubscribe_Call { _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]nats.SubOpt, len(args)-3) + variadicArgs := make([]natsgo.SubOpt, len(args)-3) for i, a := range args[3:] { if a != nil { - variadicArgs[i] = a.(nats.SubOpt) + variadicArgs[i] = a.(natsgo.SubOpt) } } - run(args[0].(string), args[1].(string), args[2].(nats.MsgHandler), variadicArgs...) + run(args[0].(string), args[1].(string), args[2].(natsgo.MsgHandler), variadicArgs...) }) return _c } -func (_c *JetStreamContext_QueueSubscribe_Call) Return(_a0 *nats.Subscription, _a1 error) *JetStreamContext_QueueSubscribe_Call { +func (_c *JetStreamContext_QueueSubscribe_Call) Return(_a0 *natsgo.Subscription, _a1 error) *JetStreamContext_QueueSubscribe_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *JetStreamContext_QueueSubscribe_Call) RunAndReturn(run func(string, string, nats.MsgHandler, ...nats.SubOpt) (*nats.Subscription, error)) *JetStreamContext_QueueSubscribe_Call { +func (_c *JetStreamContext_QueueSubscribe_Call) RunAndReturn(run func(string, string, natsgo.MsgHandler, ...natsgo.SubOpt) (*natsgo.Subscription, error)) *JetStreamContext_QueueSubscribe_Call { _c.Call.Return(run) return _c } // QueueSubscribeSync provides a mock function with given fields: subj, queue, opts -func (_m *JetStreamContext) QueueSubscribeSync(subj string, queue string, opts ...nats.SubOpt) (*nats.Subscription, error) { +func (_m *JetStreamContext) QueueSubscribeSync(subj string, queue string, opts ...natsgo.SubOpt) (*natsgo.Subscription, error) { _va := make([]interface{}, len(opts)) for _i := range opts { _va[_i] = opts[_i] @@ -1998,20 +1998,20 @@ func (_m *JetStreamContext) QueueSubscribeSync(subj string, queue string, opts . _ca = append(_ca, _va...) ret := _m.Called(_ca...) - var r0 *nats.Subscription + var r0 *natsgo.Subscription var r1 error - if rf, ok := ret.Get(0).(func(string, string, ...nats.SubOpt) (*nats.Subscription, error)); ok { + if rf, ok := ret.Get(0).(func(string, string, ...natsgo.SubOpt) (*natsgo.Subscription, error)); ok { return rf(subj, queue, opts...) } - if rf, ok := ret.Get(0).(func(string, string, ...nats.SubOpt) *nats.Subscription); ok { + if rf, ok := ret.Get(0).(func(string, string, ...natsgo.SubOpt) *natsgo.Subscription); ok { r0 = rf(subj, queue, opts...) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*nats.Subscription) + r0 = ret.Get(0).(*natsgo.Subscription) } } - if rf, ok := ret.Get(1).(func(string, string, ...nats.SubOpt) error); ok { + if rf, ok := ret.Get(1).(func(string, string, ...natsgo.SubOpt) error); ok { r1 = rf(subj, queue, opts...) } else { r1 = ret.Error(1) @@ -2028,18 +2028,18 @@ type JetStreamContext_QueueSubscribeSync_Call struct { // QueueSubscribeSync is a helper method to define mock.On call // - subj string // - queue string -// - opts ...nats.SubOpt +// - opts ...natsgo.SubOpt func (_e *JetStreamContext_Expecter) QueueSubscribeSync(subj interface{}, queue interface{}, opts ...interface{}) *JetStreamContext_QueueSubscribeSync_Call { return &JetStreamContext_QueueSubscribeSync_Call{Call: _e.mock.On("QueueSubscribeSync", append([]interface{}{subj, queue}, opts...)...)} } -func (_c *JetStreamContext_QueueSubscribeSync_Call) Run(run func(subj string, queue string, opts ...nats.SubOpt)) *JetStreamContext_QueueSubscribeSync_Call { +func (_c *JetStreamContext_QueueSubscribeSync_Call) Run(run func(subj string, queue string, opts ...natsgo.SubOpt)) *JetStreamContext_QueueSubscribeSync_Call { _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]nats.SubOpt, len(args)-2) + variadicArgs := make([]natsgo.SubOpt, len(args)-2) for i, a := range args[2:] { if a != nil { - variadicArgs[i] = a.(nats.SubOpt) + variadicArgs[i] = a.(natsgo.SubOpt) } } run(args[0].(string), args[1].(string), variadicArgs...) @@ -2047,18 +2047,18 @@ func (_c *JetStreamContext_QueueSubscribeSync_Call) Run(run func(subj string, qu return _c } -func (_c *JetStreamContext_QueueSubscribeSync_Call) Return(_a0 *nats.Subscription, _a1 error) *JetStreamContext_QueueSubscribeSync_Call { +func (_c *JetStreamContext_QueueSubscribeSync_Call) Return(_a0 *natsgo.Subscription, _a1 error) *JetStreamContext_QueueSubscribeSync_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *JetStreamContext_QueueSubscribeSync_Call) RunAndReturn(run func(string, string, ...nats.SubOpt) (*nats.Subscription, error)) *JetStreamContext_QueueSubscribeSync_Call { +func (_c *JetStreamContext_QueueSubscribeSync_Call) RunAndReturn(run func(string, string, ...natsgo.SubOpt) (*natsgo.Subscription, error)) *JetStreamContext_QueueSubscribeSync_Call { _c.Call.Return(run) return _c } // SecureDeleteMsg provides a mock function with given fields: name, seq, opts -func (_m *JetStreamContext) SecureDeleteMsg(name string, seq uint64, opts ...nats.JSOpt) error { +func (_m *JetStreamContext) SecureDeleteMsg(name string, seq uint64, opts ...natsgo.JSOpt) error { _va := make([]interface{}, len(opts)) for _i := range opts { _va[_i] = opts[_i] @@ -2069,7 +2069,7 @@ func (_m *JetStreamContext) SecureDeleteMsg(name string, seq uint64, opts ...nat ret := _m.Called(_ca...) var r0 error - if rf, ok := ret.Get(0).(func(string, uint64, ...nats.JSOpt) error); ok { + if rf, ok := ret.Get(0).(func(string, uint64, ...natsgo.JSOpt) error); ok { r0 = rf(name, seq, opts...) } else { r0 = ret.Error(0) @@ -2086,18 +2086,18 @@ type JetStreamContext_SecureDeleteMsg_Call struct { // SecureDeleteMsg is a helper method to define mock.On call // - name string // - seq uint64 -// - opts ...nats.JSOpt +// - opts ...natsgo.JSOpt func (_e *JetStreamContext_Expecter) SecureDeleteMsg(name interface{}, seq interface{}, opts ...interface{}) *JetStreamContext_SecureDeleteMsg_Call { return &JetStreamContext_SecureDeleteMsg_Call{Call: _e.mock.On("SecureDeleteMsg", append([]interface{}{name, seq}, opts...)...)} } -func (_c *JetStreamContext_SecureDeleteMsg_Call) Run(run func(name string, seq uint64, opts ...nats.JSOpt)) *JetStreamContext_SecureDeleteMsg_Call { +func (_c *JetStreamContext_SecureDeleteMsg_Call) Run(run func(name string, seq uint64, opts ...natsgo.JSOpt)) *JetStreamContext_SecureDeleteMsg_Call { _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]nats.JSOpt, len(args)-2) + variadicArgs := make([]natsgo.JSOpt, len(args)-2) for i, a := range args[2:] { if a != nil { - variadicArgs[i] = a.(nats.JSOpt) + variadicArgs[i] = a.(natsgo.JSOpt) } } run(args[0].(string), args[1].(uint64), variadicArgs...) @@ -2110,13 +2110,13 @@ func (_c *JetStreamContext_SecureDeleteMsg_Call) Return(_a0 error) *JetStreamCon return _c } -func (_c *JetStreamContext_SecureDeleteMsg_Call) RunAndReturn(run func(string, uint64, ...nats.JSOpt) error) *JetStreamContext_SecureDeleteMsg_Call { +func (_c *JetStreamContext_SecureDeleteMsg_Call) RunAndReturn(run func(string, uint64, ...natsgo.JSOpt) error) *JetStreamContext_SecureDeleteMsg_Call { _c.Call.Return(run) return _c } // StreamInfo provides a mock function with given fields: stream, opts -func (_m *JetStreamContext) StreamInfo(stream string, opts ...nats.JSOpt) (*nats.StreamInfo, error) { +func (_m *JetStreamContext) StreamInfo(stream string, opts ...natsgo.JSOpt) (*natsgo.StreamInfo, error) { _va := make([]interface{}, len(opts)) for _i := range opts { _va[_i] = opts[_i] @@ -2126,20 +2126,20 @@ func (_m *JetStreamContext) StreamInfo(stream string, opts ...nats.JSOpt) (*nats _ca = append(_ca, _va...) ret := _m.Called(_ca...) - var r0 *nats.StreamInfo + var r0 *natsgo.StreamInfo var r1 error - if rf, ok := ret.Get(0).(func(string, ...nats.JSOpt) (*nats.StreamInfo, error)); ok { + if rf, ok := ret.Get(0).(func(string, ...natsgo.JSOpt) (*natsgo.StreamInfo, error)); ok { return rf(stream, opts...) } - if rf, ok := ret.Get(0).(func(string, ...nats.JSOpt) *nats.StreamInfo); ok { + if rf, ok := ret.Get(0).(func(string, ...natsgo.JSOpt) *natsgo.StreamInfo); ok { r0 = rf(stream, opts...) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*nats.StreamInfo) + r0 = ret.Get(0).(*natsgo.StreamInfo) } } - if rf, ok := ret.Get(1).(func(string, ...nats.JSOpt) error); ok { + if rf, ok := ret.Get(1).(func(string, ...natsgo.JSOpt) error); ok { r1 = rf(stream, opts...) } else { r1 = ret.Error(1) @@ -2155,18 +2155,18 @@ type JetStreamContext_StreamInfo_Call struct { // StreamInfo is a helper method to define mock.On call // - stream string -// - opts ...nats.JSOpt +// - opts ...natsgo.JSOpt func (_e *JetStreamContext_Expecter) StreamInfo(stream interface{}, opts ...interface{}) *JetStreamContext_StreamInfo_Call { return &JetStreamContext_StreamInfo_Call{Call: _e.mock.On("StreamInfo", append([]interface{}{stream}, opts...)...)} } -func (_c *JetStreamContext_StreamInfo_Call) Run(run func(stream string, opts ...nats.JSOpt)) *JetStreamContext_StreamInfo_Call { +func (_c *JetStreamContext_StreamInfo_Call) Run(run func(stream string, opts ...natsgo.JSOpt)) *JetStreamContext_StreamInfo_Call { _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]nats.JSOpt, len(args)-1) + variadicArgs := make([]natsgo.JSOpt, len(args)-1) for i, a := range args[1:] { if a != nil { - variadicArgs[i] = a.(nats.JSOpt) + variadicArgs[i] = a.(natsgo.JSOpt) } } run(args[0].(string), variadicArgs...) @@ -2174,18 +2174,18 @@ func (_c *JetStreamContext_StreamInfo_Call) Run(run func(stream string, opts ... return _c } -func (_c *JetStreamContext_StreamInfo_Call) Return(_a0 *nats.StreamInfo, _a1 error) *JetStreamContext_StreamInfo_Call { +func (_c *JetStreamContext_StreamInfo_Call) Return(_a0 *natsgo.StreamInfo, _a1 error) *JetStreamContext_StreamInfo_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *JetStreamContext_StreamInfo_Call) RunAndReturn(run func(string, ...nats.JSOpt) (*nats.StreamInfo, error)) *JetStreamContext_StreamInfo_Call { +func (_c *JetStreamContext_StreamInfo_Call) RunAndReturn(run func(string, ...natsgo.JSOpt) (*natsgo.StreamInfo, error)) *JetStreamContext_StreamInfo_Call { _c.Call.Return(run) return _c } // StreamNameBySubject provides a mock function with given fields: _a0, _a1 -func (_m *JetStreamContext) StreamNameBySubject(_a0 string, _a1 ...nats.JSOpt) (string, error) { +func (_m *JetStreamContext) StreamNameBySubject(_a0 string, _a1 ...natsgo.JSOpt) (string, error) { _va := make([]interface{}, len(_a1)) for _i := range _a1 { _va[_i] = _a1[_i] @@ -2197,16 +2197,16 @@ func (_m *JetStreamContext) StreamNameBySubject(_a0 string, _a1 ...nats.JSOpt) ( var r0 string var r1 error - if rf, ok := ret.Get(0).(func(string, ...nats.JSOpt) (string, error)); ok { + if rf, ok := ret.Get(0).(func(string, ...natsgo.JSOpt) (string, error)); ok { return rf(_a0, _a1...) } - if rf, ok := ret.Get(0).(func(string, ...nats.JSOpt) string); ok { + if rf, ok := ret.Get(0).(func(string, ...natsgo.JSOpt) string); ok { r0 = rf(_a0, _a1...) } else { r0 = ret.Get(0).(string) } - if rf, ok := ret.Get(1).(func(string, ...nats.JSOpt) error); ok { + if rf, ok := ret.Get(1).(func(string, ...natsgo.JSOpt) error); ok { r1 = rf(_a0, _a1...) } else { r1 = ret.Error(1) @@ -2222,18 +2222,18 @@ type JetStreamContext_StreamNameBySubject_Call struct { // StreamNameBySubject is a helper method to define mock.On call // - _a0 string -// - _a1 ...nats.JSOpt +// - _a1 ...natsgo.JSOpt func (_e *JetStreamContext_Expecter) StreamNameBySubject(_a0 interface{}, _a1 ...interface{}) *JetStreamContext_StreamNameBySubject_Call { return &JetStreamContext_StreamNameBySubject_Call{Call: _e.mock.On("StreamNameBySubject", append([]interface{}{_a0}, _a1...)...)} } -func (_c *JetStreamContext_StreamNameBySubject_Call) Run(run func(_a0 string, _a1 ...nats.JSOpt)) *JetStreamContext_StreamNameBySubject_Call { +func (_c *JetStreamContext_StreamNameBySubject_Call) Run(run func(_a0 string, _a1 ...natsgo.JSOpt)) *JetStreamContext_StreamNameBySubject_Call { _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]nats.JSOpt, len(args)-1) + variadicArgs := make([]natsgo.JSOpt, len(args)-1) for i, a := range args[1:] { if a != nil { - variadicArgs[i] = a.(nats.JSOpt) + variadicArgs[i] = a.(natsgo.JSOpt) } } run(args[0].(string), variadicArgs...) @@ -2246,13 +2246,13 @@ func (_c *JetStreamContext_StreamNameBySubject_Call) Return(_a0 string, _a1 erro return _c } -func (_c *JetStreamContext_StreamNameBySubject_Call) RunAndReturn(run func(string, ...nats.JSOpt) (string, error)) *JetStreamContext_StreamNameBySubject_Call { +func (_c *JetStreamContext_StreamNameBySubject_Call) RunAndReturn(run func(string, ...natsgo.JSOpt) (string, error)) *JetStreamContext_StreamNameBySubject_Call { _c.Call.Return(run) return _c } // StreamNames provides a mock function with given fields: opts -func (_m *JetStreamContext) StreamNames(opts ...nats.JSOpt) <-chan string { +func (_m *JetStreamContext) StreamNames(opts ...natsgo.JSOpt) <-chan string { _va := make([]interface{}, len(opts)) for _i := range opts { _va[_i] = opts[_i] @@ -2262,7 +2262,7 @@ func (_m *JetStreamContext) StreamNames(opts ...nats.JSOpt) <-chan string { ret := _m.Called(_ca...) var r0 <-chan string - if rf, ok := ret.Get(0).(func(...nats.JSOpt) <-chan string); ok { + if rf, ok := ret.Get(0).(func(...natsgo.JSOpt) <-chan string); ok { r0 = rf(opts...) } else { if ret.Get(0) != nil { @@ -2279,18 +2279,18 @@ type JetStreamContext_StreamNames_Call struct { } // StreamNames is a helper method to define mock.On call -// - opts ...nats.JSOpt +// - opts ...natsgo.JSOpt func (_e *JetStreamContext_Expecter) StreamNames(opts ...interface{}) *JetStreamContext_StreamNames_Call { return &JetStreamContext_StreamNames_Call{Call: _e.mock.On("StreamNames", append([]interface{}{}, opts...)...)} } -func (_c *JetStreamContext_StreamNames_Call) Run(run func(opts ...nats.JSOpt)) *JetStreamContext_StreamNames_Call { +func (_c *JetStreamContext_StreamNames_Call) Run(run func(opts ...natsgo.JSOpt)) *JetStreamContext_StreamNames_Call { _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]nats.JSOpt, len(args)-0) + variadicArgs := make([]natsgo.JSOpt, len(args)-0) for i, a := range args[0:] { if a != nil { - variadicArgs[i] = a.(nats.JSOpt) + variadicArgs[i] = a.(natsgo.JSOpt) } } run(variadicArgs...) @@ -2303,13 +2303,13 @@ func (_c *JetStreamContext_StreamNames_Call) Return(_a0 <-chan string) *JetStrea return _c } -func (_c *JetStreamContext_StreamNames_Call) RunAndReturn(run func(...nats.JSOpt) <-chan string) *JetStreamContext_StreamNames_Call { +func (_c *JetStreamContext_StreamNames_Call) RunAndReturn(run func(...natsgo.JSOpt) <-chan string) *JetStreamContext_StreamNames_Call { _c.Call.Return(run) return _c } // Streams provides a mock function with given fields: opts -func (_m *JetStreamContext) Streams(opts ...nats.JSOpt) <-chan *nats.StreamInfo { +func (_m *JetStreamContext) Streams(opts ...natsgo.JSOpt) <-chan *natsgo.StreamInfo { _va := make([]interface{}, len(opts)) for _i := range opts { _va[_i] = opts[_i] @@ -2318,12 +2318,12 @@ func (_m *JetStreamContext) Streams(opts ...nats.JSOpt) <-chan *nats.StreamInfo _ca = append(_ca, _va...) ret := _m.Called(_ca...) - var r0 <-chan *nats.StreamInfo - if rf, ok := ret.Get(0).(func(...nats.JSOpt) <-chan *nats.StreamInfo); ok { + var r0 <-chan *natsgo.StreamInfo + if rf, ok := ret.Get(0).(func(...natsgo.JSOpt) <-chan *natsgo.StreamInfo); ok { r0 = rf(opts...) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(<-chan *nats.StreamInfo) + r0 = ret.Get(0).(<-chan *natsgo.StreamInfo) } } @@ -2336,18 +2336,18 @@ type JetStreamContext_Streams_Call struct { } // Streams is a helper method to define mock.On call -// - opts ...nats.JSOpt +// - opts ...natsgo.JSOpt func (_e *JetStreamContext_Expecter) Streams(opts ...interface{}) *JetStreamContext_Streams_Call { return &JetStreamContext_Streams_Call{Call: _e.mock.On("Streams", append([]interface{}{}, opts...)...)} } -func (_c *JetStreamContext_Streams_Call) Run(run func(opts ...nats.JSOpt)) *JetStreamContext_Streams_Call { +func (_c *JetStreamContext_Streams_Call) Run(run func(opts ...natsgo.JSOpt)) *JetStreamContext_Streams_Call { _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]nats.JSOpt, len(args)-0) + variadicArgs := make([]natsgo.JSOpt, len(args)-0) for i, a := range args[0:] { if a != nil { - variadicArgs[i] = a.(nats.JSOpt) + variadicArgs[i] = a.(natsgo.JSOpt) } } run(variadicArgs...) @@ -2355,18 +2355,18 @@ func (_c *JetStreamContext_Streams_Call) Run(run func(opts ...nats.JSOpt)) *JetS return _c } -func (_c *JetStreamContext_Streams_Call) Return(_a0 <-chan *nats.StreamInfo) *JetStreamContext_Streams_Call { +func (_c *JetStreamContext_Streams_Call) Return(_a0 <-chan *natsgo.StreamInfo) *JetStreamContext_Streams_Call { _c.Call.Return(_a0) return _c } -func (_c *JetStreamContext_Streams_Call) RunAndReturn(run func(...nats.JSOpt) <-chan *nats.StreamInfo) *JetStreamContext_Streams_Call { +func (_c *JetStreamContext_Streams_Call) RunAndReturn(run func(...natsgo.JSOpt) <-chan *natsgo.StreamInfo) *JetStreamContext_Streams_Call { _c.Call.Return(run) return _c } // StreamsInfo provides a mock function with given fields: opts -func (_m *JetStreamContext) StreamsInfo(opts ...nats.JSOpt) <-chan *nats.StreamInfo { +func (_m *JetStreamContext) StreamsInfo(opts ...natsgo.JSOpt) <-chan *natsgo.StreamInfo { _va := make([]interface{}, len(opts)) for _i := range opts { _va[_i] = opts[_i] @@ -2375,12 +2375,12 @@ func (_m *JetStreamContext) StreamsInfo(opts ...nats.JSOpt) <-chan *nats.StreamI _ca = append(_ca, _va...) ret := _m.Called(_ca...) - var r0 <-chan *nats.StreamInfo - if rf, ok := ret.Get(0).(func(...nats.JSOpt) <-chan *nats.StreamInfo); ok { + var r0 <-chan *natsgo.StreamInfo + if rf, ok := ret.Get(0).(func(...natsgo.JSOpt) <-chan *natsgo.StreamInfo); ok { r0 = rf(opts...) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(<-chan *nats.StreamInfo) + r0 = ret.Get(0).(<-chan *natsgo.StreamInfo) } } @@ -2393,18 +2393,18 @@ type JetStreamContext_StreamsInfo_Call struct { } // StreamsInfo is a helper method to define mock.On call -// - opts ...nats.JSOpt +// - opts ...natsgo.JSOpt func (_e *JetStreamContext_Expecter) StreamsInfo(opts ...interface{}) *JetStreamContext_StreamsInfo_Call { return &JetStreamContext_StreamsInfo_Call{Call: _e.mock.On("StreamsInfo", append([]interface{}{}, opts...)...)} } -func (_c *JetStreamContext_StreamsInfo_Call) Run(run func(opts ...nats.JSOpt)) *JetStreamContext_StreamsInfo_Call { +func (_c *JetStreamContext_StreamsInfo_Call) Run(run func(opts ...natsgo.JSOpt)) *JetStreamContext_StreamsInfo_Call { _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]nats.JSOpt, len(args)-0) + variadicArgs := make([]natsgo.JSOpt, len(args)-0) for i, a := range args[0:] { if a != nil { - variadicArgs[i] = a.(nats.JSOpt) + variadicArgs[i] = a.(natsgo.JSOpt) } } run(variadicArgs...) @@ -2412,18 +2412,18 @@ func (_c *JetStreamContext_StreamsInfo_Call) Run(run func(opts ...nats.JSOpt)) * return _c } -func (_c *JetStreamContext_StreamsInfo_Call) Return(_a0 <-chan *nats.StreamInfo) *JetStreamContext_StreamsInfo_Call { +func (_c *JetStreamContext_StreamsInfo_Call) Return(_a0 <-chan *natsgo.StreamInfo) *JetStreamContext_StreamsInfo_Call { _c.Call.Return(_a0) return _c } -func (_c *JetStreamContext_StreamsInfo_Call) RunAndReturn(run func(...nats.JSOpt) <-chan *nats.StreamInfo) *JetStreamContext_StreamsInfo_Call { +func (_c *JetStreamContext_StreamsInfo_Call) RunAndReturn(run func(...natsgo.JSOpt) <-chan *natsgo.StreamInfo) *JetStreamContext_StreamsInfo_Call { _c.Call.Return(run) return _c } // Subscribe provides a mock function with given fields: subj, cb, opts -func (_m *JetStreamContext) Subscribe(subj string, cb nats.MsgHandler, opts ...nats.SubOpt) (*nats.Subscription, error) { +func (_m *JetStreamContext) Subscribe(subj string, cb natsgo.MsgHandler, opts ...natsgo.SubOpt) (*natsgo.Subscription, error) { _va := make([]interface{}, len(opts)) for _i := range opts { _va[_i] = opts[_i] @@ -2433,20 +2433,20 @@ func (_m *JetStreamContext) Subscribe(subj string, cb nats.MsgHandler, opts ...n _ca = append(_ca, _va...) ret := _m.Called(_ca...) - var r0 *nats.Subscription + var r0 *natsgo.Subscription var r1 error - if rf, ok := ret.Get(0).(func(string, nats.MsgHandler, ...nats.SubOpt) (*nats.Subscription, error)); ok { + if rf, ok := ret.Get(0).(func(string, natsgo.MsgHandler, ...natsgo.SubOpt) (*natsgo.Subscription, error)); ok { return rf(subj, cb, opts...) } - if rf, ok := ret.Get(0).(func(string, nats.MsgHandler, ...nats.SubOpt) *nats.Subscription); ok { + if rf, ok := ret.Get(0).(func(string, natsgo.MsgHandler, ...natsgo.SubOpt) *natsgo.Subscription); ok { r0 = rf(subj, cb, opts...) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*nats.Subscription) + r0 = ret.Get(0).(*natsgo.Subscription) } } - if rf, ok := ret.Get(1).(func(string, nats.MsgHandler, ...nats.SubOpt) error); ok { + if rf, ok := ret.Get(1).(func(string, natsgo.MsgHandler, ...natsgo.SubOpt) error); ok { r1 = rf(subj, cb, opts...) } else { r1 = ret.Error(1) @@ -2462,38 +2462,38 @@ type JetStreamContext_Subscribe_Call struct { // Subscribe is a helper method to define mock.On call // - subj string -// - cb nats.MsgHandler -// - opts ...nats.SubOpt +// - cb natsgo.MsgHandler +// - opts ...natsgo.SubOpt func (_e *JetStreamContext_Expecter) Subscribe(subj interface{}, cb interface{}, opts ...interface{}) *JetStreamContext_Subscribe_Call { return &JetStreamContext_Subscribe_Call{Call: _e.mock.On("Subscribe", append([]interface{}{subj, cb}, opts...)...)} } -func (_c *JetStreamContext_Subscribe_Call) Run(run func(subj string, cb nats.MsgHandler, opts ...nats.SubOpt)) *JetStreamContext_Subscribe_Call { +func (_c *JetStreamContext_Subscribe_Call) Run(run func(subj string, cb natsgo.MsgHandler, opts ...natsgo.SubOpt)) *JetStreamContext_Subscribe_Call { _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]nats.SubOpt, len(args)-2) + variadicArgs := make([]natsgo.SubOpt, len(args)-2) for i, a := range args[2:] { if a != nil { - variadicArgs[i] = a.(nats.SubOpt) + variadicArgs[i] = a.(natsgo.SubOpt) } } - run(args[0].(string), args[1].(nats.MsgHandler), variadicArgs...) + run(args[0].(string), args[1].(natsgo.MsgHandler), variadicArgs...) }) return _c } -func (_c *JetStreamContext_Subscribe_Call) Return(_a0 *nats.Subscription, _a1 error) *JetStreamContext_Subscribe_Call { +func (_c *JetStreamContext_Subscribe_Call) Return(_a0 *natsgo.Subscription, _a1 error) *JetStreamContext_Subscribe_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *JetStreamContext_Subscribe_Call) RunAndReturn(run func(string, nats.MsgHandler, ...nats.SubOpt) (*nats.Subscription, error)) *JetStreamContext_Subscribe_Call { +func (_c *JetStreamContext_Subscribe_Call) RunAndReturn(run func(string, natsgo.MsgHandler, ...natsgo.SubOpt) (*natsgo.Subscription, error)) *JetStreamContext_Subscribe_Call { _c.Call.Return(run) return _c } // SubscribeSync provides a mock function with given fields: subj, opts -func (_m *JetStreamContext) SubscribeSync(subj string, opts ...nats.SubOpt) (*nats.Subscription, error) { +func (_m *JetStreamContext) SubscribeSync(subj string, opts ...natsgo.SubOpt) (*natsgo.Subscription, error) { _va := make([]interface{}, len(opts)) for _i := range opts { _va[_i] = opts[_i] @@ -2503,20 +2503,20 @@ func (_m *JetStreamContext) SubscribeSync(subj string, opts ...nats.SubOpt) (*na _ca = append(_ca, _va...) ret := _m.Called(_ca...) - var r0 *nats.Subscription + var r0 *natsgo.Subscription var r1 error - if rf, ok := ret.Get(0).(func(string, ...nats.SubOpt) (*nats.Subscription, error)); ok { + if rf, ok := ret.Get(0).(func(string, ...natsgo.SubOpt) (*natsgo.Subscription, error)); ok { return rf(subj, opts...) } - if rf, ok := ret.Get(0).(func(string, ...nats.SubOpt) *nats.Subscription); ok { + if rf, ok := ret.Get(0).(func(string, ...natsgo.SubOpt) *natsgo.Subscription); ok { r0 = rf(subj, opts...) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*nats.Subscription) + r0 = ret.Get(0).(*natsgo.Subscription) } } - if rf, ok := ret.Get(1).(func(string, ...nats.SubOpt) error); ok { + if rf, ok := ret.Get(1).(func(string, ...natsgo.SubOpt) error); ok { r1 = rf(subj, opts...) } else { r1 = ret.Error(1) @@ -2532,18 +2532,18 @@ type JetStreamContext_SubscribeSync_Call struct { // SubscribeSync is a helper method to define mock.On call // - subj string -// - opts ...nats.SubOpt +// - opts ...natsgo.SubOpt func (_e *JetStreamContext_Expecter) SubscribeSync(subj interface{}, opts ...interface{}) *JetStreamContext_SubscribeSync_Call { return &JetStreamContext_SubscribeSync_Call{Call: _e.mock.On("SubscribeSync", append([]interface{}{subj}, opts...)...)} } -func (_c *JetStreamContext_SubscribeSync_Call) Run(run func(subj string, opts ...nats.SubOpt)) *JetStreamContext_SubscribeSync_Call { +func (_c *JetStreamContext_SubscribeSync_Call) Run(run func(subj string, opts ...natsgo.SubOpt)) *JetStreamContext_SubscribeSync_Call { _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]nats.SubOpt, len(args)-1) + variadicArgs := make([]natsgo.SubOpt, len(args)-1) for i, a := range args[1:] { if a != nil { - variadicArgs[i] = a.(nats.SubOpt) + variadicArgs[i] = a.(natsgo.SubOpt) } } run(args[0].(string), variadicArgs...) @@ -2551,18 +2551,18 @@ func (_c *JetStreamContext_SubscribeSync_Call) Run(run func(subj string, opts .. return _c } -func (_c *JetStreamContext_SubscribeSync_Call) Return(_a0 *nats.Subscription, _a1 error) *JetStreamContext_SubscribeSync_Call { +func (_c *JetStreamContext_SubscribeSync_Call) Return(_a0 *natsgo.Subscription, _a1 error) *JetStreamContext_SubscribeSync_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *JetStreamContext_SubscribeSync_Call) RunAndReturn(run func(string, ...nats.SubOpt) (*nats.Subscription, error)) *JetStreamContext_SubscribeSync_Call { +func (_c *JetStreamContext_SubscribeSync_Call) RunAndReturn(run func(string, ...natsgo.SubOpt) (*natsgo.Subscription, error)) *JetStreamContext_SubscribeSync_Call { _c.Call.Return(run) return _c } // UpdateConsumer provides a mock function with given fields: stream, cfg, opts -func (_m *JetStreamContext) UpdateConsumer(stream string, cfg *nats.ConsumerConfig, opts ...nats.JSOpt) (*nats.ConsumerInfo, error) { +func (_m *JetStreamContext) UpdateConsumer(stream string, cfg *natsgo.ConsumerConfig, opts ...natsgo.JSOpt) (*natsgo.ConsumerInfo, error) { _va := make([]interface{}, len(opts)) for _i := range opts { _va[_i] = opts[_i] @@ -2572,20 +2572,20 @@ func (_m *JetStreamContext) UpdateConsumer(stream string, cfg *nats.ConsumerConf _ca = append(_ca, _va...) ret := _m.Called(_ca...) - var r0 *nats.ConsumerInfo + var r0 *natsgo.ConsumerInfo var r1 error - if rf, ok := ret.Get(0).(func(string, *nats.ConsumerConfig, ...nats.JSOpt) (*nats.ConsumerInfo, error)); ok { + if rf, ok := ret.Get(0).(func(string, *natsgo.ConsumerConfig, ...natsgo.JSOpt) (*natsgo.ConsumerInfo, error)); ok { return rf(stream, cfg, opts...) } - if rf, ok := ret.Get(0).(func(string, *nats.ConsumerConfig, ...nats.JSOpt) *nats.ConsumerInfo); ok { + if rf, ok := ret.Get(0).(func(string, *natsgo.ConsumerConfig, ...natsgo.JSOpt) *natsgo.ConsumerInfo); ok { r0 = rf(stream, cfg, opts...) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*nats.ConsumerInfo) + r0 = ret.Get(0).(*natsgo.ConsumerInfo) } } - if rf, ok := ret.Get(1).(func(string, *nats.ConsumerConfig, ...nats.JSOpt) error); ok { + if rf, ok := ret.Get(1).(func(string, *natsgo.ConsumerConfig, ...natsgo.JSOpt) error); ok { r1 = rf(stream, cfg, opts...) } else { r1 = ret.Error(1) @@ -2601,38 +2601,38 @@ type JetStreamContext_UpdateConsumer_Call struct { // UpdateConsumer is a helper method to define mock.On call // - stream string -// - cfg *nats.ConsumerConfig -// - opts ...nats.JSOpt +// - cfg *natsgo.ConsumerConfig +// - opts ...natsgo.JSOpt func (_e *JetStreamContext_Expecter) UpdateConsumer(stream interface{}, cfg interface{}, opts ...interface{}) *JetStreamContext_UpdateConsumer_Call { return &JetStreamContext_UpdateConsumer_Call{Call: _e.mock.On("UpdateConsumer", append([]interface{}{stream, cfg}, opts...)...)} } -func (_c *JetStreamContext_UpdateConsumer_Call) Run(run func(stream string, cfg *nats.ConsumerConfig, opts ...nats.JSOpt)) *JetStreamContext_UpdateConsumer_Call { +func (_c *JetStreamContext_UpdateConsumer_Call) Run(run func(stream string, cfg *natsgo.ConsumerConfig, opts ...natsgo.JSOpt)) *JetStreamContext_UpdateConsumer_Call { _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]nats.JSOpt, len(args)-2) + variadicArgs := make([]natsgo.JSOpt, len(args)-2) for i, a := range args[2:] { if a != nil { - variadicArgs[i] = a.(nats.JSOpt) + variadicArgs[i] = a.(natsgo.JSOpt) } } - run(args[0].(string), args[1].(*nats.ConsumerConfig), variadicArgs...) + run(args[0].(string), args[1].(*natsgo.ConsumerConfig), variadicArgs...) }) return _c } -func (_c *JetStreamContext_UpdateConsumer_Call) Return(_a0 *nats.ConsumerInfo, _a1 error) *JetStreamContext_UpdateConsumer_Call { +func (_c *JetStreamContext_UpdateConsumer_Call) Return(_a0 *natsgo.ConsumerInfo, _a1 error) *JetStreamContext_UpdateConsumer_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *JetStreamContext_UpdateConsumer_Call) RunAndReturn(run func(string, *nats.ConsumerConfig, ...nats.JSOpt) (*nats.ConsumerInfo, error)) *JetStreamContext_UpdateConsumer_Call { +func (_c *JetStreamContext_UpdateConsumer_Call) RunAndReturn(run func(string, *natsgo.ConsumerConfig, ...natsgo.JSOpt) (*natsgo.ConsumerInfo, error)) *JetStreamContext_UpdateConsumer_Call { _c.Call.Return(run) return _c } // UpdateStream provides a mock function with given fields: cfg, opts -func (_m *JetStreamContext) UpdateStream(cfg *nats.StreamConfig, opts ...nats.JSOpt) (*nats.StreamInfo, error) { +func (_m *JetStreamContext) UpdateStream(cfg *natsgo.StreamConfig, opts ...natsgo.JSOpt) (*natsgo.StreamInfo, error) { _va := make([]interface{}, len(opts)) for _i := range opts { _va[_i] = opts[_i] @@ -2642,20 +2642,20 @@ func (_m *JetStreamContext) UpdateStream(cfg *nats.StreamConfig, opts ...nats.JS _ca = append(_ca, _va...) ret := _m.Called(_ca...) - var r0 *nats.StreamInfo + var r0 *natsgo.StreamInfo var r1 error - if rf, ok := ret.Get(0).(func(*nats.StreamConfig, ...nats.JSOpt) (*nats.StreamInfo, error)); ok { + if rf, ok := ret.Get(0).(func(*natsgo.StreamConfig, ...natsgo.JSOpt) (*natsgo.StreamInfo, error)); ok { return rf(cfg, opts...) } - if rf, ok := ret.Get(0).(func(*nats.StreamConfig, ...nats.JSOpt) *nats.StreamInfo); ok { + if rf, ok := ret.Get(0).(func(*natsgo.StreamConfig, ...natsgo.JSOpt) *natsgo.StreamInfo); ok { r0 = rf(cfg, opts...) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*nats.StreamInfo) + r0 = ret.Get(0).(*natsgo.StreamInfo) } } - if rf, ok := ret.Get(1).(func(*nats.StreamConfig, ...nats.JSOpt) error); ok { + if rf, ok := ret.Get(1).(func(*natsgo.StreamConfig, ...natsgo.JSOpt) error); ok { r1 = rf(cfg, opts...) } else { r1 = ret.Error(1) @@ -2670,32 +2670,32 @@ type JetStreamContext_UpdateStream_Call struct { } // UpdateStream is a helper method to define mock.On call -// - cfg *nats.StreamConfig -// - opts ...nats.JSOpt +// - cfg *natsgo.StreamConfig +// - opts ...natsgo.JSOpt func (_e *JetStreamContext_Expecter) UpdateStream(cfg interface{}, opts ...interface{}) *JetStreamContext_UpdateStream_Call { return &JetStreamContext_UpdateStream_Call{Call: _e.mock.On("UpdateStream", append([]interface{}{cfg}, opts...)...)} } -func (_c *JetStreamContext_UpdateStream_Call) Run(run func(cfg *nats.StreamConfig, opts ...nats.JSOpt)) *JetStreamContext_UpdateStream_Call { +func (_c *JetStreamContext_UpdateStream_Call) Run(run func(cfg *natsgo.StreamConfig, opts ...natsgo.JSOpt)) *JetStreamContext_UpdateStream_Call { _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]nats.JSOpt, len(args)-1) + variadicArgs := make([]natsgo.JSOpt, len(args)-1) for i, a := range args[1:] { if a != nil { - variadicArgs[i] = a.(nats.JSOpt) + variadicArgs[i] = a.(natsgo.JSOpt) } } - run(args[0].(*nats.StreamConfig), variadicArgs...) + run(args[0].(*natsgo.StreamConfig), variadicArgs...) }) return _c } -func (_c *JetStreamContext_UpdateStream_Call) Return(_a0 *nats.StreamInfo, _a1 error) *JetStreamContext_UpdateStream_Call { +func (_c *JetStreamContext_UpdateStream_Call) Return(_a0 *natsgo.StreamInfo, _a1 error) *JetStreamContext_UpdateStream_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *JetStreamContext_UpdateStream_Call) RunAndReturn(run func(*nats.StreamConfig, ...nats.JSOpt) (*nats.StreamInfo, error)) *JetStreamContext_UpdateStream_Call { +func (_c *JetStreamContext_UpdateStream_Call) RunAndReturn(run func(*natsgo.StreamConfig, ...natsgo.JSOpt) (*natsgo.StreamInfo, error)) *JetStreamContext_UpdateStream_Call { _c.Call.Return(run) return _c } diff --git a/internal/controller/nats/mocks/natsconn.go b/internal/controller/nats/mocks/natsconn.go index 78915390..cd4a99b6 100644 --- a/internal/controller/nats/mocks/natsconn.go +++ b/internal/controller/nats/mocks/natsconn.go @@ -5,7 +5,7 @@ package mocks import ( mock "github.com/stretchr/testify/mock" - nats_go "github.com/nats-io/nats.go" + natsgo "github.com/nats-io/nats.go" ) // NatsConn is an autogenerated mock type for the NatsConn type @@ -95,19 +95,19 @@ func (_c *NatsConn_IsConnected_Call) RunAndReturn(run func() bool) *NatsConn_IsC } // JetStream provides a mock function with given fields: -func (_m *NatsConn) JetStream() (nats_go.JetStreamContext, error) { +func (_m *NatsConn) JetStream() (natsgo.JetStreamContext, error) { ret := _m.Called() - var r0 nats_go.JetStreamContext + var r0 natsgo.JetStreamContext var r1 error - if rf, ok := ret.Get(0).(func() (nats_go.JetStreamContext, error)); ok { + if rf, ok := ret.Get(0).(func() (natsgo.JetStreamContext, error)); ok { return rf() } - if rf, ok := ret.Get(0).(func() nats_go.JetStreamContext); ok { + if rf, ok := ret.Get(0).(func() natsgo.JetStreamContext); ok { r0 = rf() } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(nats_go.JetStreamContext) + r0 = ret.Get(0).(natsgo.JetStreamContext) } } @@ -137,25 +137,25 @@ func (_c *NatsConn_JetStream_Call) Run(run func()) *NatsConn_JetStream_Call { return _c } -func (_c *NatsConn_JetStream_Call) Return(_a0 nats_go.JetStreamContext, _a1 error) *NatsConn_JetStream_Call { +func (_c *NatsConn_JetStream_Call) Return(_a0 natsgo.JetStreamContext, _a1 error) *NatsConn_JetStream_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *NatsConn_JetStream_Call) RunAndReturn(run func() (nats_go.JetStreamContext, error)) *NatsConn_JetStream_Call { +func (_c *NatsConn_JetStream_Call) RunAndReturn(run func() (natsgo.JetStreamContext, error)) *NatsConn_JetStream_Call { _c.Call.Return(run) return _c } // Status provides a mock function with given fields: -func (_m *NatsConn) Status() nats_go.Status { +func (_m *NatsConn) Status() natsgo.Status { ret := _m.Called() - var r0 nats_go.Status - if rf, ok := ret.Get(0).(func() nats_go.Status); ok { + var r0 natsgo.Status + if rf, ok := ret.Get(0).(func() natsgo.Status); ok { r0 = rf() } else { - r0 = ret.Get(0).(nats_go.Status) + r0 = ret.Get(0).(natsgo.Status) } return r0 @@ -178,12 +178,12 @@ func (_c *NatsConn_Status_Call) Run(run func()) *NatsConn_Status_Call { return _c } -func (_c *NatsConn_Status_Call) Return(_a0 nats_go.Status) *NatsConn_Status_Call { +func (_c *NatsConn_Status_Call) Return(_a0 natsgo.Status) *NatsConn_Status_Call { _c.Call.Return(_a0) return _c } -func (_c *NatsConn_Status_Call) RunAndReturn(run func() nats_go.Status) *NatsConn_Status_Call { +func (_c *NatsConn_Status_Call) RunAndReturn(run func() natsgo.Status) *NatsConn_Status_Call { _c.Call.Return(run) return _c } diff --git a/internal/controller/nats/provisioner.go b/internal/controller/nats/provisioner.go index d2e20c8f..742f9a40 100644 --- a/internal/controller/nats/provisioner.go +++ b/internal/controller/nats/provisioner.go @@ -5,11 +5,11 @@ import ( "time" "go.uber.org/zap" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - ctrl "sigs.k8s.io/controller-runtime" + kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + kcontrollerruntime "sigs.k8s.io/controller-runtime" - natsv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" - natsurl "github.com/kyma-project/nats-manager/internal/controller/nats/url" + nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" + nmctrlurl "github.com/kyma-project/nats-manager/internal/controller/nats/url" "github.com/kyma-project/nats-manager/pkg/events" "github.com/kyma-project/nats-manager/pkg/k8s/chart" ) @@ -17,12 +17,12 @@ import ( const RequeueTimeForStatusCheck = 10 func (r *Reconciler) handleNATSReconcile(ctx context.Context, - nats *natsv1alpha1.NATS, log *zap.SugaredLogger) (ctrl.Result, error) { + nats *nmapiv1alpha1.NATS, log *zap.SugaredLogger) (kcontrollerruntime.Result, error) { log.Info("handling NATS reconciliation...") // set status to processing nats.Status.Initialize() - events.Normal(r.recorder, nats, natsv1alpha1.ConditionReasonProcessing, "Initializing NATS resource.") + events.Normal(r.recorder, nats, nmapiv1alpha1.ConditionReasonProcessing, "Initializing NATS resource.") // make sure the finalizer exists. if !r.containsFinalizer(nats) { @@ -33,25 +33,25 @@ func (r *Reconciler) handleNATSReconcile(ctx context.Context, // init a release instance (NATS resources to deploy) instance, err := r.initNATSInstance(ctx, nats, log) if err != nil { - events.Warn(r.recorder, nats, natsv1alpha1.ConditionReasonProcessingError, + events.Warn(r.recorder, nats, nmapiv1alpha1.ConditionReasonProcessingError, "Error while NATS resources were being initialized: %s", err) - return ctrl.Result{}, r.syncNATSStatusWithErr(ctx, nats, err, log) + return kcontrollerruntime.Result{}, r.syncNATSStatusWithErr(ctx, nats, err, log) } log.Info("deploying NATS resources...") // deploy NATS resources if err = r.natsManager.DeployInstance(ctx, instance); err != nil { - events.Warn(r.recorder, nats, natsv1alpha1.ConditionReasonProcessingError, + events.Warn(r.recorder, nats, nmapiv1alpha1.ConditionReasonProcessingError, "Error while NATS resources were deployed: %s", err) - return ctrl.Result{}, r.syncNATSStatusWithErr(ctx, nats, err, log) + return kcontrollerruntime.Result{}, r.syncNATSStatusWithErr(ctx, nats, err, log) } // watchers for dynamic resources managed by controller. if instance.IstioEnabled && !r.destinationRuleWatchStarted { if err = r.watchDestinationRule(log); err != nil { - events.Warn(r.recorder, nats, natsv1alpha1.ConditionReasonProcessingError, + events.Warn(r.recorder, nats, nmapiv1alpha1.ConditionReasonProcessingError, "Error while NATS resources were watched: %s", err) - return ctrl.Result{}, r.syncNATSStatusWithErr(ctx, nats, err, log) + return kcontrollerruntime.Result{}, r.syncNATSStatusWithErr(ctx, nats, err, log) } // update flag to keep track if watcher is started. r.destinationRuleWatchStarted = true @@ -65,33 +65,33 @@ func (r *Reconciler) handleNATSReconcile(ctx context.Context, // handleNATSState checks if NATS resources are ready. // It also syncs the NATS CR status. -func (r *Reconciler) handleNATSState(ctx context.Context, nats *natsv1alpha1.NATS, instance *chart.ReleaseInstance, - log *zap.SugaredLogger) (ctrl.Result, error) { +func (r *Reconciler) handleNATSState(ctx context.Context, nats *nmapiv1alpha1.NATS, instance *chart.ReleaseInstance, + log *zap.SugaredLogger) (kcontrollerruntime.Result, error) { // Clear the url until the StatefulSet is ready. nats.Status.ClearURL() // checking if statefulSet is ready. isSTSReady, err := r.natsManager.IsNATSStatefulSetReady(ctx, instance) if err != nil { - nats.Status.UpdateConditionStatefulSet(metav1.ConditionFalse, - natsv1alpha1.ConditionReasonSyncFailError, err.Error()) - events.Warn(r.recorder, nats, natsv1alpha1.ConditionReasonSyncFailError, + nats.Status.UpdateConditionStatefulSet(kmetav1.ConditionFalse, + nmapiv1alpha1.ConditionReasonSyncFailError, err.Error()) + events.Warn(r.recorder, nats, nmapiv1alpha1.ConditionReasonSyncFailError, "Failed to sync the resources. StatefulSet is not ready.") - return ctrl.Result{}, r.syncNATSStatusWithErr(ctx, nats, err, log) + return kcontrollerruntime.Result{}, r.syncNATSStatusWithErr(ctx, nats, err, log) } if isSTSReady { nats.Status.SetStateReady() - nats.Status.SetURL(natsurl.Format(nats.Name, nats.Namespace)) - events.Normal(r.recorder, nats, natsv1alpha1.ConditionReasonDeployed, "StatefulSet is ready and NATS is deployed.") + nats.Status.SetURL(nmctrlurl.Format(nats.Name, nats.Namespace)) + events.Normal(r.recorder, nats, nmapiv1alpha1.ConditionReasonDeployed, "StatefulSet is ready and NATS is deployed.") } else { nats.Status.SetWaitingStateForStatefulSet() - events.Normal(r.recorder, nats, natsv1alpha1.ConditionReasonDeploying, + events.Normal(r.recorder, nats, nmapiv1alpha1.ConditionReasonDeploying, "NATS is being deployed, waiting for StatefulSet to get ready.") r.logger.Info("Reconciliation successful: waiting for STS to get ready...") - return ctrl.Result{RequeueAfter: RequeueTimeForStatusCheck * time.Second}, r.syncNATSStatus(ctx, nats, log) + return kcontrollerruntime.Result{RequeueAfter: RequeueTimeForStatusCheck * time.Second}, r.syncNATSStatus(ctx, nats, log) } r.logger.Info("Reconciliation successful") - return ctrl.Result{}, r.syncNATSStatus(ctx, nats, log) + return kcontrollerruntime.Result{}, r.syncNATSStatus(ctx, nats, log) } diff --git a/internal/controller/nats/provisioner_test.go b/internal/controller/nats/provisioner_test.go index 20edd12c..7fff8083 100644 --- a/internal/controller/nats/provisioner_test.go +++ b/internal/controller/nats/provisioner_test.go @@ -4,14 +4,14 @@ import ( "errors" "testing" - natsmanager "github.com/kyma-project/nats-manager/pkg/manager" + nmmgr "github.com/kyma-project/nats-manager/pkg/manager" - natsv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" + nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" "github.com/kyma-project/nats-manager/pkg/k8s/chart" "github.com/kyma-project/nats-manager/testutils" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" ) @@ -22,9 +22,9 @@ func Test_handleNATSState(t *testing.T) { testCases := []struct { name string givenStatefulSetReady bool - givenNATS *natsv1alpha1.NATS + givenNATS *nmapiv1alpha1.NATS wantState string - wantConditions []metav1.Condition + wantConditions []kmetav1.Condition wantK8sEvents []string }{ { @@ -34,20 +34,20 @@ func Test_handleNATSState(t *testing.T) { testutils.WithNATSCRName("eventing-nats"), testutils.WithNATSCRNamespace("kyma-system"), ), - wantState: natsv1alpha1.StateProcessing, - wantConditions: []metav1.Condition{ + wantState: nmapiv1alpha1.StateProcessing, + wantConditions: []kmetav1.Condition{ { - Type: string(natsv1alpha1.ConditionStatefulSet), - Status: metav1.ConditionFalse, - LastTransitionTime: metav1.Now(), - Reason: string(natsv1alpha1.ConditionReasonStatefulSetPending), + Type: string(nmapiv1alpha1.ConditionStatefulSet), + Status: kmetav1.ConditionFalse, + LastTransitionTime: kmetav1.Now(), + Reason: string(nmapiv1alpha1.ConditionReasonStatefulSetPending), Message: "", }, { - Type: string(natsv1alpha1.ConditionAvailable), - Status: metav1.ConditionFalse, - LastTransitionTime: metav1.Now(), - Reason: string(natsv1alpha1.ConditionReasonDeploying), + Type: string(nmapiv1alpha1.ConditionAvailable), + Status: kmetav1.ConditionFalse, + LastTransitionTime: kmetav1.Now(), + Reason: string(nmapiv1alpha1.ConditionReasonDeploying), Message: "", }, }, @@ -62,20 +62,20 @@ func Test_handleNATSState(t *testing.T) { testutils.WithNATSCRName("eventing-nats"), testutils.WithNATSCRNamespace("kyma-system"), ), - wantState: natsv1alpha1.StateReady, - wantConditions: []metav1.Condition{ + wantState: nmapiv1alpha1.StateReady, + wantConditions: []kmetav1.Condition{ { - Type: string(natsv1alpha1.ConditionStatefulSet), - Status: metav1.ConditionTrue, - LastTransitionTime: metav1.Now(), - Reason: string(natsv1alpha1.ConditionReasonStatefulSetAvailable), + Type: string(nmapiv1alpha1.ConditionStatefulSet), + Status: kmetav1.ConditionTrue, + LastTransitionTime: kmetav1.Now(), + Reason: string(nmapiv1alpha1.ConditionReasonStatefulSetAvailable), Message: "StatefulSet is ready", }, { - Type: string(natsv1alpha1.ConditionAvailable), - Status: metav1.ConditionTrue, - LastTransitionTime: metav1.Now(), - Reason: string(natsv1alpha1.ConditionReasonDeployed), + Type: string(nmapiv1alpha1.ConditionAvailable), + Status: kmetav1.ConditionTrue, + LastTransitionTime: kmetav1.Now(), + Reason: string(nmapiv1alpha1.ConditionReasonDeployed), Message: "NATS is deployed", }, }, @@ -112,7 +112,7 @@ func Test_handleNATSState(t *testing.T) { gotNATS, err := testEnv.GetNATS(tc.givenNATS.Name, tc.givenNATS.Namespace) require.NoError(t, err) require.Equal(t, tc.wantState, gotNATS.Status.State) - require.True(t, natsv1alpha1.ConditionsEquals(tc.wantConditions, gotNATS.Status.Conditions)) + require.True(t, nmapiv1alpha1.ConditionsEquals(tc.wantConditions, gotNATS.Status.Conditions)) // check k8s events gotEvents := testEnv.GetK8sEvents() @@ -131,11 +131,11 @@ func Test_handleNATSReconcile(t *testing.T) { testCases := []struct { name string givenStatefulSetReady bool - givenNATS *natsv1alpha1.NATS + givenNATS *nmapiv1alpha1.NATS givenDeployError error wantFinalizerCheckOnly bool wantState string - wantConditions []metav1.Condition + wantConditions []kmetav1.Condition wantK8sEvents []string wantDestinationRuleWatchStarted bool }{ @@ -146,7 +146,7 @@ func Test_handleNATSReconcile(t *testing.T) { testutils.WithNATSCRName("eventing-nats"), testutils.WithNATSCRNamespace("kyma-system"), ), - wantState: natsv1alpha1.StateProcessing, + wantState: nmapiv1alpha1.StateProcessing, wantFinalizerCheckOnly: true, wantK8sEvents: []string{"Normal Processing Initializing NATS resource."}, }, @@ -159,20 +159,20 @@ func Test_handleNATSReconcile(t *testing.T) { testutils.WithNATSCRFinalizer(NATSFinalizerName), ), givenDeployError: errors.New("deploy error"), - wantState: natsv1alpha1.StateError, - wantConditions: []metav1.Condition{ + wantState: nmapiv1alpha1.StateError, + wantConditions: []kmetav1.Condition{ { - Type: string(natsv1alpha1.ConditionStatefulSet), - Status: metav1.ConditionFalse, - LastTransitionTime: metav1.Now(), - Reason: string(natsv1alpha1.ConditionReasonSyncFailError), + Type: string(nmapiv1alpha1.ConditionStatefulSet), + Status: kmetav1.ConditionFalse, + LastTransitionTime: kmetav1.Now(), + Reason: string(nmapiv1alpha1.ConditionReasonSyncFailError), Message: "", }, { - Type: string(natsv1alpha1.ConditionAvailable), - Status: metav1.ConditionFalse, - LastTransitionTime: metav1.Now(), - Reason: string(natsv1alpha1.ConditionReasonProcessingError), + Type: string(nmapiv1alpha1.ConditionAvailable), + Status: kmetav1.ConditionFalse, + LastTransitionTime: kmetav1.Now(), + Reason: string(nmapiv1alpha1.ConditionReasonProcessingError), Message: "deploy error", }, }, @@ -190,20 +190,20 @@ func Test_handleNATSReconcile(t *testing.T) { testutils.WithNATSCRFinalizer(NATSFinalizerName), ), givenDeployError: nil, - wantState: natsv1alpha1.StateReady, - wantConditions: []metav1.Condition{ + wantState: nmapiv1alpha1.StateReady, + wantConditions: []kmetav1.Condition{ { - Type: string(natsv1alpha1.ConditionStatefulSet), - Status: metav1.ConditionTrue, - LastTransitionTime: metav1.Now(), - Reason: string(natsv1alpha1.ConditionReasonStatefulSetAvailable), + Type: string(nmapiv1alpha1.ConditionStatefulSet), + Status: kmetav1.ConditionTrue, + LastTransitionTime: kmetav1.Now(), + Reason: string(nmapiv1alpha1.ConditionReasonStatefulSetAvailable), Message: "StatefulSet is ready", }, { - Type: string(natsv1alpha1.ConditionAvailable), - Status: metav1.ConditionTrue, - LastTransitionTime: metav1.Now(), - Reason: string(natsv1alpha1.ConditionReasonDeployed), + Type: string(nmapiv1alpha1.ConditionAvailable), + Status: kmetav1.ConditionTrue, + LastTransitionTime: kmetav1.Now(), + Reason: string(nmapiv1alpha1.ConditionReasonDeployed), Message: "NATS is deployed", }, }, @@ -221,20 +221,20 @@ func Test_handleNATSReconcile(t *testing.T) { testutils.WithNATSCRFinalizer(NATSFinalizerName), ), givenDeployError: nil, - wantState: natsv1alpha1.StateReady, - wantConditions: []metav1.Condition{ + wantState: nmapiv1alpha1.StateReady, + wantConditions: []kmetav1.Condition{ { - Type: string(natsv1alpha1.ConditionStatefulSet), - Status: metav1.ConditionTrue, - LastTransitionTime: metav1.Now(), - Reason: string(natsv1alpha1.ConditionReasonStatefulSetAvailable), + Type: string(nmapiv1alpha1.ConditionStatefulSet), + Status: kmetav1.ConditionTrue, + LastTransitionTime: kmetav1.Now(), + Reason: string(nmapiv1alpha1.ConditionReasonStatefulSetAvailable), Message: "StatefulSet is ready", }, { - Type: string(natsv1alpha1.ConditionAvailable), - Status: metav1.ConditionTrue, - LastTransitionTime: metav1.Now(), - Reason: string(natsv1alpha1.ConditionReasonDeployed), + Type: string(nmapiv1alpha1.ConditionAvailable), + Status: kmetav1.ConditionTrue, + LastTransitionTime: kmetav1.Now(), + Reason: string(nmapiv1alpha1.ConditionReasonDeployed), Message: "NATS is deployed", }, }, @@ -283,8 +283,8 @@ func Test_handleNATSReconcile(t *testing.T) { testEnv.natsManager.On("GenerateOverrides", mock.Anything, mock.Anything, mock.Anything).Return( map[string]interface{}{ - natsmanager.IstioEnabledKey: tc.wantDestinationRuleWatchStarted, - natsmanager.RotatePasswordKey: true, // do not recreate secret if it exists + nmmgr.IstioEnabledKey: tc.wantDestinationRuleWatchStarted, + nmmgr.RotatePasswordKey: true, // do not recreate secret if it exists }, ) if tc.wantDestinationRuleWatchStarted { @@ -319,7 +319,7 @@ func Test_handleNATSReconcile(t *testing.T) { require.Equal(t, tc.wantK8sEvents, gotEvents) // check further - require.True(t, natsv1alpha1.ConditionsEquals(tc.wantConditions, gotNATS.Status.Conditions)) + require.True(t, nmapiv1alpha1.ConditionsEquals(tc.wantConditions, gotNATS.Status.Conditions)) }) } } diff --git a/internal/controller/nats/status.go b/internal/controller/nats/status.go index be9f2290..e93b06b1 100644 --- a/internal/controller/nats/status.go +++ b/internal/controller/nats/status.go @@ -4,12 +4,12 @@ import ( "context" "errors" - natsv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" + nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" "github.com/kyma-project/nats-manager/pkg/k8s" "go.uber.org/zap" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - k8stype "k8s.io/apimachinery/pkg/types" + ktypes "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/event" "sigs.k8s.io/controller-runtime/pkg/handler" "sigs.k8s.io/controller-runtime/pkg/predicate" @@ -19,10 +19,10 @@ import ( // syncNATSStatus syncs NATS status. // Returns the relevant error. func (r *Reconciler) syncNATSStatusWithErr(ctx context.Context, - nats *natsv1alpha1.NATS, err error, log *zap.SugaredLogger) error { + nats *nmapiv1alpha1.NATS, err error, log *zap.SugaredLogger) error { // set error state in status nats.Status.SetStateError() - nats.Status.UpdateConditionAvailable(metav1.ConditionFalse, natsv1alpha1.ConditionReasonProcessingError, err.Error()) + nats.Status.UpdateConditionAvailable(kmetav1.ConditionFalse, nmapiv1alpha1.ConditionReasonProcessingError, err.Error()) // return the original error so the controller triggers another reconciliation. return errors.Join(err, r.syncNATSStatus(ctx, nats, log)) @@ -30,14 +30,14 @@ func (r *Reconciler) syncNATSStatusWithErr(ctx context.Context, // syncNATSStatus syncs NATS status. func (r *Reconciler) syncNATSStatus(ctx context.Context, - nats *natsv1alpha1.NATS, log *zap.SugaredLogger) error { - namespacedName := &k8stype.NamespacedName{ + nats *nmapiv1alpha1.NATS, log *zap.SugaredLogger) error { + namespacedName := &ktypes.NamespacedName{ Name: nats.Name, Namespace: nats.Namespace, } // fetch the latest NATS object, to avoid k8s conflict errors. - actualNATS := &natsv1alpha1.NATS{} + actualNATS := &nmapiv1alpha1.NATS{} if err := r.Client.Get(ctx, *namespacedName, actualNATS); err != nil { return err } @@ -51,7 +51,7 @@ func (r *Reconciler) syncNATSStatus(ctx context.Context, } // updateStatus updates the status to k8s if modified. -func (r *Reconciler) updateStatus(ctx context.Context, oldNATS, newNATS *natsv1alpha1.NATS, +func (r *Reconciler) updateStatus(ctx context.Context, oldNATS, newNATS *nmapiv1alpha1.NATS, logger *zap.SugaredLogger) error { // compare the status taking into consideration lastTransitionTime in conditions if oldNATS.Status.IsEqual(newNATS.Status) { @@ -82,7 +82,7 @@ func (r *Reconciler) watchDestinationRule(logger *zap.SugaredLogger) error { // define label selector for "managed-by". labelSelectorPredicate, err := predicate.LabelSelectorPredicate( - metav1.LabelSelector{ + kmetav1.LabelSelector{ MatchLabels: map[string]string{ ManagedByLabelKey: ManagedByLabelValue, }, @@ -104,7 +104,7 @@ func (r *Reconciler) watchDestinationRule(logger *zap.SugaredLogger) error { return r.controller.Watch( source.Kind(r.ctrlManager.GetCache(), destinationRuleType), handler.EnqueueRequestForOwner(r.scheme, r.ctrlManager.GetRESTMapper(), - &natsv1alpha1.NATS{}, handler.OnlyControllerOwner()), + &nmapiv1alpha1.NATS{}, handler.OnlyControllerOwner()), labelSelectorPredicate, predicate.ResourceVersionChangedPredicate{}, ignoreCreationPredicate, diff --git a/internal/controller/nats/status_test.go b/internal/controller/nats/status_test.go index e957b72f..c5ce6527 100644 --- a/internal/controller/nats/status_test.go +++ b/internal/controller/nats/status_test.go @@ -10,10 +10,10 @@ import ( "sigs.k8s.io/controller-runtime/pkg/predicate" "sigs.k8s.io/controller-runtime/pkg/source" - natsv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" + nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" "github.com/kyma-project/nats-manager/testutils" "github.com/stretchr/testify/require" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) func Test_syncNATSStatus(t *testing.T) { @@ -22,8 +22,8 @@ func Test_syncNATSStatus(t *testing.T) { // define test cases testCases := []struct { name string - givenNATS *natsv1alpha1.NATS - wantNATSStatus natsv1alpha1.NATSStatus + givenNATS *nmapiv1alpha1.NATS + wantNATSStatus nmapiv1alpha1.NATSStatus wantResult bool }{ { @@ -32,21 +32,21 @@ func Test_syncNATSStatus(t *testing.T) { testutils.WithNATSCRStatusInitialized(), testutils.WithNATSStateProcessing(), ), - wantNATSStatus: natsv1alpha1.NATSStatus{ - State: natsv1alpha1.StateReady, - Conditions: []metav1.Condition{ + wantNATSStatus: nmapiv1alpha1.NATSStatus{ + State: nmapiv1alpha1.StateReady, + Conditions: []kmetav1.Condition{ { - Type: string(natsv1alpha1.ConditionStatefulSet), - Status: metav1.ConditionTrue, - LastTransitionTime: metav1.Now(), - Reason: string(natsv1alpha1.ConditionReasonProcessing), + Type: string(nmapiv1alpha1.ConditionStatefulSet), + Status: kmetav1.ConditionTrue, + LastTransitionTime: kmetav1.Now(), + Reason: string(nmapiv1alpha1.ConditionReasonProcessing), Message: "", }, { - Type: string(natsv1alpha1.ConditionAvailable), - Status: metav1.ConditionTrue, - LastTransitionTime: metav1.Now(), - Reason: string(natsv1alpha1.ConditionReasonProcessing), + Type: string(nmapiv1alpha1.ConditionAvailable), + Status: kmetav1.ConditionTrue, + LastTransitionTime: kmetav1.Now(), + Reason: string(nmapiv1alpha1.ConditionReasonProcessing), Message: "", }, }, @@ -86,9 +86,9 @@ func Test_syncNATSStatusWithErr(t *testing.T) { // define test cases testCases := []struct { name string - givenNATS *natsv1alpha1.NATS + givenNATS *nmapiv1alpha1.NATS givenError error - wantNATSStatus natsv1alpha1.NATSStatus + wantNATSStatus nmapiv1alpha1.NATSStatus wantResult bool }{ { @@ -98,21 +98,21 @@ func Test_syncNATSStatusWithErr(t *testing.T) { testutils.WithNATSStateProcessing(), ), givenError: errors.New("test error"), - wantNATSStatus: natsv1alpha1.NATSStatus{ - State: natsv1alpha1.StateError, - Conditions: []metav1.Condition{ + wantNATSStatus: nmapiv1alpha1.NATSStatus{ + State: nmapiv1alpha1.StateError, + Conditions: []kmetav1.Condition{ { - Type: string(natsv1alpha1.ConditionStatefulSet), - Status: metav1.ConditionFalse, - LastTransitionTime: metav1.Now(), - Reason: string(natsv1alpha1.ConditionReasonSyncFailError), + Type: string(nmapiv1alpha1.ConditionStatefulSet), + Status: kmetav1.ConditionFalse, + LastTransitionTime: kmetav1.Now(), + Reason: string(nmapiv1alpha1.ConditionReasonSyncFailError), Message: "", }, { - Type: string(natsv1alpha1.ConditionAvailable), - Status: metav1.ConditionFalse, - LastTransitionTime: metav1.Now(), - Reason: string(natsv1alpha1.ConditionReasonProcessingError), + Type: string(nmapiv1alpha1.ConditionAvailable), + Status: kmetav1.ConditionFalse, + LastTransitionTime: kmetav1.Now(), + Reason: string(nmapiv1alpha1.ConditionReasonProcessingError), Message: "test error", }, }, @@ -141,7 +141,7 @@ func Test_syncNATSStatusWithErr(t *testing.T) { // the original error should have being returned. require.Error(t, err) require.Equal(t, tc.givenError.Error(), err.Error()) - // now check if the error is refelcted in the CR status. + // now check if the error is reflected in the CR status. gotNats, err := testEnv.GetNATS(tc.givenNATS.GetName(), tc.givenNATS.GetNamespace()) require.NoError(t, err) require.True(t, gotNats.Status.IsEqual(tc.wantNATSStatus)) @@ -155,8 +155,8 @@ func Test_updateStatus(t *testing.T) { // define test cases testCases := []struct { name string - givenNATS *natsv1alpha1.NATS - wantNATSStatus natsv1alpha1.NATSStatus + givenNATS *nmapiv1alpha1.NATS + wantNATSStatus nmapiv1alpha1.NATSStatus wantResult bool }{ { @@ -165,21 +165,21 @@ func Test_updateStatus(t *testing.T) { testutils.WithNATSCRStatusInitialized(), testutils.WithNATSStateProcessing(), ), - wantNATSStatus: natsv1alpha1.NATSStatus{ - State: natsv1alpha1.StateReady, - Conditions: []metav1.Condition{ + wantNATSStatus: nmapiv1alpha1.NATSStatus{ + State: nmapiv1alpha1.StateReady, + Conditions: []kmetav1.Condition{ { - Type: string(natsv1alpha1.ConditionStatefulSet), - Status: metav1.ConditionTrue, - LastTransitionTime: metav1.Now(), - Reason: string(natsv1alpha1.ConditionReasonProcessing), + Type: string(nmapiv1alpha1.ConditionStatefulSet), + Status: kmetav1.ConditionTrue, + LastTransitionTime: kmetav1.Now(), + Reason: string(nmapiv1alpha1.ConditionReasonProcessing), Message: "", }, { - Type: string(natsv1alpha1.ConditionAvailable), - Status: metav1.ConditionTrue, - LastTransitionTime: metav1.Now(), - Reason: string(natsv1alpha1.ConditionReasonProcessing), + Type: string(nmapiv1alpha1.ConditionAvailable), + Status: kmetav1.ConditionTrue, + LastTransitionTime: kmetav1.Now(), + Reason: string(nmapiv1alpha1.ConditionReasonProcessing), Message: "", }, }, diff --git a/internal/controller/nats/unit_test.go b/internal/controller/nats/unit_test.go index 099df07a..fa136e55 100644 --- a/internal/controller/nats/unit_test.go +++ b/internal/controller/nats/unit_test.go @@ -4,20 +4,20 @@ import ( "context" "testing" - corev1 "k8s.io/api/core/v1" + kcorev1 "k8s.io/api/core/v1" - ctrlmocks "github.com/kyma-project/nats-manager/internal/controller/nats/mocks" + nmctrlmocks "github.com/kyma-project/nats-manager/internal/controller/nats/mocks" "k8s.io/apimachinery/pkg/runtime" - natsv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" - chartmocks "github.com/kyma-project/nats-manager/pkg/k8s/chart/mocks" - k8smocks "github.com/kyma-project/nats-manager/pkg/k8s/mocks" - managermocks "github.com/kyma-project/nats-manager/pkg/manager/mocks" + nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" + nmkchartmocks "github.com/kyma-project/nats-manager/pkg/k8s/chart/mocks" + nmkmocks "github.com/kyma-project/nats-manager/pkg/k8s/mocks" + nmmgrmocks "github.com/kyma-project/nats-manager/pkg/manager/mocks" "github.com/kyma-project/nats-manager/testutils" "github.com/stretchr/testify/require" "go.uber.org/zap" - "k8s.io/apimachinery/pkg/types" + ktypes "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/tools/record" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/fake" @@ -27,12 +27,12 @@ import ( type MockedUnitTestEnvironment struct { Context context.Context Client client.Client - kubeClient *k8smocks.Client - chartRenderer *chartmocks.Renderer - natsManager *managermocks.Manager - ctrlManager *ctrlmocks.Manager + kubeClient *nmkmocks.Client + chartRenderer *nmkchartmocks.Renderer + natsManager *nmmgrmocks.Manager + ctrlManager *nmctrlmocks.Manager Reconciler *Reconciler - controller *ctrlmocks.Controller + controller *nmctrlmocks.Controller Logger *zap.SugaredLogger Recorder *record.FakeRecorder } @@ -47,20 +47,20 @@ func NewMockedUnitTestEnvironment(t *testing.T, objs ...client.Object) *MockedUn // setup fake client for k8s newScheme := runtime.NewScheme() - err = natsv1alpha1.AddToScheme(newScheme) + err = nmapiv1alpha1.AddToScheme(newScheme) require.NoError(t, err) - err = corev1.AddToScheme(newScheme) + err = kcorev1.AddToScheme(newScheme) require.NoError(t, err) fakeClientBuilder := fake.NewClientBuilder().WithScheme(newScheme) fakeClient := fakeClientBuilder.WithObjects(objs...).WithStatusSubresource(objs...).Build() recorder := record.NewFakeRecorder(3) // setup custom mocks - chartRenderer := new(chartmocks.Renderer) - kubeClient := new(k8smocks.Client) - natsManager := new(managermocks.Manager) - mockController := new(ctrlmocks.Controller) - mockManager := new(ctrlmocks.Manager) + chartRenderer := new(nmkchartmocks.Renderer) + kubeClient := new(nmkmocks.Client) + natsManager := new(nmmgrmocks.Manager) + mockController := new(nmctrlmocks.Controller) + mockManager := new(nmctrlmocks.Manager) // setup reconciler reconciler := NewReconciler( @@ -90,9 +90,9 @@ func NewMockedUnitTestEnvironment(t *testing.T, objs ...client.Object) *MockedUn } } -func (testEnv *MockedUnitTestEnvironment) GetNATS(name, namespace string) (natsv1alpha1.NATS, error) { - var nats natsv1alpha1.NATS - err := testEnv.Client.Get(testEnv.Context, types.NamespacedName{ +func (testEnv *MockedUnitTestEnvironment) GetNATS(name, namespace string) (nmapiv1alpha1.NATS, error) { + var nats nmapiv1alpha1.NATS + err := testEnv.Client.Get(testEnv.Context, ktypes.NamespacedName{ Name: name, Namespace: namespace, }, &nats) diff --git a/internal/controller/nats/utils.go b/internal/controller/nats/utils.go index 5a0e2152..3120cd93 100644 --- a/internal/controller/nats/utils.go +++ b/internal/controller/nats/utils.go @@ -3,28 +3,28 @@ package nats import ( "context" - natsv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" - ctrl "sigs.k8s.io/controller-runtime" + nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" + kcontrollerruntime "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" ) -func (r *Reconciler) containsFinalizer(nats *natsv1alpha1.NATS) bool { +func (r *Reconciler) containsFinalizer(nats *nmapiv1alpha1.NATS) bool { return controllerutil.ContainsFinalizer(nats, NATSFinalizerName) } -func (r *Reconciler) addFinalizer(ctx context.Context, nats *natsv1alpha1.NATS) (ctrl.Result, error) { +func (r *Reconciler) addFinalizer(ctx context.Context, nats *nmapiv1alpha1.NATS) (kcontrollerruntime.Result, error) { controllerutil.AddFinalizer(nats, NATSFinalizerName) if err := r.Update(ctx, nats); err != nil { - return ctrl.Result{}, err + return kcontrollerruntime.Result{}, err } - return ctrl.Result{}, nil + return kcontrollerruntime.Result{}, nil } -func (r *Reconciler) removeFinalizer(ctx context.Context, nats *natsv1alpha1.NATS) (ctrl.Result, error) { +func (r *Reconciler) removeFinalizer(ctx context.Context, nats *nmapiv1alpha1.NATS) (kcontrollerruntime.Result, error) { controllerutil.RemoveFinalizer(nats, NATSFinalizerName) if err := r.Update(ctx, nats); err != nil { - return ctrl.Result{}, err + return kcontrollerruntime.Result{}, err } - return ctrl.Result{}, nil + return kcontrollerruntime.Result{}, nil } diff --git a/internal/controller/nats/utils_test.go b/internal/controller/nats/utils_test.go index 33f53908..56889fc9 100644 --- a/internal/controller/nats/utils_test.go +++ b/internal/controller/nats/utils_test.go @@ -4,7 +4,7 @@ import ( "context" "testing" - natsv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" + nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" "github.com/kyma-project/nats-manager/testutils" "github.com/stretchr/testify/require" ) @@ -15,7 +15,7 @@ func Test_containsFinalizer(t *testing.T) { // define test cases testCases := []struct { name string - givenNats *natsv1alpha1.NATS + givenNats *nmapiv1alpha1.NATS wantResult bool }{ { diff --git a/pkg/events/events.go b/pkg/events/events.go index 90d5dbd3..8fc4196d 100644 --- a/pkg/events/events.go +++ b/pkg/events/events.go @@ -1,20 +1,20 @@ package events import ( - natsv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" - corev1 "k8s.io/api/core/v1" + nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" + kcorev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/tools/record" ) // Normal records a normal event for an API object. -func Normal(recorder record.EventRecorder, obj runtime.Object, rn natsv1alpha1.ConditionReason, msgFmt string, +func Normal(recorder record.EventRecorder, obj runtime.Object, rn nmapiv1alpha1.ConditionReason, msgFmt string, args ...interface{}) { - recorder.Eventf(obj, corev1.EventTypeNormal, string(rn), msgFmt, args...) + recorder.Eventf(obj, kcorev1.EventTypeNormal, string(rn), msgFmt, args...) } // Warn records a warning event for an API object. -func Warn(recorder record.EventRecorder, obj runtime.Object, rn natsv1alpha1.ConditionReason, msgFmt string, +func Warn(recorder record.EventRecorder, obj runtime.Object, rn nmapiv1alpha1.ConditionReason, msgFmt string, args ...interface{}) { - recorder.Eventf(obj, corev1.EventTypeWarning, string(rn), msgFmt, args...) + recorder.Eventf(obj, kcorev1.EventTypeWarning, string(rn), msgFmt, args...) } diff --git a/pkg/k8s/chart/utils.go b/pkg/k8s/chart/utils.go index aa14d99e..6ad4049c 100644 --- a/pkg/k8s/chart/utils.go +++ b/pkg/k8s/chart/utils.go @@ -9,7 +9,7 @@ import ( "strings" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - yamlUtil "k8s.io/apimachinery/pkg/util/yaml" + kutilyaml "k8s.io/apimachinery/pkg/util/yaml" "sigs.k8s.io/yaml" ) @@ -19,7 +19,7 @@ func IsStatefulSetObject(u unstructured.Unstructured) bool { func ParseManifestStringToObjects(manifest string) (*ManifestResources, error) { objects := &ManifestResources{} - reader := yamlUtil.NewYAMLReader(bufio.NewReader(strings.NewReader(manifest))) + reader := kutilyaml.NewYAMLReader(bufio.NewReader(strings.NewReader(manifest))) for { rawBytes, err := reader.Read() if err != nil { diff --git a/pkg/k8s/client.go b/pkg/k8s/client.go index f7117a1e..ed28f674 100644 --- a/pkg/k8s/client.go +++ b/pkg/k8s/client.go @@ -4,15 +4,15 @@ import ( "context" "strings" - appsv1 "k8s.io/api/apps/v1" - apiv1 "k8s.io/api/core/v1" - apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + kappsv1 "k8s.io/api/apps/v1" + kcorev1 "k8s.io/api/core/v1" + kapiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" + kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" - k8sclientset "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset" + kapiextclientset "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - k8stypes "k8s.io/apimachinery/pkg/types" + ktypes "k8s.io/apimachinery/pkg/types" "k8s.io/utils/ptr" "sigs.k8s.io/controller-runtime/pkg/client" ) @@ -23,21 +23,21 @@ var _ Client = &KubeClient{} //go:generate go run github.com/vektra/mockery/v2 --name=Client --outpkg=mocks --case=underscore type Client interface { PatchApply(context.Context, *unstructured.Unstructured) error - GetStatefulSet(context.Context, string, string) (*appsv1.StatefulSet, error) + GetStatefulSet(context.Context, string, string) (*kappsv1.StatefulSet, error) Delete(context.Context, *unstructured.Unstructured) error - GetSecret(context.Context, string, string) (*apiv1.Secret, error) - GetCRD(context.Context, string) (*apiextensionsv1.CustomResourceDefinition, error) + GetSecret(context.Context, string, string) (*kcorev1.Secret, error) + GetCRD(context.Context, string) (*kapiextv1.CustomResourceDefinition, error) DestinationRuleCRDExists(context.Context) (bool, error) DeletePVCsWithLabel(context.Context, string, string, string) error } type KubeClient struct { client client.Client - clientset k8sclientset.Interface + clientset kapiextclientset.Interface fieldManager string } -func NewKubeClient(client client.Client, clientset k8sclientset.Interface, fieldManager string) Client { +func NewKubeClient(client client.Client, clientset kapiextclientset.Interface, fieldManager string) Client { return &KubeClient{ client: client, clientset: clientset, @@ -56,32 +56,32 @@ func (c *KubeClient) Delete(ctx context.Context, object *unstructured.Unstructur return client.IgnoreNotFound(c.client.Delete(ctx, object)) } -func (c *KubeClient) GetStatefulSet(ctx context.Context, name, namespace string) (*appsv1.StatefulSet, error) { - nn := k8stypes.NamespacedName{ +func (c *KubeClient) GetStatefulSet(ctx context.Context, name, namespace string) (*kappsv1.StatefulSet, error) { + nn := ktypes.NamespacedName{ Name: name, Namespace: namespace, } - result := &appsv1.StatefulSet{} + result := &kappsv1.StatefulSet{} if err := c.client.Get(ctx, nn, result); err != nil { return nil, err } return result, nil } -func (c *KubeClient) GetSecret(ctx context.Context, name, namespace string) (*apiv1.Secret, error) { - nn := k8stypes.NamespacedName{ +func (c *KubeClient) GetSecret(ctx context.Context, name, namespace string) (*kcorev1.Secret, error) { + nn := ktypes.NamespacedName{ Name: name, Namespace: namespace, } - result := &apiv1.Secret{} + result := &kcorev1.Secret{} if err := c.client.Get(ctx, nn, result); err != nil { return nil, err } return result, nil } -func (c *KubeClient) GetCRD(ctx context.Context, name string) (*apiextensionsv1.CustomResourceDefinition, error) { - return c.clientset.ApiextensionsV1().CustomResourceDefinitions().Get(ctx, name, metav1.GetOptions{}) +func (c *KubeClient) GetCRD(ctx context.Context, name string) (*kapiextv1.CustomResourceDefinition, error) { + return c.clientset.ApiextensionsV1().CustomResourceDefinitions().Get(ctx, name, kmetav1.GetOptions{}) } func (c *KubeClient) DestinationRuleCRDExists(ctx context.Context) (bool, error) { @@ -100,7 +100,7 @@ func (c *KubeClient) DeletePVCsWithLabel(ctx context.Context, labelSelector stri return err } - pvcList := &apiv1.PersistentVolumeClaimList{} + pvcList := &kcorev1.PersistentVolumeClaimList{} if err = c.client.List(ctx, pvcList, &client.ListOptions{ Namespace: namespace, LabelSelector: selector, diff --git a/pkg/k8s/client_test.go b/pkg/k8s/client_test.go index 12ac8e2d..7ee0538e 100644 --- a/pkg/k8s/client_test.go +++ b/pkg/k8s/client_test.go @@ -6,12 +6,12 @@ import ( "github.com/kyma-project/nats-manager/testutils" "github.com/stretchr/testify/require" - apiv1 "k8s.io/api/core/v1" - apiclientsetfake "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/fake" - k8serrors "k8s.io/apimachinery/pkg/api/errors" + kcorev1 "k8s.io/api/core/v1" + kapiextclientsetfake "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/fake" + kapierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/types" + ktypes "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/fake" ) @@ -63,7 +63,7 @@ func Test_GetStatefulSet(t *testing.T) { // then if tc.wantNotFoundError { require.Error(t, err) - require.True(t, k8serrors.IsNotFound(err)) + require.True(t, kapierrors.IsNotFound(err)) } else { require.NoError(t, err) require.Equal(t, tc.givenStatefulSet.GetName(), gotSTS.Name) @@ -116,7 +116,7 @@ func Test_GetSecret(t *testing.T) { // then if tc.wantNotFoundError { require.Error(t, err) - require.True(t, k8serrors.IsNotFound(err)) + require.True(t, kapierrors.IsNotFound(err)) } else { require.NoError(t, err) require.Equal(t, tc.givenSecret.GetName(), gotSecret.Name) @@ -171,7 +171,7 @@ func Test_Delete(t *testing.T) { gotSTS, err := kubeClient.GetStatefulSet(context.Background(), tc.givenStatefulSet.GetName(), tc.givenStatefulSet.GetNamespace()) require.Error(t, err) - require.True(t, k8serrors.IsNotFound(err)) + require.True(t, kapierrors.IsNotFound(err)) require.Nil(t, gotSTS) }) } @@ -272,7 +272,7 @@ func Test_GetCRD(t *testing.T) { objs = append(objs, sampleCRD) } - fakeClientSet := apiclientsetfake.NewSimpleClientset(objs...) + fakeClientSet := kapiextclientsetfake.NewSimpleClientset(objs...) kubeClient := NewKubeClient(nil, fakeClientSet, testFieldManager) // when @@ -281,7 +281,7 @@ func Test_GetCRD(t *testing.T) { // then if tc.wantNotFoundError { require.Error(t, err) - require.True(t, k8serrors.IsNotFound(err)) + require.True(t, kapierrors.IsNotFound(err)) } else { require.NoError(t, err) require.Equal(t, sampleCRD.GetName(), gotCRD.Name) @@ -321,7 +321,7 @@ func Test_DestinationRuleCRDExists(t *testing.T) { objs = append(objs, sampleCRD) } - fakeClientSet := apiclientsetfake.NewSimpleClientset(objs...) + fakeClientSet := kapiextclientsetfake.NewSimpleClientset(objs...) kubeClient := NewKubeClient(nil, fakeClientSet, testFieldManager) // when @@ -342,7 +342,7 @@ func Test_DeletePVCsWithLabel(t *testing.T) { mustHaveNamePrefix string labelSelector string namespace string - givenPVC *apiv1.PersistentVolumeClaim + givenPVC *kcorev1.PersistentVolumeClaim wantNotFoundErr bool }{ { @@ -409,9 +409,9 @@ func Test_DeletePVCsWithLabel(t *testing.T) { } // check that the PVCs were deleted err = fakeClient.Get(context.Background(), - types.NamespacedName{Name: tc.givenPVC.Name, Namespace: tc.givenPVC.Namespace}, tc.givenPVC) + ktypes.NamespacedName{Name: tc.givenPVC.Name, Namespace: tc.givenPVC.Namespace}, tc.givenPVC) if tc.wantNotFoundErr { - require.True(t, k8serrors.IsNotFound(err)) + require.True(t, kapierrors.IsNotFound(err)) } else { require.NoError(t, err) } diff --git a/pkg/k8s/mocks/client.go b/pkg/k8s/mocks/client.go index 57591d66..1e472811 100644 --- a/pkg/k8s/mocks/client.go +++ b/pkg/k8s/mocks/client.go @@ -5,15 +5,15 @@ package mocks import ( context "context" - appsv1 "k8s.io/api/apps/v1" + kappsv1 "k8s.io/api/apps/v1" - corev1 "k8s.io/api/core/v1" + kcorev1 "k8s.io/api/core/v1" mock "github.com/stretchr/testify/mock" unstructured "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - v1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" + kapiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" ) // Client is an autogenerated mock type for the Client type @@ -182,23 +182,23 @@ func (_c *Client_DestinationRuleCRDExists_Call) RunAndReturn(run func(context.Co } // GetCRD provides a mock function with given fields: _a0, _a1 -func (_m *Client) GetCRD(_a0 context.Context, _a1 string) (*v1.CustomResourceDefinition, error) { +func (_m *Client) GetCRD(_a0 context.Context, _a1 string) (*kapiextv1.CustomResourceDefinition, error) { ret := _m.Called(_a0, _a1) if len(ret) == 0 { panic("no return value specified for GetCRD") } - var r0 *v1.CustomResourceDefinition + var r0 *kapiextv1.CustomResourceDefinition var r1 error - if rf, ok := ret.Get(0).(func(context.Context, string) (*v1.CustomResourceDefinition, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, string) (*kapiextv1.CustomResourceDefinition, error)); ok { return rf(_a0, _a1) } - if rf, ok := ret.Get(0).(func(context.Context, string) *v1.CustomResourceDefinition); ok { + if rf, ok := ret.Get(0).(func(context.Context, string) *kapiextv1.CustomResourceDefinition); ok { r0 = rf(_a0, _a1) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*v1.CustomResourceDefinition) + r0 = ret.Get(0).(*kapiextv1.CustomResourceDefinition) } } @@ -230,34 +230,34 @@ func (_c *Client_GetCRD_Call) Run(run func(_a0 context.Context, _a1 string)) *Cl return _c } -func (_c *Client_GetCRD_Call) Return(_a0 *v1.CustomResourceDefinition, _a1 error) *Client_GetCRD_Call { +func (_c *Client_GetCRD_Call) Return(_a0 *kapiextv1.CustomResourceDefinition, _a1 error) *Client_GetCRD_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *Client_GetCRD_Call) RunAndReturn(run func(context.Context, string) (*v1.CustomResourceDefinition, error)) *Client_GetCRD_Call { +func (_c *Client_GetCRD_Call) RunAndReturn(run func(context.Context, string) (*kapiextv1.CustomResourceDefinition, error)) *Client_GetCRD_Call { _c.Call.Return(run) return _c } // GetSecret provides a mock function with given fields: _a0, _a1, _a2 -func (_m *Client) GetSecret(_a0 context.Context, _a1 string, _a2 string) (*corev1.Secret, error) { +func (_m *Client) GetSecret(_a0 context.Context, _a1 string, _a2 string) (*kcorev1.Secret, error) { ret := _m.Called(_a0, _a1, _a2) if len(ret) == 0 { panic("no return value specified for GetSecret") } - var r0 *corev1.Secret + var r0 *kcorev1.Secret var r1 error - if rf, ok := ret.Get(0).(func(context.Context, string, string) (*corev1.Secret, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, string, string) (*kcorev1.Secret, error)); ok { return rf(_a0, _a1, _a2) } - if rf, ok := ret.Get(0).(func(context.Context, string, string) *corev1.Secret); ok { + if rf, ok := ret.Get(0).(func(context.Context, string, string) *kcorev1.Secret); ok { r0 = rf(_a0, _a1, _a2) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*corev1.Secret) + r0 = ret.Get(0).(*kcorev1.Secret) } } @@ -290,34 +290,34 @@ func (_c *Client_GetSecret_Call) Run(run func(_a0 context.Context, _a1 string, _ return _c } -func (_c *Client_GetSecret_Call) Return(_a0 *corev1.Secret, _a1 error) *Client_GetSecret_Call { +func (_c *Client_GetSecret_Call) Return(_a0 *kcorev1.Secret, _a1 error) *Client_GetSecret_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *Client_GetSecret_Call) RunAndReturn(run func(context.Context, string, string) (*corev1.Secret, error)) *Client_GetSecret_Call { +func (_c *Client_GetSecret_Call) RunAndReturn(run func(context.Context, string, string) (*kcorev1.Secret, error)) *Client_GetSecret_Call { _c.Call.Return(run) return _c } // GetStatefulSet provides a mock function with given fields: _a0, _a1, _a2 -func (_m *Client) GetStatefulSet(_a0 context.Context, _a1 string, _a2 string) (*appsv1.StatefulSet, error) { +func (_m *Client) GetStatefulSet(_a0 context.Context, _a1 string, _a2 string) (*kappsv1.StatefulSet, error) { ret := _m.Called(_a0, _a1, _a2) if len(ret) == 0 { panic("no return value specified for GetStatefulSet") } - var r0 *appsv1.StatefulSet + var r0 *kappsv1.StatefulSet var r1 error - if rf, ok := ret.Get(0).(func(context.Context, string, string) (*appsv1.StatefulSet, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, string, string) (*kappsv1.StatefulSet, error)); ok { return rf(_a0, _a1, _a2) } - if rf, ok := ret.Get(0).(func(context.Context, string, string) *appsv1.StatefulSet); ok { + if rf, ok := ret.Get(0).(func(context.Context, string, string) *kappsv1.StatefulSet); ok { r0 = rf(_a0, _a1, _a2) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*appsv1.StatefulSet) + r0 = ret.Get(0).(*kappsv1.StatefulSet) } } @@ -350,12 +350,12 @@ func (_c *Client_GetStatefulSet_Call) Run(run func(_a0 context.Context, _a1 stri return _c } -func (_c *Client_GetStatefulSet_Call) Return(_a0 *appsv1.StatefulSet, _a1 error) *Client_GetStatefulSet_Call { +func (_c *Client_GetStatefulSet_Call) Return(_a0 *kappsv1.StatefulSet, _a1 error) *Client_GetStatefulSet_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *Client_GetStatefulSet_Call) RunAndReturn(run func(context.Context, string, string) (*appsv1.StatefulSet, error)) *Client_GetStatefulSet_Call { +func (_c *Client_GetStatefulSet_Call) RunAndReturn(run func(context.Context, string, string) (*kappsv1.StatefulSet, error)) *Client_GetStatefulSet_Call { _c.Call.Return(run) return _c } diff --git a/pkg/manager/mocks/manager.go b/pkg/manager/mocks/manager.go index 600587b1..40b8b308 100644 --- a/pkg/manager/mocks/manager.go +++ b/pkg/manager/mocks/manager.go @@ -7,11 +7,11 @@ import ( chart "github.com/kyma-project/nats-manager/pkg/k8s/chart" - manager "github.com/kyma-project/nats-manager/pkg/manager" + nmmgr "github.com/kyma-project/nats-manager/pkg/manager" mock "github.com/stretchr/testify/mock" - v1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" + nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" ) // Manager is an autogenerated mock type for the Manager type @@ -122,7 +122,7 @@ func (_c *Manager_DeployInstance_Call) RunAndReturn(run func(context.Context, *c } // GenerateNATSResources provides a mock function with given fields: _a0, _a1 -func (_m *Manager) GenerateNATSResources(_a0 *chart.ReleaseInstance, _a1 ...manager.Option) (*chart.ManifestResources, error) { +func (_m *Manager) GenerateNATSResources(_a0 *chart.ReleaseInstance, _a1 ...nmmgr.Option) (*chart.ManifestResources, error) { _va := make([]interface{}, len(_a1)) for _i := range _a1 { _va[_i] = _a1[_i] @@ -138,10 +138,10 @@ func (_m *Manager) GenerateNATSResources(_a0 *chart.ReleaseInstance, _a1 ...mana var r0 *chart.ManifestResources var r1 error - if rf, ok := ret.Get(0).(func(*chart.ReleaseInstance, ...manager.Option) (*chart.ManifestResources, error)); ok { + if rf, ok := ret.Get(0).(func(*chart.ReleaseInstance, ...nmmgr.Option) (*chart.ManifestResources, error)); ok { return rf(_a0, _a1...) } - if rf, ok := ret.Get(0).(func(*chart.ReleaseInstance, ...manager.Option) *chart.ManifestResources); ok { + if rf, ok := ret.Get(0).(func(*chart.ReleaseInstance, ...nmmgr.Option) *chart.ManifestResources); ok { r0 = rf(_a0, _a1...) } else { if ret.Get(0) != nil { @@ -149,7 +149,7 @@ func (_m *Manager) GenerateNATSResources(_a0 *chart.ReleaseInstance, _a1 ...mana } } - if rf, ok := ret.Get(1).(func(*chart.ReleaseInstance, ...manager.Option) error); ok { + if rf, ok := ret.Get(1).(func(*chart.ReleaseInstance, ...nmmgr.Option) error); ok { r1 = rf(_a0, _a1...) } else { r1 = ret.Error(1) @@ -165,18 +165,18 @@ type Manager_GenerateNATSResources_Call struct { // GenerateNATSResources is a helper method to define mock.On call // - _a0 *chart.ReleaseInstance -// - _a1 ...manager.Option +// - _a1 ...nmmgr.Option func (_e *Manager_Expecter) GenerateNATSResources(_a0 interface{}, _a1 ...interface{}) *Manager_GenerateNATSResources_Call { return &Manager_GenerateNATSResources_Call{Call: _e.mock.On("GenerateNATSResources", append([]interface{}{_a0}, _a1...)...)} } -func (_c *Manager_GenerateNATSResources_Call) Run(run func(_a0 *chart.ReleaseInstance, _a1 ...manager.Option)) *Manager_GenerateNATSResources_Call { +func (_c *Manager_GenerateNATSResources_Call) Run(run func(_a0 *chart.ReleaseInstance, _a1 ...nmmgr.Option)) *Manager_GenerateNATSResources_Call { _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]manager.Option, len(args)-1) + variadicArgs := make([]nmmgr.Option, len(args)-1) for i, a := range args[1:] { if a != nil { - variadicArgs[i] = a.(manager.Option) + variadicArgs[i] = a.(nmmgr.Option) } } run(args[0].(*chart.ReleaseInstance), variadicArgs...) @@ -189,13 +189,13 @@ func (_c *Manager_GenerateNATSResources_Call) Return(_a0 *chart.ManifestResource return _c } -func (_c *Manager_GenerateNATSResources_Call) RunAndReturn(run func(*chart.ReleaseInstance, ...manager.Option) (*chart.ManifestResources, error)) *Manager_GenerateNATSResources_Call { +func (_c *Manager_GenerateNATSResources_Call) RunAndReturn(run func(*chart.ReleaseInstance, ...nmmgr.Option) (*chart.ManifestResources, error)) *Manager_GenerateNATSResources_Call { _c.Call.Return(run) return _c } // GenerateOverrides provides a mock function with given fields: _a0, _a1, _a2 -func (_m *Manager) GenerateOverrides(_a0 *v1alpha1.NATSSpec, _a1 bool, _a2 bool) map[string]interface{} { +func (_m *Manager) GenerateOverrides(_a0 *nmapiv1alpha1.NATSSpec, _a1 bool, _a2 bool) map[string]interface{} { ret := _m.Called(_a0, _a1, _a2) if len(ret) == 0 { @@ -203,7 +203,7 @@ func (_m *Manager) GenerateOverrides(_a0 *v1alpha1.NATSSpec, _a1 bool, _a2 bool) } var r0 map[string]interface{} - if rf, ok := ret.Get(0).(func(*v1alpha1.NATSSpec, bool, bool) map[string]interface{}); ok { + if rf, ok := ret.Get(0).(func(*nmapiv1alpha1.NATSSpec, bool, bool) map[string]interface{}); ok { r0 = rf(_a0, _a1, _a2) } else { if ret.Get(0) != nil { @@ -220,16 +220,16 @@ type Manager_GenerateOverrides_Call struct { } // GenerateOverrides is a helper method to define mock.On call -// - _a0 *v1alpha1.NATSSpec +// - _a0 *nmapiv1alpha1.NATSSpec // - _a1 bool // - _a2 bool func (_e *Manager_Expecter) GenerateOverrides(_a0 interface{}, _a1 interface{}, _a2 interface{}) *Manager_GenerateOverrides_Call { return &Manager_GenerateOverrides_Call{Call: _e.mock.On("GenerateOverrides", _a0, _a1, _a2)} } -func (_c *Manager_GenerateOverrides_Call) Run(run func(_a0 *v1alpha1.NATSSpec, _a1 bool, _a2 bool)) *Manager_GenerateOverrides_Call { +func (_c *Manager_GenerateOverrides_Call) Run(run func(_a0 *nmapiv1alpha1.NATSSpec, _a1 bool, _a2 bool)) *Manager_GenerateOverrides_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(*v1alpha1.NATSSpec), args[1].(bool), args[2].(bool)) + run(args[0].(*nmapiv1alpha1.NATSSpec), args[1].(bool), args[2].(bool)) }) return _c } @@ -239,7 +239,7 @@ func (_c *Manager_GenerateOverrides_Call) Return(_a0 map[string]interface{}) *Ma return _c } -func (_c *Manager_GenerateOverrides_Call) RunAndReturn(run func(*v1alpha1.NATSSpec, bool, bool) map[string]interface{}) *Manager_GenerateOverrides_Call { +func (_c *Manager_GenerateOverrides_Call) RunAndReturn(run func(*nmapiv1alpha1.NATSSpec, bool, bool) map[string]interface{}) *Manager_GenerateOverrides_Call { _c.Call.Return(run) return _c } diff --git a/pkg/manager/nats.go b/pkg/manager/nats.go index 8e2e5096..dd1a9ee8 100644 --- a/pkg/manager/nats.go +++ b/pkg/manager/nats.go @@ -6,7 +6,7 @@ import ( "go.uber.org/zap" - natsv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" + nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" "github.com/kyma-project/nats-manager/pkg/k8s" "github.com/kyma-project/nats-manager/pkg/k8s/chart" ) @@ -24,7 +24,7 @@ type Manager interface { DeployInstance(context.Context, *chart.ReleaseInstance) error DeleteInstance(context.Context, *chart.ReleaseInstance) error IsNATSStatefulSetReady(context.Context, *chart.ReleaseInstance) (bool, error) - GenerateOverrides(*natsv1alpha1.NATSSpec, bool, bool) map[string]interface{} + GenerateOverrides(*nmapiv1alpha1.NATSSpec, bool, bool) map[string]interface{} } type NATSManager struct { diff --git a/pkg/manager/nats_test.go b/pkg/manager/nats_test.go index 8da2a22b..e5fa4e04 100644 --- a/pkg/manager/nats_test.go +++ b/pkg/manager/nats_test.go @@ -6,12 +6,12 @@ import ( "testing" "github.com/kyma-project/nats-manager/pkg/k8s/chart" - chartmocks "github.com/kyma-project/nats-manager/pkg/k8s/chart/mocks" - k8smocks "github.com/kyma-project/nats-manager/pkg/k8s/mocks" + nmkchartmocks "github.com/kyma-project/nats-manager/pkg/k8s/chart/mocks" + nmkmocks "github.com/kyma-project/nats-manager/pkg/k8s/mocks" "github.com/kyma-project/nats-manager/testutils" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" - appsv1 "k8s.io/api/apps/v1" + kappsv1 "k8s.io/api/apps/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" ) @@ -58,11 +58,11 @@ func Test_GenerateNATSResources(t *testing.T) { }, } - mockHelmRenderer := chartmocks.NewRenderer(t) + mockHelmRenderer := nmkchartmocks.NewRenderer(t) mockHelmRenderer.On("RenderManifestAsUnstructured", releaseInstance).Return(manifestResources, nil).Once() - manager := NewNATSManger(k8smocks.NewClient(t), mockHelmRenderer, sugaredLogger) + manager := NewNATSManger(nmkmocks.NewClient(t), mockHelmRenderer, sugaredLogger) // when gotManifests, err := manager.GenerateNATSResources(releaseInstance, tc.givenOptions...) @@ -129,7 +129,7 @@ func Test_DeployInstance(t *testing.T) { }, }) - mockKubeClient := k8smocks.NewClient(t) + mockKubeClient := nmkmocks.NewClient(t) if tc.wantError != nil { mockKubeClient.On("PatchApply", mock.Anything, mock.Anything).Return(tc.wantError) @@ -140,7 +140,7 @@ func Test_DeployInstance(t *testing.T) { len(releaseInstance.RenderedManifests.Items)) } - manager := NewNATSManger(mockKubeClient, chartmocks.NewRenderer(t), sugaredLogger) + manager := NewNATSManger(mockKubeClient, nmkchartmocks.NewRenderer(t), sugaredLogger) // when err = manager.DeployInstance(context.Background(), releaseInstance) @@ -194,7 +194,7 @@ func Test_DeleteInstance(t *testing.T) { }, }) - mockKubeClient := k8smocks.NewClient(t) + mockKubeClient := nmkmocks.NewClient(t) if tc.wantError != nil { mockKubeClient.On("Delete", mock.Anything, mock.Anything).Return(tc.wantError) @@ -205,7 +205,7 @@ func Test_DeleteInstance(t *testing.T) { len(releaseInstance.RenderedManifests.Items)) } - manager := NewNATSManger(mockKubeClient, chartmocks.NewRenderer(t), sugaredLogger) + manager := NewNATSManger(mockKubeClient, nmkchartmocks.NewRenderer(t), sugaredLogger) // when err = manager.DeleteInstance(context.Background(), releaseInstance) @@ -297,7 +297,7 @@ func Test_IsNATSStatefulSetReady(t *testing.T) { sugaredLogger, err := testutils.NewSugaredLogger() require.NoError(t, err) // mock for k8s kube client - mockKubeClient := k8smocks.NewClient(t) + mockKubeClient := nmkmocks.NewClient(t) var items []*unstructured.Unstructured if tc.givenStatefulSet != nil { @@ -305,7 +305,7 @@ func Test_IsNATSStatefulSetReady(t *testing.T) { tc.givenStatefulSet, } - var stsStructObject appsv1.StatefulSet + var stsStructObject kappsv1.StatefulSet err = runtime.DefaultUnstructuredConverter.FromUnstructured( tc.givenStatefulSet.UnstructuredContent(), &stsStructObject) require.NoError(t, err) @@ -322,7 +322,7 @@ func Test_IsNATSStatefulSetReady(t *testing.T) { Items: items, }) - manager := NewNATSManger(mockKubeClient, chartmocks.NewRenderer(t), sugaredLogger) + manager := NewNATSManger(mockKubeClient, nmkchartmocks.NewRenderer(t), sugaredLogger) // when isReady, err := manager.IsNATSStatefulSetReady(context.Background(), releaseInstance) diff --git a/pkg/manager/options.go b/pkg/manager/options.go index 599e6b6d..ad8e5c2f 100644 --- a/pkg/manager/options.go +++ b/pkg/manager/options.go @@ -3,14 +3,14 @@ package manager import ( "errors" - "github.com/kyma-project/nats-manager/api/v1alpha1" + nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" ) type Option func(*unstructured.Unstructured) error // WithOwnerReference sets the OwnerReferences of a k8s Object. -func WithOwnerReference(nats v1alpha1.NATS) Option { +func WithOwnerReference(nats nmapiv1alpha1.NATS) Option { return func(o *unstructured.Unstructured) error { if _, exists := o.Object["metadata"]; !exists { o.Object["metadata"] = make(map[string]interface{}) diff --git a/pkg/manager/options_test.go b/pkg/manager/options_test.go index 52623c7d..4245c1be 100644 --- a/pkg/manager/options_test.go +++ b/pkg/manager/options_test.go @@ -3,9 +3,9 @@ package manager import ( "testing" - "github.com/kyma-project/nats-manager/api/v1alpha1" + nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" "github.com/stretchr/testify/require" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" ) @@ -16,13 +16,13 @@ func Test_WithOwnerReference(t *testing.T) { t.Parallel() // given - natsCR := v1alpha1.NATS{ + natsCR := nmapiv1alpha1.NATS{ // Name, UUID, Kind, APIVersion - TypeMeta: metav1.TypeMeta{ + TypeMeta: kmetav1.TypeMeta{ APIVersion: "v1alpha1", Kind: "NATS", }, - ObjectMeta: metav1.ObjectMeta{ + ObjectMeta: kmetav1.ObjectMeta{ Name: "test-object1", Namespace: "test-ns1", UID: "1234-5678-1234-5678", diff --git a/pkg/manager/overrides.go b/pkg/manager/overrides.go index 55320cbf..8a6d9db2 100644 --- a/pkg/manager/overrides.go +++ b/pkg/manager/overrides.go @@ -1,6 +1,6 @@ package manager -import natsv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" +import nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" const ( MinClusterSize = 3 @@ -22,7 +22,7 @@ const ( ResourceLimitsMemKey = "nats.resources.limits.memory" ) -func (m NATSManager) GenerateOverrides(spec *natsv1alpha1.NATSSpec, istioEnabled bool, +func (m NATSManager) GenerateOverrides(spec *nmapiv1alpha1.NATSSpec, istioEnabled bool, rotatePassword bool) map[string]interface{} { overrides := map[string]interface{}{ IstioEnabledKey: istioEnabled, diff --git a/pkg/manager/overrides_test.go b/pkg/manager/overrides_test.go index fdf6999f..31405bfc 100644 --- a/pkg/manager/overrides_test.go +++ b/pkg/manager/overrides_test.go @@ -7,10 +7,10 @@ import ( "github.com/stretchr/testify/require" "helm.sh/helm/v3/pkg/chart/loader" - corev1 "k8s.io/api/core/v1" + kcorev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" - "github.com/kyma-project/nats-manager/api/v1alpha1" + nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" "github.com/kyma-project/nats-manager/testutils" ) @@ -20,7 +20,7 @@ func Test_GenerateOverrides(t *testing.T) { // define test cases testCases := []struct { name string - givenNATS *v1alpha1.NATS + givenNATS *nmapiv1alpha1.NATS givenIstioEnabled bool givenRotatePassword bool wantOverrides map[string]interface{} @@ -52,20 +52,20 @@ func Test_GenerateOverrides(t *testing.T) { givenNATS: testutils.NewNATSCR( testutils.WithNATSClusterSize(5), testutils.WithNATSLogging(true, true), - testutils.WithNATSFileStorage(v1alpha1.FileStorage{ + testutils.WithNATSFileStorage(nmapiv1alpha1.FileStorage{ Size: resource.MustParse("15Gi"), StorageClassName: "test1", }), - testutils.WithNATSMemStorage(v1alpha1.MemStorage{ + testutils.WithNATSMemStorage(nmapiv1alpha1.MemStorage{ Enabled: true, Size: resource.MustParse("16Gi"), }), - testutils.WithNATSResources(corev1.ResourceRequirements{ - Limits: corev1.ResourceList{ + testutils.WithNATSResources(kcorev1.ResourceRequirements{ + Limits: kcorev1.ResourceList{ "cpu": resource.MustParse("999m"), "memory": resource.MustParse("999Mi"), }, - Requests: corev1.ResourceList{ + Requests: kcorev1.ResourceList{ "cpu": resource.MustParse("919m"), "memory": resource.MustParse("919Mi"), }, diff --git a/pkg/nats/client_unit_test.go b/pkg/nats/client_unit_test.go index e57ac220..50755939 100644 --- a/pkg/nats/client_unit_test.go +++ b/pkg/nats/client_unit_test.go @@ -5,8 +5,8 @@ import ( "fmt" "testing" - "github.com/kyma-project/nats-manager/internal/controller/nats/mocks" - "github.com/nats-io/nats.go" + nmctrlmocks "github.com/kyma-project/nats-manager/internal/controller/nats/mocks" + natsgo "github.com/nats-io/nats.go" "github.com/stretchr/testify/require" ) @@ -15,15 +15,15 @@ func Test_StreamExists(t *testing.T) { tests := []struct { name string createMockNatsClient func() *natsClient - streams []*nats.StreamInfo + streams []*natsgo.StreamInfo expected bool err error }{ { name: "should no stream exist", createMockNatsClient: func() *natsClient { - mockNatsConn := &mocks.NatsConn{} - jsCtx := &mocks.JetStreamContext{} + mockNatsConn := &nmctrlmocks.NatsConn{} + jsCtx := &nmctrlmocks.JetStreamContext{} jsCtx.On("Streams").Return(returnEmptyStream()) mockNatsConn.On("JetStream").Return(jsCtx, nil) return &natsClient{conn: mockNatsConn} @@ -34,8 +34,8 @@ func Test_StreamExists(t *testing.T) { { name: "should streams exist", createMockNatsClient: func() *natsClient { - mockNatsConn := &mocks.NatsConn{} - jsCtx := &mocks.JetStreamContext{} + mockNatsConn := &nmctrlmocks.NatsConn{} + jsCtx := &nmctrlmocks.JetStreamContext{} jsCtx.On("Streams").Return(returnStreams()) mockNatsConn.On("JetStream").Return(jsCtx, nil) return &natsClient{conn: mockNatsConn} @@ -46,7 +46,7 @@ func Test_StreamExists(t *testing.T) { { name: "should fail getting JetStream context", createMockNatsClient: func() *natsClient { - mockNatsConn := &mocks.NatsConn{} + mockNatsConn := &nmctrlmocks.NatsConn{} mockNatsConn.On("JetStream").Return(nil, fakeError) return &natsClient{conn: mockNatsConn} }, @@ -72,18 +72,18 @@ func Test_StreamExists(t *testing.T) { } } -func returnStreams() <-chan *nats.StreamInfo { - ch := make(chan *nats.StreamInfo) +func returnStreams() <-chan *natsgo.StreamInfo { + ch := make(chan *natsgo.StreamInfo) go func() { defer close(ch) - ch <- &nats.StreamInfo{ - Config: nats.StreamConfig{ + ch <- &natsgo.StreamInfo{ + Config: natsgo.StreamConfig{ Name: "test-stream", Subjects: []string{"test-subject"}, }, } - ch <- &nats.StreamInfo{ - Config: nats.StreamConfig{ + ch <- &natsgo.StreamInfo{ + Config: natsgo.StreamConfig{ Name: "test-stream-2", Subjects: []string{"test-subject-2"}, }, @@ -92,8 +92,8 @@ func returnStreams() <-chan *nats.StreamInfo { return ch } -func returnEmptyStream() <-chan *nats.StreamInfo { - ch := make(chan *nats.StreamInfo) +func returnEmptyStream() <-chan *natsgo.StreamInfo { + ch := make(chan *natsgo.StreamInfo) go func() { defer close(ch) }() diff --git a/pkg/nats/mocks/client.go b/pkg/nats/mocks/client.go index 85dfa335..47124843 100644 --- a/pkg/nats/mocks/client.go +++ b/pkg/nats/mocks/client.go @@ -5,7 +5,7 @@ package mocks import ( mock "github.com/stretchr/testify/mock" - nats_go "github.com/nats-io/nats.go" + natsgo "github.com/nats-io/nats.go" ) // Client is an autogenerated mock type for the Client type @@ -110,23 +110,23 @@ func (_c *Client_ConsumersExist_Call) RunAndReturn(run func(string) (bool, error } // GetStreams provides a mock function with given fields: -func (_m *Client) GetStreams() ([]*nats_go.StreamInfo, error) { +func (_m *Client) GetStreams() ([]*natsgo.StreamInfo, error) { ret := _m.Called() if len(ret) == 0 { panic("no return value specified for GetStreams") } - var r0 []*nats_go.StreamInfo + var r0 []*natsgo.StreamInfo var r1 error - if rf, ok := ret.Get(0).(func() ([]*nats_go.StreamInfo, error)); ok { + if rf, ok := ret.Get(0).(func() ([]*natsgo.StreamInfo, error)); ok { return rf() } - if rf, ok := ret.Get(0).(func() []*nats_go.StreamInfo); ok { + if rf, ok := ret.Get(0).(func() []*natsgo.StreamInfo); ok { r0 = rf() } else { if ret.Get(0) != nil { - r0 = ret.Get(0).([]*nats_go.StreamInfo) + r0 = ret.Get(0).([]*natsgo.StreamInfo) } } @@ -156,12 +156,12 @@ func (_c *Client_GetStreams_Call) Run(run func()) *Client_GetStreams_Call { return _c } -func (_c *Client_GetStreams_Call) Return(_a0 []*nats_go.StreamInfo, _a1 error) *Client_GetStreams_Call { +func (_c *Client_GetStreams_Call) Return(_a0 []*natsgo.StreamInfo, _a1 error) *Client_GetStreams_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *Client_GetStreams_Call) RunAndReturn(run func() ([]*nats_go.StreamInfo, error)) *Client_GetStreams_Call { +func (_c *Client_GetStreams_Call) RunAndReturn(run func() ([]*natsgo.StreamInfo, error)) *Client_GetStreams_Call { _c.Call.Return(run) return _c } diff --git a/testutils/integration/integration.go b/testutils/integration/integration.go index ddb761f1..449fbb64 100644 --- a/testutils/integration/integration.go +++ b/testutils/integration/integration.go @@ -10,37 +10,37 @@ import ( "testing" "time" - policyv1 "k8s.io/api/policy/v1" + kapipolicyv1 "k8s.io/api/policy/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/labels" "k8s.io/client-go/dynamic" - corev1 "k8s.io/api/core/v1" + kcorev1 "k8s.io/api/core/v1" "github.com/avast/retry-go/v3" "github.com/onsi/gomega" "github.com/stretchr/testify/require" "go.uber.org/zap" - appsv1 "k8s.io/api/apps/v1" - apiclientset "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset" - k8serrors "k8s.io/apimachinery/pkg/api/errors" - k8stypes "k8s.io/apimachinery/pkg/types" - "k8s.io/client-go/kubernetes/scheme" + kappsv1 "k8s.io/api/apps/v1" + kapiextclientset "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset" + kapierrors "k8s.io/apimachinery/pkg/api/errors" + ktypes "k8s.io/apimachinery/pkg/types" + kscheme "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/rest" "k8s.io/client-go/tools/record" - ctrl "sigs.k8s.io/controller-runtime" + kcontrollerruntime "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/envtest" "sigs.k8s.io/controller-runtime/pkg/metrics/server" "sigs.k8s.io/controller-runtime/pkg/webhook" - natsv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" - natscontroller "github.com/kyma-project/nats-manager/internal/controller/nats" + nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" + nmctrl "github.com/kyma-project/nats-manager/internal/controller/nats" "github.com/kyma-project/nats-manager/pkg/k8s" "github.com/kyma-project/nats-manager/pkg/k8s/chart" - "github.com/kyma-project/nats-manager/pkg/manager" + nmmgr "github.com/kyma-project/nats-manager/pkg/manager" "github.com/kyma-project/nats-manager/testutils" ) @@ -69,8 +69,8 @@ type TestEnvironment struct { K8sDynamicClient *dynamic.DynamicClient KubeClient *k8s.Client ChartRenderer *chart.Renderer - NATSManager *manager.Manager - Reconciler *natscontroller.Reconciler + NATSManager *nmmgr.Manager + Reconciler *nmctrl.Reconciler Logger *zap.SugaredLogger Recorder *record.EventRecorder TestCancelFn context.CancelFunc @@ -78,7 +78,7 @@ type TestEnvironment struct { //nolint:funlen // Used in testing func NewTestEnvironment(projectRootDir string, celValidationEnabled bool, - allowedNATSCR *natsv1alpha1.NATS) (*TestEnvironment, error) { + allowedNATSCR *nmapiv1alpha1.NATS) (*TestEnvironment, error) { var err error // setup context ctx := context.Background() @@ -95,14 +95,14 @@ func NewTestEnvironment(projectRootDir string, celValidationEnabled bool, } // add to Scheme - err = natsv1alpha1.AddToScheme(scheme.Scheme) + err = nmapiv1alpha1.AddToScheme(kscheme.Scheme) if err != nil { return nil, err } // +kubebuilder:scaffold:scheme - k8sClient, err := client.New(envTestKubeCfg, client.Options{Scheme: scheme.Scheme}) + k8sClient, err := client.New(envTestKubeCfg, client.Options{Scheme: kscheme.Scheme}) if err != nil { return nil, err } @@ -118,8 +118,8 @@ func NewTestEnvironment(projectRootDir string, celValidationEnabled bool, return nil, err } - ctrlMgr, err := ctrl.NewManager(envTestKubeCfg, ctrl.Options{ - Scheme: scheme.Scheme, + ctrlMgr, err := kcontrollerruntime.NewManager(envTestKubeCfg, kcontrollerruntime.Options{ + Scheme: kscheme.Scheme, HealthProbeBindAddress: "0", // disable PprofBindAddress: "0", // disable Metrics: server.Options{BindAddress: "0"}, // disable @@ -131,7 +131,7 @@ func NewTestEnvironment(projectRootDir string, celValidationEnabled bool, recorder := ctrlMgr.GetEventRecorderFor("nats-manager") // init custom kube client wrapper - apiClientSet, err := apiclientset.NewForConfig(ctrlMgr.GetConfig()) + apiClientSet, err := kapiextclientset.NewForConfig(ctrlMgr.GetConfig()) if err != nil { return nil, err } @@ -144,10 +144,10 @@ func NewTestEnvironment(projectRootDir string, celValidationEnabled bool, } // create NATS manager instance - natsManager := manager.NewNATSManger(kubeClient, helmRenderer, sugaredLogger) + natsManager := nmmgr.NewNATSManger(kubeClient, helmRenderer, sugaredLogger) // setup reconciler - natsReconciler := natscontroller.NewReconciler( + natsReconciler := nmctrl.NewReconciler( ctrlMgr.GetClient(), kubeClient, helmRenderer, @@ -165,7 +165,7 @@ func NewTestEnvironment(projectRootDir string, celValidationEnabled bool, var cancelCtx context.CancelFunc go func() { var mgrCtx context.Context - mgrCtx, cancelCtx = context.WithCancel(ctrl.SetupSignalHandler()) + mgrCtx, cancelCtx = context.WithCancel(kcontrollerruntime.SetupSignalHandler()) err = ctrlMgr.Start(mgrCtx) if err != nil { log.Fatal(err) @@ -234,7 +234,7 @@ func (env TestEnvironment) EnsureK8sResourceUpdated(t *testing.T, obj client.Obj require.NoError(t, env.k8sClient.Update(env.Context, obj)) } -func (env TestEnvironment) UpdatedNATSInK8s(nats *natsv1alpha1.NATS, options ...testutils.NATSOption) error { +func (env TestEnvironment) UpdatedNATSInK8s(nats *nmapiv1alpha1.NATS, options ...testutils.NATSOption) error { natsOnK8s, err := env.GetNATSFromK8s(nats.Name, nats.Namespace) if err != nil { log.Fatal(err) @@ -304,7 +304,7 @@ func (env TestEnvironment) EnsureK8sPVCExists(t *testing.T, label, namespace str result, err := env.GetPVCFromK8s(label, namespace) if err != nil { env.Logger.Errorw("failed to ensure PVC", "error", err, - natscontroller.InstanceLabelKey, label, "namespace", namespace) + nmctrl.InstanceLabelKey, label, "namespace", namespace) } return err == nil && result != nil }, BigTimeOut, BigPollingInterval, "failed to ensure existence of PVC") @@ -313,35 +313,35 @@ func (env TestEnvironment) EnsureK8sPVCExists(t *testing.T, label, namespace str func (env TestEnvironment) EnsureK8sConfigMapNotFound(t *testing.T, name, namespace string) { require.Eventually(t, func() bool { _, err := env.GetConfigMapFromK8s(name, namespace) - return err != nil && k8serrors.IsNotFound(err) + return err != nil && kapierrors.IsNotFound(err) }, SmallTimeOut, SmallPollingInterval, "failed to ensure non-existence of ConfigMap") } func (env TestEnvironment) EnsureK8sSecretNotFound(t *testing.T, name, namespace string) { require.Eventually(t, func() bool { _, err := env.GetSecretFromK8s(name, namespace) - return err != nil && k8serrors.IsNotFound(err) + return err != nil && kapierrors.IsNotFound(err) }, SmallTimeOut, SmallPollingInterval, "failed to ensure non-existence of Secret") } func (env TestEnvironment) EnsureK8sServiceNotFound(t *testing.T, name, namespace string) { require.Eventually(t, func() bool { _, err := env.GetServiceFromK8s(name, namespace) - return err != nil && k8serrors.IsNotFound(err) + return err != nil && kapierrors.IsNotFound(err) }, SmallTimeOut, SmallPollingInterval, "failed to ensure non-existence of Service") } func (env TestEnvironment) EnsureK8sDestinationRuleNotFound(t *testing.T, name, namespace string) { require.Eventually(t, func() bool { _, err := env.GetDestinationRuleFromK8s(name, namespace) - return err != nil && k8serrors.IsNotFound(err) + return err != nil && kapierrors.IsNotFound(err) }, SmallTimeOut, SmallPollingInterval, "failed to ensure non-existence of DestinationRule") } func (env TestEnvironment) EnsureK8sNATSNotFound(t *testing.T, name, namespace string) { require.Eventually(t, func() bool { _, err := env.GetNATSFromK8s(name, namespace) - return err != nil && k8serrors.IsNotFound(err) + return err != nil && kapierrors.IsNotFound(err) }, SmallTimeOut, SmallPollingInterval, "failed to ensure non-existence of NATS") } @@ -352,7 +352,7 @@ func (env TestEnvironment) EnsureK8sStatefulSetNotFound(t *testing.T, name, name env.Logger.Errorw("failed to ensure STS", "error", err, "name", name, "namespace", namespace) } - return err != nil && k8serrors.IsNotFound(err) + return err != nil && kapierrors.IsNotFound(err) }, BigTimeOut, BigPollingInterval, "failed to ensure non-existence of StatefulSet") } @@ -363,7 +363,7 @@ func (env TestEnvironment) EnsureK8sPVCNotFound(t *testing.T, name, namespace st env.Logger.Errorw("failed to ensure PVC", "error", err, "name", name, "namespace", namespace) } - return (err != nil && k8serrors.IsNotFound(err)) || (pvc == nil && err == nil) || + return (err != nil && kapierrors.IsNotFound(err)) || (pvc == nil && err == nil) || (pvc != nil && pvc.DeletionTimestamp != nil) }, BigTimeOut, BigPollingInterval, "failed to ensure non-existence of PVC") } @@ -410,7 +410,7 @@ func (env TestEnvironment) EnsureK8sStatefulSetHasAnnotations(t *testing.T, name // EnsureNATSSpecClusterSizeReflected ensures that NATS CR Spec.cluster.size is reflected // in relevant k8s objects. -func (env TestEnvironment) EnsureNATSSpecClusterSizeReflected(t *testing.T, nats natsv1alpha1.NATS) { +func (env TestEnvironment) EnsureNATSSpecClusterSizeReflected(t *testing.T, nats nmapiv1alpha1.NATS) { require.Eventually(t, func() bool { stsName := testutils.GetStatefulSetName(nats) result, err := env.GetStatefulSetFromK8s(stsName, nats.Namespace) @@ -425,7 +425,7 @@ func (env TestEnvironment) EnsureNATSSpecClusterSizeReflected(t *testing.T, nats // EnsureNATSSpecResourcesReflected ensures that NATS CR Spec.resources is reflected // in relevant k8s objects. -func (env TestEnvironment) EnsureNATSSpecResourcesReflected(t *testing.T, nats natsv1alpha1.NATS) { +func (env TestEnvironment) EnsureNATSSpecResourcesReflected(t *testing.T, nats nmapiv1alpha1.NATS) { require.Eventually(t, func() bool { stsName := testutils.GetStatefulSetName(nats) result, err := env.GetStatefulSetFromK8s(stsName, nats.Namespace) @@ -444,7 +444,7 @@ func (env TestEnvironment) EnsureNATSSpecResourcesReflected(t *testing.T, nats n // EnsureNATSSpecDebugTraceReflected ensures that NATS CR Spec.trace and Spec.debug is reflected // in relevant k8s objects. -func (env TestEnvironment) EnsureNATSSpecDebugTraceReflected(t *testing.T, nats natsv1alpha1.NATS) { +func (env TestEnvironment) EnsureNATSSpecDebugTraceReflected(t *testing.T, nats nmapiv1alpha1.NATS) { require.Eventually(t, func() bool { // get NATS configMap. result, err := env.GetConfigMapFromK8s(testutils.GetConfigMapName(nats), nats.Namespace) @@ -468,7 +468,7 @@ func (env TestEnvironment) EnsureNATSSpecDebugTraceReflected(t *testing.T, nats // EnsureNATSSpecFileStorageReflected ensures that NATS CR Spec.jetStream.fileStorage is reflected // in relevant k8s objects. -func (env TestEnvironment) EnsureNATSSpecFileStorageReflected(t *testing.T, nats natsv1alpha1.NATS) { +func (env TestEnvironment) EnsureNATSSpecFileStorageReflected(t *testing.T, nats nmapiv1alpha1.NATS) { require.Eventually(t, func() bool { // get NATS configMap. result, err := env.GetConfigMapFromK8s(testutils.GetConfigMapName(nats), nats.Namespace) @@ -512,7 +512,7 @@ func (env TestEnvironment) EnsureNATSSpecFileStorageReflected(t *testing.T, nats // EnsureNATSSpecMemStorageReflected ensures that NATS CR Spec.jetStream.memStorage is reflected // in relevant k8s objects. -func (env TestEnvironment) EnsureNATSSpecMemStorageReflected(t *testing.T, nats natsv1alpha1.NATS) { +func (env TestEnvironment) EnsureNATSSpecMemStorageReflected(t *testing.T, nats nmapiv1alpha1.NATS) { require.Eventually(t, func() bool { // get NATS configMap. result, err := env.GetConfigMapFromK8s(testutils.GetConfigMapName(nats), nats.Namespace) @@ -539,7 +539,7 @@ func (env TestEnvironment) EnsureURLInNATSStatus(t *testing.T, name, namespace s require.NotNil(t, natsCR) switch natsCR.Status.State { - case natsv1alpha1.StateReady: + case nmapiv1alpha1.StateReady: { wantURL := fmt.Sprintf("nats://%s.%s.svc.cluster.local:4222", natsCR.Name, natsCR.Namespace) require.Equal(t, wantURL, natsCR.Status.URL) @@ -552,34 +552,34 @@ func (env TestEnvironment) EnsureURLInNATSStatus(t *testing.T, name, namespace s } } -func (env TestEnvironment) GetNATSFromK8s(name, namespace string) (natsv1alpha1.NATS, error) { - var nats natsv1alpha1.NATS - err := env.k8sClient.Get(env.Context, k8stypes.NamespacedName{ +func (env TestEnvironment) GetNATSFromK8s(name, namespace string) (nmapiv1alpha1.NATS, error) { + var nats nmapiv1alpha1.NATS + err := env.k8sClient.Get(env.Context, ktypes.NamespacedName{ Name: name, Namespace: namespace, }, &nats) return nats, err } -func (env TestEnvironment) GetStatefulSetFromK8s(name, namespace string) (*appsv1.StatefulSet, error) { - nn := k8stypes.NamespacedName{ +func (env TestEnvironment) GetStatefulSetFromK8s(name, namespace string) (*kappsv1.StatefulSet, error) { + nn := ktypes.NamespacedName{ Name: name, Namespace: namespace, } - result := &appsv1.StatefulSet{} + result := &kappsv1.StatefulSet{} if err := env.k8sClient.Get(env.Context, nn, result); err != nil { return nil, err } return result, nil } -func (env TestEnvironment) GetPVCFromK8s(label, namespace string) (*corev1.PersistentVolumeClaim, error) { +func (env TestEnvironment) GetPVCFromK8s(label, namespace string) (*kcorev1.PersistentVolumeClaim, error) { // get PVCs. - pvcList := &corev1.PersistentVolumeClaimList{} + pvcList := &kcorev1.PersistentVolumeClaimList{} if err := env.k8sClient.List(env.Context, pvcList, &client.ListOptions{ Namespace: namespace, LabelSelector: labels.SelectorFromSet(map[string]string{ - natscontroller.InstanceLabelKey: label, + nmctrl.InstanceLabelKey: label, }), }); err != nil { return nil, err @@ -590,40 +590,40 @@ func (env TestEnvironment) GetPVCFromK8s(label, namespace string) (*corev1.Persi return &pvcList.Items[0], nil } -func (env TestEnvironment) UpdateStatefulSetStatusOnK8s(sts appsv1.StatefulSet) error { +func (env TestEnvironment) UpdateStatefulSetStatusOnK8s(sts kappsv1.StatefulSet) error { return env.k8sClient.Status().Update(env.Context, &sts) } -func (env TestEnvironment) GetConfigMapFromK8s(name, namespace string) (*corev1.ConfigMap, error) { - nn := k8stypes.NamespacedName{ +func (env TestEnvironment) GetConfigMapFromK8s(name, namespace string) (*kcorev1.ConfigMap, error) { + nn := ktypes.NamespacedName{ Name: name, Namespace: namespace, } - result := &corev1.ConfigMap{} + result := &kcorev1.ConfigMap{} if err := env.k8sClient.Get(env.Context, nn, result); err != nil { return nil, err } return result, nil } -func (env TestEnvironment) GetSecretFromK8s(name, namespace string) (*corev1.Secret, error) { - nn := k8stypes.NamespacedName{ +func (env TestEnvironment) GetSecretFromK8s(name, namespace string) (*kcorev1.Secret, error) { + nn := ktypes.NamespacedName{ Name: name, Namespace: namespace, } - result := &corev1.Secret{} + result := &kcorev1.Secret{} if err := env.k8sClient.Get(env.Context, nn, result); err != nil { return nil, err } return result, nil } -func (env TestEnvironment) GetServiceFromK8s(name, namespace string) (*corev1.Service, error) { - nn := k8stypes.NamespacedName{ +func (env TestEnvironment) GetServiceFromK8s(name, namespace string) (*kcorev1.Service, error) { + nn := ktypes.NamespacedName{ Name: name, Namespace: namespace, } - result := &corev1.Service{} + result := &kcorev1.Service{} if err := env.k8sClient.Get(env.Context, nn, result); err != nil { return nil, err } @@ -631,12 +631,12 @@ func (env TestEnvironment) GetServiceFromK8s(name, namespace string) (*corev1.Se } func (env TestEnvironment) GetPodDisruptionBudgetFromK8s(name, - namespace string) (*policyv1.PodDisruptionBudget, error) { - nn := k8stypes.NamespacedName{ + namespace string) (*kapipolicyv1.PodDisruptionBudget, error) { + nn := ktypes.NamespacedName{ Name: name, Namespace: namespace, } - result := &policyv1.PodDisruptionBudget{} + result := &kapipolicyv1.PodDisruptionBudget{} if err := env.k8sClient.Get(env.Context, nn, result); err != nil { return nil, err } @@ -645,12 +645,12 @@ func (env TestEnvironment) GetPodDisruptionBudgetFromK8s(name, func (env TestEnvironment) GetDestinationRuleFromK8s(name, namespace string) (*unstructured.Unstructured, error) { return env.K8sDynamicClient.Resource(testutils.GetDestinationRuleGVR()).Namespace( - namespace).Get(env.Context, name, metav1.GetOptions{}) + namespace).Get(env.Context, name, kmetav1.GetOptions{}) } func (env TestEnvironment) DeleteStatefulSetFromK8s(name, namespace string) error { - return env.k8sClient.Delete(env.Context, &appsv1.StatefulSet{ - ObjectMeta: metav1.ObjectMeta{ + return env.k8sClient.Delete(env.Context, &kappsv1.StatefulSet{ + ObjectMeta: kmetav1.ObjectMeta{ Name: name, Namespace: namespace, }, @@ -658,8 +658,8 @@ func (env TestEnvironment) DeleteStatefulSetFromK8s(name, namespace string) erro } func (env TestEnvironment) DeleteServiceFromK8s(name, namespace string) error { - return env.k8sClient.Delete(env.Context, &corev1.Service{ - ObjectMeta: metav1.ObjectMeta{ + return env.k8sClient.Delete(env.Context, &kcorev1.Service{ + ObjectMeta: kmetav1.ObjectMeta{ Name: name, Namespace: namespace, }, @@ -667,8 +667,8 @@ func (env TestEnvironment) DeleteServiceFromK8s(name, namespace string) error { } func (env TestEnvironment) DeletePodDisruptionBudgetFromK8s(name, namespace string) error { - return env.k8sClient.Delete(env.Context, &policyv1.PodDisruptionBudget{ - ObjectMeta: metav1.ObjectMeta{ + return env.k8sClient.Delete(env.Context, &kapipolicyv1.PodDisruptionBudget{ + ObjectMeta: kmetav1.ObjectMeta{ Name: name, Namespace: namespace, }, @@ -676,8 +676,8 @@ func (env TestEnvironment) DeletePodDisruptionBudgetFromK8s(name, namespace stri } func (env TestEnvironment) DeleteConfigMapFromK8s(name, namespace string) error { - return env.k8sClient.Delete(env.Context, &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{ + return env.k8sClient.Delete(env.Context, &kcorev1.ConfigMap{ + ObjectMeta: kmetav1.ObjectMeta{ Name: name, Namespace: namespace, }, @@ -685,8 +685,8 @@ func (env TestEnvironment) DeleteConfigMapFromK8s(name, namespace string) error } func (env TestEnvironment) DeleteSecretFromK8s(name, namespace string) error { - return env.k8sClient.Delete(env.Context, &corev1.Secret{ - ObjectMeta: metav1.ObjectMeta{ + return env.k8sClient.Delete(env.Context, &kcorev1.Secret{ + ObjectMeta: kmetav1.ObjectMeta{ Name: name, Namespace: namespace, }, @@ -695,13 +695,13 @@ func (env TestEnvironment) DeleteSecretFromK8s(name, namespace string) error { func (env TestEnvironment) DeleteDestinationRuleFromK8s(name, namespace string) error { return env.K8sDynamicClient.Resource(testutils.GetDestinationRuleGVR()).Namespace( - namespace).Delete(env.Context, name, metav1.DeleteOptions{}) + namespace).Delete(env.Context, name, kmetav1.DeleteOptions{}) } // GetNATSAssert fetches a NATS from k8s and allows making assertions on it. func (env TestEnvironment) GetNATSAssert(g *gomega.GomegaWithT, - nats *natsv1alpha1.NATS) gomega.AsyncAssertion { - return g.Eventually(func() *natsv1alpha1.NATS { + nats *nmapiv1alpha1.NATS) gomega.AsyncAssertion { + return g.Eventually(func() *nmapiv1alpha1.NATS { gotNATS, err := env.GetNATSFromK8s(nats.Name, nats.Namespace) if err != nil { log.Printf("fetch subscription %s/%s failed: %v", nats.Name, nats.Namespace, err) @@ -711,13 +711,13 @@ func (env TestEnvironment) GetNATSAssert(g *gomega.GomegaWithT, }, BigTimeOut, SmallPollingInterval) } -func (env TestEnvironment) GetK8sEventsAssert(g *gomega.GomegaWithT, nats *natsv1alpha1.NATS) gomega.AsyncAssertion { - eventList := corev1.EventList{} - return g.Eventually(func() (corev1.EventList, error) { +func (env TestEnvironment) GetK8sEventsAssert(g *gomega.GomegaWithT, nats *nmapiv1alpha1.NATS) gomega.AsyncAssertion { + eventList := kcorev1.EventList{} + return g.Eventually(func() (kcorev1.EventList, error) { err := env.k8sClient.List(env.Context, &eventList, client.InNamespace(nats.Namespace)) if err != nil { log.Printf("fetch kubernetes events in ns:%s failed: %v", nats.Namespace, err) - return corev1.EventList{}, err + return kcorev1.EventList{}, err } return eventList, err }, BigTimeOut, SmallPollingInterval) diff --git a/testutils/matchers/nats/matchers.go b/testutils/matchers/nats/matchers.go index 290819bb..5c74d99c 100644 --- a/testutils/matchers/nats/matchers.go +++ b/testutils/matchers/nats/matchers.go @@ -5,125 +5,125 @@ import ( "github.com/onsi/gomega" "github.com/onsi/gomega/gstruct" - gomegatypes "github.com/onsi/gomega/types" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + onsigomegatypes "github.com/onsi/gomega/types" + kcorev1 "k8s.io/api/core/v1" + kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/kyma-project/nats-manager/api/v1alpha1" + nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" ) -func HaveSpecJetsStreamMemStorage(ms v1alpha1.MemStorage) gomegatypes.GomegaMatcher { +func HaveSpecJetsStreamMemStorage(ms nmapiv1alpha1.MemStorage) onsigomegatypes.GomegaMatcher { return gomega.And( gomega.WithTransform( - func(n *v1alpha1.NATS) bool { + func(n *nmapiv1alpha1.NATS) bool { return n.Spec.JetStream.MemStorage.Enabled }, gomega.Equal(ms.Enabled)), gomega.WithTransform( - func(n *v1alpha1.NATS) bool { + func(n *nmapiv1alpha1.NATS) bool { return n.Spec.JetStream.MemStorage.Size.Equal(ms.Size) }, gomega.BeTrue()), ) } -func HaveSpecJetStreamFileStorage(fs v1alpha1.FileStorage) gomegatypes.GomegaMatcher { +func HaveSpecJetStreamFileStorage(fs nmapiv1alpha1.FileStorage) onsigomegatypes.GomegaMatcher { return gomega.And( gomega.WithTransform( - func(n *v1alpha1.NATS) string { + func(n *nmapiv1alpha1.NATS) string { return n.Spec.JetStream.FileStorage.StorageClassName }, gomega.Equal(fs.StorageClassName)), gomega.WithTransform( - func(n *v1alpha1.NATS) bool { + func(n *nmapiv1alpha1.NATS) bool { return n.Spec.JetStream.FileStorage.Size.Equal(fs.Size) }, gomega.BeTrue()), ) } -func HaveSpecCluster(cluster v1alpha1.Cluster) gomegatypes.GomegaMatcher { +func HaveSpecCluster(cluster nmapiv1alpha1.Cluster) onsigomegatypes.GomegaMatcher { return gomega.WithTransform( - func(n *v1alpha1.NATS) bool { + func(n *nmapiv1alpha1.NATS) bool { return reflect.DeepEqual(n.Spec.Cluster, cluster) }, gomega.BeTrue()) } -func HaveSpecClusterSize(size int) gomegatypes.GomegaMatcher { +func HaveSpecClusterSize(size int) onsigomegatypes.GomegaMatcher { return gomega.WithTransform( - func(n *v1alpha1.NATS) int { + func(n *nmapiv1alpha1.NATS) int { return n.Spec.Cluster.Size }, gomega.Equal(size)) } -func HaveSpecLogging(logging v1alpha1.Logging) gomegatypes.GomegaMatcher { +func HaveSpecLogging(logging nmapiv1alpha1.Logging) onsigomegatypes.GomegaMatcher { return gomega.And( gomega.WithTransform( - func(n *v1alpha1.NATS) bool { + func(n *nmapiv1alpha1.NATS) bool { return n.Spec.Logging.Debug }, gomega.Equal(logging.Debug)), gomega.WithTransform( - func(n *v1alpha1.NATS) bool { + func(n *nmapiv1alpha1.NATS) bool { return n.Spec.Logging.Trace }, gomega.Equal(logging.Trace)), ) } -func HaveSpecLoggingDebug(enabled bool) gomegatypes.GomegaMatcher { +func HaveSpecLoggingDebug(enabled bool) onsigomegatypes.GomegaMatcher { return gomega.WithTransform( - func(n *v1alpha1.NATS) bool { + func(n *nmapiv1alpha1.NATS) bool { return n.Spec.Logging.Debug }, gomega.Equal(enabled)) } -func HaveSpecLoggingTrace(enabled bool) gomegatypes.GomegaMatcher { +func HaveSpecLoggingTrace(enabled bool) onsigomegatypes.GomegaMatcher { return gomega.WithTransform( - func(n *v1alpha1.NATS) bool { + func(n *nmapiv1alpha1.NATS) bool { return n.Spec.Logging.Trace }, gomega.Equal(enabled)) } -func HaveSpecResources(res corev1.ResourceRequirements) gomegatypes.GomegaMatcher { +func HaveSpecResources(res kcorev1.ResourceRequirements) onsigomegatypes.GomegaMatcher { return gomega.And( gomega.WithTransform( - func(n *v1alpha1.NATS) bool { + func(n *nmapiv1alpha1.NATS) bool { return n.Spec.Resources.Requests.Storage().Equal(*res.Requests.Storage()) }, gomega.BeTrue()), gomega.WithTransform( - func(n *v1alpha1.NATS) bool { + func(n *nmapiv1alpha1.NATS) bool { return n.Spec.Resources.Requests.Cpu().Equal(*res.Requests.Cpu()) }, gomega.BeTrue()), gomega.WithTransform( - func(n *v1alpha1.NATS) bool { + func(n *nmapiv1alpha1.NATS) bool { return n.Spec.Resources.Limits.Storage().Equal(*res.Requests.Storage()) }, gomega.BeTrue()), gomega.WithTransform( - func(n *v1alpha1.NATS) bool { + func(n *nmapiv1alpha1.NATS) bool { return n.Spec.Resources.Requests.Cpu().Equal(*res.Requests.Cpu()) }, gomega.BeTrue()), ) } -func HaveStatusReady() gomegatypes.GomegaMatcher { +func HaveStatusReady() onsigomegatypes.GomegaMatcher { return gomega.WithTransform( - func(n *v1alpha1.NATS) string { + func(n *nmapiv1alpha1.NATS) string { return n.Status.State - }, gomega.Equal(v1alpha1.StateReady)) + }, gomega.Equal(nmapiv1alpha1.StateReady)) } -func HaveStatusProcessing() gomegatypes.GomegaMatcher { +func HaveStatusProcessing() onsigomegatypes.GomegaMatcher { return gomega.WithTransform( - func(n *v1alpha1.NATS) string { + func(n *nmapiv1alpha1.NATS) string { return n.Status.State - }, gomega.Equal(v1alpha1.StateProcessing)) + }, gomega.Equal(nmapiv1alpha1.StateProcessing)) } -func HaveStatusError() gomegatypes.GomegaMatcher { +func HaveStatusError() onsigomegatypes.GomegaMatcher { return gomega.WithTransform( - func(n *v1alpha1.NATS) string { + func(n *nmapiv1alpha1.NATS) string { return n.Status.State - }, gomega.Equal(v1alpha1.StateError)) + }, gomega.Equal(nmapiv1alpha1.StateError)) } -func HaveCondition(condition metav1.Condition) gomegatypes.GomegaMatcher { +func HaveCondition(condition kmetav1.Condition) onsigomegatypes.GomegaMatcher { return gomega.WithTransform( - func(n *v1alpha1.NATS) []metav1.Condition { + func(n *nmapiv1alpha1.NATS) []kmetav1.Condition { return n.Status.Conditions }, gomega.ContainElement(gstruct.MatchFields(gstruct.IgnoreExtras|gstruct.IgnoreMissing, gstruct.Fields{ @@ -134,9 +134,9 @@ func HaveCondition(condition metav1.Condition) gomegatypes.GomegaMatcher { }))) } -func HaveEvent(event corev1.Event) gomegatypes.GomegaMatcher { +func HaveEvent(event kcorev1.Event) onsigomegatypes.GomegaMatcher { return gomega.WithTransform( - func(l corev1.EventList) []corev1.Event { + func(l kcorev1.EventList) []kcorev1.Event { return l.Items }, gomega.ContainElement(gstruct.MatchFields(gstruct.IgnoreExtras|gstruct.IgnoreMissing, gstruct.Fields{ "Reason": gomega.Equal(event.Reason), @@ -145,80 +145,80 @@ func HaveEvent(event corev1.Event) gomegatypes.GomegaMatcher { }))) } -func HaveDeployedEvent() gomegatypes.GomegaMatcher { - return HaveEvent(corev1.Event{ - Reason: string(v1alpha1.ConditionReasonDeployed), +func HaveDeployedEvent() onsigomegatypes.GomegaMatcher { + return HaveEvent(kcorev1.Event{ + Reason: string(nmapiv1alpha1.ConditionReasonDeployed), Message: "StatefulSet is ready and NATS is deployed.", - Type: corev1.EventTypeNormal, + Type: kcorev1.EventTypeNormal, }) } -func HaveDeployingEvent() gomegatypes.GomegaMatcher { - return HaveEvent(corev1.Event{ - Reason: string(v1alpha1.ConditionReasonDeploying), +func HaveDeployingEvent() onsigomegatypes.GomegaMatcher { + return HaveEvent(kcorev1.Event{ + Reason: string(nmapiv1alpha1.ConditionReasonDeploying), Message: "NATS is being deployed, waiting for StatefulSet to get ready.", - Type: corev1.EventTypeNormal, + Type: kcorev1.EventTypeNormal, }) } -func HaveProcessingEvent() gomegatypes.GomegaMatcher { - return HaveEvent(corev1.Event{ - Reason: string(v1alpha1.ConditionReasonProcessing), +func HaveProcessingEvent() onsigomegatypes.GomegaMatcher { + return HaveEvent(kcorev1.Event{ + Reason: string(nmapiv1alpha1.ConditionReasonProcessing), Message: "Initializing NATS resource.", - Type: corev1.EventTypeNormal, + Type: kcorev1.EventTypeNormal, }) } -func HaveReadyConditionStatefulSet() gomegatypes.GomegaMatcher { - return HaveCondition(metav1.Condition{ - Type: string(v1alpha1.ConditionStatefulSet), - Status: metav1.ConditionTrue, - Reason: string(v1alpha1.ConditionReasonStatefulSetAvailable), +func HaveReadyConditionStatefulSet() onsigomegatypes.GomegaMatcher { + return HaveCondition(kmetav1.Condition{ + Type: string(nmapiv1alpha1.ConditionStatefulSet), + Status: kmetav1.ConditionTrue, + Reason: string(nmapiv1alpha1.ConditionReasonStatefulSetAvailable), Message: "StatefulSet is ready", }) } -func HavePendingConditionStatefulSet() gomegatypes.GomegaMatcher { - return HaveCondition(metav1.Condition{ - Type: string(v1alpha1.ConditionStatefulSet), - Status: metav1.ConditionFalse, - Reason: string(v1alpha1.ConditionReasonStatefulSetPending), +func HavePendingConditionStatefulSet() onsigomegatypes.GomegaMatcher { + return HaveCondition(kmetav1.Condition{ + Type: string(nmapiv1alpha1.ConditionStatefulSet), + Status: kmetav1.ConditionFalse, + Reason: string(nmapiv1alpha1.ConditionReasonStatefulSetPending), Message: "", }) } -func HaveForbiddenConditionStatefulSet() gomegatypes.GomegaMatcher { - return HaveCondition(metav1.Condition{ - Type: string(v1alpha1.ConditionStatefulSet), - Status: metav1.ConditionFalse, - Reason: string(v1alpha1.ConditionReasonForbidden), +func HaveForbiddenConditionStatefulSet() onsigomegatypes.GomegaMatcher { + return HaveCondition(kmetav1.Condition{ + Type: string(nmapiv1alpha1.ConditionStatefulSet), + Status: kmetav1.ConditionFalse, + Reason: string(nmapiv1alpha1.ConditionReasonForbidden), Message: "", }) } -func HaveReadyConditionAvailable() gomegatypes.GomegaMatcher { - return HaveCondition(metav1.Condition{ - Type: string(v1alpha1.ConditionAvailable), - Status: metav1.ConditionTrue, - Reason: string(v1alpha1.ConditionReasonDeployed), +func HaveReadyConditionAvailable() onsigomegatypes.GomegaMatcher { + return HaveCondition(kmetav1.Condition{ + Type: string(nmapiv1alpha1.ConditionAvailable), + Status: kmetav1.ConditionTrue, + Reason: string(nmapiv1alpha1.ConditionReasonDeployed), Message: "NATS is deployed", }) } -func HaveDeployingConditionAvailable() gomegatypes.GomegaMatcher { - return HaveCondition(metav1.Condition{ - Type: string(v1alpha1.ConditionAvailable), - Status: metav1.ConditionFalse, - Reason: string(v1alpha1.ConditionReasonDeploying), +func HaveDeployingConditionAvailable() onsigomegatypes.GomegaMatcher { + return HaveCondition(kmetav1.Condition{ + Type: string(nmapiv1alpha1.ConditionAvailable), + Status: kmetav1.ConditionFalse, + Reason: string(nmapiv1alpha1.ConditionReasonDeploying), Message: "", }) } -func HaveForbiddenConditionAvailableWithMsg(msg string) gomegatypes.GomegaMatcher { - return HaveCondition(metav1.Condition{ - Type: string(v1alpha1.ConditionAvailable), - Status: metav1.ConditionFalse, - Reason: string(v1alpha1.ConditionReasonForbidden), +func HaveForbiddenConditionAvailableWithMsg(msg string) onsigomegatypes.GomegaMatcher { + return HaveCondition(kmetav1.Condition{ + Type: string(nmapiv1alpha1.ConditionAvailable), + Status: kmetav1.ConditionFalse, + Reason: string(nmapiv1alpha1.ConditionReasonForbidden), Message: msg, }) } diff --git a/testutils/options.go b/testutils/options.go index ef381d29..66322ece 100644 --- a/testutils/options.go +++ b/testutils/options.go @@ -3,29 +3,29 @@ package testutils import ( "errors" - corev1 "k8s.io/api/core/v1" + kcorev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" - "github.com/kyma-project/nats-manager/api/v1alpha1" + nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" ) type Option func(*unstructured.Unstructured) error -type NATSOption func(*v1alpha1.NATS) error +type NATSOption func(*nmapiv1alpha1.NATS) error func WithNATSCRDefaults() NATSOption { - return func(nats *v1alpha1.NATS) error { - nats.Spec = v1alpha1.NATSSpec{ - Cluster: v1alpha1.Cluster{ + return func(nats *nmapiv1alpha1.NATS) error { + nats.Spec = nmapiv1alpha1.NATSSpec{ + Cluster: nmapiv1alpha1.Cluster{ Size: 1, }, - JetStream: v1alpha1.JetStream{ - MemStorage: v1alpha1.MemStorage{ + JetStream: nmapiv1alpha1.JetStream{ + MemStorage: nmapiv1alpha1.MemStorage{ Enabled: false, }, - FileStorage: v1alpha1.FileStorage{ + FileStorage: nmapiv1alpha1.FileStorage{ StorageClassName: "default", Size: resource.MustParse("1Gi"), }, @@ -126,120 +126,120 @@ func WithStatefulSetStatusReadyReplicas(replicas int) Option { } func WithNATSCRFinalizer(finalizer string) NATSOption { - return func(nats *v1alpha1.NATS) error { + return func(nats *nmapiv1alpha1.NATS) error { controllerutil.AddFinalizer(nats, finalizer) return nil } } func WithNATSCRStatusInitialized() NATSOption { - return func(nats *v1alpha1.NATS) error { + return func(nats *nmapiv1alpha1.NATS) error { nats.Status.Initialize() return nil } } func WithNATSStateReady() NATSOption { - return func(nats *v1alpha1.NATS) error { - nats.Status.State = v1alpha1.StateReady + return func(nats *nmapiv1alpha1.NATS) error { + nats.Status.State = nmapiv1alpha1.StateReady return nil } } func WithNATSStateWarning() NATSOption { - return func(nats *v1alpha1.NATS) error { - nats.Status.State = v1alpha1.StateWarning + return func(nats *nmapiv1alpha1.NATS) error { + nats.Status.State = nmapiv1alpha1.StateWarning return nil } } func WithNATSStateProcessing() NATSOption { - return func(nats *v1alpha1.NATS) error { - nats.Status.State = v1alpha1.StateProcessing + return func(nats *nmapiv1alpha1.NATS) error { + nats.Status.State = nmapiv1alpha1.StateProcessing return nil } } func WithNATSStateError() NATSOption { - return func(nats *v1alpha1.NATS) error { - nats.Status.State = v1alpha1.StateError + return func(nats *nmapiv1alpha1.NATS) error { + nats.Status.State = nmapiv1alpha1.StateError return nil } } func WithNATSCRName(name string) NATSOption { - return func(nats *v1alpha1.NATS) error { + return func(nats *nmapiv1alpha1.NATS) error { nats.Name = name return nil } } func WithNATSCRNamespace(namespace string) NATSOption { - return func(nats *v1alpha1.NATS) error { + return func(nats *nmapiv1alpha1.NATS) error { nats.Namespace = namespace return nil } } func WithNATSEmptySpec() NATSOption { - return func(nats *v1alpha1.NATS) error { - nats.Spec = v1alpha1.NATSSpec{} + return func(nats *nmapiv1alpha1.NATS) error { + nats.Spec = nmapiv1alpha1.NATSSpec{} return nil } } func WithNATSClusterSize(size int) NATSOption { - return func(nats *v1alpha1.NATS) error { + return func(nats *nmapiv1alpha1.NATS) error { nats.Spec.Cluster.Size = size return nil } } func WithNATSLogging(debug, trace bool) NATSOption { - return func(nats *v1alpha1.NATS) error { + return func(nats *nmapiv1alpha1.NATS) error { nats.Spec.Logging.Debug = debug nats.Spec.Logging.Trace = trace return nil } } -func WithNATSMemStorage(memStorage v1alpha1.MemStorage) NATSOption { - return func(nats *v1alpha1.NATS) error { +func WithNATSMemStorage(memStorage nmapiv1alpha1.MemStorage) NATSOption { + return func(nats *nmapiv1alpha1.NATS) error { nats.Spec.JetStream.MemStorage = memStorage return nil } } -func WithNATSFileStorage(fileStorage v1alpha1.FileStorage) NATSOption { - return func(nats *v1alpha1.NATS) error { +func WithNATSFileStorage(fileStorage nmapiv1alpha1.FileStorage) NATSOption { + return func(nats *nmapiv1alpha1.NATS) error { nats.Spec.JetStream.FileStorage = fileStorage return nil } } -func WithNATSCluster(cluster v1alpha1.Cluster) NATSOption { - return func(nats *v1alpha1.NATS) error { +func WithNATSCluster(cluster nmapiv1alpha1.Cluster) NATSOption { + return func(nats *nmapiv1alpha1.NATS) error { nats.Spec.Cluster = cluster return nil } } func WithNATSLabels(labels map[string]string) NATSOption { - return func(nats *v1alpha1.NATS) error { + return func(nats *nmapiv1alpha1.NATS) error { nats.Spec.Labels = labels return nil } } func WithNATSAnnotations(annotations map[string]string) NATSOption { - return func(nats *v1alpha1.NATS) error { + return func(nats *nmapiv1alpha1.NATS) error { nats.Spec.Annotations = annotations return nil } } -func WithNATSResources(resources corev1.ResourceRequirements) NATSOption { - return func(nats *v1alpha1.NATS) error { +func WithNATSResources(resources kcorev1.ResourceRequirements) NATSOption { + return func(nats *nmapiv1alpha1.NATS) error { nats.Spec.Resources = resources return nil } diff --git a/testutils/utils.go b/testutils/utils.go index 68773676..f6e432d2 100644 --- a/testutils/utils.go +++ b/testutils/utils.go @@ -11,14 +11,14 @@ import ( "go.uber.org/zap" "go.uber.org/zap/zapcore" - appsv1 "k8s.io/api/apps/v1" - apiv1 "k8s.io/api/core/v1" - apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + kappsv1 "k8s.io/api/apps/v1" + kcorev1 "k8s.io/api/core/v1" + kapiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" + kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" - "github.com/kyma-project/nats-manager/api/v1alpha1" + nmapiv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1" ) const ( @@ -52,13 +52,13 @@ func GetRandK8sName(length int) string { return fmt.Sprintf("name-%s", GetRandString(length)) } -func NewNamespace(name string) *apiv1.Namespace { - namespace := apiv1.Namespace{ - TypeMeta: metav1.TypeMeta{ +func NewNamespace(name string) *kcorev1.Namespace { + namespace := kcorev1.Namespace{ + TypeMeta: kmetav1.TypeMeta{ Kind: "Namespace", APIVersion: "v1", }, - ObjectMeta: metav1.ObjectMeta{ + ObjectMeta: kmetav1.ObjectMeta{ Name: name, }, } @@ -122,8 +122,8 @@ func NewSecretUnStruct(opts ...Option) *unstructured.Unstructured { return obj } -func NewSecret(opts ...Option) *apiv1.Secret { - sampleSecret := apiv1.Secret{} +func NewSecret(opts ...Option) *kcorev1.Secret { + sampleSecret := kcorev1.Secret{} err := runtime.DefaultUnstructuredConverter.FromUnstructured( NewSecretUnStruct(opts...).UnstructuredContent(), &sampleSecret) if err != nil { @@ -132,17 +132,17 @@ func NewSecret(opts ...Option) *apiv1.Secret { return &sampleSecret } -func NewNATSCR(opts ...NATSOption) *v1alpha1.NATS { +func NewNATSCR(opts ...NATSOption) *nmapiv1alpha1.NATS { name := fmt.Sprintf(NameFormat, GetRandString(randomNameLen)) namespace := fmt.Sprintf(NamespaceFormat, GetRandString(randomNameLen)) - nats := &v1alpha1.NATS{ + nats := &nmapiv1alpha1.NATS{ // Name, UUID, Kind, APIVersion - TypeMeta: metav1.TypeMeta{ + TypeMeta: kmetav1.TypeMeta{ APIVersion: "v1alpha1", Kind: "NATS", }, - ObjectMeta: metav1.ObjectMeta{ + ObjectMeta: kmetav1.ObjectMeta{ Name: name, Namespace: namespace, UID: "1234-5678-1234-5678", @@ -158,17 +158,17 @@ func NewNATSCR(opts ...NATSOption) *v1alpha1.NATS { return nats } -func NewDestinationRuleCRD() *apiextensionsv1.CustomResourceDefinition { - result := &apiextensionsv1.CustomResourceDefinition{ - TypeMeta: metav1.TypeMeta{ +func NewDestinationRuleCRD() *kapiextv1.CustomResourceDefinition { + result := &kapiextv1.CustomResourceDefinition{ + TypeMeta: kmetav1.TypeMeta{ APIVersion: "apiextensions.k8s.io/v1", Kind: "CustomResourceDefinition", }, - ObjectMeta: metav1.ObjectMeta{ + ObjectMeta: kmetav1.ObjectMeta{ Name: "destinationrules.networking.istio.io", }, - Spec: apiextensionsv1.CustomResourceDefinitionSpec{ - Names: apiextensionsv1.CustomResourceDefinitionNames{}, + Spec: kapiextv1.CustomResourceDefinitionSpec{ + Names: kapiextv1.CustomResourceDefinitionNames{}, Scope: "Namespaced", PreserveUnknownFields: false, }, @@ -177,31 +177,31 @@ func NewDestinationRuleCRD() *apiextensionsv1.CustomResourceDefinition { return result } -func GetStatefulSetName(nats v1alpha1.NATS) string { +func GetStatefulSetName(nats nmapiv1alpha1.NATS) string { return fmt.Sprintf(StatefulSetNameFormat, nats.GetName()) } -func GetConfigMapName(nats v1alpha1.NATS) string { +func GetConfigMapName(nats nmapiv1alpha1.NATS) string { return fmt.Sprintf(ConfigMapNameFormat, nats.Name) } -func GetSecretName(nats v1alpha1.NATS) string { +func GetSecretName(nats nmapiv1alpha1.NATS) string { return fmt.Sprintf(SecretNameFormat, nats.Name) } -func GetServiceName(nats v1alpha1.NATS) string { +func GetServiceName(nats nmapiv1alpha1.NATS) string { return fmt.Sprintf(ServiceNameFormat, nats.Name) } -func GetPodDisruptionBudgetName(nats v1alpha1.NATS) string { +func GetPodDisruptionBudgetName(nats nmapiv1alpha1.NATS) string { return fmt.Sprintf(PodDisruptionBudgetNameFormat, nats.Name) } -func GetDestinationRuleName(nats v1alpha1.NATS) string { +func GetDestinationRuleName(nats nmapiv1alpha1.NATS) string { return fmt.Sprintf(DestinationRuleNameFormat, nats.Name) } -func FindContainer(containers []apiv1.Container, name string) *apiv1.Container { +func FindContainer(containers []kcorev1.Container, name string) *kcorev1.Container { for _, container := range containers { if container.Name == name { return &container @@ -219,27 +219,27 @@ func GetDestinationRuleGVR() schema.GroupVersionResource { } // NewPVC creates a new PVC object with the given name, namespace, and label. -func NewPVC(name, namespace string, labels map[string]string) *apiv1.PersistentVolumeClaim { - return &apiv1.PersistentVolumeClaim{ - ObjectMeta: metav1.ObjectMeta{ +func NewPVC(name, namespace string, labels map[string]string) *kcorev1.PersistentVolumeClaim { + return &kcorev1.PersistentVolumeClaim{ + ObjectMeta: kmetav1.ObjectMeta{ Name: name, Namespace: namespace, Labels: labels, }, - Spec: apiv1.PersistentVolumeClaimSpec{ - AccessModes: []apiv1.PersistentVolumeAccessMode{apiv1.ReadWriteOnce}, - Resources: apiv1.VolumeResourceRequirements{ - Requests: apiv1.ResourceList{ - apiv1.ResourceStorage: resource.MustParse("1Gi"), + Spec: kcorev1.PersistentVolumeClaimSpec{ + AccessModes: []kcorev1.PersistentVolumeAccessMode{kcorev1.ReadWriteOnce}, + Resources: kcorev1.VolumeResourceRequirements{ + Requests: kcorev1.ResourceList{ + kcorev1.ResourceStorage: resource.MustParse("1Gi"), }, }, }, } } -func NewStatefulSet(name, namespace string, labels map[string]string) *appsv1.StatefulSet { - return &appsv1.StatefulSet{ - ObjectMeta: metav1.ObjectMeta{ +func NewStatefulSet(name, namespace string, labels map[string]string) *kappsv1.StatefulSet { + return &kappsv1.StatefulSet{ + ObjectMeta: kmetav1.ObjectMeta{ Name: name, Namespace: namespace, Labels: labels,