Skip to content

Commit

Permalink
api define and generate
Browse files Browse the repository at this point in the history
  • Loading branch information
denkensk committed Sep 8, 2020
1 parent affecd7 commit df1762a
Show file tree
Hide file tree
Showing 16 changed files with 376 additions and 4 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions hack/update-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions pkg/apis/capacityscheduling/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package capacityscheduling

const (
GroupName = "capacityscheduling.sigs.k8s.io"
)
4 changes: 4 additions & 0 deletions pkg/apis/capacityscheduling/v1alpha1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// +k8s:deepcopy-gen=package
// +groupName=capacityscheduling.sigs.k8s.io

package v1alpha1
37 changes: 37 additions & 0 deletions pkg/apis/capacityscheduling/v1alpha1/register.go
Original file line number Diff line number Diff line change
@@ -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
}
59 changes: 59 additions & 0 deletions pkg/apis/capacityscheduling/v1alpha1/types.go
Original file line number Diff line number Diff line change
@@ -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"`
}
140 changes: 140 additions & 0 deletions pkg/apis/capacityscheduling/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/apis/config/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var (
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&CoschedulingArgs{},
&CapacitySchedulingArgs{},
)
return nil
}
Expand Down
9 changes: 9 additions & 0 deletions pkg/apis/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
13 changes: 10 additions & 3 deletions pkg/apis/config/v1beta1/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -33,3 +34,9 @@ func SetDefaults_CoschedulingArgs(obj *CoschedulingArgs) {
obj.PodGroupExpirationTimeSeconds = &defaultPodGroupExpirationTimeSeconds
}
}

func SetDefaults_CapacitySchedulingArgs(obj *CapacitySchedulingArgs) {
if obj.KubeConfigPath == "" {
obj.KubeConfigPath = defaultKubeConfigPath
}
}
1 change: 1 addition & 0 deletions pkg/apis/config/v1beta1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var (
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&CoschedulingArgs{},
&CapacitySchedulingArgs{},
)
return nil
}
Expand Down
10 changes: 10 additions & 0 deletions pkg/apis/config/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
35 changes: 34 additions & 1 deletion pkg/apis/config/v1beta1/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit df1762a

Please sign in to comment.