1
0
mirror of https://github.com/rancher/types.git synced 2025-09-02 13:45:51 +00:00

Fix backward CRD group name

This commit is contained in:
Darren Shepherd
2017-11-13 14:49:28 -07:00
parent 4ab7475968
commit 62e4fa6ac7
23 changed files with 19 additions and 18 deletions

View File

@@ -0,0 +1,20 @@
package schema
import (
"github.com/rancher/norman/types"
"github.com/rancher/types/apis/authorization.cattle.io/v1"
)
var (
Version = types.APIVersion{
Version: "v1",
Group: "authorization.cattle.io",
Path: "/v1-authz",
}
Schemas = types.NewSchemas().
MustImport(&Version, v1.Project{}).
MustImport(&Version, v1.RoleTemplate{}).
MustImport(&Version, v1.PodSecurityPolicyTemplate{}).
MustImport(&Version, v1.ProjectRoleBinding{})
)

View File

@@ -0,0 +1,41 @@
package v1
import (
extv1 "k8s.io/api/extensions/v1beta1"
rbacv1 "k8s.io/api/rbac/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
type Project struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
ClusterName string `json:"clusterName,omitempty"`
}
type RoleTemplate struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Rules []rbacv1.PolicyRule `json:"rules,omitempty"`
RoleTemplates []string `json:"roles,omitempty"`
}
type PodSecurityPolicyTemplate struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec extv1.PodSecurityPolicySpec `json:"spec,omitempty"`
}
type ProjectRoleBinding struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Subjects []rbacv1.Subject `json:"subjects,omitempty"`
ProjectName string `json:"projectRef,omitempty"`
RoleTemplateName string `json:"roleTemplateName,omitempty"`
}

View File

@@ -0,0 +1,268 @@
package v1
import (
rbac_v1 "k8s.io/api/rbac/v1"
runtime "k8s.io/apimachinery/pkg/runtime"
)
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *PodSecurityPolicyTemplate) DeepCopyInto(out *PodSecurityPolicyTemplate) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
in.Spec.DeepCopyInto(&out.Spec)
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PodSecurityPolicyTemplate.
func (in *PodSecurityPolicyTemplate) DeepCopy() *PodSecurityPolicyTemplate {
if in == nil {
return nil
}
out := new(PodSecurityPolicyTemplate)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *PodSecurityPolicyTemplate) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
} else {
return nil
}
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *PodSecurityPolicyTemplateList) DeepCopyInto(out *PodSecurityPolicyTemplateList) {
*out = *in
out.TypeMeta = in.TypeMeta
out.ListMeta = in.ListMeta
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]PodSecurityPolicyTemplate, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PodSecurityPolicyTemplateList.
func (in *PodSecurityPolicyTemplateList) DeepCopy() *PodSecurityPolicyTemplateList {
if in == nil {
return nil
}
out := new(PodSecurityPolicyTemplateList)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *PodSecurityPolicyTemplateList) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
} else {
return nil
}
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Project) DeepCopyInto(out *Project) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Project.
func (in *Project) DeepCopy() *Project {
if in == nil {
return nil
}
out := new(Project)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *Project) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
} else {
return nil
}
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ProjectList) DeepCopyInto(out *ProjectList) {
*out = *in
out.TypeMeta = in.TypeMeta
out.ListMeta = in.ListMeta
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]Project, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ProjectList.
func (in *ProjectList) DeepCopy() *ProjectList {
if in == nil {
return nil
}
out := new(ProjectList)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *ProjectList) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
} else {
return nil
}
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ProjectRoleBinding) DeepCopyInto(out *ProjectRoleBinding) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
if in.Subjects != nil {
in, out := &in.Subjects, &out.Subjects
*out = make([]rbac_v1.Subject, len(*in))
copy(*out, *in)
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ProjectRoleBinding.
func (in *ProjectRoleBinding) DeepCopy() *ProjectRoleBinding {
if in == nil {
return nil
}
out := new(ProjectRoleBinding)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *ProjectRoleBinding) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
} else {
return nil
}
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ProjectRoleBindingList) DeepCopyInto(out *ProjectRoleBindingList) {
*out = *in
out.TypeMeta = in.TypeMeta
out.ListMeta = in.ListMeta
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]ProjectRoleBinding, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ProjectRoleBindingList.
func (in *ProjectRoleBindingList) DeepCopy() *ProjectRoleBindingList {
if in == nil {
return nil
}
out := new(ProjectRoleBindingList)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *ProjectRoleBindingList) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
} else {
return nil
}
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *RoleTemplate) DeepCopyInto(out *RoleTemplate) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
if in.Rules != nil {
in, out := &in.Rules, &out.Rules
*out = make([]rbac_v1.PolicyRule, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
if in.RoleTemplates != nil {
in, out := &in.RoleTemplates, &out.RoleTemplates
*out = make([]string, len(*in))
copy(*out, *in)
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RoleTemplate.
func (in *RoleTemplate) DeepCopy() *RoleTemplate {
if in == nil {
return nil
}
out := new(RoleTemplate)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *RoleTemplate) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
} else {
return nil
}
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *RoleTemplateList) DeepCopyInto(out *RoleTemplateList) {
*out = *in
out.TypeMeta = in.TypeMeta
out.ListMeta = in.ListMeta
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]RoleTemplate, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RoleTemplateList.
func (in *RoleTemplateList) DeepCopy() *RoleTemplateList {
if in == nil {
return nil
}
out := new(RoleTemplateList)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *RoleTemplateList) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
} else {
return nil
}
}

View File

@@ -0,0 +1,105 @@
package v1
import (
"sync"
"github.com/rancher/norman/clientbase"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/rest"
)
type Interface interface {
RESTClient() rest.Interface
ProjectsGetter
RoleTemplatesGetter
PodSecurityPolicyTemplatesGetter
ProjectRoleBindingsGetter
}
type Client struct {
sync.Mutex
restClient rest.Interface
projectControllers map[string]ProjectController
roleTemplateControllers map[string]RoleTemplateController
podSecurityPolicyTemplateControllers map[string]PodSecurityPolicyTemplateController
projectRoleBindingControllers map[string]ProjectRoleBindingController
}
func NewForConfig(config rest.Config) (Interface, error) {
if config.NegotiatedSerializer == nil {
configConfig := dynamic.ContentConfig()
config.NegotiatedSerializer = configConfig.NegotiatedSerializer
}
restClient, err := rest.UnversionedRESTClientFor(&config)
if err != nil {
return nil, err
}
return &Client{
restClient: restClient,
projectControllers: map[string]ProjectController{},
roleTemplateControllers: map[string]RoleTemplateController{},
podSecurityPolicyTemplateControllers: map[string]PodSecurityPolicyTemplateController{},
projectRoleBindingControllers: map[string]ProjectRoleBindingController{},
}, nil
}
func (c *Client) RESTClient() rest.Interface {
return c.restClient
}
type ProjectsGetter interface {
Projects(namespace string) ProjectInterface
}
func (c *Client) Projects(namespace string) ProjectInterface {
objectClient := clientbase.NewObjectClient(namespace, c.restClient, &ProjectResource, ProjectGroupVersionKind, projectFactory{})
return &projectClient{
ns: namespace,
client: c,
objectClient: objectClient,
}
}
type RoleTemplatesGetter interface {
RoleTemplates(namespace string) RoleTemplateInterface
}
func (c *Client) RoleTemplates(namespace string) RoleTemplateInterface {
objectClient := clientbase.NewObjectClient(namespace, c.restClient, &RoleTemplateResource, RoleTemplateGroupVersionKind, roleTemplateFactory{})
return &roleTemplateClient{
ns: namespace,
client: c,
objectClient: objectClient,
}
}
type PodSecurityPolicyTemplatesGetter interface {
PodSecurityPolicyTemplates(namespace string) PodSecurityPolicyTemplateInterface
}
func (c *Client) PodSecurityPolicyTemplates(namespace string) PodSecurityPolicyTemplateInterface {
objectClient := clientbase.NewObjectClient(namespace, c.restClient, &PodSecurityPolicyTemplateResource, PodSecurityPolicyTemplateGroupVersionKind, podSecurityPolicyTemplateFactory{})
return &podSecurityPolicyTemplateClient{
ns: namespace,
client: c,
objectClient: objectClient,
}
}
type ProjectRoleBindingsGetter interface {
ProjectRoleBindings(namespace string) ProjectRoleBindingInterface
}
func (c *Client) ProjectRoleBindings(namespace string) ProjectRoleBindingInterface {
objectClient := clientbase.NewObjectClient(namespace, c.restClient, &ProjectRoleBindingResource, ProjectRoleBindingGroupVersionKind, projectRoleBindingFactory{})
return &projectRoleBindingClient{
ns: namespace,
client: c,
objectClient: objectClient,
}
}

View File

