Skip to content

Commit

Permalink
Merge branch 'kubernetes-sigs:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
KunWuLuan authored May 5, 2023
2 parents e1e3c1e + f8a1d65 commit 8612ae5
Show file tree
Hide file tree
Showing 27 changed files with 1,666 additions and 655 deletions.
78 changes: 78 additions & 0 deletions .github/ISSUE_TEMPLATE/bug-report.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Bug Report
description: Report a bug encountered while operating Scheduler Plugins
labels: kind/bug
body:
- type: checkboxes
id: area
attributes:
label: Area
description: Which component do you used?
options:
- label: Scheduler
- label: Controller
- label: Helm Chart
- label: Documents

- type: input
id: area-custom
attributes:
label: Other components
description: If the component is not listed above, please tell us here
placeholder: ex. manifest
validations:
required: false

- type: textarea
id: problem
attributes:
label: What happened?
description: |
Please provide as much info as possible. Not doing so may result in your bug not being addressed in a timely manner.
validations:
required: true

- type: textarea
id: expected
attributes:
label: What did you expect to happen?
validations:
required: true

- type: textarea
id: repro
attributes:
label: How can we reproduce it (as minimally and precisely as possible)?
validations:
required: false

- type: textarea
id: additional
attributes:
label: Anything else we need to know?

- type: textarea
id: kubeVersion
attributes:
label: Kubernetes version
value: |
<details>
```console
$ kubectl version
# paste output here
```
</details>
validations:
required: true

- type: textarea
id: schedulerPluginsVersion
attributes:
label: Scheduler Plugins version
value: |
<details>
</details>
validations:
required: true
6 changes: 0 additions & 6 deletions cmd/controller/app/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@ import (
)

type ServerRunOptions struct {
KubeConfig string
MasterUrl string
MetricsAddr string
ProbeAddr string
InCluster bool
ApiServerQPS int
ApiServerBurst int
Workers int
Expand All @@ -39,9 +36,6 @@ func NewServerRunOptions() *ServerRunOptions {
}

func (s *ServerRunOptions) addAllFlags() {
pflag.BoolVar(&s.InCluster, "incluster", s.InCluster, "If controller run incluster.")
pflag.StringVar(&s.KubeConfig, "kubeConfig", s.KubeConfig, "Kube Config path if not run in cluster.")
pflag.StringVar(&s.MasterUrl, "masterUrl", s.MasterUrl, "Master Url if not run in cluster.")
pflag.StringVar(&s.MetricsAddr, "metricsAddr", ":8080", "Metrics server bind listen address.")
pflag.StringVar(&s.ProbeAddr, "probeAddr", ":8081", "Probe endpoint bind address.")
pflag.IntVar(&s.ApiServerQPS, "qps", 5, "qps of query apiserver.")
Expand Down
114 changes: 16 additions & 98 deletions cmd/controller/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,16 @@ limitations under the License.
package app

import (
"context"
"os"

"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/util/uuid"
"k8s.io/apiserver/pkg/server"
"k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
restclient "k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/tools/leaderelection"
"k8s.io/client-go/tools/leaderelection/resourcelock"
"k8s.io/klog/v2"
"k8s.io/klog/v2/klogr"

ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/healthz"

schedulingv1a1 "sigs.k8s.io/scheduler-plugins/apis/scheduling/v1alpha1"
"sigs.k8s.io/scheduler-plugins/pkg/controller"
"sigs.k8s.io/scheduler-plugins/pkg/controllers"
schedclientset "sigs.k8s.io/scheduler-plugins/pkg/generated/clientset/versioned"
schedformers "sigs.k8s.io/scheduler-plugins/pkg/generated/informers/externalversions"
)

var (
Expand All @@ -56,41 +40,10 @@ func init() {
utilruntime.Must(schedulingv1a1.AddToScheme(scheme))
}

func newConfig(kubeconfig, master string, inCluster bool) (*restclient.Config, error) {
var (
config *rest.Config
err error
)
if inCluster {
config, err = rest.InClusterConfig()
} else {
config, err = clientcmd.BuildConfigFromFlags(master, kubeconfig)
}
if err != nil {
return nil, err
}
return config, nil
}

func Run(s *ServerRunOptions) error {
ctx := context.Background()
config, err := newConfig(s.KubeConfig, s.MasterUrl, s.InCluster)
if err != nil {
klog.ErrorS(err, "Failed to parse config")
os.Exit(1)
}
config := ctrl.GetConfigOrDie()
config.QPS = float32(s.ApiServerQPS)
config.Burst = s.ApiServerBurst
stopCh := server.SetupSignalHandler()
schedClient := schedclientset.NewForConfigOrDie(config)
kubeClient := kubernetes.NewForConfigOrDie(config)

schedInformerFactory := schedformers.NewSharedInformerFactory(schedClient, 0)
eqInformer := schedInformerFactory.Scheduling().V1alpha1().ElasticQuotas()

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

// Controller Runtime Controllers
ctrl.SetLogger(klogr.New())
Expand All @@ -109,13 +62,23 @@ func Run(s *ServerRunOptions) error {
}

if err = (&controllers.PodGroupReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Workers: s.Workers,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "PodGroup")
return err
}

if err = (&controllers.ElasticQuotaReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Workers: s.Workers,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "ElasticQuota")
return err
}

if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
setupLog.Error(err, "unable to set up health check")
return err
Expand All @@ -125,54 +88,9 @@ func Run(s *ServerRunOptions) error {
return err
}

run := func(ctx context.Context) {
go eqCtrl.Run(s.Workers, ctx.Done())
setupLog.Info("starting manager")
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
setupLog.Error(err, "unable to start manager")
panic(err)
}

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())

rl, err := resourcelock.New("endpoints",
"kube-system",
"sched-plugins-controller",
kubeClient.CoreV1(),
kubeClient.CoordinationV1(),
resourcelock.ResourceLockConfig{
Identity: id,
})
if err != nil {
klog.ErrorS(err, "Resource lock creation failed")
os.Exit(1)
}

leaderelection.RunOrDie(context.TODO(), leaderelection.LeaderElectionConfig{
Lock: rl,
Callbacks: leaderelection.LeaderCallbacks{
OnStartedLeading: run,
OnStoppedLeading: func() {
klog.ErrorS(err, "Leaderelection lost")
os.Exit(1)
},
},
Name: "scheduler-plugins controller",
})
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
setupLog.Error(err, "unable to start manager")
return err
}

<-stopCh
return nil
}
28 changes: 28 additions & 0 deletions hack/install-etcd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

# Copyright 2014 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.

# This script is convenience to download and install etcd in third_party.
# Mostly just used by CI.
# Usage: `hack/install-etcd.sh`.

set -o errexit
set -o nounset
set -o pipefail

KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
source "${KUBE_ROOT}/hack/lib/init.sh"

kube::etcd::install
Loading

0 comments on commit 8612ae5

Please sign in to comment.