Skip to content

Commit

Permalink
Merge pull request #212 from yuchen-sun/feat/ElasticQuota/controller
Browse files Browse the repository at this point in the history
feat: add elastic quota controller
  • Loading branch information
k8s-ci-robot committed Aug 7, 2021
2 parents 74438bd + 4942ccd commit d9811fe
Show file tree
Hide file tree
Showing 12 changed files with 1,185 additions and 61 deletions.
21 changes: 21 additions & 0 deletions cmd/controller/app/import_known_versions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
Copyright 2021 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 app

import (
_ "sigs.k8s.io/scheduler-plugins/pkg/apis/scheduling/scheme"
)
37 changes: 18 additions & 19 deletions cmd/controller/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ package app

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

"k8s.io/apimachinery/pkg/util/uuid"
"k8s.io/apiserver/pkg/server"
"k8s.io/client-go/informers"
Expand All @@ -29,12 +30,10 @@ import (
"k8s.io/client-go/tools/leaderelection"
"k8s.io/client-go/tools/leaderelection/resourcelock"
"k8s.io/klog/v2"
"os"

"sigs.k8s.io/scheduler-plugins/pkg/controller"
pgclientset "sigs.k8s.io/scheduler-plugins/pkg/generated/clientset/versioned"
pgformers "sigs.k8s.io/scheduler-plugins/pkg/generated/informers/externalversions"
"sigs.k8s.io/scheduler-plugins/pkg/util"
schedclientset "sigs.k8s.io/scheduler-plugins/pkg/generated/clientset/versioned"
schedformers "sigs.k8s.io/scheduler-plugins/pkg/generated/informers/externalversions"
)

func newConfig(kubeconfig, master string, inCluster bool) (*restclient.Config, error) {
Expand Down Expand Up @@ -62,32 +61,32 @@ func Run(s *ServerRunOptions) error {
config.QPS = float32(s.ApiServerQPS)
config.Burst = s.ApiServerBurst
stopCh := server.SetupSignalHandler()

pgClient := pgclientset.NewForConfigOrDie(config)
schedClient := schedclientset.NewForConfigOrDie(config)
kubeClient := kubernetes.NewForConfigOrDie(config)

pgInformerFactory := pgformers.NewSharedInformerFactory(pgClient, 0)
pgInformer := pgInformerFactory.Scheduling().V1alpha1().PodGroups()
schedInformerFactory := schedformers.NewSharedInformerFactory(schedClient, 0)
pgInformer := schedInformerFactory.Scheduling().V1alpha1().PodGroups()
eqInformer := schedInformerFactory.Scheduling().V1alpha1().ElasticQuotas()

coreInformerFactory := informers.NewSharedInformerFactory(kubeClient, 0)
podInformer := coreInformerFactory.Core().V1().Pods()
pgCtrl := controller.NewPodGroupController(kubeClient, pgInformer, podInformer, schedClient)
eqCtrl := controller.NewElasticQuotaController(kubeClient, eqInformer, podInformer, schedClient)

informerFactory := informers.NewSharedInformerFactoryWithOptions(kubeClient, 0, informers.WithTweakListOptions(func(opt *metav1.ListOptions) {
opt.LabelSelector = util.PodGroupLabel
}))
podInformer := informerFactory.Core().V1().Pods()
ctrl := controller.NewPodGroupController(kubeClient, pgInformer, podInformer, pgClient)
pgInformerFactory.Start(stopCh)
informerFactory.Start(stopCh)
run := func(ctx context.Context) {
ctrl.Run(s.Workers, ctx.Done())
go pgCtrl.Run(s.Workers, ctx.Done())
go eqCtrl.Run(s.Workers, ctx.Done())
select {}
}

schedInformerFactory.Start(stopCh)
coreInformerFactory.Start(stopCh)
if !s.EnableLeaderElection {
run(ctx)
} else {
id, err := os.Hostname()
if err != nil {
return err
}

// add a uniquifier so that two processes on the same host don't accidentally both become active
id = id + "_" + string(uuid.NewUUID())

Expand Down
33 changes: 33 additions & 0 deletions pkg/apis/scheduling/scheme/scheme.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
Copyright 2021 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 scheme

import (
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/client-go/kubernetes/scheme"
schedv1alpha1 "sigs.k8s.io/scheduler-plugins/pkg/apis/scheduling/v1alpha1"
)

func init() {
AddToScheme(scheme.Scheme)
}

// AddToScheme builds the kubescheduler scheme using all known versions of the kubescheduler api.
func AddToScheme(scheme *runtime.Scheme) {
utilruntime.Must(schedv1alpha1.AddToScheme(scheme))
}
12 changes: 6 additions & 6 deletions pkg/apis/scheduling/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,29 +80,29 @@ type PodGroupPhase string

// These are the valid phase of podGroups.
const (
// PodPending means the pod group has been accepted by the system, but scheduler can not allocate
// PodGroupPending means the pod group has been accepted by the system, but scheduler can not allocate
// enough resources to it.
PodGroupPending PodGroupPhase = "Pending"

// PodRunning means `spec.minMember` pods of PodGroups has been in running phase.
// PodGroupRunning means `spec.minMember` pods of PodGroups has been in running phase.
PodGroupRunning PodGroupPhase = "Running"

// PreScheduling means all of pods has been are waiting to be scheduled, enqueue waitingPod
// PodGroupPreScheduling means all of pods has been are waiting to be scheduled, enqueue waitingPod
PodGroupPreScheduling PodGroupPhase = "PreScheduling"

// PodRunning means some of pods has been scheduling in running phase but have not reach the `spec.
// PodGroupScheduling means some of pods has been scheduling in running phase but have not reach the `spec.
// minMember` pods of PodGroups.
PodGroupScheduling PodGroupPhase = "Scheduling"

// PodScheduled means `spec.minMember` pods of PodGroups have been scheduled finished and pods have been in running
// PodGroupScheduled means `spec.minMember` pods of PodGroups have been scheduled finished and pods have been in running
// phase.
PodGroupScheduled PodGroupPhase = "Scheduled"

// PodGroupUnknown means part of `spec.minMember` pods are running but the other part can not
// be scheduled, e.g. not enough resource; scheduler will wait for related controller to recover it.
PodGroupUnknown PodGroupPhase = "Unknown"

// PodGroupFinish means all of `spec.minMember` pods are successfully.
// PodGroupFinished means all of `spec.minMember` pods are successfully.
PodGroupFinished PodGroupPhase = "Finished"

// PodGroupFailed means at least one of `spec.minMember` pods is failed.
Expand Down
2 changes: 1 addition & 1 deletion pkg/capacityscheduling/capacity_scheduling.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (s *PreFilterState) Clone() framework.StateData {
return s
}

// ElasticQuotaSnapshot stores the snapshot of elasticQuotas.
// ElasticQuotaSnapshotState stores the snapshot of elasticQuotas.
type ElasticQuotaSnapshotState struct {
elasticQuotaInfos ElasticQuotaInfos
}
Expand Down
Loading

0 comments on commit d9811fe

Please sign in to comment.