@@ -0,0 +1,141 @@
package v1
import (
"context"
"github.com/rancher/norman/clientbase"
"github.com/rancher/norman/controller"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/tools/cache"
)
var (
PodSecurityPolicyTemplateGroupVersionKind = schema.GroupVersionKind{
Version: "v1",
Group: "authorization.cattle.io",
Kind: "PodSecurityPolicyTemplate",
}
PodSecurityPolicyTemplateResource = metav1.APIResource{
Name: "podsecuritypolicytemplates",
SingularName: "podsecuritypolicytemplate",
Namespaced: false,
Kind: PodSecurityPolicyTemplateGroupVersionKind.Kind,
}
)
type PodSecurityPolicyTemplateList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []PodSecurityPolicyTemplate
}
type PodSecurityPolicyTemplateHandlerFunc func(key string, obj *PodSecurityPolicyTemplate) error
type PodSecurityPolicyTemplateController interface {
Informer() cache.SharedIndexInformer
AddHandler(handler PodSecurityPolicyTemplateHandlerFunc)
Enqueue(namespace, name string)
Start(threadiness int, ctx context.Context) error
}
type PodSecurityPolicyTemplateInterface interface {
Create(*PodSecurityPolicyTemplate) (*PodSecurityPolicyTemplate, error)
Get(name string, opts metav1.GetOptions) (*PodSecurityPolicyTemplate, error)
Update(*PodSecurityPolicyTemplate) (*PodSecurityPolicyTemplate, error)
Delete(name string, options *metav1.DeleteOptions) error
List(opts metav1.ListOptions) (*PodSecurityPolicyTemplateList, error)
Watch(opts metav1.ListOptions) (watch.Interface, error)
DeleteCollection(deleteOpts *metav1.DeleteOptions, listOpts metav1.ListOptions) error
Controller() PodSecurityPolicyTemplateController
}
type podSecurityPolicyTemplateController struct {
controller.GenericController
}
func (c *podSecurityPolicyTemplateController) AddHandler(handler PodSecurityPolicyTemplateHandlerFunc) {
c.GenericController.AddHandler(func(key string) error {
obj, exists, err := c.Informer().GetStore().GetByKey(key)
if err != nil {
return err
}
if !exists {
return handler(key, nil)
}
return handler(key, obj.(*PodSecurityPolicyTemplate))
})
}
type podSecurityPolicyTemplateFactory struct {
}
func (c podSecurityPolicyTemplateFactory) Object() runtime.Object {
return &PodSecurityPolicyTemplate{}
}
func (c podSecurityPolicyTemplateFactory) List() runtime.Object {
return &PodSecurityPolicyTemplateList{}
}
func (s *podSecurityPolicyTemplateClient) Controller() PodSecurityPolicyTemplateController {
s.client.Lock()
defer s.client.Unlock()
c, ok := s.client.podSecurityPolicyTemplateControllers[s.ns]
if ok {
return c
}
genericController := controller.NewGenericController(PodSecurityPolicyTemplateGroupVersionKind.Kind+"Controller",
s.objectClient)
c = &podSecurityPolicyTemplateController{
GenericController: genericController,
}
s.client.podSecurityPolicyTemplateControllers[s.ns] = c
return c
}
type podSecurityPolicyTemplateClient struct {
client *Client
ns string
objectClient *clientbase.ObjectClient
controller PodSecurityPolicyTemplateController
}
func (s *podSecurityPolicyTemplateClient) Create(o *PodSecurityPolicyTemplate) (*PodSecurityPolicyTemplate, error) {
obj, err := s.objectClient.Create(o)
return obj.(*PodSecurityPolicyTemplate), err
}
func (s *podSecurityPolicyTemplateClient) Get(name string, opts metav1.GetOptions) (*PodSecurityPolicyTemplate, error) {
obj, err := s.objectClient.Get(name, opts)
return obj.(*PodSecurityPolicyTemplate), err
}
func (s *podSecurityPolicyTemplateClient) Update(o *PodSecurityPolicyTemplate) (*PodSecurityPolicyTemplate, error) {
obj, err := s.objectClient.Update(o.Name, o)
return obj.(*PodSecurityPolicyTemplate), err
}
func (s *podSecurityPolicyTemplateClient) Delete(name string, options *metav1.DeleteOptions) error {
return s.objectClient.Delete(name, options)
}
func (s *podSecurityPolicyTemplateClient) List(opts metav1.ListOptions) (*PodSecurityPolicyTemplateList, error) {
obj, err := s.objectClient.List(opts)
return obj.(*PodSecurityPolicyTemplateList), err
}
func (s *podSecurityPolicyTemplateClient) Watch(opts metav1.ListOptions) (watch.Interface, error) {
return s.objectClient.Watch(opts)
}
func (s *podSecurityPolicyTemplateClient) DeleteCollection(deleteOpts *metav1.DeleteOptions, listOpts metav1.ListOptions) error {
return s.objectClient.DeleteCollection(deleteOpts, listOpts)
}

View File

@@ -0,0 +1,141 @@
package v1
import (
"context"
"github.com/rancher/norman/clientbase"
"github.com/rancher/norman/controller"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/tools/cache"
)
var (
ProjectGroupVersionKind = schema.GroupVersionKind{
Version: "v1",
Group: "authorization.cattle.io",
Kind: "Project",
}
ProjectResource = metav1.APIResource{
Name: "projects",
SingularName: "project",
Namespaced: false,
Kind: ProjectGroupVersionKind.Kind,
}
)
type ProjectList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Project
}
type ProjectHandlerFunc func(key string, obj *Project) error
type ProjectController interface {
Informer() cache.SharedIndexInformer
AddHandler(handler ProjectHandlerFunc)
Enqueue(namespace, name string)
Start(threadiness int, ctx context.Context) error
}
type ProjectInterface interface {
Create(*Project) (*Project, error)
Get(name string, opts metav1.GetOptions) (*Project, error)
Update(*Project) (*Project, error)
Delete(name string, options *metav1.DeleteOptions) error
List(opts metav1.ListOptions) (*ProjectList, error)
Watch(opts metav1.ListOptions) (watch.Interface, error)
DeleteCollection(deleteOpts *metav1.DeleteOptions, listOpts metav1.ListOptions) error
Controller() ProjectController
}
type projectController struct {
controller.GenericController
}
func (c *projectController) AddHandler(handler ProjectHandlerFunc) {
c.GenericController.AddHandler(func(key string) error {
obj, exists, err := c.Informer().GetStore().GetByKey(key)
if err != nil {
return err
}
if !exists {
return handler(key, nil)
}
return handler(key, obj.(*Project))
})
}
type projectFactory struct {
}
func (c projectFactory) Object() runtime.Object {
return &Project{}
}
func (c projectFactory) List() runtime.Object {
return &ProjectList{}
}
func (s *projectClient) Controller() ProjectController {
s.client.Lock()
defer s.client.Unlock()
c, ok := s.client.projectControllers[s.ns]
if ok {
return c
}
genericController := controller.NewGenericController(ProjectGroupVersionKind.Kind+"Controller",
s.objectClient)
c = &projectController{
GenericController: genericController,
}
s.client.projectControllers[s.ns] = c
return c
}
type projectClient struct {
client *Client
ns string
objectClient *clientbase.ObjectClient
controller ProjectController
}
func (s *projectClient) Create(o *Project) (*Project, error) {
obj, err := s.objectClient.Create(o)
return obj.(*Project), err
}
func (s *projectClient) Get(name string, opts metav1.GetOptions) (*Project, error) {
obj, err := s.objectClient.Get(name, opts)
return obj.(*Project), err
}
func (s *projectClient) Update(o *Project) (*Project, error) {
obj, err := s.objectClient.Update(o.Name, o)
return obj.(*Project), err
}
func (s *projectClient) Delete(name string, options *metav1.DeleteOptions) error {
return s.objectClient.Delete(name, options)
}
func (s *projectClient) List(opts metav1.ListOptions) (*ProjectList, error) {
obj, err := s.objectClient.List(opts)
return obj.(*ProjectList), err
}
func (s *projectClient) Watch(opts metav1.ListOptions) (watch.Interface, error) {
return s.objectClient.Watch(opts)
}
func (s *projectClient) DeleteCollection(deleteOpts *metav1.DeleteOptions, listOpts metav1.ListOptions) error {
return s.objectClient.DeleteCollection(deleteOpts, listOpts)
}

View File

