forked from kubernetes/kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UPSTREAM: <carry>: allows for switching KS to talk to Kube API over l…
…ocalhost to force KS to use localhost set the following flag in kubescheduler (oc edit kubescheduler cluster) unsupportedConfigOverrides: arguments: unsupported-kube-api-over-localhost:: - "true" UPSTREAM: <carry>: allows for switching KS to talk to Kube API over localhost-squash to other This commit is addendum to 04eabe5 to stop using cc and start relying on scheduler config options OpenShift-Rebase-Source: aa9dde2 UPSTREAM: <carry>: allows for switching KS to talk to Kube API over localhost
- Loading branch information
1 parent
26724cb
commit 7cb1ce5
Showing
6 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package config | ||
|
||
import ( | ||
"k8s.io/client-go/transport" | ||
|
||
"github.com/openshift/library-go/pkg/monitor/health" | ||
) | ||
|
||
// OpenShiftContext is additional context that we need to launch the kube-scheduler for openshift. | ||
// Basically, this holds our additional config information. | ||
type OpenShiftContext struct { | ||
UnsupportedKubeAPIOverPreferredHost bool | ||
PreferredHostRoundTripperWrapperFn transport.WrapperFunc | ||
PreferredHostHealthMonitor *health.Prober | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package options | ||
|
||
import ( | ||
"k8s.io/klog/v2" | ||
|
||
kubeschedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config" | ||
) | ||
|
||
func LoadKubeSchedulerConfiguration(logger klog.Logger, file string) (*kubeschedulerconfig.KubeSchedulerConfiguration, error) { | ||
return LoadConfigFromFile(logger, file) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package app | ||
|
||
import ( | ||
"time" | ||
|
||
"k8s.io/klog/v2" | ||
|
||
"k8s.io/client-go/rest" | ||
"k8s.io/client-go/tools/clientcmd" | ||
"k8s.io/component-base/metrics/legacyregistry" | ||
"k8s.io/kubernetes/cmd/kube-scheduler/app/options" | ||
|
||
libgorestclient "github.com/openshift/library-go/pkg/config/client" | ||
"github.com/openshift/library-go/pkg/monitor/health" | ||
) | ||
|
||
func setUpPreferredHostForOpenShift(logger klog.Logger, kubeSchedulerOptions *options.Options) error { | ||
if !kubeSchedulerOptions.OpenShiftContext.UnsupportedKubeAPIOverPreferredHost { | ||
return nil | ||
} | ||
|
||
master := kubeSchedulerOptions.Master | ||
var kubeConfig string | ||
|
||
// We cannot load component config anymore as the options are not being initialized. | ||
// if there was no kubeconfig specified we won't be able to get cluster info. | ||
// in that case try to load the configuration and read kubeconfig directly from it if it was provided. | ||
if len(kubeSchedulerOptions.ConfigFile) > 0 { | ||
cfg, err := options.LoadKubeSchedulerConfiguration(logger, kubeSchedulerOptions.ConfigFile) | ||
if err != nil { | ||
return err | ||
} | ||
kubeConfig = cfg.ClientConnection.Kubeconfig | ||
} | ||
|
||
config, err := clientcmd.BuildConfigFromFlags(master, kubeConfig) | ||
if err != nil { | ||
return err | ||
} | ||
libgorestclient.DefaultServerName(config) | ||
|
||
targetProvider := health.StaticTargetProvider{"localhost:6443"} | ||
kubeSchedulerOptions.OpenShiftContext.PreferredHostHealthMonitor, err = health.New(targetProvider, createRestConfigForHealthMonitor(config)) | ||
if err != nil { | ||
return err | ||
} | ||
kubeSchedulerOptions.OpenShiftContext.PreferredHostHealthMonitor. | ||
WithHealthyProbesThreshold(3). | ||
WithUnHealthyProbesThreshold(5). | ||
WithProbeInterval(5 * time.Second). | ||
WithProbeResponseTimeout(2 * time.Second). | ||
WithMetrics(health.Register(legacyregistry.MustRegister)) | ||
|
||
kubeSchedulerOptions.OpenShiftContext.PreferredHostRoundTripperWrapperFn = libgorestclient.NewPreferredHostRoundTripper(func() string { | ||
healthyTargets, _ := kubeSchedulerOptions.OpenShiftContext.PreferredHostHealthMonitor.Targets() | ||
if len(healthyTargets) == 1 { | ||
return healthyTargets[0] | ||
} | ||
return "" | ||
}) | ||
|
||
kubeSchedulerOptions.Authentication.WithCustomRoundTripper(kubeSchedulerOptions.OpenShiftContext.PreferredHostRoundTripperWrapperFn) | ||
kubeSchedulerOptions.Authorization.WithCustomRoundTripper(kubeSchedulerOptions.OpenShiftContext.PreferredHostRoundTripperWrapperFn) | ||
return nil | ||
} | ||
|
||
func createRestConfigForHealthMonitor(restConfig *rest.Config) *rest.Config { | ||
restConfigCopy := *restConfig | ||
rest.AddUserAgent(&restConfigCopy, "kube-scheduler-health-monitor") | ||
|
||
return &restConfigCopy | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters