diff --git a/autoscaler/controllers/datacollection/root.go b/autoscaler/controllers/datacollection/root.go index 9310a5081..10710a243 100644 --- a/autoscaler/controllers/datacollection/root.go +++ b/autoscaler/controllers/datacollection/root.go @@ -2,12 +2,14 @@ package datacollection import ( "context" + "time" + odigosv1 "github.com/odigos-io/odigos/api/odigos/v1alpha1" + "github.com/odigos-io/odigos/k8sutils/pkg/consts" "github.com/odigos-io/odigos/k8sutils/pkg/env" "k8s.io/apimachinery/pkg/runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/log" - "time" ) var dm = &DelayManager{} @@ -30,23 +32,11 @@ func Sync(ctx context.Context, c client.Client, scheme *runtime.Scheme, imagePul return nil } - var collectorGroups odigosv1.CollectorsGroupList - if err := c.List(ctx, &collectorGroups); err != nil { - logger.Error(err, "Failed to list collectors groups") - return err - } - - var dataCollectionCollectorGroup *odigosv1.CollectorsGroup - for _, collectorGroup := range collectorGroups.Items { - if collectorGroup.Spec.Role == odigosv1.CollectorsGroupRoleNodeCollector { - dataCollectionCollectorGroup = &collectorGroup - break - } - } - - if dataCollectionCollectorGroup == nil { - logger.V(3).Info("Data collection collector group doesn't exist, nothing to sync") - return nil + odigosNs := env.GetCurrentNamespace() + var dataCollectionCollectorGroup odigosv1.CollectorsGroup + err := c.Get(ctx, client.ObjectKey{Namespace: odigosNs, Name: consts.OdigosNodeCollectorCollectorGroupName}, &dataCollectionCollectorGroup) + if err != nil { + return client.IgnoreNotFound(err) } var dests odigosv1.DestinationList @@ -61,7 +51,7 @@ 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) } func syncDataCollection(instApps *odigosv1.InstrumentedApplicationList, dests *odigosv1.DestinationList, processors *odigosv1.ProcessorList, diff --git a/autoscaler/controllers/gateway/root.go b/autoscaler/controllers/gateway/root.go index 4fd98b55e..8c0c68b6b 100644 --- a/autoscaler/controllers/gateway/root.go +++ b/autoscaler/controllers/gateway/root.go @@ -8,6 +8,7 @@ import ( odigosv1 "github.com/odigos-io/odigos/api/odigos/v1alpha1" commonconf "github.com/odigos-io/odigos/autoscaler/controllers/common" "github.com/odigos-io/odigos/common/consts" + k8sconsts "github.com/odigos-io/odigos/k8sutils/pkg/consts" "github.com/odigos-io/odigos/k8sutils/pkg/env" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" @@ -25,35 +26,24 @@ var ( } ) -func Sync(ctx context.Context, client client.Client, scheme *runtime.Scheme, imagePullSecrets []string, odigosVersion string) error { +func Sync(ctx context.Context, k8sClient client.Client, scheme *runtime.Scheme, imagePullSecrets []string, odigosVersion string) error { logger := log.FromContext(ctx) - var collectorGroups odigosv1.CollectorsGroupList - if err := client.List(ctx, &collectorGroups); err != nil { - logger.Error(err, "Failed to list collectors groups") - return err - } - - var gatewayCollectorGroup *odigosv1.CollectorsGroup - for _, collectorGroup := range collectorGroups.Items { - if collectorGroup.Spec.Role == odigosv1.CollectorsGroupRoleClusterGateway { - gatewayCollectorGroup = &collectorGroup - break - } - } - if gatewayCollectorGroup == nil { - logger.V(3).Info("Gateway collector group doesn't exist, nothing to sync") - return nil + odigosNs := env.GetCurrentNamespace() + var gatewayCollectorGroup odigosv1.CollectorsGroup + err := k8sClient.Get(ctx, client.ObjectKey{Namespace: odigosNs, Name: k8sconsts.OdigosClusterCollectorConfigMapName}, &gatewayCollectorGroup) + if err != nil { + return client.IgnoreNotFound(err) } var dests odigosv1.DestinationList - if err := client.List(ctx, &dests); err != nil { + if err := k8sClient.List(ctx, &dests); err != nil { logger.Error(err, "Failed to list destinations") return err } var processors odigosv1.ProcessorList - if err := client.List(ctx, &processors); err != nil { + if err := k8sClient.List(ctx, &processors); err != nil { logger.Error(err, "Failed to list processors") return err } @@ -62,12 +52,12 @@ func Sync(ctx context.Context, client client.Client, scheme *runtime.Scheme, ima odigosSystemNamespaceName := env.GetCurrentNamespace() var odigosConfig odigosv1.OdigosConfiguration - if err := client.Get(ctx, types.NamespacedName{Namespace: odigosSystemNamespaceName, Name: consts.OdigosConfigurationName}, &odigosConfig); err != nil { + if err := k8sClient.Get(ctx, types.NamespacedName{Namespace: odigosSystemNamespaceName, Name: consts.OdigosConfigurationName}, &odigosConfig); err != nil { logger.Error(err, "failed to get odigos config") return err } - return syncGateway(&dests, &processors, gatewayCollectorGroup, ctx, client, scheme, imagePullSecrets, odigosVersion, &odigosConfig) + return syncGateway(&dests, &processors, &gatewayCollectorGroup, ctx, k8sClient, scheme, imagePullSecrets, odigosVersion, &odigosConfig) } func syncGateway(dests *odigosv1.DestinationList, processors *odigosv1.ProcessorList,