@@ -0,0 +1,141 @@
package v1
import (
"context"
"github.com/rancher/norman/clientbase"
"github.com/rancher/norman/controller"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/tools/cache"
)
var (
ProjectRoleBindingGroupVersionKind = schema.GroupVersionKind{
Version: "v1",
Group: "authorization.cattle.io",
Kind: "ProjectRoleBinding",
}
ProjectRoleBindingResource = metav1.APIResource{
Name: "projectrolebindings",
SingularName: "projectrolebinding",
Namespaced: false,
Kind: ProjectRoleBindingGroupVersionKind.Kind,
}
)
type ProjectRoleBindingList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []ProjectRoleBinding
}
type ProjectRoleBindingHandlerFunc func(key string, obj *ProjectRoleBinding) error
type ProjectRoleBindingController interface {
Informer() cache.SharedIndexInformer
AddHandler(handler ProjectRoleBindingHandlerFunc)
Enqueue(namespace, name string)
Start(threadiness int, ctx context.Context) error
}
type ProjectRoleBindingInterface interface {
Create(*ProjectRoleBinding) (*ProjectRoleBinding, error)
Get(name string, opts metav1.GetOptions) (*ProjectRoleBinding, error)
Update(*ProjectRoleBinding) (*ProjectRoleBinding, error)
Delete(name string, options *metav1.DeleteOptions) error
List(opts metav1.ListOptions) (*ProjectRoleBindingList, error)
Watch(opts metav1.ListOptions) (watch.Interface, error)
DeleteCollection(deleteOpts *metav1.DeleteOptions, listOpts metav1.ListOptions) error
Controller() ProjectRoleBindingController
}
type projectRoleBindingController struct {
controller.GenericController
}
func (c *projectRoleBindingController) AddHandler(handler ProjectRoleBindingHandlerFunc) {
c.GenericController.AddHandler(func(key string) error {
obj, exists, err := c.Informer().GetStore().GetByKey(key)
if err != nil {
return err
}
if !exists {
return handler(key, nil)
}
return handler(key, obj.(*ProjectRoleBinding))
})
}
type projectRoleBindingFactory struct {
}
func (c projectRoleBindingFactory) Object() runtime.Object {
return &ProjectRoleBinding{}
}
func (c projectRoleBindingFactory) List() runtime.Object {
return &ProjectRoleBindingList{}
}
func (s *projectRoleBindingClient) Controller() ProjectRoleBindingController {
s.client.Lock()
defer s.client.Unlock()
c, ok := s.client.projectRoleBindingControllers[s.ns]
if ok {
return c
}
genericController := controller.NewGenericController(ProjectRoleBindingGroupVersionKind.Kind+"Controller",
s.objectClient)
c = &projectRoleBindingController{
GenericController: genericController,
}
s.client.projectRoleBindingControllers[s.ns] = c
return c
}
type projectRoleBindingClient struct {
client *Client
ns string
objectClient *clientbase.ObjectClient
controller ProjectRoleBindingController
}
func (s *projectRoleBindingClient) Create(o *ProjectRoleBinding) (*ProjectRoleBinding, error) {
obj, err := s.objectClient.Create(o)
return obj.(*ProjectRoleBinding), err
}
func (s *projectRoleBindingClient) Get(name string, opts metav1.GetOptions) (*ProjectRoleBinding, error) {
obj, err := s.objectClient.Get(name, opts)
return obj.(*ProjectRoleBinding), err
}
func (s *projectRoleBindingClient) Update(o *ProjectRoleBinding) (*ProjectRoleBinding, error) {
obj, err := s.objectClient.Update(o.Name, o)
return obj.(*ProjectRoleBinding), err
}
func (s *projectRoleBindingClient) Delete(name string, options *metav1.DeleteOptions) error {
return s.objectClient.Delete(name, options)
}
func (s *projectRoleBindingClient) List(opts metav1.ListOptions) (*ProjectRoleBindingList, error) {
obj, err := s.objectClient.List(opts)
return obj.(*ProjectRoleBindingList), err
}
func (s *projectRoleBindingClient) Watch(opts metav1.ListOptions) (watch.Interface, error) {
return s.objectClient.Watch(opts)
}
func (s *projectRoleBindingClient) DeleteCollection(deleteOpts *metav1.DeleteOptions, listOpts metav1.ListOptions) error {
return s.objectClient.DeleteCollection(deleteOpts, listOpts)
}

View File

@@ -0,0 +1,141 @@
package v1
import (
"context"
"github.com/rancher/norman/clientbase"
"github.com/rancher/norman/controller"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/tools/cache"
)
var (
RoleTemplateGroupVersionKind = schema.GroupVersionKind{
Version: "v1",
Group: "authorization.cattle.io",
Kind: "RoleTemplate",
}
RoleTemplateResource = metav1.APIResource{
Name: "roletemplates",
SingularName: "roletemplate",
Namespaced: false,
Kind: RoleTemplateGroupVersionKind.Kind,
}
)
type RoleTemplateList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []RoleTemplate
}
type RoleTemplateHandlerFunc func(key string, obj *RoleTemplate) error
type RoleTemplateController interface {
Informer() cache.SharedIndexInformer
AddHandler(handler RoleTemplateHandlerFunc)
Enqueue(namespace, name string)
Start(threadiness int, ctx context.Context) error
}
type RoleTemplateInterface interface {
Create(*RoleTemplate) (*RoleTemplate, error)
Get(name string, opts metav1.GetOptions) (*RoleTemplate, error)
Update(*RoleTemplate) (*RoleTemplate, error)
Delete(name string, options *metav1.DeleteOptions) error
List(opts metav1.ListOptions) (*RoleTemplateList, error)
Watch(opts metav1.ListOptions) (watch.Interface, error)
DeleteCollection(deleteOpts *metav1.DeleteOptions, listOpts metav1.ListOptions) error
Controller() RoleTemplateController
}
type roleTemplateController struct {
controller.GenericController
}
func (c *roleTemplateController) AddHandler(handler RoleTemplateHandlerFunc) {
c.GenericController.AddHandler(func(key string) error {
obj, exists, err := c.Informer().GetStore().GetByKey(key)
if err != nil {
return err
}
if !exists {
return handler(key, nil)
}
return handler(key, obj.(*RoleTemplate))
})
}
type roleTemplateFactory struct {
}
func (c roleTemplateFactory) Object() runtime.Object {
return &RoleTemplate{}
}
func (c roleTemplateFactory) List() runtime.Object {
return &RoleTemplateList{}
}
func (s *roleTemplateClient) Controller() RoleTemplateController {
s.client.Lock()
defer s.client.Unlock()
c, ok := s.client.roleTemplateControllers[s.ns]
if ok {
return c
}
genericController := controller.NewGenericController(RoleTemplateGroupVersionKind.Kind+"Controller",
s.objectClient)
c = &roleTemplateController{
GenericController: genericController,
}
s.client.roleTemplateControllers[s.ns] = c
return c
}
type roleTemplateClient struct {
client *Client
ns string
objectClient *clientbase.ObjectClient
controller RoleTemplateController
}
func (s *roleTemplateClient) Create(o *RoleTemplate) (*RoleTemplate, error) {
obj, err := s.objectClient.Create(o)
return obj.(*RoleTemplate), err
}
func (s *roleTemplateClient) Get(name string, opts metav1.GetOptions) (*RoleTemplate, error) {
obj, err := s.objectClient.Get(name, opts)
return obj.(*RoleTemplate), err
}
func (s *roleTemplateClient) Update(o *RoleTemplate) (*RoleTemplate, error) {
obj, err := s.objectClient.Update(o.Name, o)
return obj.(*RoleTemplate), err
}
func (s *roleTemplateClient) Delete(name string, options *metav1.DeleteOptions) error {
return s.objectClient.Delete(name, options)
}
func (s *roleTemplateClient) List(opts metav1.ListOptions) (*RoleTemplateList, error) {
obj, err := s.objectClient.List(opts)
return obj.(*RoleTemplateList), err
}
func (s *roleTemplateClient) Watch(opts metav1.ListOptions) (watch.Interface, error) {
return s.objectClient.Watch(opts)
}
func (s *roleTemplateClient) DeleteCollection(deleteOpts *metav1.DeleteOptions, listOpts metav1.ListOptions) error {
return s.objectClient.DeleteCollection(deleteOpts, listOpts)
}

View File

@@ -0,0 +1,25 @@
package schema
import (
"github.com/rancher/norman/types"
m "github.com/rancher/norman/types/mapping/mapper"
"github.com/rancher/types/apis/cluster.cattle.io/v1"
"github.com/rancher/types/commonmappers"
)
var (
Version = types.APIVersion{
Version: "v1",
Group: "cluster.cattle.io",
Path: "/v1-cluster",
SubContexts: map[string]bool{
"projects": true,
},
}
Schemas = commonmappers.Add(&Version, types.NewSchemas()).
AddMapperForType(&Version, v1.Cluster{}, m.NewObject(nil)).
AddMapperForType(&Version, v1.ClusterNode{}, m.NewObject(nil)).
MustImport(&Version, v1.Cluster{}).
MustImport(&Version, v1.ClusterNode{})
)

View File

