diff --git a/api/v1/apiserver_types.go b/api/v1/apiserver_types.go index 9a82d76305..22a6488192 100644 --- a/api/v1/apiserver_types.go +++ b/api/v1/apiserver_types.go @@ -25,6 +25,12 @@ import ( // APIServerSpec defines the desired state of Tigera API server. type APIServerSpec struct { + // +optional + APIServerLogOptions *LogOptions `json:"apiServerLogging,omitempty"` + + // +optional + QueryServerLogOptions *LogOptions `json:"queryServerLogging,omitempty"` + // APIServerDeployment configures the calico-apiserver (or tigera-apiserver in Enterprise) Deployment. If // used in conjunction with ControlPlaneNodeSelector or ControlPlaneTolerations, then these overrides // take precedence. @@ -86,11 +92,6 @@ type APIServerDeploymentContainer struct { // If used in conjunction with the deprecated ComponentResources, then this value takes precedence. // +optional Resources *v1.ResourceRequirements `json:"resources,omitempty"` - - // +kubebuilder:validation:Enum=Fatal;Error;Warn;Info;Debug;Trace - // +kubebuilder:default=Info - // +optional - LogLevel *string `json:"logLevel,omitempty"` } // APIServerDeploymentInitContainer is an API server Deployment init container. diff --git a/api/v1/common_types.go b/api/v1/common_types.go index a74e6776d7..6f7948a503 100644 --- a/api/v1/common_types.go +++ b/api/v1/common_types.go @@ -1,4 +1,4 @@ -// Copyright (c) 2022, 2023 Tigera, Inc. All rights reserved. +// Copyright (c) 2022 - 2025 Tigera, Inc. All rights reserved. /* Licensed under the Apache License, Version 2.0 (the "License"); @@ -31,6 +31,13 @@ type Metadata struct { Annotations map[string]string `json:"annotations,omitempty"` } +type LogOptions struct { + // +kubebuilder:validation:Enum=Fatal;Error;Warn;Info;Debug;Trace + // +kubebuilder:default=Info + // +optional + LogLevel *LogLevel `json:"logLevel,omitempty"` +} + type LogLevel string const ( diff --git a/api/v1/zz_generated.deepcopy.go b/api/v1/zz_generated.deepcopy.go index 69307ba009..f7e33d37cd 100644 --- a/api/v1/zz_generated.deepcopy.go +++ b/api/v1/zz_generated.deepcopy.go @@ -88,11 +88,6 @@ func (in *APIServerDeploymentContainer) DeepCopyInto(out *APIServerDeploymentCon *out = new(corev1.ResourceRequirements) (*in).DeepCopyInto(*out) } - if in.LogLevel != nil { - in, out := &in.LogLevel, &out.LogLevel - *out = new(string) - **out = **in - } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new APIServerDeploymentContainer. @@ -265,6 +260,16 @@ func (in *APIServerList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *APIServerSpec) DeepCopyInto(out *APIServerSpec) { *out = *in + if in.APIServerLogOptions != nil { + in, out := &in.APIServerLogOptions, &out.APIServerLogOptions + *out = new(LogOptions) + (*in).DeepCopyInto(*out) + } + if in.QueryServerLogOptions != nil { + in, out := &in.QueryServerLogOptions, &out.QueryServerLogOptions + *out = new(LogOptions) + (*in).DeepCopyInto(*out) + } if in.APIServerDeployment != nil { in, out := &in.APIServerDeployment, &out.APIServerDeployment *out = new(APIServerDeployment) @@ -5785,6 +5790,26 @@ func (in *LogCollectorStatus) DeepCopy() *LogCollectorStatus { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *LogOptions) DeepCopyInto(out *LogOptions) { + *out = *in + if in.LogLevel != nil { + in, out := &in.LogLevel, &out.LogLevel + *out = new(LogLevel) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LogOptions. +func (in *LogOptions) DeepCopy() *LogOptions { + if in == nil { + return nil + } + out := new(LogOptions) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *LogStorage) DeepCopyInto(out *LogStorage) { *out = *in diff --git a/pkg/crds/operator/operator.tigera.io_apiservers.yaml b/pkg/crds/operator/operator.tigera.io_apiservers.yaml index ad220193f7..0f0083c1b8 100644 --- a/pkg/crds/operator/operator.tigera.io_apiservers.yaml +++ b/pkg/crds/operator/operator.tigera.io_apiservers.yaml @@ -1068,16 +1068,6 @@ spec: description: APIServerDeploymentContainer is an API server Deployment container. properties: - logLevel: - default: Info - enum: - - Fatal - - Error - - Warn - - Info - - Debug - - Trace - type: string name: description: |- Name is an enum which identifies the API server Deployment container by name. @@ -1458,6 +1448,32 @@ spec: type: object type: object type: object + apiServerLogging: + properties: + logLevel: + default: Info + enum: + - Fatal + - Error + - Warn + - Info + - Debug + - Trace + type: string + type: object + queryServerLogging: + properties: + logLevel: + default: Info + enum: + - Fatal + - Error + - Warn + - Info + - Debug + - Trace + type: string + type: object type: object status: description: Most recently observed status for the Tigera API server. diff --git a/pkg/render/apiserver.go b/pkg/render/apiserver.go index b1e78a7f34..a83e50b9e9 100644 --- a/pkg/render/apiserver.go +++ b/pkg/render/apiserver.go @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2024 Tigera, Inc. All rights reserved. +// Copyright (c) 2019-2025 Tigera, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -19,8 +19,6 @@ import ( "net/url" "strings" - v3 "github.com/tigera/api/pkg/apis/projectcalico/v3" - "github.com/tigera/api/pkg/lib/numorstring" admregv1 "k8s.io/api/admissionregistration/v1" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" @@ -32,6 +30,8 @@ import ( apiregv1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1" "sigs.k8s.io/controller-runtime/pkg/client" + v3 "github.com/tigera/api/pkg/apis/projectcalico/v3" + "github.com/tigera/api/pkg/lib/numorstring" operatorv1 "github.com/tigera/operator/api/v1" "github.com/tigera/operator/pkg/common" "github.com/tigera/operator/pkg/components" @@ -1194,18 +1194,10 @@ func (c *apiServerComponent) apiServerContainer() corev1.Container { env = append(env, c.cfg.K8SServiceEndpoint.EnvVars(c.hostNetwork(), c.cfg.Installation.KubernetesProvider)...) // set Log_LEVEL for apiserver container - if c.cfg.APIServer.APIServerDeployment != nil && c.cfg.APIServer.APIServerDeployment.Spec != nil && - c.cfg.APIServer.APIServerDeployment.Spec.Template != nil && - c.cfg.APIServer.APIServerDeployment.Spec.Template.Spec != nil && - c.cfg.APIServer.APIServerDeployment.Spec.Template.Spec.Containers != nil { - containers := c.cfg.APIServer.APIServerDeployment.Spec.Template.Spec.Containers - for _, con := range containers { - if strings.Contains(con.Name, "apiserver") { - if logLevel := con.LogLevel; logLevel != nil { - env = append(env, corev1.EnvVar{Name: "LOG_LEVEL", Value: strings.ToLower(*logLevel)}) - } - } - } + + if logOptions := c.cfg.APIServer.APIServerLogOptions; logOptions != nil && + logOptions.LogLevel != nil { + env = append(env, corev1.EnvVar{Name: "LOG_LEVEL", Value: strings.ToLower(string(*logOptions.LogLevel))}) } else { // set default LOG_LEVEL to info when not set by the user env = append(env, corev1.EnvVar{Name: "LOG_LEVEL", Value: "info"}) @@ -1301,18 +1293,9 @@ func (c *apiServerComponent) queryServerContainer() corev1.Container { } // set Log_LEVEL for queryserver container - if c.cfg.APIServer.APIServerDeployment != nil && c.cfg.APIServer.APIServerDeployment.Spec != nil && - c.cfg.APIServer.APIServerDeployment.Spec.Template != nil && - c.cfg.APIServer.APIServerDeployment.Spec.Template.Spec != nil && - c.cfg.APIServer.APIServerDeployment.Spec.Template.Spec.Containers != nil { - containers := c.cfg.APIServer.APIServerDeployment.Spec.Template.Spec.Containers - for _, con := range containers { - if strings.Contains(con.Name, "queryserver") { - if logLevel := con.LogLevel; logLevel != nil { - env = append(env, corev1.EnvVar{Name: "LOGLEVEL", Value: strings.ToLower(*logLevel)}) - } - } - } + if logOptions := c.cfg.APIServer.QueryServerLogOptions; logOptions != nil && + logOptions.LogLevel != nil { + env = append(env, corev1.EnvVar{Name: "LOGLEVEL", Value: strings.ToLower(string(*logOptions.LogLevel))}) } else { // set default LOGLEVEL to info when not set by the user env = append(env, corev1.EnvVar{Name: "LOGLEVEL", Value: "info"})