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: allow profiles to modify the effective config as a side-effect #2179

Merged
merged 4 commits into from
Jan 10, 2025
Merged
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
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)
}
}
Loading