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

feat(operator): accept LogLevels for all controllers #790

Merged
merged 11 commits into from
Feb 22, 2023
Merged
18 changes: 18 additions & 0 deletions helm/chart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ checks
<!-- markdownlint-disable MD012 -->
## Parameters

### Controller Log level

| Name | Description | Value |
| --------------------------------------------------- | -------------------------------------------------------- | ----- |
| `operator.keptnappController.logLevel` | Sets the log level of Keptn App Controller | `0` |
| `operator.keptnappversionController.logLevel` | Sets the log level of Keptn Version Controller | `0` |
| `operator.keptnevaluationController.logLevel` | Sets the log level of Keptn Evaluation Controller | `0` |
| `operator.keptntaskController.logLevel` | Sets the log level of Keptn Task Controller | `0` |
| `operator.keptntaskdefinitionController.logLevel` | Sets the log level of Keptn Task Defintion Controller | `0` |
| `operator.keptnworkloadController.logLevel` | Sets the log level of Keptn Workload Controller | `0` |
| `operator.keptnworkloadinstanceController.logLevel` | Sets the log level of Keptn Workload Instance Controller | `0` |
| `operator.metricsController.logLevel` | Sets the log level of Keptn Metrics Controller | `0` |
| `operator.optionsController.logLevel` | Sets the log level of Keptn Options Controller | `0` |

### OpenTelemetry

| Name | Description | Value |
Expand All @@ -18,3 +32,7 @@ checks
| ---------------------------- | ---------------------------------------------------- | -------- |
| `deployment.imagePullPolicy` | Sets the image pull policy for kubernetes deployment | `Always` |


## Other info

<!-- markdownlint-enable MD012 -->
30 changes: 30 additions & 0 deletions helm/chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,33 @@ otelCollector:

deployment:
imagePullPolicy: Always

## @section Controller Log level
operator:
keptnappController:
## @param operator.keptnappController.logLevel Sets the log level of Keptn App Controller
logLevel: 0
keptnappversionController:
## @param operator.keptnappversionController.logLevel Sets the log level of Keptn Version Controller
logLevel: 0
keptnevaluationController:
## @param operator.keptnevaluationController.logLevel Sets the log level of Keptn Evaluation Controller
logLevel: 0
keptntaskController:
## @param operator.keptntaskController.logLevel Sets the log level of Keptn Task Controller
logLevel: 0
keptntaskdefinitionController:
## @param operator.keptntaskdefinitionController.logLevel Sets the log level of Keptn Task Defintion Controller
logLevel: 0
keptnworkloadController:
## @param operator.keptnworkloadController.logLevel Sets the log level of Keptn Workload Controller
logLevel: 0
keptnworkloadinstanceController:
## @param operator.keptnworkloadinstanceController.logLevel Sets the log level of Keptn Workload Instance Controller
logLevel: 0
metricsController:
## @param operator.metricsController.logLevel Sets the log level of Keptn Metrics Controller
logLevel: 0
optionsController:
## @param operator.optionsController.logLevel Sets the log level of Keptn Options Controller
logLevel: 0
18 changes: 18 additions & 0 deletions helm/overlay/patches/patch_deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,24 @@ spec:
env:
- name: OTEL_COLLECTOR_URL
value: "{{ .Values.otelCollector.url }}"
- name: KEPTN_APP_CONTROLLER_LOG_LEVEL
value: "{{ .Values.operator.keptnappController.logLevel }}"
- name: KEPTN_APP_VERSION_CONTROLLER_LOG_LEVEL
value: "{{ .Values.operator.keptnappversionController.logLevel }}"
- name: KEPTN_EVALUATION_CONTROLLER_LOG_LEVEL
value: "{{ .Values.operator.keptnevaluationController.logLevel }}"
- name: KEPTN_TASK_CONTROLLER_LOG_LEVEL
value: "{{ .Values.operator.keptntaskController.logLevel }}"
- name: KEPTN_TASK_DEFINITION_CONTROLLER_LOG_LEVEL
value: "{{ .Values.operator.keptntaskdefinitionController.logLevel }}"
- name: KEPTN_WORKLOAD_CONTROLLER_LOG_LEVEL
value: "{{ .Values.operator.keptnworkloadController.logLevel }}"
- name: KEPTN_WORKLOAD_INSTANCE_CONTROLLER_LOG_LEVEL
value: "{{ .Values.operator.keptnworkloadinstanceController.logLevel }}"
- name: METRICS_CONTROLLER_LOG_LEVEL
value: "{{ .Values.operator.metricsController.logLevel }}"
- name: OPTIONS_CONTROLLER_LOG_LEVEL
value: "{{ .Values.operator.optionsController.logLevel }}"



Expand Down
37 changes: 28 additions & 9 deletions operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ type envConfig struct {
PodNamespace string `envconfig:"POD_NAMESPACE" default:""`
PodName string `envconfig:"POD_NAME" default:""`
ExposeKeptnMetrics bool `envconfig:"EXPOSE_KEPTN_METRICS" default:"true"`

KeptnAppControllerLogLevel int `envconfig:"KEPTN_APP_CONTROLLER_LOG_LEVEL" default:"0"`
KeptnAppVersionControllerLogLevel int `envconfig:"KEPTN_APP_VERSION_CONTROLLER_LOG_LEVEL" default:"0"`
KeptnEvaluationControllerLogLevel int `envconfig:"KEPTN_EVALUATION_CONTROLLER_LOG_LEVEL" default:"0"`
KeptnTaskControllerLogLevel int `envconfig:"KEPTN_TASK_CONTROLLER_LOG_LEVEL" default:"0"`
KeptnTaskDefinitionControllerLogLevel int `envconfig:"KEPTN_TASK_DEFINITION_CONTROLLER_LOG_LEVEL" default:"0"`
KeptnWorkloadControllerLogLevel int `envconfig:"KEPTN_WORKLOAD_CONTROLLER_LOG_LEVEL" default:"0"`
KeptnWorkloadInstanceControllerLogLevel int `envconfig:"KEPTN_WORKLOAD_INSTANCE_CONTROLLER_LOG_LEVEL" default:"0"`
KeptnMetricControllerLogLevel int `envconfig:"METRICS_CONTROLLER_LOG_LEVEL" default:"0"`
KptnOptionsControllerLogLevel int `envconfig:"OPTIONS_CONTROLLER_LOG_LEVEL" default:"0"`
}

