Skip to content

Commit

Permalink
Requeue effective config (#2224)
Browse files Browse the repository at this point in the history
requeue reconcile request if effective config is not yet reconciled
  • Loading branch information
blumamir authored Jan 14, 2025
1 parent 9e10aff commit d083730
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 15 deletions.
5 changes: 5 additions & 0 deletions helm/odigos/templates/scheduler/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ spec:
configMapKeyRef:
key: ODIGOS_TIER
name: odigos-deployment
- name: ODIGOS_VERSION
valueFrom:
configMapKeyRef:
key: ODIGOS_VERSION
name: odigos-deployment
envFrom:
- configMapRef:
name: odigos-own-telemetry-otel-config
Expand Down
13 changes: 12 additions & 1 deletion k8sutils/pkg/utils/config_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package utils

import (
"context"
"errors"

v1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/yaml"
Expand All @@ -13,13 +15,22 @@ import (
"github.com/odigos-io/odigos/k8sutils/pkg/env"
)

// error to indicate specifically that odigos effective config is not found.
// it can be used to differentiate and react specifically to this error.
// the effective config is reconciled in the scheduler, so it is possible to have a situation where the config is not found when odigos starts.
var ErrOdigosEffectiveConfigNotFound = errors.New("odigos effective config not found")

func GetCurrentOdigosConfig(ctx context.Context, k8sClient client.Client) (common.OdigosConfiguration, error) {
var configMap v1.ConfigMap
var odigosConfig common.OdigosConfiguration
odigosSystemNamespaceName := env.GetCurrentNamespace()
if err := k8sClient.Get(ctx, types.NamespacedName{Namespace: odigosSystemNamespaceName, Name: consts.OdigosEffectiveConfigName},
&configMap); err != nil {
return odigosConfig, err
if apierrors.IsNotFound(err) {
return odigosConfig, ErrOdigosEffectiveConfigNotFound
} else {
return odigosConfig, err
}
}
if err := yaml.Unmarshal([]byte(configMap.Data[consts.OdigosConfigurationFileName]), &odigosConfig); err != nil {
return odigosConfig, err
Expand Down
17 changes: 17 additions & 0 deletions k8sutils/pkg/utils/retrynoeffectiveconfig.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package utils

import (
"time"

"sigs.k8s.io/controller-runtime/pkg/reconcile"
)

func K8SNoEffectiveConfigErrorHandler(err error) (reconcile.Result, error) {
if err == ErrOdigosEffectiveConfigNotFound {
return reconcile.Result{
Requeue: true,
RequeueAfter: 5 * time.Second,
}, nil
}
return reconcile.Result{}, err
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import (
"errors"
"fmt"

"github.com/odigos-io/odigos/k8sutils/pkg/workload"
odigosv1 "github.com/odigos-io/odigos/api/odigos/v1alpha1"
criwrapper "github.com/odigos-io/odigos/k8sutils/pkg/cri"
k8sutils "github.com/odigos-io/odigos/k8sutils/pkg/utils"
"github.com/odigos-io/odigos/k8sutils/pkg/workload"
kubeutils "github.com/odigos-io/odigos/odiglet/pkg/kube/utils"
corev1 "k8s.io/api/core/v1"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes"
Expand Down Expand Up @@ -86,7 +86,7 @@ func (r *InstrumentationConfigReconciler) Reconcile(ctx context.Context, request

odigosConfig, err := k8sutils.GetCurrentOdigosConfig(ctx, r.Client)
if err != nil {
return reconcile.Result{}, err
return k8sutils.K8SNoEffectiveConfigErrorHandler(err)
}

var selectedPods []corev1.Pod
Expand Down Expand Up @@ -144,4 +144,3 @@ func getWorkloadAndLabelsfromOwner(ctx context.Context, k8sClient client.Client,

return nil, nil, errors.New("workload kind not supported")
}

2 changes: 1 addition & 1 deletion odiglet/pkg/kube/runtime_details/pods_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (p *PodsReconciler) Reconcile(ctx context.Context, request reconcile.Reques

odigosConfig, err := k8sutils.GetCurrentOdigosConfig(ctx, p.Client)
if err != nil {
return reconcile.Result{}, err
return k8sutils.K8SNoEffectiveConfigErrorHandler(err)
}

// Perform runtime inspection once we know the pod is newer that the latest runtime inspection performed and saved.
Expand Down
6 changes: 1 addition & 5 deletions profiles/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,4 @@ require (
go.opentelemetry.io/otel/trace v1.29.0 // indirect
)

replace (
github.com/odigos-io/odigos/api => ../api
github.com/odigos-io/odigos/common => ../common
github.com/odigos-io/odigos/k8sutils => ../k8sutils
)
replace github.com/odigos-io/odigos/common => ../common
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package clustercollectorsgroup
import (
"context"

"github.com/odigos-io/odigos/k8sutils/pkg/utils"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -15,5 +16,5 @@ type clusterCollectorsGroupController struct {

func (r *clusterCollectorsGroupController) Reconcile(ctx context.Context, _ ctrl.Request) (ctrl.Result, error) {
err := sync(ctx, r.Client)
return ctrl.Result{}, err
return utils.K8SNoEffectiveConfigErrorHandler(err)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package nodecollectorsgroup
import (
"context"

"github.com/odigos-io/odigos/k8sutils/pkg/utils"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -15,5 +16,5 @@ type clusterCollectorsGroupController struct {

func (r *clusterCollectorsGroupController) Reconcile(ctx context.Context, _ ctrl.Request) (ctrl.Result, error) {
err := sync(ctx, r.Client)
return ctrl.Result{}, err
return utils.K8SNoEffectiveConfigErrorHandler(err)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package nodecollectorsgroup
import (
"context"

"github.com/odigos-io/odigos/k8sutils/pkg/utils"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -15,5 +16,5 @@ type instrumentationConfigController struct {

func (r *instrumentationConfigController) Reconcile(ctx context.Context, _ ctrl.Request) (ctrl.Result, error) {
err := sync(ctx, r.Client)
return ctrl.Result{}, err
return utils.K8SNoEffectiveConfigErrorHandler(err)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package nodecollectorsgroup
import (
"context"

"github.com/odigos-io/odigos/k8sutils/pkg/utils"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -15,5 +16,5 @@ type odigosConfigController struct {

func (r *odigosConfigController) Reconcile(ctx context.Context, _ ctrl.Request) (ctrl.Result, error) {
err := sync(ctx, r.Client)
return ctrl.Result{}, err
return utils.K8SNoEffectiveConfigErrorHandler(err)
}

0 comments on commit d083730

Please sign in to comment.