Skip to content

Commit

Permalink
add 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 Feb 13, 2025
1 parent efd900b commit a41d115
Show file tree
Hide file tree
Showing 31 changed files with 2,047 additions and 12 deletions.
2 changes: 2 additions & 0 deletions cmd/scheduler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/kosmos.io/kosmos/pkg/scheduler/lifted/plugins/leafnodedistribution"
"github.com/kosmos.io/kosmos/pkg/scheduler/lifted/plugins/leafnodetainttoleration"
"github.com/kosmos.io/kosmos/pkg/scheduler/lifted/plugins/leafnodevolumebinding"
"github.com/kosmos.io/kosmos/pkg/scheduler/lifted/plugins/leafnodeworkloadpolicy"
)

func main() {
Expand All @@ -23,6 +24,7 @@ func main() {
app.WithPlugin(leafnodedistribution.Name, leafnodedistribution.New),
app.WithPlugin(leafnodetainttoleration.Name, leafnodetainttoleration.New),
app.WithPlugin(leafnodevolumebinding.Name, leafnodevolumebinding.New),
app.WithPlugin(leafnodeworkloadpolicy.Name, leafnodeworkloadpolicy.New),
)

logs.InitLogs()
Expand Down
146 changes: 146 additions & 0 deletions deploy/crds/kosmos.io_workloadpolicies.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.11.0
creationTimestamp: null
name: workloadpolicies.kosmos.io
spec:
group: kosmos.io
names:
categories:
- kosmos-io
kind: WorkloadPolicy
listKind: WorkloadPolicyList
plural: workloadpolicies
shortNames:
- wlp
singular: workloadpolicy
scope: Namespaced
versions:
- additionalPrinterColumns:
- 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.
jsonPath: .metadata.creationTimestamp
name: AGE
type: date
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 represents the desired behavior of WorkloadPolicyPolicy.
properties:
allocationMethod:
default: Balance
description: 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.
enum:
- Fill
- Balance
type: string
allocationPolicy:
description: AllocationPolicy describes the allocation policy when
scheduling pods.
items:
description: AllocationPolicy set the topologyValue required replicas
properties:
name:
description: Name is the topology value
type: string
replicas:
description: Replicas is the desired the replicas for the topology
value
format: int32
type: integer
required:
- name
- replicas
type: object
type: array
allocationType:
default: Preferred
description: 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.
enum:
- Preferred
- Required
type: string
labelSelector:
description: LabelSelector is used to filter matching pods.
properties:
matchExpressions:
description: matchExpressions is a list of label selector requirements.
The requirements are ANDed.
items:
description: A label selector requirement is a selector that
contains values, a key, and an operator that relates the key
and values.
properties:
key:
description: key is the label key that the selector applies
to.
type: string
operator:
description: operator represents a key's relationship to
a set of values. Valid operators are In, NotIn, Exists
and DoesNotExist.
type: string
values:
description: values is an array of string values. If the
operator is In or NotIn, the values array must be non-empty.
If the operator is Exists or DoesNotExist, the values
array must be empty. This array is replaced during a strategic
merge patch.
items:
type: string
type: array
required:
- key
- operator
type: object
type: array
matchLabels:
additionalProperties:
type: string
description: matchLabels is a map of {key,value} pairs. A single
{key,value} in the matchLabels map is equivalent to an element
of matchExpressions, whose key field is "key", the operator
is "In", and the values array contains only "value". The requirements
are ANDed.
type: object
type: object
x-kubernetes-map-type: atomic
topologyKey:
description: TopologyKey is used when match node topologyKey
type: string
required:
- allocationPolicy
- labelSelector
- topologyKey
type: object
type: object
served: true
storage: true
subresources: {}
9 changes: 9 additions & 0 deletions deploy/scheduler/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ data:
- name: "VolumeBinding"
enabled:
- name: "LeafNodeVolumeBinding"
- name: "LeafNodeWorkloadPolicy"
filter:
disabled:
- name: "VolumeBinding"
Expand All @@ -88,14 +89,18 @@ data:
- name: "LeafNodeTaintToleration"
- name: "LeafNodeVolumeBinding"
- name: "LeafNodeDistribution"
- name: "LeafNodeWorkloadPolicy"
score:
disabled:
- name: "VolumeBinding"
enabled:
- name: "LeafNodeWorkloadPolicy"
reserve:
disabled:
- name: "VolumeBinding"
enabled:
- name: "LeafNodeVolumeBinding"
- name: "LeafNodeWorkloadPolicy"
preBind:
disabled:
- name: "VolumeBinding"
Expand All @@ -109,3 +114,7 @@ data:
args:
# kubeConfigPath: "REPLACE_ME_WITH_KUBE_CONFIG_PATH"
kubeConfigPath: "/etc/kubernetes/kubeconfig"
- name: LeafNodeWorkloadPolicy
args:
# kubeConfigPath: "REPLACE_ME_WITH_KUBE_CONFIG_PATH"
kubeConfigPath: "/etc/kubernetes/kubeconfig"
17 changes: 17 additions & 0 deletions examples/workloadpolicy-example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: kosmos.io/v1alpha1
kind: WorkloadPolicy
metadata:
name: workload-policy-test
namespace: workload-test
spec:
allocationPolicy:
- name: member
replicas: 1
- name: host
replicas: 3
labelSelector:
matchLabels:
app: clusterlink-floater-mix
allocationType: "Required"
allocationMethod: "Fill"
topologyKey: workload-test
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.

Loading

0 comments on commit a41d115

Please sign in to comment.