Commit Graph

180 Commits

Author SHA1 Message Date
Monis Khan
e9866d2794
Clear front proxy headers after authentication is complete
This matches the logic we have for the Authorization header as well
as the impersonation headers.

Signed-off-by: Monis Khan <mok@microsoft.com>
2023-03-21 10:51:22 -04:00
Lucas Severo Alves
6b34fafdaf
Add ctx logging involved in KS startup (#115588)
* ctx logging involved in startup

as per https://github.com/kubernetes/kubernetes/pull/111155#pullrequestreview-1283257121

* use klog.Background().Error in flag handling

* revert scheduler_perf changes

* refence issue in code comment

* enable ctx logcheck for cmd/kube-scheduler
2023-02-13 09:19:29 -08:00
Richa Banker
0dae5510b2 add metrics/slis to kube-scheduler health checks 2022-10-12 13:05:47 -07:00
Han Kang
e95179ffb6 Wire up feature_gate.go with metrics via AddMetrics method
wire up feature_gate.go with metrics via AddMetrics method

Change-Id: I9b4f6b04c0f4eb9bcb198b16284393d21c774ad8

wire in metrics to kubernetes components

Change-Id: I6d4ef8b26f149f62b03f32d1658f04f3056fe4dc

rename metric since we're using the value to determine if enabled is true or false

Change-Id: I13a6b6df90a5ffb4b9c5b34fa187562413bea029

Update staging/src/k8s.io/component-base/featuregate/feature_gate.go

Co-authored-by: Jordan Liggitt <jordan@liggitt.net>
2022-09-26 08:44:42 -07:00
Patrick Ohly
4c6338ac0f logs: replace config methods with functions
API types are only supposed to have methods related to serialization.
2022-06-17 20:22:13 +02:00
Patrick Ohly
1aceac797d logs: make LoggingConfiguration an unversioned API
Making the LoggingConfiguration part of the versioned component-base/config API
had the theoretic advantage that components could have offered different
configuration APIs with experimental features limited to alpha versions (for
example, sanitization offered only in a v1alpha1.KubeletConfiguration). Some
components could have decided to only use stable logging options.

In practice, this wasn't done. Furthermore, we don't want different components
to make different choices regarding which logging features they offer to
users. It should always be the same everywhere, for the sake of consistency.

This can be achieved with a saner Go API by dropping the distinction between
internal and external LoggingConfiguration types. Different stability levels of
indidividual fields have to be covered by documentation (done) and potentially
feature gates (not currently done).

Advantages:

- everything related to logging is under component-base/logs;
  previously this was scattered across different packages and
  different files under "logs" (why some code was in logs/config.go
  vs. logs/options.go vs. logs/logs.go always confused me again
  and again when coming back to the code):

  - long-term config and command line API are clearly separated
    into the "api" package underneath that

  - logs/logs.go itself only deals with legacy global flags and
    logging configuration

- removal of separate Go APIs like logs.BindLoggingFlags and
  logs.Options

- LogRegistry becomes an implementation detail, with less code
  and less exported functionality (only registration needs to
  be exported, querying is internal)
2022-06-17 20:22:13 +02:00
Wojciech Tyczyński
fe3616cafb Clean shutdown of kcm, ccm and scheduler 2022-05-26 12:36:59 +02:00
Kubernetes Prow Robot
5b8dbfbbcf
Merge pull request #108995 from pohly/log-contextual
contextual logging
2022-03-29 17:35:59 -07:00
Patrick Ohly
7de1b05e85 logging: add ContextualLogging feature
InitLogs overrides the klog default and turns contextual logging off. This
ensures that it is only enabled in Kubernetes commands that explicitly enable
it via a feature gate. A feature gate for it gets defined in
k8s.io/component-base/logs and is then used by Options.ValidateAndApply.

The effect of disabling contextual logging is very limited according to
benchmarks with kube-scheduler. The feature gets added anyway to satisfy the
PRR recommendation that features should be controllable.

The following commands have support for contextual logging:
- kube-apiserver
- kube-controller-manager
- kubelet
- kube-scheduler
- component-base/logs example

Supporting a feature gate check in ValidateAndApply and not in InitLogs is a
simplification: changing InitLogs to accept a FeatureGate would have implied
changing also component-base/cli.Run. This didn't seem worthwhile because
ValidateAndApply already covers the relevant commands.
2022-03-29 13:29:57 +02:00
Kubernetes Prow Robot
b5f8d9ec16
Merge pull request #107724 from kkkkun/fix-leaderlost
Fixes exited messages when leaderelection lost
2022-03-28 06:44:48 -07:00
Alex Wang
8a5df1302a rename unschedulableQ to unschedulablePods
Signed-off-by: Alex Wang <wangqingcan1990@gmail.com>
2022-03-24 17:38:49 +08:00
Kun Zhang
6f8e9aa05d Fixes exited messages when leaderelection lost 2022-03-24 17:33:16 +08:00
Wojciech Tyczyński
ef2e32ab65 Log main golang runtime env vars 2022-03-04 08:04:02 +01:00
Alex Wang
87549203e9 add deprecated flag for flush pods to activeq interval 2022-02-16 11:05:52 +08:00
cyclinder
1a16de783b kube-scheduler: log the unhandled error
Signed-off-by: cyclinder <qifeng.guo@daocloud.io>
2022-01-07 18:21:11 +08:00
Kubernetes Prow Robot
90110f71cb
Merge pull request #106256 from ardaguclu/use-serve-with-listener-stopped
Rename ServeWithListenerStopped to Serve in secure_serving
2021-12-13 07:35:58 -08:00
Shivanshu Raj Shrivastava
3142acbc8c
migrated remaining lines of server.go and csi.go to structured logging 2021-11-10 21:24:34 +05:30
Arda Güçlü
a8d2b3a792 Rename ServeWithListenerStopped to Serve in secure_serving
This PR removes Serve function and uses all required places
ServeWithListenerStopped which takes place new Serve function.

This function returns ListenerStopped channel can be used to drain
requests before shutting down the server.
2021-11-08 17:20:31 +03:00
Patrick Ohly
4df70dfd41 component-base: initialize logging as soon as possible
In various places log messages where emitted as part of validation or even
before it (for example, cli.PrintFlags). Those log messages did not use the
final logging configuration, for example text output instead of JSON or not the
final verbosity. The last point became more obvious after moving the setup of
verbosity into logs.Options.Apply because PrintFlags never printed anything
anymore.

In order to force applications to deal with logging as soon as possible, the
Options.Validate and Options.Apply methods are now private. Applications should
use the new Options.ValidateAndApply directly after parsing.
2021-11-03 11:55:54 +01:00
Patrick Ohly
3948cb8d1b component-base: move v/vmodule/log-flush-frequency into LoggingConfiguration
These three options are the ones from logs.AddFlags which are not deprecated.
Therefore it makes sense to make them available also via the configuration file
support in the one command which currently supports that (kubelet).

Long-term, all commands should use LoggingConfiguration, either with a
configuration file (as in kubelet) or via flags (kube-scheduler,
kube-apiserver, kube-controller-manager).

Short-term, both approaches have to be supported. As the majority of the
commands only use logs.AddFlags, that function by default continues to register
the flags and only leaves that to Options.AddFlags when explicitly requested.

A drive-by bug fix is done for log flushing: the periodic flushing called
klog.Flush and therefore missed explicit flushing of the newer logr
backend. This bug was never present in any release Kubernetes and therefore the
fix is not submitted in a separate PR.
2021-11-03 07:41:46 +01:00
Wei Huang
e30f9648cc
sched: ensure feature gate is honored when instantiating scheduler (#105915)
* sched: ensure feature gate is honored when instantiating scheduler

* fixup: address comments
2021-11-02 14:28:06 -07:00
Wei Huang
7505701044
Revert "sched: ensure --leader-elect* CLI args are honored"
This reverts commit 3c230af59c.
2021-10-26 15:18:13 -07:00
Shivanshu Raj Shrivastava
3c87c43cef
Migrated scheduler files server.go, node_label.go, csi.go, non_csi.go to structured logging (#105855)
* migrated server.go

* fixed migration

* resolving review comments

* added storageClass

* review comments

* review comments
2021-10-26 13:21:22 -07:00
Wei Huang
3c230af59c
sched: ensure --leader-elect* CLI args are honored 2021-10-19 13:56:08 -07:00
Kubernetes Prow Robot
4753fa5dee
Merge pull request #105608 from yxxhero/reduce_code
reduce code for NewSchedulerCommand func
2021-10-11 23:23:46 -07:00
yxxhero
71a6bb3301 reduce code for NewSchedulerCommand func
Signed-off-by: yxxhero <aiopsclub@163.com>
2021-10-11 23:21:34 +08:00
kerthcet
a6f695581b remove legacy scheduler policy config, as well as associated flags policy-config-file, policy-configmap, policy-configmap-namespace and use-legacy-policy-config
Signed-off-by: kerthcet <kerthcet@gmail.com>
2021-10-08 23:57:49 +08:00
Patrick Ohly
1957fb6508 command lines: harmonize command line parse error handling
The recommendation from #sig-cli was to print usage, then the error. Extra care
is taken to only print the usage instruction when the error really was about
flag parsing.

Taking kube-scheduler as example:

  $ _output/bin/kube-scheduler
  I0929 09:42:42.289039  149029 serving.go:348] Generated self-signed cert in-memory
  ...
  W0929 09:42:42.489255  149029 client_config.go:620] error creating inClusterConfig, falling back to default config: unable to load in-cluster configuration, KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT must be defined
  E0929 09:42:42.489366  149029 run.go:98] "command failed" err="invalid configuration: no configuration has been provided, try setting KUBERNETES_MASTER environment variable"

  $ _output/bin/kube-scheduler --xxx
  Usage:
    kube-scheduler [flags]

  ...
       --vmodule moduleSpec
                  comma-separated list of pattern=N settings for file-filtered logging

  Error: unknown flag: --xxx

