1
0
mirror of https://github.com/rancher/os.git synced 2025-09-09 02:31:36 +00:00

Add operator

This commit is contained in:
Darren Shepherd
2021-10-20 10:58:54 -07:00
parent 0e46d19194
commit 5675644d9f
60 changed files with 5387 additions and 60 deletions

View File

@@ -0,0 +1,67 @@
/*
Copyright 2021 Rancher Labs, Inc.
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.
package fleet
import (
"github.com/rancher/wrangler/pkg/generic"
"k8s.io/client-go/rest"
)
type Factory struct {
*generic.Factory
}
func NewFactoryFromConfigOrDie(config *rest.Config) *Factory {
f, err := NewFactoryFromConfig(config)
if err != nil {
panic(err)
}
return f
}
func NewFactoryFromConfig(config *rest.Config) (*Factory, error) {
return NewFactoryFromConfigWithOptions(config, nil)
}
func NewFactoryFromConfigWithNamespace(config *rest.Config, namespace string) (*Factory, error) {
return NewFactoryFromConfigWithOptions(config, &FactoryOptions{
Namespace: namespace,
})
}
type FactoryOptions = generic.FactoryOptions
func NewFactoryFromConfigWithOptions(config *rest.Config, opts *FactoryOptions) (*Factory, error) {
f, err := generic.NewFactoryFromConfigWithOptions(config, opts)
return &Factory{
Factory: f,
}, err
}
func NewFactoryFromConfigWithOptionsOrDie(config *rest.Config, opts *FactoryOptions) *Factory {
f, err := NewFactoryFromConfigWithOptions(config, opts)
if err != nil {
panic(err)
}
return f
}
func (c *Factory) Fleet() Interface {
return New(c.ControllerFactory())
}

View File

@@ -0,0 +1,43 @@
/*
Copyright 2021 Rancher Labs, Inc.
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.
package fleet
import (
"github.com/rancher/lasso/pkg/controller"
v1alpha1 "github.com/rancher/os/pkg/generated/controllers/fleet.cattle.io/v1alpha1"
)
type Interface interface {
V1alpha1() v1alpha1.Interface
}
type group struct {
controllerFactory controller.SharedControllerFactory
}
// New returns a new Interface.
func New(controllerFactory controller.SharedControllerFactory) Interface {
return &group{
controllerFactory: controllerFactory,
}
}
func (g *group) V1alpha1() v1alpha1.Interface {
return v1alpha1.New(g.controllerFactory)
}

View File

@@ -0,0 +1,376 @@
/*
Copyright 2021 Rancher Labs, Inc.
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.
package v1alpha1
import (
"context"
"time"
v1alpha1 "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1"
"github.com/rancher/lasso/pkg/client"
"github.com/rancher/lasso/pkg/controller"
"github.com/rancher/wrangler/pkg/apply"
"github.com/rancher/wrangler/pkg/condition"
"github.com/rancher/wrangler/pkg/generic"
"github.com/rancher/wrangler/pkg/kv"
"k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/tools/cache"
)
type BundleHandler func(string, *v1alpha1.Bundle) (*v1alpha1.Bundle, error)
type BundleController interface {
generic.ControllerMeta
BundleClient
OnChange(ctx context.Context, name string, sync BundleHandler)
OnRemove(ctx context.Context, name string, sync BundleHandler)
Enqueue(namespace, name string)
EnqueueAfter(namespace, name string, duration time.Duration)
Cache() BundleCache
}
type BundleClient interface {
Create(*v1alpha1.Bundle) (*v1alpha1.Bundle, error)
Update(*v1alpha1.Bundle) (*v1alpha1.Bundle, error)
UpdateStatus(*v1alpha1.Bundle) (*v1alpha1.Bundle, error)
Delete(namespace, name string, options *metav1.DeleteOptions) error
Get(namespace, name string, options metav1.GetOptions) (*v1alpha1.Bundle, error)
List(namespace string, opts metav1.ListOptions) (*v1alpha1.BundleList, error)
Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error)
Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.Bundle, err error)
}
type BundleCache interface {
Get(namespace, name string) (*v1alpha1.Bundle, error)
List(namespace string, selector labels.Selector) ([]*v1alpha1.Bundle, error)
AddIndexer(indexName string, indexer BundleIndexer)
GetByIndex(indexName, key string) ([]*v1alpha1.Bundle, error)
}
type BundleIndexer func(obj *v1alpha1.Bundle) ([]string, error)
type bundleController struct {
controller controller.SharedController
client *client.Client
gvk schema.GroupVersionKind
groupResource schema.GroupResource
}
func NewBundleController(gvk schema.GroupVersionKind, resource string, namespaced bool, controller controller.SharedControllerFactory) BundleController {
c := controller.ForResourceKind(gvk.GroupVersion().WithResource(resource), gvk.Kind, namespaced)
return &bundleController{
controller: c,
client: c.Client(),
gvk: gvk,
groupResource: schema.GroupResource{
Group: gvk.Group,
Resource: resource,
},
}
}
func FromBundleHandlerToHandler(sync BundleHandler) generic.Handler {
return func(key string, obj runtime.Object) (ret runtime.Object, err error) {
var v *v1alpha1.Bundle
if obj == nil {
v, err = sync(key, nil)
} else {
v, err = sync(key, obj.(*v1alpha1.Bundle))
}
if v == nil {
return nil, err
}
return v, err
}
}
func (c *bundleController) Updater() generic.Updater {
return func(obj runtime.Object) (runtime.Object, error) {
newObj, err := c.Update(obj.(*v1alpha1.Bundle))
if newObj == nil {
return nil, err
}
return newObj, err
}
}
func UpdateBundleDeepCopyOnChange(client BundleClient, obj *v1alpha1.Bundle, handler func(obj *v1alpha1.Bundle) (*v1alpha1.Bundle, error)) (*v1alpha1.Bundle, error) {
if obj == nil {
return obj, nil
}
copyObj := obj.DeepCopy()
newObj, err := handler(copyObj)
if newObj != nil {
copyObj = newObj
}
if obj.ResourceVersion == copyObj.ResourceVersion && !equality.Semantic.DeepEqual(obj, copyObj) {
return client.Update(copyObj)
}
return copyObj, err
}
func (c *bundleController) AddGenericHandler(ctx context.Context, name string, handler generic.Handler) {
c.controller.RegisterHandler(ctx, name, controller.SharedControllerHandlerFunc(handler))
}
func (c *bundleController) AddGenericRemoveHandler(ctx context.Context, name string, handler generic.Handler) {
c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), handler))
}
func (c *bundleController) OnChange(ctx context.Context, name string, sync BundleHandler) {
c.AddGenericHandler(ctx, name, FromBundleHandlerToHandler(sync))
}
func (c *bundleController) OnRemove(ctx context.Context, name string, sync BundleHandler) {
c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), FromBundleHandlerToHandler(sync)))
}
func (c *bundleController) Enqueue(namespace, name string) {
c.controller.Enqueue(namespace, name)
}
func (c *bundleController) EnqueueAfter(namespace, name string, duration time.Duration) {
c.controller.EnqueueAfter(namespace, name, duration)
}
func (c *bundleController) Informer() cache.SharedIndexInformer {
return c.controller.Informer()
}
func (c *bundleController) GroupVersionKind() schema.GroupVersionKind {
return c.gvk
}
func (c *bundleController) Cache() BundleCache {
return &bundleCache{
indexer: c.Informer().GetIndexer(),
resource: c.groupResource,
}
}
func (c *bundleController) Create(obj *v1alpha1.Bundle) (*v1alpha1.Bundle, error) {
result := &v1alpha1.Bundle{}
return result, c.client.Create(context.TODO(), obj.Namespace, obj, result, metav1.CreateOptions{})
}
func (c *bundleController) Update(obj *v1alpha1.Bundle) (*v1alpha1.Bundle, error) {
result := &v1alpha1.Bundle{}
return result, c.client.Update(context.TODO(), obj.Namespace, obj, result, metav1.UpdateOptions{})
}
func (c *bundleController) UpdateStatus(obj *v1alpha1.Bundle) (*v1alpha1.Bundle, error) {
result := &v1alpha1.Bundle{}
return result, c.client.UpdateStatus(context.TODO(), obj.Namespace, obj, result, metav1.UpdateOptions{})
}
func (c *bundleController) Delete(namespace, name string, options *metav1.DeleteOptions) error {
if options == nil {
options = &metav1.DeleteOptions{}
}
return c.client.Delete(context.TODO(), namespace, name, *options)
}
func (c *bundleController) Get(namespace, name string, options metav1.GetOptions) (*v1alpha1.Bundle, error) {
result := &v1alpha1.Bundle{}
return result, c.client.Get(context.TODO(), namespace, name, result, options)
}
func (c *bundleController) List(namespace string, opts metav1.ListOptions) (*v1alpha1.BundleList, error) {
result := &v1alpha1.BundleList{}
return result, c.client.List(context.TODO(), namespace, result, opts)
}
func (c *bundleController) Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) {
return c.client.Watch(context.TODO(), namespace, opts)
}
func (c *bundleController) Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (*v1alpha1.Bundle, error) {
result := &v1alpha1.Bundle{}
return result, c.client.Patch(context.TODO(), namespace, name, pt, data, result, metav1.PatchOptions{}, subresources...)
}
type bundleCache struct {
indexer cache.Indexer
resource schema.GroupResource
}
func (c *bundleCache) Get(namespace, name string) (*v1alpha1.Bundle, error) {
obj, exists, err := c.indexer.GetByKey(namespace + "/" + name)
if err != nil {
return nil, err
}
if !exists {
return nil, errors.NewNotFound(c.resource, name)
}
return obj.(*v1alpha1.Bundle), nil
}
func (c *bundleCache) List(namespace string, selector labels.Selector) (ret []*v1alpha1.Bundle, err error) {
err = cache.ListAllByNamespace(c.indexer, namespace, selector, func(m interface{}) {
ret = append(ret, m.(*v1alpha1.Bundle))
})
return ret, err
}
func (c *bundleCache) AddIndexer(indexName string, indexer BundleIndexer) {
utilruntime.Must(c.indexer.AddIndexers(map[string]cache.IndexFunc{
indexName: func(obj interface{}) (strings []string, e error) {
return indexer(obj.(*v1alpha1.Bundle))
},
}))
}
func (c *bundleCache) GetByIndex(indexName, key string) (result []*v1alpha1.Bundle, err error) {
objs, err := c.indexer.ByIndex(indexName, key)
if err != nil {
return nil, err
}
result = make([]*v1alpha1.Bundle, 0, len(objs))
for _, obj := range objs {
result = append(result, obj.(*v1alpha1.Bundle))
}
return result, nil
}
type BundleStatusHandler func(obj *v1alpha1.Bundle, status v1alpha1.BundleStatus) (v1alpha1.BundleStatus, error)
type BundleGeneratingHandler func(obj *v1alpha1.Bundle, status v1alpha1.BundleStatus) ([]runtime.Object, v1alpha1.BundleStatus, error)
func RegisterBundleStatusHandler(ctx context.Context, controller BundleController, condition condition.Cond, name string, handler BundleStatusHandler) {
statusHandler := &bundleStatusHandler{
client: controller,
condition: condition,
handler: handler,
}
controller.AddGenericHandler(ctx, name, FromBundleHandlerToHandler(statusHandler.sync))
}
func RegisterBundleGeneratingHandler(ctx context.Context, controller BundleController, apply apply.Apply,
condition condition.Cond, name string, handler BundleGeneratingHandler, opts *generic.GeneratingHandlerOptions) {
statusHandler := &bundleGeneratingHandler{
BundleGeneratingHandler: handler,
apply: apply,
name: name,
gvk: controller.GroupVersionKind(),
}
if opts != nil {
statusHandler.opts = *opts
}
controller.OnChange(ctx, name, statusHandler.Remove)
RegisterBundleStatusHandler(ctx, controller, condition, name, statusHandler.Handle)
}
type bundleStatusHandler struct {
client BundleClient
condition condition.Cond
handler BundleStatusHandler
}
func (a *bundleStatusHandler) sync(key string, obj *v1alpha1.Bundle) (*v1alpha1.Bundle, error) {
if obj == nil {
return obj, nil
}
origStatus := obj.Status.DeepCopy()
obj = obj.DeepCopy()
newStatus, err := a.handler(obj, obj.Status)
if err != nil {
// Revert to old status on error
newStatus = *origStatus.DeepCopy()
}
if a.condition != "" {
if errors.IsConflict(err) {
a.condition.SetError(&newStatus, "", nil)
} else {
a.condition.SetError(&newStatus, "", err)
}
}
if !equality.Semantic.DeepEqual(origStatus, &newStatus) {
if a.condition != "" {
// Since status has changed, update the lastUpdatedTime
a.condition.LastUpdated(&newStatus, time.Now().UTC().Format(time.RFC3339))
}
var newErr error
obj.Status = newStatus
newObj, newErr := a.client.UpdateStatus(obj)
if err == nil {
err = newErr
}
if newErr == nil {
obj = newObj
}
}
return obj, err
}
type bundleGeneratingHandler struct {
BundleGeneratingHandler
apply apply.Apply
opts generic.GeneratingHandlerOptions
gvk schema.GroupVersionKind
name string
}
func (a *bundleGeneratingHandler) Remove(key string, obj *v1alpha1.Bundle) (*v1alpha1.Bundle, error) {
if obj != nil {
return obj, nil
}
obj = &v1alpha1.Bundle{}
obj.Namespace, obj.Name = kv.RSplit(key, "/")
obj.SetGroupVersionKind(a.gvk)
return nil, generic.ConfigureApplyForObject(a.apply, obj, &a.opts).
WithOwner(obj).
WithSetID(a.name).
ApplyObjects()
}
func (a *bundleGeneratingHandler) Handle(obj *v1alpha1.Bundle, status v1alpha1.BundleStatus) (v1alpha1.BundleStatus, error) {
if !obj.DeletionTimestamp.IsZero() {
return status, nil
}
objs, newStatus, err := a.BundleGeneratingHandler(obj, status)
if err != nil {
return newStatus, err
}
return newStatus, generic.ConfigureApplyForObject(a.apply, obj, &a.opts).
WithOwner(obj).
WithSetID(a.name).
ApplyObjects(objs...)
}

View File

@@ -0,0 +1,48 @@
/*
Copyright 2021 Rancher Labs, Inc.
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.
package v1alpha1
import (
v1alpha1 "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1"
"github.com/rancher/lasso/pkg/controller"
"github.com/rancher/wrangler/pkg/schemes"
"k8s.io/apimachinery/pkg/runtime/schema"
)
func init() {
schemes.Register(v1alpha1.AddToScheme)
}
type Interface interface {
Bundle() BundleController
}
func New(controllerFactory controller.SharedControllerFactory) Interface {
return &version{
controllerFactory: controllerFactory,
}
}
type version struct {
controllerFactory controller.SharedControllerFactory
}
func (c *version) Bundle() BundleController {
return NewBundleController(schema.GroupVersionKind{Group: "fleet.cattle.io", Version: "v1alpha1", Kind: "Bundle"}, "bundles", true, c.controllerFactory)
}

View File

@@ -0,0 +1,67 @@
/*
Copyright 2021 Rancher Labs, Inc.
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.
package management
import (
"github.com/rancher/wrangler/pkg/generic"
"k8s.io/client-go/rest"
)
type Factory struct {
*generic.Factory
}
func NewFactoryFromConfigOrDie(config *rest.Config) *Factory {
f, err := NewFactoryFromConfig(config)
if err != nil {
panic(err)
}
return f
}
func NewFactoryFromConfig(config *rest.Config) (*Factory, error) {
return NewFactoryFromConfigWithOptions(config, nil)
}
func NewFactoryFromConfigWithNamespace(config *rest.Config, namespace string) (*Factory, error) {
return NewFactoryFromConfigWithOptions(config, &FactoryOptions{
Namespace: namespace,
})
}
type FactoryOptions = generic.FactoryOptions
func NewFactoryFromConfigWithOptions(config *rest.Config, opts *FactoryOptions) (*Factory, error) {
f, err := generic.NewFactoryFromConfigWithOptions(config, opts)
return &Factory{
Factory: f,
}, err
}
func NewFactoryFromConfigWithOptionsOrDie(config *rest.Config, opts *FactoryOptions) *Factory {
f, err := NewFactoryFromConfigWithOptions(config, opts)
if err != nil {
panic(err)
}
return f
}
func (c *Factory) Management() Interface {
return New(c.ControllerFactory())
}

View File

@@ -0,0 +1,43 @@
/*
Copyright 2021 Rancher Labs, Inc.
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.
package management
import (
"github.com/rancher/lasso/pkg/controller"
v3 "github.com/rancher/os/pkg/generated/controllers/management.cattle.io/v3"
)
type Interface interface {
V3() v3.Interface
}
type group struct {
controllerFactory controller.SharedControllerFactory
}
// New returns a new Interface.
func New(controllerFactory controller.SharedControllerFactory) Interface {
return &group{
controllerFactory: controllerFactory,
}
}
func (g *group) V3() v3.Interface {
return v3.New(g.controllerFactory)
}

View File

@@ -0,0 +1,376 @@
/*
Copyright 2021 Rancher Labs, Inc.
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.
package v3
import (
"context"
"time"
"github.com/rancher/lasso/pkg/client"
"github.com/rancher/lasso/pkg/controller"
v3 "github.com/rancher/rancher/pkg/apis/management.cattle.io/v3"
"github.com/rancher/wrangler/pkg/apply"
"github.com/rancher/wrangler/pkg/condition"
"github.com/rancher/wrangler/pkg/generic"
"github.com/rancher/wrangler/pkg/kv"
"k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/tools/cache"
)
type ClusterRegistrationTokenHandler func(string, *v3.ClusterRegistrationToken) (*v3.ClusterRegistrationToken, error)
type ClusterRegistrationTokenController interface {
generic.ControllerMeta
ClusterRegistrationTokenClient
OnChange(ctx context.Context, name string, sync ClusterRegistrationTokenHandler)
OnRemove(ctx context.Context, name string, sync ClusterRegistrationTokenHandler)
Enqueue(namespace, name string)
EnqueueAfter(namespace, name string, duration time.Duration)
Cache() ClusterRegistrationTokenCache
}
type ClusterRegistrationTokenClient interface {
Create(*v3.ClusterRegistrationToken) (*v3.ClusterRegistrationToken, error)
Update(*v3.ClusterRegistrationToken) (*v3.ClusterRegistrationToken, error)
UpdateStatus(*v3.ClusterRegistrationToken) (*v3.ClusterRegistrationToken, error)
Delete(namespace, name string, options *metav1.DeleteOptions) error
Get(namespace, name string, options metav1.GetOptions) (*v3.ClusterRegistrationToken, error)
List(namespace string, opts metav1.ListOptions) (*v3.ClusterRegistrationTokenList, error)
Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error)
Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (result *v3.ClusterRegistrationToken, err error)
}
type ClusterRegistrationTokenCache interface {
Get(namespace, name string) (*v3.ClusterRegistrationToken, error)
List(namespace string, selector labels.Selector) ([]*v3.ClusterRegistrationToken, error)
AddIndexer(indexName string, indexer ClusterRegistrationTokenIndexer)
GetByIndex(indexName, key string) ([]*v3.ClusterRegistrationToken, error)
}
type ClusterRegistrationTokenIndexer func(obj *v3.ClusterRegistrationToken) ([]string, error)
type clusterRegistrationTokenController struct {
controller controller.SharedController
client *client.Client
gvk schema.GroupVersionKind
groupResource schema.GroupResource
}
func NewClusterRegistrationTokenController(gvk schema.GroupVersionKind, resource string, namespaced bool, controller controller.SharedControllerFactory) ClusterRegistrationTokenController {
c := controller.ForResourceKind(gvk.GroupVersion().WithResource(resource), gvk.Kind, namespaced)
return &clusterRegistrationTokenController{
controller: c,
client: c.Client(),
gvk: gvk,
groupResource: schema.GroupResource{
Group: gvk.Group,
Resource: resource,
},
}
}
func FromClusterRegistrationTokenHandlerToHandler(sync ClusterRegistrationTokenHandler) generic.Handler {
return func(key string, obj runtime.Object) (ret runtime.Object, err error) {
var v *v3.ClusterRegistrationToken
if obj == nil {
v, err = sync(key, nil)
} else {
v, err = sync(key, obj.(*v3.ClusterRegistrationToken))
}
if v == nil {
return nil, err
}
return v, err
}
}
func (c *clusterRegistrationTokenController) Updater() generic.Updater {
return func(obj runtime.Object) (runtime.Object, error) {
newObj, err := c.Update(obj.(*v3.ClusterRegistrationToken))
if newObj == nil {
return nil, err
}
return newObj, err
}
}
func UpdateClusterRegistrationTokenDeepCopyOnChange(client ClusterRegistrationTokenClient, obj *v3.ClusterRegistrationToken, handler func(obj *v3.ClusterRegistrationToken) (*v3.ClusterRegistrationToken, error)) (*v3.ClusterRegistrationToken, error) {
if obj == nil {
return obj, nil
}
copyObj := obj.DeepCopy()
newObj, err := handler(copyObj)
if newObj != nil {
copyObj = newObj
}
if obj.ResourceVersion == copyObj.ResourceVersion && !equality.Semantic.DeepEqual(obj, copyObj) {
return client.Update(copyObj)
}
return copyObj, err
}
func (c *clusterRegistrationTokenController) AddGenericHandler(ctx context.Context, name string, handler generic.Handler) {
c.controller.RegisterHandler(ctx, name, controller.SharedControllerHandlerFunc(handler))
}
func (c *clusterRegistrationTokenController) AddGenericRemoveHandler(ctx context.Context, name string, handler generic.Handler) {
c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), handler))
}
func (c *clusterRegistrationTokenController) OnChange(ctx context.Context, name string, sync ClusterRegistrationTokenHandler) {
c.AddGenericHandler(ctx, name, FromClusterRegistrationTokenHandlerToHandler(sync))
}
func (c *clusterRegistrationTokenController) OnRemove(ctx context.Context, name string, sync ClusterRegistrationTokenHandler) {
c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), FromClusterRegistrationTokenHandlerToHandler(sync)))
}
func (c *clusterRegistrationTokenController) Enqueue(namespace, name string) {
c.controller.Enqueue(namespace, name)
}
func (c *clusterRegistrationTokenController) EnqueueAfter(namespace, name string, duration time.Duration) {
c.controller.EnqueueAfter(namespace, name, duration)
}
func (c *clusterRegistrationTokenController) Informer() cache.SharedIndexInformer {
return c.controller.Informer()
}
func (c *clusterRegistrationTokenController) GroupVersionKind() schema.GroupVersionKind {
return c.gvk
}
func (c *clusterRegistrationTokenController) Cache() ClusterRegistrationTokenCache {
return &clusterRegistrationTokenCache{
indexer: c.Informer().GetIndexer(),
resource: c.groupResource,
}
}
func (c *clusterRegistrationTokenController) Create(obj *v3.ClusterRegistrationToken) (*v3.ClusterRegistrationToken, error) {
result := &v3.ClusterRegistrationToken{}
return result, c.client.Create(context.TODO(), obj.Namespace, obj, result, metav1.CreateOptions{})
}
func (c *clusterRegistrationTokenController) Update(obj *v3.ClusterRegistrationToken) (*v3.ClusterRegistrationToken, error) {
result := &v3.ClusterRegistrationToken{}
return result, c.client.Update(context.TODO(), obj.Namespace, obj, result, metav1.UpdateOptions{})
}
func (c *clusterRegistrationTokenController) UpdateStatus(obj *v3.ClusterRegistrationToken) (*v3.ClusterRegistrationToken, error) {
result := &v3.ClusterRegistrationToken{}
return result, c.client.UpdateStatus(context.TODO(), obj.Namespace, obj, result, metav1.UpdateOptions{})
}
func (c *clusterRegistrationTokenController) Delete(namespace, name string, options *metav1.DeleteOptions) error {
if options == nil {
options = &metav1.DeleteOptions{}
}
return c.client.Delete(context.TODO(), namespace, name, *options)
}
func (c *clusterRegistrationTokenController) Get(namespace, name string, options metav1.GetOptions) (*v3.ClusterRegistrationToken, error) {
result := &v3.ClusterRegistrationToken{}
return result, c.client.Get(context.TODO(), namespace, name, result, options)
}
func (c *clusterRegistrationTokenController) List(namespace string, opts metav1.ListOptions) (*v3.ClusterRegistrationTokenList, error) {
result := &v3.ClusterRegistrationTokenList{}
return result, c.client.List(context.TODO(), namespace, result, opts)
}
func (c *clusterRegistrationTokenController) Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) {
return c.client.Watch(context.TODO(), namespace, opts)
}
func (c *clusterRegistrationTokenController) Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (*v3.ClusterRegistrationToken, error) {
result := &v3.ClusterRegistrationToken{}
return result, c.client.Patch(context.TODO(), namespace, name, pt, data, result, metav1.PatchOptions{}, subresources...)
}
type clusterRegistrationTokenCache struct {
indexer cache.Indexer
resource schema.GroupResource
}
func (c *clusterRegistrationTokenCache) Get(namespace, name string) (*v3.ClusterRegistrationToken, error) {
obj, exists, err := c.indexer.GetByKey(namespace + "/" + name)
if err != nil {
return nil, err
}
if !exists {
return nil, errors.NewNotFound(c.resource, name)
}
return obj.(*v3.ClusterRegistrationToken), nil
}
func (c *clusterRegistrationTokenCache) List(namespace string, selector labels.Selector) (ret []*v3.ClusterRegistrationToken, err error) {
err = cache.ListAllByNamespace(c.indexer, namespace, selector, func(m interface{}) {
ret = append(ret, m.(*v3.ClusterRegistrationToken))
})
return ret, err
}
func (c *clusterRegistrationTokenCache) AddIndexer(indexName string, indexer ClusterRegistrationTokenIndexer) {
utilruntime.Must(c.indexer.AddIndexers(map[string]cache.IndexFunc{
indexName: func(obj interface{}) (strings []string, e error) {
return indexer(obj.(*v3.ClusterRegistrationToken))
},
}))
}
func (c *clusterRegistrationTokenCache) GetByIndex(indexName, key string) (result []*v3.ClusterRegistrationToken, err error) {
objs, err := c.indexer.ByIndex(indexName, key)
if err != nil {
return nil, err
}
result = make([]*v3.ClusterRegistrationToken, 0, len(objs))
for _, obj := range objs {
result = append(result, obj.(*v3.ClusterRegistrationToken))
}
return result, nil
}
type ClusterRegistrationTokenStatusHandler func(obj *v3.ClusterRegistrationToken, status v3.ClusterRegistrationTokenStatus) (v3.ClusterRegistrationTokenStatus, error)
type ClusterRegistrationTokenGeneratingHandler func(obj *v3.ClusterRegistrationToken, status v3.ClusterRegistrationTokenStatus) ([]runtime.Object, v3.ClusterRegistrationTokenStatus, error)
func RegisterClusterRegistrationTokenStatusHandler(ctx context.Context, controller ClusterRegistrationTokenController, condition condition.Cond, name string, handler ClusterRegistrationTokenStatusHandler) {
statusHandler := &clusterRegistrationTokenStatusHandler{
client: controller,
condition: condition,
handler: handler,
}
controller.AddGenericHandler(ctx, name, FromClusterRegistrationTokenHandlerToHandler(statusHandler.sync))
}
func RegisterClusterRegistrationTokenGeneratingHandler(ctx context.Context, controller ClusterRegistrationTokenController, apply apply.Apply,
condition condition.Cond, name string, handler ClusterRegistrationTokenGeneratingHandler, opts *generic.GeneratingHandlerOptions) {
statusHandler := &clusterRegistrationTokenGeneratingHandler{
ClusterRegistrationTokenGeneratingHandler: handler,
apply: apply,
name: name,
gvk: controller.GroupVersionKind(),
}
if opts != nil {
statusHandler.opts = *opts
}
controller.OnChange(ctx, name, statusHandler.Remove)
RegisterClusterRegistrationTokenStatusHandler(ctx, controller, condition, name, statusHandler.Handle)
}
type clusterRegistrationTokenStatusHandler struct {
client ClusterRegistrationTokenClient
condition condition.Cond
handler ClusterRegistrationTokenStatusHandler
}
func (a *clusterRegistrationTokenStatusHandler) sync(key string, obj *v3.ClusterRegistrationToken) (*v3.ClusterRegistrationToken, error) {
if obj == nil {
return obj, nil
}
origStatus := obj.Status.DeepCopy()
obj = obj.DeepCopy()
newStatus, err := a.handler(obj, obj.Status)
if err != nil {
// Revert to old status on error
newStatus = *origStatus.DeepCopy()
}
if a.condition != "" {
if errors.IsConflict(err) {
a.condition.SetError(&newStatus, "", nil)
} else {
a.condition.SetError(&newStatus, "", err)
}
}
if !equality.Semantic.DeepEqual(origStatus, &newStatus) {
if a.condition != "" {
// Since status has changed, update the lastUpdatedTime
a.condition.LastUpdated(&newStatus, time.Now().UTC().Format(time.RFC3339))
}
var newErr error
obj.Status = newStatus
newObj, newErr := a.client.UpdateStatus(obj)
if err == nil {
err = newErr
}
if newErr == nil {
obj = newObj
}
}
return obj, err
}
type clusterRegistrationTokenGeneratingHandler struct {
ClusterRegistrationTokenGeneratingHandler
apply apply.Apply
opts generic.GeneratingHandlerOptions
gvk schema.GroupVersionKind
name string
}
func (a *clusterRegistrationTokenGeneratingHandler) Remove(key string, obj *v3.ClusterRegistrationToken) (*v3.ClusterRegistrationToken, error) {
if obj != nil {
return obj, nil
}
obj = &v3.ClusterRegistrationToken{}
obj.Namespace, obj.Name = kv.RSplit(key, "/")
obj.SetGroupVersionKind(a.gvk)
return nil, generic.ConfigureApplyForObject(a.apply, obj, &a.opts).
WithOwner(obj).
WithSetID(a.name).
ApplyObjects()
}
func (a *clusterRegistrationTokenGeneratingHandler) Handle(obj *v3.ClusterRegistrationToken, status v3.ClusterRegistrationTokenStatus) (v3.ClusterRegistrationTokenStatus, error) {
if !obj.DeletionTimestamp.IsZero() {
return status, nil
}
objs, newStatus, err := a.ClusterRegistrationTokenGeneratingHandler(obj, status)
if err != nil {
return newStatus, err
}
return newStatus, generic.ConfigureApplyForObject(a.apply, obj, &a.opts).
WithOwner(obj).
WithSetID(a.name).
ApplyObjects(objs...)
}

View File

@@ -0,0 +1,52 @@
/*
Copyright 2021 Rancher Labs, Inc.
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.
package v3
import (
"github.com/rancher/lasso/pkg/controller"
v3 "github.com/rancher/rancher/pkg/apis/management.cattle.io/v3"
"github.com/rancher/wrangler/pkg/schemes"
"k8s.io/apimachinery/pkg/runtime/schema"
)
func init() {
schemes.Register(v3.AddToScheme)
}
type Interface interface {
ClusterRegistrationToken() ClusterRegistrationTokenController
Setting() SettingController
}
func New(controllerFactory controller.SharedControllerFactory) Interface {
return &version{
controllerFactory: controllerFactory,
}
}
type version struct {
controllerFactory controller.SharedControllerFactory
}
func (c *version) ClusterRegistrationToken() ClusterRegistrationTokenController {
return NewClusterRegistrationTokenController(schema.GroupVersionKind{Group: "management.cattle.io", Version: "v3", Kind: "ClusterRegistrationToken"}, "clusterregistrationtokens", true, c.controllerFactory)
}
func (c *version) Setting() SettingController {
return NewSettingController(schema.GroupVersionKind{Group: "management.cattle.io", Version: "v3", Kind: "Setting"}, "settings", false, c.controllerFactory)
}

View File

@@ -0,0 +1,256 @@
/*
Copyright 2021 Rancher Labs, Inc.
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.
package v3
import (
"context"
"time"
"github.com/rancher/lasso/pkg/client"
"github.com/rancher/lasso/pkg/controller"
v3 "github.com/rancher/rancher/pkg/apis/management.cattle.io/v3"
"github.com/rancher/wrangler/pkg/generic"
"k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/tools/cache"
)
type SettingHandler func(string, *v3.Setting) (*v3.Setting, error)
type SettingController interface {
generic.ControllerMeta
SettingClient
OnChange(ctx context.Context, name string, sync SettingHandler)
OnRemove(ctx context.Context, name string, sync SettingHandler)
Enqueue(name string)
EnqueueAfter(name string, duration time.Duration)
Cache() SettingCache
}
type SettingClient interface {
Create(*v3.Setting) (*v3.Setting, error)
Update(*v3.Setting) (*v3.Setting, error)
Delete(name string, options *metav1.DeleteOptions) error
Get(name string, options metav1.GetOptions) (*v3.Setting, error)
List(opts metav1.ListOptions) (*v3.SettingList, error)
Watch(opts metav1.ListOptions) (watch.Interface, error)
Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v3.Setting, err error)
}
type SettingCache interface {
Get(name string) (*v3.Setting, error)
List(selector labels.Selector) ([]*v3.Setting, error)
AddIndexer(indexName string, indexer SettingIndexer)
GetByIndex(indexName, key string) ([]*v3.Setting, error)
}
type SettingIndexer func(obj *v3.Setting) ([]string, error)
type settingController struct {
controller controller.SharedController
client *client.Client
gvk schema.GroupVersionKind
groupResource schema.GroupResource
}
func NewSettingController(gvk schema.GroupVersionKind, resource string, namespaced bool, controller controller.SharedControllerFactory) SettingController {
c := controller.ForResourceKind(gvk.GroupVersion().WithResource(resource), gvk.Kind, namespaced)
return &settingController{
controller: c,
client: c.Client(),
gvk: gvk,
groupResource: schema.GroupResource{
Group: gvk.Group,
Resource: resource,
},
}
}
func FromSettingHandlerToHandler(sync SettingHandler) generic.Handler {
return func(key string, obj runtime.Object) (ret runtime.Object, err error) {
var v *v3.Setting
if obj == nil {
v, err = sync(key, nil)
} else {
v, err = sync(key, obj.(*v3.Setting))
}
if v == nil {
return nil, err
}
return v, err
}
}
func (c *settingController) Updater() generic.Updater {
return func(obj runtime.Object) (runtime.Object, error) {
newObj, err := c.Update(obj.(*v3.Setting))
if newObj == nil {
return nil, err
}
return newObj, err
}
}
func UpdateSettingDeepCopyOnChange(client SettingClient, obj *v3.Setting, handler func(obj *v3.Setting) (*v3.Setting, error)) (*v3.Setting, error) {
if obj == nil {
return obj, nil
}
copyObj := obj.DeepCopy()
newObj, err := handler(copyObj)
if newObj != nil {
copyObj = newObj
}
if obj.ResourceVersion == copyObj.ResourceVersion && !equality.Semantic.DeepEqual(obj, copyObj) {
return client.Update(copyObj)
}
return copyObj, err
}
func (c *settingController) AddGenericHandler(ctx context.Context, name string, handler generic.Handler) {
c.controller.RegisterHandler(ctx, name, controller.SharedControllerHandlerFunc(handler))
}
func (c *settingController) AddGenericRemoveHandler(ctx context.Context, name string, handler generic.Handler) {
c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), handler))
}
func (c *settingController) OnChange(ctx context.Context, name string, sync SettingHandler) {
c.AddGenericHandler(ctx, name, FromSettingHandlerToHandler(sync))
}
func (c *settingController) OnRemove(ctx context.Context, name string, sync SettingHandler) {
c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), FromSettingHandlerToHandler(sync)))
}
func (c *settingController) Enqueue(name string) {
c.controller.Enqueue("", name)
}
func (c *settingController) EnqueueAfter(name string, duration time.Duration) {
c.controller.EnqueueAfter("", name, duration)
}
func (c *settingController) Informer() cache.SharedIndexInformer {
return c.controller.Informer()
}
func (c *settingController) GroupVersionKind() schema.GroupVersionKind {
return c.gvk
}
func (c *settingController) Cache() SettingCache {
return &settingCache{
indexer: c.Informer().GetIndexer(),
resource: c.groupResource,
}
}
func (c *settingController) Create(obj *v3.Setting) (*v3.Setting, error) {
result := &v3.Setting{}
return result, c.client.Create(context.TODO(), "", obj, result, metav1.CreateOptions{})
}
func (c *settingController) Update(obj *v3.Setting) (*v3.Setting, error) {
result := &v3.Setting{}
return result, c.client.Update(context.TODO(), "", obj, result, metav1.UpdateOptions{})
}
func (c *settingController) Delete(name string, options *metav1.DeleteOptions) error {
if options == nil {
options = &metav1.DeleteOptions{}
}
return c.client.Delete(context.TODO(), "", name, *options)
}
func (c *settingController) Get(name string, options metav1.GetOptions) (*v3.Setting, error) {
result := &v3.Setting{}
return result, c.client.Get(context.TODO(), "", name, result, options)
}
func (c *settingController) List(opts metav1.ListOptions) (*v3.SettingList, error) {
result := &v3.SettingList{}
return result, c.client.List(context.TODO(), "", result, opts)
}
func (c *settingController) Watch(opts metav1.ListOptions) (watch.Interface, error) {
return c.client.Watch(context.TODO(), "", opts)
}
func (c *settingController) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (*v3.Setting, error) {
result := &v3.Setting{}
return result, c.client.Patch(context.TODO(), "", name, pt, data, result, metav1.PatchOptions{}, subresources...)
}
type settingCache struct {
indexer cache.Indexer
resource schema.GroupResource
}
func (c *settingCache) Get(name string) (*v3.Setting, error) {
obj, exists, err := c.indexer.GetByKey(name)
if err != nil {
return nil, err
}
if !exists {
return nil, errors.NewNotFound(c.resource, name)
}
return obj.(*v3.Setting), nil
}
func (c *settingCache) List(selector labels.Selector) (ret []*v3.Setting, err error) {
err = cache.ListAll(c.indexer, selector, func(m interface{}) {
ret = append(ret, m.(*v3.Setting))
})
return ret, err
}
func (c *settingCache) AddIndexer(indexName string, indexer SettingIndexer) {
utilruntime.Must(c.indexer.AddIndexers(map[string]cache.IndexFunc{
indexName: func(obj interface{}) (strings []string, e error) {
return indexer(obj.(*v3.Setting))
},
}))
}
func (c *settingCache) GetByIndex(indexName, key string) (result []*v3.Setting, err error) {
objs, err := c.indexer.ByIndex(indexName, key)
if err != nil {
return nil, err
}
result = make([]*v3.Setting, 0, len(objs))
for _, obj := range objs {
result = append(result, obj.(*v3.Setting))
}
return result, nil
}

View File

@@ -0,0 +1,67 @@
/*
Copyright 2021 Rancher Labs, Inc.
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.
package provisioning
import (
"github.com/rancher/wrangler/pkg/generic"
"k8s.io/client-go/rest"
)
type Factory struct {
*generic.Factory
}
func NewFactoryFromConfigOrDie(config *rest.Config) *Factory {
f, err := NewFactoryFromConfig(config)
if err != nil {
panic(err)
}
return f
}
func NewFactoryFromConfig(config *rest.Config) (*Factory, error) {
return NewFactoryFromConfigWithOptions(config, nil)
}
func NewFactoryFromConfigWithNamespace(config *rest.Config, namespace string) (*Factory, error) {
return NewFactoryFromConfigWithOptions(config, &FactoryOptions{
Namespace: namespace,
})
}
type FactoryOptions = generic.FactoryOptions
func NewFactoryFromConfigWithOptions(config *rest.Config, opts *FactoryOptions) (*Factory, error) {
f, err := generic.NewFactoryFromConfigWithOptions(config, opts)
return &Factory{
Factory: f,
}, err
}
func NewFactoryFromConfigWithOptionsOrDie(config *rest.Config, opts *FactoryOptions) *Factory {
f, err := NewFactoryFromConfigWithOptions(config, opts)
if err != nil {
panic(err)
}
return f
}
func (c *Factory) Provisioning() Interface {
return New(c.ControllerFactory())
}

View File

@@ -0,0 +1,43 @@
/*
Copyright 2021 Rancher Labs, Inc.
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.
package provisioning
import (
"github.com/rancher/lasso/pkg/controller"
v1 "github.com/rancher/os/pkg/generated/controllers/provisioning.cattle.io/v1"
)
type Interface interface {
V1() v1.Interface
}
type group struct {
controllerFactory controller.SharedControllerFactory
}
// New returns a new Interface.
func New(controllerFactory controller.SharedControllerFactory) Interface {
return &group{
controllerFactory: controllerFactory,
}
}
func (g *group) V1() v1.Interface {
return v1.New(g.controllerFactory)
}

View File

@@ -0,0 +1,376 @@
/*
Copyright 2021 Rancher Labs, Inc.
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.
package v1
import (
"context"
"time"
"github.com/rancher/lasso/pkg/client"
"github.com/rancher/lasso/pkg/controller"
v1 "github.com/rancher/rancher/pkg/apis/provisioning.cattle.io/v1"
"github.com/rancher/wrangler/pkg/apply"
"github.com/rancher/wrangler/pkg/condition"
"github.com/rancher/wrangler/pkg/generic"
"github.com/rancher/wrangler/pkg/kv"
"k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/tools/cache"
)
type ClusterHandler func(string, *v1.Cluster) (*v1.Cluster, error)
type ClusterController interface {
generic.ControllerMeta
ClusterClient
OnChange(ctx context.Context, name string, sync ClusterHandler)
OnRemove(ctx context.Context, name string, sync ClusterHandler)
Enqueue(namespace, name string)
EnqueueAfter(namespace, name string, duration time.Duration)
Cache() ClusterCache
}
type ClusterClient interface {
Create(*v1.Cluster) (*v1.Cluster, error)
Update(*v1.Cluster) (*v1.Cluster, error)
UpdateStatus(*v1.Cluster) (*v1.Cluster, error)
Delete(namespace, name string, options *metav1.DeleteOptions) error
Get(namespace, name string, options metav1.GetOptions) (*v1.Cluster, error)
List(namespace string, opts metav1.ListOptions) (*v1.ClusterList, error)
Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error)
Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.Cluster, err error)
}
type ClusterCache interface {
Get(namespace, name string) (*v1.Cluster, error)
List(namespace string, selector labels.Selector) ([]*v1.Cluster, error)
AddIndexer(indexName string, indexer ClusterIndexer)
GetByIndex(indexName, key string) ([]*v1.Cluster, error)
}
type ClusterIndexer func(obj *v1.Cluster) ([]string, error)
type clusterController struct {
controller controller.SharedController
client *client.Client
gvk schema.GroupVersionKind
groupResource schema.GroupResource
}
func NewClusterController(gvk schema.GroupVersionKind, resource string, namespaced bool, controller controller.SharedControllerFactory) ClusterController {
c := controller.ForResourceKind(gvk.GroupVersion().WithResource(resource), gvk.Kind, namespaced)
return &clusterController{
controller: c,
client: c.Client(),
gvk: gvk,
groupResource: schema.GroupResource{
Group: gvk.Group,
Resource: resource,
},
}
}
func FromClusterHandlerToHandler(sync ClusterHandler) generic.Handler {
return func(key string, obj runtime.Object) (ret runtime.Object, err error) {
var v *v1.Cluster
if obj == nil {
v, err = sync(key, nil)
} else {
v, err = sync(key, obj.(*v1.Cluster))
}
if v == nil {
return nil, err
}
return v, err
}
}
func (c *clusterController) Updater() generic.Updater {
return func(obj runtime.Object) (runtime.Object, error) {
newObj, err := c.Update(obj.(*v1.Cluster))
if newObj == nil {
return nil, err
}
return newObj, err
}
}
func UpdateClusterDeepCopyOnChange(client ClusterClient, obj *v1.Cluster, handler func(obj *v1.Cluster) (*v1.Cluster, error)) (*v1.Cluster, error) {
if obj == nil {
return obj, nil
}
copyObj := obj.DeepCopy()
newObj, err := handler(copyObj)
if newObj != nil {
copyObj = newObj
}
if obj.ResourceVersion == copyObj.ResourceVersion && !equality.Semantic.DeepEqual(obj, copyObj) {
return client.Update(copyObj)
}
return copyObj, err
}
func (c *clusterController) AddGenericHandler(ctx context.Context, name string, handler generic.Handler) {
c.controller.RegisterHandler(ctx, name, controller.SharedControllerHandlerFunc(handler))
}
func (c *clusterController) AddGenericRemoveHandler(ctx context.Context, name string, handler generic.Handler) {
c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), handler))
}
func (c *clusterController) OnChange(ctx context.Context, name string, sync ClusterHandler) {
c.AddGenericHandler(ctx, name, FromClusterHandlerToHandler(sync))
}
func (c *clusterController) OnRemove(ctx context.Context, name string, sync ClusterHandler) {
c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), FromClusterHandlerToHandler(sync)))
}
func (c *clusterController) Enqueue(namespace, name string) {
c.controller.Enqueue(namespace, name)
}
func (c *clusterController) EnqueueAfter(namespace, name string, duration time.Duration) {
c.controller.EnqueueAfter(namespace, name, duration)
}
func (c *clusterController) Informer() cache.SharedIndexInformer {
return c.controller.Informer()
}
func (c *clusterController) GroupVersionKind() schema.GroupVersionKind {
return c.gvk
}
func (c *clusterController) Cache() ClusterCache {
return &clusterCache{
indexer: c.Informer().GetIndexer(),
resource: c.groupResource,
}
}
func (c *clusterController) Create(obj *v1.Cluster) (*v1.Cluster, error) {
result := &v1.Cluster{}
return result, c.client.Create(context.TODO(), obj.Namespace, obj, result, metav1.CreateOptions{})
}
func (c *clusterController) Update(obj *v1.Cluster) (*v1.Cluster, error) {
result := &v1.Cluster{}
return result, c.client.Update(context.TODO(), obj.Namespace, obj, result, metav1.UpdateOptions{})
}
func (c *clusterController) UpdateStatus(obj *v1.Cluster) (*v1.Cluster, error) {
result := &v1.Cluster{}
return result, c.client.UpdateStatus(context.TODO(), obj.Namespace, obj, result, metav1.UpdateOptions{})
}
func (c *clusterController) Delete(namespace, name string, options *metav1.DeleteOptions) error {
if options == nil {
options = &metav1.DeleteOptions{}
}
return c.client.Delete(context.TODO(), namespace, name, *options)
}
func (c *clusterController) Get(namespace, name string, options metav1.GetOptions) (*v1.Cluster, error) {
result := &v1.Cluster{}
return result, c.client.Get(context.TODO(), namespace, name, result, options)
}
func (c *clusterController) List(namespace string, opts metav1.ListOptions) (*v1.ClusterList, error) {
result := &v1.ClusterList{}
return result, c.client.List(context.TODO(), namespace, result, opts)
}
func (c *clusterController) Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) {
return c.client.Watch(context.TODO(), namespace, opts)
}
func (c *clusterController) Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (*v1.Cluster, error) {
result := &v1.Cluster{}
return result, c.client.Patch(context.TODO(), namespace, name, pt, data, result, metav1.PatchOptions{}, subresources...)
}
type clusterCache struct {
indexer cache.Indexer
resource schema.GroupResource
}
func (c *clusterCache) Get(namespace, name string) (*v1.Cluster, error) {
obj, exists, err := c.indexer.GetByKey(namespace + "/" + name)
if err != nil {
return nil, err
}
if !exists {
return nil, errors.NewNotFound(c.resource, name)
}
return obj.(*v1.Cluster), nil
}
func (c *clusterCache) List(namespace string, selector labels.Selector) (ret []*v1.Cluster, err error) {
err = cache.ListAllByNamespace(c.indexer, namespace, selector, func(m interface{}) {
ret = append(ret, m.(*v1.Cluster))
})
return ret, err
}
func (c *clusterCache) AddIndexer(indexName string, indexer ClusterIndexer) {
utilruntime.Must(c.indexer.AddIndexers(map[string]cache.IndexFunc{
indexName: func(obj interface{}) (strings []string, e error) {
return indexer(obj.(*v1.Cluster))
},
}))
}
func (c *clusterCache) GetByIndex(indexName, key string) (result []*v1.Cluster, err error) {
objs, err := c.indexer.ByIndex(indexName, key)
if err != nil {
return nil, err
}
result = make([]*v1.Cluster, 0, len(objs))
for _, obj := range objs {
result = append(result, obj.(*v1.Cluster))
}
return result, nil
}
type ClusterStatusHandler func(obj *v1.Cluster, status v1.ClusterStatus) (v1.ClusterStatus, error)
type ClusterGeneratingHandler func(obj *v1.Cluster, status v1.ClusterStatus) ([]runtime.Object, v1.ClusterStatus, error)
func RegisterClusterStatusHandler(ctx context.Context, controller ClusterController, condition condition.Cond, name string, handler ClusterStatusHandler) {
statusHandler := &clusterStatusHandler{
client: controller,
condition: condition,
handler: handler,
}
controller.AddGenericHandler(ctx, name, FromClusterHandlerToHandler(statusHandler.sync))
}
func RegisterClusterGeneratingHandler(ctx context.Context, controller ClusterController, apply apply.Apply,
condition condition.Cond, name string, handler ClusterGeneratingHandler, opts *generic.GeneratingHandlerOptions) {
statusHandler := &clusterGeneratingHandler{
ClusterGeneratingHandler: handler,
apply: apply,
name: name,
gvk: controller.GroupVersionKind(),
}
if opts != nil {
statusHandler.opts = *opts
}
controller.OnChange(ctx, name, statusHandler.Remove)
RegisterClusterStatusHandler(ctx, controller, condition, name, statusHandler.Handle)
}
type clusterStatusHandler struct {
client ClusterClient
condition condition.Cond
handler ClusterStatusHandler
}
func (a *clusterStatusHandler) sync(key string, obj *v1.Cluster) (*v1.Cluster, error) {
if obj == nil {
return obj, nil
}
origStatus := obj.Status.DeepCopy()
obj = obj.DeepCopy()
newStatus, err := a.handler(obj, obj.Status)
if err != nil {
// Revert to old status on error
newStatus = *origStatus.DeepCopy()
}
if a.condition != "" {
if errors.IsConflict(err) {
a.condition.SetError(&newStatus, "", nil)
} else {
a.condition.SetError(&newStatus, "", err)
}
}
if !equality.Semantic.DeepEqual(origStatus, &newStatus) {
if a.condition != "" {
// Since status has changed, update the lastUpdatedTime
a.condition.LastUpdated(&newStatus, time.Now().UTC().Format(time.RFC3339))
}
var newErr error
obj.Status = newStatus
newObj, newErr := a.client.UpdateStatus(obj)
if err == nil {
err = newErr
}
if newErr == nil {
obj = newObj
}
}
return obj, err
}
type clusterGeneratingHandler struct {
ClusterGeneratingHandler
apply apply.Apply
opts generic.GeneratingHandlerOptions
gvk schema.GroupVersionKind
name string
}
func (a *clusterGeneratingHandler) Remove(key string, obj *v1.Cluster) (*v1.Cluster, error) {
if obj != nil {
return obj, nil
}
obj = &v1.Cluster{}
obj.Namespace, obj.Name = kv.RSplit(key, "/")
obj.SetGroupVersionKind(a.gvk)
return nil, generic.ConfigureApplyForObject(a.apply, obj, &a.opts).
WithOwner(obj).
WithSetID(a.name).
ApplyObjects()
}
func (a *clusterGeneratingHandler) Handle(obj *v1.Cluster, status v1.ClusterStatus) (v1.ClusterStatus, error) {
if !obj.DeletionTimestamp.IsZero() {
return status, nil
}
objs, newStatus, err := a.ClusterGeneratingHandler(obj, status)
if err != nil {
return newStatus, err
}
return newStatus, generic.ConfigureApplyForObject(a.apply, obj, &a.opts).
WithOwner(obj).
WithSetID(a.name).
ApplyObjects(objs...)
}

View File

@@ -0,0 +1,48 @@
/*
Copyright 2021 Rancher Labs, Inc.
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.
package v1
import (
"github.com/rancher/lasso/pkg/controller"
v1 "github.com/rancher/rancher/pkg/apis/provisioning.cattle.io/v1"
"github.com/rancher/wrangler/pkg/schemes"
"k8s.io/apimachinery/pkg/runtime/schema"
)
func init() {
schemes.Register(v1.AddToScheme)
}
type Interface interface {
Cluster() ClusterController
}
func New(controllerFactory controller.SharedControllerFactory) Interface {
return &version{
controllerFactory: controllerFactory,
}
}
type version struct {
controllerFactory controller.SharedControllerFactory
}
func (c *version) Cluster() ClusterController {
return NewClusterController(schema.GroupVersionKind{Group: "provisioning.cattle.io", Version: "v1", Kind: "Cluster"}, "clusters", true, c.controllerFactory)
}

View File

@@ -0,0 +1,67 @@
/*
Copyright 2021 Rancher Labs, Inc.
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.
package rancheros
import (
"github.com/rancher/wrangler/pkg/generic"
"k8s.io/client-go/rest"
)
type Factory struct {
*generic.Factory
}
func NewFactoryFromConfigOrDie(config *rest.Config) *Factory {
f, err := NewFactoryFromConfig(config)
if err != nil {
panic(err)
}
return f
}
func NewFactoryFromConfig(config *rest.Config) (*Factory, error) {
return NewFactoryFromConfigWithOptions(config, nil)
}
func NewFactoryFromConfigWithNamespace(config *rest.Config, namespace string) (*Factory, error) {
return NewFactoryFromConfigWithOptions(config, &FactoryOptions{
Namespace: namespace,
})
}
type FactoryOptions = generic.FactoryOptions
func NewFactoryFromConfigWithOptions(config *rest.Config, opts *FactoryOptions) (*Factory, error) {
f, err := generic.NewFactoryFromConfigWithOptions(config, opts)
return &Factory{
Factory: f,
}, err
}
func NewFactoryFromConfigWithOptionsOrDie(config *rest.Config, opts *FactoryOptions) *Factory {
f, err := NewFactoryFromConfigWithOptions(config, opts)
if err != nil {
panic(err)
}
return f
}
func (c *Factory) Rancheros() Interface {
return New(c.ControllerFactory())
}

View File

@@ -0,0 +1,43 @@
/*
Copyright 2021 Rancher Labs, Inc.
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.
package rancheros
import (
"github.com/rancher/lasso/pkg/controller"
v1 "github.com/rancher/os/pkg/generated/controllers/rancheros.cattle.io/v1"
)
type Interface interface {
V1() v1.Interface
}
type group struct {
controllerFactory controller.SharedControllerFactory
}
// New returns a new Interface.
func New(controllerFactory controller.SharedControllerFactory) Interface {
return &group{
controllerFactory: controllerFactory,
}
}
func (g *group) V1() v1.Interface {
return v1.New(g.controllerFactory)
}

View File

@@ -0,0 +1,52 @@
/*
Copyright 2021 Rancher Labs, Inc.
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.
package v1
import (
"github.com/rancher/lasso/pkg/controller"
v1 "github.com/rancher/os/pkg/apis/rancheros.cattle.io/v1"
"github.com/rancher/wrangler/pkg/schemes"
"k8s.io/apimachinery/pkg/runtime/schema"
)
func init() {
schemes.Register(v1.AddToScheme)
}
type Interface interface {
MachineInventory() MachineInventoryController
ManagedOSImage() ManagedOSImageController
}
func New(controllerFactory controller.SharedControllerFactory) Interface {
return &version{
controllerFactory: controllerFactory,
}
}
type version struct {
controllerFactory controller.SharedControllerFactory
}
func (c *version) MachineInventory() MachineInventoryController {
return NewMachineInventoryController(schema.GroupVersionKind{Group: "rancheros.cattle.io", Version: "v1", Kind: "MachineInventory"}, "machineinventories", true, c.controllerFactory)
}
func (c *version) ManagedOSImage() ManagedOSImageController {
return NewManagedOSImageController(schema.GroupVersionKind{Group: "rancheros.cattle.io", Version: "v1", Kind: "ManagedOSImage"}, "managedosimages", true, c.controllerFactory)
}

View File

@@ -0,0 +1,376 @@
/*
Copyright 2021 Rancher Labs, Inc.
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.
package v1
import (
"context"
"time"
"github.com/rancher/lasso/pkg/client"
"github.com/rancher/lasso/pkg/controller"
v1 "github.com/rancher/os/pkg/apis/rancheros.cattle.io/v1"
"github.com/rancher/wrangler/pkg/apply"
"github.com/rancher/wrangler/pkg/condition"
"github.com/rancher/wrangler/pkg/generic"
"github.com/rancher/wrangler/pkg/kv"
"k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/tools/cache"
)
type MachineInventoryHandler func(string, *v1.MachineInventory) (*v1.MachineInventory, error)
type MachineInventoryController interface {
generic.ControllerMeta
MachineInventoryClient
OnChange(ctx context.Context, name string, sync MachineInventoryHandler)
OnRemove(ctx context.Context, name string, sync MachineInventoryHandler)
Enqueue(namespace, name string)
EnqueueAfter(namespace, name string, duration time.Duration)
Cache() MachineInventoryCache
}
type MachineInventoryClient interface {
Create(*v1.MachineInventory) (*v1.MachineInventory, error)
Update(*v1.MachineInventory) (*v1.MachineInventory, error)
UpdateStatus(*v1.MachineInventory) (*v1.MachineInventory, error)
Delete(namespace, name string, options *metav1.DeleteOptions) error
Get(namespace, name string, options metav1.GetOptions) (*v1.MachineInventory, error)
List(namespace string, opts metav1.ListOptions) (*v1.MachineInventoryList, error)
Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error)
Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.MachineInventory, err error)
}
type MachineInventoryCache interface {
Get(namespace, name string) (*v1.MachineInventory, error)
List(namespace string, selector labels.Selector) ([]*v1.MachineInventory, error)
AddIndexer(indexName string, indexer MachineInventoryIndexer)
GetByIndex(indexName, key string) ([]*v1.MachineInventory, error)
}
type MachineInventoryIndexer func(obj *v1.MachineInventory) ([]string, error)
type machineInventoryController struct {
controller controller.SharedController
client *client.Client
gvk schema.GroupVersionKind
groupResource schema.GroupResource
}
func NewMachineInventoryController(gvk schema.GroupVersionKind, resource string, namespaced bool, controller controller.SharedControllerFactory) MachineInventoryController {
c := controller.ForResourceKind(gvk.GroupVersion().WithResource(resource), gvk.Kind, namespaced)
return &machineInventoryController{
controller: c,
client: c.Client(),
gvk: gvk,
groupResource: schema.GroupResource{
Group: gvk.Group,
Resource: resource,
},
}
}
func FromMachineInventoryHandlerToHandler(sync MachineInventoryHandler) generic.Handler {
return func(key string, obj runtime.Object) (ret runtime.Object, err error) {
var v *v1.MachineInventory
if obj == nil {
v, err = sync(key, nil)
} else {
v, err = sync(key, obj.(*v1.MachineInventory))
}
if v == nil {
return nil, err
}
return v, err
}
}
func (c *machineInventoryController) Updater() generic.Updater {
return func(obj runtime.Object) (runtime.Object, error) {
newObj, err := c.Update(obj.(*v1.MachineInventory))
if newObj == nil {
return nil, err
}
return newObj, err
}
}
func UpdateMachineInventoryDeepCopyOnChange(client MachineInventoryClient, obj *v1.MachineInventory, handler func(obj *v1.MachineInventory) (*v1.MachineInventory, error)) (*v1.MachineInventory, error) {
if obj == nil {
return obj, nil
}
copyObj := obj.DeepCopy()
newObj, err := handler(copyObj)
if newObj != nil {
copyObj = newObj
}
if obj.ResourceVersion == copyObj.ResourceVersion && !equality.Semantic.DeepEqual(obj, copyObj) {
return client.Update(copyObj)
}
return copyObj, err
}
func (c *machineInventoryController) AddGenericHandler(ctx context.Context, name string, handler generic.Handler) {
c.controller.RegisterHandler(ctx, name, controller.SharedControllerHandlerFunc(handler))
}
func (c *machineInventoryController) AddGenericRemoveHandler(ctx context.Context, name string, handler generic.Handler) {
c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), handler))
}
func (c *machineInventoryController) OnChange(ctx context.Context, name string, sync MachineInventoryHandler) {
c.AddGenericHandler(ctx, name, FromMachineInventoryHandlerToHandler(sync))
}
func (c *machineInventoryController) OnRemove(ctx context.Context, name string, sync MachineInventoryHandler) {
c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), FromMachineInventoryHandlerToHandler(sync)))
}
func (c *machineInventoryController) Enqueue(namespace, name string) {
c.controller.Enqueue(namespace, name)
}
func (c *machineInventoryController) EnqueueAfter(namespace, name string, duration time.Duration) {
c.controller.EnqueueAfter(namespace, name, duration)
}
func (c *machineInventoryController) Informer() cache.SharedIndexInformer {
return c.controller.Informer()
}
func (c *machineInventoryController) GroupVersionKind() schema.GroupVersionKind {
return c.gvk
}
func (c *machineInventoryController) Cache() MachineInventoryCache {
return &machineInventoryCache{
indexer: c.Informer().GetIndexer(),
resource: c.groupResource,
}
}
func (c *machineInventoryController) Create(obj *v1.MachineInventory) (*v1.MachineInventory, error) {
result := &v1.MachineInventory{}
return result, c.client.Create(context.TODO(), obj.Namespace, obj, result, metav1.CreateOptions{})
}
func (c *machineInventoryController) Update(obj *v1.MachineInventory) (*v1.MachineInventory, error) {
result := &v1.MachineInventory{}
return result, c.client.Update(context.TODO(), obj.Namespace, obj, result, metav1.UpdateOptions{})
}
func (c *machineInventoryController) UpdateStatus(obj *v1.MachineInventory) (*v1.MachineInventory, error) {
result := &v1.MachineInventory{}
return result, c.client.UpdateStatus(context.TODO(), obj.Namespace, obj, result, metav1.UpdateOptions{})
}
func (c *machineInventoryController) Delete(namespace, name string, options *metav1.DeleteOptions) error {
if options == nil {
options = &metav1.DeleteOptions{}
}
return c.client.Delete(context.TODO(), namespace, name, *options)
}
func (c *machineInventoryController) Get(namespace, name string, options metav1.GetOptions) (*v1.MachineInventory, error) {
result := &v1.MachineInventory{}
return result, c.client.Get(context.TODO(), namespace, name, result, options)
}
func (c *machineInventoryController) List(namespace string, opts metav1.ListOptions) (*v1.MachineInventoryList, error) {
result := &v1.MachineInventoryList{}
return result, c.client.List(context.TODO(), namespace, result, opts)
}
func (c *machineInventoryController) Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) {
return c.client.Watch(context.TODO(), namespace, opts)
}
func (c *machineInventoryController) Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (*v1.MachineInventory, error) {
result := &v1.MachineInventory{}
return result, c.client.Patch(context.TODO(), namespace, name, pt, data, result, metav1.PatchOptions{}, subresources...)
}
type machineInventoryCache struct {
indexer cache.Indexer
resource schema.GroupResource
}
func (c *machineInventoryCache) Get(namespace, name string) (*v1.MachineInventory, error) {
obj, exists, err := c.indexer.GetByKey(namespace + "/" + name)
if err != nil {
return nil, err
}
if !exists {
return nil, errors.NewNotFound(c.resource, name)
}
return obj.(*v1.MachineInventory), nil
}
func (c *machineInventoryCache) List(namespace string, selector labels.Selector) (ret []*v1.MachineInventory, err error) {
err = cache.ListAllByNamespace(c.indexer, namespace, selector, func(m interface{}) {
ret = append(ret, m.(*v1.MachineInventory))
})
return ret, err
}
func (c *machineInventoryCache) AddIndexer(indexName string, indexer MachineInventoryIndexer) {
utilruntime.Must(c.indexer.AddIndexers(map[string]cache.IndexFunc{
indexName: func(obj interface{}) (strings []string, e error) {
return indexer(obj.(*v1.MachineInventory))
},
}))
}
func (c *machineInventoryCache) GetByIndex(indexName, key string) (result []*v1.MachineInventory, err error) {
objs, err := c.indexer.ByIndex(indexName, key)
if err != nil {
return nil, err
}
result = make([]*v1.MachineInventory, 0, len(objs))
for _, obj := range objs {
result = append(result, obj.(*v1.MachineInventory))
}
return result, nil
}
type MachineInventoryStatusHandler func(obj *v1.MachineInventory, status v1.MachineInventoryStatus) (v1.MachineInventoryStatus, error)
type MachineInventoryGeneratingHandler func(obj *v1.MachineInventory, status v1.MachineInventoryStatus) ([]runtime.Object, v1.MachineInventoryStatus, error)
func RegisterMachineInventoryStatusHandler(ctx context.Context, controller MachineInventoryController, condition condition.Cond, name string, handler MachineInventoryStatusHandler) {
statusHandler := &machineInventoryStatusHandler{
client: controller,
condition: condition,
handler: handler,
}
controller.AddGenericHandler(ctx, name, FromMachineInventoryHandlerToHandler(statusHandler.sync))
}
func RegisterMachineInventoryGeneratingHandler(ctx context.Context, controller MachineInventoryController, apply apply.Apply,
condition condition.Cond, name string, handler MachineInventoryGeneratingHandler, opts *generic.GeneratingHandlerOptions) {
statusHandler := &machineInventoryGeneratingHandler{
MachineInventoryGeneratingHandler: handler,
apply: apply,
name: name,
gvk: controller.GroupVersionKind(),
}
if opts != nil {
statusHandler.opts = *opts
}
controller.OnChange(ctx, name, statusHandler.Remove)
RegisterMachineInventoryStatusHandler(ctx, controller, condition, name, statusHandler.Handle)
}
type machineInventoryStatusHandler struct {
client MachineInventoryClient
condition condition.Cond
handler MachineInventoryStatusHandler
}
func (a *machineInventoryStatusHandler) sync(key string, obj *v1.MachineInventory) (*v1.MachineInventory, error) {
if obj == nil {
return obj, nil
}
origStatus := obj.Status.DeepCopy()
obj = obj.DeepCopy()
newStatus, err := a.handler(obj, obj.Status)
if err != nil {
// Revert to old status on error
newStatus = *origStatus.DeepCopy()
}
if a.condition != "" {
if errors.IsConflict(err) {
a.condition.SetError(&newStatus, "", nil)
} else {
a.condition.SetError(&newStatus, "", err)
}
}
if !equality.Semantic.DeepEqual(origStatus, &newStatus) {
if a.condition != "" {
// Since status has changed, update the lastUpdatedTime
a.condition.LastUpdated(&newStatus, time.Now().UTC().Format(time.RFC3339))
}
var newErr error
obj.Status = newStatus
newObj, newErr := a.client.UpdateStatus(obj)
if err == nil {
err = newErr
}
if newErr == nil {
obj = newObj
}
}
return obj, err
}
type machineInventoryGeneratingHandler struct {
MachineInventoryGeneratingHandler
apply apply.Apply
opts generic.GeneratingHandlerOptions
gvk schema.GroupVersionKind
name string
}
func (a *machineInventoryGeneratingHandler) Remove(key string, obj *v1.MachineInventory) (*v1.MachineInventory, error) {
if obj != nil {
return obj, nil
}
obj = &v1.MachineInventory{}
obj.Namespace, obj.Name = kv.RSplit(key, "/")
obj.SetGroupVersionKind(a.gvk)
return nil, generic.ConfigureApplyForObject(a.apply, obj, &a.opts).
WithOwner(obj).
WithSetID(a.name).
ApplyObjects()
}
func (a *machineInventoryGeneratingHandler) Handle(obj *v1.MachineInventory, status v1.MachineInventoryStatus) (v1.MachineInventoryStatus, error) {
if !obj.DeletionTimestamp.IsZero() {
return status, nil
}
objs, newStatus, err := a.MachineInventoryGeneratingHandler(obj, status)
if err != nil {
return newStatus, err
}
return newStatus, generic.ConfigureApplyForObject(a.apply, obj, &a.opts).
WithOwner(obj).
WithSetID(a.name).
ApplyObjects(objs...)
}

View File

@@ -0,0 +1,376 @@
/*
Copyright 2021 Rancher Labs, Inc.
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.
package v1
import (
"context"
"time"
"github.com/rancher/lasso/pkg/client"
"github.com/rancher/lasso/pkg/controller"
v1 "github.com/rancher/os/pkg/apis/rancheros.cattle.io/v1"
"github.com/rancher/wrangler/pkg/apply"
"github.com/rancher/wrangler/pkg/condition"
"github.com/rancher/wrangler/pkg/generic"
"github.com/rancher/wrangler/pkg/kv"
"k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/tools/cache"
)
type ManagedOSImageHandler func(string, *v1.ManagedOSImage) (*v1.ManagedOSImage, error)
type ManagedOSImageController interface {
generic.ControllerMeta
ManagedOSImageClient
OnChange(ctx context.Context, name string, sync ManagedOSImageHandler)
OnRemove(ctx context.Context, name string, sync ManagedOSImageHandler)
Enqueue(namespace, name string)
EnqueueAfter(namespace, name string, duration time.Duration)
Cache() ManagedOSImageCache
}
type ManagedOSImageClient interface {
Create(*v1.ManagedOSImage) (*v1.ManagedOSImage, error)
Update(*v1.ManagedOSImage) (*v1.ManagedOSImage, error)
UpdateStatus(*v1.ManagedOSImage) (*v1.ManagedOSImage, error)
Delete(namespace, name string, options *metav1.DeleteOptions) error
Get(namespace, name string, options metav1.GetOptions) (*v1.ManagedOSImage, error)
List(namespace string, opts metav1.ListOptions) (*v1.ManagedOSImageList, error)
Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error)
Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.ManagedOSImage, err error)
}
type ManagedOSImageCache interface {
Get(namespace, name string) (*v1.ManagedOSImage, error)
List(namespace string, selector labels.Selector) ([]*v1.ManagedOSImage, error)
AddIndexer(indexName string, indexer ManagedOSImageIndexer)
GetByIndex(indexName, key string) ([]*v1.ManagedOSImage, error)
}
type ManagedOSImageIndexer func(obj *v1.ManagedOSImage) ([]string, error)
type managedOSImageController struct {
controller controller.SharedController
client *client.Client
gvk schema.GroupVersionKind
groupResource schema.GroupResource
}
func NewManagedOSImageController(gvk schema.GroupVersionKind, resource string, namespaced bool, controller controller.SharedControllerFactory) ManagedOSImageController {
c := controller.ForResourceKind(gvk.GroupVersion().WithResource(resource), gvk.Kind, namespaced)
return &managedOSImageController{
controller: c,
client: c.Client(),
gvk: gvk,
groupResource: schema.GroupResource{
Group: gvk.Group,
Resource: resource,
},
}
}
func FromManagedOSImageHandlerToHandler(sync ManagedOSImageHandler) generic.Handler {
return func(key string, obj runtime.Object) (ret runtime.Object, err error) {
var v *v1.ManagedOSImage
if obj == nil {
v, err = sync(key, nil)
} else {
v, err = sync(key, obj.(*v1.ManagedOSImage))
}
if v == nil {
return nil, err
}
return v, err
}
}
func (c *managedOSImageController) Updater() generic.Updater {
return func(obj runtime.Object) (runtime.Object, error) {
newObj, err := c.Update(obj.(*v1.ManagedOSImage))
if newObj == nil {
return nil, err
}
return newObj, err
}
}
func UpdateManagedOSImageDeepCopyOnChange(client ManagedOSImageClient, obj *v1.ManagedOSImage, handler func(obj *v1.ManagedOSImage) (*v1.ManagedOSImage, error)) (*v1.ManagedOSImage, error) {
if obj == nil {
return obj, nil
}
copyObj := obj.DeepCopy()
newObj, err := handler(copyObj)
if newObj != nil {
copyObj = newObj
}
if obj.ResourceVersion == copyObj.ResourceVersion && !equality.Semantic.DeepEqual(obj, copyObj) {
return client.Update(copyObj)
}
return copyObj, err
}
func (c *managedOSImageController) AddGenericHandler(ctx context.Context, name string, handler generic.Handler) {
c.controller.RegisterHandler(ctx, name, controller.SharedControllerHandlerFunc(handler))
}
func (c *managedOSImageController) AddGenericRemoveHandler(ctx context.Context, name string, handler generic.Handler) {
c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), handler))
}
func (c *managedOSImageController) OnChange(ctx context.Context, name string, sync ManagedOSImageHandler) {
c.AddGenericHandler(ctx, name, FromManagedOSImageHandlerToHandler(sync))
}
func (c *managedOSImageController) OnRemove(ctx context.Context, name string, sync ManagedOSImageHandler) {
c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), FromManagedOSImageHandlerToHandler(sync)))
}
func (c *managedOSImageController) Enqueue(namespace, name string) {
c.controller.Enqueue(namespace, name)
}
func (c *managedOSImageController) EnqueueAfter(namespace, name string, duration time.Duration) {
c.controller.EnqueueAfter(namespace, name, duration)
}
func (c *managedOSImageController) Informer() cache.SharedIndexInformer {
return c.controller.Informer()
}
func (c *managedOSImageController) GroupVersionKind() schema.GroupVersionKind {
return c.gvk
}
func (c *managedOSImageController) Cache() ManagedOSImageCache {
return &managedOSImageCache{
indexer: c.Informer().GetIndexer(),
resource: c.groupResource,
}
}
func (c *managedOSImageController) Create(obj *v1.ManagedOSImage) (*v1.ManagedOSImage, error) {
result := &v1.ManagedOSImage{}
return result, c.client.Create(context.TODO(), obj.Namespace, obj, result, metav1.CreateOptions{})
}
func (c *managedOSImageController) Update(obj *v1.ManagedOSImage) (*v1.ManagedOSImage, error) {
result := &v1.ManagedOSImage{}
return result, c.client.Update(context.TODO(), obj.Namespace, obj, result, metav1.UpdateOptions{})
}
func (c *managedOSImageController) UpdateStatus(obj *v1.ManagedOSImage) (*v1.ManagedOSImage, error) {
result := &v1.ManagedOSImage{}
return result, c.client.UpdateStatus(context.TODO(), obj.Namespace, obj, result, metav1.UpdateOptions{})
}
func (c *managedOSImageController) Delete(namespace, name string, options *metav1.DeleteOptions) error {
if options == nil {
options = &metav1.DeleteOptions{}
}
return c.client.Delete(context.TODO(), namespace, name, *options)
}
func (c *managedOSImageController) Get(namespace, name string, options metav1.GetOptions) (*v1.ManagedOSImage, error) {
result := &v1.ManagedOSImage{}
return result, c.client.Get(context.TODO(), namespace, name, result, options)
}
func (c *managedOSImageController) List(namespace string, opts metav1.ListOptions) (*v1.ManagedOSImageList, error) {
result := &v1.ManagedOSImageList{}
return result, c.client.List(context.TODO(), namespace, result, opts)
}
func (c *managedOSImageController) Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) {
return c.client.Watch(context.TODO(), namespace, opts)
}
func (c *managedOSImageController) Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (*v1.ManagedOSImage, error) {
result := &v1.ManagedOSImage{}
return result, c.client.Patch(context.TODO(), namespace, name, pt, data, result, metav1.PatchOptions{}, subresources...)
}
type managedOSImageCache struct {
indexer cache.Indexer
resource schema.GroupResource
}
func (c *managedOSImageCache) Get(namespace, name string) (*v1.ManagedOSImage, error) {
obj, exists, err := c.indexer.GetByKey(namespace + "/" + name)
if err != nil {
return nil, err
}
if !exists {
return nil, errors.NewNotFound(c.resource, name)
}
return obj.(*v1.ManagedOSImage), nil
}
func (c *managedOSImageCache) List(namespace string, selector labels.Selector) (ret []*v1.ManagedOSImage, err error) {
err = cache.ListAllByNamespace(c.indexer, namespace, selector, func(m interface{}) {
ret = append(ret, m.(*v1.ManagedOSImage))
})
return ret, err
}
func (c *managedOSImageCache) AddIndexer(indexName string, indexer ManagedOSImageIndexer) {
utilruntime.Must(c.indexer.AddIndexers(map[string]cache.IndexFunc{
indexName: func(obj interface{}) (strings []string, e error) {
return indexer(obj.(*v1.ManagedOSImage))
},
}))
}
func (c *managedOSImageCache) GetByIndex(indexName, key string) (result []*v1.ManagedOSImage, err error) {
objs, err := c.indexer.ByIndex(indexName, key)
if err != nil {
return nil, err
}
result = make([]*v1.ManagedOSImage, 0, len(objs))
for _, obj := range objs {
result = append(result, obj.(*v1.ManagedOSImage))
}
return result, nil
}
type ManagedOSImageStatusHandler func(obj *v1.ManagedOSImage, status v1.ManagedOSImageStatus) (v1.ManagedOSImageStatus, error)
type ManagedOSImageGeneratingHandler func(obj *v1.ManagedOSImage, status v1.ManagedOSImageStatus) ([]runtime.Object, v1.ManagedOSImageStatus, error)
func RegisterManagedOSImageStatusHandler(ctx context.Context, controller ManagedOSImageController, condition condition.Cond, name string, handler ManagedOSImageStatusHandler) {
statusHandler := &managedOSImageStatusHandler{
client: controller,
condition: condition,
handler: handler,
}
controller.AddGenericHandler(ctx, name, FromManagedOSImageHandlerToHandler(statusHandler.sync))
}
func RegisterManagedOSImageGeneratingHandler(ctx context.Context, controller ManagedOSImageController, apply apply.Apply,
condition condition.Cond, name string, handler ManagedOSImageGeneratingHandler, opts *generic.GeneratingHandlerOptions) {
statusHandler := &managedOSImageGeneratingHandler{
ManagedOSImageGeneratingHandler: handler,
apply: apply,
name: name,
gvk: controller.GroupVersionKind(),
}
if opts != nil {
statusHandler.opts = *opts
}
controller.OnChange(ctx, name, statusHandler.Remove)
RegisterManagedOSImageStatusHandler(ctx, controller, condition, name, statusHandler.Handle)
}
type managedOSImageStatusHandler struct {
client ManagedOSImageClient
condition condition.Cond
handler ManagedOSImageStatusHandler
}
func (a *managedOSImageStatusHandler) sync(key string, obj *v1.ManagedOSImage) (*v1.ManagedOSImage, error) {
if obj == nil {
return obj, nil
}
origStatus := obj.Status.DeepCopy()
obj = obj.DeepCopy()
newStatus, err := a.handler(obj, obj.Status)
if err != nil {
// Revert to old status on error
newStatus = *origStatus.DeepCopy()
}
if a.condition != "" {
if errors.IsConflict(err) {
a.condition.SetError(&newStatus, "", nil)
} else {
a.condition.SetError(&newStatus, "", err)
}
}
if !equality.Semantic.DeepEqual(origStatus, &newStatus) {
if a.condition != "" {
// Since status has changed, update the lastUpdatedTime
a.condition.LastUpdated(&newStatus, time.Now().UTC().Format(time.RFC3339))
}
var newErr error
obj.Status = newStatus
newObj, newErr := a.client.UpdateStatus(obj)
if err == nil {
err = newErr
}
if newErr == nil {
obj = newObj
}
}
return obj, err
}
type managedOSImageGeneratingHandler struct {
ManagedOSImageGeneratingHandler
apply apply.Apply
opts generic.GeneratingHandlerOptions
gvk schema.GroupVersionKind
name string
}
func (a *managedOSImageGeneratingHandler) Remove(key string, obj *v1.ManagedOSImage) (*v1.ManagedOSImage, error) {
if obj != nil {
return obj, nil
}
obj = &v1.ManagedOSImage{}
obj.Namespace, obj.Name = kv.RSplit(key, "/")
obj.SetGroupVersionKind(a.gvk)
return nil, generic.ConfigureApplyForObject(a.apply, obj, &a.opts).
WithOwner(obj).
WithSetID(a.name).
ApplyObjects()
}
func (a *managedOSImageGeneratingHandler) Handle(obj *v1.ManagedOSImage, status v1.ManagedOSImageStatus) (v1.ManagedOSImageStatus, error) {
if !obj.DeletionTimestamp.IsZero() {
return status, nil
}
objs, newStatus, err := a.ManagedOSImageGeneratingHandler(obj, status)
if err != nil {
return newStatus, err
}
return newStatus, generic.ConfigureApplyForObject(a.apply, obj, &a.opts).
WithOwner(obj).
WithSetID(a.name).
ApplyObjects(objs...)
}