@@ -0,0 +1,211 @@
package v1
import (
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
type ClusterConditionType string
const (
// ClusterConditionReady Cluster ready to serve API (healthy when true, unehalthy when false)
ClusterConditionReady = "Ready"
// ClusterConditionProvisioned Cluster is provisioned
ClusterConditionProvisioned = "Provisioned"
// ClusterConditionUpdating Cluster is being updating (upgrading, scaling up)
ClusterConditionUpdating = "Updating"
// ClusterConditionSufficientDisk true when all cluster nodes have sufficient disk
ClusterConditionSufficientDisk = "SufficientDisk"
// ClusterConditionSufficientMemory true when all cluster nodes have sufficient memory
ClusterConditionSufficientMemory = "SufficientMemory"
// ClusterConditionNoDiskPressure true when all cluster nodes have no disk pressure
ClusterConditionNoDiskPressure = "NoDiskPressure"
// More conditions can be added if unredlying controllers request it
)
type Cluster struct {
metav1.TypeMeta `json:",inline"`
// Standard objects metadata. More info:
// https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#metadata
metav1.ObjectMeta `json:"metadata,omitempty"`
// Specification of the desired behavior of the the cluster. More info:
// https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#spec-and-status
Spec ClusterSpec `json:"spec"`
// Most recent observed status of the cluster. More info:
// https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#spec-and-status
Status *ClusterStatus `json:"status"`
}
type ClusterSpec struct {
GKEConfig *GKEConfig `json:"gkeConfig,omitempty"`
AKSConfig *AKSConfig `json:"aksConfig,omitempty"`
RKEConfig *RKEConfig `json:"rkeConfig,omitempty"`
}
type ClusterStatus struct {
//Conditions represent the latest available observations of an object's current state:
//More info: https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#typical-status-properties
Conditions []ClusterCondition `json:"conditions,omitempty"`
//Component statuses will represent cluster's components (etcd/controller/scheduler) health
// https://kubernetes.io/docs/api-reference/v1.8/#componentstatus-v1-core
ComponentStatuses []ClusterComponentStatus
APIEndpoint string `json:"apiEndpoint,omitempty"`
ServiceAccountToken string `json:"serviceAccountToken,omitempty"`
CACert string `json:"caCert,omitempty"`
Capacity v1.ResourceList `json:"capacity,omitempty"`
Allocatable v1.ResourceList `json:"allocatable,omitempty"`
}
type ClusterComponentStatus struct {
Name string
Conditions []v1.ComponentCondition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,2,rep,name=conditions"`
}
type ClusterCondition struct {
// Type of cluster condition.
Type ClusterConditionType `json:"type"`
// Status of the condition, one of True, False, Unknown.
Status v1.ConditionStatus `json:"status"`
// The last time this condition was updated.
LastUpdateTime string `json:"lastUpdateTime,omitempty"`
// Last time the condition transitioned from one status to another.
LastTransitionTime string `json:"lastTransitionTime,omitempty"`
// The reason for the condition's last transition.
Reason string `json:"reason,omitempty"`
}
type GKEConfig struct {
// ProjectID is the ID of your project to use when creating a cluster
ProjectID string `json:"projectId,omitempty"`
// The zone to launch the cluster
Zone string `json:"zone,omitempty"`
// The IP address range of the container pods
ClusterIpv4Cidr string `json:"clusterIpv4Cidr,omitempty"`
// An optional description of this cluster
Description string `json:"description,omitempty"`
// The number of nodes to create in this cluster
InitialNodeCount int64 `json:"initialNodeCount,omitempty"`
// Size of the disk attached to each node
DiskSizeGb int64 `json:"diskSizeGb,omitempty"`
// The name of a Google Compute Engine
MachineType string `json:"machineType,omitempty"`
// the initial kubernetes version
InitialClusterVersion string `json:"initialClusterVersion,omitempty"`
// The map of Kubernetes labels (key/value pairs) to be applied
// to each node.
Labels map[string]string `json:"labels,omitempty"`
// The path to the credential file(key.json)
CredentialPath string `json:"credentialPath,omitempty"`
// Enable alpha feature
EnableAlphaFeature bool `json:"enableAlphaFeature,omitempty"`
// NodePool id
NodePoolID string `json:"nodePoolId,omitempty"`
// Update Config
UpdateConfig gkeUpdateConfig `json:"updateConfig,omitempty"`
}
type gkeUpdateConfig struct {
// the number of node
NodeCount int64 `json:"nodeCount,omitempty"`
// Master kubernetes version
MasterVersion string `json:"masterVersion,omitempty"`
// Node kubernetes version
NodeVersion string `json:"nodeVersion,omitempty"`
}
type AKSConfig struct {
//TBD
}
type RKEConfig struct {
// Kubernetes nodes
Hosts []RKEConfigHost `yaml:"hosts"`
// Kubernetes components
Services RKEConfigServices `yaml:"services"`
// Network plugin used in the kubernetes cluster (flannel, calico)
NetworkPlugin string `yaml:"network_plugin"`
// Authentication type used in the cluster (default: x509)
AuthType string `yaml:"auth_type"`
}
type RKEConfigHost struct {
// SSH IP address of the host
IP string `yaml:"ip"`
// Advertised address that will be used for components communication
AdvertiseAddress string `yaml:"advertise_address"`
// Host role in kubernetes cluster (controlplane, worker, or etcd)
Role []string `yaml:"role"`
// Hostname of the host
Hostname string `yaml:"hostname"`
// SSH usesr that will be used by RKE
User string `yaml:"user"`
// Docker socket on the host that will be used in tunneling
DockerSocket string `yaml:"docker_socket"`
}
type RKEConfigServices struct {
// Etcd Service
Etcd ETCDService `yaml:"etcd"`
// KubeAPI Service
KubeAPI KubeAPIService `yaml:"kube-api"`
// KubeController Service
KubeController KubeControllerService `yaml:"kube-controller"`
// Scheduler Service
Scheduler SchedulerService `yaml:"scheduler"`
// Kubelet Service
Kubelet KubeletService `yaml:"kubelet"`
// KubeProxy Service
Kubeproxy KubeproxyService `yaml:"kubeproxy"`
}
type ETCDService struct {
// Base service properties
baseService `yaml:",inline"`
}
type KubeAPIService struct {
// Base service properties
baseService `yaml:",inline"`
// Virtual IP range that will be used by Kubernetes services
ServiceClusterIPRange string `yaml:"service_cluster_ip_range"`
}
type KubeControllerService struct {
// Base service properties
baseService `yaml:",inline"`
// CIDR Range for Pods in cluster
ClusterCIDR string `yaml:"cluster_cidr"`
// Virtual IP range that will be used by Kubernetes services
ServiceClusterIPRange string `yaml:"service_cluster_ip_range"`
}
type KubeletService struct {
// Base service properties
baseService `yaml:",inline"`
// Domain of the cluster (default: "cluster.local")
ClusterDomain string `yaml:"cluster_domain"`
// The image whose network/ipc namespaces containers in each pod will use
InfraContainerImage string `yaml:"infra_container_image"`
// Cluster DNS service ip
ClusterDNSServer string `yaml:"cluster_dns_server"`
}
type KubeproxyService struct {
// Base service properties
baseService `yaml:",inline"`
}
type SchedulerService struct {
// Base service properties
baseService `yaml:",inline"`
}
type baseService struct {
// Docker image of the service
Image string `yaml:"image"`
}
type ClusterNode struct {
v1.Node
}

View File

@@ -0,0 +1,141 @@
package v1
import (
"context"
"github.com/rancher/norman/clientbase"
"github.com/rancher/norman/controller"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/tools/cache"
)
var (
ClusterGroupVersionKind = schema.GroupVersionKind{
Version: "v1",
Group: "cluster.cattle.io",
Kind: "Cluster",
}
ClusterResource = metav1.APIResource{
Name: "",
SingularName: "cluster",
Namespaced: false,
Kind: ClusterGroupVersionKind.Kind,
}
)
type ClusterList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Cluster
}
type ClusterHandlerFunc func(key string, obj *Cluster) error
type ClusterController interface {
Informer() cache.SharedIndexInformer
AddHandler(handler ClusterHandlerFunc)
Enqueue(namespace, name string)
Start(threadiness int, ctx context.Context) error
}
type ClusterInterface interface {
Create(*Cluster) (*Cluster, error)
Get(name string, opts metav1.GetOptions) (*Cluster, error)
Update(*Cluster) (*Cluster, error)
Delete(name string, options *metav1.DeleteOptions) error
List(opts metav1.ListOptions) (*ClusterList, error)
Watch(opts metav1.ListOptions) (watch.Interface, error)
DeleteCollection(deleteOpts *metav1.DeleteOptions, listOpts metav1.ListOptions) error
Controller() ClusterController
}
type clusterController struct {
controller.GenericController
}
func (c *clusterController) AddHandler(handler ClusterHandlerFunc) {
c.GenericController.AddHandler(func(key string) error {
obj, exists, err := c.Informer().GetStore().GetByKey(key)
if err != nil {
return err
}
if !exists {
return handler(key, nil)
}
return handler(key, obj.(*Cluster))
})
}
type clusterFactory struct {
}
func (c clusterFactory) Object() runtime.Object {
return &Cluster{}
}
func (c clusterFactory) List() runtime.Object {
return &ClusterList{}
}
func (s *clusterClient) Controller() ClusterController {
s.client.Lock()
defer s.client.Unlock()
c, ok := s.client.clusterControllers[s.ns]
if ok {
return c
}
genericController := controller.NewGenericController(ClusterGroupVersionKind.Kind+"Controller",
s.objectClient)
c = &clusterController{
GenericController: genericController,
}
s.client.clusterControllers[s.ns] = c
return c
}
type clusterClient struct {
client *Client
ns string
objectClient *clientbase.ObjectClient
controller ClusterController
}
func (s *clusterClient) Create(o *Cluster) (*Cluster, error) {
obj, err := s.objectClient.Create(o)
return obj.(*Cluster), err
}
func (s *clusterClient) Get(name string, opts metav1.GetOptions) (*Cluster, error) {
obj, err := s.objectClient.Get(name, opts)
return obj.(*Cluster), err
}
func (s *clusterClient) Update(o *Cluster) (*Cluster, error) {
obj, err := s.objectClient.Update(o.Name, o)
return obj.(*Cluster), err
}
func (s *clusterClient) Delete(name string, options *metav1.DeleteOptions) error {
return s.objectClient.Delete(name, options)
}
func (s *clusterClient) List(opts metav1.ListOptions) (*ClusterList, error) {
obj, err := s.objectClient.List(opts)
return obj.(*ClusterList), err
}
func (s *clusterClient) Watch(opts metav1.ListOptions) (watch.Interface, error) {
return s.objectClient.Watch(opts)
}
func (s *clusterClient) DeleteCollection(deleteOpts *metav1.DeleteOptions, listOpts metav1.ListOptions) error {
return s.objectClient.DeleteCollection(deleteOpts, listOpts)
}