The kubectl behavior doesn't change:

  $ _output/bin/kubectl get nodes
  Unable to connect to the server: dial tcp: lookup xxxx: No address associated with hostname

  $ _output/bin/kubectl --xxx
  Error: unknown flag: --xxx
  See 'kubectl --help' for usage.
2021-09-30 13:46:49 +02:00
Patrick Ohly
00e4a599f6 command lines: always show flags with hyphens
All Kubernetes commands should show flags with hyphens in their help text even
when the flag originally was defined with underscore. Converting a command to
this style is not breaking its command line API because the old-style parameter
with underscore is accepted as alias.

The easiest solution to achieve this is to set normalization shortly before
running the command in the new central cli.Run or the few places where that
function isn't used yet.

There may be some texts which depends on normalization at flag definition time,
like the --logging-format usage warning. Those get generated assuming that
hyphens will be used.
2021-09-30 13:46:49 +02:00
Patrick Ohly
21d1bcd6b8 initialize logging after flag parsing
It wasn't documented that InitLogs already uses the log flush frequency, so
some commands have called it before parsing (for example, kubectl in the
original code for logs.go). The flag never had an effect in such commands.

Fixing this turned into a major refactoring of how commands set up flags and
run their Cobra command:

- component-base/logs: implicitely registering flags during package init is an
  anti-pattern that makes it impossible to use the package in commands which
  want full control over their command line. Logging flags must be added
  explicitly now, something that the new cli.Run does automatically.

