Skip to content

Commit

Permalink
apiserver: move loglevel under spec
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-afra committed Jan 9, 2025
1 parent 2facd57 commit 9a53897
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 47 deletions.
15 changes: 10 additions & 5 deletions api/v1/apiserver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ import (

// APIServerSpec defines the desired state of Tigera API server.
type APIServerSpec struct {
// +kubebuilder:validation:Enum=Fatal;Error;Warn;Info;Debug;Trace
// +kubebuilder:default=Info
// +optional
ApiServerLogLevel *string `json:"apiServerLogLevel,omitempty"`

// +kubebuilder:validation:Enum=Fatal;Error;Warn;Info;Debug;Trace
// +kubebuilder:default=Info
// +optional
QueryServerLogLevel *string `json:"queryServerLogLevel,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 +96,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
15 changes: 10 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.

30 changes: 20 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,26 @@ spec:
type: object
type: object
type: object
apiServerLogLevel:
default: Info
enum:
- Fatal
- Error
- Warn
- Info
- Debug
- Trace
type: string
queryServerLogLevel:
default: Info
enum:
- Fatal
- Error
- Warn
- Info
- Debug
- Trace
type: string
type: object
status:
description: Most recently observed status for the Tigera API server.
Expand Down
35 changes: 8 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,9 @@ 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 logLevel := c.cfg.APIServer.ApiServerLogLevel; logLevel != nil {
env = append(env, corev1.EnvVar{Name: "LOG_LEVEL", Value: strings.ToLower(*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 +1292,8 @@ 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 logLevel := c.cfg.APIServer.QueryServerLogLevel; logLevel != nil {
env = append(env, corev1.EnvVar{Name: "LOGLEVEL", Value: strings.ToLower(*logLevel)})
} else {
// set default LOGLEVEL to info when not set by the user
env = append(env, corev1.EnvVar{Name: "LOGLEVEL", Value: "info"})
Expand Down

0 comments on commit 9a53897

Please sign in to comment.