k8s.io/kubernetes@v1.31.0-alpha.0.0.20240520171757-56147500dadc/cmd/kube-scheduler/app/config/config.go (about)

     1  /*
     2  Copyright 2018 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package config
    18  
    19  import (
    20  	"time"
    21  
    22  	apiserver "k8s.io/apiserver/pkg/server"
    23  	"k8s.io/client-go/dynamic/dynamicinformer"
    24  	"k8s.io/client-go/informers"
    25  	clientset "k8s.io/client-go/kubernetes"
    26  	restclient "k8s.io/client-go/rest"
    27  	"k8s.io/client-go/tools/events"
    28  	"k8s.io/client-go/tools/leaderelection"
    29  	kubeschedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
    30  )
    31  
    32  // Config has all the context to run a Scheduler
    33  type Config struct {
    34  	// ComponentConfig is the scheduler server's configuration object.
    35  	ComponentConfig kubeschedulerconfig.KubeSchedulerConfiguration
    36  
    37  	// LoopbackClientConfig is a config for a privileged loopback connection
    38  	LoopbackClientConfig *restclient.Config
    39  
    40  	Authentication apiserver.AuthenticationInfo
    41  	Authorization  apiserver.AuthorizationInfo
    42  	SecureServing  *apiserver.SecureServingInfo
    43  
    44  	Client             clientset.Interface
    45  	KubeConfig         *restclient.Config
    46  	InformerFactory    informers.SharedInformerFactory
    47  	DynInformerFactory dynamicinformer.DynamicSharedInformerFactory
    48  
    49  	//nolint:staticcheck // SA1019 this deprecated field still needs to be used for now. It will be removed once the migration is done.
    50  	EventBroadcaster events.EventBroadcasterAdapter
    51  
    52  	// LeaderElection is optional.
    53  	LeaderElection *leaderelection.LeaderElectionConfig
    54  
    55  	// PodMaxInUnschedulablePodsDuration is the maximum time a pod can stay in
    56  	// unschedulablePods. If a pod stays in unschedulablePods for longer than this
    57  	// value, the pod will be moved from unschedulablePods to backoffQ or activeQ.
    58  	// If this value is empty, the default value (5min) will be used.
    59  	PodMaxInUnschedulablePodsDuration time.Duration
    60  }
    61  
    62  type completedConfig struct {
    63  	*Config
    64  }
    65  
    66  // CompletedConfig same as Config, just to swap private object.
    67  type CompletedConfig struct {
    68  	// Embed a private pointer that cannot be instantiated outside of this package.
    69  	*completedConfig
    70  }
    71  
    72  // Complete fills in any fields not set that are required to have valid data. It's mutating the receiver.
    73  func (c *Config) Complete() CompletedConfig {
    74  	cc := completedConfig{c}
    75  
    76  	apiserver.AuthorizeClientBearerToken(c.LoopbackClientConfig, &c.Authentication, &c.Authorization)
    77  
    78  	return CompletedConfig{&cc}
    79  }