Skip to content

Commit

Permalink
Merge pull request #7 from solo-io/kube-clients
Browse files Browse the repository at this point in the history
Kube clients
  • Loading branch information
EItanya authored Apr 21, 2020
2 parents 41c854d + 4f0187f commit a1a0c55
Show file tree
Hide file tree
Showing 16 changed files with 4,002 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ vendor*/
.idea/
.vscode/
# ignore packr files
*-packr.go
*-packr.g
5 changes: 5 additions & 0 deletions changelog/v0.0.2/dynamic-k8s-clients.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
changelog:
- type: NEW_FEATURE
description: Add basic dynamic kube clients.g
issueLink: https://github.com/solo-io/skv2/issues/6

4 changes: 2 additions & 2 deletions codegen/templates/code/types/clients.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}
}

Expand Down
4 changes: 2 additions & 2 deletions codegen/test/api/things.test.io/v1/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
144 changes: 144 additions & 0 deletions pkg/generated/generate.go
Original file line number Diff line number Diff line change
@@ -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")
}
144 changes: 144 additions & 0 deletions pkg/generated/kubernetes/admissionregistration.k8s.io/v1/clients.go
Original file line number Diff line number Diff line change
@@ -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...)
}
Loading

0 comments on commit a1a0c55

Please sign in to comment.