Skip to content

Commit

Permalink
define workload-policy scheduler plugin for k8s1.21
Browse files Browse the repository at this point in the history
Signed-off-by: qiuming520 <[email protected]>
  • Loading branch information
qiuming520 committed Jan 16, 2025
1 parent efd900b commit a93e6be
Show file tree
Hide file tree
Showing 21 changed files with 957 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/apis/config/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&LeafNodeVolumeBindingArgs{},
&LeafNodeDistributionArgs{},
&LeafNodeWorkloadArgs{},
)
return nil
}
Expand Down
10 changes: 10 additions & 0 deletions pkg/apis/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,13 @@ type LeafNodeDistributionArgs struct {
// KubeConfigPath is the path of kubeconfig.
KubeConfigPath string `json:"kubeConfigPath,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// LeafNodeWorkloadArgs defines the scheduling parameters for WorkloadPolicy plugin.
type LeafNodeWorkloadArgs struct {
metav1.TypeMeta `json:",inline"`

// KubeConfigPath is the path of kubeconfig.
KubeConfigPath string `json:"kubeConfigPath,omitempty"`
}
32 changes: 32 additions & 0 deletions pkg/apis/config/v1beta1/leafnodeworkloadpolicy_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
Copyright 2020 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.
*/

package v1beta1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +k8s:defaulter-gen=true

// LeafNodeWorkloadArgs defines the scheduling parameters for WorkloadPolicy plugin.
type LeafNodeWorkloadArgs struct {
metav1.TypeMeta `json:",inline"`

// KubeConfigPath is the path of kubeconfig.
KubeConfigPath *string `json:"kubeConfigPath,omitempty"`
}
1 change: 1 addition & 0 deletions pkg/apis/config/v1beta1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&LeafNodeVolumeBindingArgs{},
&LeafNodeDistributionArgs{},
&LeafNodeWorkloadArgs{},
)
return nil
}
Expand Down
35 changes: 35 additions & 0 deletions 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.

30 changes: 30 additions & 0 deletions pkg/apis/config/v1beta1/zz_generated.deepcopy.go

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

25 changes: 25 additions & 0 deletions pkg/apis/config/zz_generated.deepcopy.go

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

74 changes: 74 additions & 0 deletions pkg/apis/kosmos/v1alpha1/workloadpolicy_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// +genclient
// +kubebuilder:resource:shortName=wlp,categories={kosmos-io}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp",description="CreationTimestamp is a timestamp representing the server time when this object was created. It is not guaranteed to be set in happens-before order across separate operations. Clients may not set this value. It is represented in RFC3339 form and is in UTC."

type WorkloadPolicy struct {
metav1.TypeMeta `json:",inline"`

// Standard object's metadata.
// +optional
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`

// Spec represents the desired behavior of WorkloadPolicyPolicy.
// +required
Spec WorkloadPolicySpec `json:"spec,omitempty"`
}

// WorkloadPolicySpec represents the desired behavior of WorkloadPolicyPolicy.
type WorkloadPolicySpec struct {
// TopologyKey is used when match node topologyKey
// +required
TopologyKey string `json:"topologyKey"`

// LabelSelector is used to filter matching pods.
// +required
LabelSelector *metav1.LabelSelector `json:"labelSelector"`

// AllocationPolicy describes the allocation policy when scheduling pods.
// +required
AllocationPolicy []AllocationPolicy `json:"allocationPolicy"`

// AllocationType sets the scheduling constraint to schedule pods for a WorkloadPolicy.
// Valid options are Required or Preferred.
// Required means that the pods will get scheduled only on nodes that has a topologyKey=topologyValue label.
// Preferred means that the pods will prefer nodes that has a topologyKey=topologyValue label.
// +kubebuilder:default="Preferred"
// +kubebuilder:validation:Enum=Preferred;Required
// +optional
AllocationType string `json:"allocationType"`

// AllocationMethod sets the scheduling method to schedule pods for a WorkloadPolicy.
// Valid options are Fill or Balance.
// Fill, pods with the same label are scheduled in fill mode between nodes in the same topology.
// Balance, pods with the same label are scheduled in balance mode between nodes in the same topology.
// +kubebuilder:default="Balance"
// +kubebuilder:validation:Enum=Fill;Balance
// +optional
AllocationMethod string `json:"allocationMethod"`
}

// AllocationPolicy set the topologyValue required replicas
type AllocationPolicy struct {
// Name is the topology value
// +required
Name string `json:"name"`

// Replicas is the desired the replicas for the topology value
// +required
Replicas int32 `json:"replicas"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

type WorkloadPolicyList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`
Items []WorkloadPolicy `json:"items"`
}
102 changes: 102 additions & 0 deletions pkg/apis/kosmos/v1alpha1/zz_generated.deepcopy.go

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

2 changes: 2 additions & 0 deletions pkg/apis/kosmos/v1alpha1/zz_generated.register.go

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

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

Loading

0 comments on commit a93e6be

Please sign in to comment.