Skip to content

Commit 7033f45

Browse files
authored
feat(helm): option to set the odigos-gateway collector name (#4239) (#4242)
Fixes: CORE-624 This PR adds a new option to helm to specify the name of the `odigos-gateway` deployment (which will also show up in pods name) Reasons is that some users prefer to have this name with the name of the team, so if there are any issues, the pod name is enough to know which team to ping. feature, dependency update, or breaking change?? ```release-note new helm values option - set a custom name for the gateway collector deployment ```
1 parent 30aff90 commit 7033f45

37 files changed

Lines changed: 281 additions & 80 deletions

File tree

api/config/crd/bases/odigos.io_collectorsgroups.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ spec:
5252
This can be used to resolve conflicting ports when a collector is using the host network.
5353
format: int32
5454
type: integer
55+
deploymentName:
56+
description: |-
57+
Deployment name for the collectors group deployment.
58+
Only relevant for cluster gateway collector.
59+
type: string
5560
enableDataCompression:
5661
description: |-
5762
Deprecated - use OtlpExporterConfiguration instead.

api/generated/odigos/applyconfiguration/odigos/v1alpha1/collectorsgroupspec.go

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/k8sconsts/clustercollector.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ const (
1111
OdigosClusterCollectorCollectorGroupName = OdigosClusterCollectorDeploymentName
1212
OdigosClusterCollectorConfigMapKey = "collector-conf"
1313

14-
OdigosClusterCollectorServiceAccountName = "odigos-gateway"
15-
OdigosClusterCollectorRoleName = "odigos-gateway"
16-
OdigosClusterCollectorRoleBindingName = "odigos-gateway"
14+
OdigosClusterCollectorServiceAccountName = OdigosClusterCollectorDeploymentName
15+
OdigosClusterCollectorRoleName = OdigosClusterCollectorDeploymentName
16+
OdigosClusterCollectorRoleBindingName = OdigosClusterCollectorDeploymentName
17+
18+
OdigosClusterCollectorHpaName = OdigosClusterCollectorDeploymentName
1719

1820
OdigosClusterCollectorContainerName = "gateway"
1921

api/odigos/v1alpha1/collectorsgroup_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ type CollectorsGroupSpec struct {
198198
// This is a hard requirement: the pod will be scheduled ONLY on nodes that match all labels.
199199
// If no matching nodes exist, the pod will remain Pending.
200200
NodeSelector *map[string]string `json:"nodeSelector,omitempty"`
201+
202+
// Deployment name for the collectors group deployment.
203+
// Only relevant for cluster gateway collector.
204+
DeploymentName string `json:"deploymentName,omitempty"`
201205
}
202206

203207
// CollectorsGroupStatus defines the observed state of Collector

autoscaler/controllers/clustercollector/collectorsgroup_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111

1212
type CollectorsGroupReconciler struct {
1313
client.Client
14-
Scheme *runtime.Scheme
15-
OdigosVersion string
14+
Scheme *runtime.Scheme
15+
OdigosVersion string
1616
}
1717

1818
func (r *CollectorsGroupReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {

autoscaler/controllers/clustercollector/configmap.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,15 @@ func addSelfTelemetryPipeline(c *config.Config, ownTelemetryPort int32, destinat
8383
},
8484
},
8585
}
86+
c.Processors["resource/odigos-collector-role"] = config.GenericMap{
87+
"attributes": []config.GenericMap{
88+
{
89+
"key": "odigos.collector.role",
90+
"value": string(k8sconsts.CollectorsRoleClusterGateway),
91+
"action": "upsert",
92+
},
93+
},
94+
}
8695
// odigostrafficmetrics processor should be the last processor in the pipeline
8796
// as it helps to calculate the size of the data being exported.
8897
// In case of performance impact caused by this processor, we should modify this config to reduce the sampling ratio.
@@ -98,7 +107,7 @@ func addSelfTelemetryPipeline(c *config.Config, ownTelemetryPort int32, destinat
98107
}
99108
c.Service.Pipelines["metrics/otelcol"] = config.Pipeline{
100109
Receivers: []string{"prometheus/self-metrics"},
101-
Processors: []string{"resource/pod-name"},
110+
Processors: []string{"resource/pod-name", "resource/odigos-collector-role"},
102111
Exporters: []string{"otlp/odigos-own-telemetry-ui"},
103112
}
104113

autoscaler/controllers/clustercollector/configmap_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,10 @@ func TestAddSelfTelemetryPipeline(t *testing.T) {
112112
}
113113
assert.NotEmpty(t, c.Receivers["prometheus/self-metrics"])
114114
assert.NotEmpty(t, c.Processors["resource/pod-name"])
115+
assert.NotEmpty(t, c.Processors["resource/odigos-collector-role"])
115116
assert.NotEmpty(t, c.Service.Pipelines["metrics/otelcol"])
116117
assert.Equal(t, []string{"prometheus/self-metrics"}, c.Service.Pipelines["metrics/otelcol"].Receivers)
117-
assert.Equal(t, []string{"resource/pod-name"}, c.Service.Pipelines["metrics/otelcol"].Processors)
118+
assert.Equal(t, []string{"resource/pod-name", "resource/odigos-collector-role"}, c.Service.Pipelines["metrics/otelcol"].Processors)
118119
assert.Equal(t, []string{"otlp/odigos-own-telemetry-ui"}, c.Service.Pipelines["metrics/otelcol"].Exporters)
119120
pullExporter := c.Service.Telemetry.Metrics.Readers[0]["pull"].(config.GenericMap)["exporter"].(config.GenericMap)
120121
port := pullExporter["prometheus"].(config.GenericMap)["port"]

autoscaler/controllers/clustercollector/deployment.go

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,16 @@ func syncDeployment(enabledDests *odigosv1.DestinationList, gateway *odigosv1.Co
5959
}
6060

6161
existingDeployment := &appsv1.Deployment{}
62-
getError := c.Get(ctx, client.ObjectKey{Name: gateway.Name, Namespace: gateway.Namespace}, existingDeployment)
62+
getError := c.Get(ctx, client.ObjectKey{Name: desiredDeployment.Name, Namespace: desiredDeployment.Namespace}, existingDeployment)
6363
if getError != nil && !apierrors.IsNotFound(getError) {
6464
return nil, errors.Join(getError, errors.New("failed to get gateway deployment"))
6565
}
6666

67+
err = deleteOldDeployments(ctx, c, gateway.Namespace, desiredDeployment.Name)
68+
if err != nil {
69+
return nil, errors.Join(err, errors.New("failed to delete old deployments"))
70+
}
71+
6772
if apierrors.IsNotFound(getError) {
6873
logger.V(0).Info("Creating new gateway deployment")
6974
err := c.Create(ctx, desiredDeployment)
@@ -81,6 +86,32 @@ func syncDeployment(enabledDests *odigosv1.DestinationList, gateway *odigosv1.Co
8186
}
8287
}
8388

89+
// users can set the deploymentName of the gateway collector to a custom value.
90+
// if that happens, the old deployments stays around, so this function takes care of deleting them.
91+
func deleteOldDeployments(ctx context.Context, c client.Client, namespace string, deploymentName string) error {
92+
var deployments appsv1.DeploymentList
93+
err := c.List(ctx, &deployments, client.InNamespace(namespace), client.MatchingLabels(ClusterCollectorGateway))
94+
if err != nil {
95+
return err
96+
}
97+
98+
if len(deployments.Items) == 1 && deployments.Items[0].Name == deploymentName {
99+
return nil
100+
}
101+
102+
logger := log.FromContext(ctx)
103+
for _, deployment := range deployments.Items {
104+
if deployment.Name != deploymentName {
105+
logger.V(0).Info("Deleting old gateway deployment pre odigos cluster collector deployment rename", "deployment", deployment.Name)
106+
err := c.Delete(ctx, &deployment)
107+
if err != nil {
108+
return err
109+
}
110+
}
111+
}
112+
return nil
113+
}
114+
84115
func patchDeployment(existing *appsv1.Deployment, desired *appsv1.Deployment, ctx context.Context, c client.Client) (*appsv1.Deployment, error) {
85116
logger := log.FromContext(ctx)
86117
res, err := controllerutil.CreateOrPatch(ctx, c, existing, func() error {
@@ -132,9 +163,11 @@ func getDesiredDeployment(ctx context.Context, c client.Client, enabledDests *od
132163
})
133164
}
134165

166+
deploymentName := commonconfig.GetDeploymentName(gateway)
167+
135168
desiredDeployment := &appsv1.Deployment{
136169
ObjectMeta: v1.ObjectMeta{
137-
Name: k8sconsts.OdigosClusterCollectorDeploymentName,
170+
Name: deploymentName,
138171
Namespace: gateway.Namespace,
139172
Labels: ClusterCollectorGateway,
140173
},
@@ -152,7 +185,7 @@ func getDesiredDeployment(ctx context.Context, c client.Client, enabledDests *od
152185
},
153186
Spec: corev1.PodSpec{
154187
NodeSelector: *nodeSelector,
155-
ServiceAccountName: k8sconsts.OdigosClusterCollectorDeploymentName,
188+
ServiceAccountName: k8sconsts.OdigosClusterCollectorServiceAccountName,
156189
SecurityContext: &corev1.PodSecurityContext{
157190
RunAsNonRoot: boolPtr(true),
158191
RunAsUser: int64Ptr(65534), // nobody user

autoscaler/controllers/clustercollector/destination_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111

1212
type DestinationReconciler struct {
1313
client.Client
14-
Scheme *runtime.Scheme
15-
OdigosVersion string
14+
Scheme *runtime.Scheme
15+
OdigosVersion string
1616
}
1717

1818
func (r *DestinationReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {

autoscaler/controllers/clustercollector/gatewaydeployment_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func (r *ClusterCollectorDeploymentReconciler) Reconcile(ctx context.Context, re
3030
var gatewayCollectorGroup odigosv1.CollectorsGroup
3131
if err := r.Get(ctx, types.NamespacedName{
3232
Namespace: dep.Namespace,
33-
Name: k8sconsts.OdigosClusterCollectorDeploymentName,
33+
Name: k8sconsts.OdigosClusterCollectorCollectorGroupName,
3434
}, &gatewayCollectorGroup); err != nil {
3535
return ctrl.Result{}, client.IgnoreNotFound(err)
3636
}

0 commit comments

Comments
 (0)