Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pick #3688 apiserver: move loglevel under spec #3689

Open
wants to merge 2 commits into
base: release-v1.37
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions api/v1/apiserver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
9 changes: 8 additions & 1 deletion api/v1/common_types.go
Original file line number Diff line number Diff line change
@@ -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");
Expand Down Expand Up @@ -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 (
Expand Down
35 changes: 30 additions & 5 deletions api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 26 additions & 10 deletions pkg/crds/operator/operator.tigera.io_apiservers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
37 changes: 10 additions & 27 deletions pkg/render/apiserver.go
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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"})
Expand Down Expand Up @@ -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"})
Expand Down