diff --git a/autoscaler/controllers/collectorsgroup_controller.go b/autoscaler/controllers/collectorsgroup_controller.go index ad8c646d0..4136f3b7f 100644 --- a/autoscaler/controllers/collectorsgroup_controller.go +++ b/autoscaler/controllers/collectorsgroup_controller.go @@ -23,6 +23,7 @@ import ( "github.com/odigos-io/odigos/autoscaler/controllers/datacollection" "github.com/odigos-io/odigos/autoscaler/controllers/gateway" + "github.com/odigos-io/odigos/common" "sigs.k8s.io/controller-runtime/pkg/log" "k8s.io/apimachinery/pkg/runtime" @@ -36,6 +37,7 @@ type CollectorsGroupReconciler struct { Scheme *runtime.Scheme ImagePullSecrets []string OdigosVersion string + OdigosTier common.OdigosTier } //+kubebuilder:rbac:groups=odigos.io,namespace=odigos-system,resources=collectorsgroups,verbs=get;list;watch;create;update;patch;delete @@ -65,7 +67,7 @@ func (r *CollectorsGroupReconciler) Reconcile(ctx context.Context, req ctrl.Requ return ctrl.Result{}, err } - err = datacollection.Sync(ctx, r.Client, r.Scheme, r.ImagePullSecrets, r.OdigosVersion) + err = datacollection.Sync(ctx, r.Client, r.Scheme, r.ImagePullSecrets, r.OdigosVersion, r.OdigosTier) if err != nil { return ctrl.Result{}, err } diff --git a/autoscaler/controllers/datacollection/configmap.go b/autoscaler/controllers/datacollection/configmap.go index 1231a0aff..333a1c430 100644 --- a/autoscaler/controllers/datacollection/configmap.go +++ b/autoscaler/controllers/datacollection/configmap.go @@ -7,14 +7,13 @@ import ( "slices" "strings" - "github.com/odigos-io/odigos/autoscaler/controllers/datacollection/custom" - "github.com/odigos-io/odigos/common" - "github.com/odigos-io/odigos/common/consts" - "github.com/ghodss/yaml" odigosv1 "github.com/odigos-io/odigos/api/odigos/v1alpha1" commonconf "github.com/odigos-io/odigos/autoscaler/controllers/common" + "github.com/odigos-io/odigos/autoscaler/controllers/datacollection/custom" + "github.com/odigos-io/odigos/common" "github.com/odigos-io/odigos/common/config" + "github.com/odigos-io/odigos/common/consts" constsK8s "github.com/odigos-io/odigos/k8sutils/pkg/consts" "github.com/odigos-io/odigos/k8sutils/pkg/env" v1 "k8s.io/api/core/v1" @@ -30,7 +29,7 @@ import ( func SyncConfigMap(apps *odigosv1.InstrumentedApplicationList, dests *odigosv1.DestinationList, allProcessors *odigosv1.ProcessorList, datacollection *odigosv1.CollectorsGroup, ctx context.Context, - c client.Client, scheme *runtime.Scheme) (string, error) { + c client.Client, scheme *runtime.Scheme, tier common.OdigosTier) (string, error) { logger := log.FromContext(ctx) processors := commonconf.FilterAndSortProcessorsByOrderHint(allProcessors, odigosv1.CollectorsGroupRoleNodeCollector) @@ -39,7 +38,7 @@ func SyncConfigMap(apps *odigosv1.InstrumentedApplicationList, dests *odigosv1.D SamplingExists := commonconf.FindFirstProcessorByType(allProcessors, "odigossampling") setTracesLoadBalancer := SamplingExists != nil - desired, err := getDesiredConfigMap(apps, dests, processors, datacollection, scheme, setTracesLoadBalancer) + desired, err := getDesiredConfigMap(apps, dests, processors, datacollection, scheme, setTracesLoadBalancer, tier) if err != nil { logger.Error(err, "failed to get desired config map") return "", err @@ -98,8 +97,8 @@ func createConfigMap(desired *v1.ConfigMap, ctx context.Context, c client.Client } func getDesiredConfigMap(apps *odigosv1.InstrumentedApplicationList, dests *odigosv1.DestinationList, processors []*odigosv1.Processor, - datacollection *odigosv1.CollectorsGroup, scheme *runtime.Scheme, setTracesLoadBalancer bool) (*v1.ConfigMap, error) { - cmData, err := calculateConfigMapData(apps, dests, processors, setTracesLoadBalancer) + datacollection *odigosv1.CollectorsGroup, scheme *runtime.Scheme, setTracesLoadBalancer bool, tier common.OdigosTier) (*v1.ConfigMap, error) { + cmData, err := calculateConfigMapData(apps, dests, processors, setTracesLoadBalancer, tier) if err != nil { return nil, err } @@ -126,7 +125,7 @@ func getDesiredConfigMap(apps *odigosv1.InstrumentedApplicationList, dests *odig } func calculateConfigMapData(apps *odigosv1.InstrumentedApplicationList, dests *odigosv1.DestinationList, processors []*odigosv1.Processor, - setTracesLoadBalancer bool) (string, error) { + setTracesLoadBalancer bool, tier common.OdigosTier) (string, error) { empty := struct{}{} @@ -136,8 +135,12 @@ func calculateConfigMapData(apps *odigosv1.InstrumentedApplicationList, dests *o log.Log.V(0).Info(err.Error(), "processor", name) } } + + if tier != common.OnPremOdigosTier { + processorsCfg["odigosresourcename"] = empty + } + processorsCfg["batch"] = empty - processorsCfg["odigosresourcename"] = empty processorsCfg["resource"] = config.GenericMap{ "attributes": []config.GenericMap{{ "key": "k8s.node.name", @@ -207,7 +210,7 @@ func calculateConfigMapData(apps *odigosv1.InstrumentedApplicationList, dests *o "config": config.GenericMap{ "scrape_configs": []config.GenericMap{ { - "job_name": "otelcol", + "job_name": "otelcol", "scrape_interval": "10s", "static_configs": []config.GenericMap{ { @@ -217,8 +220,8 @@ func calculateConfigMapData(apps *odigosv1.InstrumentedApplicationList, dests *o "metric_relabel_configs": []config.GenericMap{ { "source_labels": []string{"__name__"}, - "regex": "(.*odigos.*|^otelcol_processor_accepted.*)", - "action": "keep", + "regex": "(.*odigos.*|^otelcol_processor_accepted.*)", + "action": "keep", }, }, }, @@ -234,11 +237,11 @@ func calculateConfigMapData(apps *odigosv1.InstrumentedApplicationList, dests *o }, }, Service: config.Service{ - Pipelines: map[string]config.Pipeline{ + Pipelines: map[string]config.Pipeline{ "metrics/otelcol": { - Receivers: []string{"prometheus/self-metrics"}, + Receivers: []string{"prometheus/self-metrics"}, Processors: []string{"resource/pod-name"}, - Exporters: []string{"otlp/odigos-own-telemetry-ui"}, + Exporters: []string{"otlp/odigos-own-telemetry-ui"}, }, }, Extensions: []string{"health_check"}, @@ -249,7 +252,7 @@ func calculateConfigMapData(apps *odigosv1.InstrumentedApplicationList, dests *o Resource: map[string]*string{ // The collector add "otelcol" as a service name, so we need to remove it // to avoid duplication, since we are interested in the instrumented services. - string(semconv.ServiceNameKey): nil, + string(semconv.ServiceNameKey): nil, // The collector adds its own version as a service version, which is not needed currently. string(semconv.ServiceVersionKey): nil, }, @@ -274,6 +277,8 @@ func calculateConfigMapData(apps *odigosv1.InstrumentedApplicationList, dests *o } } + commonProcessors := getCommonProcessorsByTier(tier) + if collectLogs { includes := make([]string, 0) for _, element := range apps.Items { @@ -313,7 +318,7 @@ func calculateConfigMapData(apps *odigosv1.InstrumentedApplicationList, dests *o cfg.Service.Pipelines["logs"] = config.Pipeline{ Receivers: []string{"filelog"}, - Processors: append([]string{"batch", "odigosresourcename", "resource", "resourcedetection", "odigostrafficmetrics"}, logsProcessors...), + Processors: append(commonProcessors, logsProcessors...), Exporters: []string{"otlp/gateway"}, } } @@ -321,7 +326,7 @@ func calculateConfigMapData(apps *odigosv1.InstrumentedApplicationList, dests *o if collectTraces { cfg.Service.Pipelines["traces"] = config.Pipeline{ Receivers: []string{"otlp"}, - Processors: append([]string{"batch", "odigosresourcename", "resource", "resourcedetection", "odigostrafficmetrics"}, tracesProcessors...), + Processors: append(commonProcessors, tracesProcessors...), Exporters: tracesPipelineExporter, } } @@ -336,7 +341,7 @@ func calculateConfigMapData(apps *odigosv1.InstrumentedApplicationList, dests *o cfg.Service.Pipelines["metrics"] = config.Pipeline{ Receivers: []string{"otlp", "kubeletstats"}, - Processors: append([]string{"batch", "odigosresourcename", "resource", "resourcedetection", "odigostrafficmetrics"}, metricsProcessors...), + Processors: append(commonProcessors, metricsProcessors...), Exporters: []string{"otlp/gateway"}, } } @@ -396,3 +401,12 @@ func getSignalsFromOtelcolConfig(otelcolConfigContent string) ([]common.Observab return signals, nil } + +func getCommonProcessorsByTier(tier common.OdigosTier) []string { + processors := []string{"batch"} + if tier != common.OnPremOdigosTier { + processors = append(processors, "odigosresourcename") + } + processors = append(processors, "resource", "resourcedetection", "odigostrafficmetrics") + return processors +} diff --git a/autoscaler/controllers/datacollection/configmap_test.go b/autoscaler/controllers/datacollection/configmap_test.go index a8ab56bdb..702e75fee 100644 --- a/autoscaler/controllers/datacollection/configmap_test.go +++ b/autoscaler/controllers/datacollection/configmap_test.go @@ -149,7 +149,7 @@ func TestCalculateConfigMapData(t *testing.T) { }, }, }, - false) + false, common.CommunityOdigosTier) assert.Equal(t, err, nil) assert.Equal(t, want, got) diff --git a/autoscaler/controllers/datacollection/root.go b/autoscaler/controllers/datacollection/root.go index 10710a243..8a484e197 100644 --- a/autoscaler/controllers/datacollection/root.go +++ b/autoscaler/controllers/datacollection/root.go @@ -5,6 +5,7 @@ import ( "time" odigosv1 "github.com/odigos-io/odigos/api/odigos/v1alpha1" + "github.com/odigos-io/odigos/common" "github.com/odigos-io/odigos/k8sutils/pkg/consts" "github.com/odigos-io/odigos/k8sutils/pkg/env" "k8s.io/apimachinery/pkg/runtime" @@ -18,7 +19,7 @@ const ( syncDaemonsetRetry = 3 ) -func Sync(ctx context.Context, c client.Client, scheme *runtime.Scheme, imagePullSecrets []string, odigosVersion string) error { +func Sync(ctx context.Context, c client.Client, scheme *runtime.Scheme, imagePullSecrets []string, odigosVersion string, tier common.OdigosTier) error { logger := log.FromContext(ctx) var instApps odigosv1.InstrumentedApplicationList @@ -51,16 +52,16 @@ func Sync(ctx context.Context, c client.Client, scheme *runtime.Scheme, imagePul return err } - return syncDataCollection(&instApps, &dests, &processors, &dataCollectionCollectorGroup, ctx, c, scheme, imagePullSecrets, odigosVersion) + return syncDataCollection(&instApps, &dests, &processors, &dataCollectionCollectorGroup, ctx, c, scheme, imagePullSecrets, odigosVersion, tier) } func syncDataCollection(instApps *odigosv1.InstrumentedApplicationList, dests *odigosv1.DestinationList, processors *odigosv1.ProcessorList, dataCollection *odigosv1.CollectorsGroup, ctx context.Context, c client.Client, - scheme *runtime.Scheme, imagePullSecrets []string, odigosVersion string) error { + scheme *runtime.Scheme, imagePullSecrets []string, odigosVersion string, tier common.OdigosTier) error { logger := log.FromContext(ctx) logger.V(0).Info("Syncing data collection") - _, err := SyncConfigMap(instApps, dests, processors, dataCollection, ctx, c, scheme) + _, err := SyncConfigMap(instApps, dests, processors, dataCollection, ctx, c, scheme, tier) if err != nil { logger.Error(err, "Failed to sync config map") return err diff --git a/autoscaler/controllers/instrumentedapplication_controller.go b/autoscaler/controllers/instrumentedapplication_controller.go index 4bc03cbf0..d7cb43104 100644 --- a/autoscaler/controllers/instrumentedapplication_controller.go +++ b/autoscaler/controllers/instrumentedapplication_controller.go @@ -21,6 +21,7 @@ import ( odigosv1 "github.com/odigos-io/odigos/api/odigos/v1alpha1" "github.com/odigos-io/odigos/autoscaler/controllers/datacollection" + "github.com/odigos-io/odigos/common" "k8s.io/apimachinery/pkg/runtime" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" @@ -33,6 +34,7 @@ type InstrumentedApplicationReconciler struct { Scheme *runtime.Scheme ImagePullSecrets []string OdigosVersion string + OdigosTier common.OdigosTier } //+kubebuilder:rbac:groups=odigos.io,resources=instrumentedapplications,verbs=get;list;watch;create;update;patch;delete @@ -50,7 +52,7 @@ type InstrumentedApplicationReconciler struct { func (r *InstrumentedApplicationReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { logger := log.FromContext(ctx) logger.V(0).Info("Reconciling InstrumentedApps") - err := datacollection.Sync(ctx, r.Client, r.Scheme, r.ImagePullSecrets, r.OdigosVersion) + err := datacollection.Sync(ctx, r.Client, r.Scheme, r.ImagePullSecrets, r.OdigosVersion, r.OdigosTier) if err != nil { return ctrl.Result{}, err } diff --git a/autoscaler/controllers/processor_controller.go b/autoscaler/controllers/processor_controller.go index 96a083242..a73fce7ed 100644 --- a/autoscaler/controllers/processor_controller.go +++ b/autoscaler/controllers/processor_controller.go @@ -6,6 +6,7 @@ import ( v1 "github.com/odigos-io/odigos/api/odigos/v1alpha1" "github.com/odigos-io/odigos/autoscaler/controllers/datacollection" "github.com/odigos-io/odigos/autoscaler/controllers/gateway" + "github.com/odigos-io/odigos/common" "k8s.io/apimachinery/pkg/runtime" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" @@ -17,6 +18,7 @@ type ProcessorReconciler struct { Scheme *runtime.Scheme ImagePullSecrets []string OdigosVersion string + OdigosTier common.OdigosTier } func (r *ProcessorReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { @@ -29,7 +31,7 @@ func (r *ProcessorReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( return ctrl.Result{}, err } - err = datacollection.Sync(ctx, r.Client, r.Scheme, r.ImagePullSecrets, r.OdigosVersion) + err = datacollection.Sync(ctx, r.Client, r.Scheme, r.ImagePullSecrets, r.OdigosVersion, r.OdigosTier) if err != nil { return ctrl.Result{}, err } diff --git a/autoscaler/go.mod b/autoscaler/go.mod index 4028e6c09..a84aa65f1 100644 --- a/autoscaler/go.mod +++ b/autoscaler/go.mod @@ -25,15 +25,15 @@ require ( github.com/cenkalti/backoff/v4 v4.3.0 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect - github.com/emicklei/go-restful/v3 v3.11.0 // indirect + github.com/emicklei/go-restful/v3 v3.12.0 // indirect github.com/evanphx/json-patch/v5 v5.9.0 // indirect github.com/fatih/color v1.16.0 // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/fxamacker/cbor/v2 v2.7.0 // indirect github.com/go-logr/stdr v1.2.2 // indirect - github.com/go-openapi/jsonpointer v0.19.6 // indirect - github.com/go-openapi/jsonreference v0.20.2 // indirect - github.com/go-openapi/swag v0.22.4 // indirect + github.com/go-openapi/jsonpointer v0.21.0 // indirect + github.com/go-openapi/jsonreference v0.21.0 // indirect + github.com/go-openapi/swag v0.23.0 // indirect github.com/goccy/go-yaml v1.11.3 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect @@ -44,7 +44,7 @@ require ( github.com/google/uuid v1.6.0 // indirect github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect github.com/hashicorp/go-version v1.7.0 // indirect - github.com/imdario/mergo v0.3.12 // indirect + github.com/imdario/mergo v0.3.16 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/mailru/easyjson v0.7.7 // indirect @@ -70,10 +70,10 @@ require ( golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc // indirect golang.org/x/net v0.26.0 // indirect golang.org/x/oauth2 v0.21.0 // indirect - golang.org/x/sys v0.21.0 // indirect + golang.org/x/sys v0.22.0 // indirect golang.org/x/term v0.21.0 // indirect golang.org/x/text v0.16.0 // indirect - golang.org/x/time v0.3.0 // indirect + golang.org/x/time v0.5.0 // indirect golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20240528184218-531527333157 // indirect @@ -85,7 +85,7 @@ require ( gopkg.in/yaml.v3 v3.0.1 // indirect k8s.io/apiextensions-apiserver v0.31.0 // indirect k8s.io/klog/v2 v2.130.1 // indirect - k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect + k8s.io/kube-openapi v0.0.0-20240430033511-f0e62f92d13f // indirect k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect diff --git a/autoscaler/go.sum b/autoscaler/go.sum index dcdac5ced..e942f563b 100644 --- a/autoscaler/go.sum +++ b/autoscaler/go.sum @@ -6,13 +6,12 @@ github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK3 github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/emicklei/go-restful/v3 v3.11.0 h1:rAQeMHw1c7zTmncogyy8VvRZwtkmkZ4FxERmMY4rD+g= -github.com/emicklei/go-restful/v3 v3.11.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= +github.com/emicklei/go-restful/v3 v3.12.0 h1:y2DdzBAURM29NFF94q6RaY4vjIH1rtwDapwQtU84iWk= +github.com/emicklei/go-restful/v3 v3.12.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= github.com/evanphx/json-patch v0.5.2 h1:xVCHIVMUu1wtM/VkR9jVZ45N3FhZfYMMYGorLCR8P3k= github.com/evanphx/json-patch v0.5.2/go.mod h1:ZWS5hhDbVDyob71nXKNL0+PWn6ToqBHMikGIFbs31qQ= github.com/evanphx/json-patch/v5 v5.9.0 h1:kcBlZQbplgElYIlo/n1hJbls2z/1awpXxpRi0/FOJfg= @@ -32,13 +31,12 @@ github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-logr/zapr v1.3.0 h1:XGdV8XW8zdwFiwOA2Dryh1gj2KRQyOOoNmBy4EplIcQ= github.com/go-logr/zapr v1.3.0/go.mod h1:YKepepNBd1u/oyhd/yQmtjVXmm9uML4IXUgMOwR8/Gg= -github.com/go-openapi/jsonpointer v0.19.6 h1:eCs3fxoIi3Wh6vtgmLTOjdhSpiqphQ+DaPn38N2ZdrE= -github.com/go-openapi/jsonpointer v0.19.6/go.mod h1:osyAmYz/mB/C3I+WsTTSgw1ONzaLJoLCyoi6/zppojs= -github.com/go-openapi/jsonreference v0.20.2 h1:3sVjiK66+uXK/6oQ8xgcRKcFgQ5KXa2KvnJRumpMGbE= -github.com/go-openapi/jsonreference v0.20.2/go.mod h1:Bl1zwGIM8/wsvqjsOQLJ/SH+En5Ap4rVB5KVcIDZG2k= -github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14= -github.com/go-openapi/swag v0.22.4 h1:QLMzNJnMGPRNDCbySlcj1x01tzU8/9LTTL9hZZZogBU= -github.com/go-openapi/swag v0.22.4/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14= +github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ= +github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY= +github.com/go-openapi/jsonreference v0.21.0 h1:Rs+Y7hSXT83Jacb7kFyjn4ijOuVGSvOdF2+tg1TRrwQ= +github.com/go-openapi/jsonreference v0.21.0/go.mod h1:LmZmgsrTkVg9LG4EaHeY8cBDslNPMo06cago5JNLkm4= +github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE= +github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ= github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no= @@ -71,19 +69,16 @@ github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 h1:bkypFPDjIYGfCYD5mRBvpqxfYX1 github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0/go.mod h1:P+Lt/0by1T8bfcF3z737NnSbmxQAppXMRziHUxPOC8k= github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY= github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= -github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU= -github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= +github.com/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4= +github.com/imdario/mergo v0.3.16/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= @@ -126,12 +121,7 @@ github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99 github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/tj/assert v0.0.3 h1:Df/BlaZ20mq6kuai7f5z2TvPFiwC3xaWJSDQNiIS3Rk= @@ -181,16 +171,16 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= -golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= +golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.21.0 h1:WVXCp+/EBEHOj53Rvu+7KiT/iElMrO8ACK16SMZ3jaA= golang.org/x/term v0.21.0/go.mod h1:ooXLefLobQVslOqselCNF4SxFAaoS6KujMbsGzSDmX0= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= -golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4= -golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= +golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= @@ -221,10 +211,8 @@ gopkg.in/evanphx/json-patch.v4 v4.12.0/go.mod h1:p8EYWUEYMpynmqDbY58zCKCFZw8pRWM gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= k8s.io/api v0.31.0 h1:b9LiSjR2ym/SzTOlfMHm1tr7/21aD7fSkqgD/CVJBCo= @@ -237,8 +225,8 @@ k8s.io/client-go v0.31.0 h1:QqEJzNjbN2Yv1H79SsS+SWnXkBgVu4Pj3CJQgbx0gI8= k8s.io/client-go v0.31.0/go.mod h1:Y9wvC76g4fLjmU0BA+rV+h2cncoadjvjjkkIGoTLcGU= k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk= k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE= -k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 h1:BZqlfIlq5YbRMFko6/PM7FjZpUb45WallggurYhKGag= -k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340/go.mod h1:yD4MZYeKMBwQKVht279WycxKyM84kkAx2DPrTXaeb98= +k8s.io/kube-openapi v0.0.0-20240430033511-f0e62f92d13f h1:0LQagt0gDpKqvIkAMPaRGcXawNMouPECM1+F9BVxEaM= +k8s.io/kube-openapi v0.0.0-20240430033511-f0e62f92d13f/go.mod h1:S9tOR0FxgyusSNR+MboCuiDpVWkAifZvaYI1Q2ubgro= k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 h1:pUdcCO1Lk/tbT5ztQWOBi5HBgbBP1J8+AsQnQCKsi8A= k8s.io/utils v0.0.0-20240711033017-18e509b52bc8/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= sigs.k8s.io/controller-runtime v0.19.0 h1:nWVM7aq+Il2ABxwiCizrVDSlmDcshi9llbaFbC0ji/Q= diff --git a/autoscaler/main.go b/autoscaler/main.go index b8b264832..6e6d052a5 100644 --- a/autoscaler/main.go +++ b/autoscaler/main.go @@ -29,6 +29,8 @@ import ( appsv1 "k8s.io/api/apps/v1" "sigs.k8s.io/controller-runtime/pkg/client" + k8sClient "github.com/odigos-io/odigos/k8sutils/pkg/client" + k8sUtils "github.com/odigos-io/odigos/k8sutils/pkg/utils" "sigs.k8s.io/controller-runtime/pkg/cache" "github.com/go-logr/zapr" @@ -163,6 +165,16 @@ func main() { os.Exit(1) } + client, err := k8sClient.GetK8sClientset() + if err != nil { + setupLog.Error(err, "unable to create k8s clientset") + } + + tier, err := k8sUtils.GetCurrentOdigosTier(context.Background(), odigosNs, client) + if err != nil { + setupLog.Error(err, "unable to get current odigos tier") + } + if err = (&controllers.DestinationReconciler{ Client: mgr.GetClient(), Scheme: mgr.GetScheme(), @@ -178,6 +190,7 @@ func main() { Scheme: mgr.GetScheme(), ImagePullSecrets: imagePullSecrets, OdigosVersion: odigosVersion, + OdigosTier: tier, }).SetupWithManager(mgr); err != nil { setupLog.Error(err, "unable to create controller", "controller", "Processor") os.Exit(1) @@ -187,6 +200,7 @@ func main() { Scheme: mgr.GetScheme(), ImagePullSecrets: imagePullSecrets, OdigosVersion: odigosVersion, + OdigosTier: tier, }).SetupWithManager(mgr); err != nil { setupLog.Error(err, "unable to create controller", "controller", "CollectorsGroup") os.Exit(1) @@ -196,6 +210,7 @@ func main() { Scheme: mgr.GetScheme(), ImagePullSecrets: imagePullSecrets, OdigosVersion: odigosVersion, + OdigosTier: tier, }).SetupWithManager(mgr); err != nil { setupLog.Error(err, "unable to create controller", "controller", "InstrumentedApplication") os.Exit(1) diff --git a/k8sutils/pkg/client/client.go b/k8sutils/pkg/client/client.go index bfe14f693..26463d2c2 100644 --- a/k8sutils/pkg/client/client.go +++ b/k8sutils/pkg/client/client.go @@ -3,6 +3,7 @@ package client import ( "os" + "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" ) @@ -58,3 +59,16 @@ func GetCurrentClusterDetails(kc string) ClusterDetails { ServerEndpoint: server, } } + +func GetK8sClientset() (*kubernetes.Clientset, error) { + // Init Kubernetes API client + cfg, err := rest.InClusterConfig() + if err != nil { + return nil, err + } + clientset, err := kubernetes.NewForConfig(cfg) + if err != nil { + return nil, err + } + return clientset, nil +} diff --git a/k8sutils/pkg/utils/tiers.go b/k8sutils/pkg/utils/tiers.go new file mode 100644 index 000000000..1b5bc10e2 --- /dev/null +++ b/k8sutils/pkg/utils/tiers.go @@ -0,0 +1,55 @@ +package utils + +import ( + "context" + + "github.com/odigos-io/odigos/common" + corev1 "k8s.io/api/core/v1" + apierrors "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/client-go/kubernetes" +) + +const ( + odigosCloudApiKeySecretKey = "odigos-cloud-api-key" + odigosOnpremTokenSecretKey = "odigos-onprem-token" + odigosProSecretName = "odigos-pro" +) + +func GetCurrentOdigosTier(ctx context.Context, namespaces string, client *kubernetes.Clientset) (common.OdigosTier, error) { + + sec, err := getCurrentOdigosProSecret(ctx, namespaces, client) + + if err != nil { + return "", err + } + if sec == nil { + return common.CommunityOdigosTier, nil + } + + if _, exists := sec.Data[odigosCloudApiKeySecretKey]; exists { + return common.CloudOdigosTier, nil + } + if _, exists := sec.Data[odigosOnpremTokenSecretKey]; exists { + return common.OnPremOdigosTier, nil + } + return common.CommunityOdigosTier, nil +} + +func getCurrentOdigosProSecret(ctx context.Context, namespace string, client *kubernetes.Clientset) (*corev1.Secret, error) { + + secret, err := client.CoreV1().Secrets(namespace).Get(ctx, odigosProSecretName, metav1.GetOptions{}) + if apierrors.IsNotFound(err) { + return nil, nil + } + if err != nil { + return nil, err + } + + // apparently, k8s is not setting the type meta for the object obtained with Get. + secret.TypeMeta = metav1.TypeMeta{ + Kind: "Secret", + APIVersion: "v1", + } + return secret, err +}