Skip to content

Commit

Permalink
koord-descheduler: implement descheduling configuration (#422)
Browse files Browse the repository at this point in the history
Signed-off-by: Joseph <joseph.t.lee@outlook.com>
  • Loading branch information
eahydra committed Aug 1, 2022
1 parent b7b70b0 commit 78afa0a
Show file tree
Hide file tree
Showing 22 changed files with 2,299 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .licenseignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
vendor
pkg/descheduler
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ require (
k8s.io/kubernetes v1.22.6
k8s.io/utils v0.0.0-20210819203725-bdf08cb9a70a
sigs.k8s.io/controller-runtime v0.10.3
sigs.k8s.io/yaml v1.2.0
)

require (
Expand Down Expand Up @@ -140,7 +141,6 @@ require (
k8s.io/mount-utils v0.22.6 // indirect
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.27 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
)

replace (
Expand Down
9 changes: 9 additions & 0 deletions hack/update-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ ${SCRIPT_ROOT}/hack/generate-internal-groups.sh \
--output-base "${TEMP_DIR}" \
--go-header-file hack/boilerplate/boilerplate.go.txt

${SCRIPT_ROOT}/hack/generate-internal-groups.sh \
"deepcopy,conversion,defaulter" \
github.com/koordinator-sh/koordinator/pkg/descheduler/apis/generated \
github.com/koordinator-sh/koordinator/pkg/descheduler/apis \
github.com/koordinator-sh/koordinator/pkg/descheduler/apis \
"config:v1alpha2" \
--output-base "${TEMP_DIR}" \
--go-header-file hack/boilerplate/boilerplate.go.txt

# Copy everything back.
cp -a "${TEMP_DIR}/${ROOT_PKG}/." "${SCRIPT_ROOT}/"

Expand Down
4 changes: 3 additions & 1 deletion hack/update-license-header.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ LICENSEHEADERCHECKER_VERSION=v1.3.0

GOBIN=${PROJECT}/bin go install github.com/lsm-dev/license-header-checker/cmd/license-header-checker@${LICENSEHEADERCHECKER_VERSION}

${PROJECT}/bin/license-header-checker -r -a -v -i vendor ${PROJECT}/hack/boilerplate/boilerplate.go.txt . go
LICENSEIGNORE=$(cat ${PROJECT}/.licenseignore | tr '\n' ',')

${PROJECT}/bin/license-header-checker -r -a -v -i ${LICENSEIGNORE} ${PROJECT}/hack/boilerplate/boilerplate.go.txt . go
20 changes: 20 additions & 0 deletions pkg/descheduler/apis/config/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
Copyright 2022 The Koordinator 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.
*/

// +k8s:deepcopy-gen=package
// +groupName=descheduler

package config
53 changes: 53 additions & 0 deletions pkg/descheduler/apis/config/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
Copyright 2022 The Koordinator 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 config

import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
)

var (
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
AddToScheme = SchemeBuilder.AddToScheme
Scheme = runtime.NewScheme()
)

// GroupName is the group name use in this package
const GroupName = "descheduler"

// SchemeGroupVersion is group version used to register these objects
var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: runtime.APIVersionInternal}

// Kind takes an unqualified kind and returns 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()
}

func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&DeschedulerConfiguration{},
&DefaultEvictorArgs{},
&RemovePodsViolatingNodeAffinityArgs{},
)
return nil
}
44 changes: 44 additions & 0 deletions pkg/descheduler/apis/config/scheme/scheme.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
Copyright 2022 The Koordinator 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 scheme

import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"

"github.com/koordinator-sh/koordinator/pkg/descheduler/apis/config"
"github.com/koordinator-sh/koordinator/pkg/descheduler/apis/config/v1alpha2"
)

var (
// Scheme is the runtime.Scheme to which all koord-descheduler api types are registered.
Scheme = runtime.NewScheme()

// Codecs provides access to encoding and decoding for the scheme.
Codecs = serializer.NewCodecFactory(Scheme, serializer.EnableStrict)
)

func init() {
AddToScheme(Scheme)
}

