From 3b8f121bf2d36e3d1e1566e8794fa13c25fec997 Mon Sep 17 00:00:00 2001 From: Tommy Xiao Date: Mon, 21 Oct 2024 13:50:05 +0800 Subject: [PATCH] fix: fix Dockerfile issue 1. fix generated resource issue 2. fix Dockerfile issue --- .github/workflows/builder-arm64.yaml | 2 +- .github/workflows/release.yml | 2 +- .github/workflows/testing.yml | 2 +- Dockerfile.dapper | 6 +- pkg/codegen/main.go | 2 +- pkg/deploy/zz_generated_bindata.go | 23 --- .../clientset/versioned/clientset.go | 3 +- pkg/generated/clientset/versioned/doc.go | 19 --- .../versioned/fake/clientset_generated.go | 6 +- .../versioned/typed/k8e.cattle.io/v1/addon.go | 129 ++--------------- .../k8e.cattle.io/v1/etcdsnapshotfile.go | 135 ++---------------- .../typed/k8e.cattle.io/v1/fake/fake_addon.go | 70 ++++----- .../v1/fake/fake_etcdsnapshotfile.go | 79 +++++----- .../controllers/k8e.cattle.io/factory.go | 2 +- .../controllers/k8e.cattle.io/v1/addon.go | 2 +- .../k8e.cattle.io/v1/etcdsnapshotfile.go | 57 +++++++- .../controllers/k8e.cattle.io/v1/interface.go | 4 +- 17 files changed, 167 insertions(+), 376 deletions(-) delete mode 100644 pkg/generated/clientset/versioned/doc.go diff --git a/.github/workflows/builder-arm64.yaml b/.github/workflows/builder-arm64.yaml index 3f1203f9f..52493ac52 100644 --- a/.github/workflows/builder-arm64.yaml +++ b/.github/workflows/builder-arm64.yaml @@ -20,7 +20,7 @@ jobs: - uses: actions/checkout@master - uses: actions/setup-go@v4 with: - go-version: '1.20.10' + go-version: '1.22.5' cache-dependency-path: subdir/go.sum - name: generate resources run: mkdir -p {build/data,build/static} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ffd6529c2..f42fe5ff4 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -20,7 +20,7 @@ jobs: - uses: actions/checkout@master - uses: actions/setup-go@v4 with: - go-version: '1.20.10' + go-version: '1.22.5' cache-dependency-path: subdir/go.sum - name: check depends run: sudo apt-get install -y libseccomp-dev diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 19e025afc..5188a4fb4 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -21,7 +21,7 @@ jobs: ref: 'dev' - uses: actions/setup-go@v4 with: - go-version: '1.20.10' + go-version: '1.22.5' cache-dependency-path: subdir/go.sum - name: generate resources run: | diff --git a/Dockerfile.dapper b/Dockerfile.dapper index 643b12651..63b9b234d 100644 --- a/Dockerfile.dapper +++ b/Dockerfile.dapper @@ -48,10 +48,10 @@ ARG SELINUX=true ENV SELINUX=${SELINUX} # Set Dapper configuration variables -ENV DAPPER_RUN_ARGS --privileged -v k8e-cache:/go/src/github.com/xiaods/k8e/.cache -v trivy-cache:/root/.cache/trivy - DAPPER_ENV REPO TAG RELEASE_TAG IMAGE_NAME SKIP_VALIDATE GCLOUD_AUTH GITHUB_TOKEN GOLANG GOOS GOARCH DEBUG +ENV DAPPER_RUN_ARGS="--privileged -v k3s-cache:/go/src/github.com/k3s-io/k3s/.cache -v trivy-cache:/root/.cache/trivy" \ + DAPPER_ENV="REPO TAG DRONE_TAG IMAGE_NAME SKIP_VALIDATE SKIP_IMAGE SKIP_AIRGAP AWS_SECRET_ACCESS_KEY AWS_ACCESS_KEY_ID GITHUB_TOKEN GOLANG GOCOVER DEBUG" \ DAPPER_SOURCE="/go/src/github.com/xiaods/k8e/" \ - DAPPER_OUTPUT ./bin ./dist ./build/out ./build/static ./pkg/static ./pkg/deploy \ + DAPPER_OUTPUT="./bin ./dist ./build/out ./build/static ./pkg/static ./pkg/deploy" \ DAPPER_DOCKER_SOCKET=true \ CROSS=true \ STATIC_BUILD=true diff --git a/pkg/codegen/main.go b/pkg/codegen/main.go index 349780779..6406c63ca 100644 --- a/pkg/codegen/main.go +++ b/pkg/codegen/main.go @@ -69,7 +69,7 @@ func main() { controllergen.Run(args.Options{ OutputPackage: "github.com/xiaods/k8e/pkg/generated", - Boilerplate: "scripts/boilerplate.go.txt", + Boilerplate: "hack/boilerplate.go.txt", Groups: map[string]args.Group{ "k8e.cattle.io": { Types: []interface{}{ diff --git a/pkg/deploy/zz_generated_bindata.go b/pkg/deploy/zz_generated_bindata.go index 77881f9eb..97dff4d94 100644 --- a/pkg/deploy/zz_generated_bindata.go +++ b/pkg/deploy/zz_generated_bindata.go @@ -1,6 +1,5 @@ // Code generated for package deploy by go-bindata DO NOT EDIT. (@generated) // sources: -// manifests/.DS_Store // manifests/ccm.yaml // manifests/coredns.yaml // manifests/local-storage.yaml @@ -92,26 +91,6 @@ func (fi bindataFileInfo) Sys() interface{} { return nil } -var _Ds_store = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\xd8\x31\x0a\x02\x31\x10\x85\xe1\x37\x31\x45\xc0\x26\xa5\x65\x1a\x0f\xe0\x0d\xc2\xb2\x9e\xc0\x0b\x58\x78\x05\xfb\x1c\x5d\x96\x79\x60\x60\xd5\x4e\x8c\xcb\xfb\x40\xfe\x05\x37\x2a\x16\x31\x23\x00\x9b\xee\xb7\x13\x90\x01\x24\x78\x71\xc4\x4b\x89\x8f\x95\xd0\x5d\x1b\x5f\x43\x44\x44\x44\xc6\x66\x9e\xb4\xff\xf5\x07\x11\x91\xe1\x2c\xfb\x43\x61\x2b\xdb\xbc\xc6\xe7\x03\x1b\xbb\x35\x99\x2d\x6c\x65\x9b\xd7\x78\x5f\x60\x23\x9b\xd8\xcc\x16\xb6\xb2\xcd\xcb\x4d\xcb\x38\x7c\x18\xdf\xd9\x38\xa1\x18\xa7\x10\x2b\x6c\xfd\xce\x77\x23\xf2\xef\x76\x9e\xbc\xfc\xfe\x9f\xdf\xcf\xff\x22\xb2\x61\x16\xe7\xcb\x3c\x3d\x07\x82\xf5\x0d\x00\xae\xdd\xf5\xa7\x43\x40\xf0\x3f\x0b\x0f\xdd\x5a\x1d\x04\x44\x06\xf3\x08\x00\x00\xff\xff\x6a\x00\x88\x6d\x04\x18\x00\x00") - -func Ds_storeBytes() ([]byte, error) { - return bindataRead( - _Ds_store, - ".DS_Store", - ) -} - -func Ds_store() (*asset, error) { - bytes, err := Ds_storeBytes() - if err != nil { - return nil, err - } - - info := bindataFileInfo{name: ".DS_Store", size: 0, mode: os.FileMode(0), modTime: time.Unix(0, 0)} - a := &asset{bytes: bytes, info: info} - return a, nil -} - var _ccmYaml = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xcc\x94\x41\x8f\x13\x31\x0c\x85\xef\xf3\x2b\xa2\x1e\x91\xd2\x15\xb7\xd5\x1c\xe1\xc0\x7d\x25\xb8\xbb\xc9\xa3\x1b\x9a\x89\x23\xdb\x29\x2c\xbf\x1e\x4d\xa7\x2b\x4a\x67\x5b\xda\x02\x62\x6f\x91\x15\x7f\x7e\x7e\x4e\x4c\x35\x7d\x82\x68\xe2\xd2\x3b\x59\x51\x58\x52\xb3\x47\x96\xf4\x9d\x2c\x71\x59\x6e\xee\x75\x99\xf8\x6e\xfb\xb6\xdb\xa4\x12\x7b\xf7\x3e\x37\x35\xc8\x03\x67\x74\x03\x8c\x22\x19\xf5\x9d\x73\x85\x06\xf4\x6e\x73\x0f\x1f\x32\xb7\xe8\x03\x17\x13\xce\x19\xe2\x07\x2a\xb4\x86\x74\xd2\x32\xb4\xef\xbc\xa3\x9a\x3e\x08\xb7\xaa\x63\xa2\x77\x81\x59\x62\x2a\x87\xf5\x3a\xe7\x04\xca\x4d\x02\xf6\x97\x32\x48\xa1\x9d\x73\x5b\xc8\x6a\x1f\x5b\xc3\x26\x80\x80\x0c\xbb\x63\xab\x71\x3c\xce\x6a\x2c\x16\x73\x24\xb6\x28\x76\x84\x3c\x40\x55\xb2\xf0\x78\x35\xb4\x70\x3c\x96\xb9\x78\xb3\xb8\x22\xf7\x4e\x8d\xac\xe9\x2e\xa0\x90\x6d\x0a\x87\xb1\x03\xec\xa4\xef\x22\xf0\x33\x67\xca\xe3\x78\xc2\xc7\x9c\x74\x3a\x7c\xbd\x09\x3d\xd3\x76\xad\x77\x7b\x16\x85\xc0\xed\xdc\x64\x46\xbd\x97\x19\x4a\x03\xb4\xd2\x4c\xde\xef\x58\x54\xab\xce\x69\x91\x30\x70\x51\x1c\x2b\x7b\x79\xbe\x31\x69\xe0\x2d\xe4\x69\xff\xa4\x5f\x7a\x80\x25\x56\x4e\xc5\x34\xcf\x1d\x3c\x35\x13\xef\xbb\xdb\x7f\xec\xbb\x54\x62\x2a\xeb\xab\x3f\x2e\x67\x3c\xe0\xf3\x78\xfb\xb9\xcb\x33\x95\x3b\xe7\xe6\xab\xe2\xa2\x3a\xda\x56\x5f\x10\x6c\xb7\x23\x26\xc4\x47\x85\x5c\x96\xeb\x7e\x0e\xbb\x77\x9b\xb6\x82\xd7\x27\x35\x0c\xff\xc5\x31\x3f\xf2\x7d\x44\xc6\x9a\x8c\xff\xaa\x81\x53\x57\xfd\x51\x81\xd7\xe2\xdc\x1f\x5a\x86\x62\x29\xec\xc8\x5e\x40\xf1\x9c\xb8\x1b\x2d\xfd\xc5\x4b\x7c\x33\x94\xb1\x37\x4f\x35\x8d\xcb\xe7\xa4\x8c\x7f\xe1\xef\x8f\x00\x00\x00\xff\xff\x18\x8a\xd1\x0a\x79\x07\x00\x00") func ccmYamlBytes() ([]byte, error) { @@ -404,7 +383,6 @@ func AssetNames() []string { // _bindata is a table, holding each asset generator, mapped to its name. var _bindata = map[string]func() (*asset, error){ - ".DS_Store": Ds_store, "ccm.yaml": ccmYaml, "coredns.yaml": corednsYaml, "local-storage.yaml": localStorageYaml, @@ -462,7 +440,6 @@ type bintree struct { } var _bintree = &bintree{nil, map[string]*bintree{ - ".DS_Store": &bintree{Ds_store, map[string]*bintree{}}, "ccm.yaml": &bintree{ccmYaml, map[string]*bintree{}}, "coredns.yaml": &bintree{corednsYaml, map[string]*bintree{}}, "local-storage.yaml": &bintree{localStorageYaml, map[string]*bintree{}}, diff --git a/pkg/generated/clientset/versioned/clientset.go b/pkg/generated/clientset/versioned/clientset.go index 2fe94ff0e..0b5d593d3 100644 --- a/pkg/generated/clientset/versioned/clientset.go +++ b/pkg/generated/clientset/versioned/clientset.go @@ -32,8 +32,7 @@ type Interface interface { K8eV1() k8ev1.K8eV1Interface } -// Clientset contains the clients for groups. Each group has exactly one -// version included in a Clientset. +// Clientset contains the clients for groups. type Clientset struct { *discovery.DiscoveryClient k8eV1 *k8ev1.K8eV1Client diff --git a/pkg/generated/clientset/versioned/doc.go b/pkg/generated/clientset/versioned/doc.go deleted file mode 100644 index 4ae39dd07..000000000 --- a/pkg/generated/clientset/versioned/doc.go +++ /dev/null @@ -1,19 +0,0 @@ -/* -Copyright 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. -*/ -// Code generated by main. DO NOT EDIT. - -// This package has the automatically generated clientset. -package versioned diff --git a/pkg/generated/clientset/versioned/fake/clientset_generated.go b/pkg/generated/clientset/versioned/fake/clientset_generated.go index ef1ef71ad..c9c448f1e 100644 --- a/pkg/generated/clientset/versioned/fake/clientset_generated.go +++ b/pkg/generated/clientset/versioned/fake/clientset_generated.go @@ -30,8 +30,12 @@ import ( // 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 +// without applying any field management, validations and/or defaults. It shouldn't be considered a replacement // for a real clientset and is mostly useful in simple unit tests. +// +// DEPRECATED: NewClientset replaces this with support for field management, which significantly improves +// server side apply testing. NewClientset is only available when apply configurations are generated (e.g. +// via --with-applyconfig). func NewSimpleClientset(objects ...runtime.Object) *Clientset { o := testing.NewObjectTracker(scheme, codecs.UniversalDecoder()) for _, obj := range objects { diff --git a/pkg/generated/clientset/versioned/typed/k8e.cattle.io/v1/addon.go b/pkg/generated/clientset/versioned/typed/k8e.cattle.io/v1/addon.go index 05cc400fb..82eb51574 100644 --- a/pkg/generated/clientset/versioned/typed/k8e.cattle.io/v1/addon.go +++ b/pkg/generated/clientset/versioned/typed/k8e.cattle.io/v1/addon.go @@ -19,14 +19,13 @@ package v1 import ( "context" - "time" v1 "github.com/xiaods/k8e/pkg/apis/k8e.cattle.io/v1" scheme "github.com/xiaods/k8e/pkg/generated/clientset/versioned/scheme" metav1 "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" + gentype "k8s.io/client-go/gentype" ) // AddonsGetter has a method to return a AddonInterface. @@ -50,128 +49,18 @@ type AddonInterface interface { // addons implements AddonInterface type addons struct { - client rest.Interface - ns string + *gentype.ClientWithList[*v1.Addon, *v1.AddonList] } // newAddons returns a Addons func newAddons(c *K8eV1Client, namespace string) *addons { return &addons{ - client: c.RESTClient(), - ns: namespace, + gentype.NewClientWithList[*v1.Addon, *v1.AddonList]( + "addons", + c.RESTClient(), + scheme.ParameterCodec, + namespace, + func() *v1.Addon { return &v1.Addon{} }, + func() *v1.AddonList { return &v1.AddonList{} }), } } - -// Get takes name of the addon, and returns the corresponding addon object, and an error if there is any. -func (c *addons) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.Addon, err error) { - result = &v1.Addon{} - err = c.client.Get(). - Namespace(c.ns). - Resource("addons"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of Addons that match those selectors. -func (c *addons) List(ctx context.Context, opts metav1.ListOptions) (result *v1.AddonList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v1.AddonList{} - err = c.client.Get(). - Namespace(c.ns). - Resource("addons"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(ctx). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested addons. -func (c *addons) Watch(ctx context.Context, opts metav1.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("addons"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch(ctx) -} - -// Create takes the representation of a addon and creates it. Returns the server's representation of the addon, and an error, if there is any. -func (c *addons) Create(ctx context.Context, addon *v1.Addon, opts metav1.CreateOptions) (result *v1.Addon, err error) { - result = &v1.Addon{} - err = c.client.Post(). - Namespace(c.ns). - Resource("addons"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(addon). - Do(ctx). - Into(result) - return -} - -// Update takes the representation of a addon and updates it. Returns the server's representation of the addon, and an error, if there is any. -func (c *addons) Update(ctx context.Context, addon *v1.Addon, opts metav1.UpdateOptions) (result *v1.Addon, err error) { - result = &v1.Addon{} - err = c.client.Put(). - Namespace(c.ns). - Resource("addons"). - Name(addon.Name). - VersionedParams(&opts, scheme.ParameterCodec). - Body(addon). - Do(ctx). - Into(result) - return -} - -// Delete takes name of the addon and deletes it. Returns an error if one occurs. -func (c *addons) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - return c.client.Delete(). - Namespace(c.ns). - Resource("addons"). - Name(name). - Body(&opts). - Do(ctx). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *addons) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.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("addons"). - VersionedParams(&listOpts, scheme.ParameterCodec). - Timeout(timeout). - Body(&opts). - Do(ctx). - Error() -} - -// Patch applies the patch and returns the patched addon. -func (c *addons) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.Addon, err error) { - result = &v1.Addon{} - err = c.client.Patch(pt). - Namespace(c.ns). - Resource("addons"). - Name(name). - SubResource(subresources...). - VersionedParams(&opts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} diff --git a/pkg/generated/clientset/versioned/typed/k8e.cattle.io/v1/etcdsnapshotfile.go b/pkg/generated/clientset/versioned/typed/k8e.cattle.io/v1/etcdsnapshotfile.go index 04e417344..9cb3cb883 100644 --- a/pkg/generated/clientset/versioned/typed/k8e.cattle.io/v1/etcdsnapshotfile.go +++ b/pkg/generated/clientset/versioned/typed/k8e.cattle.io/v1/etcdsnapshotfile.go @@ -19,14 +19,13 @@ package v1 import ( "context" - "time" v1 "github.com/xiaods/k8e/pkg/apis/k8e.cattle.io/v1" scheme "github.com/xiaods/k8e/pkg/generated/clientset/versioned/scheme" metav1 "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" + gentype "k8s.io/client-go/gentype" ) // ETCDSnapshotFilesGetter has a method to return a ETCDSnapshotFileInterface. @@ -39,6 +38,7 @@ type ETCDSnapshotFilesGetter interface { type ETCDSnapshotFileInterface interface { Create(ctx context.Context, eTCDSnapshotFile *v1.ETCDSnapshotFile, opts metav1.CreateOptions) (*v1.ETCDSnapshotFile, error) Update(ctx context.Context, eTCDSnapshotFile *v1.ETCDSnapshotFile, opts metav1.UpdateOptions) (*v1.ETCDSnapshotFile, error) + // Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). UpdateStatus(ctx context.Context, eTCDSnapshotFile *v1.ETCDSnapshotFile, opts metav1.UpdateOptions) (*v1.ETCDSnapshotFile, error) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error @@ -51,133 +51,18 @@ type ETCDSnapshotFileInterface interface { // eTCDSnapshotFiles implements ETCDSnapshotFileInterface type eTCDSnapshotFiles struct { - client rest.Interface + *gentype.ClientWithList[*v1.ETCDSnapshotFile, *v1.ETCDSnapshotFileList] } // newETCDSnapshotFiles returns a ETCDSnapshotFiles func newETCDSnapshotFiles(c *K8eV1Client) *eTCDSnapshotFiles { return &eTCDSnapshotFiles{ - client: c.RESTClient(), + gentype.NewClientWithList[*v1.ETCDSnapshotFile, *v1.ETCDSnapshotFileList]( + "etcdsnapshotfiles", + c.RESTClient(), + scheme.ParameterCodec, + "", + func() *v1.ETCDSnapshotFile { return &v1.ETCDSnapshotFile{} }, + func() *v1.ETCDSnapshotFileList { return &v1.ETCDSnapshotFileList{} }), } } - -// Get takes name of the eTCDSnapshotFile, and returns the corresponding eTCDSnapshotFile object, and an error if there is any. -func (c *eTCDSnapshotFiles) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.ETCDSnapshotFile, err error) { - result = &v1.ETCDSnapshotFile{} - err = c.client.Get(). - Resource("etcdsnapshotfiles"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of ETCDSnapshotFiles that match those selectors. -func (c *eTCDSnapshotFiles) List(ctx context.Context, opts metav1.ListOptions) (result *v1.ETCDSnapshotFileList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v1.ETCDSnapshotFileList{} - err = c.client.Get(). - Resource("etcdsnapshotfiles"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(ctx). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested eTCDSnapshotFiles. -func (c *eTCDSnapshotFiles) Watch(ctx context.Context, opts metav1.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(). - Resource("etcdsnapshotfiles"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch(ctx) -} - -// Create takes the representation of a eTCDSnapshotFile and creates it. Returns the server's representation of the eTCDSnapshotFile, and an error, if there is any. -func (c *eTCDSnapshotFiles) Create(ctx context.Context, eTCDSnapshotFile *v1.ETCDSnapshotFile, opts metav1.CreateOptions) (result *v1.ETCDSnapshotFile, err error) { - result = &v1.ETCDSnapshotFile{} - err = c.client.Post(). - Resource("etcdsnapshotfiles"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(eTCDSnapshotFile). - Do(ctx). - Into(result) - return -} - -// Update takes the representation of a eTCDSnapshotFile and updates it. Returns the server's representation of the eTCDSnapshotFile, and an error, if there is any. -func (c *eTCDSnapshotFiles) Update(ctx context.Context, eTCDSnapshotFile *v1.ETCDSnapshotFile, opts metav1.UpdateOptions) (result *v1.ETCDSnapshotFile, err error) { - result = &v1.ETCDSnapshotFile{} - err = c.client.Put(). - Resource("etcdsnapshotfiles"). - Name(eTCDSnapshotFile.Name). - VersionedParams(&opts, scheme.ParameterCodec). - Body(eTCDSnapshotFile). - 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 *eTCDSnapshotFiles) UpdateStatus(ctx context.Context, eTCDSnapshotFile *v1.ETCDSnapshotFile, opts metav1.UpdateOptions) (result *v1.ETCDSnapshotFile, err error) { - result = &v1.ETCDSnapshotFile{} - err = c.client.Put(). - Resource("etcdsnapshotfiles"). - Name(eTCDSnapshotFile.Name). - SubResource("status"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(eTCDSnapshotFile). - Do(ctx). - Into(result) - return -} - -// Delete takes name of the eTCDSnapshotFile and deletes it. Returns an error if one occurs. -func (c *eTCDSnapshotFiles) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - return c.client.Delete(). - Resource("etcdsnapshotfiles"). - Name(name). - Body(&opts). - Do(ctx). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *eTCDSnapshotFiles) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - var timeout time.Duration - if listOpts.TimeoutSeconds != nil { - timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second - } - return c.client.Delete(). - Resource("etcdsnapshotfiles"). - VersionedParams(&listOpts, scheme.ParameterCodec). - Timeout(timeout). - Body(&opts). - Do(ctx). - Error() -} - -// Patch applies the patch and returns the patched eTCDSnapshotFile. -func (c *eTCDSnapshotFiles) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.ETCDSnapshotFile, err error) { - result = &v1.ETCDSnapshotFile{} - err = c.client.Patch(pt). - Resource("etcdsnapshotfiles"). - Name(name). - SubResource(subresources...). - VersionedParams(&opts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} diff --git a/pkg/generated/clientset/versioned/typed/k8e.cattle.io/v1/fake/fake_addon.go b/pkg/generated/clientset/versioned/typed/k8e.cattle.io/v1/fake/fake_addon.go index 366b9533d..0910521e3 100644 --- a/pkg/generated/clientset/versioned/typed/k8e.cattle.io/v1/fake/fake_addon.go +++ b/pkg/generated/clientset/versioned/typed/k8e.cattle.io/v1/fake/fake_addon.go @@ -20,10 +20,9 @@ package fake import ( "context" - k8ecattleiov1 "github.com/xiaods/k8e/pkg/apis/k8e.cattle.io/v1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + v1 "github.com/xiaods/k8e/pkg/apis/k8e.cattle.io/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" labels "k8s.io/apimachinery/pkg/labels" - schema "k8s.io/apimachinery/pkg/runtime/schema" types "k8s.io/apimachinery/pkg/types" watch "k8s.io/apimachinery/pkg/watch" testing "k8s.io/client-go/testing" @@ -35,36 +34,38 @@ type FakeAddons struct { ns string } -var addonsResource = schema.GroupVersionResource{Group: "k8e.cattle.io", Version: "v1", Resource: "addons"} +var addonsResource = v1.SchemeGroupVersion.WithResource("addons") -var addonsKind = schema.GroupVersionKind{Group: "k8e.cattle.io", Version: "v1", Kind: "Addon"} +var addonsKind = v1.SchemeGroupVersion.WithKind("Addon") // Get takes name of the addon, and returns the corresponding addon object, and an error if there is any. -func (c *FakeAddons) Get(ctx context.Context, name string, options v1.GetOptions) (result *k8ecattleiov1.Addon, err error) { +func (c *FakeAddons) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.Addon, err error) { + emptyResult := &v1.Addon{} obj, err := c.Fake. - Invokes(testing.NewGetAction(addonsResource, c.ns, name), &k8ecattleiov1.Addon{}) + Invokes(testing.NewGetActionWithOptions(addonsResource, c.ns, name, options), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } - return obj.(*k8ecattleiov1.Addon), err + return obj.(*v1.Addon), err } // List takes label and field selectors, and returns the list of Addons that match those selectors. -func (c *FakeAddons) List(ctx context.Context, opts v1.ListOptions) (result *k8ecattleiov1.AddonList, err error) { +func (c *FakeAddons) List(ctx context.Context, opts metav1.ListOptions) (result *v1.AddonList, err error) { + emptyResult := &v1.AddonList{} obj, err := c.Fake. - Invokes(testing.NewListAction(addonsResource, addonsKind, c.ns, opts), &k8ecattleiov1.AddonList{}) + Invokes(testing.NewListActionWithOptions(addonsResource, addonsKind, c.ns, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } label, _, _ := testing.ExtractFromListOptions(opts) if label == nil { label = labels.Everything() } - list := &k8ecattleiov1.AddonList{ListMeta: obj.(*k8ecattleiov1.AddonList).ListMeta} - for _, item := range obj.(*k8ecattleiov1.AddonList).Items { + list := &v1.AddonList{ListMeta: obj.(*v1.AddonList).ListMeta} + for _, item := range obj.(*v1.AddonList).Items { if label.Matches(labels.Set(item.Labels)) { list.Items = append(list.Items, item) } @@ -73,57 +74,60 @@ func (c *FakeAddons) List(ctx context.Context, opts v1.ListOptions) (result *k8e } // Watch returns a watch.Interface that watches the requested addons. -func (c *FakeAddons) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { +func (c *FakeAddons) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { return c.Fake. - InvokesWatch(testing.NewWatchAction(addonsResource, c.ns, opts)) + InvokesWatch(testing.NewWatchActionWithOptions(addonsResource, c.ns, opts)) } // Create takes the representation of a addon and creates it. Returns the server's representation of the addon, and an error, if there is any. -func (c *FakeAddons) Create(ctx context.Context, addon *k8ecattleiov1.Addon, opts v1.CreateOptions) (result *k8ecattleiov1.Addon, err error) { +func (c *FakeAddons) Create(ctx context.Context, addon *v1.Addon, opts metav1.CreateOptions) (result *v1.Addon, err error) { + emptyResult := &v1.Addon{} obj, err := c.Fake. - Invokes(testing.NewCreateAction(addonsResource, c.ns, addon), &k8ecattleiov1.Addon{}) + Invokes(testing.NewCreateActionWithOptions(addonsResource, c.ns, addon, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } - return obj.(*k8ecattleiov1.Addon), err + return obj.(*v1.Addon), err } // Update takes the representation of a addon and updates it. Returns the server's representation of the addon, and an error, if there is any. -func (c *FakeAddons) Update(ctx context.Context, addon *k8ecattleiov1.Addon, opts v1.UpdateOptions) (result *k8ecattleiov1.Addon, err error) { +func (c *FakeAddons) Update(ctx context.Context, addon *v1.Addon, opts metav1.UpdateOptions) (result *v1.Addon, err error) { + emptyResult := &v1.Addon{} obj, err := c.Fake. - Invokes(testing.NewUpdateAction(addonsResource, c.ns, addon), &k8ecattleiov1.Addon{}) + Invokes(testing.NewUpdateActionWithOptions(addonsResource, c.ns, addon, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } - return obj.(*k8ecattleiov1.Addon), err + return obj.(*v1.Addon), err } // Delete takes name of the addon and deletes it. Returns an error if one occurs. -func (c *FakeAddons) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { +func (c *FakeAddons) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { _, err := c.Fake. - Invokes(testing.NewDeleteActionWithOptions(addonsResource, c.ns, name, opts), &k8ecattleiov1.Addon{}) + Invokes(testing.NewDeleteActionWithOptions(addonsResource, c.ns, name, opts), &v1.Addon{}) return err } // DeleteCollection deletes a collection of objects. -func (c *FakeAddons) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - action := testing.NewDeleteCollectionAction(addonsResource, c.ns, listOpts) +func (c *FakeAddons) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { + action := testing.NewDeleteCollectionActionWithOptions(addonsResource, c.ns, opts, listOpts) - _, err := c.Fake.Invokes(action, &k8ecattleiov1.AddonList{}) + _, err := c.Fake.Invokes(action, &v1.AddonList{}) return err } // Patch applies the patch and returns the patched addon. -func (c *FakeAddons) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *k8ecattleiov1.Addon, err error) { +func (c *FakeAddons) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.Addon, err error) { + emptyResult := &v1.Addon{} obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceAction(addonsResource, c.ns, name, pt, data, subresources...), &k8ecattleiov1.Addon{}) + Invokes(testing.NewPatchSubresourceActionWithOptions(addonsResource, c.ns, name, pt, data, opts, subresources...), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } - return obj.(*k8ecattleiov1.Addon), err + return obj.(*v1.Addon), err } diff --git a/pkg/generated/clientset/versioned/typed/k8e.cattle.io/v1/fake/fake_etcdsnapshotfile.go b/pkg/generated/clientset/versioned/typed/k8e.cattle.io/v1/fake/fake_etcdsnapshotfile.go index 91d9a1e21..e4f3b8037 100644 --- a/pkg/generated/clientset/versioned/typed/k8e.cattle.io/v1/fake/fake_etcdsnapshotfile.go +++ b/pkg/generated/clientset/versioned/typed/k8e.cattle.io/v1/fake/fake_etcdsnapshotfile.go @@ -20,10 +20,9 @@ package fake import ( "context" - k8ecattleiov1 "github.com/xiaods/k8e/pkg/apis/k8e.cattle.io/v1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + v1 "github.com/xiaods/k8e/pkg/apis/k8e.cattle.io/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" labels "k8s.io/apimachinery/pkg/labels" - schema "k8s.io/apimachinery/pkg/runtime/schema" types "k8s.io/apimachinery/pkg/types" watch "k8s.io/apimachinery/pkg/watch" testing "k8s.io/client-go/testing" @@ -34,34 +33,36 @@ type FakeETCDSnapshotFiles struct { Fake *FakeK8eV1 } -var etcdsnapshotfilesResource = schema.GroupVersionResource{Group: "k8e.cattle.io", Version: "v1", Resource: "etcdsnapshotfiles"} +var etcdsnapshotfilesResource = v1.SchemeGroupVersion.WithResource("etcdsnapshotfiles") -var etcdsnapshotfilesKind = schema.GroupVersionKind{Group: "k8e.cattle.io", Version: "v1", Kind: "ETCDSnapshotFile"} +var etcdsnapshotfilesKind = v1.SchemeGroupVersion.WithKind("ETCDSnapshotFile") // Get takes name of the eTCDSnapshotFile, and returns the corresponding eTCDSnapshotFile object, and an error if there is any. -func (c *FakeETCDSnapshotFiles) Get(ctx context.Context, name string, options v1.GetOptions) (result *k8ecattleiov1.ETCDSnapshotFile, err error) { +func (c *FakeETCDSnapshotFiles) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.ETCDSnapshotFile, err error) { + emptyResult := &v1.ETCDSnapshotFile{} obj, err := c.Fake. - Invokes(testing.NewRootGetAction(etcdsnapshotfilesResource, name), &k8ecattleiov1.ETCDSnapshotFile{}) + Invokes(testing.NewRootGetActionWithOptions(etcdsnapshotfilesResource, name, options), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } - return obj.(*k8ecattleiov1.ETCDSnapshotFile), err + return obj.(*v1.ETCDSnapshotFile), err } // List takes label and field selectors, and returns the list of ETCDSnapshotFiles that match those selectors. -func (c *FakeETCDSnapshotFiles) List(ctx context.Context, opts v1.ListOptions) (result *k8ecattleiov1.ETCDSnapshotFileList, err error) { +func (c *FakeETCDSnapshotFiles) List(ctx context.Context, opts metav1.ListOptions) (result *v1.ETCDSnapshotFileList, err error) { + emptyResult := &v1.ETCDSnapshotFileList{} obj, err := c.Fake. - Invokes(testing.NewRootListAction(etcdsnapshotfilesResource, etcdsnapshotfilesKind, opts), &k8ecattleiov1.ETCDSnapshotFileList{}) + Invokes(testing.NewRootListActionWithOptions(etcdsnapshotfilesResource, etcdsnapshotfilesKind, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } label, _, _ := testing.ExtractFromListOptions(opts) if label == nil { label = labels.Everything() } - list := &k8ecattleiov1.ETCDSnapshotFileList{ListMeta: obj.(*k8ecattleiov1.ETCDSnapshotFileList).ListMeta} - for _, item := range obj.(*k8ecattleiov1.ETCDSnapshotFileList).Items { + list := &v1.ETCDSnapshotFileList{ListMeta: obj.(*v1.ETCDSnapshotFileList).ListMeta} + for _, item := range obj.(*v1.ETCDSnapshotFileList).Items { if label.Matches(labels.Set(item.Labels)) { list.Items = append(list.Items, item) } @@ -70,63 +71,67 @@ func (c *FakeETCDSnapshotFiles) List(ctx context.Context, opts v1.ListOptions) ( } // Watch returns a watch.Interface that watches the requested eTCDSnapshotFiles. -func (c *FakeETCDSnapshotFiles) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { +func (c *FakeETCDSnapshotFiles) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { return c.Fake. - InvokesWatch(testing.NewRootWatchAction(etcdsnapshotfilesResource, opts)) + InvokesWatch(testing.NewRootWatchActionWithOptions(etcdsnapshotfilesResource, opts)) } // Create takes the representation of a eTCDSnapshotFile and creates it. Returns the server's representation of the eTCDSnapshotFile, and an error, if there is any. -func (c *FakeETCDSnapshotFiles) Create(ctx context.Context, eTCDSnapshotFile *k8ecattleiov1.ETCDSnapshotFile, opts v1.CreateOptions) (result *k8ecattleiov1.ETCDSnapshotFile, err error) { +func (c *FakeETCDSnapshotFiles) Create(ctx context.Context, eTCDSnapshotFile *v1.ETCDSnapshotFile, opts metav1.CreateOptions) (result *v1.ETCDSnapshotFile, err error) { + emptyResult := &v1.ETCDSnapshotFile{} obj, err := c.Fake. - Invokes(testing.NewRootCreateAction(etcdsnapshotfilesResource, eTCDSnapshotFile), &k8ecattleiov1.ETCDSnapshotFile{}) + Invokes(testing.NewRootCreateActionWithOptions(etcdsnapshotfilesResource, eTCDSnapshotFile, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } - return obj.(*k8ecattleiov1.ETCDSnapshotFile), err + return obj.(*v1.ETCDSnapshotFile), err } // Update takes the representation of a eTCDSnapshotFile and updates it. Returns the server's representation of the eTCDSnapshotFile, and an error, if there is any. -func (c *FakeETCDSnapshotFiles) Update(ctx context.Context, eTCDSnapshotFile *k8ecattleiov1.ETCDSnapshotFile, opts v1.UpdateOptions) (result *k8ecattleiov1.ETCDSnapshotFile, err error) { +func (c *FakeETCDSnapshotFiles) Update(ctx context.Context, eTCDSnapshotFile *v1.ETCDSnapshotFile, opts metav1.UpdateOptions) (result *v1.ETCDSnapshotFile, err error) { + emptyResult := &v1.ETCDSnapshotFile{} obj, err := c.Fake. - Invokes(testing.NewRootUpdateAction(etcdsnapshotfilesResource, eTCDSnapshotFile), &k8ecattleiov1.ETCDSnapshotFile{}) + Invokes(testing.NewRootUpdateActionWithOptions(etcdsnapshotfilesResource, eTCDSnapshotFile, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } - return obj.(*k8ecattleiov1.ETCDSnapshotFile), err + return obj.(*v1.ETCDSnapshotFile), 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 *FakeETCDSnapshotFiles) UpdateStatus(ctx context.Context, eTCDSnapshotFile *k8ecattleiov1.ETCDSnapshotFile, opts v1.UpdateOptions) (*k8ecattleiov1.ETCDSnapshotFile, error) { +func (c *FakeETCDSnapshotFiles) UpdateStatus(ctx context.Context, eTCDSnapshotFile *v1.ETCDSnapshotFile, opts metav1.UpdateOptions) (result *v1.ETCDSnapshotFile, err error) { + emptyResult := &v1.ETCDSnapshotFile{} obj, err := c.Fake. - Invokes(testing.NewRootUpdateSubresourceAction(etcdsnapshotfilesResource, "status", eTCDSnapshotFile), &k8ecattleiov1.ETCDSnapshotFile{}) + Invokes(testing.NewRootUpdateSubresourceActionWithOptions(etcdsnapshotfilesResource, "status", eTCDSnapshotFile, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } - return obj.(*k8ecattleiov1.ETCDSnapshotFile), err + return obj.(*v1.ETCDSnapshotFile), err } // Delete takes name of the eTCDSnapshotFile and deletes it. Returns an error if one occurs. -func (c *FakeETCDSnapshotFiles) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { +func (c *FakeETCDSnapshotFiles) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { _, err := c.Fake. - Invokes(testing.NewRootDeleteActionWithOptions(etcdsnapshotfilesResource, name, opts), &k8ecattleiov1.ETCDSnapshotFile{}) + Invokes(testing.NewRootDeleteActionWithOptions(etcdsnapshotfilesResource, name, opts), &v1.ETCDSnapshotFile{}) return err } // DeleteCollection deletes a collection of objects. -func (c *FakeETCDSnapshotFiles) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - action := testing.NewRootDeleteCollectionAction(etcdsnapshotfilesResource, listOpts) +func (c *FakeETCDSnapshotFiles) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { + action := testing.NewRootDeleteCollectionActionWithOptions(etcdsnapshotfilesResource, opts, listOpts) - _, err := c.Fake.Invokes(action, &k8ecattleiov1.ETCDSnapshotFileList{}) + _, err := c.Fake.Invokes(action, &v1.ETCDSnapshotFileList{}) return err } // Patch applies the patch and returns the patched eTCDSnapshotFile. -func (c *FakeETCDSnapshotFiles) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *k8ecattleiov1.ETCDSnapshotFile, err error) { +func (c *FakeETCDSnapshotFiles) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.ETCDSnapshotFile, err error) { + emptyResult := &v1.ETCDSnapshotFile{} obj, err := c.Fake. - Invokes(testing.NewRootPatchSubresourceAction(etcdsnapshotfilesResource, name, pt, data, subresources...), &k8ecattleiov1.ETCDSnapshotFile{}) + Invokes(testing.NewRootPatchSubresourceActionWithOptions(etcdsnapshotfilesResource, name, pt, data, opts, subresources...), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } - return obj.(*k8ecattleiov1.ETCDSnapshotFile), err + return obj.(*v1.ETCDSnapshotFile), err } diff --git a/pkg/generated/controllers/k8e.cattle.io/factory.go b/pkg/generated/controllers/k8e.cattle.io/factory.go index 58174f88c..34568c7d4 100644 --- a/pkg/generated/controllers/k8e.cattle.io/factory.go +++ b/pkg/generated/controllers/k8e.cattle.io/factory.go @@ -19,7 +19,7 @@ package k8e import ( "github.com/rancher/lasso/pkg/controller" - "github.com/rancher/wrangler/pkg/generic" + "github.com/rancher/wrangler/v3/pkg/generic" "k8s.io/client-go/rest" ) diff --git a/pkg/generated/controllers/k8e.cattle.io/v1/addon.go b/pkg/generated/controllers/k8e.cattle.io/v1/addon.go index a07ec6d93..6d456e57a 100644 --- a/pkg/generated/controllers/k8e.cattle.io/v1/addon.go +++ b/pkg/generated/controllers/k8e.cattle.io/v1/addon.go @@ -18,7 +18,7 @@ limitations under the License. package v1 import ( - "github.com/rancher/wrangler/pkg/generic" + "github.com/rancher/wrangler/v3/pkg/generic" v1 "github.com/xiaods/k8e/pkg/apis/k8e.cattle.io/v1" ) diff --git a/pkg/generated/controllers/k8e.cattle.io/v1/etcdsnapshotfile.go b/pkg/generated/controllers/k8e.cattle.io/v1/etcdsnapshotfile.go index a3fea87ba..904ab7a4a 100644 --- a/pkg/generated/controllers/k8e.cattle.io/v1/etcdsnapshotfile.go +++ b/pkg/generated/controllers/k8e.cattle.io/v1/etcdsnapshotfile.go @@ -19,12 +19,13 @@ package v1 import ( "context" + "sync" "time" - "github.com/rancher/wrangler/pkg/apply" - "github.com/rancher/wrangler/pkg/condition" - "github.com/rancher/wrangler/pkg/generic" - "github.com/rancher/wrangler/pkg/kv" + "github.com/rancher/wrangler/v3/pkg/apply" + "github.com/rancher/wrangler/v3/pkg/condition" + "github.com/rancher/wrangler/v3/pkg/generic" + "github.com/rancher/wrangler/v3/pkg/kv" v1 "github.com/xiaods/k8e/pkg/apis/k8e.cattle.io/v1" "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/errors" @@ -47,10 +48,14 @@ type ETCDSnapshotFileCache interface { generic.NonNamespacedCacheInterface[*v1.ETCDSnapshotFile] } +// ETCDSnapshotFileStatusHandler is executed for every added or modified ETCDSnapshotFile. Should return the new status to be updated type ETCDSnapshotFileStatusHandler func(obj *v1.ETCDSnapshotFile, status v1.ETCDSnapshotStatus) (v1.ETCDSnapshotStatus, error) +// ETCDSnapshotFileGeneratingHandler is the top-level handler that is executed for every ETCDSnapshotFile event. It extends ETCDSnapshotFileStatusHandler by a returning a slice of child objects to be passed to apply.Apply type ETCDSnapshotFileGeneratingHandler func(obj *v1.ETCDSnapshotFile, status v1.ETCDSnapshotStatus) ([]runtime.Object, v1.ETCDSnapshotStatus, error) +// RegisterETCDSnapshotFileStatusHandler configures a ETCDSnapshotFileController to execute a ETCDSnapshotFileStatusHandler for every events observed. +// If a non-empty condition is provided, it will be updated in the status conditions for every handler execution func RegisterETCDSnapshotFileStatusHandler(ctx context.Context, controller ETCDSnapshotFileController, condition condition.Cond, name string, handler ETCDSnapshotFileStatusHandler) { statusHandler := &eTCDSnapshotFileStatusHandler{ client: controller, @@ -60,6 +65,8 @@ func RegisterETCDSnapshotFileStatusHandler(ctx context.Context, controller ETCDS controller.AddGenericHandler(ctx, name, generic.FromObjectHandlerToHandler(statusHandler.sync)) } +// RegisterETCDSnapshotFileGeneratingHandler configures a ETCDSnapshotFileController to execute a ETCDSnapshotFileGeneratingHandler for every events observed, passing the returned objects to the provided apply.Apply. +// If a non-empty condition is provided, it will be updated in the status conditions for every handler execution func RegisterETCDSnapshotFileGeneratingHandler(ctx context.Context, controller ETCDSnapshotFileController, apply apply.Apply, condition condition.Cond, name string, handler ETCDSnapshotFileGeneratingHandler, opts *generic.GeneratingHandlerOptions) { statusHandler := &eTCDSnapshotFileGeneratingHandler{ @@ -81,6 +88,7 @@ type eTCDSnapshotFileStatusHandler struct { handler ETCDSnapshotFileStatusHandler } +// sync is executed on every resource addition or modification. Executes the configured handlers and sends the updated status to the Kubernetes API func (a *eTCDSnapshotFileStatusHandler) sync(key string, obj *v1.ETCDSnapshotFile) (*v1.ETCDSnapshotFile, error) { if obj == nil { return obj, nil @@ -126,8 +134,10 @@ type eTCDSnapshotFileGeneratingHandler struct { opts generic.GeneratingHandlerOptions gvk schema.GroupVersionKind name string + seen sync.Map } +// Remove handles the observed deletion of a resource, cascade deleting every associated resource previously applied func (a *eTCDSnapshotFileGeneratingHandler) Remove(key string, obj *v1.ETCDSnapshotFile) (*v1.ETCDSnapshotFile, error) { if obj != nil { return obj, nil @@ -137,12 +147,17 @@ func (a *eTCDSnapshotFileGeneratingHandler) Remove(key string, obj *v1.ETCDSnaps obj.Namespace, obj.Name = kv.RSplit(key, "/") obj.SetGroupVersionKind(a.gvk) + if a.opts.UniqueApplyForResourceVersion { + a.seen.Delete(key) + } + return nil, generic.ConfigureApplyForObject(a.apply, obj, &a.opts). WithOwner(obj). WithSetID(a.name). ApplyObjects() } +// Handle executes the configured ETCDSnapshotFileGeneratingHandler and pass the resulting objects to apply.Apply, finally returning the new status of the resource func (a *eTCDSnapshotFileGeneratingHandler) Handle(obj *v1.ETCDSnapshotFile, status v1.ETCDSnapshotStatus) (v1.ETCDSnapshotStatus, error) { if !obj.DeletionTimestamp.IsZero() { return status, nil @@ -152,9 +167,41 @@ func (a *eTCDSnapshotFileGeneratingHandler) Handle(obj *v1.ETCDSnapshotFile, sta if err != nil { return newStatus, err } + if !a.isNewResourceVersion(obj) { + return newStatus, nil + } - return newStatus, generic.ConfigureApplyForObject(a.apply, obj, &a.opts). + err = generic.ConfigureApplyForObject(a.apply, obj, &a.opts). WithOwner(obj). WithSetID(a.name). ApplyObjects(objs...) + if err != nil { + return newStatus, err + } + a.storeResourceVersion(obj) + return newStatus, nil +} + +// isNewResourceVersion detects if a specific resource version was already successfully processed. +// Only used if UniqueApplyForResourceVersion is set in generic.GeneratingHandlerOptions +func (a *eTCDSnapshotFileGeneratingHandler) isNewResourceVersion(obj *v1.ETCDSnapshotFile) bool { + if !a.opts.UniqueApplyForResourceVersion { + return true + } + + // Apply once per resource version + key := obj.Namespace + "/" + obj.Name + previous, ok := a.seen.Load(key) + return !ok || previous != obj.ResourceVersion +} + +// storeResourceVersion keeps track of the latest resource version of an object for which Apply was executed +// Only used if UniqueApplyForResourceVersion is set in generic.GeneratingHandlerOptions +func (a *eTCDSnapshotFileGeneratingHandler) storeResourceVersion(obj *v1.ETCDSnapshotFile) { + if !a.opts.UniqueApplyForResourceVersion { + return + } + + key := obj.Namespace + "/" + obj.Name + a.seen.Store(key, obj.ResourceVersion) } diff --git a/pkg/generated/controllers/k8e.cattle.io/v1/interface.go b/pkg/generated/controllers/k8e.cattle.io/v1/interface.go index 68c49d228..162c3c1b7 100644 --- a/pkg/generated/controllers/k8e.cattle.io/v1/interface.go +++ b/pkg/generated/controllers/k8e.cattle.io/v1/interface.go @@ -19,8 +19,8 @@ package v1 import ( "github.com/rancher/lasso/pkg/controller" - "github.com/rancher/wrangler/pkg/generic" - "github.com/rancher/wrangler/pkg/schemes" + "github.com/rancher/wrangler/v3/pkg/generic" + "github.com/rancher/wrangler/v3/pkg/schemes" v1 "github.com/xiaods/k8e/pkg/apis/k8e.cattle.io/v1" "k8s.io/apimachinery/pkg/runtime/schema" )