From 43dc375ced96668b4be559716b55cd482cb85f22 Mon Sep 17 00:00:00 2001 From: dntosas Date: Sun, 23 May 2021 23:17:12 +0300 Subject: [PATCH] Add support for logging-format option (text/json) Signed-off-by: dntosas --- docs/cluster_spec.md | 42 ++++++++++++++++++- k8s/crds/kops.k8s.io_clusters.yaml | 20 +++++++++ k8s/crds/kops.k8s.io_instancegroups.yaml | 4 ++ pkg/apis/kops/componentconfig.go | 16 +++++++ pkg/apis/kops/v1alpha2/componentconfig.go | 16 +++++++ .../kops/v1alpha2/zz_generated.conversion.go | 8 ++++ pkg/apis/kops/validation/validation.go | 9 ++++ pkg/apis/kops/validation/validation_test.go | 6 +++ 8 files changed, 120 insertions(+), 1 deletion(-) diff --git a/docs/cluster_spec.md b/docs/cluster_spec.md index 3a7eb4e873..dd469dd33e 100644 --- a/docs/cluster_spec.md +++ b/docs/cluster_spec.md @@ -554,6 +554,16 @@ spec: defaultUnreachableTolerationSeconds: 600 ``` +### LogFormat + +Choose between log format. Permitted formats: "json", "text". Default: "text". + +```yaml +spec: + kubeAPIServer: + logFormat: json +``` + ## externalDns This block contains configuration options for your `external-DNS` provider. @@ -698,6 +708,16 @@ spec: eventBurst: 10 ``` +### LogFormat + +Choose between log format. Permitted formats: "json", "text". Default: "text". + +```yaml +spec: + kubelet: + logFormat: json +``` + ## kubeScheduler This block contains configurations for `kube-scheduler`. See https://kubernetes.io/docs/admin/kube-scheduler/ @@ -713,6 +733,16 @@ Will make kube-scheduler use the scheduler policy from configmap "scheduler-poli Note that as of Kubernetes 1.8.0 kube-scheduler does not reload its configuration from configmap automatically. You will need to ssh into the master instance and restart the Docker container manually. +### LogFormat + +Choose between log format. Permitted formats: "json", "text". Default: "text". + +```yaml +spec: + kubeScheduler: + logFormat: json +``` + ## kubeDNS This block contains configurations for [CoreDNS](https://coredns.io/). @@ -795,6 +825,16 @@ spec: For more details on `horizontalPodAutoscaler` flags see the [official HPA docs](https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/) and the [kOps guides on how to set it up](horizontal_pod_autoscaling.md). +### LogFormat + +Choose between log format. Permitted formats: "json", "text". Default: "text". + +```yaml +spec: + kubeControllerManager: + logFormat: json +``` + ## Feature Gates Feature gates can be configured on the kubelet. @@ -1322,7 +1362,7 @@ The `discoveryStore` option causes kOps to publish an OIDC-compatible discovery to a path in an S3 bucket. This would ordinarily be a different bucket than the state store. kOps will automatically configure `spec.kubeAPIServer.serviceAccountIssuer` and default `spec.kubeAPIServer.serviceAccountJWKSURI` to the corresponding -HTTPS URL. +HTTPS URL. The `enableAWSOIDCProvider` configures AWS to trust the service account issuer to authenticate service accounts for IAM Roles for Service Accounts (IRSA). In order for this to work, diff --git a/k8s/crds/kops.k8s.io_clusters.yaml b/k8s/crds/kops.k8s.io_clusters.yaml index d98c9031e7..4b88b62bbb 100644 --- a/k8s/crds/kops.k8s.io_clusters.yaml +++ b/k8s/crds/kops.k8s.io_clusters.yaml @@ -1510,6 +1510,10 @@ spec: items: type: string type: array + logFormat: + description: 'LogFormat is the logging format of the api. Supported + values: text, json. Default: text' + type: string logLevel: description: LogLevel is the logging level of the api format: int32 @@ -1917,6 +1921,10 @@ spec: is enabled. type: string type: object + logFormat: + description: 'LogFormat is the logging format of the controler + manager. Supported values: text, json. Default: text' + type: string logLevel: description: LogLevel is the defined logLevel format: int32 @@ -2259,6 +2267,10 @@ spec: is enabled. type: string type: object + logFormat: + description: 'LogFormat is the logging format of the scheduler. + Supported values: text, json. Default: text' + type: string logLevel: description: LogLevel is the logging level format: int32 @@ -2504,6 +2516,10 @@ spec: description: KubeletCgroups is the absolute name of cgroups to isolate the kubelet in. type: string + logFormat: + description: 'LogFormat is the logging format of the kubelet. + Supported values: text, json. Default: text' + type: string logLevel: description: LogLevel is the logging level of the kubelet format: int32 @@ -2910,6 +2926,10 @@ spec: description: KubeletCgroups is the absolute name of cgroups to isolate the kubelet in. type: string + logFormat: + description: 'LogFormat is the logging format of the kubelet. + Supported values: text, json. Default: text' + type: string logLevel: description: LogLevel is the logging level of the kubelet format: int32 diff --git a/k8s/crds/kops.k8s.io_instancegroups.yaml b/k8s/crds/kops.k8s.io_instancegroups.yaml index b4335ba1ca..d8388b4619 100644 --- a/k8s/crds/kops.k8s.io_instancegroups.yaml +++ b/k8s/crds/kops.k8s.io_instancegroups.yaml @@ -470,6 +470,10 @@ spec: description: KubeletCgroups is the absolute name of cgroups to isolate the kubelet in. type: string + logFormat: + description: 'LogFormat is the logging format of the kubelet. + Supported values: text, json. Default: text' + type: string logLevel: description: LogLevel is the logging level of the kubelet format: int32 diff --git a/pkg/apis/kops/componentconfig.go b/pkg/apis/kops/componentconfig.go index 8c52f8b937..a625c9851e 100644 --- a/pkg/apis/kops/componentconfig.go +++ b/pkg/apis/kops/componentconfig.go @@ -45,6 +45,10 @@ type KubeletConfigSpec struct { KubeconfigPath string `json:"kubeconfigPath,omitempty" flag:"kubeconfig"` // RequireKubeconfig indicates a kubeconfig is required RequireKubeconfig *bool `json:"requireKubeconfig,omitempty" flag:"require-kubeconfig"` + // LogFormat is the logging format of the kubelet. + // Supported values: text, json. + // Default: text + LogFormat string `json:"logFormat,omitempty" flag:"logging-format" flag-empty:"text"` // LogLevel is the logging level of the kubelet LogLevel *int32 `json:"logLevel,omitempty" flag:"v" flag-empty:"0"` // config is the path to the config file or directory of files @@ -269,6 +273,10 @@ type KubeAPIServerConfig struct { Image string `json:"image,omitempty"` // DisableBasicAuth removes the --basic-auth-file flag DisableBasicAuth *bool `json:"disableBasicAuth,omitempty"` + // LogFormat is the logging format of the api. + // Supported values: text, json. + // Default: text + LogFormat string `json:"logFormat,omitempty" flag:"logging-format" flag-empty:"text"` // LogLevel is the logging level of the api LogLevel int32 `json:"logLevel,omitempty" flag:"v" flag-empty:"0"` // CloudProvider is the name of the cloudProvider we are using, aws, gce etcd @@ -511,6 +519,10 @@ type KubeAPIServerConfig struct { type KubeControllerManagerConfig struct { // Master is the url for the kube api master Master string `json:"master,omitempty" flag:"master"` + // LogFormat is the logging format of the controler manager. + // Supported values: text, json. + // Default: text + LogFormat string `json:"logFormat,omitempty" flag:"logging-format" flag-empty:"text"` // LogLevel is the defined logLevel LogLevel int32 `json:"logLevel,omitempty" flag:"v" flag-empty:"0"` // ServiceAccountPrivateKeyFile is the location of the private key for service account token signing. @@ -663,6 +675,10 @@ type CloudControllerManagerConfig struct { type KubeSchedulerConfig struct { // Master is a url to the kube master Master string `json:"master,omitempty" flag:"master"` + // LogFormat is the logging format of the scheduler. + // Supported values: text, json. + // Default: text + LogFormat string `json:"logFormat,omitempty" flag:"logging-format" flag-empty:"text"` // LogLevel is the logging level LogLevel int32 `json:"logLevel,omitempty" flag:"v"` // Image is the docker image to use diff --git a/pkg/apis/kops/v1alpha2/componentconfig.go b/pkg/apis/kops/v1alpha2/componentconfig.go index 5866a5a285..a2822faeec 100644 --- a/pkg/apis/kops/v1alpha2/componentconfig.go +++ b/pkg/apis/kops/v1alpha2/componentconfig.go @@ -45,6 +45,10 @@ type KubeletConfigSpec struct { KubeconfigPath string `json:"kubeconfigPath,omitempty" flag:"kubeconfig"` // RequireKubeconfig indicates a kubeconfig is required RequireKubeconfig *bool `json:"requireKubeconfig,omitempty" flag:"require-kubeconfig"` + // LogFormat is the logging format of the kubelet. + // Supported values: text, json. + // Default: text + LogFormat string `json:"logFormat,omitempty" flag:"logging-format" flag-empty:"text"` // LogLevel is the logging level of the kubelet LogLevel *int32 `json:"logLevel,omitempty" flag:"v" flag-empty:"0"` // config is the path to the config file or directory of files @@ -269,6 +273,10 @@ type KubeAPIServerConfig struct { Image string `json:"image,omitempty"` // DisableBasicAuth removes the --basic-auth-file flag DisableBasicAuth *bool `json:"disableBasicAuth,omitempty"` + // LogFormat is the logging format of the api. + // Supported values: text, json. + // Default: text + LogFormat string `json:"logFormat,omitempty" flag:"logging-format" flag-empty:"text"` // LogLevel is the logging level of the api LogLevel int32 `json:"logLevel,omitempty" flag:"v" flag-empty:"0"` // CloudProvider is the name of the cloudProvider we are using, aws, gce etcd @@ -511,6 +519,10 @@ type KubeAPIServerConfig struct { type KubeControllerManagerConfig struct { // Master is the url for the kube api master Master string `json:"master,omitempty" flag:"master"` + // LogFormat is the logging format of the controler manager. + // Supported values: text, json. + // Default: text + LogFormat string `json:"logFormat,omitempty" flag:"logging-format" flag-empty:"text"` // LogLevel is the defined logLevel LogLevel int32 `json:"logLevel,omitempty" flag:"v" flag-empty:"0"` // ServiceAccountPrivateKeyFile is the location of the private key for service account token signing. @@ -662,6 +674,10 @@ type CloudControllerManagerConfig struct { type KubeSchedulerConfig struct { // Master is a url to the kube master Master string `json:"master,omitempty" flag:"master"` + // LogFormat is the logging format of the scheduler. + // Supported values: text, json. + // Default: text + LogFormat string `json:"logFormat,omitempty" flag:"logging-format" flag-empty:"text"` // LogLevel is the logging level LogLevel int32 `json:"logLevel,omitempty" flag:"v"` // Image is the docker image to use diff --git a/pkg/apis/kops/v1alpha2/zz_generated.conversion.go b/pkg/apis/kops/v1alpha2/zz_generated.conversion.go index 60c526f31a..47423814ea 100644 --- a/pkg/apis/kops/v1alpha2/zz_generated.conversion.go +++ b/pkg/apis/kops/v1alpha2/zz_generated.conversion.go @@ -4533,6 +4533,7 @@ func Convert_kops_KopeioNetworkingSpec_To_v1alpha2_KopeioNetworkingSpec(in *kops func autoConvert_v1alpha2_KubeAPIServerConfig_To_kops_KubeAPIServerConfig(in *KubeAPIServerConfig, out *kops.KubeAPIServerConfig, s conversion.Scope) error { out.Image = in.Image out.DisableBasicAuth = in.DisableBasicAuth + out.LogFormat = in.LogFormat out.LogLevel = in.LogLevel out.CloudProvider = in.CloudProvider out.SecurePort = in.SecurePort @@ -4643,6 +4644,7 @@ func Convert_v1alpha2_KubeAPIServerConfig_To_kops_KubeAPIServerConfig(in *KubeAP func autoConvert_kops_KubeAPIServerConfig_To_v1alpha2_KubeAPIServerConfig(in *kops.KubeAPIServerConfig, out *KubeAPIServerConfig, s conversion.Scope) error { out.Image = in.Image out.DisableBasicAuth = in.DisableBasicAuth + out.LogFormat = in.LogFormat out.LogLevel = in.LogLevel out.CloudProvider = in.CloudProvider out.SecurePort = in.SecurePort @@ -4752,6 +4754,7 @@ func Convert_kops_KubeAPIServerConfig_To_v1alpha2_KubeAPIServerConfig(in *kops.K func autoConvert_v1alpha2_KubeControllerManagerConfig_To_kops_KubeControllerManagerConfig(in *KubeControllerManagerConfig, out *kops.KubeControllerManagerConfig, s conversion.Scope) error { out.Master = in.Master + out.LogFormat = in.LogFormat out.LogLevel = in.LogLevel out.ServiceAccountPrivateKeyFile = in.ServiceAccountPrivateKeyFile out.Image = in.Image @@ -4818,6 +4821,7 @@ func Convert_v1alpha2_KubeControllerManagerConfig_To_kops_KubeControllerManagerC func autoConvert_kops_KubeControllerManagerConfig_To_v1alpha2_KubeControllerManagerConfig(in *kops.KubeControllerManagerConfig, out *KubeControllerManagerConfig, s conversion.Scope) error { out.Master = in.Master + out.LogFormat = in.LogFormat out.LogLevel = in.LogLevel out.ServiceAccountPrivateKeyFile = in.ServiceAccountPrivateKeyFile out.Image = in.Image @@ -5008,6 +5012,7 @@ func Convert_kops_KubeProxyConfig_To_v1alpha2_KubeProxyConfig(in *kops.KubeProxy func autoConvert_v1alpha2_KubeSchedulerConfig_To_kops_KubeSchedulerConfig(in *KubeSchedulerConfig, out *kops.KubeSchedulerConfig, s conversion.Scope) error { out.Master = in.Master + out.LogFormat = in.LogFormat out.LogLevel = in.LogLevel out.Image = in.Image if in.LeaderElection != nil { @@ -5038,6 +5043,7 @@ func Convert_v1alpha2_KubeSchedulerConfig_To_kops_KubeSchedulerConfig(in *KubeSc func autoConvert_kops_KubeSchedulerConfig_To_v1alpha2_KubeSchedulerConfig(in *kops.KubeSchedulerConfig, out *KubeSchedulerConfig, s conversion.Scope) error { out.Master = in.Master + out.LogFormat = in.LogFormat out.LogLevel = in.LogLevel out.Image = in.Image if in.LeaderElection != nil { @@ -5078,6 +5084,7 @@ func autoConvert_v1alpha2_KubeletConfigSpec_To_kops_KubeletConfigSpec(in *Kubele out.TLSMinVersion = in.TLSMinVersion out.KubeconfigPath = in.KubeconfigPath out.RequireKubeconfig = in.RequireKubeconfig + out.LogFormat = in.LogFormat out.LogLevel = in.LogLevel out.PodManifestPath = in.PodManifestPath out.HostnameOverride = in.HostnameOverride @@ -5172,6 +5179,7 @@ func autoConvert_kops_KubeletConfigSpec_To_v1alpha2_KubeletConfigSpec(in *kops.K out.TLSMinVersion = in.TLSMinVersion out.KubeconfigPath = in.KubeconfigPath out.RequireKubeconfig = in.RequireKubeconfig + out.LogFormat = in.LogFormat out.LogLevel = in.LogLevel out.PodManifestPath = in.PodManifestPath out.HostnameOverride = in.HostnameOverride diff --git a/pkg/apis/kops/validation/validation.go b/pkg/apis/kops/validation/validation.go index a72d0e4d0c..ac3c8333a0 100644 --- a/pkg/apis/kops/validation/validation.go +++ b/pkg/apis/kops/validation/validation.go @@ -564,6 +564,11 @@ func validateKubeAPIServer(v *kops.KubeAPIServerConfig, c *kops.Cluster, fldPath } } } + + if v.LogFormat != "" { + allErrs = append(allErrs, IsValidValue(fldPath.Child("logFormat"), &v.LogFormat, []string{"text", "json"})...) + } + return allErrs } @@ -627,6 +632,10 @@ func validateKubelet(k *kops.KubeletConfigSpec, c *kops.Cluster, kubeletPath *fi } } + if k.LogFormat != "" { + allErrs = append(allErrs, IsValidValue(kubeletPath.Child("logFormat"), &k.LogFormat, []string{"text", "json"})...) + } + } return allErrs } diff --git a/pkg/apis/kops/validation/validation_test.go b/pkg/apis/kops/validation/validation_test.go index 79b03f7d44..9cfe204428 100644 --- a/pkg/apis/kops/validation/validation_test.go +++ b/pkg/apis/kops/validation/validation_test.go @@ -289,6 +289,12 @@ func TestValidateKubeAPIServer(t *testing.T) { "Unsupported value::KubeAPIServer.authorizationMode", }, }, + { + Input: kops.KubeAPIServerConfig{ + LogFormat: "no-json", + }, + ExpectedErrors: []string{"Unsupported value::KubeAPIServer.logFormat"}, + }, } for _, g := range grid { if g.Cluster == nil {