From a677dc2d37d58c67ed36899e70b4e2752ae87eb1 Mon Sep 17 00:00:00 2001 From: duanmengkk Date: Thu, 8 Feb 2024 14:40:03 +0800 Subject: [PATCH] Add VirtualCluster api Signed-off-by: duanmengkk --- deploy/crds/kosmos.io_virtualclusters.yaml | 77 ++++++++ .../kosmos/v1alpha1/virtualcluster_types.go | 62 +++++++ .../kosmos/v1alpha1/zz_generated.deepcopy.go | 89 ++++++++++ .../kosmos/v1alpha1/zz_generated.register.go | 1 + .../v1alpha1/fake/fake_kosmos_client.go | 4 + .../v1alpha1/fake/fake_virtualcluster.go | 117 ++++++++++++ .../kosmos/v1alpha1/generated_expansion.go | 2 + .../typed/kosmos/v1alpha1/kosmos_client.go | 5 + .../typed/kosmos/v1alpha1/virtualcluster.go | 168 ++++++++++++++++++ .../informers/externalversions/generic.go | 2 + .../kosmos/v1alpha1/interface.go | 7 + .../kosmos/v1alpha1/virtualcluster.go | 73 ++++++++ .../kosmos/v1alpha1/expansion_generated.go | 4 + .../listers/kosmos/v1alpha1/virtualcluster.go | 52 ++++++ pkg/generated/openapi/zz_generated.openapi.go | 145 +++++++++++++++ 15 files changed, 808 insertions(+) create mode 100644 deploy/crds/kosmos.io_virtualclusters.yaml create mode 100644 pkg/apis/kosmos/v1alpha1/virtualcluster_types.go create mode 100644 pkg/generated/clientset/versioned/typed/kosmos/v1alpha1/fake/fake_virtualcluster.go create mode 100644 pkg/generated/clientset/versioned/typed/kosmos/v1alpha1/virtualcluster.go create mode 100644 pkg/generated/informers/externalversions/kosmos/v1alpha1/virtualcluster.go create mode 100644 pkg/generated/listers/kosmos/v1alpha1/virtualcluster.go diff --git a/deploy/crds/kosmos.io_virtualclusters.yaml b/deploy/crds/kosmos.io_virtualclusters.yaml new file mode 100644 index 000000000..989caedc2 --- /dev/null +++ b/deploy/crds/kosmos.io_virtualclusters.yaml @@ -0,0 +1,77 @@ +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.11.0 + creationTimestamp: null + name: virtualclusters.kosmos.io +spec: + group: kosmos.io + names: + kind: VirtualCluster + listKind: VirtualClusterList + plural: virtualclusters + singular: virtualcluster + scope: Cluster + versions: + - name: v1alpha1 + schema: + openAPIV3Schema: + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + spec: + description: Spec is the specification for the behaviour of the VirtualCluster. + properties: + kubeconfig: + description: Kubeconfig is the kubeconfig of the virtual kubernetes's + control plane + type: string + promoteResources: + description: PromoteResources definites the resources for promote + to the kubernetes's control plane, the resources can be nodes or + just cpu,memory or gpu resources + properties: + nodes: + description: Nodes is the names of node to promote to the kubernetes's + control plane + items: + type: string + type: array + resources: + additionalProperties: + anyOf: + - type: integer + - type: string + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + description: Resources is the resources to promote to the kubernetes's + control plane + type: object + type: object + required: + - promoteResources + type: object + status: + description: Status describes the current status of a VirtualCluster. + properties: + phase: + description: Phase is the phase of kosmos-operator handling the VirtualCluster + type: string + type: object + required: + - spec + type: object + served: true + storage: true diff --git a/pkg/apis/kosmos/v1alpha1/virtualcluster_types.go b/pkg/apis/kosmos/v1alpha1/virtualcluster_types.go new file mode 100644 index 000000000..c73441dd5 --- /dev/null +++ b/pkg/apis/kosmos/v1alpha1/virtualcluster_types.go @@ -0,0 +1,62 @@ +package v1alpha1 + +import ( + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +type Phase string + +const ( + // Preparing means kubernetes control plane is preparing,and kubeconfig is not ready + Preparing Phase = "Preparing" + // Initialized means kubernetes control plane is ready,and kubeconfig is ready for use + Initialized Phase = "Initialized" + // Completed means kubernetes control plane is ready,kosmos is joined, and resource is promoted + Completed Phase = "Completed" +) + +// +genclient +// +genclient:nonNamespaced +// +kubebuilder:resource:scope="Cluster" +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +type VirtualCluster struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + // Spec is the specification for the behaviour of the VirtualCluster. + // +required + Spec VirtualClusterSpec `json:"spec"` + + // Status describes the current status of a VirtualCluster. + // +optional + Status VirtualClusterStatus `json:"status,omitempty"` +} + +type VirtualClusterSpec struct { + // Kubeconfig is the kubeconfig of the virtual kubernetes's control plane + // +optional + Kubeconfig string `json:"kubeconfig,omitempty"` + + // PromoteResources definites the resources for promote to the kubernetes's control plane, + // the resources can be nodes or just cpu,memory or gpu resources + // +required + PromoteResources PromoteResources `json:"promoteResources"` +} + +type PromoteResources struct { + // Nodes is the names of node to promote to the kubernetes's control plane + // +optional + Nodes []string `json:"nodes,omitempty"` + + // Resources is the resources to promote to the kubernetes's control plane + // +optional + Resources corev1.ResourceList `json:"resources,omitempty"` +} + +type VirtualClusterStatus struct { + // Phase is the phase of kosmos-operator handling the VirtualCluster + // +optional + Phase Phase `json:"phase,omitempty"` +} diff --git a/pkg/apis/kosmos/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/kosmos/v1alpha1/zz_generated.deepcopy.go index 2419c61f0..f3bd850b7 100644 --- a/pkg/apis/kosmos/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/kosmos/v1alpha1/zz_generated.deepcopy.go @@ -1102,6 +1102,34 @@ func (in *PodConvertPolicySpec) DeepCopy() *PodConvertPolicySpec { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PromoteResources) DeepCopyInto(out *PromoteResources) { + *out = *in + if in.Nodes != nil { + in, out := &in.Nodes, &out.Nodes + *out = make([]string, len(*in)) + copy(*out, *in) + } + if in.Resources != nil { + in, out := &in.Resources, &out.Resources + *out = make(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 PromoteResources. +func (in *PromoteResources) DeepCopy() *PromoteResources { + if in == nil { + return nil + } + out := new(PromoteResources) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Proxy) DeepCopyInto(out *Proxy) { *out = *in @@ -1266,6 +1294,67 @@ func (in *TopologySpreadConstraintsConverter) DeepCopy() *TopologySpreadConstrai return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *VirtualCluster) DeepCopyInto(out *VirtualCluster) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + out.Status = in.Status + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new VirtualCluster. +func (in *VirtualCluster) DeepCopy() *VirtualCluster { + if in == nil { + return nil + } + out := new(VirtualCluster) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *VirtualCluster) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *VirtualClusterSpec) DeepCopyInto(out *VirtualClusterSpec) { + *out = *in + in.PromoteResources.DeepCopyInto(&out.PromoteResources) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new VirtualClusterSpec. +func (in *VirtualClusterSpec) DeepCopy() *VirtualClusterSpec { + if in == nil { + return nil + } + out := new(VirtualClusterSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *VirtualClusterStatus) DeepCopyInto(out *VirtualClusterStatus) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new VirtualClusterStatus. +func (in *VirtualClusterStatus) DeepCopy() *VirtualClusterStatus { + if in == nil { + return nil + } + out := new(VirtualClusterStatus) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *VxlanCIDRs) DeepCopyInto(out *VxlanCIDRs) { *out = *in diff --git a/pkg/apis/kosmos/v1alpha1/zz_generated.register.go b/pkg/apis/kosmos/v1alpha1/zz_generated.register.go index d8a8d9128..e735373bd 100644 --- a/pkg/apis/kosmos/v1alpha1/zz_generated.register.go +++ b/pkg/apis/kosmos/v1alpha1/zz_generated.register.go @@ -59,6 +59,7 @@ func addKnownTypes(scheme *runtime.Scheme) error { &Proxy{}, &ShadowDaemonSet{}, &ShadowDaemonSetList{}, + &VirtualCluster{}, ) // AddToGroupVersion allows the serialization of client types like ListOptions. v1.AddToGroupVersion(scheme, SchemeGroupVersion) diff --git a/pkg/generated/clientset/versioned/typed/kosmos/v1alpha1/fake/fake_kosmos_client.go b/pkg/generated/clientset/versioned/typed/kosmos/v1alpha1/fake/fake_kosmos_client.go index c01d7fdce..76c57372d 100644 --- a/pkg/generated/clientset/versioned/typed/kosmos/v1alpha1/fake/fake_kosmos_client.go +++ b/pkg/generated/clientset/versioned/typed/kosmos/v1alpha1/fake/fake_kosmos_client.go @@ -44,6 +44,10 @@ func (c *FakeKosmosV1alpha1) ShadowDaemonSets(namespace string) v1alpha1.ShadowD return &FakeShadowDaemonSets{c, namespace} } +func (c *FakeKosmosV1alpha1) VirtualClusters() v1alpha1.VirtualClusterInterface { + return &FakeVirtualClusters{c} +} + // RESTClient returns a RESTClient that is used to communicate // with API server by this client implementation. func (c *FakeKosmosV1alpha1) RESTClient() rest.Interface { diff --git a/pkg/generated/clientset/versioned/typed/kosmos/v1alpha1/fake/fake_virtualcluster.go b/pkg/generated/clientset/versioned/typed/kosmos/v1alpha1/fake/fake_virtualcluster.go new file mode 100644 index 000000000..2416dc638 --- /dev/null +++ b/pkg/generated/clientset/versioned/typed/kosmos/v1alpha1/fake/fake_virtualcluster.go @@ -0,0 +1,117 @@ +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + "context" + + v1alpha1 "github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + schema "k8s.io/apimachinery/pkg/runtime/schema" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + testing "k8s.io/client-go/testing" +) + +// FakeVirtualClusters implements VirtualClusterInterface +type FakeVirtualClusters struct { + Fake *FakeKosmosV1alpha1 +} + +var virtualclustersResource = schema.GroupVersionResource{Group: "kosmos.io", Version: "v1alpha1", Resource: "virtualclusters"} + +var virtualclustersKind = schema.GroupVersionKind{Group: "kosmos.io", Version: "v1alpha1", Kind: "VirtualCluster"} + +// Get takes name of the virtualCluster, and returns the corresponding virtualCluster object, and an error if there is any. +func (c *FakeVirtualClusters) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.VirtualCluster, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootGetAction(virtualclustersResource, name), &v1alpha1.VirtualCluster{}) + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.VirtualCluster), err +} + +// List takes label and field selectors, and returns the list of VirtualClusters that match those selectors. +func (c *FakeVirtualClusters) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.VirtualClusterList, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootListAction(virtualclustersResource, virtualclustersKind, opts), &v1alpha1.VirtualClusterList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1alpha1.VirtualClusterList{ListMeta: obj.(*v1alpha1.VirtualClusterList).ListMeta} + for _, item := range obj.(*v1alpha1.VirtualClusterList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +// Watch returns a watch.Interface that watches the requested virtualClusters. +func (c *FakeVirtualClusters) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewRootWatchAction(virtualclustersResource, opts)) +} + +// Create takes the representation of a virtualCluster and creates it. Returns the server's representation of the virtualCluster, and an error, if there is any. +func (c *FakeVirtualClusters) Create(ctx context.Context, virtualCluster *v1alpha1.VirtualCluster, opts v1.CreateOptions) (result *v1alpha1.VirtualCluster, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootCreateAction(virtualclustersResource, virtualCluster), &v1alpha1.VirtualCluster{}) + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.VirtualCluster), err +} + +// Update takes the representation of a virtualCluster and updates it. Returns the server's representation of the virtualCluster, and an error, if there is any. +func (c *FakeVirtualClusters) Update(ctx context.Context, virtualCluster *v1alpha1.VirtualCluster, opts v1.UpdateOptions) (result *v1alpha1.VirtualCluster, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootUpdateAction(virtualclustersResource, virtualCluster), &v1alpha1.VirtualCluster{}) + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.VirtualCluster), err +} + +// UpdateStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). +func (c *FakeVirtualClusters) UpdateStatus(ctx context.Context, virtualCluster *v1alpha1.VirtualCluster, opts v1.UpdateOptions) (*v1alpha1.VirtualCluster, error) { + obj, err := c.Fake. + Invokes(testing.NewRootUpdateSubresourceAction(virtualclustersResource, "status", virtualCluster), &v1alpha1.VirtualCluster{}) + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.VirtualCluster), err +} + +// Delete takes name of the virtualCluster and deletes it. Returns an error if one occurs. +func (c *FakeVirtualClusters) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewRootDeleteActionWithOptions(virtualclustersResource, name, opts), &v1alpha1.VirtualCluster{}) + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeVirtualClusters) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + action := testing.NewRootDeleteCollectionAction(virtualclustersResource, listOpts) + + _, err := c.Fake.Invokes(action, &v1alpha1.VirtualClusterList{}) + return err +} + +// Patch applies the patch and returns the patched virtualCluster. +func (c *FakeVirtualClusters) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.VirtualCluster, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootPatchSubresourceAction(virtualclustersResource, name, pt, data, subresources...), &v1alpha1.VirtualCluster{}) + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.VirtualCluster), err +} diff --git a/pkg/generated/clientset/versioned/typed/kosmos/v1alpha1/generated_expansion.go b/pkg/generated/clientset/versioned/typed/kosmos/v1alpha1/generated_expansion.go index ed90e7f97..dc2c40d78 100644 --- a/pkg/generated/clientset/versioned/typed/kosmos/v1alpha1/generated_expansion.go +++ b/pkg/generated/clientset/versioned/typed/kosmos/v1alpha1/generated_expansion.go @@ -17,3 +17,5 @@ type NodeConfigExpansion interface{} type PodConvertPolicyExpansion interface{} type ShadowDaemonSetExpansion interface{} + +type VirtualClusterExpansion interface{} diff --git a/pkg/generated/clientset/versioned/typed/kosmos/v1alpha1/kosmos_client.go b/pkg/generated/clientset/versioned/typed/kosmos/v1alpha1/kosmos_client.go index 250b16f43..4e307a2d4 100644 --- a/pkg/generated/clientset/versioned/typed/kosmos/v1alpha1/kosmos_client.go +++ b/pkg/generated/clientset/versioned/typed/kosmos/v1alpha1/kosmos_client.go @@ -20,6 +20,7 @@ type KosmosV1alpha1Interface interface { NodeConfigsGetter PodConvertPoliciesGetter ShadowDaemonSetsGetter + VirtualClustersGetter } // KosmosV1alpha1Client is used to interact with features provided by the kosmos.io group. @@ -59,6 +60,10 @@ func (c *KosmosV1alpha1Client) ShadowDaemonSets(namespace string) ShadowDaemonSe return newShadowDaemonSets(c, namespace) } +func (c *KosmosV1alpha1Client) VirtualClusters() VirtualClusterInterface { + return newVirtualClusters(c) +} + // NewForConfig creates a new KosmosV1alpha1Client for the given config. // NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), // where httpClient was generated with rest.HTTPClientFor(c). diff --git a/pkg/generated/clientset/versioned/typed/kosmos/v1alpha1/virtualcluster.go b/pkg/generated/clientset/versioned/typed/kosmos/v1alpha1/virtualcluster.go new file mode 100644 index 000000000..011eceeae --- /dev/null +++ b/pkg/generated/clientset/versioned/typed/kosmos/v1alpha1/virtualcluster.go @@ -0,0 +1,168 @@ +// Code generated by client-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + "context" + "time" + + v1alpha1 "github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1" + scheme "github.com/kosmos.io/kosmos/pkg/generated/clientset/versioned/scheme" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + rest "k8s.io/client-go/rest" +) + +// VirtualClustersGetter has a method to return a VirtualClusterInterface. +// A group's client should implement this interface. +type VirtualClustersGetter interface { + VirtualClusters() VirtualClusterInterface +} + +// VirtualClusterInterface has methods to work with VirtualCluster resources. +type VirtualClusterInterface interface { + Create(ctx context.Context, virtualCluster *v1alpha1.VirtualCluster, opts v1.CreateOptions) (*v1alpha1.VirtualCluster, error) + Update(ctx context.Context, virtualCluster *v1alpha1.VirtualCluster, opts v1.UpdateOptions) (*v1alpha1.VirtualCluster, error) + UpdateStatus(ctx context.Context, virtualCluster *v1alpha1.VirtualCluster, opts v1.UpdateOptions) (*v1alpha1.VirtualCluster, error) + Delete(ctx context.Context, name string, opts v1.DeleteOptions) error + DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error + Get(ctx context.Context, name string, opts v1.GetOptions) (*v1alpha1.VirtualCluster, error) + List(ctx context.Context, opts v1.ListOptions) (*v1alpha1.VirtualClusterList, error) + Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) + Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.VirtualCluster, err error) + VirtualClusterExpansion +} + +// virtualClusters implements VirtualClusterInterface +type virtualClusters struct { + client rest.Interface +} + +// newVirtualClusters returns a VirtualClusters +func newVirtualClusters(c *KosmosV1alpha1Client) *virtualClusters { + return &virtualClusters{ + client: c.RESTClient(), + } +} + +// Get takes name of the virtualCluster, and returns the corresponding virtualCluster object, and an error if there is any. +func (c *virtualClusters) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.VirtualCluster, err error) { + result = &v1alpha1.VirtualCluster{} + err = c.client.Get(). + Resource("virtualclusters"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(ctx). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of VirtualClusters that match those selectors. +func (c *virtualClusters) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.VirtualClusterList, err error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + result = &v1alpha1.VirtualClusterList{} + err = c.client.Get(). + Resource("virtualclusters"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Do(ctx). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested virtualClusters. +func (c *virtualClusters) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + opts.Watch = true + return c.client.Get(). + Resource("virtualclusters"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Watch(ctx) +} + +// Create takes the representation of a virtualCluster and creates it. Returns the server's representation of the virtualCluster, and an error, if there is any. +func (c *virtualClusters) Create(ctx context.Context, virtualCluster *v1alpha1.VirtualCluster, opts v1.CreateOptions) (result *v1alpha1.VirtualCluster, err error) { + result = &v1alpha1.VirtualCluster{} + err = c.client.Post(). + Resource("virtualclusters"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(virtualCluster). + Do(ctx). + Into(result) + return +} + +// Update takes the representation of a virtualCluster and updates it. Returns the server's representation of the virtualCluster, and an error, if there is any. +func (c *virtualClusters) Update(ctx context.Context, virtualCluster *v1alpha1.VirtualCluster, opts v1.UpdateOptions) (result *v1alpha1.VirtualCluster, err error) { + result = &v1alpha1.VirtualCluster{} + err = c.client.Put(). + Resource("virtualclusters"). + Name(virtualCluster.Name). + VersionedParams(&opts, scheme.ParameterCodec). + Body(virtualCluster). + Do(ctx). + Into(result) + return +} + +// UpdateStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). +func (c *virtualClusters) UpdateStatus(ctx context.Context, virtualCluster *v1alpha1.VirtualCluster, opts v1.UpdateOptions) (result *v1alpha1.VirtualCluster, err error) { + result = &v1alpha1.VirtualCluster{} + err = c.client.Put(). + Resource("virtualclusters"). + Name(virtualCluster.Name). + SubResource("status"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(virtualCluster). + Do(ctx). + Into(result) + return +} + +// Delete takes name of the virtualCluster and deletes it. Returns an error if one occurs. +func (c *virtualClusters) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + return c.client.Delete(). + Resource("virtualclusters"). + Name(name). + Body(&opts). + Do(ctx). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *virtualClusters) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + var timeout time.Duration + if listOpts.TimeoutSeconds != nil { + timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second + } + return c.client.Delete(). + Resource("virtualclusters"). + VersionedParams(&listOpts, scheme.ParameterCodec). + Timeout(timeout). + Body(&opts). + Do(ctx). + Error() +} + +// Patch applies the patch and returns the patched virtualCluster. +func (c *virtualClusters) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.VirtualCluster, err error) { + result = &v1alpha1.VirtualCluster{} + err = c.client.Patch(pt). + Resource("virtualclusters"). + Name(name). + SubResource(subresources...). + VersionedParams(&opts, scheme.ParameterCodec). + Body(data). + Do(ctx). + Into(result) + return +} diff --git a/pkg/generated/informers/externalversions/generic.go b/pkg/generated/informers/externalversions/generic.go index 8b822beb5..c04ffcbdf 100644 --- a/pkg/generated/informers/externalversions/generic.go +++ b/pkg/generated/informers/externalversions/generic.go @@ -54,6 +54,8 @@ func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource return &genericInformer{resource: resource.GroupResource(), informer: f.Kosmos().V1alpha1().PodConvertPolicies().Informer()}, nil case v1alpha1.SchemeGroupVersion.WithResource("shadowdaemonsets"): return &genericInformer{resource: resource.GroupResource(), informer: f.Kosmos().V1alpha1().ShadowDaemonSets().Informer()}, nil + case v1alpha1.SchemeGroupVersion.WithResource("virtualclusters"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Kosmos().V1alpha1().VirtualClusters().Informer()}, nil // Group=multicluster.x-k8s.io, Version=v1alpha1 case apisv1alpha1.SchemeGroupVersion.WithResource("serviceexports"): diff --git a/pkg/generated/informers/externalversions/kosmos/v1alpha1/interface.go b/pkg/generated/informers/externalversions/kosmos/v1alpha1/interface.go index cf716ae3e..d1e0f80de 100644 --- a/pkg/generated/informers/externalversions/kosmos/v1alpha1/interface.go +++ b/pkg/generated/informers/externalversions/kosmos/v1alpha1/interface.go @@ -24,6 +24,8 @@ type Interface interface { PodConvertPolicies() PodConvertPolicyInformer // ShadowDaemonSets returns a ShadowDaemonSetInformer. ShadowDaemonSets() ShadowDaemonSetInformer + // VirtualClusters returns a VirtualClusterInformer. + VirtualClusters() VirtualClusterInformer } type version struct { @@ -76,3 +78,8 @@ func (v *version) PodConvertPolicies() PodConvertPolicyInformer { func (v *version) ShadowDaemonSets() ShadowDaemonSetInformer { return &shadowDaemonSetInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} } + +// VirtualClusters returns a VirtualClusterInformer. +func (v *version) VirtualClusters() VirtualClusterInformer { + return &virtualClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +} diff --git a/pkg/generated/informers/externalversions/kosmos/v1alpha1/virtualcluster.go b/pkg/generated/informers/externalversions/kosmos/v1alpha1/virtualcluster.go new file mode 100644 index 000000000..edd381d34 --- /dev/null +++ b/pkg/generated/informers/externalversions/kosmos/v1alpha1/virtualcluster.go @@ -0,0 +1,73 @@ +// Code generated by informer-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + "context" + time "time" + + kosmosv1alpha1 "github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1" + versioned "github.com/kosmos.io/kosmos/pkg/generated/clientset/versioned" + internalinterfaces "github.com/kosmos.io/kosmos/pkg/generated/informers/externalversions/internalinterfaces" + v1alpha1 "github.com/kosmos.io/kosmos/pkg/generated/listers/kosmos/v1alpha1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" +) + +// VirtualClusterInformer provides access to a shared informer and lister for +// VirtualClusters. +type VirtualClusterInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1alpha1.VirtualClusterLister +} + +type virtualClusterInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// NewVirtualClusterInformer constructs a new informer for VirtualCluster type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewVirtualClusterInformer(client versioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredVirtualClusterInformer(client, resyncPeriod, indexers, nil) +} + +// NewFilteredVirtualClusterInformer constructs a new informer for VirtualCluster type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFilteredVirtualClusterInformer(client versioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.KosmosV1alpha1().VirtualClusters().List(context.TODO(), options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.KosmosV1alpha1().VirtualClusters().Watch(context.TODO(), options) + }, + }, + &kosmosv1alpha1.VirtualCluster{}, + resyncPeriod, + indexers, + ) +} + +func (f *virtualClusterInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredVirtualClusterInformer(client, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *virtualClusterInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&kosmosv1alpha1.VirtualCluster{}, f.defaultInformer) +} + +func (f *virtualClusterInformer) Lister() v1alpha1.VirtualClusterLister { + return v1alpha1.NewVirtualClusterLister(f.Informer().GetIndexer()) +} diff --git a/pkg/generated/listers/kosmos/v1alpha1/expansion_generated.go b/pkg/generated/listers/kosmos/v1alpha1/expansion_generated.go index c565580ce..864ed3523 100644 --- a/pkg/generated/listers/kosmos/v1alpha1/expansion_generated.go +++ b/pkg/generated/listers/kosmos/v1alpha1/expansion_generated.go @@ -45,3 +45,7 @@ type ShadowDaemonSetListerExpansion interface{} // ShadowDaemonSetNamespaceListerExpansion allows custom methods to be added to // ShadowDaemonSetNamespaceLister. type ShadowDaemonSetNamespaceListerExpansion interface{} + +// VirtualClusterListerExpansion allows custom methods to be added to +// VirtualClusterLister. +type VirtualClusterListerExpansion interface{} diff --git a/pkg/generated/listers/kosmos/v1alpha1/virtualcluster.go b/pkg/generated/listers/kosmos/v1alpha1/virtualcluster.go new file mode 100644 index 000000000..d5aaf7902 --- /dev/null +++ b/pkg/generated/listers/kosmos/v1alpha1/virtualcluster.go @@ -0,0 +1,52 @@ +// Code generated by lister-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + v1alpha1 "github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1" + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" +) + +// VirtualClusterLister helps list VirtualClusters. +// All objects returned here must be treated as read-only. +type VirtualClusterLister interface { + // List lists all VirtualClusters in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1alpha1.VirtualCluster, err error) + // Get retrieves the VirtualCluster from the index for a given name. + // Objects returned here must be treated as read-only. + Get(name string) (*v1alpha1.VirtualCluster, error) + VirtualClusterListerExpansion +} + +// virtualClusterLister implements the VirtualClusterLister interface. +type virtualClusterLister struct { + indexer cache.Indexer +} + +// NewVirtualClusterLister returns a new VirtualClusterLister. +func NewVirtualClusterLister(indexer cache.Indexer) VirtualClusterLister { + return &virtualClusterLister{indexer: indexer} +} + +// List lists all VirtualClusters in the indexer. +func (s *virtualClusterLister) List(selector labels.Selector) (ret []*v1alpha1.VirtualCluster, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha1.VirtualCluster)) + }) + return ret, err +} + +// Get retrieves the VirtualCluster from the index for a given name. +func (s *virtualClusterLister) Get(name string) (*v1alpha1.VirtualCluster, error) { + obj, exists, err := s.indexer.GetByKey(name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1alpha1.Resource("virtualcluster"), name) + } + return obj.(*v1alpha1.VirtualCluster), nil +} diff --git a/pkg/generated/openapi/zz_generated.openapi.go b/pkg/generated/openapi/zz_generated.openapi.go index e1a676118..47a304cff 100644 --- a/pkg/generated/openapi/zz_generated.openapi.go +++ b/pkg/generated/openapi/zz_generated.openapi.go @@ -57,6 +57,7 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA "github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1.PodConvertPolicy": schema_pkg_apis_kosmos_v1alpha1_PodConvertPolicy(ref), "github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1.PodConvertPolicyList": schema_pkg_apis_kosmos_v1alpha1_PodConvertPolicyList(ref), "github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1.PodConvertPolicySpec": schema_pkg_apis_kosmos_v1alpha1_PodConvertPolicySpec(ref), + "github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1.PromoteResources": schema_pkg_apis_kosmos_v1alpha1_PromoteResources(ref), "github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1.Proxy": schema_pkg_apis_kosmos_v1alpha1_Proxy(ref), "github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1.Route": schema_pkg_apis_kosmos_v1alpha1_Route(ref), "github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1.SchedulerNameConverter": schema_pkg_apis_kosmos_v1alpha1_SchedulerNameConverter(ref), @@ -64,6 +65,9 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA "github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1.ShadowDaemonSetList": schema_pkg_apis_kosmos_v1alpha1_ShadowDaemonSetList(ref), "github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1.TolerationConverter": schema_pkg_apis_kosmos_v1alpha1_TolerationConverter(ref), "github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1.TopologySpreadConstraintsConverter": schema_pkg_apis_kosmos_v1alpha1_TopologySpreadConstraintsConverter(ref), + "github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1.VirtualCluster": schema_pkg_apis_kosmos_v1alpha1_VirtualCluster(ref), + "github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1.VirtualClusterSpec": schema_pkg_apis_kosmos_v1alpha1_VirtualClusterSpec(ref), + "github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1.VirtualClusterStatus": schema_pkg_apis_kosmos_v1alpha1_VirtualClusterStatus(ref), "github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1.VxlanCIDRs": schema_pkg_apis_kosmos_v1alpha1_VxlanCIDRs(ref), "k8s.io/apimachinery/pkg/apis/meta/v1.APIGroup": schema_pkg_apis_meta_v1_APIGroup(ref), "k8s.io/apimachinery/pkg/apis/meta/v1.APIGroupList": schema_pkg_apis_meta_v1_APIGroupList(ref), @@ -1984,6 +1988,50 @@ func schema_pkg_apis_kosmos_v1alpha1_PodConvertPolicySpec(ref common.ReferenceCa } } +func schema_pkg_apis_kosmos_v1alpha1_PromoteResources(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "nodes": { + SchemaProps: spec.SchemaProps{ + Description: "Nodes is the names of node to promote to the kubernetes's control plane", + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + }, + }, + }, + "resources": { + SchemaProps: spec.SchemaProps{ + Description: "Resources is the resources to promote to the kubernetes's control plane", + Type: []string{"object"}, + AdditionalProperties: &spec.SchemaOrBool{ + Allows: true, + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("k8s.io/apimachinery/pkg/api/resource.Quantity"), + }, + }, + }, + }, + }, + }, + }, + }, + Dependencies: []string{ + "k8s.io/apimachinery/pkg/api/resource.Quantity"}, + } +} + func schema_pkg_apis_kosmos_v1alpha1_Proxy(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ @@ -2243,6 +2291,103 @@ func schema_pkg_apis_kosmos_v1alpha1_TopologySpreadConstraintsConverter(ref comm } } +func schema_pkg_apis_kosmos_v1alpha1_VirtualCluster(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "kind": { + SchemaProps: spec.SchemaProps{ + Description: "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds", + Type: []string{"string"}, + Format: "", + }, + }, + "apiVersion": { + SchemaProps: spec.SchemaProps{ + Description: "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources", + Type: []string{"string"}, + Format: "", + }, + }, + "metadata": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"), + }, + }, + "spec": { + SchemaProps: spec.SchemaProps{ + Description: "Spec is the specification for the behaviour of the VirtualCluster.", + Default: map[string]interface{}{}, + Ref: ref("github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1.VirtualClusterSpec"), + }, + }, + "status": { + SchemaProps: spec.SchemaProps{ + Description: "Status describes the current status of a VirtualCluster.", + Default: map[string]interface{}{}, + Ref: ref("github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1.VirtualClusterStatus"), + }, + }, + }, + Required: []string{"spec"}, + }, + }, + Dependencies: []string{ + "github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1.VirtualClusterSpec", "github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1.VirtualClusterStatus", "k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"}, + } +} + +func schema_pkg_apis_kosmos_v1alpha1_VirtualClusterSpec(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "kubeconfig": { + SchemaProps: spec.SchemaProps{ + Description: "Kubeconfig is the kubeconfig of the virtual kubernetes's control plane", + Type: []string{"string"}, + Format: "", + }, + }, + "promoteResources": { + SchemaProps: spec.SchemaProps{ + Description: "PromoteResources definites the resources for promote to the kubernetes's control plane, the resources can be nodes or just cpu,memory or gpu resources", + Default: map[string]interface{}{}, + Ref: ref("github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1.PromoteResources"), + }, + }, + }, + Required: []string{"promoteResources"}, + }, + }, + Dependencies: []string{ + "github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1.PromoteResources"}, + } +} + +func schema_pkg_apis_kosmos_v1alpha1_VirtualClusterStatus(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "phase": { + SchemaProps: spec.SchemaProps{ + Description: "Phase is the phase of kosmos-operator handling the VirtualCluster", + Type: []string{"string"}, + Format: "", + }, + }, + }, + }, + }, + } +} + func schema_pkg_apis_kosmos_v1alpha1_VxlanCIDRs(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{