// AddToScheme builds the koord-descheduler scheme using all known versions of the koord-descheduler api.
func AddToScheme(scheme *runtime.Scheme) {
utilruntime.Must(config.AddToScheme(scheme))
utilruntime.Must(v1alpha2.AddToScheme(scheme))
}
91 changes: 91 additions & 0 deletions pkg/descheduler/apis/config/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
Copyright 2022 The Koordinator 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 config

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/component-base/config"
)

const (
DefaultDeschedulerPort = 10258
DefaultInsecureDeschedulerPort = 10251
)

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

// DeschedulerConfiguration configures a descheduler
type DeschedulerConfiguration struct {
metav1.TypeMeta

// LeaderElection defines the configuration of leader election client.
LeaderElection config.LeaderElectionConfiguration

// ClientConnection specifies the kubeconfig file and client connection
// settings for the proxy server to use when communicating with the apiserver.
ClientConnection config.ClientConnectionConfiguration

// DebuggingConfiguration holds configuration for Debugging related features
// TODO: We might wanna make this a substruct like Debugging componentbaseconfig.DebuggingConfiguration
config.DebuggingConfiguration

// HealthzBindAddress is the IP address and port for the health check server to serve on.
HealthzBindAddress string
// MetricsBindAddress is the IP address and port for the metrics server to serve on.
MetricsBindAddress string

// Time interval for descheduler to run
DeschedulingInterval metav1.Duration

// Dry run
DryRun bool

// Profiles are descheduling profiles that koord-descheduler supports.
Profiles []DeschedulerProfile

// NodeSelector for a set of nodes to operate over
NodeSelector *metav1.LabelSelector
}

// DeschedulerProfile is a descheduling profile.
type DeschedulerProfile struct {
Name string
PluginConfig []PluginConfig
Plugins *Plugins
}

type Plugins struct {
Deschedule PluginSet
Balance PluginSet
Evictor PluginSet
}

type PluginSet struct {
Enabled []Plugin
Disabled []Plugin
}

type Plugin struct {
// Name defines the name of plugin
Name string `json:"name"`
}

type PluginConfig struct {
Name string
Args runtime.Object
}
81 changes: 81 additions & 0 deletions pkg/descheduler/apis/config/types_pluginargs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
Copyright 2022 The Koordinator 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 config

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

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

// DefaultEvictorArgs holds arguments used to configure the DefaultEvictor plugin.
type DefaultEvictorArgs struct {
metav1.TypeMeta

DryRun bool
// MaxNoOfPodsToEvictPerNode restricts maximum of pods to be evicted per node.
MaxNoOfPodsToEvictPerNode *int
// MaxNoOfPodsToEvictPerNamespace restricts maximum of pods to be evicted per namespace.
MaxNoOfPodsToEvictPerNamespace *int

// EvictFailedBarePods allows pods without ownerReferences and in failed phase to be evicted.
EvictFailedBarePods bool

// EvictLocalStoragePods allows pods using local storage to be evicted.
EvictLocalStoragePods bool

// EvictSystemCriticalPods allows eviction of pods of any priority (including Kubernetes system pods)
EvictSystemCriticalPods bool

// IgnorePVCPods prevents pods with PVCs from being evicted.
IgnorePvcPods bool

// NodeFit sets whether to consider taints, node selectors,
// and pod affinity when evicting. A pod whose tolerations, node selectors,
// and affinity match a node other than the one it is currently running on
// is evictable.
NodeFit bool
// PriorityThreshold represents a threshold for pod's priority class.
// Any pod whose priority class is lower is evictable.
PriorityThreshold *PriorityThreshold
// LabelSelector sets whether to apply label filtering when evicting.
// Any pod matching the label selector is considered evictable.
LabelSelector *metav1.LabelSelector
}

type PriorityThreshold struct {
Value *int32
Name string
}

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

// RemovePodsViolatingNodeAffinityArgs holds arguments used to configure the RemovePodsViolatingNodeAffinity plugin.
type RemovePodsViolatingNodeAffinityArgs struct {
metav1.TypeMeta

Namespaces *Namespaces
LabelSelector *metav1.LabelSelector
NodeAffinityType []string
}

// Namespaces carries a list of included/excluded namespaces
// for which a given strategy is applicable
type Namespaces struct {
Include []string
Exclude []string
}

0 comments on commit 78afa0a

Please sign in to comment.