-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create effective-config configmap (#2176)
The "odigos-config" configmap in odigos is currently treated as "user" object, containing raw configuration as the user supplied it. It can come from few places: - cli (via install) - manual edits of the cm - gitops (forcing the content) - ui (not at the moment, but in the future) This PR introduces a new "effective-config" configmap that is reconciled in schedualer. Having a reconciliation step will allow us to: - consolidate duplicate code in cli and helm that does defaulting, maintaining the default values and merging in one place and update regardless of the source of these values - ability to apply profiles as odigos-config changes - removing any config handling specific logic from consumers (like defaulting, applying profiles, merging different options), o they will get the digested values ready to use - good visibility into the reconciled values that effectively used by various odigos components after they are processed
- Loading branch information
Showing
20 changed files
with
167 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package odigosconfig | ||
|
||
import ( | ||
odigospredicates "github.com/odigos-io/odigos/k8sutils/pkg/predicate" | ||
corev1 "k8s.io/api/core/v1" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
) | ||
|
||
func SetupWithManager(mgr ctrl.Manager) error { | ||
|
||
err := ctrl.NewControllerManagedBy(mgr). | ||
For(&corev1.ConfigMap{}). | ||
Named("odigosconfig-odigosconfig"). | ||
WithEventFilter(&odigospredicates.OdigosConfigMapPredicate). | ||
Complete(&odigosConfigController{ | ||
Client: mgr.GetClient(), | ||
Scheme: mgr.GetScheme(), | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
96 changes: 96 additions & 0 deletions
96
scheduler/controllers/odigosconfig/odigosconfig_controller.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package odigosconfig | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/odigos-io/odigos/common" | ||
"github.com/odigos-io/odigos/common/consts" | ||
"github.com/odigos-io/odigos/k8sutils/pkg/env" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/types" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
"sigs.k8s.io/yaml" | ||
) | ||
|
||
type odigosConfigController struct { | ||
client.Client | ||
Scheme *runtime.Scheme | ||
} | ||
|
||
func (r *odigosConfigController) Reconcile(ctx context.Context, _ ctrl.Request) (ctrl.Result, error) { | ||
|
||
odigosConfig, err := r.getOdigosConfigUserObject(ctx) | ||
if err != nil { | ||
return ctrl.Result{}, err | ||
} | ||
|
||
err = r.persistEffectiveConfig(ctx, odigosConfig) | ||
if err != nil { | ||
return ctrl.Result{}, err | ||
} | ||
|
||
return ctrl.Result{}, nil | ||
} | ||
|
||
func (r *odigosConfigController) getOdigosConfigUserObject(ctx context.Context) (*common.OdigosConfiguration, error) { | ||
var configMap corev1.ConfigMap | ||
var odigosConfig common.OdigosConfiguration | ||
odigosNs := env.GetCurrentNamespace() | ||
|
||
// read current content in odigos-config, which is the content supplied by the user. | ||
// this is the baseline for reconciling, without defaults and profiles applied. | ||
err := r.Client.Get(ctx, types.NamespacedName{Namespace: odigosNs, Name: consts.OdigosConfigurationName}, &configMap) | ||
if err != nil { | ||
return nil, err | ||
} | ||
err = yaml.Unmarshal([]byte(configMap.Data[consts.OdigosConfigurationFileName]), &odigosConfig) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &odigosConfig, nil | ||
} | ||
|
||
func (r *odigosConfigController) persistEffectiveConfig(ctx context.Context, effectiveConfig *common.OdigosConfiguration) error { | ||
odigosNs := env.GetCurrentNamespace() | ||
|
||
// apply patch the OdigosEffectiveConfigName configmap with the effective configuration | ||
// this is the configuration after applying defaults and profiles. | ||
|
||
effectiveConfigYamlText, err := yaml.Marshal(effectiveConfig) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
effectiveConfigMap := corev1.ConfigMap{ | ||
TypeMeta: metav1.TypeMeta{ | ||
Kind: "ConfigMap", | ||
APIVersion: "v1", | ||
}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Namespace: odigosNs, | ||
Name: consts.OdigosEffectiveConfigName, | ||
}, | ||
Data: map[string]string{ | ||
consts.OdigosConfigurationFileName: string(effectiveConfigYamlText), | ||
}, | ||
} | ||
|
||
objApplyBytes, err := yaml.Marshal(effectiveConfigMap) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = r.Client.Patch(ctx, &effectiveConfigMap, client.RawPatch(types.ApplyYAMLPatchType, objApplyBytes), client.ForceOwnership, client.FieldOwner("scheduler-odigosconfig")) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
logger := ctrl.LoggerFrom(ctx) | ||
logger.Info("Successfully persisted effective configuration") | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters