diff --git a/.gitignore b/.gitignore index d01b9d003..f651625a3 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,4 @@ vendor*/ .idea/ .vscode/ # ignore packr files -*-packr.go +*-packr.g \ No newline at end of file diff --git a/changelog/v0.0.2/dynamic-k8s-clients.yaml b/changelog/v0.0.2/dynamic-k8s-clients.yaml new file mode 100644 index 000000000..d05059c37 --- /dev/null +++ b/changelog/v0.0.2/dynamic-k8s-clients.yaml @@ -0,0 +1,5 @@ +changelog: +- type: NEW_FEATURE + description: Add basic dynamic kube clients.g + issueLink: https://github.com/solo-io/skv2/issues/6 + diff --git a/codegen/templates/code/types/clients.gotmpl b/codegen/templates/code/types/clients.gotmpl index 5cd00472a..7cc083457 100644 --- a/codegen/templates/code/types/clients.gotmpl +++ b/codegen/templates/code/types/clients.gotmpl @@ -25,7 +25,7 @@ type clientSet struct { client client.Client } -func NewClientsetFromConfig(cfg *rest.Config) (*clientSet, error) { +func NewClientsetFromConfig(cfg *rest.Config) (Clientset, error) { scheme := scheme.Scheme if err := AddToScheme(scheme); err != nil{ return nil, err @@ -39,7 +39,7 @@ func NewClientsetFromConfig(cfg *rest.Config) (*clientSet, error) { return NewClientset(client), nil } -func NewClientset(client client.Client) *clientSet { +func NewClientset(client client.Client) Clientset { return &clientSet{client: client} } diff --git a/codegen/test/api/things.test.io/v1/clients.go b/codegen/test/api/things.test.io/v1/clients.go index c6cb6aa84..2a5634cb4 100644 --- a/codegen/test/api/things.test.io/v1/clients.go +++ b/codegen/test/api/things.test.io/v1/clients.go @@ -20,7 +20,7 @@ type clientSet struct { client client.Client } -func NewClientsetFromConfig(cfg *rest.Config) (*clientSet, error) { +func NewClientsetFromConfig(cfg *rest.Config) (Clientset, error) { scheme := scheme.Scheme if err := AddToScheme(scheme); err != nil { return nil, err @@ -34,7 +34,7 @@ func NewClientsetFromConfig(cfg *rest.Config) (*clientSet, error) { return NewClientset(client), nil } -func NewClientset(client client.Client) *clientSet { +func NewClientset(client client.Client) Clientset { return &clientSet{client: client} } diff --git a/go.mod b/go.mod index 288cbd4b4..170c50316 100644 --- a/go.mod +++ b/go.mod @@ -31,7 +31,7 @@ require ( go.uber.org/zap v1.13.0 golang.org/x/crypto v0.0.0-20200117160349-530e935923ad // indirect golang.org/x/sys v0.0.0-20200117145432-59e60aa80a0c // indirect - golang.org/x/tools v0.0.0-20200420001825-978e26b7c37c + golang.org/x/tools v0.0.0-20200421170005-7504fd22198d k8s.io/api v0.17.2 k8s.io/apiextensions-apiserver v0.17.2 k8s.io/apimachinery v0.17.2 diff --git a/go.sum b/go.sum index a746a0c60..eaea119a8 100644 --- a/go.sum +++ b/go.sum @@ -806,8 +806,8 @@ golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5 h1:hKsoRgsbwY1NafxrwTs+k64bikrLBkAgPir1TNCj3Zs= golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20200420001825-978e26b7c37c h1:JzwTM5XxGxiCwZEIZQPG46csyhWQxQlu2uSi3bEza34= -golang.org/x/tools v0.0.0-20200420001825-978e26b7c37c/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200421170005-7504fd22198d h1:2zkujgKxxH12wdYfr5bRiRtNNLTxEaSbO6kVWKCCkfw= +golang.org/x/tools v0.0.0-20200421170005-7504fd22198d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 h1:9zdDQZ7Thm29KFXgAX/+yaf3eVbP7djjWp/dXAppNCc= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/pkg/generated/generate.go b/pkg/generated/generate.go new file mode 100644 index 000000000..2fb19c79e --- /dev/null +++ b/pkg/generated/generate.go @@ -0,0 +1,144 @@ +package main + +import ( + "log" + "path/filepath" + + "github.com/solo-io/skv2/codegen" + "github.com/solo-io/skv2/codegen/model" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +//go:generate go run generate.go + +const ( + generatedPackageName = "pkg/generated" +) + +var ( + kubeGeneratedPackage = filepath.Join(generatedPackageName, "kubernetes") +) + +func main() { + log.Println("starting kube client generation") + skv2Cmd := codegen.Command{ + Groups: []model.Group{ + { + GroupVersion: schema.GroupVersion{ + Group: "core", + Version: "v1", + }, + Module: "k8s.io/api", + Resources: []model.Resource{ + { + Kind: "Secret", + }, + { + Kind: "ServiceAccount", + }, + { + Kind: "ConfigMap", + }, + { + Kind: "Service", + }, + { + Kind: "Pod", + }, + { + Kind: "Namespace", + ClusterScoped: true, + }, + { + Kind: "Node", + ClusterScoped: true, + }, + }, + RenderController: true, + RenderClients: true, + CustomTypesImportPath: "k8s.io/api/core/v1", + ApiRoot: kubeGeneratedPackage, + }, + { + GroupVersion: schema.GroupVersion{ + Group: "apps", + Version: "v1", + }, + Module: "k8s.io/api", + Resources: []model.Resource{ + { + Kind: "Deployment", + }, + { + Kind: "ReplicaSet", + }, + }, + RenderController: true, + RenderClients: true, + CustomTypesImportPath: "k8s.io/api/apps/v1", + ApiRoot: kubeGeneratedPackage, + }, + { + GroupVersion: schema.GroupVersion{ + Group: "admissionregistration.k8s.io", + Version: "v1", + }, + Module: "k8s.io/apiextensions-apiserver", + Resources: []model.Resource{ + { + Kind: "ValidatingWebhookConfiguration", + }, + }, + RenderClients: true, + CustomTypesImportPath: "k8s.io/api/admissionregistration/v1", + ApiRoot: kubeGeneratedPackage, + }, + { + GroupVersion: schema.GroupVersion{ + Group: "rbac.authorization.k8s.io", + Version: "v1", + }, + Module: "k8s.io/apiextensions-apiserver", + Resources: []model.Resource{ + { + Kind: "Role", + }, + { + Kind: "RoleBinding", + }, + { + Kind: "ClusterRole", + ClusterScoped: true, + }, + { + Kind: "ClusterRoleBinding", + ClusterScoped: true, + }, + }, + RenderClients: true, + CustomTypesImportPath: "k8s.io/api/rbac/v1", + ApiRoot: kubeGeneratedPackage, + }, + { + GroupVersion: schema.GroupVersion{ + Group: "apiextensions.k8s.io", + Version: "v1beta1", + }, + Module: "k8s.io/apiextensions-apiserver", + Resources: []model.Resource{ + { + Kind: "CustomResourceDefinition", + ClusterScoped: true, + }, + }, + RenderClients: true, + CustomTypesImportPath: "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1", + ApiRoot: kubeGeneratedPackage, + }, + }, + } + if err := skv2Cmd.Execute(); err != nil { + log.Fatal(err) + } + log.Printf("Finished generating kube clients\n") +} diff --git a/pkg/generated/kubernetes/admissionregistration.k8s.io/v1/clients.go b/pkg/generated/kubernetes/admissionregistration.k8s.io/v1/clients.go new file mode 100644 index 000000000..e5fc98e21 --- /dev/null +++ b/pkg/generated/kubernetes/admissionregistration.k8s.io/v1/clients.go @@ -0,0 +1,144 @@ +package v1 + +import ( + "context" + + "k8s.io/client-go/kubernetes/scheme" + "k8s.io/client-go/rest" + "sigs.k8s.io/controller-runtime/pkg/client" + + . "k8s.io/api/admissionregistration/v1" +) + +// clienset for the admissionregistration.k8s.io/v1 APIs +type Clientset interface { + // clienset for the admissionregistration.k8s.io/v1/v1 APIs + ValidatingWebhookConfigurations() ValidatingWebhookConfigurationClient +} + +type clientSet struct { + client client.Client +} + +func NewClientsetFromConfig(cfg *rest.Config) (Clientset, error) { + scheme := scheme.Scheme + if err := AddToScheme(scheme); err != nil { + return nil, err + } + client, err := client.New(cfg, client.Options{ + Scheme: scheme, + }) + if err != nil { + return nil, err + } + return NewClientset(client), nil +} + +func NewClientset(client client.Client) Clientset { + return &clientSet{client: client} +} + +// clienset for the admissionregistration.k8s.io/v1/v1 APIs +func (c *clientSet) ValidatingWebhookConfigurations() ValidatingWebhookConfigurationClient { + return NewValidatingWebhookConfigurationClient(c.client) +} + +// Reader knows how to read and list ValidatingWebhookConfigurations. +type ValidatingWebhookConfigurationReader interface { + // Get retrieves a ValidatingWebhookConfiguration for the given object key + GetValidatingWebhookConfiguration(ctx context.Context, key client.ObjectKey) (*ValidatingWebhookConfiguration, error) + + // List retrieves list of ValidatingWebhookConfigurations for a given namespace and list options. + ListValidatingWebhookConfiguration(ctx context.Context, opts ...client.ListOption) (*ValidatingWebhookConfigurationList, error) +} + +// Writer knows how to create, delete, and update ValidatingWebhookConfigurations. +type ValidatingWebhookConfigurationWriter interface { + // Create saves the ValidatingWebhookConfiguration object. + CreateValidatingWebhookConfiguration(ctx context.Context, obj *ValidatingWebhookConfiguration, opts ...client.CreateOption) error + + // Delete deletes the ValidatingWebhookConfiguration object. + DeleteValidatingWebhookConfiguration(ctx context.Context, key client.ObjectKey, opts ...client.DeleteOption) error + + // Update updates the given ValidatingWebhookConfiguration object. + UpdateValidatingWebhookConfiguration(ctx context.Context, obj *ValidatingWebhookConfiguration, opts ...client.UpdateOption) error + + // Patch patches the given ValidatingWebhookConfiguration object. + PatchValidatingWebhookConfiguration(ctx context.Context, obj *ValidatingWebhookConfiguration, patch client.Patch, opts ...client.PatchOption) error + + // DeleteAllOf deletes all ValidatingWebhookConfiguration objects matching the given options. + DeleteAllOfValidatingWebhookConfiguration(ctx context.Context, opts ...client.DeleteAllOfOption) error +} + +// StatusWriter knows how to update status subresource of a ValidatingWebhookConfiguration object. +type ValidatingWebhookConfigurationStatusWriter interface { + // Update updates the fields corresponding to the status subresource for the + // given ValidatingWebhookConfiguration object. + UpdateValidatingWebhookConfigurationStatus(ctx context.Context, obj *ValidatingWebhookConfiguration, opts ...client.UpdateOption) error + + // Patch patches the given ValidatingWebhookConfiguration object's subresource. + PatchValidatingWebhookConfigurationStatus(ctx context.Context, obj *ValidatingWebhookConfiguration, patch client.Patch, opts ...client.PatchOption) error +} + +// Client knows how to perform CRUD operations on ValidatingWebhookConfigurations. +type ValidatingWebhookConfigurationClient interface { + ValidatingWebhookConfigurationReader + ValidatingWebhookConfigurationWriter + ValidatingWebhookConfigurationStatusWriter +} + +type validatingWebhookConfigurationClient struct { + client client.Client +} + +func NewValidatingWebhookConfigurationClient(client client.Client) *validatingWebhookConfigurationClient { + return &validatingWebhookConfigurationClient{client: client} +} + +func (c *validatingWebhookConfigurationClient) GetValidatingWebhookConfiguration(ctx context.Context, key client.ObjectKey) (*ValidatingWebhookConfiguration, error) { + obj := &ValidatingWebhookConfiguration{} + if err := c.client.Get(ctx, key, obj); err != nil { + return nil, err + } + return obj, nil +} + +func (c *validatingWebhookConfigurationClient) ListValidatingWebhookConfiguration(ctx context.Context, opts ...client.ListOption) (*ValidatingWebhookConfigurationList, error) { + list := &ValidatingWebhookConfigurationList{} + if err := c.client.List(ctx, list, opts...); err != nil { + return nil, err + } + return list, nil +} + +func (c *validatingWebhookConfigurationClient) CreateValidatingWebhookConfiguration(ctx context.Context, obj *ValidatingWebhookConfiguration, opts ...client.CreateOption) error { + return c.client.Create(ctx, obj, opts...) +} + +func (c *validatingWebhookConfigurationClient) DeleteValidatingWebhookConfiguration(ctx context.Context, key client.ObjectKey, opts ...client.DeleteOption) error { + obj := &ValidatingWebhookConfiguration{} + obj.SetName(key.Name) + obj.SetNamespace(key.Namespace) + return c.client.Delete(ctx, obj, opts...) +} + +func (c *validatingWebhookConfigurationClient) UpdateValidatingWebhookConfiguration(ctx context.Context, obj *ValidatingWebhookConfiguration, opts ...client.UpdateOption) error { + return c.client.Update(ctx, obj, opts...) +} + +func (c *validatingWebhookConfigurationClient) PatchValidatingWebhookConfiguration(ctx context.Context, obj *ValidatingWebhookConfiguration, patch client.Patch, opts ...client.PatchOption) error { + return c.client.Patch(ctx, obj, patch, opts...) +} + +func (c *validatingWebhookConfigurationClient) DeleteAllOfValidatingWebhookConfiguration(ctx context.Context, opts ...client.DeleteAllOfOption) error { + obj := &ValidatingWebhookConfiguration{} + return c.client.DeleteAllOf(ctx, obj, opts...) +} + +func (c *validatingWebhookConfigurationClient) UpdateValidatingWebhookConfigurationStatus(ctx context.Context, obj *ValidatingWebhookConfiguration, opts ...client.UpdateOption) error { + return c.client.Status().Update(ctx, obj, opts...) +} + +func (c *validatingWebhookConfigurationClient) PatchValidatingWebhookConfigurationStatus(ctx context.Context, obj *ValidatingWebhookConfiguration, patch client.Patch, opts ...client.PatchOption) error { + return c.client.Status().Patch(ctx, obj, patch, opts...) +} diff --git a/pkg/generated/kubernetes/apiextensions.k8s.io/v1beta1/clients.go b/pkg/generated/kubernetes/apiextensions.k8s.io/v1beta1/clients.go new file mode 100644 index 000000000..9ff956125 --- /dev/null +++ b/pkg/generated/kubernetes/apiextensions.k8s.io/v1beta1/clients.go @@ -0,0 +1,146 @@ +package v1beta1 + +import ( + "context" + + "k8s.io/client-go/kubernetes/scheme" + "k8s.io/client-go/rest" + "sigs.k8s.io/controller-runtime/pkg/client" + + . "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1" +) + +// clienset for the apiextensions.k8s.io/v1beta1 APIs +type Clientset interface { + // clienset for the apiextensions.k8s.io/v1beta1/v1beta1 APIs + CustomResourceDefinitions() CustomResourceDefinitionClient +} + +type clientSet struct { + client client.Client +} + +func NewClientsetFromConfig(cfg *rest.Config) (Clientset, error) { + scheme := scheme.Scheme + if err := AddToScheme(scheme); err != nil { + return nil, err + } + client, err := client.New(cfg, client.Options{ + Scheme: scheme, + }) + if err != nil { + return nil, err + } + return NewClientset(client), nil +} + +func NewClientset(client client.Client) Clientset { + return &clientSet{client: client} +} + +// clienset for the apiextensions.k8s.io/v1beta1/v1beta1 APIs +func (c *clientSet) CustomResourceDefinitions() CustomResourceDefinitionClient { + return NewCustomResourceDefinitionClient(c.client) +} + +// Reader knows how to read and list CustomResourceDefinitions. +type CustomResourceDefinitionReader interface { + // Get retrieves a CustomResourceDefinition for the given object key + GetCustomResourceDefinition(ctx context.Context, name string) (*CustomResourceDefinition, error) + + // List retrieves list of CustomResourceDefinitions for a given namespace and list options. + ListCustomResourceDefinition(ctx context.Context, opts ...client.ListOption) (*CustomResourceDefinitionList, error) +} + +// Writer knows how to create, delete, and update CustomResourceDefinitions. +type CustomResourceDefinitionWriter interface { + // Create saves the CustomResourceDefinition object. + CreateCustomResourceDefinition(ctx context.Context, obj *CustomResourceDefinition, opts ...client.CreateOption) error + + // Delete deletes the CustomResourceDefinition object. + DeleteCustomResourceDefinition(ctx context.Context, name string, opts ...client.DeleteOption) error + + // Update updates the given CustomResourceDefinition object. + UpdateCustomResourceDefinition(ctx context.Context, obj *CustomResourceDefinition, opts ...client.UpdateOption) error + + // Patch patches the given CustomResourceDefinition object. + PatchCustomResourceDefinition(ctx context.Context, obj *CustomResourceDefinition, patch client.Patch, opts ...client.PatchOption) error + + // DeleteAllOf deletes all CustomResourceDefinition objects matching the given options. + DeleteAllOfCustomResourceDefinition(ctx context.Context, opts ...client.DeleteAllOfOption) error +} + +// StatusWriter knows how to update status subresource of a CustomResourceDefinition object. +type CustomResourceDefinitionStatusWriter interface { + // Update updates the fields corresponding to the status subresource for the + // given CustomResourceDefinition object. + UpdateCustomResourceDefinitionStatus(ctx context.Context, obj *CustomResourceDefinition, opts ...client.UpdateOption) error + + // Patch patches the given CustomResourceDefinition object's subresource. + PatchCustomResourceDefinitionStatus(ctx context.Context, obj *CustomResourceDefinition, patch client.Patch, opts ...client.PatchOption) error +} + +// Client knows how to perform CRUD operations on CustomResourceDefinitions. +type CustomResourceDefinitionClient interface { + CustomResourceDefinitionReader + CustomResourceDefinitionWriter + CustomResourceDefinitionStatusWriter +} + +type customResourceDefinitionClient struct { + client client.Client +} + +func NewCustomResourceDefinitionClient(client client.Client) *customResourceDefinitionClient { + return &customResourceDefinitionClient{client: client} +} + +func (c *customResourceDefinitionClient) GetCustomResourceDefinition(ctx context.Context, name string) (*CustomResourceDefinition, error) { + obj := &CustomResourceDefinition{} + key := client.ObjectKey{ + Name: name, + } + if err := c.client.Get(ctx, key, obj); err != nil { + return nil, err + } + return obj, nil +} + +func (c *customResourceDefinitionClient) ListCustomResourceDefinition(ctx context.Context, opts ...client.ListOption) (*CustomResourceDefinitionList, error) { + list := &CustomResourceDefinitionList{} + if err := c.client.List(ctx, list, opts...); err != nil { + return nil, err + } + return list, nil +} + +func (c *customResourceDefinitionClient) CreateCustomResourceDefinition(ctx context.Context, obj *CustomResourceDefinition, opts ...client.CreateOption) error { + return c.client.Create(ctx, obj, opts...) +} + +func (c *customResourceDefinitionClient) DeleteCustomResourceDefinition(ctx context.Context, name string, opts ...client.DeleteOption) error { + obj := &CustomResourceDefinition{} + obj.SetName(name) + return c.client.Delete(ctx, obj, opts...) +} + +func (c *customResourceDefinitionClient) UpdateCustomResourceDefinition(ctx context.Context, obj *CustomResourceDefinition, opts ...client.UpdateOption) error { + return c.client.Update(ctx, obj, opts...) +} + +func (c *customResourceDefinitionClient) PatchCustomResourceDefinition(ctx context.Context, obj *CustomResourceDefinition, patch client.Patch, opts ...client.PatchOption) error { + return c.client.Patch(ctx, obj, patch, opts...) +} + +func (c *customResourceDefinitionClient) DeleteAllOfCustomResourceDefinition(ctx context.Context, opts ...client.DeleteAllOfOption) error { + obj := &CustomResourceDefinition{} + return c.client.DeleteAllOf(ctx, obj, opts...) +} + +func (c *customResourceDefinitionClient) UpdateCustomResourceDefinitionStatus(ctx context.Context, obj *CustomResourceDefinition, opts ...client.UpdateOption) error { + return c.client.Status().Update(ctx, obj, opts...) +} + +func (c *customResourceDefinitionClient) PatchCustomResourceDefinitionStatus(ctx context.Context, obj *CustomResourceDefinition, patch client.Patch, opts ...client.PatchOption) error { + return c.client.Status().Patch(ctx, obj, patch, opts...) +} diff --git a/pkg/generated/kubernetes/apps/v1/clients.go b/pkg/generated/kubernetes/apps/v1/clients.go new file mode 100644 index 000000000..ced1cc9a6 --- /dev/null +++ b/pkg/generated/kubernetes/apps/v1/clients.go @@ -0,0 +1,251 @@ +package v1 + +import ( + "context" + + "k8s.io/client-go/kubernetes/scheme" + "k8s.io/client-go/rest" + "sigs.k8s.io/controller-runtime/pkg/client" + + . "k8s.io/api/apps/v1" +) + +// clienset for the apps/v1 APIs +type Clientset interface { + // clienset for the apps/v1/v1 APIs + Deployments() DeploymentClient + // clienset for the apps/v1/v1 APIs + ReplicaSets() ReplicaSetClient +} + +type clientSet struct { + client client.Client +} + +func NewClientsetFromConfig(cfg *rest.Config) (Clientset, error) { + scheme := scheme.Scheme + if err := AddToScheme(scheme); err != nil { + return nil, err + } + client, err := client.New(cfg, client.Options{ + Scheme: scheme, + }) + if err != nil { + return nil, err + } + return NewClientset(client), nil +} + +func NewClientset(client client.Client) Clientset { + return &clientSet{client: client} +} + +// clienset for the apps/v1/v1 APIs +func (c *clientSet) Deployments() DeploymentClient { + return NewDeploymentClient(c.client) +} + +// clienset for the apps/v1/v1 APIs +func (c *clientSet) ReplicaSets() ReplicaSetClient { + return NewReplicaSetClient(c.client) +} + +// Reader knows how to read and list Deployments. +type DeploymentReader interface { + // Get retrieves a Deployment for the given object key + GetDeployment(ctx context.Context, key client.ObjectKey) (*Deployment, error) + + // List retrieves list of Deployments for a given namespace and list options. + ListDeployment(ctx context.Context, opts ...client.ListOption) (*DeploymentList, error) +} + +// Writer knows how to create, delete, and update Deployments. +type DeploymentWriter interface { + // Create saves the Deployment object. + CreateDeployment(ctx context.Context, obj *Deployment, opts ...client.CreateOption) error + + // Delete deletes the Deployment object. + DeleteDeployment(ctx context.Context, key client.ObjectKey, opts ...client.DeleteOption) error + + // Update updates the given Deployment object. + UpdateDeployment(ctx context.Context, obj *Deployment, opts ...client.UpdateOption) error + + // Patch patches the given Deployment object. + PatchDeployment(ctx context.Context, obj *Deployment, patch client.Patch, opts ...client.PatchOption) error + + // DeleteAllOf deletes all Deployment objects matching the given options. + DeleteAllOfDeployment(ctx context.Context, opts ...client.DeleteAllOfOption) error +} + +// StatusWriter knows how to update status subresource of a Deployment object. +type DeploymentStatusWriter interface { + // Update updates the fields corresponding to the status subresource for the + // given Deployment object. + UpdateDeploymentStatus(ctx context.Context, obj *Deployment, opts ...client.UpdateOption) error + + // Patch patches the given Deployment object's subresource. + PatchDeploymentStatus(ctx context.Context, obj *Deployment, patch client.Patch, opts ...client.PatchOption) error +} + +// Client knows how to perform CRUD operations on Deployments. +type DeploymentClient interface { + DeploymentReader + DeploymentWriter + DeploymentStatusWriter +} + +type deploymentClient struct { + client client.Client +} + +func NewDeploymentClient(client client.Client) *deploymentClient { + return &deploymentClient{client: client} +} + +func (c *deploymentClient) GetDeployment(ctx context.Context, key client.ObjectKey) (*Deployment, error) { + obj := &Deployment{} + if err := c.client.Get(ctx, key, obj); err != nil { + return nil, err + } + return obj, nil +} + +func (c *deploymentClient) ListDeployment(ctx context.Context, opts ...client.ListOption) (*DeploymentList, error) { + list := &DeploymentList{} + if err := c.client.List(ctx, list, opts...); err != nil { + return nil, err + } + return list, nil +} + +func (c *deploymentClient) CreateDeployment(ctx context.Context, obj *Deployment, opts ...client.CreateOption) error { + return c.client.Create(ctx, obj, opts...) +} + +func (c *deploymentClient) DeleteDeployment(ctx context.Context, key client.ObjectKey, opts ...client.DeleteOption) error { + obj := &Deployment{} + obj.SetName(key.Name) + obj.SetNamespace(key.Namespace) + return c.client.Delete(ctx, obj, opts...) +} + +func (c *deploymentClient) UpdateDeployment(ctx context.Context, obj *Deployment, opts ...client.UpdateOption) error { + return c.client.Update(ctx, obj, opts...) +} + +func (c *deploymentClient) PatchDeployment(ctx context.Context, obj *Deployment, patch client.Patch, opts ...client.PatchOption) error { + return c.client.Patch(ctx, obj, patch, opts...) +} + +func (c *deploymentClient) DeleteAllOfDeployment(ctx context.Context, opts ...client.DeleteAllOfOption) error { + obj := &Deployment{} + return c.client.DeleteAllOf(ctx, obj, opts...) +} + +func (c *deploymentClient) UpdateDeploymentStatus(ctx context.Context, obj *Deployment, opts ...client.UpdateOption) error { + return c.client.Status().Update(ctx, obj, opts...) +} + +func (c *deploymentClient) PatchDeploymentStatus(ctx context.Context, obj *Deployment, patch client.Patch, opts ...client.PatchOption) error { + return c.client.Status().Patch(ctx, obj, patch, opts...) +} + +// Reader knows how to read and list ReplicaSets. +type ReplicaSetReader interface { + // Get retrieves a ReplicaSet for the given object key + GetReplicaSet(ctx context.Context, key client.ObjectKey) (*ReplicaSet, error) + + // List retrieves list of ReplicaSets for a given namespace and list options. + ListReplicaSet(ctx context.Context, opts ...client.ListOption) (*ReplicaSetList, error) +} + +// Writer knows how to create, delete, and update ReplicaSets. +type ReplicaSetWriter interface { + // Create saves the ReplicaSet object. + CreateReplicaSet(ctx context.Context, obj *ReplicaSet, opts ...client.CreateOption) error + + // Delete deletes the ReplicaSet object. + DeleteReplicaSet(ctx context.Context, key client.ObjectKey, opts ...client.DeleteOption) error + + // Update updates the given ReplicaSet object. + UpdateReplicaSet(ctx context.Context, obj *ReplicaSet, opts ...client.UpdateOption) error + + // Patch patches the given ReplicaSet object. + PatchReplicaSet(ctx context.Context, obj *ReplicaSet, patch client.Patch, opts ...client.PatchOption) error + + // DeleteAllOf deletes all ReplicaSet objects matching the given options. + DeleteAllOfReplicaSet(ctx context.Context, opts ...client.DeleteAllOfOption) error +} + +// StatusWriter knows how to update status subresource of a ReplicaSet object. +type ReplicaSetStatusWriter interface { + // Update updates the fields corresponding to the status subresource for the + // given ReplicaSet object. + UpdateReplicaSetStatus(ctx context.Context, obj *ReplicaSet, opts ...client.UpdateOption) error + + // Patch patches the given ReplicaSet object's subresource. + PatchReplicaSetStatus(ctx context.Context, obj *ReplicaSet, patch client.Patch, opts ...client.PatchOption) error +} + +// Client knows how to perform CRUD operations on ReplicaSets. +type ReplicaSetClient interface { + ReplicaSetReader + ReplicaSetWriter + ReplicaSetStatusWriter +} + +type replicaSetClient struct { + client client.Client +} + +func NewReplicaSetClient(client client.Client) *replicaSetClient { + return &replicaSetClient{client: client} +} + +func (c *replicaSetClient) GetReplicaSet(ctx context.Context, key client.ObjectKey) (*ReplicaSet, error) { + obj := &ReplicaSet{} + if err := c.client.Get(ctx, key, obj); err != nil { + return nil, err + } + return obj, nil +} + +func (c *replicaSetClient) ListReplicaSet(ctx context.Context, opts ...client.ListOption) (*ReplicaSetList, error) { + list := &ReplicaSetList{} + if err := c.client.List(ctx, list, opts...); err != nil { + return nil, err + } + return list, nil +} + +func (c *replicaSetClient) CreateReplicaSet(ctx context.Context, obj *ReplicaSet, opts ...client.CreateOption) error { + return c.client.Create(ctx, obj, opts...) +} + +func (c *replicaSetClient) DeleteReplicaSet(ctx context.Context, key client.ObjectKey, opts ...client.DeleteOption) error { + obj := &ReplicaSet{} + obj.SetName(key.Name) + obj.SetNamespace(key.Namespace) + return c.client.Delete(ctx, obj, opts...) +} + +func (c *replicaSetClient) UpdateReplicaSet(ctx context.Context, obj *ReplicaSet, opts ...client.UpdateOption) error { + return c.client.Update(ctx, obj, opts...) +} + +func (c *replicaSetClient) PatchReplicaSet(ctx context.Context, obj *ReplicaSet, patch client.Patch, opts ...client.PatchOption) error { + return c.client.Patch(ctx, obj, patch, opts...) +} + +func (c *replicaSetClient) DeleteAllOfReplicaSet(ctx context.Context, opts ...client.DeleteAllOfOption) error { + obj := &ReplicaSet{} + return c.client.DeleteAllOf(ctx, obj, opts...) +} + +func (c *replicaSetClient) UpdateReplicaSetStatus(ctx context.Context, obj *ReplicaSet, opts ...client.UpdateOption) error { + return c.client.Status().Update(ctx, obj, opts...) +} + +func (c *replicaSetClient) PatchReplicaSetStatus(ctx context.Context, obj *ReplicaSet, patch client.Patch, opts ...client.PatchOption) error { + return c.client.Status().Patch(ctx, obj, patch, opts...) +} diff --git a/pkg/generated/kubernetes/apps/v1/controller/event_handlers.go b/pkg/generated/kubernetes/apps/v1/controller/event_handlers.go new file mode 100644 index 000000000..66f7883ef --- /dev/null +++ b/pkg/generated/kubernetes/apps/v1/controller/event_handlers.go @@ -0,0 +1,226 @@ +// Definitions for the Kubernetes Controllers +package controller + +import ( + "context" + + apps_v1 "k8s.io/api/apps/v1" + + "github.com/pkg/errors" + "github.com/solo-io/skv2/pkg/events" + "k8s.io/apimachinery/pkg/runtime" + "sigs.k8s.io/controller-runtime/pkg/manager" + "sigs.k8s.io/controller-runtime/pkg/predicate" +) + +// Handle events for the Deployment Resource +type DeploymentEventHandler interface { + CreateDeployment(obj *apps_v1.Deployment) error + UpdateDeployment(old, new *apps_v1.Deployment) error + DeleteDeployment(obj *apps_v1.Deployment) error + GenericDeployment(obj *apps_v1.Deployment) error +} + +type DeploymentEventHandlerFuncs struct { + OnCreate func(obj *apps_v1.Deployment) error + OnUpdate func(old, new *apps_v1.Deployment) error + OnDelete func(obj *apps_v1.Deployment) error + OnGeneric func(obj *apps_v1.Deployment) error +} + +func (f *DeploymentEventHandlerFuncs) CreateDeployment(obj *apps_v1.Deployment) error { + if f.OnCreate == nil { + return nil + } + return f.OnCreate(obj) +} + +func (f *DeploymentEventHandlerFuncs) DeleteDeployment(obj *apps_v1.Deployment) error { + if f.OnDelete == nil { + return nil + } + return f.OnDelete(obj) +} + +func (f *DeploymentEventHandlerFuncs) UpdateDeployment(objOld, objNew *apps_v1.Deployment) error { + if f.OnUpdate == nil { + return nil + } + return f.OnUpdate(objOld, objNew) +} + +func (f *DeploymentEventHandlerFuncs) GenericDeployment(obj *apps_v1.Deployment) error { + if f.OnGeneric == nil { + return nil + } + return f.OnGeneric(obj) +} + +type DeploymentEventWatcher interface { + AddEventHandler(ctx context.Context, h DeploymentEventHandler, predicates ...predicate.Predicate) error +} + +type deploymentEventWatcher struct { + watcher events.EventWatcher +} + +func NewDeploymentEventWatcher(name string, mgr manager.Manager) DeploymentEventWatcher { + return &deploymentEventWatcher{ + watcher: events.NewWatcher(name, mgr, &apps_v1.Deployment{}), + } +} + +func (c *deploymentEventWatcher) AddEventHandler(ctx context.Context, h DeploymentEventHandler, predicates ...predicate.Predicate) error { + handler := genericDeploymentHandler{handler: h} + if err := c.watcher.Watch(ctx, handler, predicates...); err != nil { + return err + } + return nil +} + +// genericDeploymentHandler implements a generic events.EventHandler +type genericDeploymentHandler struct { + handler DeploymentEventHandler +} + +func (h genericDeploymentHandler) Create(object runtime.Object) error { + obj, ok := object.(*apps_v1.Deployment) + if !ok { + return errors.Errorf("internal error: Deployment handler received event for %T", object) + } + return h.handler.CreateDeployment(obj) +} + +func (h genericDeploymentHandler) Delete(object runtime.Object) error { + obj, ok := object.(*apps_v1.Deployment) + if !ok { + return errors.Errorf("internal error: Deployment handler received event for %T", object) + } + return h.handler.DeleteDeployment(obj) +} + +func (h genericDeploymentHandler) Update(old, new runtime.Object) error { + objOld, ok := old.(*apps_v1.Deployment) + if !ok { + return errors.Errorf("internal error: Deployment handler received event for %T", old) + } + objNew, ok := new.(*apps_v1.Deployment) + if !ok { + return errors.Errorf("internal error: Deployment handler received event for %T", new) + } + return h.handler.UpdateDeployment(objOld, objNew) +} + +func (h genericDeploymentHandler) Generic(object runtime.Object) error { + obj, ok := object.(*apps_v1.Deployment) + if !ok { + return errors.Errorf("internal error: Deployment handler received event for %T", object) + } + return h.handler.GenericDeployment(obj) +} + +// Handle events for the ReplicaSet Resource +type ReplicaSetEventHandler interface { + CreateReplicaSet(obj *apps_v1.ReplicaSet) error + UpdateReplicaSet(old, new *apps_v1.ReplicaSet) error + DeleteReplicaSet(obj *apps_v1.ReplicaSet) error + GenericReplicaSet(obj *apps_v1.ReplicaSet) error +} + +type ReplicaSetEventHandlerFuncs struct { + OnCreate func(obj *apps_v1.ReplicaSet) error + OnUpdate func(old, new *apps_v1.ReplicaSet) error + OnDelete func(obj *apps_v1.ReplicaSet) error + OnGeneric func(obj *apps_v1.ReplicaSet) error +} + +func (f *ReplicaSetEventHandlerFuncs) CreateReplicaSet(obj *apps_v1.ReplicaSet) error { + if f.OnCreate == nil { + return nil + } + return f.OnCreate(obj) +} + +func (f *ReplicaSetEventHandlerFuncs) DeleteReplicaSet(obj *apps_v1.ReplicaSet) error { + if f.OnDelete == nil { + return nil + } + return f.OnDelete(obj) +} + +func (f *ReplicaSetEventHandlerFuncs) UpdateReplicaSet(objOld, objNew *apps_v1.ReplicaSet) error { + if f.OnUpdate == nil { + return nil + } + return f.OnUpdate(objOld, objNew) +} + +func (f *ReplicaSetEventHandlerFuncs) GenericReplicaSet(obj *apps_v1.ReplicaSet) error { + if f.OnGeneric == nil { + return nil + } + return f.OnGeneric(obj) +} + +type ReplicaSetEventWatcher interface { + AddEventHandler(ctx context.Context, h ReplicaSetEventHandler, predicates ...predicate.Predicate) error +} + +type replicaSetEventWatcher struct { + watcher events.EventWatcher +} + +func NewReplicaSetEventWatcher(name string, mgr manager.Manager) ReplicaSetEventWatcher { + return &replicaSetEventWatcher{ + watcher: events.NewWatcher(name, mgr, &apps_v1.ReplicaSet{}), + } +} + +func (c *replicaSetEventWatcher) AddEventHandler(ctx context.Context, h ReplicaSetEventHandler, predicates ...predicate.Predicate) error { + handler := genericReplicaSetHandler{handler: h} + if err := c.watcher.Watch(ctx, handler, predicates...); err != nil { + return err + } + return nil +} + +// genericReplicaSetHandler implements a generic events.EventHandler +type genericReplicaSetHandler struct { + handler ReplicaSetEventHandler +} + +func (h genericReplicaSetHandler) Create(object runtime.Object) error { + obj, ok := object.(*apps_v1.ReplicaSet) + if !ok { + return errors.Errorf("internal error: ReplicaSet handler received event for %T", object) + } + return h.handler.CreateReplicaSet(obj) +} + +func (h genericReplicaSetHandler) Delete(object runtime.Object) error { + obj, ok := object.(*apps_v1.ReplicaSet) + if !ok { + return errors.Errorf("internal error: ReplicaSet handler received event for %T", object) + } + return h.handler.DeleteReplicaSet(obj) +} + +func (h genericReplicaSetHandler) Update(old, new runtime.Object) error { + objOld, ok := old.(*apps_v1.ReplicaSet) + if !ok { + return errors.Errorf("internal error: ReplicaSet handler received event for %T", old) + } + objNew, ok := new.(*apps_v1.ReplicaSet) + if !ok { + return errors.Errorf("internal error: ReplicaSet handler received event for %T", new) + } + return h.handler.UpdateReplicaSet(objOld, objNew) +} + +func (h genericReplicaSetHandler) Generic(object runtime.Object) error { + obj, ok := object.(*apps_v1.ReplicaSet) + if !ok { + return errors.Errorf("internal error: ReplicaSet handler received event for %T", object) + } + return h.handler.GenericReplicaSet(obj) +} diff --git a/pkg/generated/kubernetes/apps/v1/controller/reconcilers.go b/pkg/generated/kubernetes/apps/v1/controller/reconcilers.go new file mode 100644 index 000000000..35b617577 --- /dev/null +++ b/pkg/generated/kubernetes/apps/v1/controller/reconcilers.go @@ -0,0 +1,244 @@ +// Definitions for the Kubernetes Controllers +package controller + +import ( + "context" + + apps_v1 "k8s.io/api/apps/v1" + + "github.com/pkg/errors" + "github.com/solo-io/skv2/pkg/ezkube" + "github.com/solo-io/skv2/pkg/reconcile" + "sigs.k8s.io/controller-runtime/pkg/manager" + "sigs.k8s.io/controller-runtime/pkg/predicate" +) + +// Reconcile Upsert events for the Deployment Resource. +// implemented by the user +type DeploymentReconciler interface { + ReconcileDeployment(obj *apps_v1.Deployment) (reconcile.Result, error) +} + +// Reconcile deletion events for the Deployment Resource. +// Deletion receives a reconcile.Request as we cannot guarantee the last state of the object +// before being deleted. +// implemented by the user +type DeploymentDeletionReconciler interface { + ReconcileDeploymentDeletion(req reconcile.Request) +} + +type DeploymentReconcilerFuncs struct { + OnReconcileDeployment func(obj *apps_v1.Deployment) (reconcile.Result, error) + OnReconcileDeploymentDeletion func(req reconcile.Request) +} + +func (f *DeploymentReconcilerFuncs) ReconcileDeployment(obj *apps_v1.Deployment) (reconcile.Result, error) { + if f.OnReconcileDeployment == nil { + return reconcile.Result{}, nil + } + return f.OnReconcileDeployment(obj) +} + +func (f *DeploymentReconcilerFuncs) ReconcileDeploymentDeletion(req reconcile.Request) { + if f.OnReconcileDeploymentDeletion == nil { + return + } + f.OnReconcileDeploymentDeletion(req) +} + +// Reconcile and finalize the Deployment Resource +// implemented by the user +type DeploymentFinalizer interface { + DeploymentReconciler + + // name of the finalizer used by this handler. + // finalizer names should be unique for a single task + DeploymentFinalizerName() string + + // finalize the object before it is deleted. + // Watchers created with a finalizing handler will a + FinalizeDeployment(obj *apps_v1.Deployment) error +} + +type DeploymentReconcileLoop interface { + RunDeploymentReconciler(ctx context.Context, rec DeploymentReconciler, predicates ...predicate.Predicate) error +} + +type deploymentReconcileLoop struct { + loop reconcile.Loop +} + +func NewDeploymentReconcileLoop(name string, mgr manager.Manager) DeploymentReconcileLoop { + return &deploymentReconcileLoop{ + loop: reconcile.NewLoop(name, mgr, &apps_v1.Deployment{}), + } +} + +func (c *deploymentReconcileLoop) RunDeploymentReconciler(ctx context.Context, reconciler DeploymentReconciler, predicates ...predicate.Predicate) error { + genericReconciler := genericDeploymentReconciler{ + reconciler: reconciler, + } + + var reconcilerWrapper reconcile.Reconciler + if finalizingReconciler, ok := reconciler.(DeploymentFinalizer); ok { + reconcilerWrapper = genericDeploymentFinalizer{ + genericDeploymentReconciler: genericReconciler, + finalizingReconciler: finalizingReconciler, + } + } else { + reconcilerWrapper = genericReconciler + } + return c.loop.RunReconciler(ctx, reconcilerWrapper, predicates...) +} + +// genericDeploymentHandler implements a generic reconcile.Reconciler +type genericDeploymentReconciler struct { + reconciler DeploymentReconciler +} + +func (r genericDeploymentReconciler) Reconcile(object ezkube.Object) (reconcile.Result, error) { + obj, ok := object.(*apps_v1.Deployment) + if !ok { + return reconcile.Result{}, errors.Errorf("internal error: Deployment handler received event for %T", object) + } + return r.reconciler.ReconcileDeployment(obj) +} + +func (r genericDeploymentReconciler) ReconcileDeletion(request reconcile.Request) { + if deletionReconciler, ok := r.reconciler.(DeploymentDeletionReconciler); ok { + deletionReconciler.ReconcileDeploymentDeletion(request) + } +} + +// genericDeploymentFinalizer implements a generic reconcile.FinalizingReconciler +type genericDeploymentFinalizer struct { + genericDeploymentReconciler + finalizingReconciler DeploymentFinalizer +} + +func (r genericDeploymentFinalizer) FinalizerName() string { + return r.finalizingReconciler.DeploymentFinalizerName() +} + +func (r genericDeploymentFinalizer) Finalize(object ezkube.Object) error { + obj, ok := object.(*apps_v1.Deployment) + if !ok { + return errors.Errorf("internal error: Deployment handler received event for %T", object) + } + return r.finalizingReconciler.FinalizeDeployment(obj) +} + +// Reconcile Upsert events for the ReplicaSet Resource. +// implemented by the user +type ReplicaSetReconciler interface { + ReconcileReplicaSet(obj *apps_v1.ReplicaSet) (reconcile.Result, error) +} + +// Reconcile deletion events for the ReplicaSet Resource. +// Deletion receives a reconcile.Request as we cannot guarantee the last state of the object +// before being deleted. +// implemented by the user +type ReplicaSetDeletionReconciler interface { + ReconcileReplicaSetDeletion(req reconcile.Request) +} + +type ReplicaSetReconcilerFuncs struct { + OnReconcileReplicaSet func(obj *apps_v1.ReplicaSet) (reconcile.Result, error) + OnReconcileReplicaSetDeletion func(req reconcile.Request) +} + +func (f *ReplicaSetReconcilerFuncs) ReconcileReplicaSet(obj *apps_v1.ReplicaSet) (reconcile.Result, error) { + if f.OnReconcileReplicaSet == nil { + return reconcile.Result{}, nil + } + return f.OnReconcileReplicaSet(obj) +} + +func (f *ReplicaSetReconcilerFuncs) ReconcileReplicaSetDeletion(req reconcile.Request) { + if f.OnReconcileReplicaSetDeletion == nil { + return + } + f.OnReconcileReplicaSetDeletion(req) +} + +// Reconcile and finalize the ReplicaSet Resource +// implemented by the user +type ReplicaSetFinalizer interface { + ReplicaSetReconciler + + // name of the finalizer used by this handler. + // finalizer names should be unique for a single task + ReplicaSetFinalizerName() string + + // finalize the object before it is deleted. + // Watchers created with a finalizing handler will a + FinalizeReplicaSet(obj *apps_v1.ReplicaSet) error +} + +type ReplicaSetReconcileLoop interface { + RunReplicaSetReconciler(ctx context.Context, rec ReplicaSetReconciler, predicates ...predicate.Predicate) error +} + +type replicaSetReconcileLoop struct { + loop reconcile.Loop +} + +func NewReplicaSetReconcileLoop(name string, mgr manager.Manager) ReplicaSetReconcileLoop { + return &replicaSetReconcileLoop{ + loop: reconcile.NewLoop(name, mgr, &apps_v1.ReplicaSet{}), + } +} + +func (c *replicaSetReconcileLoop) RunReplicaSetReconciler(ctx context.Context, reconciler ReplicaSetReconciler, predicates ...predicate.Predicate) error { + genericReconciler := genericReplicaSetReconciler{ + reconciler: reconciler, + } + + var reconcilerWrapper reconcile.Reconciler + if finalizingReconciler, ok := reconciler.(ReplicaSetFinalizer); ok { + reconcilerWrapper = genericReplicaSetFinalizer{ + genericReplicaSetReconciler: genericReconciler, + finalizingReconciler: finalizingReconciler, + } + } else { + reconcilerWrapper = genericReconciler + } + return c.loop.RunReconciler(ctx, reconcilerWrapper, predicates...) +} + +// genericReplicaSetHandler implements a generic reconcile.Reconciler +type genericReplicaSetReconciler struct { + reconciler ReplicaSetReconciler +} + +func (r genericReplicaSetReconciler) Reconcile(object ezkube.Object) (reconcile.Result, error) { + obj, ok := object.(*apps_v1.ReplicaSet) + if !ok { + return reconcile.Result{}, errors.Errorf("internal error: ReplicaSet handler received event for %T", object) + } + return r.reconciler.ReconcileReplicaSet(obj) +} + +func (r genericReplicaSetReconciler) ReconcileDeletion(request reconcile.Request) { + if deletionReconciler, ok := r.reconciler.(ReplicaSetDeletionReconciler); ok { + deletionReconciler.ReconcileReplicaSetDeletion(request) + } +} + +// genericReplicaSetFinalizer implements a generic reconcile.FinalizingReconciler +type genericReplicaSetFinalizer struct { + genericReplicaSetReconciler + finalizingReconciler ReplicaSetFinalizer +} + +func (r genericReplicaSetFinalizer) FinalizerName() string { + return r.finalizingReconciler.ReplicaSetFinalizerName() +} + +func (r genericReplicaSetFinalizer) Finalize(object ezkube.Object) error { + obj, ok := object.(*apps_v1.ReplicaSet) + if !ok { + return errors.Errorf("internal error: ReplicaSet handler received event for %T", object) + } + return r.finalizingReconciler.FinalizeReplicaSet(obj) +} diff --git a/pkg/generated/kubernetes/core/v1/clients.go b/pkg/generated/kubernetes/core/v1/clients.go new file mode 100644 index 000000000..6e377e209 --- /dev/null +++ b/pkg/generated/kubernetes/core/v1/clients.go @@ -0,0 +1,790 @@ +package v1 + +import ( + "context" + + "k8s.io/client-go/kubernetes/scheme" + "k8s.io/client-go/rest" + "sigs.k8s.io/controller-runtime/pkg/client" + + . "k8s.io/api/core/v1" +) + +// clienset for the core/v1 APIs +type Clientset interface { + // clienset for the core/v1/v1 APIs + Secrets() SecretClient + // clienset for the core/v1/v1 APIs + ServiceAccounts() ServiceAccountClient + // clienset for the core/v1/v1 APIs + ConfigMaps() ConfigMapClient + // clienset for the core/v1/v1 APIs + Services() ServiceClient + // clienset for the core/v1/v1 APIs + Pods() PodClient + // clienset for the core/v1/v1 APIs + Namespaces() NamespaceClient + // clienset for the core/v1/v1 APIs + Nodes() NodeClient +} + +type clientSet struct { + client client.Client +} + +func NewClientsetFromConfig(cfg *rest.Config) (Clientset, error) { + scheme := scheme.Scheme + if err := AddToScheme(scheme); err != nil { + return nil, err + } + client, err := client.New(cfg, client.Options{ + Scheme: scheme, + }) + if err != nil { + return nil, err + } + return NewClientset(client), nil +} + +func NewClientset(client client.Client) Clientset { + return &clientSet{client: client} +} + +// clienset for the core/v1/v1 APIs +func (c *clientSet) Secrets() SecretClient { + return NewSecretClient(c.client) +} + +// clienset for the core/v1/v1 APIs +func (c *clientSet) ServiceAccounts() ServiceAccountClient { + return NewServiceAccountClient(c.client) +} + +// clienset for the core/v1/v1 APIs +func (c *clientSet) ConfigMaps() ConfigMapClient { + return NewConfigMapClient(c.client) +} + +// clienset for the core/v1/v1 APIs +func (c *clientSet) Services() ServiceClient { + return NewServiceClient(c.client) +} + +// clienset for the core/v1/v1 APIs +func (c *clientSet) Pods() PodClient { + return NewPodClient(c.client) +} + +// clienset for the core/v1/v1 APIs +func (c *clientSet) Namespaces() NamespaceClient { + return NewNamespaceClient(c.client) +} + +// clienset for the core/v1/v1 APIs +func (c *clientSet) Nodes() NodeClient { + return NewNodeClient(c.client) +} + +// Reader knows how to read and list Secrets. +type SecretReader interface { + // Get retrieves a Secret for the given object key + GetSecret(ctx context.Context, key client.ObjectKey) (*Secret, error) + + // List retrieves list of Secrets for a given namespace and list options. + ListSecret(ctx context.Context, opts ...client.ListOption) (*SecretList, error) +} + +// Writer knows how to create, delete, and update Secrets. +type SecretWriter interface { + // Create saves the Secret object. + CreateSecret(ctx context.Context, obj *Secret, opts ...client.CreateOption) error + + // Delete deletes the Secret object. + DeleteSecret(ctx context.Context, key client.ObjectKey, opts ...client.DeleteOption) error + + // Update updates the given Secret object. + UpdateSecret(ctx context.Context, obj *Secret, opts ...client.UpdateOption) error + + // Patch patches the given Secret object. + PatchSecret(ctx context.Context, obj *Secret, patch client.Patch, opts ...client.PatchOption) error + + // DeleteAllOf deletes all Secret objects matching the given options. + DeleteAllOfSecret(ctx context.Context, opts ...client.DeleteAllOfOption) error +} + +// StatusWriter knows how to update status subresource of a Secret object. +type SecretStatusWriter interface { + // Update updates the fields corresponding to the status subresource for the + // given Secret object. + UpdateSecretStatus(ctx context.Context, obj *Secret, opts ...client.UpdateOption) error + + // Patch patches the given Secret object's subresource. + PatchSecretStatus(ctx context.Context, obj *Secret, patch client.Patch, opts ...client.PatchOption) error +} + +// Client knows how to perform CRUD operations on Secrets. +type SecretClient interface { + SecretReader + SecretWriter + SecretStatusWriter +} + +type secretClient struct { + client client.Client +} + +func NewSecretClient(client client.Client) *secretClient { + return &secretClient{client: client} +} + +func (c *secretClient) GetSecret(ctx context.Context, key client.ObjectKey) (*Secret, error) { + obj := &Secret{} + if err := c.client.Get(ctx, key, obj); err != nil { + return nil, err + } + return obj, nil +} + +func (c *secretClient) ListSecret(ctx context.Context, opts ...client.ListOption) (*SecretList, error) { + list := &SecretList{} + if err := c.client.List(ctx, list, opts...); err != nil { + return nil, err + } + return list, nil +} + +func (c *secretClient) CreateSecret(ctx context.Context, obj *Secret, opts ...client.CreateOption) error { + return c.client.Create(ctx, obj, opts...) +} + +func (c *secretClient) DeleteSecret(ctx context.Context, key client.ObjectKey, opts ...client.DeleteOption) error { + obj := &Secret{} + obj.SetName(key.Name) + obj.SetNamespace(key.Namespace) + return c.client.Delete(ctx, obj, opts...) +} + +func (c *secretClient) UpdateSecret(ctx context.Context, obj *Secret, opts ...client.UpdateOption) error { + return c.client.Update(ctx, obj, opts...) +} + +func (c *secretClient) PatchSecret(ctx context.Context, obj *Secret, patch client.Patch, opts ...client.PatchOption) error { + return c.client.Patch(ctx, obj, patch, opts...) +} + +func (c *secretClient) DeleteAllOfSecret(ctx context.Context, opts ...client.DeleteAllOfOption) error { + obj := &Secret{} + return c.client.DeleteAllOf(ctx, obj, opts...) +} + +func (c *secretClient) UpdateSecretStatus(ctx context.Context, obj *Secret, opts ...client.UpdateOption) error { + return c.client.Status().Update(ctx, obj, opts...) +} + +func (c *secretClient) PatchSecretStatus(ctx context.Context, obj *Secret, patch client.Patch, opts ...client.PatchOption) error { + return c.client.Status().Patch(ctx, obj, patch, opts...) +} + +// Reader knows how to read and list ServiceAccounts. +type ServiceAccountReader interface { + // Get retrieves a ServiceAccount for the given object key + GetServiceAccount(ctx context.Context, key client.ObjectKey) (*ServiceAccount, error) + + // List retrieves list of ServiceAccounts for a given namespace and list options. + ListServiceAccount(ctx context.Context, opts ...client.ListOption) (*ServiceAccountList, error) +} + +// Writer knows how to create, delete, and update ServiceAccounts. +type ServiceAccountWriter interface { + // Create saves the ServiceAccount object. + CreateServiceAccount(ctx context.Context, obj *ServiceAccount, opts ...client.CreateOption) error + + // Delete deletes the ServiceAccount object. + DeleteServiceAccount(ctx context.Context, key client.ObjectKey, opts ...client.DeleteOption) error + + // Update updates the given ServiceAccount object. + UpdateServiceAccount(ctx context.Context, obj *ServiceAccount, opts ...client.UpdateOption) error + + // Patch patches the given ServiceAccount object. + PatchServiceAccount(ctx context.Context, obj *ServiceAccount, patch client.Patch, opts ...client.PatchOption) error + + // DeleteAllOf deletes all ServiceAccount objects matching the given options. + DeleteAllOfServiceAccount(ctx context.Context, opts ...client.DeleteAllOfOption) error +} + +// StatusWriter knows how to update status subresource of a ServiceAccount object. +type ServiceAccountStatusWriter interface { + // Update updates the fields corresponding to the status subresource for the + // given ServiceAccount object. + UpdateServiceAccountStatus(ctx context.Context, obj *ServiceAccount, opts ...client.UpdateOption) error + + // Patch patches the given ServiceAccount object's subresource. + PatchServiceAccountStatus(ctx context.Context, obj *ServiceAccount, patch client.Patch, opts ...client.PatchOption) error +} + +// Client knows how to perform CRUD operations on ServiceAccounts. +type ServiceAccountClient interface { + ServiceAccountReader + ServiceAccountWriter + ServiceAccountStatusWriter +} + +type serviceAccountClient struct { + client client.Client +} + +func NewServiceAccountClient(client client.Client) *serviceAccountClient { + return &serviceAccountClient{client: client} +} + +func (c *serviceAccountClient) GetServiceAccount(ctx context.Context, key client.ObjectKey) (*ServiceAccount, error) { + obj := &ServiceAccount{} + if err := c.client.Get(ctx, key, obj); err != nil { + return nil, err + } + return obj, nil +} + +func (c *serviceAccountClient) ListServiceAccount(ctx context.Context, opts ...client.ListOption) (*ServiceAccountList, error) { + list := &ServiceAccountList{} + if err := c.client.List(ctx, list, opts...); err != nil { + return nil, err + } + return list, nil +} + +func (c *serviceAccountClient) CreateServiceAccount(ctx context.Context, obj *ServiceAccount, opts ...client.CreateOption) error { + return c.client.Create(ctx, obj, opts...) +} + +func (c *serviceAccountClient) DeleteServiceAccount(ctx context.Context, key client.ObjectKey, opts ...client.DeleteOption) error { + obj := &ServiceAccount{} + obj.SetName(key.Name) + obj.SetNamespace(key.Namespace) + return c.client.Delete(ctx, obj, opts...) +} + +func (c *serviceAccountClient) UpdateServiceAccount(ctx context.Context, obj *ServiceAccount, opts ...client.UpdateOption) error { + return c.client.Update(ctx, obj, opts...) +} + +func (c *serviceAccountClient) PatchServiceAccount(ctx context.Context, obj *ServiceAccount, patch client.Patch, opts ...client.PatchOption) error { + return c.client.Patch(ctx, obj, patch, opts...) +} + +func (c *serviceAccountClient) DeleteAllOfServiceAccount(ctx context.Context, opts ...client.DeleteAllOfOption) error { + obj := &ServiceAccount{} + return c.client.DeleteAllOf(ctx, obj, opts...) +} + +func (c *serviceAccountClient) UpdateServiceAccountStatus(ctx context.Context, obj *ServiceAccount, opts ...client.UpdateOption) error { + return c.client.Status().Update(ctx, obj, opts...) +} + +func (c *serviceAccountClient) PatchServiceAccountStatus(ctx context.Context, obj *ServiceAccount, patch client.Patch, opts ...client.PatchOption) error { + return c.client.Status().Patch(ctx, obj, patch, opts...) +} + +// Reader knows how to read and list ConfigMaps. +type ConfigMapReader interface { + // Get retrieves a ConfigMap for the given object key + GetConfigMap(ctx context.Context, key client.ObjectKey) (*ConfigMap, error) + + // List retrieves list of ConfigMaps for a given namespace and list options. + ListConfigMap(ctx context.Context, opts ...client.ListOption) (*ConfigMapList, error) +} + +// Writer knows how to create, delete, and update ConfigMaps. +type ConfigMapWriter interface { + // Create saves the ConfigMap object. + CreateConfigMap(ctx context.Context, obj *ConfigMap, opts ...client.CreateOption) error + + // Delete deletes the ConfigMap object. + DeleteConfigMap(ctx context.Context, key client.ObjectKey, opts ...client.DeleteOption) error + + // Update updates the given ConfigMap object. + UpdateConfigMap(ctx context.Context, obj *ConfigMap, opts ...client.UpdateOption) error + + // Patch patches the given ConfigMap object. + PatchConfigMap(ctx context.Context, obj *ConfigMap, patch client.Patch, opts ...client.PatchOption) error + + // DeleteAllOf deletes all ConfigMap objects matching the given options. + DeleteAllOfConfigMap(ctx context.Context, opts ...client.DeleteAllOfOption) error +} + +// StatusWriter knows how to update status subresource of a ConfigMap object. +type ConfigMapStatusWriter interface { + // Update updates the fields corresponding to the status subresource for the + // given ConfigMap object. + UpdateConfigMapStatus(ctx context.Context, obj *ConfigMap, opts ...client.UpdateOption) error + + // Patch patches the given ConfigMap object's subresource. + PatchConfigMapStatus(ctx context.Context, obj *ConfigMap, patch client.Patch, opts ...client.PatchOption) error +} + +// Client knows how to perform CRUD operations on ConfigMaps. +type ConfigMapClient interface { + ConfigMapReader + ConfigMapWriter + ConfigMapStatusWriter +} + +type configMapClient struct { + client client.Client +} + +func NewConfigMapClient(client client.Client) *configMapClient { + return &configMapClient{client: client} +} + +func (c *configMapClient) GetConfigMap(ctx context.Context, key client.ObjectKey) (*ConfigMap, error) { + obj := &ConfigMap{} + if err := c.client.Get(ctx, key, obj); err != nil { + return nil, err + } + return obj, nil +} + +func (c *configMapClient) ListConfigMap(ctx context.Context, opts ...client.ListOption) (*ConfigMapList, error) { + list := &ConfigMapList{} + if err := c.client.List(ctx, list, opts...); err != nil { + return nil, err + } + return list, nil +} + +func (c *configMapClient) CreateConfigMap(ctx context.Context, obj *ConfigMap, opts ...client.CreateOption) error { + return c.client.Create(ctx, obj, opts...) +} + +func (c *configMapClient) DeleteConfigMap(ctx context.Context, key client.ObjectKey, opts ...client.DeleteOption) error { + obj := &ConfigMap{} + obj.SetName(key.Name) + obj.SetNamespace(key.Namespace) + return c.client.Delete(ctx, obj, opts...) +} + +func (c *configMapClient) UpdateConfigMap(ctx context.Context, obj *ConfigMap, opts ...client.UpdateOption) error { + return c.client.Update(ctx, obj, opts...) +} + +func (c *configMapClient) PatchConfigMap(ctx context.Context, obj *ConfigMap, patch client.Patch, opts ...client.PatchOption) error { + return c.client.Patch(ctx, obj, patch, opts...) +} + +func (c *configMapClient) DeleteAllOfConfigMap(ctx context.Context, opts ...client.DeleteAllOfOption) error { + obj := &ConfigMap{} + return c.client.DeleteAllOf(ctx, obj, opts...) +} + +func (c *configMapClient) UpdateConfigMapStatus(ctx context.Context, obj *ConfigMap, opts ...client.UpdateOption) error { + return c.client.Status().Update(ctx, obj, opts...) +} + +func (c *configMapClient) PatchConfigMapStatus(ctx context.Context, obj *ConfigMap, patch client.Patch, opts ...client.PatchOption) error { + return c.client.Status().Patch(ctx, obj, patch, opts...) +} + +// Reader knows how to read and list Services. +type ServiceReader interface { + // Get retrieves a Service for the given object key + GetService(ctx context.Context, key client.ObjectKey) (*Service, error) + + // List retrieves list of Services for a given namespace and list options. + ListService(ctx context.Context, opts ...client.ListOption) (*ServiceList, error) +} + +// Writer knows how to create, delete, and update Services. +type ServiceWriter interface { + // Create saves the Service object. + CreateService(ctx context.Context, obj *Service, opts ...client.CreateOption) error + + // Delete deletes the Service object. + DeleteService(ctx context.Context, key client.ObjectKey, opts ...client.DeleteOption) error + + // Update updates the given Service object. + UpdateService(ctx context.Context, obj *Service, opts ...client.UpdateOption) error + + // Patch patches the given Service object. + PatchService(ctx context.Context, obj *Service, patch client.Patch, opts ...client.PatchOption) error + + // DeleteAllOf deletes all Service objects matching the given options. + DeleteAllOfService(ctx context.Context, opts ...client.DeleteAllOfOption) error +} + +// StatusWriter knows how to update status subresource of a Service object. +type ServiceStatusWriter interface { + // Update updates the fields corresponding to the status subresource for the + // given Service object. + UpdateServiceStatus(ctx context.Context, obj *Service, opts ...client.UpdateOption) error + + // Patch patches the given Service object's subresource. + PatchServiceStatus(ctx context.Context, obj *Service, patch client.Patch, opts ...client.PatchOption) error +} + +// Client knows how to perform CRUD operations on Services. +type ServiceClient interface { + ServiceReader + ServiceWriter + ServiceStatusWriter +} + +type serviceClient struct { + client client.Client +} + +func NewServiceClient(client client.Client) *serviceClient { + return &serviceClient{client: client} +} + +func (c *serviceClient) GetService(ctx context.Context, key client.ObjectKey) (*Service, error) { + obj := &Service{} + if err := c.client.Get(ctx, key, obj); err != nil { + return nil, err + } + return obj, nil +} + +func (c *serviceClient) ListService(ctx context.Context, opts ...client.ListOption) (*ServiceList, error) { + list := &ServiceList{} + if err := c.client.List(ctx, list, opts...); err != nil { + return nil, err + } + return list, nil +} + +func (c *serviceClient) CreateService(ctx context.Context, obj *Service, opts ...client.CreateOption) error { + return c.client.Create(ctx, obj, opts...) +} + +func (c *serviceClient) DeleteService(ctx context.Context, key client.ObjectKey, opts ...client.DeleteOption) error { + obj := &Service{} + obj.SetName(key.Name) + obj.SetNamespace(key.Namespace) + return c.client.Delete(ctx, obj, opts...) +} + +func (c *serviceClient) UpdateService(ctx context.Context, obj *Service, opts ...client.UpdateOption) error { + return c.client.Update(ctx, obj, opts...) +} + +func (c *serviceClient) PatchService(ctx context.Context, obj *Service, patch client.Patch, opts ...client.PatchOption) error { + return c.client.Patch(ctx, obj, patch, opts...) +} + +func (c *serviceClient) DeleteAllOfService(ctx context.Context, opts ...client.DeleteAllOfOption) error { + obj := &Service{} + return c.client.DeleteAllOf(ctx, obj, opts...) +} + +func (c *serviceClient) UpdateServiceStatus(ctx context.Context, obj *Service, opts ...client.UpdateOption) error { + return c.client.Status().Update(ctx, obj, opts...) +} + +func (c *serviceClient) PatchServiceStatus(ctx context.Context, obj *Service, patch client.Patch, opts ...client.PatchOption) error { + return c.client.Status().Patch(ctx, obj, patch, opts...) +} + +// Reader knows how to read and list Pods. +type PodReader interface { + // Get retrieves a Pod for the given object key + GetPod(ctx context.Context, key client.ObjectKey) (*Pod, error) + + // List retrieves list of Pods for a given namespace and list options. + ListPod(ctx context.Context, opts ...client.ListOption) (*PodList, error) +} + +// Writer knows how to create, delete, and update Pods. +type PodWriter interface { + // Create saves the Pod object. + CreatePod(ctx context.Context, obj *Pod, opts ...client.CreateOption) error + + // Delete deletes the Pod object. + DeletePod(ctx context.Context, key client.ObjectKey, opts ...client.DeleteOption) error + + // Update updates the given Pod object. + UpdatePod(ctx context.Context, obj *Pod, opts ...client.UpdateOption) error + + // Patch patches the given Pod object. + PatchPod(ctx context.Context, obj *Pod, patch client.Patch, opts ...client.PatchOption) error + + // DeleteAllOf deletes all Pod objects matching the given options. + DeleteAllOfPod(ctx context.Context, opts ...client.DeleteAllOfOption) error +} + +// StatusWriter knows how to update status subresource of a Pod object. +type PodStatusWriter interface { + // Update updates the fields corresponding to the status subresource for the + // given Pod object. + UpdatePodStatus(ctx context.Context, obj *Pod, opts ...client.UpdateOption) error + + // Patch patches the given Pod object's subresource. + PatchPodStatus(ctx context.Context, obj *Pod, patch client.Patch, opts ...client.PatchOption) error +} + +// Client knows how to perform CRUD operations on Pods. +type PodClient interface { + PodReader + PodWriter + PodStatusWriter +} + +type podClient struct { + client client.Client +} + +func NewPodClient(client client.Client) *podClient { + return &podClient{client: client} +} + +func (c *podClient) GetPod(ctx context.Context, key client.ObjectKey) (*Pod, error) { + obj := &Pod{} + if err := c.client.Get(ctx, key, obj); err != nil { + return nil, err + } + return obj, nil +} + +func (c *podClient) ListPod(ctx context.Context, opts ...client.ListOption) (*PodList, error) { + list := &PodList{} + if err := c.client.List(ctx, list, opts...); err != nil { + return nil, err + } + return list, nil +} + +func (c *podClient) CreatePod(ctx context.Context, obj *Pod, opts ...client.CreateOption) error { + return c.client.Create(ctx, obj, opts...) +} + +func (c *podClient) DeletePod(ctx context.Context, key client.ObjectKey, opts ...client.DeleteOption) error { + obj := &Pod{} + obj.SetName(key.Name) + obj.SetNamespace(key.Namespace) + return c.client.Delete(ctx, obj, opts...) +} + +func (c *podClient) UpdatePod(ctx context.Context, obj *Pod, opts ...client.UpdateOption) error { + return c.client.Update(ctx, obj, opts...) +} + +func (c *podClient) PatchPod(ctx context.Context, obj *Pod, patch client.Patch, opts ...client.PatchOption) error { + return c.client.Patch(ctx, obj, patch, opts...) +} + +func (c *podClient) DeleteAllOfPod(ctx context.Context, opts ...client.DeleteAllOfOption) error { + obj := &Pod{} + return c.client.DeleteAllOf(ctx, obj, opts...) +} + +func (c *podClient) UpdatePodStatus(ctx context.Context, obj *Pod, opts ...client.UpdateOption) error { + return c.client.Status().Update(ctx, obj, opts...) +} + +func (c *podClient) PatchPodStatus(ctx context.Context, obj *Pod, patch client.Patch, opts ...client.PatchOption) error { + return c.client.Status().Patch(ctx, obj, patch, opts...) +} + +// Reader knows how to read and list Namespaces. +type NamespaceReader interface { + // Get retrieves a Namespace for the given object key + GetNamespace(ctx context.Context, name string) (*Namespace, error) + + // List retrieves list of Namespaces for a given namespace and list options. + ListNamespace(ctx context.Context, opts ...client.ListOption) (*NamespaceList, error) +} + +// Writer knows how to create, delete, and update Namespaces. +type NamespaceWriter interface { + // Create saves the Namespace object. + CreateNamespace(ctx context.Context, obj *Namespace, opts ...client.CreateOption) error + + // Delete deletes the Namespace object. + DeleteNamespace(ctx context.Context, name string, opts ...client.DeleteOption) error + + // Update updates the given Namespace object. + UpdateNamespace(ctx context.Context, obj *Namespace, opts ...client.UpdateOption) error + + // Patch patches the given Namespace object. + PatchNamespace(ctx context.Context, obj *Namespace, patch client.Patch, opts ...client.PatchOption) error + + // DeleteAllOf deletes all Namespace objects matching the given options. + DeleteAllOfNamespace(ctx context.Context, opts ...client.DeleteAllOfOption) error +} + +// StatusWriter knows how to update status subresource of a Namespace object. +type NamespaceStatusWriter interface { + // Update updates the fields corresponding to the status subresource for the + // given Namespace object. + UpdateNamespaceStatus(ctx context.Context, obj *Namespace, opts ...client.UpdateOption) error + + // Patch patches the given Namespace object's subresource. + PatchNamespaceStatus(ctx context.Context, obj *Namespace, patch client.Patch, opts ...client.PatchOption) error +} + +// Client knows how to perform CRUD operations on Namespaces. +type NamespaceClient interface { + NamespaceReader + NamespaceWriter + NamespaceStatusWriter +} + +type namespaceClient struct { + client client.Client +} + +func NewNamespaceClient(client client.Client) *namespaceClient { + return &namespaceClient{client: client} +} + +func (c *namespaceClient) GetNamespace(ctx context.Context, name string) (*Namespace, error) { + obj := &Namespace{} + key := client.ObjectKey{ + Name: name, + } + if err := c.client.Get(ctx, key, obj); err != nil { + return nil, err + } + return obj, nil +} + +func (c *namespaceClient) ListNamespace(ctx context.Context, opts ...client.ListOption) (*NamespaceList, error) { + list := &NamespaceList{} + if err := c.client.List(ctx, list, opts...); err != nil { + return nil, err + } + return list, nil +} + +func (c *namespaceClient) CreateNamespace(ctx context.Context, obj *Namespace, opts ...client.CreateOption) error { + return c.client.Create(ctx, obj, opts...) +} + +func (c *namespaceClient) DeleteNamespace(ctx context.Context, name string, opts ...client.DeleteOption) error { + obj := &Namespace{} + obj.SetName(name) + return c.client.Delete(ctx, obj, opts...) +} + +func (c *namespaceClient) UpdateNamespace(ctx context.Context, obj *Namespace, opts ...client.UpdateOption) error { + return c.client.Update(ctx, obj, opts...) +} + +func (c *namespaceClient) PatchNamespace(ctx context.Context, obj *Namespace, patch client.Patch, opts ...client.PatchOption) error { + return c.client.Patch(ctx, obj, patch, opts...) +} + +func (c *namespaceClient) DeleteAllOfNamespace(ctx context.Context, opts ...client.DeleteAllOfOption) error { + obj := &Namespace{} + return c.client.DeleteAllOf(ctx, obj, opts...) +} + +func (c *namespaceClient) UpdateNamespaceStatus(ctx context.Context, obj *Namespace, opts ...client.UpdateOption) error { + return c.client.Status().Update(ctx, obj, opts...) +} + +func (c *namespaceClient) PatchNamespaceStatus(ctx context.Context, obj *Namespace, patch client.Patch, opts ...client.PatchOption) error { + return c.client.Status().Patch(ctx, obj, patch, opts...) +} + +// Reader knows how to read and list Nodes. +type NodeReader interface { + // Get retrieves a Node for the given object key + GetNode(ctx context.Context, name string) (*Node, error) + + // List retrieves list of Nodes for a given namespace and list options. + ListNode(ctx context.Context, opts ...client.ListOption) (*NodeList, error) +} + +// Writer knows how to create, delete, and update Nodes. +type NodeWriter interface { + // Create saves the Node object. + CreateNode(ctx context.Context, obj *Node, opts ...client.CreateOption) error + + // Delete deletes the Node object. + DeleteNode(ctx context.Context, name string, opts ...client.DeleteOption) error + + // Update updates the given Node object. + UpdateNode(ctx context.Context, obj *Node, opts ...client.UpdateOption) error + + // Patch patches the given Node object. + PatchNode(ctx context.Context, obj *Node, patch client.Patch, opts ...client.PatchOption) error + + // DeleteAllOf deletes all Node objects matching the given options. + DeleteAllOfNode(ctx context.Context, opts ...client.DeleteAllOfOption) error +} + +// StatusWriter knows how to update status subresource of a Node object. +type NodeStatusWriter interface { + // Update updates the fields corresponding to the status subresource for the + // given Node object. + UpdateNodeStatus(ctx context.Context, obj *Node, opts ...client.UpdateOption) error + + // Patch patches the given Node object's subresource. + PatchNodeStatus(ctx context.Context, obj *Node, patch client.Patch, opts ...client.PatchOption) error +} + +// Client knows how to perform CRUD operations on Nodes. +type NodeClient interface { + NodeReader + NodeWriter + NodeStatusWriter +} + +type nodeClient struct { + client client.Client +} + +func NewNodeClient(client client.Client) *nodeClient { + return &nodeClient{client: client} +} + +func (c *nodeClient) GetNode(ctx context.Context, name string) (*Node, error) { + obj := &Node{} + key := client.ObjectKey{ + Name: name, + } + if err := c.client.Get(ctx, key, obj); err != nil { + return nil, err + } + return obj, nil +} + +func (c *nodeClient) ListNode(ctx context.Context, opts ...client.ListOption) (*NodeList, error) { + list := &NodeList{} + if err := c.client.List(ctx, list, opts...); err != nil { + return nil, err + } + return list, nil +} + +func (c *nodeClient) CreateNode(ctx context.Context, obj *Node, opts ...client.CreateOption) error { + return c.client.Create(ctx, obj, opts...) +} + +func (c *nodeClient) DeleteNode(ctx context.Context, name string, opts ...client.DeleteOption) error { + obj := &Node{} + obj.SetName(name) + return c.client.Delete(ctx, obj, opts...) +} + +func (c *nodeClient) UpdateNode(ctx context.Context, obj *Node, opts ...client.UpdateOption) error { + return c.client.Update(ctx, obj, opts...) +} + +func (c *nodeClient) PatchNode(ctx context.Context, obj *Node, patch client.Patch, opts ...client.PatchOption) error { + return c.client.Patch(ctx, obj, patch, opts...) +} + +func (c *nodeClient) DeleteAllOfNode(ctx context.Context, opts ...client.DeleteAllOfOption) error { + obj := &Node{} + return c.client.DeleteAllOf(ctx, obj, opts...) +} + +func (c *nodeClient) UpdateNodeStatus(ctx context.Context, obj *Node, opts ...client.UpdateOption) error { + return c.client.Status().Update(ctx, obj, opts...) +} + +func (c *nodeClient) PatchNodeStatus(ctx context.Context, obj *Node, patch client.Patch, opts ...client.PatchOption) error { + return c.client.Status().Patch(ctx, obj, patch, opts...) +} diff --git a/pkg/generated/kubernetes/core/v1/controller/event_handlers.go b/pkg/generated/kubernetes/core/v1/controller/event_handlers.go new file mode 100644 index 000000000..7256fb71b --- /dev/null +++ b/pkg/generated/kubernetes/core/v1/controller/event_handlers.go @@ -0,0 +1,756 @@ +// Definitions for the Kubernetes Controllers +package controller + +import ( + "context" + + core_v1 "k8s.io/api/core/v1" + + "github.com/pkg/errors" + "github.com/solo-io/skv2/pkg/events" + "k8s.io/apimachinery/pkg/runtime" + "sigs.k8s.io/controller-runtime/pkg/manager" + "sigs.k8s.io/controller-runtime/pkg/predicate" +) + +// Handle events for the Secret Resource +type SecretEventHandler interface { + CreateSecret(obj *core_v1.Secret) error + UpdateSecret(old, new *core_v1.Secret) error + DeleteSecret(obj *core_v1.Secret) error + GenericSecret(obj *core_v1.Secret) error +} + +type SecretEventHandlerFuncs struct { + OnCreate func(obj *core_v1.Secret) error + OnUpdate func(old, new *core_v1.Secret) error + OnDelete func(obj *core_v1.Secret) error + OnGeneric func(obj *core_v1.Secret) error +} + +func (f *SecretEventHandlerFuncs) CreateSecret(obj *core_v1.Secret) error { + if f.OnCreate == nil { + return nil + } + return f.OnCreate(obj) +} + +func (f *SecretEventHandlerFuncs) DeleteSecret(obj *core_v1.Secret) error { + if f.OnDelete == nil { + return nil + } + return f.OnDelete(obj) +} + +func (f *SecretEventHandlerFuncs) UpdateSecret(objOld, objNew *core_v1.Secret) error { + if f.OnUpdate == nil { + return nil + } + return f.OnUpdate(objOld, objNew) +} + +func (f *SecretEventHandlerFuncs) GenericSecret(obj *core_v1.Secret) error { + if f.OnGeneric == nil { + return nil + } + return f.OnGeneric(obj) +} + +type SecretEventWatcher interface { + AddEventHandler(ctx context.Context, h SecretEventHandler, predicates ...predicate.Predicate) error +} + +type secretEventWatcher struct { + watcher events.EventWatcher +} + +func NewSecretEventWatcher(name string, mgr manager.Manager) SecretEventWatcher { + return &secretEventWatcher{ + watcher: events.NewWatcher(name, mgr, &core_v1.Secret{}), + } +} + +func (c *secretEventWatcher) AddEventHandler(ctx context.Context, h SecretEventHandler, predicates ...predicate.Predicate) error { + handler := genericSecretHandler{handler: h} + if err := c.watcher.Watch(ctx, handler, predicates...); err != nil { + return err + } + return nil +} + +// genericSecretHandler implements a generic events.EventHandler +type genericSecretHandler struct { + handler SecretEventHandler +} + +func (h genericSecretHandler) Create(object runtime.Object) error { + obj, ok := object.(*core_v1.Secret) + if !ok { + return errors.Errorf("internal error: Secret handler received event for %T", object) + } + return h.handler.CreateSecret(obj) +} + +func (h genericSecretHandler) Delete(object runtime.Object) error { + obj, ok := object.(*core_v1.Secret) + if !ok { + return errors.Errorf("internal error: Secret handler received event for %T", object) + } + return h.handler.DeleteSecret(obj) +} + +func (h genericSecretHandler) Update(old, new runtime.Object) error { + objOld, ok := old.(*core_v1.Secret) + if !ok { + return errors.Errorf("internal error: Secret handler received event for %T", old) + } + objNew, ok := new.(*core_v1.Secret) + if !ok { + return errors.Errorf("internal error: Secret handler received event for %T", new) + } + return h.handler.UpdateSecret(objOld, objNew) +} + +func (h genericSecretHandler) Generic(object runtime.Object) error { + obj, ok := object.(*core_v1.Secret) + if !ok { + return errors.Errorf("internal error: Secret handler received event for %T", object) + } + return h.handler.GenericSecret(obj) +} + +// Handle events for the ServiceAccount Resource +type ServiceAccountEventHandler interface { + CreateServiceAccount(obj *core_v1.ServiceAccount) error + UpdateServiceAccount(old, new *core_v1.ServiceAccount) error + DeleteServiceAccount(obj *core_v1.ServiceAccount) error + GenericServiceAccount(obj *core_v1.ServiceAccount) error +} + +type ServiceAccountEventHandlerFuncs struct { + OnCreate func(obj *core_v1.ServiceAccount) error + OnUpdate func(old, new *core_v1.ServiceAccount) error + OnDelete func(obj *core_v1.ServiceAccount) error + OnGeneric func(obj *core_v1.ServiceAccount) error +} + +func (f *ServiceAccountEventHandlerFuncs) CreateServiceAccount(obj *core_v1.ServiceAccount) error { + if f.OnCreate == nil { + return nil + } + return f.OnCreate(obj) +} + +func (f *ServiceAccountEventHandlerFuncs) DeleteServiceAccount(obj *core_v1.ServiceAccount) error { + if f.OnDelete == nil { + return nil + } + return f.OnDelete(obj) +} + +func (f *ServiceAccountEventHandlerFuncs) UpdateServiceAccount(objOld, objNew *core_v1.ServiceAccount) error { + if f.OnUpdate == nil { + return nil + } + return f.OnUpdate(objOld, objNew) +} + +func (f *ServiceAccountEventHandlerFuncs) GenericServiceAccount(obj *core_v1.ServiceAccount) error { + if f.OnGeneric == nil { + return nil + } + return f.OnGeneric(obj) +} + +type ServiceAccountEventWatcher interface { + AddEventHandler(ctx context.Context, h ServiceAccountEventHandler, predicates ...predicate.Predicate) error +} + +type serviceAccountEventWatcher struct { + watcher events.EventWatcher +} + +func NewServiceAccountEventWatcher(name string, mgr manager.Manager) ServiceAccountEventWatcher { + return &serviceAccountEventWatcher{ + watcher: events.NewWatcher(name, mgr, &core_v1.ServiceAccount{}), + } +} + +func (c *serviceAccountEventWatcher) AddEventHandler(ctx context.Context, h ServiceAccountEventHandler, predicates ...predicate.Predicate) error { + handler := genericServiceAccountHandler{handler: h} + if err := c.watcher.Watch(ctx, handler, predicates...); err != nil { + return err + } + return nil +} + +// genericServiceAccountHandler implements a generic events.EventHandler +type genericServiceAccountHandler struct { + handler ServiceAccountEventHandler +} + +func (h genericServiceAccountHandler) Create(object runtime.Object) error { + obj, ok := object.(*core_v1.ServiceAccount) + if !ok { + return errors.Errorf("internal error: ServiceAccount handler received event for %T", object) + } + return h.handler.CreateServiceAccount(obj) +} + +func (h genericServiceAccountHandler) Delete(object runtime.Object) error { + obj, ok := object.(*core_v1.ServiceAccount) + if !ok { + return errors.Errorf("internal error: ServiceAccount handler received event for %T", object) + } + return h.handler.DeleteServiceAccount(obj) +} + +func (h genericServiceAccountHandler) Update(old, new runtime.Object) error { + objOld, ok := old.(*core_v1.ServiceAccount) + if !ok { + return errors.Errorf("internal error: ServiceAccount handler received event for %T", old) + } + objNew, ok := new.(*core_v1.ServiceAccount) + if !ok { + return errors.Errorf("internal error: ServiceAccount handler received event for %T", new) + } + return h.handler.UpdateServiceAccount(objOld, objNew) +} + +func (h genericServiceAccountHandler) Generic(object runtime.Object) error { + obj, ok := object.(*core_v1.ServiceAccount) + if !ok { + return errors.Errorf("internal error: ServiceAccount handler received event for %T", object) + } + return h.handler.GenericServiceAccount(obj) +} + +// Handle events for the ConfigMap Resource +type ConfigMapEventHandler interface { + CreateConfigMap(obj *core_v1.ConfigMap) error + UpdateConfigMap(old, new *core_v1.ConfigMap) error + DeleteConfigMap(obj *core_v1.ConfigMap) error + GenericConfigMap(obj *core_v1.ConfigMap) error +} + +type ConfigMapEventHandlerFuncs struct { + OnCreate func(obj *core_v1.ConfigMap) error + OnUpdate func(old, new *core_v1.ConfigMap) error + OnDelete func(obj *core_v1.ConfigMap) error + OnGeneric func(obj *core_v1.ConfigMap) error +} + +func (f *ConfigMapEventHandlerFuncs) CreateConfigMap(obj *core_v1.ConfigMap) error { + if f.OnCreate == nil { + return nil + } + return f.OnCreate(obj) +} + +func (f *ConfigMapEventHandlerFuncs) DeleteConfigMap(obj *core_v1.ConfigMap) error { + if f.OnDelete == nil { + return nil + } + return f.OnDelete(obj) +} + +func (f *ConfigMapEventHandlerFuncs) UpdateConfigMap(objOld, objNew *core_v1.ConfigMap) error { + if f.OnUpdate == nil { + return nil + } + return f.OnUpdate(objOld, objNew) +} + +func (f *ConfigMapEventHandlerFuncs) GenericConfigMap(obj *core_v1.ConfigMap) error { + if f.OnGeneric == nil { + return nil + } + return f.OnGeneric(obj) +} + +type ConfigMapEventWatcher interface { + AddEventHandler(ctx context.Context, h ConfigMapEventHandler, predicates ...predicate.Predicate) error +} + +type configMapEventWatcher struct { + watcher events.EventWatcher +} + +func NewConfigMapEventWatcher(name string, mgr manager.Manager) ConfigMapEventWatcher { + return &configMapEventWatcher{ + watcher: events.NewWatcher(name, mgr, &core_v1.ConfigMap{}), + } +} + +func (c *configMapEventWatcher) AddEventHandler(ctx context.Context, h ConfigMapEventHandler, predicates ...predicate.Predicate) error { + handler := genericConfigMapHandler{handler: h} + if err := c.watcher.Watch(ctx, handler, predicates...); err != nil { + return err + } + return nil +} + +// genericConfigMapHandler implements a generic events.EventHandler +type genericConfigMapHandler struct { + handler ConfigMapEventHandler +} + +func (h genericConfigMapHandler) Create(object runtime.Object) error { + obj, ok := object.(*core_v1.ConfigMap) + if !ok { + return errors.Errorf("internal error: ConfigMap handler received event for %T", object) + } + return h.handler.CreateConfigMap(obj) +} + +func (h genericConfigMapHandler) Delete(object runtime.Object) error { + obj, ok := object.(*core_v1.ConfigMap) + if !ok { + return errors.Errorf("internal error: ConfigMap handler received event for %T", object) + } + return h.handler.DeleteConfigMap(obj) +} + +func (h genericConfigMapHandler) Update(old, new runtime.Object) error { + objOld, ok := old.(*core_v1.ConfigMap) + if !ok { + return errors.Errorf("internal error: ConfigMap handler received event for %T", old) + } + objNew, ok := new.(*core_v1.ConfigMap) + if !ok { + return errors.Errorf("internal error: ConfigMap handler received event for %T", new) + } + return h.handler.UpdateConfigMap(objOld, objNew) +} + +func (h genericConfigMapHandler) Generic(object runtime.Object) error { + obj, ok := object.(*core_v1.ConfigMap) + if !ok { + return errors.Errorf("internal error: ConfigMap handler received event for %T", object) + } + return h.handler.GenericConfigMap(obj) +} + +// Handle events for the Service Resource +type ServiceEventHandler interface { + CreateService(obj *core_v1.Service) error + UpdateService(old, new *core_v1.Service) error + DeleteService(obj *core_v1.Service) error + GenericService(obj *core_v1.Service) error +} + +type ServiceEventHandlerFuncs struct { + OnCreate func(obj *core_v1.Service) error + OnUpdate func(old, new *core_v1.Service) error + OnDelete func(obj *core_v1.Service) error + OnGeneric func(obj *core_v1.Service) error +} + +func (f *ServiceEventHandlerFuncs) CreateService(obj *core_v1.Service) error { + if f.OnCreate == nil { + return nil + } + return f.OnCreate(obj) +} + +func (f *ServiceEventHandlerFuncs) DeleteService(obj *core_v1.Service) error { + if f.OnDelete == nil { + return nil + } + return f.OnDelete(obj) +} + +func (f *ServiceEventHandlerFuncs) UpdateService(objOld, objNew *core_v1.Service) error { + if f.OnUpdate == nil { + return nil + } + return f.OnUpdate(objOld, objNew) +} + +func (f *ServiceEventHandlerFuncs) GenericService(obj *core_v1.Service) error { + if f.OnGeneric == nil { + return nil + } + return f.OnGeneric(obj) +} + +type ServiceEventWatcher interface { + AddEventHandler(ctx context.Context, h ServiceEventHandler, predicates ...predicate.Predicate) error +} + +type serviceEventWatcher struct { + watcher events.EventWatcher +} + +func NewServiceEventWatcher(name string, mgr manager.Manager) ServiceEventWatcher { + return &serviceEventWatcher{ + watcher: events.NewWatcher(name, mgr, &core_v1.Service{}), + } +} + +func (c *serviceEventWatcher) AddEventHandler(ctx context.Context, h ServiceEventHandler, predicates ...predicate.Predicate) error { + handler := genericServiceHandler{handler: h} + if err := c.watcher.Watch(ctx, handler, predicates...); err != nil { + return err + } + return nil +} + +// genericServiceHandler implements a generic events.EventHandler +type genericServiceHandler struct { + handler ServiceEventHandler +} + +func (h genericServiceHandler) Create(object runtime.Object) error { + obj, ok := object.(*core_v1.Service) + if !ok { + return errors.Errorf("internal error: Service handler received event for %T", object) + } + return h.handler.CreateService(obj) +} + +func (h genericServiceHandler) Delete(object runtime.Object) error { + obj, ok := object.(*core_v1.Service) + if !ok { + return errors.Errorf("internal error: Service handler received event for %T", object) + } + return h.handler.DeleteService(obj) +} + +func (h genericServiceHandler) Update(old, new runtime.Object) error { + objOld, ok := old.(*core_v1.Service) + if !ok { + return errors.Errorf("internal error: Service handler received event for %T", old) + } + objNew, ok := new.(*core_v1.Service) + if !ok { + return errors.Errorf("internal error: Service handler received event for %T", new) + } + return h.handler.UpdateService(objOld, objNew) +} + +func (h genericServiceHandler) Generic(object runtime.Object) error { + obj, ok := object.(*core_v1.Service) + if !ok { + return errors.Errorf("internal error: Service handler received event for %T", object) + } + return h.handler.GenericService(obj) +} + +// Handle events for the Pod Resource +type PodEventHandler interface { + CreatePod(obj *core_v1.Pod) error + UpdatePod(old, new *core_v1.Pod) error + DeletePod(obj *core_v1.Pod) error + GenericPod(obj *core_v1.Pod) error +} + +type PodEventHandlerFuncs struct { + OnCreate func(obj *core_v1.Pod) error + OnUpdate func(old, new *core_v1.Pod) error + OnDelete func(obj *core_v1.Pod) error + OnGeneric func(obj *core_v1.Pod) error +} + +func (f *PodEventHandlerFuncs) CreatePod(obj *core_v1.Pod) error { + if f.OnCreate == nil { + return nil + } + return f.OnCreate(obj) +} + +func (f *PodEventHandlerFuncs) DeletePod(obj *core_v1.Pod) error { + if f.OnDelete == nil { + return nil + } + return f.OnDelete(obj) +} + +func (f *PodEventHandlerFuncs) UpdatePod(objOld, objNew *core_v1.Pod) error { + if f.OnUpdate == nil { + return nil + } + return f.OnUpdate(objOld, objNew) +} + +func (f *PodEventHandlerFuncs) GenericPod(obj *core_v1.Pod) error { + if f.OnGeneric == nil { + return nil + } + return f.OnGeneric(obj) +} + +type PodEventWatcher interface { + AddEventHandler(ctx context.Context, h PodEventHandler, predicates ...predicate.Predicate) error +} + +type podEventWatcher struct { + watcher events.EventWatcher +} + +func NewPodEventWatcher(name string, mgr manager.Manager) PodEventWatcher { + return &podEventWatcher{ + watcher: events.NewWatcher(name, mgr, &core_v1.Pod{}), + } +} + +func (c *podEventWatcher) AddEventHandler(ctx context.Context, h PodEventHandler, predicates ...predicate.Predicate) error { + handler := genericPodHandler{handler: h} + if err := c.watcher.Watch(ctx, handler, predicates...); err != nil { + return err + } + return nil +} + +// genericPodHandler implements a generic events.EventHandler +type genericPodHandler struct { + handler PodEventHandler +} + +func (h genericPodHandler) Create(object runtime.Object) error { + obj, ok := object.(*core_v1.Pod) + if !ok { + return errors.Errorf("internal error: Pod handler received event for %T", object) + } + return h.handler.CreatePod(obj) +} + +func (h genericPodHandler) Delete(object runtime.Object) error { + obj, ok := object.(*core_v1.Pod) + if !ok { + return errors.Errorf("internal error: Pod handler received event for %T", object) + } + return h.handler.DeletePod(obj) +} + +func (h genericPodHandler) Update(old, new runtime.Object) error { + objOld, ok := old.(*core_v1.Pod) + if !ok { + return errors.Errorf("internal error: Pod handler received event for %T", old) + } + objNew, ok := new.(*core_v1.Pod) + if !ok { + return errors.Errorf("internal error: Pod handler received event for %T", new) + } + return h.handler.UpdatePod(objOld, objNew) +} + +func (h genericPodHandler) Generic(object runtime.Object) error { + obj, ok := object.(*core_v1.Pod) + if !ok { + return errors.Errorf("internal error: Pod handler received event for %T", object) + } + return h.handler.GenericPod(obj) +} + +// Handle events for the Namespace Resource +type NamespaceEventHandler interface { + CreateNamespace(obj *core_v1.Namespace) error + UpdateNamespace(old, new *core_v1.Namespace) error + DeleteNamespace(obj *core_v1.Namespace) error + GenericNamespace(obj *core_v1.Namespace) error +} + +type NamespaceEventHandlerFuncs struct { + OnCreate func(obj *core_v1.Namespace) error + OnUpdate func(old, new *core_v1.Namespace) error + OnDelete func(obj *core_v1.Namespace) error + OnGeneric func(obj *core_v1.Namespace) error +} + +func (f *NamespaceEventHandlerFuncs) CreateNamespace(obj *core_v1.Namespace) error { + if f.OnCreate == nil { + return nil + } + return f.OnCreate(obj) +} + +func (f *NamespaceEventHandlerFuncs) DeleteNamespace(obj *core_v1.Namespace) error { + if f.OnDelete == nil { + return nil + } + return f.OnDelete(obj) +} + +func (f *NamespaceEventHandlerFuncs) UpdateNamespace(objOld, objNew *core_v1.Namespace) error { + if f.OnUpdate == nil { + return nil + } + return f.OnUpdate(objOld, objNew) +} + +func (f *NamespaceEventHandlerFuncs) GenericNamespace(obj *core_v1.Namespace) error { + if f.OnGeneric == nil { + return nil + } + return f.OnGeneric(obj) +} + +type NamespaceEventWatcher interface { + AddEventHandler(ctx context.Context, h NamespaceEventHandler, predicates ...predicate.Predicate) error +} + +type namespaceEventWatcher struct { + watcher events.EventWatcher +} + +func NewNamespaceEventWatcher(name string, mgr manager.Manager) NamespaceEventWatcher { + return &namespaceEventWatcher{ + watcher: events.NewWatcher(name, mgr, &core_v1.Namespace{}), + } +} + +func (c *namespaceEventWatcher) AddEventHandler(ctx context.Context, h NamespaceEventHandler, predicates ...predicate.Predicate) error { + handler := genericNamespaceHandler{handler: h} + if err := c.watcher.Watch(ctx, handler, predicates...); err != nil { + return err + } + return nil +} + +// genericNamespaceHandler implements a generic events.EventHandler +type genericNamespaceHandler struct { + handler NamespaceEventHandler +} + +func (h genericNamespaceHandler) Create(object runtime.Object) error { + obj, ok := object.(*core_v1.Namespace) + if !ok { + return errors.Errorf("internal error: Namespace handler received event for %T", object) + } + return h.handler.CreateNamespace(obj) +} + +func (h genericNamespaceHandler) Delete(object runtime.Object) error { + obj, ok := object.(*core_v1.Namespace) + if !ok { + return errors.Errorf("internal error: Namespace handler received event for %T", object) + } + return h.handler.DeleteNamespace(obj) +} + +func (h genericNamespaceHandler) Update(old, new runtime.Object) error { + objOld, ok := old.(*core_v1.Namespace) + if !ok { + return errors.Errorf("internal error: Namespace handler received event for %T", old) + } + objNew, ok := new.(*core_v1.Namespace) + if !ok { + return errors.Errorf("internal error: Namespace handler received event for %T", new) + } + return h.handler.UpdateNamespace(objOld, objNew) +} + +func (h genericNamespaceHandler) Generic(object runtime.Object) error { + obj, ok := object.(*core_v1.Namespace) + if !ok { + return errors.Errorf("internal error: Namespace handler received event for %T", object) + } + return h.handler.GenericNamespace(obj) +} + +// Handle events for the Node Resource +type NodeEventHandler interface { + CreateNode(obj *core_v1.Node) error + UpdateNode(old, new *core_v1.Node) error + DeleteNode(obj *core_v1.Node) error + GenericNode(obj *core_v1.Node) error +} + +type NodeEventHandlerFuncs struct { + OnCreate func(obj *core_v1.Node) error + OnUpdate func(old, new *core_v1.Node) error + OnDelete func(obj *core_v1.Node) error + OnGeneric func(obj *core_v1.Node) error +} + +func (f *NodeEventHandlerFuncs) CreateNode(obj *core_v1.Node) error { + if f.OnCreate == nil { + return nil + } + return f.OnCreate(obj) +} + +func (f *NodeEventHandlerFuncs) DeleteNode(obj *core_v1.Node) error { + if f.OnDelete == nil { + return nil + } + return f.OnDelete(obj) +} + +func (f *NodeEventHandlerFuncs) UpdateNode(objOld, objNew *core_v1.Node) error { + if f.OnUpdate == nil { + return nil + } + return f.OnUpdate(objOld, objNew) +} + +func (f *NodeEventHandlerFuncs) GenericNode(obj *core_v1.Node) error { + if f.OnGeneric == nil { + return nil + } + return f.OnGeneric(obj) +} + +type NodeEventWatcher interface { + AddEventHandler(ctx context.Context, h NodeEventHandler, predicates ...predicate.Predicate) error +} + +type nodeEventWatcher struct { + watcher events.EventWatcher +} + +func NewNodeEventWatcher(name string, mgr manager.Manager) NodeEventWatcher { + return &nodeEventWatcher{ + watcher: events.NewWatcher(name, mgr, &core_v1.Node{}), + } +} + +func (c *nodeEventWatcher) AddEventHandler(ctx context.Context, h NodeEventHandler, predicates ...predicate.Predicate) error { + handler := genericNodeHandler{handler: h} + if err := c.watcher.Watch(ctx, handler, predicates...); err != nil { + return err + } + return nil +} + +// genericNodeHandler implements a generic events.EventHandler +type genericNodeHandler struct { + handler NodeEventHandler +} + +func (h genericNodeHandler) Create(object runtime.Object) error { + obj, ok := object.(*core_v1.Node) + if !ok { + return errors.Errorf("internal error: Node handler received event for %T", object) + } + return h.handler.CreateNode(obj) +} + +func (h genericNodeHandler) Delete(object runtime.Object) error { + obj, ok := object.(*core_v1.Node) + if !ok { + return errors.Errorf("internal error: Node handler received event for %T", object) + } + return h.handler.DeleteNode(obj) +} + +func (h genericNodeHandler) Update(old, new runtime.Object) error { + objOld, ok := old.(*core_v1.Node) + if !ok { + return errors.Errorf("internal error: Node handler received event for %T", old) + } + objNew, ok := new.(*core_v1.Node) + if !ok { + return errors.Errorf("internal error: Node handler received event for %T", new) + } + return h.handler.UpdateNode(objOld, objNew) +} + +func (h genericNodeHandler) Generic(object runtime.Object) error { + obj, ok := object.(*core_v1.Node) + if !ok { + return errors.Errorf("internal error: Node handler received event for %T", object) + } + return h.handler.GenericNode(obj) +} diff --git a/pkg/generated/kubernetes/core/v1/controller/reconcilers.go b/pkg/generated/kubernetes/core/v1/controller/reconcilers.go new file mode 100644 index 000000000..49367b5f6 --- /dev/null +++ b/pkg/generated/kubernetes/core/v1/controller/reconcilers.go @@ -0,0 +1,819 @@ +// Definitions for the Kubernetes Controllers +package controller + +import ( + "context" + + core_v1 "k8s.io/api/core/v1" + + "github.com/pkg/errors" + "github.com/solo-io/skv2/pkg/ezkube" + "github.com/solo-io/skv2/pkg/reconcile" + "sigs.k8s.io/controller-runtime/pkg/manager" + "sigs.k8s.io/controller-runtime/pkg/predicate" +) + +// Reconcile Upsert events for the Secret Resource. +// implemented by the user +type SecretReconciler interface { + ReconcileSecret(obj *core_v1.Secret) (reconcile.Result, error) +} + +// Reconcile deletion events for the Secret Resource. +// Deletion receives a reconcile.Request as we cannot guarantee the last state of the object +// before being deleted. +// implemented by the user +type SecretDeletionReconciler interface { + ReconcileSecretDeletion(req reconcile.Request) +} + +type SecretReconcilerFuncs struct { + OnReconcileSecret func(obj *core_v1.Secret) (reconcile.Result, error) + OnReconcileSecretDeletion func(req reconcile.Request) +} + +func (f *SecretReconcilerFuncs) ReconcileSecret(obj *core_v1.Secret) (reconcile.Result, error) { + if f.OnReconcileSecret == nil { + return reconcile.Result{}, nil + } + return f.OnReconcileSecret(obj) +} + +func (f *SecretReconcilerFuncs) ReconcileSecretDeletion(req reconcile.Request) { + if f.OnReconcileSecretDeletion == nil { + return + } + f.OnReconcileSecretDeletion(req) +} + +// Reconcile and finalize the Secret Resource +// implemented by the user +type SecretFinalizer interface { + SecretReconciler + + // name of the finalizer used by this handler. + // finalizer names should be unique for a single task + SecretFinalizerName() string + + // finalize the object before it is deleted. + // Watchers created with a finalizing handler will a + FinalizeSecret(obj *core_v1.Secret) error +} + +type SecretReconcileLoop interface { + RunSecretReconciler(ctx context.Context, rec SecretReconciler, predicates ...predicate.Predicate) error +} + +type secretReconcileLoop struct { + loop reconcile.Loop +} + +func NewSecretReconcileLoop(name string, mgr manager.Manager) SecretReconcileLoop { + return &secretReconcileLoop{ + loop: reconcile.NewLoop(name, mgr, &core_v1.Secret{}), + } +} + +func (c *secretReconcileLoop) RunSecretReconciler(ctx context.Context, reconciler SecretReconciler, predicates ...predicate.Predicate) error { + genericReconciler := genericSecretReconciler{ + reconciler: reconciler, + } + + var reconcilerWrapper reconcile.Reconciler + if finalizingReconciler, ok := reconciler.(SecretFinalizer); ok { + reconcilerWrapper = genericSecretFinalizer{ + genericSecretReconciler: genericReconciler, + finalizingReconciler: finalizingReconciler, + } + } else { + reconcilerWrapper = genericReconciler + } + return c.loop.RunReconciler(ctx, reconcilerWrapper, predicates...) +} + +// genericSecretHandler implements a generic reconcile.Reconciler +type genericSecretReconciler struct { + reconciler SecretReconciler +} + +func (r genericSecretReconciler) Reconcile(object ezkube.Object) (reconcile.Result, error) { + obj, ok := object.(*core_v1.Secret) + if !ok { + return reconcile.Result{}, errors.Errorf("internal error: Secret handler received event for %T", object) + } + return r.reconciler.ReconcileSecret(obj) +} + +func (r genericSecretReconciler) ReconcileDeletion(request reconcile.Request) { + if deletionReconciler, ok := r.reconciler.(SecretDeletionReconciler); ok { + deletionReconciler.ReconcileSecretDeletion(request) + } +} + +// genericSecretFinalizer implements a generic reconcile.FinalizingReconciler +type genericSecretFinalizer struct { + genericSecretReconciler + finalizingReconciler SecretFinalizer +} + +func (r genericSecretFinalizer) FinalizerName() string { + return r.finalizingReconciler.SecretFinalizerName() +} + +func (r genericSecretFinalizer) Finalize(object ezkube.Object) error { + obj, ok := object.(*core_v1.Secret) + if !ok { + return errors.Errorf("internal error: Secret handler received event for %T", object) + } + return r.finalizingReconciler.FinalizeSecret(obj) +} + +// Reconcile Upsert events for the ServiceAccount Resource. +// implemented by the user +type ServiceAccountReconciler interface { + ReconcileServiceAccount(obj *core_v1.ServiceAccount) (reconcile.Result, error) +} + +// Reconcile deletion events for the ServiceAccount Resource. +// Deletion receives a reconcile.Request as we cannot guarantee the last state of the object +// before being deleted. +// implemented by the user +type ServiceAccountDeletionReconciler interface { + ReconcileServiceAccountDeletion(req reconcile.Request) +} + +type ServiceAccountReconcilerFuncs struct { + OnReconcileServiceAccount func(obj *core_v1.ServiceAccount) (reconcile.Result, error) + OnReconcileServiceAccountDeletion func(req reconcile.Request) +} + +func (f *ServiceAccountReconcilerFuncs) ReconcileServiceAccount(obj *core_v1.ServiceAccount) (reconcile.Result, error) { + if f.OnReconcileServiceAccount == nil { + return reconcile.Result{}, nil + } + return f.OnReconcileServiceAccount(obj) +} + +func (f *ServiceAccountReconcilerFuncs) ReconcileServiceAccountDeletion(req reconcile.Request) { + if f.OnReconcileServiceAccountDeletion == nil { + return + } + f.OnReconcileServiceAccountDeletion(req) +} + +// Reconcile and finalize the ServiceAccount Resource +// implemented by the user +type ServiceAccountFinalizer interface { + ServiceAccountReconciler + + // name of the finalizer used by this handler. + // finalizer names should be unique for a single task + ServiceAccountFinalizerName() string + + // finalize the object before it is deleted. + // Watchers created with a finalizing handler will a + FinalizeServiceAccount(obj *core_v1.ServiceAccount) error +} + +type ServiceAccountReconcileLoop interface { + RunServiceAccountReconciler(ctx context.Context, rec ServiceAccountReconciler, predicates ...predicate.Predicate) error +} + +type serviceAccountReconcileLoop struct { + loop reconcile.Loop +} + +func NewServiceAccountReconcileLoop(name string, mgr manager.Manager) ServiceAccountReconcileLoop { + return &serviceAccountReconcileLoop{ + loop: reconcile.NewLoop(name, mgr, &core_v1.ServiceAccount{}), + } +} + +func (c *serviceAccountReconcileLoop) RunServiceAccountReconciler(ctx context.Context, reconciler ServiceAccountReconciler, predicates ...predicate.Predicate) error { + genericReconciler := genericServiceAccountReconciler{ + reconciler: reconciler, + } + + var reconcilerWrapper reconcile.Reconciler + if finalizingReconciler, ok := reconciler.(ServiceAccountFinalizer); ok { + reconcilerWrapper = genericServiceAccountFinalizer{ + genericServiceAccountReconciler: genericReconciler, + finalizingReconciler: finalizingReconciler, + } + } else { + reconcilerWrapper = genericReconciler + } + return c.loop.RunReconciler(ctx, reconcilerWrapper, predicates...) +} + +// genericServiceAccountHandler implements a generic reconcile.Reconciler +type genericServiceAccountReconciler struct { + reconciler ServiceAccountReconciler +} + +func (r genericServiceAccountReconciler) Reconcile(object ezkube.Object) (reconcile.Result, error) { + obj, ok := object.(*core_v1.ServiceAccount) + if !ok { + return reconcile.Result{}, errors.Errorf("internal error: ServiceAccount handler received event for %T", object) + } + return r.reconciler.ReconcileServiceAccount(obj) +} + +func (r genericServiceAccountReconciler) ReconcileDeletion(request reconcile.Request) { + if deletionReconciler, ok := r.reconciler.(ServiceAccountDeletionReconciler); ok { + deletionReconciler.ReconcileServiceAccountDeletion(request) + } +} + +// genericServiceAccountFinalizer implements a generic reconcile.FinalizingReconciler +type genericServiceAccountFinalizer struct { + genericServiceAccountReconciler + finalizingReconciler ServiceAccountFinalizer +} + +func (r genericServiceAccountFinalizer) FinalizerName() string { + return r.finalizingReconciler.ServiceAccountFinalizerName() +} + +func (r genericServiceAccountFinalizer) Finalize(object ezkube.Object) error { + obj, ok := object.(*core_v1.ServiceAccount) + if !ok { + return errors.Errorf("internal error: ServiceAccount handler received event for %T", object) + } + return r.finalizingReconciler.FinalizeServiceAccount(obj) +} + +// Reconcile Upsert events for the ConfigMap Resource. +// implemented by the user +type ConfigMapReconciler interface { + ReconcileConfigMap(obj *core_v1.ConfigMap) (reconcile.Result, error) +} + +// Reconcile deletion events for the ConfigMap Resource. +// Deletion receives a reconcile.Request as we cannot guarantee the last state of the object +// before being deleted. +// implemented by the user +type ConfigMapDeletionReconciler interface { + ReconcileConfigMapDeletion(req reconcile.Request) +} + +type ConfigMapReconcilerFuncs struct { + OnReconcileConfigMap func(obj *core_v1.ConfigMap) (reconcile.Result, error) + OnReconcileConfigMapDeletion func(req reconcile.Request) +} + +func (f *ConfigMapReconcilerFuncs) ReconcileConfigMap(obj *core_v1.ConfigMap) (reconcile.Result, error) { + if f.OnReconcileConfigMap == nil { + return reconcile.Result{}, nil + } + return f.OnReconcileConfigMap(obj) +} + +func (f *ConfigMapReconcilerFuncs) ReconcileConfigMapDeletion(req reconcile.Request) { + if f.OnReconcileConfigMapDeletion == nil { + return + } + f.OnReconcileConfigMapDeletion(req) +} + +// Reconcile and finalize the ConfigMap Resource +// implemented by the user +type ConfigMapFinalizer interface { + ConfigMapReconciler + + // name of the finalizer used by this handler. + // finalizer names should be unique for a single task + ConfigMapFinalizerName() string + + // finalize the object before it is deleted. + // Watchers created with a finalizing handler will a + FinalizeConfigMap(obj *core_v1.ConfigMap) error +} + +type ConfigMapReconcileLoop interface { + RunConfigMapReconciler(ctx context.Context, rec ConfigMapReconciler, predicates ...predicate.Predicate) error +} + +type configMapReconcileLoop struct { + loop reconcile.Loop +} + +func NewConfigMapReconcileLoop(name string, mgr manager.Manager) ConfigMapReconcileLoop { + return &configMapReconcileLoop{ + loop: reconcile.NewLoop(name, mgr, &core_v1.ConfigMap{}), + } +} + +func (c *configMapReconcileLoop) RunConfigMapReconciler(ctx context.Context, reconciler ConfigMapReconciler, predicates ...predicate.Predicate) error { + genericReconciler := genericConfigMapReconciler{ + reconciler: reconciler, + } + + var reconcilerWrapper reconcile.Reconciler + if finalizingReconciler, ok := reconciler.(ConfigMapFinalizer); ok { + reconcilerWrapper = genericConfigMapFinalizer{ + genericConfigMapReconciler: genericReconciler, + finalizingReconciler: finalizingReconciler, + } + } else { + reconcilerWrapper = genericReconciler + } + return c.loop.RunReconciler(ctx, reconcilerWrapper, predicates...) +} + +// genericConfigMapHandler implements a generic reconcile.Reconciler +type genericConfigMapReconciler struct { + reconciler ConfigMapReconciler +} + +func (r genericConfigMapReconciler) Reconcile(object ezkube.Object) (reconcile.Result, error) { + obj, ok := object.(*core_v1.ConfigMap) + if !ok { + return reconcile.Result{}, errors.Errorf("internal error: ConfigMap handler received event for %T", object) + } + return r.reconciler.ReconcileConfigMap(obj) +} + +func (r genericConfigMapReconciler) ReconcileDeletion(request reconcile.Request) { + if deletionReconciler, ok := r.reconciler.(ConfigMapDeletionReconciler); ok { + deletionReconciler.ReconcileConfigMapDeletion(request) + } +} + +// genericConfigMapFinalizer implements a generic reconcile.FinalizingReconciler +type genericConfigMapFinalizer struct { + genericConfigMapReconciler + finalizingReconciler ConfigMapFinalizer +} + +func (r genericConfigMapFinalizer) FinalizerName() string { + return r.finalizingReconciler.ConfigMapFinalizerName() +} + +func (r genericConfigMapFinalizer) Finalize(object ezkube.Object) error { + obj, ok := object.(*core_v1.ConfigMap) + if !ok { + return errors.Errorf("internal error: ConfigMap handler received event for %T", object) + } + return r.finalizingReconciler.FinalizeConfigMap(obj) +} + +// Reconcile Upsert events for the Service Resource. +// implemented by the user +type ServiceReconciler interface { + ReconcileService(obj *core_v1.Service) (reconcile.Result, error) +} + +// Reconcile deletion events for the Service Resource. +// Deletion receives a reconcile.Request as we cannot guarantee the last state of the object +// before being deleted. +// implemented by the user +type ServiceDeletionReconciler interface { + ReconcileServiceDeletion(req reconcile.Request) +} + +type ServiceReconcilerFuncs struct { + OnReconcileService func(obj *core_v1.Service) (reconcile.Result, error) + OnReconcileServiceDeletion func(req reconcile.Request) +} + +func (f *ServiceReconcilerFuncs) ReconcileService(obj *core_v1.Service) (reconcile.Result, error) { + if f.OnReconcileService == nil { + return reconcile.Result{}, nil + } + return f.OnReconcileService(obj) +} + +func (f *ServiceReconcilerFuncs) ReconcileServiceDeletion(req reconcile.Request) { + if f.OnReconcileServiceDeletion == nil { + return + } + f.OnReconcileServiceDeletion(req) +} + +// Reconcile and finalize the Service Resource +// implemented by the user +type ServiceFinalizer interface { + ServiceReconciler + + // name of the finalizer used by this handler. + // finalizer names should be unique for a single task + ServiceFinalizerName() string + + // finalize the object before it is deleted. + // Watchers created with a finalizing handler will a + FinalizeService(obj *core_v1.Service) error +} + +type ServiceReconcileLoop interface { + RunServiceReconciler(ctx context.Context, rec ServiceReconciler, predicates ...predicate.Predicate) error +} + +type serviceReconcileLoop struct { + loop reconcile.Loop +} + +func NewServiceReconcileLoop(name string, mgr manager.Manager) ServiceReconcileLoop { + return &serviceReconcileLoop{ + loop: reconcile.NewLoop(name, mgr, &core_v1.Service{}), + } +} + +func (c *serviceReconcileLoop) RunServiceReconciler(ctx context.Context, reconciler ServiceReconciler, predicates ...predicate.Predicate) error { + genericReconciler := genericServiceReconciler{ + reconciler: reconciler, + } + + var reconcilerWrapper reconcile.Reconciler + if finalizingReconciler, ok := reconciler.(ServiceFinalizer); ok { + reconcilerWrapper = genericServiceFinalizer{ + genericServiceReconciler: genericReconciler, + finalizingReconciler: finalizingReconciler, + } + } else { + reconcilerWrapper = genericReconciler + } + return c.loop.RunReconciler(ctx, reconcilerWrapper, predicates...) +} + +// genericServiceHandler implements a generic reconcile.Reconciler +type genericServiceReconciler struct { + reconciler ServiceReconciler +} + +func (r genericServiceReconciler) Reconcile(object ezkube.Object) (reconcile.Result, error) { + obj, ok := object.(*core_v1.Service) + if !ok { + return reconcile.Result{}, errors.Errorf("internal error: Service handler received event for %T", object) + } + return r.reconciler.ReconcileService(obj) +} + +func (r genericServiceReconciler) ReconcileDeletion(request reconcile.Request) { + if deletionReconciler, ok := r.reconciler.(ServiceDeletionReconciler); ok { + deletionReconciler.ReconcileServiceDeletion(request) + } +} + +// genericServiceFinalizer implements a generic reconcile.FinalizingReconciler +type genericServiceFinalizer struct { + genericServiceReconciler + finalizingReconciler ServiceFinalizer +} + +func (r genericServiceFinalizer) FinalizerName() string { + return r.finalizingReconciler.ServiceFinalizerName() +} + +func (r genericServiceFinalizer) Finalize(object ezkube.Object) error { + obj, ok := object.(*core_v1.Service) + if !ok { + return errors.Errorf("internal error: Service handler received event for %T", object) + } + return r.finalizingReconciler.FinalizeService(obj) +} + +// Reconcile Upsert events for the Pod Resource. +// implemented by the user +type PodReconciler interface { + ReconcilePod(obj *core_v1.Pod) (reconcile.Result, error) +} + +// Reconcile deletion events for the Pod Resource. +// Deletion receives a reconcile.Request as we cannot guarantee the last state of the object +// before being deleted. +// implemented by the user +type PodDeletionReconciler interface { + ReconcilePodDeletion(req reconcile.Request) +} + +type PodReconcilerFuncs struct { + OnReconcilePod func(obj *core_v1.Pod) (reconcile.Result, error) + OnReconcilePodDeletion func(req reconcile.Request) +} + +func (f *PodReconcilerFuncs) ReconcilePod(obj *core_v1.Pod) (reconcile.Result, error) { + if f.OnReconcilePod == nil { + return reconcile.Result{}, nil + } + return f.OnReconcilePod(obj) +} + +func (f *PodReconcilerFuncs) ReconcilePodDeletion(req reconcile.Request) { + if f.OnReconcilePodDeletion == nil { + return + } + f.OnReconcilePodDeletion(req) +} + +// Reconcile and finalize the Pod Resource +// implemented by the user +type PodFinalizer interface { + PodReconciler + + // name of the finalizer used by this handler. + // finalizer names should be unique for a single task + PodFinalizerName() string + + // finalize the object before it is deleted. + // Watchers created with a finalizing handler will a + FinalizePod(obj *core_v1.Pod) error +} + +type PodReconcileLoop interface { + RunPodReconciler(ctx context.Context, rec PodReconciler, predicates ...predicate.Predicate) error +} + +type podReconcileLoop struct { + loop reconcile.Loop +} + +func NewPodReconcileLoop(name string, mgr manager.Manager) PodReconcileLoop { + return &podReconcileLoop{ + loop: reconcile.NewLoop(name, mgr, &core_v1.Pod{}), + } +} + +func (c *podReconcileLoop) RunPodReconciler(ctx context.Context, reconciler PodReconciler, predicates ...predicate.Predicate) error { + genericReconciler := genericPodReconciler{ + reconciler: reconciler, + } + + var reconcilerWrapper reconcile.Reconciler + if finalizingReconciler, ok := reconciler.(PodFinalizer); ok { + reconcilerWrapper = genericPodFinalizer{ + genericPodReconciler: genericReconciler, + finalizingReconciler: finalizingReconciler, + } + } else { + reconcilerWrapper = genericReconciler + } + return c.loop.RunReconciler(ctx, reconcilerWrapper, predicates...) +} + +// genericPodHandler implements a generic reconcile.Reconciler +type genericPodReconciler struct { + reconciler PodReconciler +} + +func (r genericPodReconciler) Reconcile(object ezkube.Object) (reconcile.Result, error) { + obj, ok := object.(*core_v1.Pod) + if !ok { + return reconcile.Result{}, errors.Errorf("internal error: Pod handler received event for %T", object) + } + return r.reconciler.ReconcilePod(obj) +} + +func (r genericPodReconciler) ReconcileDeletion(request reconcile.Request) { + if deletionReconciler, ok := r.reconciler.(PodDeletionReconciler); ok { + deletionReconciler.ReconcilePodDeletion(request) + } +} + +// genericPodFinalizer implements a generic reconcile.FinalizingReconciler +type genericPodFinalizer struct { + genericPodReconciler + finalizingReconciler PodFinalizer +} + +func (r genericPodFinalizer) FinalizerName() string { + return r.finalizingReconciler.PodFinalizerName() +} + +func (r genericPodFinalizer) Finalize(object ezkube.Object) error { + obj, ok := object.(*core_v1.Pod) + if !ok { + return errors.Errorf("internal error: Pod handler received event for %T", object) + } + return r.finalizingReconciler.FinalizePod(obj) +} + +// Reconcile Upsert events for the Namespace Resource. +// implemented by the user +type NamespaceReconciler interface { + ReconcileNamespace(obj *core_v1.Namespace) (reconcile.Result, error) +} + +// Reconcile deletion events for the Namespace Resource. +// Deletion receives a reconcile.Request as we cannot guarantee the last state of the object +// before being deleted. +// implemented by the user +type NamespaceDeletionReconciler interface { + ReconcileNamespaceDeletion(req reconcile.Request) +} + +type NamespaceReconcilerFuncs struct { + OnReconcileNamespace func(obj *core_v1.Namespace) (reconcile.Result, error) + OnReconcileNamespaceDeletion func(req reconcile.Request) +} + +func (f *NamespaceReconcilerFuncs) ReconcileNamespace(obj *core_v1.Namespace) (reconcile.Result, error) { + if f.OnReconcileNamespace == nil { + return reconcile.Result{}, nil + } + return f.OnReconcileNamespace(obj) +} + +func (f *NamespaceReconcilerFuncs) ReconcileNamespaceDeletion(req reconcile.Request) { + if f.OnReconcileNamespaceDeletion == nil { + return + } + f.OnReconcileNamespaceDeletion(req) +} + +// Reconcile and finalize the Namespace Resource +// implemented by the user +type NamespaceFinalizer interface { + NamespaceReconciler + + // name of the finalizer used by this handler. + // finalizer names should be unique for a single task + NamespaceFinalizerName() string + + // finalize the object before it is deleted. + // Watchers created with a finalizing handler will a + FinalizeNamespace(obj *core_v1.Namespace) error +} + +type NamespaceReconcileLoop interface { + RunNamespaceReconciler(ctx context.Context, rec NamespaceReconciler, predicates ...predicate.Predicate) error +} + +type namespaceReconcileLoop struct { + loop reconcile.Loop +} + +func NewNamespaceReconcileLoop(name string, mgr manager.Manager) NamespaceReconcileLoop { + return &namespaceReconcileLoop{ + loop: reconcile.NewLoop(name, mgr, &core_v1.Namespace{}), + } +} + +func (c *namespaceReconcileLoop) RunNamespaceReconciler(ctx context.Context, reconciler NamespaceReconciler, predicates ...predicate.Predicate) error { + genericReconciler := genericNamespaceReconciler{ + reconciler: reconciler, + } + + var reconcilerWrapper reconcile.Reconciler + if finalizingReconciler, ok := reconciler.(NamespaceFinalizer); ok { + reconcilerWrapper = genericNamespaceFinalizer{ + genericNamespaceReconciler: genericReconciler, + finalizingReconciler: finalizingReconciler, + } + } else { + reconcilerWrapper = genericReconciler + } + return c.loop.RunReconciler(ctx, reconcilerWrapper, predicates...) +} + +// genericNamespaceHandler implements a generic reconcile.Reconciler +type genericNamespaceReconciler struct { + reconciler NamespaceReconciler +} + +func (r genericNamespaceReconciler) Reconcile(object ezkube.Object) (reconcile.Result, error) { + obj, ok := object.(*core_v1.Namespace) + if !ok { + return reconcile.Result{}, errors.Errorf("internal error: Namespace handler received event for %T", object) + } + return r.reconciler.ReconcileNamespace(obj) +} + +func (r genericNamespaceReconciler) ReconcileDeletion(request reconcile.Request) { + if deletionReconciler, ok := r.reconciler.(NamespaceDeletionReconciler); ok { + deletionReconciler.ReconcileNamespaceDeletion(request) + } +} + +// genericNamespaceFinalizer implements a generic reconcile.FinalizingReconciler +type genericNamespaceFinalizer struct { + genericNamespaceReconciler + finalizingReconciler NamespaceFinalizer +} + +func (r genericNamespaceFinalizer) FinalizerName() string { + return r.finalizingReconciler.NamespaceFinalizerName() +} + +func (r genericNamespaceFinalizer) Finalize(object ezkube.Object) error { + obj, ok := object.(*core_v1.Namespace) + if !ok { + return errors.Errorf("internal error: Namespace handler received event for %T", object) + } + return r.finalizingReconciler.FinalizeNamespace(obj) +} + +// Reconcile Upsert events for the Node Resource. +// implemented by the user +type NodeReconciler interface { + ReconcileNode(obj *core_v1.Node) (reconcile.Result, error) +} + +// Reconcile deletion events for the Node Resource. +// Deletion receives a reconcile.Request as we cannot guarantee the last state of the object +// before being deleted. +// implemented by the user +type NodeDeletionReconciler interface { + ReconcileNodeDeletion(req reconcile.Request) +} + +type NodeReconcilerFuncs struct { + OnReconcileNode func(obj *core_v1.Node) (reconcile.Result, error) + OnReconcileNodeDeletion func(req reconcile.Request) +} + +func (f *NodeReconcilerFuncs) ReconcileNode(obj *core_v1.Node) (reconcile.Result, error) { + if f.OnReconcileNode == nil { + return reconcile.Result{}, nil + } + return f.OnReconcileNode(obj) +} + +func (f *NodeReconcilerFuncs) ReconcileNodeDeletion(req reconcile.Request) { + if f.OnReconcileNodeDeletion == nil { + return + } + f.OnReconcileNodeDeletion(req) +} + +// Reconcile and finalize the Node Resource +// implemented by the user +type NodeFinalizer interface { + NodeReconciler + + // name of the finalizer used by this handler. + // finalizer names should be unique for a single task + NodeFinalizerName() string + + // finalize the object before it is deleted. + // Watchers created with a finalizing handler will a + FinalizeNode(obj *core_v1.Node) error +} + +type NodeReconcileLoop interface { + RunNodeReconciler(ctx context.Context, rec NodeReconciler, predicates ...predicate.Predicate) error +} + +type nodeReconcileLoop struct { + loop reconcile.Loop +} + +func NewNodeReconcileLoop(name string, mgr manager.Manager) NodeReconcileLoop { + return &nodeReconcileLoop{ + loop: reconcile.NewLoop(name, mgr, &core_v1.Node{}), + } +} + +func (c *nodeReconcileLoop) RunNodeReconciler(ctx context.Context, reconciler NodeReconciler, predicates ...predicate.Predicate) error { + genericReconciler := genericNodeReconciler{ + reconciler: reconciler, + } + + var reconcilerWrapper reconcile.Reconciler + if finalizingReconciler, ok := reconciler.(NodeFinalizer); ok { + reconcilerWrapper = genericNodeFinalizer{ + genericNodeReconciler: genericReconciler, + finalizingReconciler: finalizingReconciler, + } + } else { + reconcilerWrapper = genericReconciler + } + return c.loop.RunReconciler(ctx, reconcilerWrapper, predicates...) +} + +// genericNodeHandler implements a generic reconcile.Reconciler +type genericNodeReconciler struct { + reconciler NodeReconciler +} + +func (r genericNodeReconciler) Reconcile(object ezkube.Object) (reconcile.Result, error) { + obj, ok := object.(*core_v1.Node) + if !ok { + return reconcile.Result{}, errors.Errorf("internal error: Node handler received event for %T", object) + } + return r.reconciler.ReconcileNode(obj) +} + +func (r genericNodeReconciler) ReconcileDeletion(request reconcile.Request) { + if deletionReconciler, ok := r.reconciler.(NodeDeletionReconciler); ok { + deletionReconciler.ReconcileNodeDeletion(request) + } +} + +// genericNodeFinalizer implements a generic reconcile.FinalizingReconciler +type genericNodeFinalizer struct { + genericNodeReconciler + finalizingReconciler NodeFinalizer +} + +func (r genericNodeFinalizer) FinalizerName() string { + return r.finalizingReconciler.NodeFinalizerName() +} + +func (r genericNodeFinalizer) Finalize(object ezkube.Object) error { + obj, ok := object.(*core_v1.Node) + if !ok { + return errors.Errorf("internal error: Node handler received event for %T", object) + } + return r.finalizingReconciler.FinalizeNode(obj) +} diff --git a/pkg/generated/kubernetes/rbac.authorization.k8s.io/v1/clients.go b/pkg/generated/kubernetes/rbac.authorization.k8s.io/v1/clients.go new file mode 100644 index 000000000..8c864da80 --- /dev/null +++ b/pkg/generated/kubernetes/rbac.authorization.k8s.io/v1/clients.go @@ -0,0 +1,469 @@ +package v1 + +import ( + "context" + + "k8s.io/client-go/kubernetes/scheme" + "k8s.io/client-go/rest" + "sigs.k8s.io/controller-runtime/pkg/client" + + . "k8s.io/api/rbac/v1" +) + +// clienset for the rbac.authorization.k8s.io/v1 APIs +type Clientset interface { + // clienset for the rbac.authorization.k8s.io/v1/v1 APIs + Roles() RoleClient + // clienset for the rbac.authorization.k8s.io/v1/v1 APIs + RoleBindings() RoleBindingClient + // clienset for the rbac.authorization.k8s.io/v1/v1 APIs + ClusterRoles() ClusterRoleClient + // clienset for the rbac.authorization.k8s.io/v1/v1 APIs + ClusterRoleBindings() ClusterRoleBindingClient +} + +type clientSet struct { + client client.Client +} + +func NewClientsetFromConfig(cfg *rest.Config) (Clientset, error) { + scheme := scheme.Scheme + if err := AddToScheme(scheme); err != nil { + return nil, err + } + client, err := client.New(cfg, client.Options{ + Scheme: scheme, + }) + if err != nil { + return nil, err + } + return NewClientset(client), nil +} + +func NewClientset(client client.Client) Clientset { + return &clientSet{client: client} +} + +// clienset for the rbac.authorization.k8s.io/v1/v1 APIs +func (c *clientSet) Roles() RoleClient { + return NewRoleClient(c.client) +} + +// clienset for the rbac.authorization.k8s.io/v1/v1 APIs +func (c *clientSet) RoleBindings() RoleBindingClient { + return NewRoleBindingClient(c.client) +} + +// clienset for the rbac.authorization.k8s.io/v1/v1 APIs +func (c *clientSet) ClusterRoles() ClusterRoleClient { + return NewClusterRoleClient(c.client) +} + +// clienset for the rbac.authorization.k8s.io/v1/v1 APIs +func (c *clientSet) ClusterRoleBindings() ClusterRoleBindingClient { + return NewClusterRoleBindingClient(c.client) +} + +// Reader knows how to read and list Roles. +type RoleReader interface { + // Get retrieves a Role for the given object key + GetRole(ctx context.Context, key client.ObjectKey) (*Role, error) + + // List retrieves list of Roles for a given namespace and list options. + ListRole(ctx context.Context, opts ...client.ListOption) (*RoleList, error) +} + +// Writer knows how to create, delete, and update Roles. +type RoleWriter interface { + // Create saves the Role object. + CreateRole(ctx context.Context, obj *Role, opts ...client.CreateOption) error + + // Delete deletes the Role object. + DeleteRole(ctx context.Context, key client.ObjectKey, opts ...client.DeleteOption) error + + // Update updates the given Role object. + UpdateRole(ctx context.Context, obj *Role, opts ...client.UpdateOption) error + + // Patch patches the given Role object. + PatchRole(ctx context.Context, obj *Role, patch client.Patch, opts ...client.PatchOption) error + + // DeleteAllOf deletes all Role objects matching the given options. + DeleteAllOfRole(ctx context.Context, opts ...client.DeleteAllOfOption) error +} + +// StatusWriter knows how to update status subresource of a Role object. +type RoleStatusWriter interface { + // Update updates the fields corresponding to the status subresource for the + // given Role object. + UpdateRoleStatus(ctx context.Context, obj *Role, opts ...client.UpdateOption) error + + // Patch patches the given Role object's subresource. + PatchRoleStatus(ctx context.Context, obj *Role, patch client.Patch, opts ...client.PatchOption) error +} + +// Client knows how to perform CRUD operations on Roles. +type RoleClient interface { + RoleReader + RoleWriter + RoleStatusWriter +} + +type roleClient struct { + client client.Client +} + +func NewRoleClient(client client.Client) *roleClient { + return &roleClient{client: client} +} + +func (c *roleClient) GetRole(ctx context.Context, key client.ObjectKey) (*Role, error) { + obj := &Role{} + if err := c.client.Get(ctx, key, obj); err != nil { + return nil, err + } + return obj, nil +} + +func (c *roleClient) ListRole(ctx context.Context, opts ...client.ListOption) (*RoleList, error) { + list := &RoleList{} + if err := c.client.List(ctx, list, opts...); err != nil { + return nil, err + } + return list, nil +} + +func (c *roleClient) CreateRole(ctx context.Context, obj *Role, opts ...client.CreateOption) error { + return c.client.Create(ctx, obj, opts...) +} + +func (c *roleClient) DeleteRole(ctx context.Context, key client.ObjectKey, opts ...client.DeleteOption) error { + obj := &Role{} + obj.SetName(key.Name) + obj.SetNamespace(key.Namespace) + return c.client.Delete(ctx, obj, opts...) +} + +func (c *roleClient) UpdateRole(ctx context.Context, obj *Role, opts ...client.UpdateOption) error { + return c.client.Update(ctx, obj, opts...) +} + +func (c *roleClient) PatchRole(ctx context.Context, obj *Role, patch client.Patch, opts ...client.PatchOption) error { + return c.client.Patch(ctx, obj, patch, opts...) +} + +func (c *roleClient) DeleteAllOfRole(ctx context.Context, opts ...client.DeleteAllOfOption) error { + obj := &Role{} + return c.client.DeleteAllOf(ctx, obj, opts...) +} + +func (c *roleClient) UpdateRoleStatus(ctx context.Context, obj *Role, opts ...client.UpdateOption) error { + return c.client.Status().Update(ctx, obj, opts...) +} + +func (c *roleClient) PatchRoleStatus(ctx context.Context, obj *Role, patch client.Patch, opts ...client.PatchOption) error { + return c.client.Status().Patch(ctx, obj, patch, opts...) +} + +// Reader knows how to read and list RoleBindings. +type RoleBindingReader interface { + // Get retrieves a RoleBinding for the given object key + GetRoleBinding(ctx context.Context, key client.ObjectKey) (*RoleBinding, error) + + // List retrieves list of RoleBindings for a given namespace and list options. + ListRoleBinding(ctx context.Context, opts ...client.ListOption) (*RoleBindingList, error) +} + +// Writer knows how to create, delete, and update RoleBindings. +type RoleBindingWriter interface { + // Create saves the RoleBinding object. + CreateRoleBinding(ctx context.Context, obj *RoleBinding, opts ...client.CreateOption) error + + // Delete deletes the RoleBinding object. + DeleteRoleBinding(ctx context.Context, key client.ObjectKey, opts ...client.DeleteOption) error + + // Update updates the given RoleBinding object. + UpdateRoleBinding(ctx context.Context, obj *RoleBinding, opts ...client.UpdateOption) error + + // Patch patches the given RoleBinding object. + PatchRoleBinding(ctx context.Context, obj *RoleBinding, patch client.Patch, opts ...client.PatchOption) error + + // DeleteAllOf deletes all RoleBinding objects matching the given options. + DeleteAllOfRoleBinding(ctx context.Context, opts ...client.DeleteAllOfOption) error +} + +// StatusWriter knows how to update status subresource of a RoleBinding object. +type RoleBindingStatusWriter interface { + // Update updates the fields corresponding to the status subresource for the + // given RoleBinding object. + UpdateRoleBindingStatus(ctx context.Context, obj *RoleBinding, opts ...client.UpdateOption) error + + // Patch patches the given RoleBinding object's subresource. + PatchRoleBindingStatus(ctx context.Context, obj *RoleBinding, patch client.Patch, opts ...client.PatchOption) error +} + +// Client knows how to perform CRUD operations on RoleBindings. +type RoleBindingClient interface { + RoleBindingReader + RoleBindingWriter + RoleBindingStatusWriter +} + +type roleBindingClient struct { + client client.Client +} + +func NewRoleBindingClient(client client.Client) *roleBindingClient { + return &roleBindingClient{client: client} +} + +func (c *roleBindingClient) GetRoleBinding(ctx context.Context, key client.ObjectKey) (*RoleBinding, error) { + obj := &RoleBinding{} + if err := c.client.Get(ctx, key, obj); err != nil { + return nil, err + } + return obj, nil +} + +func (c *roleBindingClient) ListRoleBinding(ctx context.Context, opts ...client.ListOption) (*RoleBindingList, error) { + list := &RoleBindingList{} + if err := c.client.List(ctx, list, opts...); err != nil { + return nil, err + } + return list, nil +} + +func (c *roleBindingClient) CreateRoleBinding(ctx context.Context, obj *RoleBinding, opts ...client.CreateOption) error { + return c.client.Create(ctx, obj, opts...) +} + +func (c *roleBindingClient) DeleteRoleBinding(ctx context.Context, key client.ObjectKey, opts ...client.DeleteOption) error { + obj := &RoleBinding{} + obj.SetName(key.Name) + obj.SetNamespace(key.Namespace) + return c.client.Delete(ctx, obj, opts...) +} + +func (c *roleBindingClient) UpdateRoleBinding(ctx context.Context, obj *RoleBinding, opts ...client.UpdateOption) error { + return c.client.Update(ctx, obj, opts...) +} + +func (c *roleBindingClient) PatchRoleBinding(ctx context.Context, obj *RoleBinding, patch client.Patch, opts ...client.PatchOption) error { + return c.client.Patch(ctx, obj, patch, opts...) +} + +func (c *roleBindingClient) DeleteAllOfRoleBinding(ctx context.Context, opts ...client.DeleteAllOfOption) error { + obj := &RoleBinding{} + return c.client.DeleteAllOf(ctx, obj, opts...) +} + +func (c *roleBindingClient) UpdateRoleBindingStatus(ctx context.Context, obj *RoleBinding, opts ...client.UpdateOption) error { + return c.client.Status().Update(ctx, obj, opts...) +} + +func (c *roleBindingClient) PatchRoleBindingStatus(ctx context.Context, obj *RoleBinding, patch client.Patch, opts ...client.PatchOption) error { + return c.client.Status().Patch(ctx, obj, patch, opts...) +} + +// Reader knows how to read and list ClusterRoles. +type ClusterRoleReader interface { + // Get retrieves a ClusterRole for the given object key + GetClusterRole(ctx context.Context, name string) (*ClusterRole, error) + + // List retrieves list of ClusterRoles for a given namespace and list options. + ListClusterRole(ctx context.Context, opts ...client.ListOption) (*ClusterRoleList, error) +} + +// Writer knows how to create, delete, and update ClusterRoles. +type ClusterRoleWriter interface { + // Create saves the ClusterRole object. + CreateClusterRole(ctx context.Context, obj *ClusterRole, opts ...client.CreateOption) error + + // Delete deletes the ClusterRole object. + DeleteClusterRole(ctx context.Context, name string, opts ...client.DeleteOption) error + + // Update updates the given ClusterRole object. + UpdateClusterRole(ctx context.Context, obj *ClusterRole, opts ...client.UpdateOption) error + + // Patch patches the given ClusterRole object. + PatchClusterRole(ctx context.Context, obj *ClusterRole, patch client.Patch, opts ...client.PatchOption) error + + // DeleteAllOf deletes all ClusterRole objects matching the given options. + DeleteAllOfClusterRole(ctx context.Context, opts ...client.DeleteAllOfOption) error +} + +// StatusWriter knows how to update status subresource of a ClusterRole object. +type ClusterRoleStatusWriter interface { + // Update updates the fields corresponding to the status subresource for the + // given ClusterRole object. + UpdateClusterRoleStatus(ctx context.Context, obj *ClusterRole, opts ...client.UpdateOption) error + + // Patch patches the given ClusterRole object's subresource. + PatchClusterRoleStatus(ctx context.Context, obj *ClusterRole, patch client.Patch, opts ...client.PatchOption) error +} + +// Client knows how to perform CRUD operations on ClusterRoles. +type ClusterRoleClient interface { + ClusterRoleReader + ClusterRoleWriter + ClusterRoleStatusWriter +} + +type clusterRoleClient struct { + client client.Client +} + +func NewClusterRoleClient(client client.Client) *clusterRoleClient { + return &clusterRoleClient{client: client} +} + +func (c *clusterRoleClient) GetClusterRole(ctx context.Context, name string) (*ClusterRole, error) { + obj := &ClusterRole{} + key := client.ObjectKey{ + Name: name, + } + if err := c.client.Get(ctx, key, obj); err != nil { + return nil, err + } + return obj, nil +} + +func (c *clusterRoleClient) ListClusterRole(ctx context.Context, opts ...client.ListOption) (*ClusterRoleList, error) { + list := &ClusterRoleList{} + if err := c.client.List(ctx, list, opts...); err != nil { + return nil, err + } + return list, nil +} + +func (c *clusterRoleClient) CreateClusterRole(ctx context.Context, obj *ClusterRole, opts ...client.CreateOption) error { + return c.client.Create(ctx, obj, opts...) +} + +func (c *clusterRoleClient) DeleteClusterRole(ctx context.Context, name string, opts ...client.DeleteOption) error { + obj := &ClusterRole{} + obj.SetName(name) + return c.client.Delete(ctx, obj, opts...) +} + +func (c *clusterRoleClient) UpdateClusterRole(ctx context.Context, obj *ClusterRole, opts ...client.UpdateOption) error { + return c.client.Update(ctx, obj, opts...) +} + +func (c *clusterRoleClient) PatchClusterRole(ctx context.Context, obj *ClusterRole, patch client.Patch, opts ...client.PatchOption) error { + return c.client.Patch(ctx, obj, patch, opts...) +} + +func (c *clusterRoleClient) DeleteAllOfClusterRole(ctx context.Context, opts ...client.DeleteAllOfOption) error { + obj := &ClusterRole{} + return c.client.DeleteAllOf(ctx, obj, opts...) +} + +func (c *clusterRoleClient) UpdateClusterRoleStatus(ctx context.Context, obj *ClusterRole, opts ...client.UpdateOption) error { + return c.client.Status().Update(ctx, obj, opts...) +} + +func (c *clusterRoleClient) PatchClusterRoleStatus(ctx context.Context, obj *ClusterRole, patch client.Patch, opts ...client.PatchOption) error { + return c.client.Status().Patch(ctx, obj, patch, opts...) +} + +// Reader knows how to read and list ClusterRoleBindings. +type ClusterRoleBindingReader interface { + // Get retrieves a ClusterRoleBinding for the given object key + GetClusterRoleBinding(ctx context.Context, name string) (*ClusterRoleBinding, error) + + // List retrieves list of ClusterRoleBindings for a given namespace and list options. + ListClusterRoleBinding(ctx context.Context, opts ...client.ListOption) (*ClusterRoleBindingList, error) +} + +// Writer knows how to create, delete, and update ClusterRoleBindings. +type ClusterRoleBindingWriter interface { + // Create saves the ClusterRoleBinding object. + CreateClusterRoleBinding(ctx context.Context, obj *ClusterRoleBinding, opts ...client.CreateOption) error + + // Delete deletes the ClusterRoleBinding object. + DeleteClusterRoleBinding(ctx context.Context, name string, opts ...client.DeleteOption) error + + // Update updates the given ClusterRoleBinding object. + UpdateClusterRoleBinding(ctx context.Context, obj *ClusterRoleBinding, opts ...client.UpdateOption) error + + // Patch patches the given ClusterRoleBinding object. + PatchClusterRoleBinding(ctx context.Context, obj *ClusterRoleBinding, patch client.Patch, opts ...client.PatchOption) error + + // DeleteAllOf deletes all ClusterRoleBinding objects matching the given options. + DeleteAllOfClusterRoleBinding(ctx context.Context, opts ...client.DeleteAllOfOption) error +} + +// StatusWriter knows how to update status subresource of a ClusterRoleBinding object. +type ClusterRoleBindingStatusWriter interface { + // Update updates the fields corresponding to the status subresource for the + // given ClusterRoleBinding object. + UpdateClusterRoleBindingStatus(ctx context.Context, obj *ClusterRoleBinding, opts ...client.UpdateOption) error + + // Patch patches the given ClusterRoleBinding object's subresource. + PatchClusterRoleBindingStatus(ctx context.Context, obj *ClusterRoleBinding, patch client.Patch, opts ...client.PatchOption) error +} + +// Client knows how to perform CRUD operations on ClusterRoleBindings. +type ClusterRoleBindingClient interface { + ClusterRoleBindingReader + ClusterRoleBindingWriter + ClusterRoleBindingStatusWriter +} + +type clusterRoleBindingClient struct { + client client.Client +} + +func NewClusterRoleBindingClient(client client.Client) *clusterRoleBindingClient { + return &clusterRoleBindingClient{client: client} +} + +func (c *clusterRoleBindingClient) GetClusterRoleBinding(ctx context.Context, name string) (*ClusterRoleBinding, error) { + obj := &ClusterRoleBinding{} + key := client.ObjectKey{ + Name: name, + } + if err := c.client.Get(ctx, key, obj); err != nil { + return nil, err + } + return obj, nil +} + +func (c *clusterRoleBindingClient) ListClusterRoleBinding(ctx context.Context, opts ...client.ListOption) (*ClusterRoleBindingList, error) { + list := &ClusterRoleBindingList{} + if err := c.client.List(ctx, list, opts...); err != nil { + return nil, err + } + return list, nil +} + +func (c *clusterRoleBindingClient) CreateClusterRoleBinding(ctx context.Context, obj *ClusterRoleBinding, opts ...client.CreateOption) error { + return c.client.Create(ctx, obj, opts...) +} + +func (c *clusterRoleBindingClient) DeleteClusterRoleBinding(ctx context.Context, name string, opts ...client.DeleteOption) error { + obj := &ClusterRoleBinding{} + obj.SetName(name) + return c.client.Delete(ctx, obj, opts...) +} + +func (c *clusterRoleBindingClient) UpdateClusterRoleBinding(ctx context.Context, obj *ClusterRoleBinding, opts ...client.UpdateOption) error { + return c.client.Update(ctx, obj, opts...) +} + +func (c *clusterRoleBindingClient) PatchClusterRoleBinding(ctx context.Context, obj *ClusterRoleBinding, patch client.Patch, opts ...client.PatchOption) error { + return c.client.Patch(ctx, obj, patch, opts...) +} + +func (c *clusterRoleBindingClient) DeleteAllOfClusterRoleBinding(ctx context.Context, opts ...client.DeleteAllOfOption) error { + obj := &ClusterRoleBinding{} + return c.client.DeleteAllOf(ctx, obj, opts...) +} + +func (c *clusterRoleBindingClient) UpdateClusterRoleBindingStatus(ctx context.Context, obj *ClusterRoleBinding, opts ...client.UpdateOption) error { + return c.client.Status().Update(ctx, obj, opts...) +} + +func (c *clusterRoleBindingClient) PatchClusterRoleBindingStatus(ctx context.Context, obj *ClusterRoleBinding, patch client.Patch, opts ...client.PatchOption) error { + return c.client.Status().Patch(ctx, obj, patch, opts...) +}