- component-base/logs: AddFlags would have crashed in kubectl-convert if it
  had been called because it relied on the global pflag.CommandLine. This
  has been fixed and kubectl-convert now has the same --log-flush-frequency
  flag as other commands.

- component-base/logs/testinit: an exception are tests where flag.CommandLine has
  to be used. This new package can be imported to add flags to that
  once per test program.

- Normalization of the klog command line flags was inconsistent. Some commands
  unintentionally didn't normalize to the recommended format with hyphens. This
  gets fixed for sample programs, but not for production programs because
  it would be a breaking change.

This refactoring has the following user-visible effects:

- The validation error for `go run ./cmd/kube-apiserver --logging-format=json
  --add-dir-header` now references `add-dir-header` instead of `add_dir_header`.

- `staging/src/k8s.io/cloud-provider/sample` uses flags with hyphen instead of
  underscore.

- `--log-flush-frequency` is not listed anymore in the --logging-format flag's
  `non-default formats don't honor these flags` usage text because it will also
  work for non-default formats once it is needed.

- `cmd/kubelet`: the description of `--logging-format` uses hyphens instead of
  underscores for the flags, which now matches what the command is using.

- `staging/src/k8s.io/component-base/logs/example/cmd`: added logging flags.

- `apiextensions-apiserver` no longer prints a useless stack trace for `main`
  when command line parsing raises an error.
