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

components, logger: use contextual logging approach #1253

Open
wants to merge 1 commit into
base: incubation
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
3 changes: 1 addition & 2 deletions components/codeflare/codeflare.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"fmt"
"path/filepath"

"github.com/go-logr/logr"
operatorv1 "github.com/openshift/api/operator/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -74,11 +73,11 @@ func (c *CodeFlare) GetComponentName() string {

func (c *CodeFlare) ReconcileComponent(ctx context.Context,
cli client.Client,
l logr.Logger,
owner metav1.Object,
dscispec *dsciv1.DSCInitializationSpec,
platform cluster.Platform,
_ bool) error {
l := logf.FromContext(ctx)
enabled := c.GetManagementState() == operatorv1.Managed
monitoringEnabled := dscispec.Monitoring.ManagementState == operatorv1.Managed

Expand Down
2 changes: 1 addition & 1 deletion components/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ type ManifestsConfig struct {

type ComponentInterface interface {
Init(ctx context.Context, platform cluster.Platform) error
ReconcileComponent(ctx context.Context, cli client.Client, logger logr.Logger,
ReconcileComponent(ctx context.Context, cli client.Client,
owner metav1.Object, DSCISpec *dsciv1.DSCInitializationSpec, platform cluster.Platform, currentComponentStatus bool) error
Cleanup(ctx context.Context, cli client.Client, owner metav1.Object, DSCISpec *dsciv1.DSCInitializationSpec) error
GetComponentName() string
Expand Down
2 changes: 1 addition & 1 deletion components/dashboard/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ func (d *Dashboard) GetComponentName() string {

func (d *Dashboard) ReconcileComponent(ctx context.Context,
cli client.Client,
l logr.Logger,
owner metav1.Object,
dscispec *dsciv1.DSCInitializationSpec,
platform cluster.Platform,
currentComponentExist bool,
) error {
entryPath := DefaultPath
l := logf.FromContext(ctx)
enabled := d.GetManagementState() == operatorv1.Managed
monitoringEnabled := dscispec.Monitoring.ManagementState == operatorv1.Managed

Expand Down
3 changes: 1 addition & 2 deletions components/datasciencepipelines/datasciencepipelines.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"fmt"
"path/filepath"

"github.com/go-logr/logr"
operatorv1 "github.com/openshift/api/operator/v1"
conditionsv1 "github.com/openshift/custom-resource-status/conditions/v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -95,12 +94,12 @@ func (d *DataSciencePipelines) GetComponentName() string {

func (d *DataSciencePipelines) ReconcileComponent(ctx context.Context,
cli client.Client,
l logr.Logger,
owner metav1.Object,
dscispec *dsciv1.DSCInitializationSpec,
platform cluster.Platform,
_ bool,
) error {
l := logf.FromContext(ctx)
enabled := d.GetManagementState() == operatorv1.Managed
monitoringEnabled := dscispec.Monitoring.ManagementState == operatorv1.Managed

Expand Down
4 changes: 2 additions & 2 deletions components/kserve/kserve.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"path/filepath"
"strings"

"github.com/go-logr/logr"
operatorv1 "github.com/openshift/api/operator/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -112,7 +111,8 @@ func (k *Kserve) GetComponentName() string {
}

func (k *Kserve) ReconcileComponent(ctx context.Context, cli client.Client,
l logr.Logger, owner metav1.Object, dscispec *dsciv1.DSCInitializationSpec, platform cluster.Platform, _ bool) error {
owner metav1.Object, dscispec *dsciv1.DSCInitializationSpec, platform cluster.Platform, _ bool) error {
l := logf.FromContext(ctx)
enabled := k.GetManagementState() == operatorv1.Managed
monitoringEnabled := dscispec.Monitoring.ManagementState == operatorv1.Managed

Expand Down
4 changes: 2 additions & 2 deletions components/kueue/kueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"path/filepath"

"github.com/go-logr/logr"
operatorv1 "github.com/openshift/api/operator/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -68,8 +67,9 @@ func (k *Kueue) GetComponentName() string {
return ComponentName
}

func (k *Kueue) ReconcileComponent(ctx context.Context, cli client.Client, l logr.Logger,
func (k *Kueue) ReconcileComponent(ctx context.Context, cli client.Client,
owner metav1.Object, dscispec *dsciv1.DSCInitializationSpec, platform cluster.Platform, _ bool) error {
l := logf.FromContext(ctx)
enabled := k.GetManagementState() == operatorv1.Managed
monitoringEnabled := dscispec.Monitoring.ManagementState == operatorv1.Managed
if enabled {
Expand Down
3 changes: 1 addition & 2 deletions components/modelmeshserving/modelmeshserving.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"path/filepath"
"strings"

"github.com/go-logr/logr"
operatorv1 "github.com/openshift/api/operator/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -103,12 +102,12 @@ func (m *ModelMeshServing) GetComponentName() string {

func (m *ModelMeshServing) ReconcileComponent(ctx context.Context,
cli client.Client,
l logr.Logger,
owner metav1.Object,
dscispec *dsciv1.DSCInitializationSpec,
platform cluster.Platform,
_ bool,
) error {
l := logf.FromContext(ctx)
enabled := m.GetManagementState() == operatorv1.Managed
monitoringEnabled := dscispec.Monitoring.ManagementState == operatorv1.Managed

Expand Down
4 changes: 2 additions & 2 deletions components/modelregistry/modelregistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"strings"
"text/template"

"github.com/go-logr/logr"
operatorv1 "github.com/openshift/api/operator/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -97,8 +96,9 @@ func (m *ModelRegistry) GetComponentName() string {
return ComponentName
}

func (m *ModelRegistry) ReconcileComponent(ctx context.Context, cli client.Client, l logr.Logger,
func (m *ModelRegistry) ReconcileComponent(ctx context.Context, cli client.Client,
owner metav1.Object, dscispec *dsciv1.DSCInitializationSpec, platform cluster.Platform, _ bool) error {
l := logf.FromContext(ctx)
enabled := m.GetManagementState() == operatorv1.Managed
monitoringEnabled := dscispec.Monitoring.ManagementState == operatorv1.Managed

Expand Down
4 changes: 2 additions & 2 deletions components/ray/ray.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"fmt"
"path/filepath"

"github.com/go-logr/logr"
operatorv1 "github.com/openshift/api/operator/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -69,8 +68,9 @@ func (r *Ray) GetComponentName() string {
return ComponentName
}

func (r *Ray) ReconcileComponent(ctx context.Context, cli client.Client, l logr.Logger,
func (r *Ray) ReconcileComponent(ctx context.Context, cli client.Client,
owner metav1.Object, dscispec *dsciv1.DSCInitializationSpec, platform cluster.Platform, _ bool) error {
l := logf.FromContext(ctx)
enabled := r.GetManagementState() == operatorv1.Managed
monitoringEnabled := dscispec.Monitoring.ManagementState == operatorv1.Managed

Expand Down
4 changes: 2 additions & 2 deletions components/trainingoperator/trainingoperator.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"fmt"
"path/filepath"

"github.com/go-logr/logr"
operatorv1 "github.com/openshift/api/operator/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -70,8 +69,9 @@ func (r *TrainingOperator) GetComponentName() string {
return ComponentName
}

func (r *TrainingOperator) ReconcileComponent(ctx context.Context, cli client.Client, l logr.Logger,
func (r *TrainingOperator) ReconcileComponent(ctx context.Context, cli client.Client,
owner metav1.Object, dscispec *dsciv1.DSCInitializationSpec, platform cluster.Platform, _ bool) error {
l := logf.FromContext(ctx)
enabled := r.GetManagementState() == operatorv1.Managed
monitoringEnabled := dscispec.Monitoring.ManagementState == operatorv1.Managed

Expand Down
4 changes: 2 additions & 2 deletions components/trustyai/trustyai.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"fmt"
"path/filepath"

"github.com/go-logr/logr"
operatorv1 "github.com/openshift/api/operator/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -79,8 +78,9 @@ func (t *TrustyAI) GetComponentName() string {
return ComponentName
}

func (t *TrustyAI) ReconcileComponent(ctx context.Context, cli client.Client, l logr.Logger,
func (t *TrustyAI) ReconcileComponent(ctx context.Context, cli client.Client,
owner metav1.Object, dscispec *dsciv1.DSCInitializationSpec, platform cluster.Platform, _ bool) error {
l := logf.FromContext(ctx)
enabled := t.GetManagementState() == operatorv1.Managed
monitoringEnabled := dscispec.Monitoring.ManagementState == operatorv1.Managed
entryPath := DefaultPath
Expand Down
4 changes: 2 additions & 2 deletions components/workbenches/workbenches.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"path/filepath"
"strings"

"github.com/go-logr/logr"
operatorv1 "github.com/openshift/api/operator/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -111,8 +110,9 @@ func (w *Workbenches) GetComponentName() string {
return ComponentName
}

func (w *Workbenches) ReconcileComponent(ctx context.Context, cli client.Client, l logr.Logger,
func (w *Workbenches) ReconcileComponent(ctx context.Context, cli client.Client,
owner metav1.Object, dscispec *dsciv1.DSCInitializationSpec, platform cluster.Platform, _ bool) error {
l := logf.FromContext(ctx)
// Set default notebooks namespace
// Create rhods-notebooks namespace in managed platforms
enabled := w.GetManagementState() == operatorv1.Managed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/handler"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

Expand Down Expand Up @@ -311,7 +312,8 @@ func (r *DataScienceClusterReconciler) reconcileSubComponent(ctx context.Context
}
// Reconcile component
componentLogger := newComponentLogger(log, componentName, r.DataScienceCluster.DSCISpec)
err := component.ReconcileComponent(ctx, r.Client, componentLogger, instance, r.DataScienceCluster.DSCISpec, platform, installedComponentValue)
componentCtx := logf.IntoContext(ctx, componentLogger)
err := component.ReconcileComponent(componentCtx, r.Client, instance, r.DataScienceCluster.DSCISpec, platform, installedComponentValue)

// TODO: replace this hack with a full refactor of component status in the future

Expand Down
Loading