diff --git a/go.mod b/go.mod index 53e1aa5ceb..b8cb5ed172 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,7 @@ require ( github.com/spf13/pflag v1.0.5 k8s.io/api v0.19.0 k8s.io/apimachinery v0.19.0 + k8s.io/apiserver v0.19.0 k8s.io/client-go v0.19.0 k8s.io/code-generator v0.19.0 k8s.io/klog/v2 v2.2.0 diff --git a/hack/update-codegen.sh b/hack/update-codegen.sh index cf2ed2ca18..c121f1b1ff 100755 --- a/hack/update-codegen.sh +++ b/hack/update-codegen.sh @@ -27,4 +27,14 @@ bash "${CODEGEN_PKG}"/generate-internal-groups.sh \ sigs.k8s.io/scheduler-plugins/pkg/apis \ sigs.k8s.io/scheduler-plugins/pkg/apis \ "config:v1beta1" \ + --output-base "$(dirname "${BASH_SOURCE[0]}")/../../.." \ --go-header-file "${SCRIPT_ROOT}"/hack/boilerplate/boilerplate.generatego.txt + +bash "${CODEGEN_PKG}"/generate-groups.sh \ + all \ + sigs.k8s.io/scheduler-plugins/pkg/client \ + sigs.k8s.io/scheduler-plugins/pkg/apis \ + sigs.k8s.io/scheduler-plugins/pkg/apis \ + "capacityscheduling:v1alpha1" \ + --output-base "$(dirname "${BASH_SOURCE[0]}")/../../.." \ + --go-header-file "${SCRIPT_ROOT}"/hack/boilerplate/boilerplate.generatego.txt \ No newline at end of file diff --git a/pkg/apis/capacityscheduling/register.go b/pkg/apis/capacityscheduling/register.go new file mode 100644 index 0000000000..855ebaae41 --- /dev/null +++ b/pkg/apis/capacityscheduling/register.go @@ -0,0 +1,5 @@ +package capacityscheduling + +const ( + GroupName = "capacityscheduling.sigs.k8s.io" +) diff --git a/pkg/apis/capacityscheduling/v1alpha1/doc.go b/pkg/apis/capacityscheduling/v1alpha1/doc.go new file mode 100644 index 0000000000..07a51b74e0 --- /dev/null +++ b/pkg/apis/capacityscheduling/v1alpha1/doc.go @@ -0,0 +1,4 @@ +// +k8s:deepcopy-gen=package +// +groupName=capacityscheduling.sigs.k8s.io + +package v1alpha1 diff --git a/pkg/apis/capacityscheduling/v1alpha1/register.go b/pkg/apis/capacityscheduling/v1alpha1/register.go new file mode 100644 index 0000000000..5cdec1bf6b --- /dev/null +++ b/pkg/apis/capacityscheduling/v1alpha1/register.go @@ -0,0 +1,37 @@ +package v1alpha1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" + + "sigs.k8s.io/scheduler-plugins/pkg/apis/capacityscheduling" +) + +// SchemeGroupVersion is group version used to register these objects +var SchemeGroupVersion = schema.GroupVersion{Group: capacityscheduling.GroupName, Version: "v1alpha1"} + +// Kind takes an unqualified kind and returns back a Group qualified GroupKind +func Kind(kind string) schema.GroupKind { + return SchemeGroupVersion.WithKind(kind).GroupKind() +} + +// Resource takes an unqualified resource and returns a Group qualified GroupResource +func Resource(resource string) schema.GroupResource { + return SchemeGroupVersion.WithResource(resource).GroupResource() +} + +var ( + SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) + AddToScheme = SchemeBuilder.AddToScheme +) + +// Adds the list of known types to Scheme. +func addKnownTypes(scheme *runtime.Scheme) error { + scheme.AddKnownTypes(SchemeGroupVersion, + &ElasticQuota{}, + &ElasticQuotaList{}, + ) + metav1.AddToGroupVersion(scheme, SchemeGroupVersion) + return nil +} diff --git a/pkg/apis/capacityscheduling/v1alpha1/types.go b/pkg/apis/capacityscheduling/v1alpha1/types.go new file mode 100644 index 0000000000..7522652f46 --- /dev/null +++ b/pkg/apis/capacityscheduling/v1alpha1/types.go @@ -0,0 +1,59 @@ +package v1alpha1 + +import ( + "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// +genclient +// +genclient:noStatus +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// ElasticQuota sets elastic quota restrictions per namespace +type ElasticQuota struct { + metav1.TypeMeta `json:",inline"` + + // Standard object's metadata. + // +optional + metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` + + // ElasticQuotaSpec defines the Min and Max for Quota. + // +optional + Spec ElasticQuotaSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"` + + // ElasticQuotaStatus defines the observed use. + // +optional + Status ElasticQuotaStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"` +} + +// ElasticQuotaSpec defines the Min and Max for Quota. +type ElasticQuotaSpec struct { + // Min is the set of desired guaranteed limits for each named resource. + // +optional + Min v1.ResourceList `json:"min,omitempty" protobuf:"bytes,1,rep,name=min, casttype=ResourceList,castkey=ResourceName"` + + // Max is the set of desired max limits for each named resource. The usage of max is based on the resource configurations of + // successfully scheduled pods. + // +optional + Max v1.ResourceList `json:"max,omitempty" protobuf:"bytes,2,rep,name=max, casttype=ResourceList,castkey=ResourceName"` +} + +// ElasticQuotaStatus defines the observed use. +type ElasticQuotaStatus struct { + // Used is the current observed total usage of the resource in the namespace. + // +optional + Used v1.ResourceList `json:"used,omitempty" protobuf:"bytes,1,rep,name=used,casttype=ResourceList,castkey=ResourceName"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +// ElasticQuotaList is a list of ElasticQuota items. +type ElasticQuotaList struct { + metav1.TypeMeta `json:",inline"` + + // Standard list metadata. + // +optional + metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` + + // Items is a list of ElasticQuota objects. + Items []ElasticQuota `json:"items" protobuf:"bytes,2,rep,name=items"` +} diff --git a/pkg/apis/capacityscheduling/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/capacityscheduling/v1alpha1/zz_generated.deepcopy.go new file mode 100644 index 0000000000..2882ea857c --- /dev/null +++ b/pkg/apis/capacityscheduling/v1alpha1/zz_generated.deepcopy.go @@ -0,0 +1,140 @@ +// +build !ignore_autogenerated + +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by deepcopy-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + 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 *ElasticQuota) DeepCopyInto(out *ElasticQuota) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + in.Status.DeepCopyInto(&out.Status) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ElasticQuota. +func (in *ElasticQuota) DeepCopy() *ElasticQuota { + if in == nil { + return nil + } + out := new(ElasticQuota) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ElasticQuota) 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 *ElasticQuotaList) DeepCopyInto(out *ElasticQuotaList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]ElasticQuota, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ElasticQuotaList. +func (in *ElasticQuotaList) DeepCopy() *ElasticQuotaList { + if in == nil { + return nil + } + out := new(ElasticQuotaList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ElasticQuotaList) 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 *ElasticQuotaSpec) DeepCopyInto(out *ElasticQuotaSpec) { + *out = *in + if in.Min != nil { + in, out := &in.Min, &out.Min + *out = make(v1.ResourceList, len(*in)) + for key, val := range *in { + (*out)[key] = val.DeepCopy() + } + } + if in.Max != nil { + in, out := &in.Max, &out.Max + *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 ElasticQuotaSpec. +func (in *ElasticQuotaSpec) DeepCopy() *ElasticQuotaSpec { + if in == nil { + return nil + } + out := new(ElasticQuotaSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ElasticQuotaStatus) DeepCopyInto(out *ElasticQuotaStatus) { + *out = *in + if in.Used != nil { + in, out := &in.Used, &out.Used + *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 ElasticQuotaStatus. +func (in *ElasticQuotaStatus) DeepCopy() *ElasticQuotaStatus { + if in == nil { + return nil + } + out := new(ElasticQuotaStatus) + in.DeepCopyInto(out) + return out +} diff --git a/pkg/apis/config/register.go b/pkg/apis/config/register.go index c978d56618..41495ee7a7 100644 --- a/pkg/apis/config/register.go +++ b/pkg/apis/config/register.go @@ -38,6 +38,7 @@ var ( func addKnownTypes(scheme *runtime.Scheme) error { scheme.AddKnownTypes(SchemeGroupVersion, &CoschedulingArgs{}, + &CapacitySchedulingArgs{}, ) return nil } diff --git a/pkg/apis/config/types.go b/pkg/apis/config/types.go index 45dc7cd55b..078fb4ba73 100644 --- a/pkg/apis/config/types.go +++ b/pkg/apis/config/types.go @@ -33,3 +33,12 @@ type CoschedulingArgs struct { // the PodGroup will be deleted from PodGroupInfos. PodGroupExpirationTimeSeconds *int64 } + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +type CapacitySchedulingArgs struct { + metav1.TypeMeta + + // KubeConfigPath is the path of kubeconfig. + KubeConfigPath string +} diff --git a/pkg/apis/config/v1beta1/defaults.go b/pkg/apis/config/v1beta1/defaults.go index c5365d7b1d..fb89b0ceca 100644 --- a/pkg/apis/config/v1beta1/defaults.go +++ b/pkg/apis/config/v1beta1/defaults.go @@ -17,9 +17,10 @@ limitations under the License. package v1beta1 var ( - defaultPermitWaitingTimeSeconds int64 = 10 - defaultPodGroupGCIntervalSeconds int64 = 30 - defaultPodGroupExpirationTimeSeconds int64 = 600 + defaultPermitWaitingTimeSeconds int64 = 10 + defaultPodGroupGCIntervalSeconds int64 = 30 + defaultPodGroupExpirationTimeSeconds int64 = 600 + defaultKubeConfigPath string = "/etc/kubernetes/scheduler.conf" ) func SetDefaults_CoschedulingArgs(obj *CoschedulingArgs) { @@ -33,3 +34,9 @@ func SetDefaults_CoschedulingArgs(obj *CoschedulingArgs) { obj.PodGroupExpirationTimeSeconds = &defaultPodGroupExpirationTimeSeconds } } + +func SetDefaults_CapacitySchedulingArgs(obj *CapacitySchedulingArgs) { + if obj.KubeConfigPath == "" { + obj.KubeConfigPath = defaultKubeConfigPath + } +} diff --git a/pkg/apis/config/v1beta1/register.go b/pkg/apis/config/v1beta1/register.go index e636a2d946..acabc215df 100644 --- a/pkg/apis/config/v1beta1/register.go +++ b/pkg/apis/config/v1beta1/register.go @@ -38,6 +38,7 @@ var ( func addKnownTypes(scheme *runtime.Scheme) error { scheme.AddKnownTypes(SchemeGroupVersion, &CoschedulingArgs{}, + &CapacitySchedulingArgs{}, ) return nil } diff --git a/pkg/apis/config/v1beta1/types.go b/pkg/apis/config/v1beta1/types.go index 30ab4a6796..04161838f6 100644 --- a/pkg/apis/config/v1beta1/types.go +++ b/pkg/apis/config/v1beta1/types.go @@ -34,3 +34,13 @@ type CoschedulingArgs struct { // the PodGroup will be deleted from PodGroupInfos. PodGroupExpirationTimeSeconds *int64 `json:"podGroupExpirationTimeSeconds,omitempty"` } + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// CapacitySchedulingArgs defines the scheduling parameters for CapacityScheduling plugin. +type CapacitySchedulingArgs struct { + metav1.TypeMeta `json:",inline"` + + // KubeConfigPath is the path of kubeconfig. + KubeConfigPath string `json:"kubeconfigpath,omitempty"` +} diff --git a/pkg/apis/config/v1beta1/zz_generated.conversion.go b/pkg/apis/config/v1beta1/zz_generated.conversion.go index 4f74c86c00..f6c2d294b8 100644 --- a/pkg/apis/config/v1beta1/zz_generated.conversion.go +++ b/pkg/apis/config/v1beta1/zz_generated.conversion.go @@ -25,13 +25,26 @@ import ( conversion "k8s.io/apimachinery/pkg/conversion" runtime "k8s.io/apimachinery/pkg/runtime" - config "sigs.k8s.io/scheduler-plugins/pkg/apis/config" ) +func init() { + localSchemeBuilder.Register(RegisterConversions) +} + // RegisterConversions adds conversion functions to the given scheme. // Public to allow building arbitrary schemes. func RegisterConversions(s *runtime.Scheme) error { + if err := s.AddGeneratedConversionFunc((*CapacitySchedulingArgs)(nil), (*config.CapacitySchedulingArgs)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta1_CapacitySchedulingArgs_To_config_CapacitySchedulingArgs(a.(*CapacitySchedulingArgs), b.(*config.CapacitySchedulingArgs), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*config.CapacitySchedulingArgs)(nil), (*CapacitySchedulingArgs)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_config_CapacitySchedulingArgs_To_v1beta1_CapacitySchedulingArgs(a.(*config.CapacitySchedulingArgs), b.(*CapacitySchedulingArgs), scope) + }); err != nil { + return err + } if err := s.AddGeneratedConversionFunc((*CoschedulingArgs)(nil), (*config.CoschedulingArgs)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1beta1_CoschedulingArgs_To_config_CoschedulingArgs(a.(*CoschedulingArgs), b.(*config.CoschedulingArgs), scope) }); err != nil { @@ -45,6 +58,26 @@ func RegisterConversions(s *runtime.Scheme) error { return nil } +func autoConvert_v1beta1_CapacitySchedulingArgs_To_config_CapacitySchedulingArgs(in *CapacitySchedulingArgs, out *config.CapacitySchedulingArgs, s conversion.Scope) error { + out.KubeConfigPath = in.KubeConfigPath + return nil +} + +// Convert_v1beta1_CapacitySchedulingArgs_To_config_CapacitySchedulingArgs is an autogenerated conversion function. +func Convert_v1beta1_CapacitySchedulingArgs_To_config_CapacitySchedulingArgs(in *CapacitySchedulingArgs, out *config.CapacitySchedulingArgs, s conversion.Scope) error { + return autoConvert_v1beta1_CapacitySchedulingArgs_To_config_CapacitySchedulingArgs(in, out, s) +} + +func autoConvert_config_CapacitySchedulingArgs_To_v1beta1_CapacitySchedulingArgs(in *config.CapacitySchedulingArgs, out *CapacitySchedulingArgs, s conversion.Scope) error { + out.KubeConfigPath = in.KubeConfigPath + return nil +} + +// Convert_config_CapacitySchedulingArgs_To_v1beta1_CapacitySchedulingArgs is an autogenerated conversion function. +func Convert_config_CapacitySchedulingArgs_To_v1beta1_CapacitySchedulingArgs(in *config.CapacitySchedulingArgs, out *CapacitySchedulingArgs, s conversion.Scope) error { + return autoConvert_config_CapacitySchedulingArgs_To_v1beta1_CapacitySchedulingArgs(in, out, s) +} + func autoConvert_v1beta1_CoschedulingArgs_To_config_CoschedulingArgs(in *CoschedulingArgs, out *config.CoschedulingArgs, s conversion.Scope) error { out.PermitWaitingTimeSeconds = (*int64)(unsafe.Pointer(in.PermitWaitingTimeSeconds)) out.PodGroupGCIntervalSeconds = (*int64)(unsafe.Pointer(in.PodGroupGCIntervalSeconds)) diff --git a/pkg/apis/config/v1beta1/zz_generated.deepcopy.go b/pkg/apis/config/v1beta1/zz_generated.deepcopy.go index 999e0ea18d..612180fbac 100644 --- a/pkg/apis/config/v1beta1/zz_generated.deepcopy.go +++ b/pkg/apis/config/v1beta1/zz_generated.deepcopy.go @@ -24,6 +24,31 @@ import ( 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 *CapacitySchedulingArgs) DeepCopyInto(out *CapacitySchedulingArgs) { + *out = *in + out.TypeMeta = in.TypeMeta + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CapacitySchedulingArgs. +func (in *CapacitySchedulingArgs) DeepCopy() *CapacitySchedulingArgs { + if in == nil { + return nil + } + out := new(CapacitySchedulingArgs) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *CapacitySchedulingArgs) 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 *CoschedulingArgs) DeepCopyInto(out *CoschedulingArgs) { *out = *in diff --git a/pkg/apis/config/v1beta1/zz_generated.defaults.go b/pkg/apis/config/v1beta1/zz_generated.defaults.go index 65a56742d7..5e07d24db4 100644 --- a/pkg/apis/config/v1beta1/zz_generated.defaults.go +++ b/pkg/apis/config/v1beta1/zz_generated.defaults.go @@ -28,10 +28,15 @@ import ( // Public to allow building arbitrary schemes. // All generated defaulters are covering - they call all nested defaulters. func RegisterDefaults(scheme *runtime.Scheme) error { + scheme.AddTypeDefaultingFunc(&CapacitySchedulingArgs{}, func(obj interface{}) { SetObjectDefaults_CapacitySchedulingArgs(obj.(*CapacitySchedulingArgs)) }) scheme.AddTypeDefaultingFunc(&CoschedulingArgs{}, func(obj interface{}) { SetObjectDefaults_CoschedulingArgs(obj.(*CoschedulingArgs)) }) return nil } +func SetObjectDefaults_CapacitySchedulingArgs(in *CapacitySchedulingArgs) { + SetDefaults_CapacitySchedulingArgs(in) +} + func SetObjectDefaults_CoschedulingArgs(in *CoschedulingArgs) { SetDefaults_CoschedulingArgs(in) } diff --git a/pkg/apis/config/zz_generated.deepcopy.go b/pkg/apis/config/zz_generated.deepcopy.go index 9f1f3a7931..82521ebca8 100644 --- a/pkg/apis/config/zz_generated.deepcopy.go +++ b/pkg/apis/config/zz_generated.deepcopy.go @@ -24,6 +24,31 @@ import ( 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 *CapacitySchedulingArgs) DeepCopyInto(out *CapacitySchedulingArgs) { + *out = *in + out.TypeMeta = in.TypeMeta + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CapacitySchedulingArgs. +func (in *CapacitySchedulingArgs) DeepCopy() *CapacitySchedulingArgs { + if in == nil { + return nil + } + out := new(CapacitySchedulingArgs) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *CapacitySchedulingArgs) 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 *CoschedulingArgs) DeepCopyInto(out *CoschedulingArgs) { *out = *in