View File

@@ -0,0 +1,141 @@
package v1
import (
"context"
"github.com/rancher/norman/clientbase"
"github.com/rancher/norman/controller"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/tools/cache"
)
var (
ClusterNodeGroupVersionKind = schema.GroupVersionKind{
Version: "v1",
Group: "cluster.cattle.io",
Kind: "ClusterNode",
}
ClusterNodeResource = metav1.APIResource{
Name: "",
SingularName: "clusternode",
Namespaced: false,
Kind: ClusterNodeGroupVersionKind.Kind,
}
)
type ClusterNodeList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []ClusterNode
}
type ClusterNodeHandlerFunc func(key string, obj *ClusterNode) error
type ClusterNodeController interface {
Informer() cache.SharedIndexInformer
AddHandler(handler ClusterNodeHandlerFunc)
Enqueue(namespace, name string)
Start(threadiness int, ctx context.Context) error
}
type ClusterNodeInterface interface {
Create(*ClusterNode) (*ClusterNode, error)
Get(name string, opts metav1.GetOptions) (*ClusterNode, error)
Update(*ClusterNode) (*ClusterNode, error)
Delete(name string, options *metav1.DeleteOptions) error
List(opts metav1.ListOptions) (*ClusterNodeList, error)
Watch(opts metav1.ListOptions) (watch.Interface, error)
DeleteCollection(deleteOpts *metav1.DeleteOptions, listOpts metav1.ListOptions) error
Controller() ClusterNodeController
}
type clusterNodeController struct {
controller.GenericController
}
func (c *clusterNodeController) AddHandler(handler ClusterNodeHandlerFunc) {
c.GenericController.AddHandler(func(key string) error {
obj, exists, err := c.Informer().GetStore().GetByKey(key)
if err != nil {
return err
}
if !exists {
return handler(key, nil)
}
return handler(key, obj.(*ClusterNode))
})
}
type clusterNodeFactory struct {
}
func (c clusterNodeFactory) Object() runtime.Object {
return &ClusterNode{}
}
func (c clusterNodeFactory) List() runtime.Object {
return &ClusterNodeList{}
}
func (s *clusterNodeClient) Controller() ClusterNodeController {
s.client.Lock()
defer s.client.Unlock()
c, ok := s.client.clusterNodeControllers[s.ns]
if ok {
return c
}
genericController := controller.NewGenericController(ClusterNodeGroupVersionKind.Kind+"Controller",
s.objectClient)
c = &clusterNodeController{
GenericController: genericController,
}
s.client.clusterNodeControllers[s.ns] = c
return c
}
type clusterNodeClient struct {
client *Client
ns string
objectClient *clientbase.ObjectClient
controller ClusterNodeController
}
func (s *clusterNodeClient) Create(o *ClusterNode) (*ClusterNode, error) {
obj, err := s.objectClient.Create(o)
return obj.(*ClusterNode), err
}
func (s *clusterNodeClient) Get(name string, opts metav1.GetOptions) (*ClusterNode, error) {
obj, err := s.objectClient.Get(name, opts)
return obj.(*ClusterNode), err
}
func (s *clusterNodeClient) Update(o *ClusterNode) (*ClusterNode, error) {
obj, err := s.objectClient.Update(o.Name, o)
return obj.(*ClusterNode), err
}
func (s *clusterNodeClient) Delete(name string, options *metav1.DeleteOptions) error {
return s.objectClient.Delete(name, options)
}
func (s *clusterNodeClient) List(opts metav1.ListOptions) (*ClusterNodeList, error) {
obj, err := s.objectClient.List(opts)
return obj.(*ClusterNodeList), err
}
func (s *clusterNodeClient) Watch(opts metav1.ListOptions) (watch.Interface, error) {
return s.objectClient.Watch(opts)
}
func (s *clusterNodeClient) DeleteCollection(deleteOpts *metav1.DeleteOptions, listOpts metav1.ListOptions) error {
return s.objectClient.DeleteCollection(deleteOpts, listOpts)
}

View File