2021-09-30 13:46:49 +02:00
Wei Huang
a689ad4cda
sched: start dynamicInformerFactory along with regular informerFactory (#105016)
* sched: start dynamicInformerFactory along with regular informerFactory

* fixup: start all informers and then wait for their syncs
2021-09-16 19:33:00 -07:00
Kubernetes Prow Robot
c10be982d1
Merge pull request #96345 from ingvagabund/disable-insecure-port-in-scheduler
refactor: disable insecure serving in kube-scheduler
2021-09-14 08:01:09 -07:00
Jan Chaloupka
07af6697e9 refactor: disable insecure serving in kube-scheduler 2021-09-14 07:52:16 +02:00
wangyamei
50865679b9 Scheduler version should be printed out by default 2021-09-02 21:46:41 +08:00
sanposhiho
0252865601 Fix: set SilenceErrors and SilenceUsage not to change error message 2021-08-23 13:29:44 +09:00
sanposhiho
a06d6138b5 Fix: not change the error messages 2021-08-22 21:20:32 +09:00
sanposhiho
b8ae016ee6 Fix: return error instead of os.Exit when something goes wrong 2021-08-22 19:20:47 +09:00
Wei Huang
4c9c761bbb
instantiates scheduler ComponentConfig after parsing feature gates 2021-07-06 10:39:12 -07:00
Abdullah Gharaibeh
52f5ba3a58 Remove SchedulerAlgorithmSource from scheduler's internal CC API 2021-06-09 19:14:54 -04:00
Adhityaa Chandrasekar
3c8e56bef9 scheduler: graduate CC to v1beta2, deprecate plugins
Signed-off-by: Adhityaa Chandrasekar <adtac@google.com>
2021-06-07 12:42:55 +00:00
Kubernetes Prow Robot
70f745a37a
Merge pull request #100305 from ingvagabund/kube-scheduler-release-lock-on-cancel
Release lock on cancel for scheduler
2021-04-30 07:27:58 -07:00
BinacsLee
75dde4dce4 code cleanup: Abstract repetitive codes in cmd as a function 2021-04-22 23:35:04 +08:00
Kubernetes Prow Robot
ed3e0d302f
Merge pull request #100644 from Huang-Wei/sched-fwk-config
Surface kube config in scheduler framework handle
2021-04-12 19:12:49 -07:00
Kubernetes Prow Robot
89056f66c8
Merge pull request #100877 from lojies/schedulerlogstructured
Structured Logging migration: modify logs of kube-scheduler
2021-04-10 19:04:45 -07:00
卢振兴10069964
98a03ae57b Structured Logging migration: modify logs of kube-scheduler 2021-04-07 15:53:06 +08:00
Wei Huang
e7f67b1a63
Surface kube config in scheduler framework handle 2021-03-30 11:54:59 -07:00
Maciej Szulik
c5a5230d93 Release lock on cancel for scheduler 2021-03-16 19:04:44 +01:00
Abu Kashem
71199664be
use request received timestamp in httplog 2021-03-05 15:34:17 -05:00
Kubernetes Prow Robot
cd21a1240a
Merge pull request #94866 from smarterclayton/scheduling_metrics
scheduler: Implement resource metrics at /metrics/resources
2020-11-12 18:36:23 -08:00
Mike Dame
14fa76d92f Log defaulted kube-scheduler component config at startup 2020-11-12 16:03:11 -05:00