mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
Merge pull request #91522 from SataQiu/add-logging-format-flag-20200528
Add '--logging-format' flag to kube-scheduler
This commit is contained in:
commit
36083e4292
@ -39,6 +39,7 @@ go_library(
|
|||||||
"//staging/src/k8s.io/component-base/config:go_default_library",
|
"//staging/src/k8s.io/component-base/config:go_default_library",
|
||||||
"//staging/src/k8s.io/component-base/config/options:go_default_library",
|
"//staging/src/k8s.io/component-base/config/options:go_default_library",
|
||||||
"//staging/src/k8s.io/component-base/config/v1alpha1:go_default_library",
|
"//staging/src/k8s.io/component-base/config/v1alpha1:go_default_library",
|
||||||
|
"//staging/src/k8s.io/component-base/logs:go_default_library",
|
||||||
"//staging/src/k8s.io/component-base/metrics:go_default_library",
|
"//staging/src/k8s.io/component-base/metrics:go_default_library",
|
||||||
"//staging/src/k8s.io/kube-scheduler/config/v1beta1:go_default_library",
|
"//staging/src/k8s.io/kube-scheduler/config/v1beta1:go_default_library",
|
||||||
"//vendor/github.com/spf13/pflag:go_default_library",
|
"//vendor/github.com/spf13/pflag:go_default_library",
|
||||||
@ -77,6 +78,7 @@ go_test(
|
|||||||
"//staging/src/k8s.io/apimachinery/pkg/util/rand:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/util/rand:go_default_library",
|
||||||
"//staging/src/k8s.io/apiserver/pkg/server/options:go_default_library",
|
"//staging/src/k8s.io/apiserver/pkg/server/options:go_default_library",
|
||||||
"//staging/src/k8s.io/component-base/config:go_default_library",
|
"//staging/src/k8s.io/component-base/config:go_default_library",
|
||||||
|
"//staging/src/k8s.io/component-base/logs:go_default_library",
|
||||||
"//vendor/github.com/google/go-cmp/cmp:go_default_library",
|
"//vendor/github.com/google/go-cmp/cmp:go_default_library",
|
||||||
"//vendor/github.com/stretchr/testify/assert:go_default_library",
|
"//vendor/github.com/stretchr/testify/assert:go_default_library",
|
||||||
],
|
],
|
||||||
|
@ -41,6 +41,7 @@ import (
|
|||||||
componentbaseconfig "k8s.io/component-base/config"
|
componentbaseconfig "k8s.io/component-base/config"
|
||||||
"k8s.io/component-base/config/options"
|
"k8s.io/component-base/config/options"
|
||||||
configv1alpha1 "k8s.io/component-base/config/v1alpha1"
|
configv1alpha1 "k8s.io/component-base/config/v1alpha1"
|
||||||
|
"k8s.io/component-base/logs"
|
||||||
"k8s.io/component-base/metrics"
|
"k8s.io/component-base/metrics"
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
kubeschedulerconfigv1beta1 "k8s.io/kube-scheduler/config/v1beta1"
|
kubeschedulerconfigv1beta1 "k8s.io/kube-scheduler/config/v1beta1"
|
||||||
@ -61,6 +62,7 @@ type Options struct {
|
|||||||
Authentication *apiserveroptions.DelegatingAuthenticationOptions
|
Authentication *apiserveroptions.DelegatingAuthenticationOptions
|
||||||
Authorization *apiserveroptions.DelegatingAuthorizationOptions
|
Authorization *apiserveroptions.DelegatingAuthorizationOptions
|
||||||
Metrics *metrics.Options
|
Metrics *metrics.Options
|
||||||
|
Logs *logs.Options
|
||||||
Deprecated *DeprecatedOptions
|
Deprecated *DeprecatedOptions
|
||||||
|
|
||||||
// ConfigFile is the location of the scheduler server's configuration file.
|
// ConfigFile is the location of the scheduler server's configuration file.
|
||||||
@ -106,6 +108,7 @@ func NewOptions() (*Options, error) {
|
|||||||
HardPodAffinitySymmetricWeight: 1,
|
HardPodAffinitySymmetricWeight: 1,
|
||||||
},
|
},
|
||||||
Metrics: metrics.NewOptions(),
|
Metrics: metrics.NewOptions(),
|
||||||
|
Logs: logs.NewOptions(),
|
||||||
}
|
}
|
||||||
|
|
||||||
o.Authentication.TolerateInClusterLookupFailure = true
|
o.Authentication.TolerateInClusterLookupFailure = true
|
||||||
@ -167,6 +170,7 @@ func (o *Options) Flags() (nfs cliflag.NamedFlagSets) {
|
|||||||
options.BindLeaderElectionFlags(&o.ComponentConfig.LeaderElection, nfs.FlagSet("leader election"))
|
options.BindLeaderElectionFlags(&o.ComponentConfig.LeaderElection, nfs.FlagSet("leader election"))
|
||||||
utilfeature.DefaultMutableFeatureGate.AddFlag(nfs.FlagSet("feature gate"))
|
utilfeature.DefaultMutableFeatureGate.AddFlag(nfs.FlagSet("feature gate"))
|
||||||
o.Metrics.AddFlags(nfs.FlagSet("metrics"))
|
o.Metrics.AddFlags(nfs.FlagSet("metrics"))
|
||||||
|
o.Logs.AddFlags(nfs.FlagSet("logs"))
|
||||||
|
|
||||||
return nfs
|
return nfs
|
||||||
}
|
}
|
||||||
@ -219,6 +223,7 @@ func (o *Options) ApplyTo(c *schedulerappconfig.Config) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
o.Metrics.Apply()
|
o.Metrics.Apply()
|
||||||
|
o.Logs.Apply()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -244,6 +249,7 @@ func (o *Options) Validate() []error {
|
|||||||
errs = append(errs, o.Authorization.Validate()...)
|
errs = append(errs, o.Authorization.Validate()...)
|
||||||
errs = append(errs, o.Deprecated.Validate()...)
|
errs = append(errs, o.Deprecated.Validate()...)
|
||||||
errs = append(errs, o.Metrics.Validate()...)
|
errs = append(errs, o.Metrics.Validate()...)
|
||||||
|
errs = append(errs, o.Logs.Validate()...)
|
||||||
|
|
||||||
return errs
|
return errs
|
||||||
}
|
}
|
||||||
|
@ -29,13 +29,14 @@ import (
|
|||||||
|
|
||||||
"github.com/google/go-cmp/cmp"
|
"github.com/google/go-cmp/cmp"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/interpodaffinity"
|
|
||||||
|
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
apiserveroptions "k8s.io/apiserver/pkg/server/options"
|
apiserveroptions "k8s.io/apiserver/pkg/server/options"
|
||||||
componentbaseconfig "k8s.io/component-base/config"
|
componentbaseconfig "k8s.io/component-base/config"
|
||||||
|
"k8s.io/component-base/logs"
|
||||||
kubeschedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
|
kubeschedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
|
||||||
|
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/interpodaffinity"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSchedulerOptions(t *testing.T) {
|
func TestSchedulerOptions(t *testing.T) {
|
||||||
@ -293,6 +294,7 @@ profiles:
|
|||||||
RemoteKubeConfigFileOptional: true,
|
RemoteKubeConfigFileOptional: true,
|
||||||
AlwaysAllowPaths: []string{"/healthz"}, // note: this does not match /healthz/ or /healthz/*
|
AlwaysAllowPaths: []string{"/healthz"}, // note: this does not match /healthz/ or /healthz/*
|
||||||
},
|
},
|
||||||
|
Logs: logs.NewOptions(),
|
||||||
},
|
},
|
||||||
expectedUsername: "config",
|
expectedUsername: "config",
|
||||||
expectedConfig: kubeschedulerconfig.KubeSchedulerConfiguration{
|
expectedConfig: kubeschedulerconfig.KubeSchedulerConfiguration{
|
||||||
@ -337,18 +339,25 @@ profiles:
|
|||||||
}
|
}
|
||||||
return *cfg
|
return *cfg
|
||||||
}(),
|
}(),
|
||||||
|
Logs: logs.NewOptions(),
|
||||||
},
|
},
|
||||||
expectedError: "no kind \"KubeSchedulerConfiguration\" is registered for version \"componentconfig/v1alpha1\"",
|
expectedError: "no kind \"KubeSchedulerConfiguration\" is registered for version \"componentconfig/v1alpha1\"",
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
name: "unknown version kubescheduler.config.k8s.io/unknown",
|
name: "unknown version kubescheduler.config.k8s.io/unknown",
|
||||||
options: &Options{ConfigFile: unknownVersionConfig},
|
options: &Options{
|
||||||
|
ConfigFile: unknownVersionConfig,
|
||||||
|
Logs: logs.NewOptions(),
|
||||||
|
},
|
||||||
expectedError: "no kind \"KubeSchedulerConfiguration\" is registered for version \"kubescheduler.config.k8s.io/unknown\"",
|
expectedError: "no kind \"KubeSchedulerConfiguration\" is registered for version \"kubescheduler.config.k8s.io/unknown\"",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "config file with no version",
|
name: "config file with no version",
|
||||||
options: &Options{ConfigFile: noVersionConfig},
|
options: &Options{
|
||||||
|
ConfigFile: noVersionConfig,
|
||||||
|
Logs: logs.NewOptions(),
|
||||||
|
},
|
||||||
expectedError: "Object 'apiVersion' is missing",
|
expectedError: "Object 'apiVersion' is missing",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -382,6 +391,7 @@ profiles:
|
|||||||
RemoteKubeConfigFileOptional: true,
|
RemoteKubeConfigFileOptional: true,
|
||||||
AlwaysAllowPaths: []string{"/healthz"}, // note: this does not match /healthz/ or /healthz/*
|
AlwaysAllowPaths: []string{"/healthz"}, // note: this does not match /healthz/ or /healthz/*
|
||||||
},
|
},
|
||||||
|
Logs: logs.NewOptions(),
|
||||||
},
|
},
|
||||||
expectedUsername: "flag",
|
expectedUsername: "flag",
|
||||||
expectedConfig: kubeschedulerconfig.KubeSchedulerConfiguration{
|
expectedConfig: kubeschedulerconfig.KubeSchedulerConfiguration{
|
||||||
@ -446,6 +456,7 @@ profiles:
|
|||||||
RemoteKubeConfigFileOptional: true,
|
RemoteKubeConfigFileOptional: true,
|
||||||
AlwaysAllowPaths: []string{"/healthz"}, // note: this does not match /healthz/ or /healthz/*
|
AlwaysAllowPaths: []string{"/healthz"}, // note: this does not match /healthz/ or /healthz/*
|
||||||
},
|
},
|
||||||
|
Logs: logs.NewOptions(),
|
||||||
},
|
},
|
||||||
expectedConfig: kubeschedulerconfig.KubeSchedulerConfiguration{
|
expectedConfig: kubeschedulerconfig.KubeSchedulerConfiguration{
|
||||||
AlgorithmSource: kubeschedulerconfig.SchedulerAlgorithmSource{Provider: &defaultSource},
|
AlgorithmSource: kubeschedulerconfig.SchedulerAlgorithmSource{Provider: &defaultSource},
|
||||||
@ -483,6 +494,7 @@ profiles:
|
|||||||
name: "plugin config",
|
name: "plugin config",
|
||||||
options: &Options{
|
options: &Options{
|
||||||
ConfigFile: pluginConfigFile,
|
ConfigFile: pluginConfigFile,
|
||||||
|
Logs: logs.NewOptions(),
|
||||||
},
|
},
|
||||||
expectedUsername: "config",
|
expectedUsername: "config",
|
||||||
expectedConfig: kubeschedulerconfig.KubeSchedulerConfiguration{
|
expectedConfig: kubeschedulerconfig.KubeSchedulerConfiguration{
|
||||||
@ -556,6 +568,7 @@ profiles:
|
|||||||
name: "multiple profiles",
|
name: "multiple profiles",
|
||||||
options: &Options{
|
options: &Options{
|
||||||
ConfigFile: multiProfilesConfig,
|
ConfigFile: multiProfilesConfig,
|
||||||
|
Logs: logs.NewOptions(),
|
||||||
},
|
},
|
||||||
expectedUsername: "config",
|
expectedUsername: "config",
|
||||||
expectedConfig: kubeschedulerconfig.KubeSchedulerConfiguration{
|
expectedConfig: kubeschedulerconfig.KubeSchedulerConfiguration{
|
||||||
@ -614,8 +627,10 @@ profiles:
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "no config",
|
name: "no config",
|
||||||
options: &Options{},
|
options: &Options{
|
||||||
|
Logs: logs.NewOptions(),
|
||||||
|
},
|
||||||
expectedError: "no configuration has been provided",
|
expectedError: "no configuration has been provided",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -629,6 +644,7 @@ profiles:
|
|||||||
Deprecated: &DeprecatedOptions{
|
Deprecated: &DeprecatedOptions{
|
||||||
HardPodAffinitySymmetricWeight: 5,
|
HardPodAffinitySymmetricWeight: 5,
|
||||||
},
|
},
|
||||||
|
Logs: logs.NewOptions(),
|
||||||
},
|
},
|
||||||
expectedUsername: "flag",
|
expectedUsername: "flag",
|
||||||
expectedConfig: kubeschedulerconfig.KubeSchedulerConfiguration{
|
expectedConfig: kubeschedulerconfig.KubeSchedulerConfiguration{
|
||||||
@ -680,6 +696,7 @@ profiles:
|
|||||||
SchedulerName: "my-nice-scheduler",
|
SchedulerName: "my-nice-scheduler",
|
||||||
HardPodAffinitySymmetricWeight: 1,
|
HardPodAffinitySymmetricWeight: 1,
|
||||||
},
|
},
|
||||||
|
Logs: logs.NewOptions(),
|
||||||
},
|
},
|
||||||
expectedUsername: "flag",
|
expectedUsername: "flag",
|
||||||
expectedConfig: kubeschedulerconfig.KubeSchedulerConfiguration{
|
expectedConfig: kubeschedulerconfig.KubeSchedulerConfiguration{
|
||||||
@ -735,6 +752,7 @@ profiles:
|
|||||||
name: "unknown field",
|
name: "unknown field",
|
||||||
options: &Options{
|
options: &Options{
|
||||||
ConfigFile: unknownFieldConfig,
|
ConfigFile: unknownFieldConfig,
|
||||||
|
Logs: logs.NewOptions(),
|
||||||
},
|
},
|
||||||
expectedError: "found unknown field: foo",
|
expectedError: "found unknown field: foo",
|
||||||
checkErrFn: runtime.IsStrictDecodingError,
|
checkErrFn: runtime.IsStrictDecodingError,
|
||||||
@ -743,6 +761,7 @@ profiles:
|
|||||||
name: "duplicate fields",
|
name: "duplicate fields",
|
||||||
options: &Options{
|
options: &Options{
|
||||||
ConfigFile: duplicateFieldConfig,
|
ConfigFile: duplicateFieldConfig,
|
||||||
|
Logs: logs.NewOptions(),
|
||||||
},
|
},
|
||||||
expectedError: `key "leaderElect" already set`,
|
expectedError: `key "leaderElect" already set`,
|
||||||
checkErrFn: runtime.IsStrictDecodingError,
|
checkErrFn: runtime.IsStrictDecodingError,
|
||||||
|
Loading…
Reference in New Issue
Block a user