@@ -0,0 +1,468 @@
package v1
import (
core_v1 "k8s.io/api/core/v1"
runtime "k8s.io/apimachinery/pkg/runtime"
)
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *AKSConfig) DeepCopyInto(out *AKSConfig) {
*out = *in
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AKSConfig.
func (in *AKSConfig) DeepCopy() *AKSConfig {
if in == nil {
return nil
}
out := new(AKSConfig)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Cluster) DeepCopyInto(out *Cluster) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
in.Spec.DeepCopyInto(&out.Spec)
if in.Status != nil {
in, out := &in.Status, &out.Status
if *in == nil {
*out = nil
} else {
*out = new(ClusterStatus)
(*in).DeepCopyInto(*out)
}
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Cluster.
func (in *Cluster) DeepCopy() *Cluster {
if in == nil {
return nil
}
out := new(Cluster)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *Cluster) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
} else {
return nil
}
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ClusterComponentStatus) DeepCopyInto(out *ClusterComponentStatus) {
*out = *in
if in.Conditions != nil {
in, out := &in.Conditions, &out.Conditions
*out = make([]core_v1.ComponentCondition, len(*in))
copy(*out, *in)
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterComponentStatus.
func (in *ClusterComponentStatus) DeepCopy() *ClusterComponentStatus {
if in == nil {
return nil
}
out := new(ClusterComponentStatus)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ClusterCondition) DeepCopyInto(out *ClusterCondition) {
*out = *in
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterCondition.
func (in *ClusterCondition) DeepCopy() *ClusterCondition {
if in == nil {
return nil
}
out := new(ClusterCondition)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ClusterList) DeepCopyInto(out *ClusterList) {
*out = *in
out.TypeMeta = in.TypeMeta
out.ListMeta = in.ListMeta
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]Cluster, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterList.
func (in *ClusterList) DeepCopy() *ClusterList {
if in == nil {
return nil
}
out := new(ClusterList)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *ClusterList) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
} else {
return nil
}
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ClusterNode) DeepCopyInto(out *ClusterNode) {
*out = *in
in.Node.DeepCopyInto(&out.Node)
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterNode.
func (in *ClusterNode) DeepCopy() *ClusterNode {
if in == nil {
return nil
}
out := new(ClusterNode)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *ClusterNode) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
} else {
return nil
}
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ClusterNodeList) DeepCopyInto(out *ClusterNodeList) {
*out = *in
out.TypeMeta = in.TypeMeta
out.ListMeta = in.ListMeta
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]ClusterNode, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterNodeList.
func (in *ClusterNodeList) DeepCopy() *ClusterNodeList {
if in == nil {
return nil
}
out := new(ClusterNodeList)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *ClusterNodeList) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
} else {
return nil
}
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ClusterSpec) DeepCopyInto(out *ClusterSpec) {
*out = *in
if in.GKEConfig != nil {
in, out := &in.GKEConfig, &out.GKEConfig
if *in == nil {
*out = nil
} else {
*out = new(GKEConfig)
(*in).DeepCopyInto(*out)
}
}
if in.AKSConfig != nil {
in, out := &in.AKSConfig, &out.AKSConfig
if *in == nil {
*out = nil
} else {
*out = new(AKSConfig)
**out = **in
}
}
if in.RKEConfig != nil {
in, out := &in.RKEConfig, &out.RKEConfig
if *in == nil {
*out = nil
} else {
*out = new(RKEConfig)
(*in).DeepCopyInto(*out)
}
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterSpec.
func (in *ClusterSpec) DeepCopy() *ClusterSpec {
if in == nil {
return nil
}
out := new(ClusterSpec)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ClusterStatus) DeepCopyInto(out *ClusterStatus) {
*out = *in
if in.Conditions != nil {
in, out := &in.Conditions, &out.Conditions
*out = make([]ClusterCondition, len(*in))
copy(*out, *in)
}
if in.ComponentStatuses != nil {
in, out := &in.ComponentStatuses, &out.ComponentStatuses
*out = make([]ClusterComponentStatus, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
if in.Capacity != nil {
in, out := &in.Capacity, &out.Capacity
*out = make(core_v1.ResourceList, len(*in))
for key, val := range *in {
(*out)[key] = val.DeepCopy()
}
}
if in.Allocatable != nil {
in, out := &in.Allocatable, &out.Allocatable
*out = make(core_v1.ResourceList, len(*in))
for key, val := range *in {
(*out)[key] = val.DeepCopy()
}
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterStatus.
func (in *ClusterStatus) DeepCopy() *ClusterStatus {
if in == nil {
return nil
}
out := new(ClusterStatus)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ETCDService) DeepCopyInto(out *ETCDService) {
*out = *in
out.baseService = in.baseService
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ETCDService.
func (in *ETCDService) DeepCopy() *ETCDService {
if in == nil {
return nil
}
out := new(ETCDService)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *GKEConfig) DeepCopyInto(out *GKEConfig) {
*out = *in
if in.Labels != nil {
in, out := &in.Labels, &out.Labels
*out = make(map[string]string, len(*in))
for key, val := range *in {
(*out)[key] = val
}
}
out.UpdateConfig = in.UpdateConfig
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GKEConfig.
func (in *GKEConfig) DeepCopy() *GKEConfig {
if in == nil {
return nil
}
out := new(GKEConfig)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *KubeAPIService) DeepCopyInto(out *KubeAPIService) {
*out = *in
out.baseService = in.baseService
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KubeAPIService.
func (in *KubeAPIService) DeepCopy() *KubeAPIService {
if in == nil {
return nil
}
out := new(KubeAPIService)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *KubeControllerService) DeepCopyInto(out *KubeControllerService) {
*out = *in
out.baseService = in.baseService
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KubeControllerService.
func (in *KubeControllerService) DeepCopy() *KubeControllerService {
if in == nil {
return nil
}
out := new(KubeControllerService)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *KubeletService) DeepCopyInto(out *KubeletService) {
*out = *in
out.baseService = in.baseService
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KubeletService.
func (in *KubeletService) DeepCopy() *KubeletService {
if in == nil {
return nil
}
out := new(KubeletService)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *KubeproxyService) DeepCopyInto(out *KubeproxyService) {
*out = *in
out.baseService = in.baseService
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KubeproxyService.
func (in *KubeproxyService) DeepCopy() *KubeproxyService {
if in == nil {
return nil
}
out := new(KubeproxyService)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *RKEConfig) DeepCopyInto(out *RKEConfig) {
*out = *in
if in.Hosts != nil {
in, out := &in.Hosts, &out.Hosts
*out = make([]RKEConfigHost, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
out.Services = in.Services
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RKEConfig.
func (in *RKEConfig) DeepCopy() *RKEConfig {
if in == nil {
return nil
}
out := new(RKEConfig)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *RKEConfigHost) DeepCopyInto(out *RKEConfigHost) {
*out = *in
if in.Role != nil {
in, out := &in.Role, &out.Role
*out = make([]string, len(*in))
copy(*out, *in)
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RKEConfigHost.
func (in *RKEConfigHost) DeepCopy() *RKEConfigHost {
if in == nil {
return nil
}
out := new(RKEConfigHost)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *RKEConfigServices) DeepCopyInto(out *RKEConfigServices) {
*out = *in
out.Etcd = in.Etcd
out.KubeAPI = in.KubeAPI
out.KubeController = in.KubeController
out.Scheduler = in.Scheduler
out.Kubelet = in.Kubelet
out.Kubeproxy = in.Kubeproxy
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RKEConfigServices.
func (in *RKEConfigServices) DeepCopy() *RKEConfigServices {
if in == nil {
return nil
}
out := new(RKEConfigServices)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *SchedulerService) DeepCopyInto(out *SchedulerService) {
*out = *in
out.baseService = in.baseService
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SchedulerService.
func (in *SchedulerService) DeepCopy() *SchedulerService {
if in == nil {
return nil
}
out := new(SchedulerService)
in.DeepCopyInto(out)
return out
}

View File

@@ -0,0 +1,73 @@
package v1
import (
"sync"
"github.com/rancher/norman/clientbase"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/rest"
)
type Interface interface {
RESTClient() rest.Interface
ClustersGetter
ClusterNodesGetter
}
type Client struct {
sync.Mutex
restClient rest.Interface
clusterControllers map[string]ClusterController
clusterNodeControllers map[string]ClusterNodeController
}
func NewForConfig(config rest.Config) (Interface, error) {
if config.NegotiatedSerializer == nil {
configConfig := dynamic.ContentConfig()
config.NegotiatedSerializer = configConfig.NegotiatedSerializer
}
restClient, err := rest.UnversionedRESTClientFor(&config)
if err != nil {
return nil, err
}
return &Client{
restClient: restClient,
clusterControllers: map[string]ClusterController{},
clusterNodeControllers: map[string]ClusterNodeController{},
}, nil
}
func (c *Client) RESTClient() rest.Interface {
return c.restClient
}
type ClustersGetter interface {
Clusters(namespace string) ClusterInterface
}
func (c *Client) Clusters(namespace string) ClusterInterface {
objectClient := clientbase.NewObjectClient(namespace, c.restClient, &ClusterResource, ClusterGroupVersionKind, clusterFactory{})
return &clusterClient{
ns: namespace,
client: c,
objectClient: objectClient,
}
}
type ClusterNodesGetter interface {
ClusterNodes(namespace string) ClusterNodeInterface
}
func (c *Client) ClusterNodes(namespace string) ClusterNodeInterface {
objectClient := clientbase.NewObjectClient(namespace, c.restClient, &ClusterNodeResource, ClusterNodeGroupVersionKind, clusterNodeFactory{})
return &clusterNodeClient{
ns: namespace,
client: c,
objectClient: objectClient,
}
}

View File

@@ -0,0 +1,190 @@
package mapper
import (
"github.com/rancher/norman/types"
"github.com/rancher/norman/types/convert"
"k8s.io/api/core/v1"
)
type EnvironmentMapper struct {
}
func (e EnvironmentMapper) FromInternal(data map[string]interface{}) {
env := []v1.EnvVar{}
envFrom := []v1.EnvFromSource{}
envMap := map[string]interface{}{}
envFromMaps := []map[string]interface{}{}
if err := convert.ToObj(data["env"], &env); err == nil {
for _, envVar := range env {
if envVar.ValueFrom == nil {
envMap[envVar.Name] = envVar.Value
continue
}
if envVar.ValueFrom.FieldRef != nil {
envFromMaps = append(envFromMaps, map[string]interface{}{
"source": "field",
"sourceName": envVar.ValueFrom.FieldRef.FieldPath,
"targetKey": envVar.Name,
})
}
if envVar.ValueFrom.ResourceFieldRef != nil {
envFromMaps = append(envFromMaps, map[string]interface{}{
"source": "resource",
"sourceName": envVar.ValueFrom.ResourceFieldRef.ContainerName,
"sourceKey": envVar.ValueFrom.ResourceFieldRef.Resource,
"divisor": envVar.ValueFrom.ResourceFieldRef.Divisor,
"targetKey": envVar.Name,
})
}
if envVar.ValueFrom.ConfigMapKeyRef != nil {
envFromMaps = append(envFromMaps, map[string]interface{}{
"source": "configMap",
"sourceName": envVar.ValueFrom.ConfigMapKeyRef.Name,
"sourceKey": envVar.ValueFrom.ConfigMapKeyRef.Key,
"optional": envVar.ValueFrom.ConfigMapKeyRef.Optional,
"targetKey": envVar.Name,
})
}
if envVar.ValueFrom.SecretKeyRef != nil {
envFromMaps = append(envFromMaps, map[string]interface{}{
"source": "secret",
"sourceName": envVar.ValueFrom.SecretKeyRef.Name,
"sourceKey": envVar.ValueFrom.SecretKeyRef.Key,
"optional": envVar.ValueFrom.SecretKeyRef.Optional,
"targetKey": envVar.Name,
})
}
}
}
if err := convert.ToObj(data["envFrom"], &envFrom); err == nil {
for _, envVar := range envFrom {
if envVar.SecretRef != nil {
envFromMaps = append(envFromMaps, map[string]interface{}{
"source": "secret",
"sourceName": envVar.SecretRef.Name,
"prefix": envVar.Prefix,
"optional": envVar.SecretRef.Optional,
})
}
if envVar.ConfigMapRef != nil {
envFromMaps = append(envFromMaps, map[string]interface{}{
"source": "configMap",
"sourceName": envVar.ConfigMapRef.Name,
"prefix": envVar.Prefix,
"optional": envVar.ConfigMapRef.Optional,
})
}
}
}
delete(data, "env")
delete(data, "envFrom")
if len(envMap) > 0 {
data["environment"] = envMap
}
if len(envFromMaps) > 0 {
data["environmentFrom"] = envFromMaps
}
}
func (e EnvironmentMapper) ToInternal(data map[string]interface{}) {
envVar := []map[string]interface{}{}
envVarFrom := []map[string]interface{}{}
for key, value := range convert.ToMapInterface(data["environment"]) {
envVar = append(envVar, map[string]interface{}{
"name": key,
"value": value,
})
}
for _, value := range convert.ToMapSlice(data["environmentFrom"]) {
source := convert.ToString(value["source"])
if source == "" {
continue
}
targetKey := convert.ToString(value["targetKey"])
if targetKey == "" {
switch source {
case "secret":
envVarFrom = append(envVarFrom, map[string]interface{}{
"prefix": value["prefix"],
"secretRef": map[string]interface{}{
"name": value["sourceName"],
"optional": value["optional"],
},
})
case "configMap":
envVarFrom = append(envVarFrom, map[string]interface{}{
"prefix": value["prefix"],
"configMapRef": map[string]interface{}{
"name": value["sourceName"],
"optional": value["optional"],
},
})
}
} else {
switch source {
case "field":
envVar = append(envVarFrom, map[string]interface{}{
"name": targetKey,
"valueFrom": map[string]interface{}{
"fieldRef": map[string]interface{}{
"fieldPath": value["sourceName"],
},
},
})
case "resource":
envVar = append(envVarFrom, map[string]interface{}{
"name": targetKey,
"valueFrom": map[string]interface{}{
"resourceFieldRef": map[string]interface{}{
"containerName": value["sourceName"],
"resource": value["sourceKey"],
"divisor": value["divisor"],
},
},
})
case "configMap":
envVar = append(envVarFrom, map[string]interface{}{
"name": targetKey,
"valueFrom": map[string]interface{}{
"configMapKeyRef": map[string]interface{}{
"name": value["sourceName"],
"key": value["sourceKey"],
"optional": value["optional"],
},
},
})
case "secret":
envVar = append(envVarFrom, map[string]interface{}{
"name": targetKey,
"valueFrom": map[string]interface{}{
"secretKeyRef": map[string]interface{}{
"name": value["sourceName"],
"key": value["sourceKey"],
"optional": value["optional"],
},
},
})
}
}
}
delete(data, "environment")
delete(data, "environmentFrom")
data["env"] = envVar
data["envFrom"] = envVarFrom
}
func (e EnvironmentMapper) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {
delete(schema.ResourceFields, "env")
delete(schema.ResourceFields, "envFrom")
return nil
}

View File

@@ -0,0 +1,45 @@
package mapper
import (
"github.com/rancher/norman/types"
"github.com/rancher/norman/types/convert"
)
type InitContainerMapper struct {
}
func (e InitContainerMapper) FromInternal(data map[string]interface{}) {
containers, _ := data["containers"].([]interface{})
for _, initContainer := range convert.ToMapSlice(data["initContainers"]) {
if initContainer == nil {
continue
}
initContainer["initContainer"] = true
containers = append(containers, initContainer)
}
data["containers"] = containers
}
func (e InitContainerMapper) ToInternal(data map[string]interface{}) {
newContainers := []interface{}{}
newInitContainers := []interface{}{}
for _, container := range convert.ToMapSlice(data["container"]) {
if convert.ToBool(container["initContainer"]) {
newInitContainers = append(newInitContainers, container)
} else {
newContainers = append(newContainers, container)
}
delete(container, "initContainer")
}
data["containers"] = newContainers
data["initContainers"] = newInitContainers
}
func (e InitContainerMapper) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {
delete(schema.ResourceFields, "initContainers")
return nil
}

View File

@@ -0,0 +1,44 @@
package mapper
import (
"github.com/rancher/norman/types"
"github.com/rancher/norman/types/convert"
)
var namespaceMapping = map[string]string{
"hostNetwork": "net",
"hostIPC": "ipc",
"hostPID": "pid",
}
type NamespaceMapper struct {
}
func (e NamespaceMapper) FromInternal(data map[string]interface{}) {
for name, friendlyName := range namespaceMapping {
value := convert.ToBool(data[name])
if value {
data[friendlyName] = "host"
}
delete(data, name)
}
}
func (e NamespaceMapper) ToInternal(data map[string]interface{}) {
for name, friendlyName := range namespaceMapping {
value := convert.ToString(data[friendlyName])
if value == "host" {
data[name] = true
} else {
data[name] = false
}
delete(data, friendlyName)
}
}
func (e NamespaceMapper) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {
delete(schema.ResourceFields, "hostNetwork")
delete(schema.ResourceFields, "hostPID")
delete(schema.ResourceFields, "hostIPC")
return nil
}

View File

@@ -0,0 +1,43 @@
package mapper
import (
"strings"
"github.com/rancher/norman/types"
m "github.com/rancher/norman/types/mapping/mapper"
)
type ResourceRequirementsMapper struct {
}
func (r ResourceRequirementsMapper) FromInternal(data map[string]interface{}) {
for key, value := range data {
mapValue, ok := value.(map[string]interface{})
if !ok {
continue
}
for subKey, subValue := range mapValue {
m.PutValue(data, subValue, subKey, strings.TrimSuffix(key, "s"))
}
delete(data, key)
}
}
func (r ResourceRequirementsMapper) ToInternal(data map[string]interface{}) {
for key, value := range data {
mapValue, ok := value.(map[string]interface{})
if !ok {
continue
}
for subKey, subValue := range mapValue {
m.PutValue(data, subValue, subKey, key+"s")
}
delete(data, key)
}
}
func (r ResourceRequirementsMapper) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {
return nil
}

View File

@@ -0,0 +1,261 @@
package mapper
import (
"fmt"
"sort"
"strings"
"regexp"
"github.com/rancher/norman/types"
"github.com/rancher/norman/types/convert"
"github.com/rancher/norman/types/mapping/mapper"
"k8s.io/api/core/v1"
)
var (
exprRegexp = regexp.MustCompile("^(.*)(=|!=|<|>| in | notin )(.*)$")
)
type SchedulingMapper struct {
}
func (s SchedulingMapper) FromInternal(data map[string]interface{}) {
defer func() {
delete(data, "nodeSelector")
delete(data, "affinity")
}()
requireAll := []string{}
for key, value := range convert.ToMapInterface(data["nodeSelector"]) {
if value == "" {
requireAll = append(requireAll, key)
} else {
requireAll = append(requireAll, fmt.Sprintf("%s = %s", key, value))
}
}
if len(requireAll) > 0 {
mapper.PutValue(data, requireAll, "scheduling", "node", "requireAll")
}
v, ok := data["affinity"]
if !ok || v == nil {
return
}
affinity := &v1.Affinity{}
if err := convert.ToObj(v, affinity); err != nil {
return
}
if affinity.NodeAffinity != nil {
s.nodeAffinity(data, affinity.NodeAffinity)
}
}
func (s SchedulingMapper) nodeAffinity(data map[string]interface{}, nodeAffinity *v1.NodeAffinity) {
requireAll := []string{}
requireAny := []string{}
preferred := []string{}
if nodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution != nil {
for _, term := range nodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms {
exprs := NodeSelectorTermToStrings(term)
if len(exprs) == 0 {
continue
}
if len(requireAny) > 0 {
// Once any is set all new terms go to any
requireAny = append(requireAny, strings.Join(exprs, " && "))
} else if len(requireAll) > 0 {
// If all is already set, we actually need to move everything to any
requireAny = append(requireAny, strings.Join(requireAll, " && "))
requireAny = append(requireAny, strings.Join(exprs, " && "))
requireAll = []string{}
} else {
// The first term is considered all
requireAll = exprs
}
}
}
if nodeAffinity.PreferredDuringSchedulingIgnoredDuringExecution != nil {
sortPreferred(nodeAffinity.PreferredDuringSchedulingIgnoredDuringExecution)
for _, term := range nodeAffinity.PreferredDuringSchedulingIgnoredDuringExecution {
exprs := NodeSelectorTermToStrings(term.Preference)
preferred = append(preferred, strings.Join(exprs, " && "))
}
}
if len(requireAll) > 0 {
mapper.PutValue(data, requireAll, "scheduling", "node", "requireAll")
}
if len(requireAny) > 0 {
mapper.PutValue(data, requireAny, "scheduling", "node", "requireAny")
}
if len(preferred) > 0 {
mapper.PutValue(data, requireAny, "scheduling", "node", "preferred")
}
}
func sortPreferred(terms []v1.PreferredSchedulingTerm) {
sort.Slice(terms, func(i, j int) bool {
return terms[i].Weight > terms[j].Weight
})
}
func NodeSelectorTermToStrings(term v1.NodeSelectorTerm) []string {
exprs := []string{}
for _, expr := range term.MatchExpressions {
nextExpr := ""
switch expr.Operator {
case v1.NodeSelectorOpIn:
if len(expr.Values) > 1 {
nextExpr = fmt.Sprintf("%s in (%s)", expr.Key, strings.Join(expr.Values, ", "))
} else if len(expr.Values) == 1 {
nextExpr = fmt.Sprintf("%s = %s", expr.Key, expr.Values[0])
}
case v1.NodeSelectorOpNotIn:
if len(expr.Values) > 1 {
nextExpr = fmt.Sprintf("%s notin (%s)", expr.Key, strings.Join(expr.Values, ", "))
} else if len(expr.Values) == 1 {
nextExpr = fmt.Sprintf("%s != %s", expr.Key, expr.Values[0])
}
case v1.NodeSelectorOpExists:
nextExpr = expr.Key
case v1.NodeSelectorOpDoesNotExist:
nextExpr = "!" + expr.Key
case v1.NodeSelectorOpGt:
if len(expr.Values) == 1 {
nextExpr = fmt.Sprintf("%s > %s", expr.Key, expr.Values[0])
}
case v1.NodeSelectorOpLt:
if len(expr.Values) == 1 {
nextExpr = fmt.Sprintf("%s < %s", expr.Key, expr.Values[0])
}
}
if nextExpr != "" {
exprs = append(exprs, nextExpr)
}
}
return exprs
}
func StringsToNodeSelectorTerm(exprs []string) []v1.NodeSelectorTerm {
result := []v1.NodeSelectorTerm{}
for _, inter := range exprs {
term := v1.NodeSelectorTerm{}
for _, expr := range strings.Split(inter, "&&") {
groups := exprRegexp.FindStringSubmatch(expr)
selectorRequirement := v1.NodeSelectorRequirement{}
if groups == nil {
if strings.HasPrefix(expr, "!") {
selectorRequirement.Key = strings.TrimSpace(expr[1:])
selectorRequirement.Operator = v1.NodeSelectorOpDoesNotExist
} else {
selectorRequirement.Key = strings.TrimSpace(expr)
selectorRequirement.Operator = v1.NodeSelectorOpExists
}
} else {
selectorRequirement.Key = strings.TrimSpace(groups[1])
selectorRequirement.Values = convert.ToValuesSlice(groups[3])
op := strings.TrimSpace(groups[2])
switch op {
case "=":
selectorRequirement.Operator = v1.NodeSelectorOpIn
case "!=":
selectorRequirement.Operator = v1.NodeSelectorOpNotIn
case "notin":
selectorRequirement.Operator = v1.NodeSelectorOpNotIn
case "in":
selectorRequirement.Operator = v1.NodeSelectorOpIn
case "<":
selectorRequirement.Operator = v1.NodeSelectorOpLt
case ">":
selectorRequirement.Operator = v1.NodeSelectorOpGt
}
}
term.MatchExpressions = append(term.MatchExpressions, selectorRequirement)
}
result = append(result, term)
}
return result
}
func (s SchedulingMapper) ToInternal(data map[string]interface{}) {
defer func() {
delete(data, "scheduling")
}()
nodeName := convert.ToString(mapper.GetValueN(data, "scheduling", "node", "name"))
if nodeName != "" {
data["nodeName"] = nodeName
}
requireAll := convert.ToStringSlice(mapper.GetValueN(data, "scheduling", "node", "requireAll"))
requireAny := convert.ToStringSlice(mapper.GetValueN(data, "scheduling", "node", "requireAny"))
preferred := convert.ToStringSlice(mapper.GetValueN(data, "scheduling", "node", "preferred"))
if len(requireAll) == 0 && len(requireAny) == 0 && len(preferred) == 0 {
return
}
nodeAffinity := v1.NodeAffinity{}
if len(requireAll) > 0 {
nodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution = &v1.NodeSelector{
NodeSelectorTerms: []v1.NodeSelectorTerm{
AggregateTerms(StringsToNodeSelectorTerm(requireAll)),
},
}
}
if len(requireAny) > 0 {
if nodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution == nil {
nodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution = &v1.NodeSelector{}
}
nodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms = StringsToNodeSelectorTerm(requireAny)
}
if len(preferred) > 0 {
count := int32(100)
for _, term := range StringsToNodeSelectorTerm(preferred) {
nodeAffinity.PreferredDuringSchedulingIgnoredDuringExecution = append(
nodeAffinity.PreferredDuringSchedulingIgnoredDuringExecution, v1.PreferredSchedulingTerm{
Weight: count,
Preference: term,
})
count--
}
}
affinity, _ := convert.EncodeToMap(&v1.Affinity{
NodeAffinity: &nodeAffinity,
})
data["affinity"] = affinity
}
func AggregateTerms(terms []v1.NodeSelectorTerm) v1.NodeSelectorTerm {
result := v1.NodeSelectorTerm{}
for _, term := range terms {
result.MatchExpressions = append(result.MatchExpressions, term.MatchExpressions...)
}
return result
}
func (s SchedulingMapper) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {
delete(schema.ResourceFields, "nodeSelector")
delete(schema.ResourceFields, "affinity")
return nil
}

View File

@@ -0,0 +1,119 @@
package schema
import (
"github.com/rancher/norman/types"
m "github.com/rancher/norman/types/mapping/mapper"
"github.com/rancher/types/apis/workload.cattle.io/v1/schema/mapper"
"github.com/rancher/types/commonmappers"
"k8s.io/api/core/v1"
)
var (
Version = types.APIVersion{
Version: "v1",
Group: "workload.cattle.io",
Path: "/v1-app",
SubContexts: map[string]bool{
"projects": true,
},
}
Schemas = commonmappers.Add(&Version, types.NewSchemas()).
AddMapperForType(&Version, v1.Capabilities{}, &types.TypeMapper{
Mappers: []types.Mapper{
m.Move{From: "add", To: "capAdd"},
m.Move{From: "drop", To: "capDrop"},
},
}).
AddMapperForType(&Version, v1.PodSecurityContext{}, &types.TypeMapper{
Mappers: []types.Mapper{
m.Drop{"seLinuxOptions"},
m.Move{From: "runAsUser", To: "uid"},
m.Move{From: "supplementalGroups", To: "gids"},
m.Move{From: "fsGroup", To: "fsgid"},
},
}).
AddMapperForType(&Version, v1.SecurityContext{}, &types.TypeMapper{
Mappers: []types.Mapper{
&m.Embed{Field: "capabilities"},
m.Drop{"seLinuxOptions"},
m.Move{From: "readOnlyRootFilesystem", To: "readOnly"},
m.Move{From: "runAsUser", To: "uid"},
},
}).
AddMapperForType(&Version, v1.Container{}, &types.TypeMapper{
Mappers: []types.Mapper{
m.Move{"command", "entrypoint"},
m.Move{"args", "command"},
m.Move{"livenessProbe", "healthcheck"},
m.Move{"readinessProbe", "readycheck"},
m.Move{"imagePullPolicy", "pullPolicy"},
mapper.EnvironmentMapper{},
&m.Embed{Field: "securityContext"},
&m.Embed{Field: "lifecycle"},
},
}).
AddMapperForType(&Version, v1.ContainerPort{}, &types.TypeMapper{
Mappers: []types.Mapper{
m.Drop{"name"},
},
}).
AddMapperForType(&Version, v1.VolumeMount{}, &types.TypeMapper{
Mappers: []types.Mapper{
m.Enum{
Field: "mountPropagation",
Values: map[string][]string{
"HostToContainer": []string{"rslave"},
"Bidirectional": []string{"rshared", "shared"},
},
},
},
}).
AddMapperForType(&Version, v1.Handler{}, handlerMapper).
AddMapperForType(&Version, v1.Probe{}, handlerMapper).
AddMapperForType(&Version, v1.PodSpec{}, &types.TypeMapper{
Mappers: []types.Mapper{
m.Move{From: "restartPolicy", To: "restart"},
m.Move{From: "imagePullSecrets", To: "pullSecrets"},
mapper.NamespaceMapper{},
mapper.InitContainerMapper{},
mapper.SchedulingMapper{},
&m.Embed{Field: "securityContext"},
&m.SliceToMap{
Field: "containers",
Key: "name",
},
&m.SliceToMap{
Field: "hostAliases",
Key: "ip",
},
},
}).
AddMapperForType(&Version, v1.Pod{}, &types.TypeMapper{
Mappers: []types.Mapper{
&m.Drop{"status"},
&m.Embed{Field: "metadata"},
&m.Embed{Field: "spec"},
},
}).
AddMapperForType(&Version, v1.ResourceRequirements{}, &types.TypeMapper{
Mappers: []types.Mapper{
mapper.ResourceRequirementsMapper{},
},
}).
MustImport(&Version, v1.Handler{}, handlerOverride{}).
MustImport(&Version, v1.Probe{}, handlerOverride{}).
MustImport(&Version, v1.Container{}, struct {
Scheduling *Scheduling
Resources *Resources
Environment map[string]string
EnvironmentFrom []EnvironmentFrom
InitContainer bool
}{}).
MustImport(&Version, v1.PodSpec{}, struct {
Net string
PID string
IPC string
}{}).
MustImport(&Version, v1.Pod{})
)

View File

@@ -0,0 +1,79 @@
package schema
import (
"github.com/rancher/norman/types"
m "github.com/rancher/norman/types/mapping/mapper"
)
var (
handlerMapper = &types.TypeMapper{
Mappers: []types.Mapper{
&m.UnionEmbed{
Fields: []m.UnionMapping{
{
FieldName: "exec",
CheckFields: []string{"command"},
},
{
FieldName: "tcpSocket",
CheckFields: []string{"tcp", "port"},
},
{
FieldName: "httpGet",
CheckFields: []string{"port"},
},
},
},
},
}
)
type handlerOverride struct {
TCP bool
}
type EnvironmentFrom struct {
Source string
SourceName string
SourceKey string
Prefix string
Optional bool
TargetKey string
}
type Resources struct {
CPU *ResourceRequest
Memory *ResourceRequest
NvidiaGPU *ResourceRequest
}
type ResourceRequest struct {
Request string
Limit string
}
type Scheduling struct {
AntiAffinity string
Node *NodeScheduling
Tolerate []string
Scheduler string
Priority *int64
PriorityClassName string
}
type NodeScheduling struct {
Name string
RequireAll []string
RequireAny []string
Preferred []string
}
type deployParams struct {
BatchSize int64
Scale int64
Global bool
Cron string
Job bool
Ordered bool
QuorumSize int64
}