diff --git a/instrumentor/controllers/instrumentationdevice/common.go b/instrumentor/controllers/instrumentationdevice/common.go index c7cbe0747..0023dbddf 100644 --- a/instrumentor/controllers/instrumentationdevice/common.go +++ b/instrumentor/controllers/instrumentationdevice/common.go @@ -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" @@ -126,8 +125,8 @@ func addInstrumentationDeviceToWorkload(ctx context.Context, kubeClient client.C return err } - // User input 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 } diff --git a/k8sutils/pkg/profiles/profile.go b/k8sutils/pkg/profiles/profile.go index 909cc2ea6..021f4cdf8 100644 --- a/k8sutils/pkg/profiles/profile.go +++ b/k8sutils/pkg/profiles/profile.go @@ -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 { @@ -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"), diff --git a/k8sutils/pkg/profiles/utils.go b/k8sutils/pkg/profiles/utils.go index 1a55d7286..0f748c7fa 100644 --- a/k8sutils/pkg/profiles/utils.go +++ b/k8sutils/pkg/profiles/utils.go @@ -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 { diff --git a/scheduler/controllers/odigosconfig/odigosconfig_controller.go b/scheduler/controllers/odigosconfig/odigosconfig_controller.go index 81c2d084f..65ed3acd5 100644 --- a/scheduler/controllers/odigosconfig/odigosconfig_controller.go +++ b/scheduler/controllers/odigosconfig/odigosconfig_controller.go @@ -7,6 +7,7 @@ import ( "github.com/odigos-io/odigos/common/consts" k8sconsts "github.com/odigos-io/odigos/k8sutils/pkg/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" @@ -35,6 +36,8 @@ func (r *odigosConfigController) Reconcile(ctx context.Context, _ ctrl.Request) // make sure the default ignored containers are always present odigosConfig.IgnoredContainers = mergeIgnoredItemLists(odigosConfig.IgnoredContainers, k8sconsts.DefaultIgnoredContainers) + applyProfilesToOdigosConfig(odigosConfig) + err = r.persistEffectiveConfig(ctx, odigosConfig) if err != nil { return ctrl.Result{}, err @@ -102,3 +105,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) + } +}