//nolint:funlen,gocognit,gocyclo
Expand Down Expand Up @@ -167,10 +177,11 @@ func main() {

spanHandler := &controllercommon.SpanHandler{}

taskLogger := ctrl.Log.WithName("KeptnTask Controller")
taskReconciler := &keptntask.KeptnTaskReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Log: ctrl.Log.WithName("KeptnTask Controller"),
Log: taskLogger.V(env.KeptnTaskControllerLogLevel),
Recorder: mgr.GetEventRecorderFor("keptntask-controller"),
Meters: keptnMeters,
TracerFactory: controllercommon.GetOtelInstance(),
Expand All @@ -180,21 +191,23 @@ func main() {
os.Exit(1)
}

taskDefinitionLogger := ctrl.Log.WithName("KeptnTaskDefinition Controller")
taskDefinitionReconciler := &keptntaskdefinition.KeptnTaskDefinitionReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Log: ctrl.Log.WithName("KeptnTaskDefinition Controller"),
Log: taskDefinitionLogger.V(env.KeptnTaskDefinitionControllerLogLevel),
Recorder: mgr.GetEventRecorderFor("keptntaskdefinition-controller"),
}
if err = (taskDefinitionReconciler).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "KeptnTaskDefinition")
os.Exit(1)
}

appLogger := ctrl.Log.WithName("KeptnApp Controller")
appReconciler := &keptnapp.KeptnAppReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Log: ctrl.Log.WithName("KeptnApp Controller"),
Log: appLogger.V(env.KeptnAppControllerLogLevel),
Recorder: mgr.GetEventRecorderFor("keptnapp-controller"),
TracerFactory: controllercommon.GetOtelInstance(),
}
Expand All @@ -203,10 +216,11 @@ func main() {
os.Exit(1)
}

workloadLogger := ctrl.Log.WithName("KeptnWorkload Controller")
workloadReconciler := &keptnworkload.KeptnWorkloadReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Log: ctrl.Log.WithName("KeptnWorkload Controller"),
Log: workloadLogger.V(env.KeptnWorkloadControllerLogLevel),
Recorder: mgr.GetEventRecorderFor("keptnworkload-controller"),
TracerFactory: controllercommon.GetOtelInstance(),
}
Expand All @@ -215,10 +229,11 @@ func main() {
os.Exit(1)
}

workloadInstanceLogger := ctrl.Log.WithName("KeptnWorkloadInstance Controller")
workloadInstanceReconciler := &keptnworkloadinstance.KeptnWorkloadInstanceReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Log: ctrl.Log.WithName("KeptnWorkloadInstance Controller"),
Log: workloadInstanceLogger.V(env.KeptnWorkloadInstanceControllerLogLevel),
Recorder: mgr.GetEventRecorderFor("keptnworkloadinstance-controller"),
Meters: keptnMeters,
TracerFactory: controllercommon.GetOtelInstance(),
Expand All @@ -229,10 +244,11 @@ func main() {
os.Exit(1)
}

appVersionLogger := ctrl.Log.WithName("KeptnAppVersion Controller")
appVersionReconciler := &keptnappversion.KeptnAppVersionReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Log: ctrl.Log.WithName("KeptnAppVersion Controller"),
Log: appVersionLogger.V(env.KeptnAppVersionControllerLogLevel),
Recorder: mgr.GetEventRecorderFor("keptnappversion-controller"),
TracerFactory: controllercommon.GetOtelInstance(),
Meters: keptnMeters,
Expand All @@ -243,10 +259,11 @@ func main() {
os.Exit(1)
}

evaluationLogger := ctrl.Log.WithName("KeptnEvaluation Controller")
evaluationReconciler := &keptnevaluation.KeptnEvaluationReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Log: ctrl.Log.WithName("KeptnEvaluation Controller"),
Log: evaluationLogger.V(env.KeptnEvaluationControllerLogLevel),
Recorder: mgr.GetEventRecorderFor("keptnevaluation-controller"),
TracerFactory: controllercommon.GetOtelInstance(),
Meters: keptnMeters,
Expand All @@ -257,20 +274,22 @@ func main() {
os.Exit(1)
}

metricsLogger := ctrl.Log.WithName("KeptnMetric Controller")
metricsReconciler := &keptnmetric.KeptnMetricReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Log: ctrl.Log.WithName("KeptnMetric Controller"),
Log: metricsLogger.V(env.KeptnMetricControllerLogLevel),
}
if err = (metricsReconciler).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "KeptnMetric")
os.Exit(1)
}

configLogger := ctrl.Log.WithName("KeptnConfig Controller")
configReconciler := &controlleroptions.KeptnConfigReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Log: ctrl.Log.WithName("KeptnConfig Controller"),
Log: configLogger.V(env.KptnOptionsControllerLogLevel),
}
if err = (configReconciler).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "KeptnConfig")
Expand Down