diff --git a/Makefile b/Makefile index b70f699..29371bb 100644 --- a/Makefile +++ b/Makefile @@ -3,34 +3,15 @@ IMG ?= redis-operator:latest # K8s version used by envtest ENVTEST_K8S_VERSION = 1.26.1 -# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) -ifeq (,$(shell go env GOBIN)) -GOBIN=$(shell go env GOPATH)/bin -else -GOBIN=$(shell go env GOBIN) -endif - -# Setting SHELL to bash allows bash commands to be executed by recipes. -# Options are set to exit when a recipe line exits non-zero or a piped command fails. -SHELL = /usr/bin/env bash -o pipefail -.SHELLFLAGS = -ec +# Set shell to bash +SHELL = /usr/bin/env bash +.SHELLFLAGS = -o pipefail -ec .PHONY: all all: build ##@ General -# The help target prints out all targets with their descriptions organized -# beneath their categories. The categories are represented by '##@' and the -# target descriptions by '##'. The awk command is responsible for reading the -# entire set of makefiles included in this invocation, looking for lines of the -# file as xyz: ## something, and then pretty-format the target and help. Then, -# if there's a line with ##@ something, that gets pretty-printed as a category. -# More info on the usage of ANSI control characters for terminal formatting: -# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters -# More info on the awk command: -# http://linuxcommand.org/lc3_adv_awk.php - .PHONY: help help: ## Display this help. @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) @@ -39,12 +20,17 @@ help: ## Display this help. .PHONY: manifests manifests: controller-gen ## Generate CustomResourceDefinition objects. - $(CONTROLLER_GEN) crd paths="./api/..." output:crd:artifacts:config=crds + $(CONTROLLER_GEN) crd paths="./api/..." output:crd:artifacts:config=crds ;\ + test ! -d chart || test -e chart/crds || ln -s ../crds chart/crds .PHONY: generate generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations. $(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./api/..." +.PHONY: generate-client +generate-client: client-gen informer-gen lister-gen ## Generate typed client. + ./hack/genclient.sh + .PHONY: fmt fmt: ## Run go fmt against code. go fmt ./... @@ -83,13 +69,10 @@ docker-push: ## Push docker image with the manager. PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le .PHONY: docker-buildx docker-buildx: ## Build and push docker image for the manager for cross-platform support. - # copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile - sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross - docker buildx create --name project-v3-builder docker buildx use project-v3-builder - - docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross . + - docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} . - docker buildx rm project-v3-builder - rm Dockerfile.cross ##@ Build Dependencies @@ -100,10 +83,14 @@ $(LOCALBIN): ## Tool Binaries CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen +CLIENT_GEN ?= $(LOCALBIN)/client-gen +INFORMER_GEN ?= $(LOCALBIN)/informer-gen +LISTER_GEN ?= $(LOCALBIN)/lister-gen SETUP_ENVTEST ?= $(LOCALBIN)/setup-envtest ## Tool Versions CONTROLLER_TOOLS_VERSION ?= v0.9.2 +CODE_GENERATOR_VERSION ?= v0.27.3 SETUP_ENVTEST_VERSION ?= latest .PHONY: controller-gen @@ -111,6 +98,21 @@ controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessar $(CONTROLLER_GEN): $(LOCALBIN) test -s $(LOCALBIN)/controller-gen || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION) +.PHONY: client-gen +client-gen: $(CLIENT_GEN) ## Download client-gen locally if necessary. +$(CLIENT_GEN): $(LOCALBIN) + test -s $(LOCALBIN)/client-gen || GOBIN=$(LOCALBIN) go install k8s.io/code-generator/cmd/client-gen@$(CODE_GENERATOR_VERSION) + +.PHONY: informer-gen +informer-gen: $(INFORMER_GEN) ## Download informer-gen locally if necessary. +$(INFORMER_GEN): $(LOCALBIN) + test -s $(LOCALBIN)/informer-gen || GOBIN=$(LOCALBIN) go install k8s.io/code-generator/cmd/informer-gen@$(CODE_GENERATOR_VERSION) + +.PHONY: lister-gen +lister-gen: $(LISTER_GEN) ## Download lister-gen locally if necessary. +$(LISTER_GEN): $(LOCALBIN) + test -s $(LOCALBIN)/lister-gen || GOBIN=$(LOCALBIN) go install k8s.io/code-generator/cmd/lister-gen@$(CODE_GENERATOR_VERSION) + .PHONY: setup-envtest setup-envtest: $(SETUP_ENVTEST) ## Download setup-envtest locally if necessary. $(SETUP_ENVTEST): $(LOCALBIN) diff --git a/api/v1alpha1/groupversion_info.go b/api/v1alpha1/groupversion_info.go index d88784a..d5d5947 100644 --- a/api/v1alpha1/groupversion_info.go +++ b/api/v1alpha1/groupversion_info.go @@ -22,4 +22,12 @@ var ( // AddToScheme adds the types in this group-version to the given scheme. AddToScheme = SchemeBuilder.AddToScheme + + // Needed by kubernetes/code-generator + SchemeGroupVersion = GroupVersion ) + +// Needed by kubernetes/code-generator. +func Resource(resource string) schema.GroupResource { + return GroupVersion.WithResource(resource).GroupResource() +} diff --git a/api/v1alpha1/types.go b/api/v1alpha1/types.go index 43b93d7..8a2cdef 100644 --- a/api/v1alpha1/types.go +++ b/api/v1alpha1/types.go @@ -80,6 +80,7 @@ type RedisStatus struct { // +kubebuilder:subresource:status // +kubebuilder:printcolumn:name="State",type=string,JSONPath=`.status.state` // +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp" +// +genclient // Redis is the Schema for the redis API type Redis struct { diff --git a/go.mod b/go.mod index dab04d9..372733a 100644 --- a/go.mod +++ b/go.mod @@ -11,14 +11,14 @@ require ( github.com/pkg/errors v0.9.1 github.com/redis/go-redis/v9 v9.0.5 github.com/sap/admission-webhook-runtime v0.1.0 - github.com/sap/component-operator-runtime v0.1.3 + github.com/sap/component-operator-runtime v0.1.4 github.com/sap/go-generics v0.1.1 golang.org/x/mod v0.10.0 - k8s.io/api v0.27.2 - k8s.io/apiextensions-apiserver v0.27.2 - k8s.io/apimachinery v0.27.2 - k8s.io/client-go v0.27.2 - k8s.io/kube-aggregator v0.27.2 + k8s.io/api v0.27.3 + k8s.io/apiextensions-apiserver v0.27.3 + k8s.io/apimachinery v0.27.3 + k8s.io/client-go v0.27.3 + k8s.io/kube-aggregator v0.27.3 sigs.k8s.io/controller-runtime v0.15.0 sigs.k8s.io/yaml v1.3.0 ) @@ -88,7 +88,7 @@ require ( gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect - k8s.io/component-base v0.27.2 // indirect + k8s.io/component-base v0.27.3 // indirect k8s.io/klog/v2 v2.100.1 // indirect k8s.io/kube-openapi v0.0.0-20230515203736-54b630e78af5 // indirect k8s.io/utils v0.0.0-20230505201702-9f6742963106 // indirect diff --git a/go.sum b/go.sum index 2949f31..9c6feae 100644 --- a/go.sum +++ b/go.sum @@ -179,8 +179,8 @@ github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6L github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= github.com/sap/admission-webhook-runtime v0.1.0 h1:9dSdV83D4Rl8LLNtLUSGIMO8tP9M7PMDoWGKnWQlvdE= github.com/sap/admission-webhook-runtime v0.1.0/go.mod h1:cDEoEgPYViopO39tvICpGUhbIxzNiZkkZGLXyfrvh/0= -github.com/sap/component-operator-runtime v0.1.3 h1:QePHQKf5vk92L6/tI9feFPKajpnqgeqvcMLam1iEpNM= -github.com/sap/component-operator-runtime v0.1.3/go.mod h1:lsiy/74HxGc+x6+LZG0qd1K80vS57VZPHbRlfke/dBo= +github.com/sap/component-operator-runtime v0.1.4 h1:oB4KTrBx/+Dm9EQE5FCRDXEXSyHzOpdv1SGPKhCsqP4= +github.com/sap/component-operator-runtime v0.1.4/go.mod h1:5cMR7EGRQBv+/dhzNDiKTibvklTyZVYTfSbuone8edk= github.com/sap/go-generics v0.1.1 h1:3T4McSGF5epH8Yp4bbxD07oa5J0pH7Nfx4r4zwdsr4o= github.com/sap/go-generics v0.1.1/go.mod h1:8L5jyDKi/FHKG/R+qwyy9h1TymA7XO5YSu+J/27gTCg= github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= @@ -375,20 +375,20 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -k8s.io/api v0.27.2 h1:+H17AJpUMvl+clT+BPnKf0E3ksMAzoBBg7CntpSuADo= -k8s.io/api v0.27.2/go.mod h1:ENmbocXfBT2ADujUXcBhHV55RIT31IIEvkntP6vZKS4= -k8s.io/apiextensions-apiserver v0.27.2 h1:iwhyoeS4xj9Y7v8YExhUwbVuBhMr3Q4bd/laClBV6Bo= -k8s.io/apiextensions-apiserver v0.27.2/go.mod h1:Oz9UdvGguL3ULgRdY9QMUzL2RZImotgxvGjdWRq6ZXQ= -k8s.io/apimachinery v0.27.2 h1:vBjGaKKieaIreI+oQwELalVG4d8f3YAMNpWLzDXkxeg= -k8s.io/apimachinery v0.27.2/go.mod h1:XNfZ6xklnMCOGGFNqXG7bUrQCoR04dh/E7FprV6pb+E= -k8s.io/client-go v0.27.2 h1:vDLSeuYvCHKeoQRhCXjxXO45nHVv2Ip4Fe0MfioMrhE= -k8s.io/client-go v0.27.2/go.mod h1:tY0gVmUsHrAmjzHX9zs7eCjxcBsf8IiNe7KQ52biTcQ= -k8s.io/component-base v0.27.2 h1:neju+7s/r5O4x4/txeUONNTS9r1HsPbyoPBAtHsDCpo= -k8s.io/component-base v0.27.2/go.mod h1:5UPk7EjfgrfgRIuDBFtsEFAe4DAvP3U+M8RTzoSJkpo= +k8s.io/api v0.27.3 h1:yR6oQXXnUEBWEWcvPWS0jQL575KoAboQPfJAuKNrw5Y= +k8s.io/api v0.27.3/go.mod h1:C4BNvZnQOF7JA/0Xed2S+aUyJSfTGkGFxLXz9MnpIpg= +k8s.io/apiextensions-apiserver v0.27.3 h1:xAwC1iYabi+TDfpRhxh4Eapl14Hs2OftM2DN5MpgKX4= +k8s.io/apiextensions-apiserver v0.27.3/go.mod h1:BH3wJ5NsB9XE1w+R6SSVpKmYNyIiyIz9xAmBl8Mb+84= +k8s.io/apimachinery v0.27.3 h1:Ubye8oBufD04l9QnNtW05idcOe9Z3GQN8+7PqmuVcUM= +k8s.io/apimachinery v0.27.3/go.mod h1:XNfZ6xklnMCOGGFNqXG7bUrQCoR04dh/E7FprV6pb+E= +k8s.io/client-go v0.27.3 h1:7dnEGHZEJld3lYwxvLl7WoehK6lAq7GvgjxpA3nv1E8= +k8s.io/client-go v0.27.3/go.mod h1:2MBEKuTo6V1lbKy3z1euEGnhPfGZLKTS9tiJ2xodM48= +k8s.io/component-base v0.27.3 h1:g078YmdcdTfrCE4fFobt7qmVXwS8J/3cI1XxRi/2+6k= +k8s.io/component-base v0.27.3/go.mod h1:JNiKYcGImpQ44iwSYs6dysxzR9SxIIgQalk4HaCNVUY= k8s.io/klog/v2 v2.100.1 h1:7WCHKK6K8fNhTqfBhISHQ97KrnJNFZMcQvKp7gP/tmg= k8s.io/klog/v2 v2.100.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0= -k8s.io/kube-aggregator v0.27.2 h1:jfHoPip+qN/fn3OcrYs8/xMuVYvkJHKo0H0DYciqdns= -k8s.io/kube-aggregator v0.27.2/go.mod h1:mwrTt4ESjQ7A6847biwohgZWn8P/KzSFHegEScbSGY4= +k8s.io/kube-aggregator v0.27.3 h1:0o/Q30C84hHvhUef7OOTHMhO2eCySOPHKOUUrhBwpfo= +k8s.io/kube-aggregator v0.27.3/go.mod h1:zbx67NbFee9cqjbXjib89/oOyrXdOq3UYStIBGazv08= k8s.io/kube-openapi v0.0.0-20230515203736-54b630e78af5 h1:azYPdzztXxPSa8wb+hksEKayiz0o+PPisO/d+QhWnoo= k8s.io/kube-openapi v0.0.0-20230515203736-54b630e78af5/go.mod h1:kzo02I3kQ4BTtEfVLaPbjvCkX97YqGve33wzlb3fofQ= k8s.io/utils v0.0.0-20230505201702-9f6742963106 h1:EObNQ3TW2D+WptiYXlApGNLVy0zm/JIBVY9i+M4wpAU= diff --git a/hack/genclient.sh b/hack/genclient.sh new file mode 100755 index 0000000..e8ff83d --- /dev/null +++ b/hack/genclient.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash + +set -eo pipefail + +export GOROOT=$(go env GOROOT) + +BASEDIR=$(realpath $(dirname "$0")/..) +TEMPDIR=$BASEDIR/tmp/gen +trap 'rm -rf "$TEMPDIR"' EXIT +mkdir -p "$TEMPDIR" + +mkdir -p "$TEMPDIR"/apis/cache.cs.sap.com +ln -s "$BASEDIR"/api/v1alpha1 "$TEMPDIR"/apis/cache.cs.sap.com/v1alpha1 + +"$BASEDIR"/bin/client-gen \ + --clientset-name versioned \ + --input-base "" \ + --input github.com/sap/redis-operator/tmp/gen/apis/cache.cs.sap.com/v1alpha1 \ + --go-header-file "$BASEDIR"/hack/boilerplate.go.txt \ + --output-package github.com/sap/redis-operator/pkg/client/clientset \ + --output-base "$TEMPDIR"/pkg/client \ + --plural-exceptions Redis:redis + +"$BASEDIR"/bin/lister-gen \ + --input-dirs github.com/sap/redis-operator/tmp/gen/apis/cache.cs.sap.com/v1alpha1 \ + --go-header-file "$BASEDIR"/hack/boilerplate.go.txt \ + --output-package github.com/sap/redis-operator/pkg/client/listers \ + --output-base "$TEMPDIR"/pkg/client \ + --plural-exceptions Redis:redis + +"$BASEDIR"/bin/informer-gen \ + --input-dirs github.com/sap/redis-operator/tmp/gen/apis/cache.cs.sap.com/v1alpha1 \ + --versioned-clientset-package github.com/sap/redis-operator/pkg/client/clientset/versioned \ + --listers-package github.com/sap/redis-operator/pkg/client/listers \ + --go-header-file "$BASEDIR"/hack/boilerplate.go.txt \ + --output-package github.com/sap/redis-operator/pkg/client/informers \ + --output-base "$TEMPDIR"/pkg/client \ + --plural-exceptions Redis:redis + +find "$TEMPDIR"/pkg/client -name "*.go" -exec \ + perl -pi -e "s#github\.com/sap/redis-operator/tmp/gen/apis/cache\.cs\.sap\.com/v1alpha1#github.com/sap/redis-operator/api/v1alpha1#g" \ + {} + + +rm -rf "$BASEDIR"/pkg/client +mv "$TEMPDIR"/pkg/client/github.com/sap/redis-operator/pkg/client "$BASEDIR"/pkg + +cd "$BASEDIR" +go fmt ./pkg/client/... +go vet ./pkg/client/... diff --git a/pkg/client/clientset/versioned/clientset.go b/pkg/client/clientset/versioned/clientset.go new file mode 100644 index 0000000..ca8a5bf --- /dev/null +++ b/pkg/client/clientset/versioned/clientset.go @@ -0,0 +1,109 @@ +/* +SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and redis-operator contributors +SPDX-License-Identifier: Apache-2.0 +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package versioned + +import ( + "fmt" + "net/http" + + cachev1alpha1 "github.com/sap/redis-operator/pkg/client/clientset/versioned/typed/cache.cs.sap.com/v1alpha1" + discovery "k8s.io/client-go/discovery" + rest "k8s.io/client-go/rest" + flowcontrol "k8s.io/client-go/util/flowcontrol" +) + +type Interface interface { + Discovery() discovery.DiscoveryInterface + CacheV1alpha1() cachev1alpha1.CacheV1alpha1Interface +} + +// Clientset contains the clients for groups. +type Clientset struct { + *discovery.DiscoveryClient + cacheV1alpha1 *cachev1alpha1.CacheV1alpha1Client +} + +// CacheV1alpha1 retrieves the CacheV1alpha1Client +func (c *Clientset) CacheV1alpha1() cachev1alpha1.CacheV1alpha1Interface { + return c.cacheV1alpha1 +} + +// Discovery retrieves the DiscoveryClient +func (c *Clientset) Discovery() discovery.DiscoveryInterface { + if c == nil { + return nil + } + return c.DiscoveryClient +} + +// NewForConfig creates a new Clientset for the given config. +// If config's RateLimiter is not set and QPS and Burst are acceptable, +// NewForConfig will generate a rate-limiter in configShallowCopy. +// NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), +// where httpClient was generated with rest.HTTPClientFor(c). +func NewForConfig(c *rest.Config) (*Clientset, error) { + configShallowCopy := *c + + if configShallowCopy.UserAgent == "" { + configShallowCopy.UserAgent = rest.DefaultKubernetesUserAgent() + } + + // share the transport between all clients + httpClient, err := rest.HTTPClientFor(&configShallowCopy) + if err != nil { + return nil, err + } + + return NewForConfigAndClient(&configShallowCopy, httpClient) +} + +// NewForConfigAndClient creates a new Clientset for the given config and http client. +// Note the http client provided takes precedence over the configured transport values. +// If config's RateLimiter is not set and QPS and Burst are acceptable, +// NewForConfigAndClient will generate a rate-limiter in configShallowCopy. +func NewForConfigAndClient(c *rest.Config, httpClient *http.Client) (*Clientset, error) { + configShallowCopy := *c + if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 { + if configShallowCopy.Burst <= 0 { + return nil, fmt.Errorf("burst is required to be greater than 0 when RateLimiter is not set and QPS is set to greater than 0") + } + configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst) + } + + var cs Clientset + var err error + cs.cacheV1alpha1, err = cachev1alpha1.NewForConfigAndClient(&configShallowCopy, httpClient) + if err != nil { + return nil, err + } + + cs.DiscoveryClient, err = discovery.NewDiscoveryClientForConfigAndClient(&configShallowCopy, httpClient) + if err != nil { + return nil, err + } + return &cs, nil +} + +// NewForConfigOrDie creates a new Clientset for the given config and +// panics if there is an error in the config. +func NewForConfigOrDie(c *rest.Config) *Clientset { + cs, err := NewForConfig(c) + if err != nil { + panic(err) + } + return cs +} + +// New creates a new Clientset for the given RESTClient. +func New(c rest.Interface) *Clientset { + var cs Clientset + cs.cacheV1alpha1 = cachev1alpha1.New(c) + + cs.DiscoveryClient = discovery.NewDiscoveryClient(c) + return &cs +} diff --git a/pkg/client/clientset/versioned/fake/clientset_generated.go b/pkg/client/clientset/versioned/fake/clientset_generated.go new file mode 100644 index 0000000..2410a8c --- /dev/null +++ b/pkg/client/clientset/versioned/fake/clientset_generated.go @@ -0,0 +1,74 @@ +/* +SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and redis-operator contributors +SPDX-License-Identifier: Apache-2.0 +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + clientset "github.com/sap/redis-operator/pkg/client/clientset/versioned" + cachev1alpha1 "github.com/sap/redis-operator/pkg/client/clientset/versioned/typed/cache.cs.sap.com/v1alpha1" + fakecachev1alpha1 "github.com/sap/redis-operator/pkg/client/clientset/versioned/typed/cache.cs.sap.com/v1alpha1/fake" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/watch" + "k8s.io/client-go/discovery" + fakediscovery "k8s.io/client-go/discovery/fake" + "k8s.io/client-go/testing" +) + +// NewSimpleClientset returns a clientset that will respond with the provided objects. +// It's backed by a very simple object tracker that processes creates, updates and deletions as-is, +// without applying any validations and/or defaults. It shouldn't be considered a replacement +// for a real clientset and is mostly useful in simple unit tests. +func NewSimpleClientset(objects ...runtime.Object) *Clientset { + o := testing.NewObjectTracker(scheme, codecs.UniversalDecoder()) + for _, obj := range objects { + if err := o.Add(obj); err != nil { + panic(err) + } + } + + cs := &Clientset{tracker: o} + cs.discovery = &fakediscovery.FakeDiscovery{Fake: &cs.Fake} + cs.AddReactor("*", "*", testing.ObjectReaction(o)) + cs.AddWatchReactor("*", func(action testing.Action) (handled bool, ret watch.Interface, err error) { + gvr := action.GetResource() + ns := action.GetNamespace() + watch, err := o.Watch(gvr, ns) + if err != nil { + return false, nil, err + } + return true, watch, nil + }) + + return cs +} + +// Clientset implements clientset.Interface. Meant to be embedded into a +// struct to get a default implementation. This makes faking out just the method +// you want to test easier. +type Clientset struct { + testing.Fake + discovery *fakediscovery.FakeDiscovery + tracker testing.ObjectTracker +} + +func (c *Clientset) Discovery() discovery.DiscoveryInterface { + return c.discovery +} + +func (c *Clientset) Tracker() testing.ObjectTracker { + return c.tracker +} + +var ( + _ clientset.Interface = &Clientset{} + _ testing.FakeClient = &Clientset{} +) + +// CacheV1alpha1 retrieves the CacheV1alpha1Client +func (c *Clientset) CacheV1alpha1() cachev1alpha1.CacheV1alpha1Interface { + return &fakecachev1alpha1.FakeCacheV1alpha1{Fake: &c.Fake} +} diff --git a/pkg/client/clientset/versioned/fake/doc.go b/pkg/client/clientset/versioned/fake/doc.go new file mode 100644 index 0000000..bb98a59 --- /dev/null +++ b/pkg/client/clientset/versioned/fake/doc.go @@ -0,0 +1,9 @@ +/* +SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and redis-operator contributors +SPDX-License-Identifier: Apache-2.0 +*/ + +// Code generated by client-gen. DO NOT EDIT. + +// This package has the automatically generated fake clientset. +package fake diff --git a/pkg/client/clientset/versioned/fake/register.go b/pkg/client/clientset/versioned/fake/register.go new file mode 100644 index 0000000..68cbf6e --- /dev/null +++ b/pkg/client/clientset/versioned/fake/register.go @@ -0,0 +1,45 @@ +/* +SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and redis-operator contributors +SPDX-License-Identifier: Apache-2.0 +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + cachev1alpha1 "github.com/sap/redis-operator/api/v1alpha1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + schema "k8s.io/apimachinery/pkg/runtime/schema" + serializer "k8s.io/apimachinery/pkg/runtime/serializer" + utilruntime "k8s.io/apimachinery/pkg/util/runtime" +) + +var scheme = runtime.NewScheme() +var codecs = serializer.NewCodecFactory(scheme) + +var localSchemeBuilder = runtime.SchemeBuilder{ + cachev1alpha1.AddToScheme, +} + +// AddToScheme adds all types of this clientset into the given scheme. This allows composition +// of clientsets, like in: +// +// import ( +// "k8s.io/client-go/kubernetes" +// clientsetscheme "k8s.io/client-go/kubernetes/scheme" +// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" +// ) +// +// kclientset, _ := kubernetes.NewForConfig(c) +// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) +// +// After this, RawExtensions in Kubernetes types will serialize kube-aggregator types +// correctly. +var AddToScheme = localSchemeBuilder.AddToScheme + +func init() { + v1.AddToGroupVersion(scheme, schema.GroupVersion{Version: "v1"}) + utilruntime.Must(AddToScheme(scheme)) +} diff --git a/pkg/client/clientset/versioned/scheme/doc.go b/pkg/client/clientset/versioned/scheme/doc.go new file mode 100644 index 0000000..1d24477 --- /dev/null +++ b/pkg/client/clientset/versioned/scheme/doc.go @@ -0,0 +1,9 @@ +/* +SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and redis-operator contributors +SPDX-License-Identifier: Apache-2.0 +*/ + +// Code generated by client-gen. DO NOT EDIT. + +// This package contains the scheme of the automatically generated clientset. +package scheme diff --git a/pkg/client/clientset/versioned/scheme/register.go b/pkg/client/clientset/versioned/scheme/register.go new file mode 100644 index 0000000..d3a41ef --- /dev/null +++ b/pkg/client/clientset/versioned/scheme/register.go @@ -0,0 +1,45 @@ +/* +SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and redis-operator contributors +SPDX-License-Identifier: Apache-2.0 +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package scheme + +import ( + cachev1alpha1 "github.com/sap/redis-operator/api/v1alpha1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + schema "k8s.io/apimachinery/pkg/runtime/schema" + serializer "k8s.io/apimachinery/pkg/runtime/serializer" + utilruntime "k8s.io/apimachinery/pkg/util/runtime" +) + +var Scheme = runtime.NewScheme() +var Codecs = serializer.NewCodecFactory(Scheme) +var ParameterCodec = runtime.NewParameterCodec(Scheme) +var localSchemeBuilder = runtime.SchemeBuilder{ + cachev1alpha1.AddToScheme, +} + +// AddToScheme adds all types of this clientset into the given scheme. This allows composition +// of clientsets, like in: +// +// import ( +// "k8s.io/client-go/kubernetes" +// clientsetscheme "k8s.io/client-go/kubernetes/scheme" +// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" +// ) +// +// kclientset, _ := kubernetes.NewForConfig(c) +// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) +// +// After this, RawExtensions in Kubernetes types will serialize kube-aggregator types +// correctly. +var AddToScheme = localSchemeBuilder.AddToScheme + +func init() { + v1.AddToGroupVersion(Scheme, schema.GroupVersion{Version: "v1"}) + utilruntime.Must(AddToScheme(Scheme)) +} diff --git a/pkg/client/clientset/versioned/typed/cache.cs.sap.com/v1alpha1/cache.cs.sap.com_client.go b/pkg/client/clientset/versioned/typed/cache.cs.sap.com/v1alpha1/cache.cs.sap.com_client.go new file mode 100644 index 0000000..b05277a --- /dev/null +++ b/pkg/client/clientset/versioned/typed/cache.cs.sap.com/v1alpha1/cache.cs.sap.com_client.go @@ -0,0 +1,96 @@ +/* +SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and redis-operator contributors +SPDX-License-Identifier: Apache-2.0 +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + "net/http" + + v1alpha1 "github.com/sap/redis-operator/api/v1alpha1" + "github.com/sap/redis-operator/pkg/client/clientset/versioned/scheme" + rest "k8s.io/client-go/rest" +) + +type CacheV1alpha1Interface interface { + RESTClient() rest.Interface + RedisGetter +} + +// CacheV1alpha1Client is used to interact with features provided by the cache.cs.sap.com group. +type CacheV1alpha1Client struct { + restClient rest.Interface +} + +func (c *CacheV1alpha1Client) Redis(namespace string) RedisInterface { + return newRedis(c, namespace) +} + +// NewForConfig creates a new CacheV1alpha1Client for the given config. +// NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), +// where httpClient was generated with rest.HTTPClientFor(c). +func NewForConfig(c *rest.Config) (*CacheV1alpha1Client, error) { + config := *c + if err := setConfigDefaults(&config); err != nil { + return nil, err + } + httpClient, err := rest.HTTPClientFor(&config) + if err != nil { + return nil, err + } + return NewForConfigAndClient(&config, httpClient) +} + +// NewForConfigAndClient creates a new CacheV1alpha1Client for the given config and http client. +// Note the http client provided takes precedence over the configured transport values. +func NewForConfigAndClient(c *rest.Config, h *http.Client) (*CacheV1alpha1Client, error) { + config := *c + if err := setConfigDefaults(&config); err != nil { + return nil, err + } + client, err := rest.RESTClientForConfigAndClient(&config, h) + if err != nil { + return nil, err + } + return &CacheV1alpha1Client{client}, nil +} + +// NewForConfigOrDie creates a new CacheV1alpha1Client for the given config and +// panics if there is an error in the config. +func NewForConfigOrDie(c *rest.Config) *CacheV1alpha1Client { + client, err := NewForConfig(c) + if err != nil { + panic(err) + } + return client +} + +// New creates a new CacheV1alpha1Client for the given RESTClient. +func New(c rest.Interface) *CacheV1alpha1Client { + return &CacheV1alpha1Client{c} +} + +func setConfigDefaults(config *rest.Config) error { + gv := v1alpha1.SchemeGroupVersion + config.GroupVersion = &gv + config.APIPath = "/apis" + config.NegotiatedSerializer = scheme.Codecs.WithoutConversion() + + if config.UserAgent == "" { + config.UserAgent = rest.DefaultKubernetesUserAgent() + } + + return nil +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *CacheV1alpha1Client) RESTClient() rest.Interface { + if c == nil { + return nil + } + return c.restClient +} diff --git a/pkg/client/clientset/versioned/typed/cache.cs.sap.com/v1alpha1/doc.go b/pkg/client/clientset/versioned/typed/cache.cs.sap.com/v1alpha1/doc.go new file mode 100644 index 0000000..dda849f --- /dev/null +++ b/pkg/client/clientset/versioned/typed/cache.cs.sap.com/v1alpha1/doc.go @@ -0,0 +1,9 @@ +/* +SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and redis-operator contributors +SPDX-License-Identifier: Apache-2.0 +*/ + +// Code generated by client-gen. DO NOT EDIT. + +// This package has the automatically generated typed clients. +package v1alpha1 diff --git a/pkg/client/clientset/versioned/typed/cache.cs.sap.com/v1alpha1/fake/doc.go b/pkg/client/clientset/versioned/typed/cache.cs.sap.com/v1alpha1/fake/doc.go new file mode 100644 index 0000000..097fc30 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/cache.cs.sap.com/v1alpha1/fake/doc.go @@ -0,0 +1,9 @@ +/* +SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and redis-operator contributors +SPDX-License-Identifier: Apache-2.0 +*/ + +// Code generated by client-gen. DO NOT EDIT. + +// Package fake has the automatically generated clients. +package fake diff --git a/pkg/client/clientset/versioned/typed/cache.cs.sap.com/v1alpha1/fake/fake_cache.cs.sap.com_client.go b/pkg/client/clientset/versioned/typed/cache.cs.sap.com/v1alpha1/fake/fake_cache.cs.sap.com_client.go new file mode 100644 index 0000000..8d5e261 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/cache.cs.sap.com/v1alpha1/fake/fake_cache.cs.sap.com_client.go @@ -0,0 +1,29 @@ +/* +SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and redis-operator contributors +SPDX-License-Identifier: Apache-2.0 +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + v1alpha1 "github.com/sap/redis-operator/pkg/client/clientset/versioned/typed/cache.cs.sap.com/v1alpha1" + rest "k8s.io/client-go/rest" + testing "k8s.io/client-go/testing" +) + +type FakeCacheV1alpha1 struct { + *testing.Fake +} + +func (c *FakeCacheV1alpha1) Redis(namespace string) v1alpha1.RedisInterface { + return &FakeRedis{c, namespace} +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *FakeCacheV1alpha1) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret +} diff --git a/pkg/client/clientset/versioned/typed/cache.cs.sap.com/v1alpha1/fake/fake_redis.go b/pkg/client/clientset/versioned/typed/cache.cs.sap.com/v1alpha1/fake/fake_redis.go new file mode 100644 index 0000000..6ba1372 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/cache.cs.sap.com/v1alpha1/fake/fake_redis.go @@ -0,0 +1,130 @@ +/* +SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and redis-operator contributors +SPDX-License-Identifier: Apache-2.0 +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + "context" + + v1alpha1 "github.com/sap/redis-operator/api/v1alpha1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + testing "k8s.io/client-go/testing" +) + +// FakeRedis implements RedisInterface +type FakeRedis struct { + Fake *FakeCacheV1alpha1 + ns string +} + +var redisResource = v1alpha1.SchemeGroupVersion.WithResource("redis") + +var redisKind = v1alpha1.SchemeGroupVersion.WithKind("Redis") + +// Get takes name of the redis, and returns the corresponding redis object, and an error if there is any. +func (c *FakeRedis) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.Redis, err error) { + obj, err := c.Fake. + Invokes(testing.NewGetAction(redisResource, c.ns, name), &v1alpha1.Redis{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Redis), err +} + +// List takes label and field selectors, and returns the list of Redis that match those selectors. +func (c *FakeRedis) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.RedisList, err error) { + obj, err := c.Fake. + Invokes(testing.NewListAction(redisResource, redisKind, c.ns, opts), &v1alpha1.RedisList{}) + + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1alpha1.RedisList{ListMeta: obj.(*v1alpha1.RedisList).ListMeta} + for _, item := range obj.(*v1alpha1.RedisList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +// Watch returns a watch.Interface that watches the requested redis. +func (c *FakeRedis) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewWatchAction(redisResource, c.ns, opts)) + +} + +// Create takes the representation of a redis and creates it. Returns the server's representation of the redis, and an error, if there is any. +func (c *FakeRedis) Create(ctx context.Context, redis *v1alpha1.Redis, opts v1.CreateOptions) (result *v1alpha1.Redis, err error) { + obj, err := c.Fake. + Invokes(testing.NewCreateAction(redisResource, c.ns, redis), &v1alpha1.Redis{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Redis), err +} + +// Update takes the representation of a redis and updates it. Returns the server's representation of the redis, and an error, if there is any. +func (c *FakeRedis) Update(ctx context.Context, redis *v1alpha1.Redis, opts v1.UpdateOptions) (result *v1alpha1.Redis, err error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateAction(redisResource, c.ns, redis), &v1alpha1.Redis{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Redis), err +} + +// UpdateStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). +func (c *FakeRedis) UpdateStatus(ctx context.Context, redis *v1alpha1.Redis, opts v1.UpdateOptions) (*v1alpha1.Redis, error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateSubresourceAction(redisResource, "status", c.ns, redis), &v1alpha1.Redis{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Redis), err +} + +// Delete takes name of the redis and deletes it. Returns an error if one occurs. +func (c *FakeRedis) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewDeleteActionWithOptions(redisResource, c.ns, name, opts), &v1alpha1.Redis{}) + + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeRedis) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + action := testing.NewDeleteCollectionAction(redisResource, c.ns, listOpts) + + _, err := c.Fake.Invokes(action, &v1alpha1.RedisList{}) + return err +} + +// Patch applies the patch and returns the patched redis. +func (c *FakeRedis) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.Redis, err error) { + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceAction(redisResource, c.ns, name, pt, data, subresources...), &v1alpha1.Redis{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Redis), err +} diff --git a/pkg/client/clientset/versioned/typed/cache.cs.sap.com/v1alpha1/generated_expansion.go b/pkg/client/clientset/versioned/typed/cache.cs.sap.com/v1alpha1/generated_expansion.go new file mode 100644 index 0000000..75cf7d3 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/cache.cs.sap.com/v1alpha1/generated_expansion.go @@ -0,0 +1,10 @@ +/* +SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and redis-operator contributors +SPDX-License-Identifier: Apache-2.0 +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package v1alpha1 + +type RedisExpansion interface{} diff --git a/pkg/client/clientset/versioned/typed/cache.cs.sap.com/v1alpha1/redis.go b/pkg/client/clientset/versioned/typed/cache.cs.sap.com/v1alpha1/redis.go new file mode 100644 index 0000000..ecb5626 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/cache.cs.sap.com/v1alpha1/redis.go @@ -0,0 +1,184 @@ +/* +SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and redis-operator contributors +SPDX-License-Identifier: Apache-2.0 +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + "context" + "time" + + v1alpha1 "github.com/sap/redis-operator/api/v1alpha1" + scheme "github.com/sap/redis-operator/pkg/client/clientset/versioned/scheme" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + rest "k8s.io/client-go/rest" +) + +// RedisGetter has a method to return a RedisInterface. +// A group's client should implement this interface. +type RedisGetter interface { + Redis(namespace string) RedisInterface +} + +// RedisInterface has methods to work with Redis resources. +type RedisInterface interface { + Create(ctx context.Context, redis *v1alpha1.Redis, opts v1.CreateOptions) (*v1alpha1.Redis, error) + Update(ctx context.Context, redis *v1alpha1.Redis, opts v1.UpdateOptions) (*v1alpha1.Redis, error) + UpdateStatus(ctx context.Context, redis *v1alpha1.Redis, opts v1.UpdateOptions) (*v1alpha1.Redis, error) + Delete(ctx context.Context, name string, opts v1.DeleteOptions) error + DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error + Get(ctx context.Context, name string, opts v1.GetOptions) (*v1alpha1.Redis, error) + List(ctx context.Context, opts v1.ListOptions) (*v1alpha1.RedisList, error) + Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) + Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.Redis, err error) + RedisExpansion +} + +// redis implements RedisInterface +type redis struct { + client rest.Interface + ns string +} + +// newRedis returns a Redis +func newRedis(c *CacheV1alpha1Client, namespace string) *redis { + return &redis{ + client: c.RESTClient(), + ns: namespace, + } +} + +// Get takes name of the redis, and returns the corresponding redis object, and an error if there is any. +func (c *redis) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.Redis, err error) { + result = &v1alpha1.Redis{} + err = c.client.Get(). + Namespace(c.ns). + Resource("redis"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(ctx). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of Redis that match those selectors. +func (c *redis) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.RedisList, err error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + result = &v1alpha1.RedisList{} + err = c.client.Get(). + Namespace(c.ns). + Resource("redis"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Do(ctx). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested redis. +func (c *redis) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + opts.Watch = true + return c.client.Get(). + Namespace(c.ns). + Resource("redis"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Watch(ctx) +} + +// Create takes the representation of a redis and creates it. Returns the server's representation of the redis, and an error, if there is any. +func (c *redis) Create(ctx context.Context, redis *v1alpha1.Redis, opts v1.CreateOptions) (result *v1alpha1.Redis, err error) { + result = &v1alpha1.Redis{} + err = c.client.Post(). + Namespace(c.ns). + Resource("redis"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(redis). + Do(ctx). + Into(result) + return +} + +// Update takes the representation of a redis and updates it. Returns the server's representation of the redis, and an error, if there is any. +func (c *redis) Update(ctx context.Context, redis *v1alpha1.Redis, opts v1.UpdateOptions) (result *v1alpha1.Redis, err error) { + result = &v1alpha1.Redis{} + err = c.client.Put(). + Namespace(c.ns). + Resource("redis"). + Name(redis.Name). + VersionedParams(&opts, scheme.ParameterCodec). + Body(redis). + Do(ctx). + Into(result) + return +} + +// UpdateStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). +func (c *redis) UpdateStatus(ctx context.Context, redis *v1alpha1.Redis, opts v1.UpdateOptions) (result *v1alpha1.Redis, err error) { + result = &v1alpha1.Redis{} + err = c.client.Put(). + Namespace(c.ns). + Resource("redis"). + Name(redis.Name). + SubResource("status"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(redis). + Do(ctx). + Into(result) + return +} + +// Delete takes name of the redis and deletes it. Returns an error if one occurs. +func (c *redis) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("redis"). + Name(name). + Body(&opts). + Do(ctx). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *redis) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + var timeout time.Duration + if listOpts.TimeoutSeconds != nil { + timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second + } + return c.client.Delete(). + Namespace(c.ns). + Resource("redis"). + VersionedParams(&listOpts, scheme.ParameterCodec). + Timeout(timeout). + Body(&opts). + Do(ctx). + Error() +} + +// Patch applies the patch and returns the patched redis. +func (c *redis) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.Redis, err error) { + result = &v1alpha1.Redis{} + err = c.client.Patch(pt). + Namespace(c.ns). + Resource("redis"). + Name(name). + SubResource(subresources...). + VersionedParams(&opts, scheme.ParameterCodec). + Body(data). + Do(ctx). + Into(result) + return +} diff --git a/pkg/client/informers/externalversions/cache.cs.sap.com/interface.go b/pkg/client/informers/externalversions/cache.cs.sap.com/interface.go new file mode 100644 index 0000000..f75f039 --- /dev/null +++ b/pkg/client/informers/externalversions/cache.cs.sap.com/interface.go @@ -0,0 +1,35 @@ +/* +SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and redis-operator contributors +SPDX-License-Identifier: Apache-2.0 +*/ + +// Code generated by informer-gen. DO NOT EDIT. + +package cache + +import ( + v1alpha1 "github.com/sap/redis-operator/pkg/client/informers/externalversions/cache.cs.sap.com/v1alpha1" + internalinterfaces "github.com/sap/redis-operator/pkg/client/informers/externalversions/internalinterfaces" +) + +// Interface provides access to each of this group's versions. +type Interface interface { + // V1alpha1 provides access to shared informers for resources in V1alpha1. + V1alpha1() v1alpha1.Interface +} + +type group struct { + factory internalinterfaces.SharedInformerFactory + namespace string + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// New returns a new Interface. +func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { + return &group{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} +} + +// V1alpha1 returns a new v1alpha1.Interface. +func (g *group) V1alpha1() v1alpha1.Interface { + return v1alpha1.New(g.factory, g.namespace, g.tweakListOptions) +} diff --git a/pkg/client/informers/externalversions/cache.cs.sap.com/v1alpha1/interface.go b/pkg/client/informers/externalversions/cache.cs.sap.com/v1alpha1/interface.go new file mode 100644 index 0000000..0074e97 --- /dev/null +++ b/pkg/client/informers/externalversions/cache.cs.sap.com/v1alpha1/interface.go @@ -0,0 +1,34 @@ +/* +SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and redis-operator contributors +SPDX-License-Identifier: Apache-2.0 +*/ + +// Code generated by informer-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + internalinterfaces "github.com/sap/redis-operator/pkg/client/informers/externalversions/internalinterfaces" +) + +// Interface provides access to all the informers in this group version. +type Interface interface { + // Redis returns a RedisInformer. + Redis() RedisInformer +} + +type version struct { + factory internalinterfaces.SharedInformerFactory + namespace string + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// New returns a new Interface. +func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { + return &version{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} +} + +// Redis returns a RedisInformer. +func (v *version) Redis() RedisInformer { + return &redisInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} diff --git a/pkg/client/informers/externalversions/cache.cs.sap.com/v1alpha1/redis.go b/pkg/client/informers/externalversions/cache.cs.sap.com/v1alpha1/redis.go new file mode 100644 index 0000000..b0997dc --- /dev/null +++ b/pkg/client/informers/externalversions/cache.cs.sap.com/v1alpha1/redis.go @@ -0,0 +1,79 @@ +/* +SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and redis-operator contributors +SPDX-License-Identifier: Apache-2.0 +*/ + +// Code generated by informer-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + "context" + time "time" + + cachecssapcomv1alpha1 "github.com/sap/redis-operator/api/v1alpha1" + versioned "github.com/sap/redis-operator/pkg/client/clientset/versioned" + internalinterfaces "github.com/sap/redis-operator/pkg/client/informers/externalversions/internalinterfaces" + v1alpha1 "github.com/sap/redis-operator/pkg/client/listers/cache.cs.sap.com/v1alpha1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" +) + +// RedisInformer provides access to a shared informer and lister for +// Redis. +type RedisInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1alpha1.RedisLister +} + +type redisInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// NewRedisInformer constructs a new informer for Redis type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewRedisInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredRedisInformer(client, namespace, resyncPeriod, indexers, nil) +} + +// NewFilteredRedisInformer constructs a new informer for Redis type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFilteredRedisInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.CacheV1alpha1().Redis(namespace).List(context.TODO(), options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.CacheV1alpha1().Redis(namespace).Watch(context.TODO(), options) + }, + }, + &cachecssapcomv1alpha1.Redis{}, + resyncPeriod, + indexers, + ) +} + +func (f *redisInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredRedisInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *redisInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&cachecssapcomv1alpha1.Redis{}, f.defaultInformer) +} + +func (f *redisInformer) Lister() v1alpha1.RedisLister { + return v1alpha1.NewRedisLister(f.Informer().GetIndexer()) +} diff --git a/pkg/client/informers/externalversions/factory.go b/pkg/client/informers/externalversions/factory.go new file mode 100644 index 0000000..09494cb --- /dev/null +++ b/pkg/client/informers/externalversions/factory.go @@ -0,0 +1,240 @@ +/* +SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and redis-operator contributors +SPDX-License-Identifier: Apache-2.0 +*/ + +// Code generated by informer-gen. DO NOT EDIT. + +package externalversions + +import ( + reflect "reflect" + sync "sync" + time "time" + + versioned "github.com/sap/redis-operator/pkg/client/clientset/versioned" + cachecssapcom "github.com/sap/redis-operator/pkg/client/informers/externalversions/cache.cs.sap.com" + internalinterfaces "github.com/sap/redis-operator/pkg/client/informers/externalversions/internalinterfaces" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + schema "k8s.io/apimachinery/pkg/runtime/schema" + cache "k8s.io/client-go/tools/cache" +) + +// SharedInformerOption defines the functional option type for SharedInformerFactory. +type SharedInformerOption func(*sharedInformerFactory) *sharedInformerFactory + +type sharedInformerFactory struct { + client versioned.Interface + namespace string + tweakListOptions internalinterfaces.TweakListOptionsFunc + lock sync.Mutex + defaultResync time.Duration + customResync map[reflect.Type]time.Duration + + informers map[reflect.Type]cache.SharedIndexInformer + // startedInformers is used for tracking which informers have been started. + // This allows Start() to be called multiple times safely. + startedInformers map[reflect.Type]bool + // wg tracks how many goroutines were started. + wg sync.WaitGroup + // shuttingDown is true when Shutdown has been called. It may still be running + // because it needs to wait for goroutines. + shuttingDown bool +} + +// WithCustomResyncConfig sets a custom resync period for the specified informer types. +func WithCustomResyncConfig(resyncConfig map[v1.Object]time.Duration) SharedInformerOption { + return func(factory *sharedInformerFactory) *sharedInformerFactory { + for k, v := range resyncConfig { + factory.customResync[reflect.TypeOf(k)] = v + } + return factory + } +} + +// WithTweakListOptions sets a custom filter on all listers of the configured SharedInformerFactory. +func WithTweakListOptions(tweakListOptions internalinterfaces.TweakListOptionsFunc) SharedInformerOption { + return func(factory *sharedInformerFactory) *sharedInformerFactory { + factory.tweakListOptions = tweakListOptions + return factory + } +} + +// WithNamespace limits the SharedInformerFactory to the specified namespace. +func WithNamespace(namespace string) SharedInformerOption { + return func(factory *sharedInformerFactory) *sharedInformerFactory { + factory.namespace = namespace + return factory + } +} + +// NewSharedInformerFactory constructs a new instance of sharedInformerFactory for all namespaces. +func NewSharedInformerFactory(client versioned.Interface, defaultResync time.Duration) SharedInformerFactory { + return NewSharedInformerFactoryWithOptions(client, defaultResync) +} + +// NewFilteredSharedInformerFactory constructs a new instance of sharedInformerFactory. +// Listers obtained via this SharedInformerFactory will be subject to the same filters +// as specified here. +// Deprecated: Please use NewSharedInformerFactoryWithOptions instead +func NewFilteredSharedInformerFactory(client versioned.Interface, defaultResync time.Duration, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) SharedInformerFactory { + return NewSharedInformerFactoryWithOptions(client, defaultResync, WithNamespace(namespace), WithTweakListOptions(tweakListOptions)) +} + +// NewSharedInformerFactoryWithOptions constructs a new instance of a SharedInformerFactory with additional options. +func NewSharedInformerFactoryWithOptions(client versioned.Interface, defaultResync time.Duration, options ...SharedInformerOption) SharedInformerFactory { + factory := &sharedInformerFactory{ + client: client, + namespace: v1.NamespaceAll, + defaultResync: defaultResync, + informers: make(map[reflect.Type]cache.SharedIndexInformer), + startedInformers: make(map[reflect.Type]bool), + customResync: make(map[reflect.Type]time.Duration), + } + + // Apply all options + for _, opt := range options { + factory = opt(factory) + } + + return factory +} + +func (f *sharedInformerFactory) Start(stopCh <-chan struct{}) { + f.lock.Lock() + defer f.lock.Unlock() + + if f.shuttingDown { + return + } + + for informerType, informer := range f.informers { + if !f.startedInformers[informerType] { + f.wg.Add(1) + // We need a new variable in each loop iteration, + // otherwise the goroutine would use the loop variable + // and that keeps changing. + informer := informer + go func() { + defer f.wg.Done() + informer.Run(stopCh) + }() + f.startedInformers[informerType] = true + } + } +} + +func (f *sharedInformerFactory) Shutdown() { + f.lock.Lock() + f.shuttingDown = true + f.lock.Unlock() + + // Will return immediately if there is nothing to wait for. + f.wg.Wait() +} + +func (f *sharedInformerFactory) WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool { + informers := func() map[reflect.Type]cache.SharedIndexInformer { + f.lock.Lock() + defer f.lock.Unlock() + + informers := map[reflect.Type]cache.SharedIndexInformer{} + for informerType, informer := range f.informers { + if f.startedInformers[informerType] { + informers[informerType] = informer + } + } + return informers + }() + + res := map[reflect.Type]bool{} + for informType, informer := range informers { + res[informType] = cache.WaitForCacheSync(stopCh, informer.HasSynced) + } + return res +} + +// InternalInformerFor returns the SharedIndexInformer for obj using an internal +// client. +func (f *sharedInformerFactory) InformerFor(obj runtime.Object, newFunc internalinterfaces.NewInformerFunc) cache.SharedIndexInformer { + f.lock.Lock() + defer f.lock.Unlock() + + informerType := reflect.TypeOf(obj) + informer, exists := f.informers[informerType] + if exists { + return informer + } + + resyncPeriod, exists := f.customResync[informerType] + if !exists { + resyncPeriod = f.defaultResync + } + + informer = newFunc(f.client, resyncPeriod) + f.informers[informerType] = informer + + return informer +} + +// SharedInformerFactory provides shared informers for resources in all known +// API group versions. +// +// It is typically used like this: +// +// ctx, cancel := context.Background() +// defer cancel() +// factory := NewSharedInformerFactory(client, resyncPeriod) +// defer factory.WaitForStop() // Returns immediately if nothing was started. +// genericInformer := factory.ForResource(resource) +// typedInformer := factory.SomeAPIGroup().V1().SomeType() +// factory.Start(ctx.Done()) // Start processing these informers. +// synced := factory.WaitForCacheSync(ctx.Done()) +// for v, ok := range synced { +// if !ok { +// fmt.Fprintf(os.Stderr, "caches failed to sync: %v", v) +// return +// } +// } +// +// // Creating informers can also be created after Start, but then +// // Start must be called again: +// anotherGenericInformer := factory.ForResource(resource) +// factory.Start(ctx.Done()) +type SharedInformerFactory interface { + internalinterfaces.SharedInformerFactory + + // Start initializes all requested informers. They are handled in goroutines + // which run until the stop channel gets closed. + Start(stopCh <-chan struct{}) + + // Shutdown marks a factory as shutting down. At that point no new + // informers can be started anymore and Start will return without + // doing anything. + // + // In addition, Shutdown blocks until all goroutines have terminated. For that + // to happen, the close channel(s) that they were started with must be closed, + // either before Shutdown gets called or while it is waiting. + // + // Shutdown may be called multiple times, even concurrently. All such calls will + // block until all goroutines have terminated. + Shutdown() + + // WaitForCacheSync blocks until all started informers' caches were synced + // or the stop channel gets closed. + WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool + + // ForResource gives generic access to a shared informer of the matching type. + ForResource(resource schema.GroupVersionResource) (GenericInformer, error) + + // InternalInformerFor returns the SharedIndexInformer for obj using an internal + // client. + InformerFor(obj runtime.Object, newFunc internalinterfaces.NewInformerFunc) cache.SharedIndexInformer + + Cache() cachecssapcom.Interface +} + +func (f *sharedInformerFactory) Cache() cachecssapcom.Interface { + return cachecssapcom.New(f, f.namespace, f.tweakListOptions) +} diff --git a/pkg/client/informers/externalversions/generic.go b/pkg/client/informers/externalversions/generic.go new file mode 100644 index 0000000..bf3fc19 --- /dev/null +++ b/pkg/client/informers/externalversions/generic.go @@ -0,0 +1,51 @@ +/* +SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and redis-operator contributors +SPDX-License-Identifier: Apache-2.0 +*/ + +// Code generated by informer-gen. DO NOT EDIT. + +package externalversions + +import ( + "fmt" + + v1alpha1 "github.com/sap/redis-operator/api/v1alpha1" + schema "k8s.io/apimachinery/pkg/runtime/schema" + cache "k8s.io/client-go/tools/cache" +) + +// GenericInformer is type of SharedIndexInformer which will locate and delegate to other +// sharedInformers based on type +type GenericInformer interface { + Informer() cache.SharedIndexInformer + Lister() cache.GenericLister +} + +type genericInformer struct { + informer cache.SharedIndexInformer + resource schema.GroupResource +} + +// Informer returns the SharedIndexInformer. +func (f *genericInformer) Informer() cache.SharedIndexInformer { + return f.informer +} + +// Lister returns the GenericLister. +func (f *genericInformer) Lister() cache.GenericLister { + return cache.NewGenericLister(f.Informer().GetIndexer(), f.resource) +} + +// ForResource gives generic access to a shared informer of the matching type +// TODO extend this to unknown resources with a client pool +func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) { + switch resource { + // Group=cache.cs.sap.com, Version=v1alpha1 + case v1alpha1.SchemeGroupVersion.WithResource("redis"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Cache().V1alpha1().Redis().Informer()}, nil + + } + + return nil, fmt.Errorf("no informer found for %v", resource) +} diff --git a/pkg/client/informers/externalversions/internalinterfaces/factory_interfaces.go b/pkg/client/informers/externalversions/internalinterfaces/factory_interfaces.go new file mode 100644 index 0000000..3ac618c --- /dev/null +++ b/pkg/client/informers/externalversions/internalinterfaces/factory_interfaces.go @@ -0,0 +1,29 @@ +/* +SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and redis-operator contributors +SPDX-License-Identifier: Apache-2.0 +*/ + +// Code generated by informer-gen. DO NOT EDIT. + +package internalinterfaces + +import ( + time "time" + + versioned "github.com/sap/redis-operator/pkg/client/clientset/versioned" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + cache "k8s.io/client-go/tools/cache" +) + +// NewInformerFunc takes versioned.Interface and time.Duration to return a SharedIndexInformer. +type NewInformerFunc func(versioned.Interface, time.Duration) cache.SharedIndexInformer + +// SharedInformerFactory a small interface to allow for adding an informer without an import cycle +type SharedInformerFactory interface { + Start(stopCh <-chan struct{}) + InformerFor(obj runtime.Object, newFunc NewInformerFunc) cache.SharedIndexInformer +} + +// TweakListOptionsFunc is a function that transforms a v1.ListOptions. +type TweakListOptionsFunc func(*v1.ListOptions) diff --git a/pkg/client/listers/cache.cs.sap.com/v1alpha1/expansion_generated.go b/pkg/client/listers/cache.cs.sap.com/v1alpha1/expansion_generated.go new file mode 100644 index 0000000..f8263b5 --- /dev/null +++ b/pkg/client/listers/cache.cs.sap.com/v1alpha1/expansion_generated.go @@ -0,0 +1,16 @@ +/* +SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and redis-operator contributors +SPDX-License-Identifier: Apache-2.0 +*/ + +// Code generated by lister-gen. DO NOT EDIT. + +package v1alpha1 + +// RedisListerExpansion allows custom methods to be added to +// RedisLister. +type RedisListerExpansion interface{} + +// RedisNamespaceListerExpansion allows custom methods to be added to +// RedisNamespaceLister. +type RedisNamespaceListerExpansion interface{} diff --git a/pkg/client/listers/cache.cs.sap.com/v1alpha1/redis.go b/pkg/client/listers/cache.cs.sap.com/v1alpha1/redis.go new file mode 100644 index 0000000..a3a402a --- /dev/null +++ b/pkg/client/listers/cache.cs.sap.com/v1alpha1/redis.go @@ -0,0 +1,88 @@ +/* +SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and redis-operator contributors +SPDX-License-Identifier: Apache-2.0 +*/ + +// Code generated by lister-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + v1alpha1 "github.com/sap/redis-operator/api/v1alpha1" + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" +) + +// RedisLister helps list Redis. +// All objects returned here must be treated as read-only. +type RedisLister interface { + // List lists all Redis in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1alpha1.Redis, err error) + // Redis returns an object that can list and get Redis. + Redis(namespace string) RedisNamespaceLister + RedisListerExpansion +} + +// redisLister implements the RedisLister interface. +type redisLister struct { + indexer cache.Indexer +} + +// NewRedisLister returns a new RedisLister. +func NewRedisLister(indexer cache.Indexer) RedisLister { + return &redisLister{indexer: indexer} +} + +// List lists all Redis in the indexer. +func (s *redisLister) List(selector labels.Selector) (ret []*v1alpha1.Redis, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha1.Redis)) + }) + return ret, err +} + +// Redis returns an object that can list and get Redis. +func (s *redisLister) Redis(namespace string) RedisNamespaceLister { + return redisNamespaceLister{indexer: s.indexer, namespace: namespace} +} + +// RedisNamespaceLister helps list and get Redis. +// All objects returned here must be treated as read-only. +type RedisNamespaceLister interface { + // List lists all Redis in the indexer for a given namespace. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1alpha1.Redis, err error) + // Get retrieves the Redis from the indexer for a given namespace and name. + // Objects returned here must be treated as read-only. + Get(name string) (*v1alpha1.Redis, error) + RedisNamespaceListerExpansion +} + +// redisNamespaceLister implements the RedisNamespaceLister +// interface. +type redisNamespaceLister struct { + indexer cache.Indexer + namespace string +} + +// List lists all Redis in the indexer for a given namespace. +func (s redisNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.Redis, err error) { + err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha1.Redis)) + }) + return ret, err +} + +// Get retrieves the Redis from the indexer for a given namespace and name. +func (s redisNamespaceLister) Get(name string) (*v1alpha1.Redis, error) { + obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1alpha1.Resource("redis"), name) + } + return obj.(*v1alpha1.Redis), nil +}