From 27b745ee07aa9fc0d5dae0437465c77e22dcc8ec Mon Sep 17 00:00:00 2001 From: Federico Paolinelli Date: Fri, 5 Jul 2024 13:39:32 +0200 Subject: [PATCH] API: generate code-gen style helpers As the FRR-K8s api is meant to be consumed by other controllers, we export the helpers so a pre-controller runtime controller can consume it. Note: the "core" symlink is to get around https://github.com/kubernetes/code-generator/issues/167 Signed-off-by: Federico Paolinelli --- api/v1beta1/frrconfiguration_types.go | 2 + api/v1beta1/groupversion_info.go | 6 + core | 1 + go.mod | 1 + hack/boilerplate.go.txt | 16 +- hack/update-codegen.sh | 108 ++++++++ pkg/client/clientset/versioned/clientset.go | 106 ++++++++ .../versioned/fake/clientset_generated.go | 71 +++++ pkg/client/clientset/versioned/fake/doc.go | 6 + .../clientset/versioned/fake/register.go | 42 +++ pkg/client/clientset/versioned/scheme/doc.go | 6 + .../clientset/versioned/scheme/register.go | 42 +++ .../typed/core/v1beta1/core_client.go | 93 +++++++ .../versioned/typed/core/v1beta1/doc.go | 6 + .../versioned/typed/core/v1beta1/fake/doc.go | 6 + .../core/v1beta1/fake/fake_core_client.go | 26 ++ .../v1beta1/fake/fake_frrconfiguration.go | 127 +++++++++ .../typed/core/v1beta1/frrconfiguration.go | 181 +++++++++++++ .../typed/core/v1beta1/generated_expansion.go | 7 + .../externalversions/core/interface.go | 32 +++ .../core/v1beta1/frrconfiguration.go | 76 ++++++ .../core/v1beta1/interface.go | 31 +++ .../informers/externalversions/factory.go | 247 ++++++++++++++++++ .../informers/externalversions/generic.go | 48 ++++ .../internalinterfaces/factory_interfaces.go | 26 ++ .../core/v1beta1/expansion_generated.go | 13 + .../listers/core/v1beta1/frrconfiguration.go | 85 ++++++ 27 files changed, 1396 insertions(+), 15 deletions(-) create mode 120000 core create mode 100755 hack/update-codegen.sh create mode 100644 pkg/client/clientset/versioned/clientset.go create mode 100644 pkg/client/clientset/versioned/fake/clientset_generated.go create mode 100644 pkg/client/clientset/versioned/fake/doc.go create mode 100644 pkg/client/clientset/versioned/fake/register.go create mode 100644 pkg/client/clientset/versioned/scheme/doc.go create mode 100644 pkg/client/clientset/versioned/scheme/register.go create mode 100644 pkg/client/clientset/versioned/typed/core/v1beta1/core_client.go create mode 100644 pkg/client/clientset/versioned/typed/core/v1beta1/doc.go create mode 100644 pkg/client/clientset/versioned/typed/core/v1beta1/fake/doc.go create mode 100644 pkg/client/clientset/versioned/typed/core/v1beta1/fake/fake_core_client.go create mode 100644 pkg/client/clientset/versioned/typed/core/v1beta1/fake/fake_frrconfiguration.go create mode 100644 pkg/client/clientset/versioned/typed/core/v1beta1/frrconfiguration.go create mode 100644 pkg/client/clientset/versioned/typed/core/v1beta1/generated_expansion.go create mode 100644 pkg/client/informers/externalversions/core/interface.go create mode 100644 pkg/client/informers/externalversions/core/v1beta1/frrconfiguration.go create mode 100644 pkg/client/informers/externalversions/core/v1beta1/interface.go create mode 100644 pkg/client/informers/externalversions/factory.go create mode 100644 pkg/client/informers/externalversions/generic.go create mode 100644 pkg/client/informers/externalversions/internalinterfaces/factory_interfaces.go create mode 100644 pkg/client/listers/core/v1beta1/expansion_generated.go create mode 100644 pkg/client/listers/core/v1beta1/frrconfiguration.go diff --git a/api/v1beta1/frrconfiguration_types.go b/api/v1beta1/frrconfiguration_types.go index d9afb8b0..90ea90d7 100644 --- a/api/v1beta1/frrconfiguration_types.go +++ b/api/v1beta1/frrconfiguration_types.go @@ -307,6 +307,8 @@ type FRRConfigurationStatus struct { //+kubebuilder:object:root=true //+kubebuilder:subresource:status +//nolint +//+genclient // FRRConfiguration is a piece of FRR configuration. type FRRConfiguration struct { diff --git a/api/v1beta1/groupversion_info.go b/api/v1beta1/groupversion_info.go index 985870a0..987dda84 100644 --- a/api/v1beta1/groupversion_info.go +++ b/api/v1beta1/groupversion_info.go @@ -34,3 +34,9 @@ var ( // AddToScheme adds the types in this group-version to the given scheme. AddToScheme = SchemeBuilder.AddToScheme ) + +var SchemeGroupVersion = schema.GroupVersion{Group: "frrk8s.metallb.io", Version: "v1beta1"} + +func Resource(resource string) schema.GroupResource { + return SchemeGroupVersion.WithResource(resource).GroupResource() +} diff --git a/core b/core new file mode 120000 index 00000000..9e5bfb42 --- /dev/null +++ b/core @@ -0,0 +1 @@ +api \ No newline at end of file diff --git a/go.mod b/go.mod index a8c39d1b..c0b54e36 100644 --- a/go.mod +++ b/go.mod @@ -34,6 +34,7 @@ require ( github.com/docker/go-connections v0.4.0 // indirect github.com/docker/go-units v0.4.0 // indirect github.com/emicklei/go-restful/v3 v3.12.1 // indirect + github.com/evanphx/json-patch v4.12.0+incompatible // indirect github.com/evanphx/json-patch/v5 v5.9.0 // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/go-logfmt/logfmt v0.5.1 // indirect diff --git a/hack/boilerplate.go.txt b/hack/boilerplate.go.txt index 65b86227..b1dc19fd 100644 --- a/hack/boilerplate.go.txt +++ b/hack/boilerplate.go.txt @@ -1,15 +1 @@ -/* -Copyright 2023. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ \ No newline at end of file +// SPDX-License-Identifier:Apache-2.0 diff --git a/hack/update-codegen.sh b/hack/update-codegen.sh new file mode 100755 index 00000000..232e5ad7 --- /dev/null +++ b/hack/update-codegen.sh @@ -0,0 +1,108 @@ +#!/usr/bin/env bash + +# Copyright 2020 The Kubernetes Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Strongly "inspired" by https://github.com/kubernetes-sigs/gateway-api/blob/1b14708b143e837fd94be97698ecbe0e6a4e058d/hack/update-codegen.sh + +set -o errexit +set -o nounset +set -o pipefail + +readonly SCRIPT_ROOT="$(cd "$(dirname "${BASH_SOURCE}")"/.. && pwd)" + +# Keep outer module cache so we don't need to redownload them each time. +# The build cache already is persisted. +readonly GOMODCACHE="$(go env GOMODCACHE)" +readonly GO111MODULE="on" +readonly GOFLAGS="-mod=readonly" +readonly GOPATH="$(mktemp -d)" +readonly MIN_REQUIRED_GO_VER="$(go list -m -f '{{.GoVersion}}')" + +function go_version_matches { + go version | perl -ne "exit 1 unless m{go version go([0-9]+.[0-9]+)}; exit 1 if (\$1 < ${MIN_REQUIRED_GO_VER})" + return $? +} + +if ! go_version_matches; then + echo "Go v${MIN_REQUIRED_GO_VER} or later is required to run code generation" + exit 1 +fi + +export GOMODCACHE GO111MODULE GOFLAGS GOPATH + +# Even when modules are enabled, the code-generator tools always write to +# a traditional GOPATH directory, so fake on up to point to the current +# workspace. +mkdir -p "$GOPATH/src/github.com/metallb" +ln -s "${SCRIPT_ROOT}" "$GOPATH/src/github.com/metallb/frr-k8s" + +echo $GOPATH +readonly OUTPUT_PKG=github.com/metallb/frr-k8s/pkg/client +readonly APIS_PKG=github.com/metallb/frr-k8s +readonly CLIENTSET_NAME=versioned +readonly CLIENTSET_PKG_NAME=clientset +readonly VERSIONS=(v1beta1) + +INPUT_DIRS_SPACE="" +INPUT_DIRS_COMMA="" +for VERSION in "${VERSIONS[@]}" +do + INPUT_DIRS_SPACE+="${APIS_PKG}/api/${VERSION} " + INPUT_DIRS_COMMA+="${APIS_PKG}/api/${VERSION}," +done +INPUT_DIRS_SPACE="${INPUT_DIRS_SPACE%,}" # drop trailing space +INPUT_DIRS_COMMA="${INPUT_DIRS_COMMA%,}" # drop trailing comma + + +if [[ "${VERIFY_CODEGEN:-}" == "true" ]]; then + echo "Running in verification mode" + readonly VERIFY_FLAG="--verify-only" +fi + +readonly COMMON_FLAGS="${VERIFY_FLAG:-} --go-header-file ${SCRIPT_ROOT}/hack/boilerplate.go.txt" + +# throw away +new_report="$(mktemp -t "$(basename "$0").api_violations.XXXXXX")" + + +# TEMPORARY FIX (sure!) until https://github.com/kubernetes/kubernetes/pull/125162 +# lands on a tagged release. See also https://github.com/kubernetes/code-generator/issues/167 +rm core || true +ln -s api core + +echo "Generating clientset at ${OUTPUT_PKG}/${CLIENTSET_PKG_NAME}" +go run k8s.io/code-generator/cmd/client-gen@v0.30.2 \ + --clientset-name "${CLIENTSET_NAME}" \ + --input-base "${APIS_PKG}" \ + --input "${INPUT_DIRS_COMMA//${APIS_PKG}/}" \ + --output-dir "pkg/client/${CLIENTSET_PKG_NAME}" \ + --output-pkg "${OUTPUT_PKG}/${CLIENTSET_PKG_NAME}" \ + ${COMMON_FLAGS} + +echo "Generating listers at ${OUTPUT_PKG}/listers" +go run k8s.io/code-generator/cmd/lister-gen@v0.30.2 \ + --output-dir "pkg/client/listers" \ + --output-pkg "${OUTPUT_PKG}/listers" \ + ${COMMON_FLAGS} \ + ${INPUT_DIRS_SPACE} + +echo "Generating informers at ${OUTPUT_PKG}/informers" +go run k8s.io/code-generator/cmd/informer-gen@v0.30.2 \ + --versioned-clientset-package "${OUTPUT_PKG}/${CLIENTSET_PKG_NAME}/${CLIENTSET_NAME}" \ + --listers-package "${OUTPUT_PKG}/listers" \ + --output-dir "pkg/client/informers" \ + --output-pkg "${OUTPUT_PKG}/informers" \ + ${COMMON_FLAGS} \ + ${INPUT_DIRS_SPACE} diff --git a/pkg/client/clientset/versioned/clientset.go b/pkg/client/clientset/versioned/clientset.go new file mode 100644 index 00000000..4b69af41 --- /dev/null +++ b/pkg/client/clientset/versioned/clientset.go @@ -0,0 +1,106 @@ +// SPDX-License-Identifier:Apache-2.0 + +// Code generated by client-gen. DO NOT EDIT. + +package versioned + +import ( + "fmt" + "net/http" + + corev1beta1 "github.com/metallb/frr-k8s/pkg/client/clientset/versioned/typed/core/v1beta1" + 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 + CoreV1beta1() corev1beta1.CoreV1beta1Interface +} + +// Clientset contains the clients for groups. +type Clientset struct { + *discovery.DiscoveryClient + coreV1beta1 *corev1beta1.CoreV1beta1Client +} + +// CoreV1beta1 retrieves the CoreV1beta1Client +func (c *Clientset) CoreV1beta1() corev1beta1.CoreV1beta1Interface { + return c.coreV1beta1 +} + +// 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.coreV1beta1, err = corev1beta1.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.coreV1beta1 = corev1beta1.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 00000000..11d5f43c --- /dev/null +++ b/pkg/client/clientset/versioned/fake/clientset_generated.go @@ -0,0 +1,71 @@ +// SPDX-License-Identifier:Apache-2.0 + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + clientset "github.com/metallb/frr-k8s/pkg/client/clientset/versioned" + corev1beta1 "github.com/metallb/frr-k8s/pkg/client/clientset/versioned/typed/core/v1beta1" + fakecorev1beta1 "github.com/metallb/frr-k8s/pkg/client/clientset/versioned/typed/core/v1beta1/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{} +) + +// CoreV1beta1 retrieves the CoreV1beta1Client +func (c *Clientset) CoreV1beta1() corev1beta1.CoreV1beta1Interface { + return &fakecorev1beta1.FakeCoreV1beta1{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 00000000..1284e340 --- /dev/null +++ b/pkg/client/clientset/versioned/fake/doc.go @@ -0,0 +1,6 @@ +// 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 00000000..a2c58746 --- /dev/null +++ b/pkg/client/clientset/versioned/fake/register.go @@ -0,0 +1,42 @@ +// SPDX-License-Identifier:Apache-2.0 + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + corev1beta1 "github.com/metallb/frr-k8s/core/v1beta1" + 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{ + corev1beta1.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 00000000..1f081673 --- /dev/null +++ b/pkg/client/clientset/versioned/scheme/doc.go @@ -0,0 +1,6 @@ +// 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 00000000..42279688 --- /dev/null +++ b/pkg/client/clientset/versioned/scheme/register.go @@ -0,0 +1,42 @@ +// SPDX-License-Identifier:Apache-2.0 + +// Code generated by client-gen. DO NOT EDIT. + +package scheme + +import ( + corev1beta1 "github.com/metallb/frr-k8s/core/v1beta1" + 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{ + corev1beta1.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/core/v1beta1/core_client.go b/pkg/client/clientset/versioned/typed/core/v1beta1/core_client.go new file mode 100644 index 00000000..20061aac --- /dev/null +++ b/pkg/client/clientset/versioned/typed/core/v1beta1/core_client.go @@ -0,0 +1,93 @@ +// SPDX-License-Identifier:Apache-2.0 + +// Code generated by client-gen. DO NOT EDIT. + +package v1beta1 + +import ( + "net/http" + + v1beta1 "github.com/metallb/frr-k8s/core/v1beta1" + "github.com/metallb/frr-k8s/pkg/client/clientset/versioned/scheme" + rest "k8s.io/client-go/rest" +) + +type CoreV1beta1Interface interface { + RESTClient() rest.Interface + FRRConfigurationsGetter +} + +// CoreV1beta1Client is used to interact with features provided by the group. +type CoreV1beta1Client struct { + restClient rest.Interface +} + +func (c *CoreV1beta1Client) FRRConfigurations(namespace string) FRRConfigurationInterface { + return newFRRConfigurations(c, namespace) +} + +// NewForConfig creates a new CoreV1beta1Client for the given config. +// NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), +// where httpClient was generated with rest.HTTPClientFor(c). +func NewForConfig(c *rest.Config) (*CoreV1beta1Client, 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 CoreV1beta1Client 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) (*CoreV1beta1Client, 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 &CoreV1beta1Client{client}, nil +} + +// NewForConfigOrDie creates a new CoreV1beta1Client for the given config and +// panics if there is an error in the config. +func NewForConfigOrDie(c *rest.Config) *CoreV1beta1Client { + client, err := NewForConfig(c) + if err != nil { + panic(err) + } + return client +} + +// New creates a new CoreV1beta1Client for the given RESTClient. +func New(c rest.Interface) *CoreV1beta1Client { + return &CoreV1beta1Client{c} +} + +func setConfigDefaults(config *rest.Config) error { + gv := v1beta1.SchemeGroupVersion + config.GroupVersion = &gv + config.APIPath = "/api" + 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 *CoreV1beta1Client) RESTClient() rest.Interface { + if c == nil { + return nil + } + return c.restClient +} diff --git a/pkg/client/clientset/versioned/typed/core/v1beta1/doc.go b/pkg/client/clientset/versioned/typed/core/v1beta1/doc.go new file mode 100644 index 00000000..0fb653f4 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/core/v1beta1/doc.go @@ -0,0 +1,6 @@ +// SPDX-License-Identifier:Apache-2.0 + +// Code generated by client-gen. DO NOT EDIT. + +// This package has the automatically generated typed clients. +package v1beta1 diff --git a/pkg/client/clientset/versioned/typed/core/v1beta1/fake/doc.go b/pkg/client/clientset/versioned/typed/core/v1beta1/fake/doc.go new file mode 100644 index 00000000..8a9a8420 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/core/v1beta1/fake/doc.go @@ -0,0 +1,6 @@ +// 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/core/v1beta1/fake/fake_core_client.go b/pkg/client/clientset/versioned/typed/core/v1beta1/fake/fake_core_client.go new file mode 100644 index 00000000..7a0f7211 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/core/v1beta1/fake/fake_core_client.go @@ -0,0 +1,26 @@ +// SPDX-License-Identifier:Apache-2.0 + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + v1beta1 "github.com/metallb/frr-k8s/pkg/client/clientset/versioned/typed/core/v1beta1" + rest "k8s.io/client-go/rest" + testing "k8s.io/client-go/testing" +) + +type FakeCoreV1beta1 struct { + *testing.Fake +} + +func (c *FakeCoreV1beta1) FRRConfigurations(namespace string) v1beta1.FRRConfigurationInterface { + return &FakeFRRConfigurations{c, namespace} +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *FakeCoreV1beta1) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret +} diff --git a/pkg/client/clientset/versioned/typed/core/v1beta1/fake/fake_frrconfiguration.go b/pkg/client/clientset/versioned/typed/core/v1beta1/fake/fake_frrconfiguration.go new file mode 100644 index 00000000..6c07e123 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/core/v1beta1/fake/fake_frrconfiguration.go @@ -0,0 +1,127 @@ +// SPDX-License-Identifier:Apache-2.0 + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + "context" + + v1beta1 "github.com/metallb/frr-k8s/core/v1beta1" + 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" +) + +// FakeFRRConfigurations implements FRRConfigurationInterface +type FakeFRRConfigurations struct { + Fake *FakeCoreV1beta1 + ns string +} + +var frrconfigurationsResource = v1beta1.SchemeGroupVersion.WithResource("frrconfigurations") + +var frrconfigurationsKind = v1beta1.SchemeGroupVersion.WithKind("FRRConfiguration") + +// Get takes name of the fRRConfiguration, and returns the corresponding fRRConfiguration object, and an error if there is any. +func (c *FakeFRRConfigurations) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1beta1.FRRConfiguration, err error) { + obj, err := c.Fake. + Invokes(testing.NewGetAction(frrconfigurationsResource, c.ns, name), &v1beta1.FRRConfiguration{}) + + if obj == nil { + return nil, err + } + return obj.(*v1beta1.FRRConfiguration), err +} + +// List takes label and field selectors, and returns the list of FRRConfigurations that match those selectors. +func (c *FakeFRRConfigurations) List(ctx context.Context, opts v1.ListOptions) (result *v1beta1.FRRConfigurationList, err error) { + obj, err := c.Fake. + Invokes(testing.NewListAction(frrconfigurationsResource, frrconfigurationsKind, c.ns, opts), &v1beta1.FRRConfigurationList{}) + + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1beta1.FRRConfigurationList{ListMeta: obj.(*v1beta1.FRRConfigurationList).ListMeta} + for _, item := range obj.(*v1beta1.FRRConfigurationList).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 fRRConfigurations. +func (c *FakeFRRConfigurations) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewWatchAction(frrconfigurationsResource, c.ns, opts)) + +} + +// Create takes the representation of a fRRConfiguration and creates it. Returns the server's representation of the fRRConfiguration, and an error, if there is any. +func (c *FakeFRRConfigurations) Create(ctx context.Context, fRRConfiguration *v1beta1.FRRConfiguration, opts v1.CreateOptions) (result *v1beta1.FRRConfiguration, err error) { + obj, err := c.Fake. + Invokes(testing.NewCreateAction(frrconfigurationsResource, c.ns, fRRConfiguration), &v1beta1.FRRConfiguration{}) + + if obj == nil { + return nil, err + } + return obj.(*v1beta1.FRRConfiguration), err +} + +// Update takes the representation of a fRRConfiguration and updates it. Returns the server's representation of the fRRConfiguration, and an error, if there is any. +func (c *FakeFRRConfigurations) Update(ctx context.Context, fRRConfiguration *v1beta1.FRRConfiguration, opts v1.UpdateOptions) (result *v1beta1.FRRConfiguration, err error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateAction(frrconfigurationsResource, c.ns, fRRConfiguration), &v1beta1.FRRConfiguration{}) + + if obj == nil { + return nil, err + } + return obj.(*v1beta1.FRRConfiguration), 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 *FakeFRRConfigurations) UpdateStatus(ctx context.Context, fRRConfiguration *v1beta1.FRRConfiguration, opts v1.UpdateOptions) (*v1beta1.FRRConfiguration, error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateSubresourceAction(frrconfigurationsResource, "status", c.ns, fRRConfiguration), &v1beta1.FRRConfiguration{}) + + if obj == nil { + return nil, err + } + return obj.(*v1beta1.FRRConfiguration), err +} + +// Delete takes name of the fRRConfiguration and deletes it. Returns an error if one occurs. +func (c *FakeFRRConfigurations) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewDeleteActionWithOptions(frrconfigurationsResource, c.ns, name, opts), &v1beta1.FRRConfiguration{}) + + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeFRRConfigurations) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + action := testing.NewDeleteCollectionAction(frrconfigurationsResource, c.ns, listOpts) + + _, err := c.Fake.Invokes(action, &v1beta1.FRRConfigurationList{}) + return err +} + +// Patch applies the patch and returns the patched fRRConfiguration. +func (c *FakeFRRConfigurations) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.FRRConfiguration, err error) { + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceAction(frrconfigurationsResource, c.ns, name, pt, data, subresources...), &v1beta1.FRRConfiguration{}) + + if obj == nil { + return nil, err + } + return obj.(*v1beta1.FRRConfiguration), err +} diff --git a/pkg/client/clientset/versioned/typed/core/v1beta1/frrconfiguration.go b/pkg/client/clientset/versioned/typed/core/v1beta1/frrconfiguration.go new file mode 100644 index 00000000..aa57b44f --- /dev/null +++ b/pkg/client/clientset/versioned/typed/core/v1beta1/frrconfiguration.go @@ -0,0 +1,181 @@ +// SPDX-License-Identifier:Apache-2.0 + +// Code generated by client-gen. DO NOT EDIT. + +package v1beta1 + +import ( + "context" + "time" + + v1beta1 "github.com/metallb/frr-k8s/core/v1beta1" + scheme "github.com/metallb/frr-k8s/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" +) + +// FRRConfigurationsGetter has a method to return a FRRConfigurationInterface. +// A group's client should implement this interface. +type FRRConfigurationsGetter interface { + FRRConfigurations(namespace string) FRRConfigurationInterface +} + +// FRRConfigurationInterface has methods to work with FRRConfiguration resources. +type FRRConfigurationInterface interface { + Create(ctx context.Context, fRRConfiguration *v1beta1.FRRConfiguration, opts v1.CreateOptions) (*v1beta1.FRRConfiguration, error) + Update(ctx context.Context, fRRConfiguration *v1beta1.FRRConfiguration, opts v1.UpdateOptions) (*v1beta1.FRRConfiguration, error) + UpdateStatus(ctx context.Context, fRRConfiguration *v1beta1.FRRConfiguration, opts v1.UpdateOptions) (*v1beta1.FRRConfiguration, 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) (*v1beta1.FRRConfiguration, error) + List(ctx context.Context, opts v1.ListOptions) (*v1beta1.FRRConfigurationList, 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 *v1beta1.FRRConfiguration, err error) + FRRConfigurationExpansion +} + +// fRRConfigurations implements FRRConfigurationInterface +type fRRConfigurations struct { + client rest.Interface + ns string +} + +// newFRRConfigurations returns a FRRConfigurations +func newFRRConfigurations(c *CoreV1beta1Client, namespace string) *fRRConfigurations { + return &fRRConfigurations{ + client: c.RESTClient(), + ns: namespace, + } +} + +// Get takes name of the fRRConfiguration, and returns the corresponding fRRConfiguration object, and an error if there is any. +func (c *fRRConfigurations) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1beta1.FRRConfiguration, err error) { + result = &v1beta1.FRRConfiguration{} + err = c.client.Get(). + Namespace(c.ns). + Resource("frrconfigurations"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(ctx). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of FRRConfigurations that match those selectors. +func (c *fRRConfigurations) List(ctx context.Context, opts v1.ListOptions) (result *v1beta1.FRRConfigurationList, err error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + result = &v1beta1.FRRConfigurationList{} + err = c.client.Get(). + Namespace(c.ns). + Resource("frrconfigurations"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Do(ctx). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested fRRConfigurations. +func (c *fRRConfigurations) 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("frrconfigurations"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Watch(ctx) +} + +// Create takes the representation of a fRRConfiguration and creates it. Returns the server's representation of the fRRConfiguration, and an error, if there is any. +func (c *fRRConfigurations) Create(ctx context.Context, fRRConfiguration *v1beta1.FRRConfiguration, opts v1.CreateOptions) (result *v1beta1.FRRConfiguration, err error) { + result = &v1beta1.FRRConfiguration{} + err = c.client.Post(). + Namespace(c.ns). + Resource("frrconfigurations"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(fRRConfiguration). + Do(ctx). + Into(result) + return +} + +// Update takes the representation of a fRRConfiguration and updates it. Returns the server's representation of the fRRConfiguration, and an error, if there is any. +func (c *fRRConfigurations) Update(ctx context.Context, fRRConfiguration *v1beta1.FRRConfiguration, opts v1.UpdateOptions) (result *v1beta1.FRRConfiguration, err error) { + result = &v1beta1.FRRConfiguration{} + err = c.client.Put(). + Namespace(c.ns). + Resource("frrconfigurations"). + Name(fRRConfiguration.Name). + VersionedParams(&opts, scheme.ParameterCodec). + Body(fRRConfiguration). + 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 *fRRConfigurations) UpdateStatus(ctx context.Context, fRRConfiguration *v1beta1.FRRConfiguration, opts v1.UpdateOptions) (result *v1beta1.FRRConfiguration, err error) { + result = &v1beta1.FRRConfiguration{} + err = c.client.Put(). + Namespace(c.ns). + Resource("frrconfigurations"). + Name(fRRConfiguration.Name). + SubResource("status"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(fRRConfiguration). + Do(ctx). + Into(result) + return +} + +// Delete takes name of the fRRConfiguration and deletes it. Returns an error if one occurs. +func (c *fRRConfigurations) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("frrconfigurations"). + Name(name). + Body(&opts). + Do(ctx). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *fRRConfigurations) 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("frrconfigurations"). + VersionedParams(&listOpts, scheme.ParameterCodec). + Timeout(timeout). + Body(&opts). + Do(ctx). + Error() +} + +// Patch applies the patch and returns the patched fRRConfiguration. +func (c *fRRConfigurations) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.FRRConfiguration, err error) { + result = &v1beta1.FRRConfiguration{} + err = c.client.Patch(pt). + Namespace(c.ns). + Resource("frrconfigurations"). + Name(name). + SubResource(subresources...). + VersionedParams(&opts, scheme.ParameterCodec). + Body(data). + Do(ctx). + Into(result) + return +} diff --git a/pkg/client/clientset/versioned/typed/core/v1beta1/generated_expansion.go b/pkg/client/clientset/versioned/typed/core/v1beta1/generated_expansion.go new file mode 100644 index 00000000..864abd79 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/core/v1beta1/generated_expansion.go @@ -0,0 +1,7 @@ +// SPDX-License-Identifier:Apache-2.0 + +// Code generated by client-gen. DO NOT EDIT. + +package v1beta1 + +type FRRConfigurationExpansion interface{} diff --git a/pkg/client/informers/externalversions/core/interface.go b/pkg/client/informers/externalversions/core/interface.go new file mode 100644 index 00000000..4534f623 --- /dev/null +++ b/pkg/client/informers/externalversions/core/interface.go @@ -0,0 +1,32 @@ +// SPDX-License-Identifier:Apache-2.0 + +// Code generated by informer-gen. DO NOT EDIT. + +package core + +import ( + v1beta1 "github.com/metallb/frr-k8s/pkg/client/informers/externalversions/core/v1beta1" + internalinterfaces "github.com/metallb/frr-k8s/pkg/client/informers/externalversions/internalinterfaces" +) + +// Interface provides access to each of this group's versions. +type Interface interface { + // V1beta1 provides access to shared informers for resources in V1beta1. + V1beta1() v1beta1.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} +} + +// V1beta1 returns a new v1beta1.Interface. +func (g *group) V1beta1() v1beta1.Interface { + return v1beta1.New(g.factory, g.namespace, g.tweakListOptions) +} diff --git a/pkg/client/informers/externalversions/core/v1beta1/frrconfiguration.go b/pkg/client/informers/externalversions/core/v1beta1/frrconfiguration.go new file mode 100644 index 00000000..9348c109 --- /dev/null +++ b/pkg/client/informers/externalversions/core/v1beta1/frrconfiguration.go @@ -0,0 +1,76 @@ +// SPDX-License-Identifier:Apache-2.0 + +// Code generated by informer-gen. DO NOT EDIT. + +package v1beta1 + +import ( + "context" + time "time" + + apiv1beta1 "github.com/metallb/frr-k8s/api/v1beta1" + versioned "github.com/metallb/frr-k8s/pkg/client/clientset/versioned" + internalinterfaces "github.com/metallb/frr-k8s/pkg/client/informers/externalversions/internalinterfaces" + v1beta1 "github.com/metallb/frr-k8s/pkg/client/listers/core/v1beta1" + 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" +) + +// FRRConfigurationInformer provides access to a shared informer and lister for +// FRRConfigurations. +type FRRConfigurationInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1beta1.FRRConfigurationLister +} + +type fRRConfigurationInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// NewFRRConfigurationInformer constructs a new informer for FRRConfiguration 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 NewFRRConfigurationInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredFRRConfigurationInformer(client, namespace, resyncPeriod, indexers, nil) +} + +// NewFilteredFRRConfigurationInformer constructs a new informer for FRRConfiguration 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 NewFilteredFRRConfigurationInformer(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.CoreV1beta1().FRRConfigurations(namespace).List(context.TODO(), options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.CoreV1beta1().FRRConfigurations(namespace).Watch(context.TODO(), options) + }, + }, + &apiv1beta1.FRRConfiguration{}, + resyncPeriod, + indexers, + ) +} + +func (f *fRRConfigurationInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredFRRConfigurationInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *fRRConfigurationInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&apiv1beta1.FRRConfiguration{}, f.defaultInformer) +} + +func (f *fRRConfigurationInformer) Lister() v1beta1.FRRConfigurationLister { + return v1beta1.NewFRRConfigurationLister(f.Informer().GetIndexer()) +} diff --git a/pkg/client/informers/externalversions/core/v1beta1/interface.go b/pkg/client/informers/externalversions/core/v1beta1/interface.go new file mode 100644 index 00000000..f87efaa2 --- /dev/null +++ b/pkg/client/informers/externalversions/core/v1beta1/interface.go @@ -0,0 +1,31 @@ +// SPDX-License-Identifier:Apache-2.0 + +// Code generated by informer-gen. DO NOT EDIT. + +package v1beta1 + +import ( + internalinterfaces "github.com/metallb/frr-k8s/pkg/client/informers/externalversions/internalinterfaces" +) + +// Interface provides access to all the informers in this group version. +type Interface interface { + // FRRConfigurations returns a FRRConfigurationInformer. + FRRConfigurations() FRRConfigurationInformer +} + +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} +} + +// FRRConfigurations returns a FRRConfigurationInformer. +func (v *version) FRRConfigurations() FRRConfigurationInformer { + return &fRRConfigurationInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} diff --git a/pkg/client/informers/externalversions/factory.go b/pkg/client/informers/externalversions/factory.go new file mode 100644 index 00000000..b5fc1ba3 --- /dev/null +++ b/pkg/client/informers/externalversions/factory.go @@ -0,0 +1,247 @@ +// 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/metallb/frr-k8s/pkg/client/clientset/versioned" + core "github.com/metallb/frr-k8s/pkg/client/informers/externalversions/core" + internalinterfaces "github.com/metallb/frr-k8s/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 + transform cache.TransformFunc + + 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 + } +} + +// WithTransform sets a transform on all informers. +func WithTransform(transform cache.TransformFunc) SharedInformerOption { + return func(factory *sharedInformerFactory) *sharedInformerFactory { + factory.transform = transform + 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 +} + +// InformerFor 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) + informer.SetTransform(f.transform) + 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) + + // InformerFor returns the SharedIndexInformer for obj using an internal + // client. + InformerFor(obj runtime.Object, newFunc internalinterfaces.NewInformerFunc) cache.SharedIndexInformer + + Core() core.Interface +} + +func (f *sharedInformerFactory) Core() core.Interface { + return core.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 00000000..40a8eee2 --- /dev/null +++ b/pkg/client/informers/externalversions/generic.go @@ -0,0 +1,48 @@ +// SPDX-License-Identifier:Apache-2.0 + +// Code generated by informer-gen. DO NOT EDIT. + +package externalversions + +import ( + "fmt" + + v1beta1 "github.com/metallb/frr-k8s/api/v1beta1" + 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=core, Version=v1beta1 + case v1beta1.SchemeGroupVersion.WithResource("frrconfigurations"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Core().V1beta1().FRRConfigurations().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 00000000..34957879 --- /dev/null +++ b/pkg/client/informers/externalversions/internalinterfaces/factory_interfaces.go @@ -0,0 +1,26 @@ +// SPDX-License-Identifier:Apache-2.0 + +// Code generated by informer-gen. DO NOT EDIT. + +package internalinterfaces + +import ( + time "time" + + versioned "github.com/metallb/frr-k8s/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/core/v1beta1/expansion_generated.go b/pkg/client/listers/core/v1beta1/expansion_generated.go new file mode 100644 index 00000000..4b69446d --- /dev/null +++ b/pkg/client/listers/core/v1beta1/expansion_generated.go @@ -0,0 +1,13 @@ +// SPDX-License-Identifier:Apache-2.0 + +// Code generated by lister-gen. DO NOT EDIT. + +package v1beta1 + +// FRRConfigurationListerExpansion allows custom methods to be added to +// FRRConfigurationLister. +type FRRConfigurationListerExpansion interface{} + +// FRRConfigurationNamespaceListerExpansion allows custom methods to be added to +// FRRConfigurationNamespaceLister. +type FRRConfigurationNamespaceListerExpansion interface{} diff --git a/pkg/client/listers/core/v1beta1/frrconfiguration.go b/pkg/client/listers/core/v1beta1/frrconfiguration.go new file mode 100644 index 00000000..cbf83854 --- /dev/null +++ b/pkg/client/listers/core/v1beta1/frrconfiguration.go @@ -0,0 +1,85 @@ +// SPDX-License-Identifier:Apache-2.0 + +// Code generated by lister-gen. DO NOT EDIT. + +package v1beta1 + +import ( + v1beta1 "github.com/metallb/frr-k8s/api/v1beta1" + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" +) + +// FRRConfigurationLister helps list FRRConfigurations. +// All objects returned here must be treated as read-only. +type FRRConfigurationLister interface { + // List lists all FRRConfigurations in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1beta1.FRRConfiguration, err error) + // FRRConfigurations returns an object that can list and get FRRConfigurations. + FRRConfigurations(namespace string) FRRConfigurationNamespaceLister + FRRConfigurationListerExpansion +} + +// fRRConfigurationLister implements the FRRConfigurationLister interface. +type fRRConfigurationLister struct { + indexer cache.Indexer +} + +// NewFRRConfigurationLister returns a new FRRConfigurationLister. +func NewFRRConfigurationLister(indexer cache.Indexer) FRRConfigurationLister { + return &fRRConfigurationLister{indexer: indexer} +} + +// List lists all FRRConfigurations in the indexer. +func (s *fRRConfigurationLister) List(selector labels.Selector) (ret []*v1beta1.FRRConfiguration, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1beta1.FRRConfiguration)) + }) + return ret, err +} + +// FRRConfigurations returns an object that can list and get FRRConfigurations. +func (s *fRRConfigurationLister) FRRConfigurations(namespace string) FRRConfigurationNamespaceLister { + return fRRConfigurationNamespaceLister{indexer: s.indexer, namespace: namespace} +} + +// FRRConfigurationNamespaceLister helps list and get FRRConfigurations. +// All objects returned here must be treated as read-only. +type FRRConfigurationNamespaceLister interface { + // List lists all FRRConfigurations in the indexer for a given namespace. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1beta1.FRRConfiguration, err error) + // Get retrieves the FRRConfiguration from the indexer for a given namespace and name. + // Objects returned here must be treated as read-only. + Get(name string) (*v1beta1.FRRConfiguration, error) + FRRConfigurationNamespaceListerExpansion +} + +// fRRConfigurationNamespaceLister implements the FRRConfigurationNamespaceLister +// interface. +type fRRConfigurationNamespaceLister struct { + indexer cache.Indexer + namespace string +} + +// List lists all FRRConfigurations in the indexer for a given namespace. +func (s fRRConfigurationNamespaceLister) List(selector labels.Selector) (ret []*v1beta1.FRRConfiguration, err error) { + err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { + ret = append(ret, m.(*v1beta1.FRRConfiguration)) + }) + return ret, err +} + +// Get retrieves the FRRConfiguration from the indexer for a given namespace and name. +func (s fRRConfigurationNamespaceLister) Get(name string) (*v1beta1.FRRConfiguration, error) { + obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1beta1.Resource("frrconfiguration"), name) + } + return obj.(*v1beta1.FRRConfiguration), nil +}