Skip to content

Commit

Permalink
feat: allow profiles to modify the effective config as a side-effect (#…
Browse files Browse the repository at this point in the history
…2179)

This is an ongoing effort to consolidate all profile apply logic as
reconcilers rather than have them spread around.
  • Loading branch information
blumamir authored Jan 10, 2025
1 parent 7e8571a commit 04e3894
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 21 deletions.
5 changes: 2 additions & 3 deletions instrumentor/controllers/instrumentationdevice/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/odigos-io/odigos/k8sutils/pkg/conditions"
odigosk8sconsts "github.com/odigos-io/odigos/k8sutils/pkg/consts"
"github.com/odigos-io/odigos/k8sutils/pkg/env"
k8sprofiles "github.com/odigos-io/odigos/k8sutils/pkg/profiles"
k8sutils "github.com/odigos-io/odigos/k8sutils/pkg/utils"
"github.com/odigos-io/odigos/k8sutils/pkg/workload"
appsv1 "k8s.io/api/apps/v1"
Expand Down Expand Up @@ -126,8 +125,8 @@ func addInstrumentationDeviceToWorkload(ctx context.Context, kubeClient client.C
return err
}

// User input <odigosConfiguration.AllowConcurrentAgents> prefered over the profile configuration
agentsCanRunConcurrently := k8sprofiles.AgentsCanRunConcurrently(odigosConfiguration.Profiles)
// allowConcurrentAgents is false by default unless explicitly set to true in the OdigosConfiguration
agentsCanRunConcurrently := false
if odigosConfiguration.AllowConcurrentAgents != nil {
agentsCanRunConcurrently = *odigosConfiguration.AllowConcurrentAgents
}
Expand Down
11 changes: 9 additions & 2 deletions k8sutils/pkg/profiles/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import (
type Profile struct {
ProfileName common.ProfileName
ShortDescription string
KubeObject Object // used to read it from the embedded YAML file
Dependencies []common.ProfileName // other profiles that are applied by the current profile
KubeObject Object // used to read it from the embedded YAML file
Dependencies []common.ProfileName // other profiles that are applied by the current profile
ModifyConfigFunc func(*common.OdigosConfiguration) // function to update the configuration based on the profile
}

type Object interface {
Expand All @@ -36,6 +37,12 @@ var (
AllowConcurrentAgents = Profile{
ProfileName: common.ProfileName("allow_concurrent_agents"),
ShortDescription: "This profile allows Odigos to run concurrently with other agents",
ModifyConfigFunc: func(c *common.OdigosConfiguration) {
if c.AllowConcurrentAgents == nil {
allowConcurrentAgents := true
c.AllowConcurrentAgents = &allowConcurrentAgents
}
},
}
FullPayloadCollectionProfile = Profile{
ProfileName: common.ProfileName("full-payload-collection"),
Expand Down
16 changes: 0 additions & 16 deletions k8sutils/pkg/profiles/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,6 @@ package profiles

import "github.com/odigos-io/odigos/common"

func AgentsCanRunConcurrently(profiles []common.ProfileName) bool {
for _, profile := range profiles {
if profile == AllowConcurrentAgents.ProfileName {
return true
}

profileDependencies := ProfilesMap[profile].Dependencies
for _, dependencyProfile := range profileDependencies {
if dependencyProfile == AllowConcurrentAgents.ProfileName {
return true
}
}
}
return false
}

func FilterSizeProfiles(profiles []common.ProfileName) common.ProfileName {
// In case multiple size profiles are provided, the first one will be used.
for _, profile := range profiles {
Expand Down
24 changes: 24 additions & 0 deletions scheduler/controllers/odigosconfig/odigosconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/odigos-io/odigos/common"
"github.com/odigos-io/odigos/common/consts"
"github.com/odigos-io/odigos/k8sutils/pkg/env"
"github.com/odigos-io/odigos/k8sutils/pkg/profiles"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -27,6 +28,8 @@ func (r *odigosConfigController) Reconcile(ctx context.Context, _ ctrl.Request)
return ctrl.Result{}, err
}

applyProfilesToOdigosConfig(odigosConfig)

err = r.persistEffectiveConfig(ctx, odigosConfig)
if err != nil {
return ctrl.Result{}, err
Expand Down Expand Up @@ -94,3 +97,24 @@ func (r *odigosConfigController) persistEffectiveConfig(ctx context.Context, eff

return nil
}

func applySingleProfile(profile common.ProfileName, odigosConfig *common.OdigosConfiguration) {
profileConfig, found := profiles.ProfilesMap[profile]
if !found {
return
}

if profileConfig.ModifyConfigFunc != nil {
profileConfig.ModifyConfigFunc(odigosConfig)
}

for _, dependency := range profileConfig.Dependencies {
applySingleProfile(dependency, odigosConfig)
}
}

func applyProfilesToOdigosConfig(odigosConfig *common.OdigosConfiguration) {
for _, profile := range odigosConfig.Profiles {
applySingleProfile(profile, odigosConfig)
}
}

0 comments on commit 04e3894

Please sign in to comment.