From 5b080db0f5a88c1cd0912e8dd91bf612a6bcd392 Mon Sep 17 00:00:00 2001 From: Ankit152 Date: Mon, 11 Nov 2024 00:56:46 +0530 Subject: [PATCH] chore: implemented ingress for extensions Signed-off-by: Ankit152 --- internal/manifests/collector/ingress.go | 41 +++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/internal/manifests/collector/ingress.go b/internal/manifests/collector/ingress.go index aaddac4181..4d775a4b66 100644 --- a/internal/manifests/collector/ingress.go +++ b/internal/manifests/collector/ingress.go @@ -70,6 +70,38 @@ func Ingress(params manifests.Params) (*networkingv1.Ingress, error) { }, nil } +func ExtensionIngress(params manifests.Params) (*networkingv1.Ingress, error) { + name := naming.Ingress(params.OtelCol.Name) + labels := manifestutils.Labels(params.OtelCol.ObjectMeta, name, params.OtelCol.Spec.Image, ComponentOpenTelemetryCollector, params.Config.LabelsFilter()) + + ports, err := extensionServicePortsFromCfg(params.Log, params.OtelCol) + + if err != nil { + return nil, err + } + + // if there are no ports, no ingress required + if len(ports) == 0 { + return nil, nil + } + + rules := createSubdomainIngressRules(name, "", ports) + + return &networkingv1.Ingress{ + ObjectMeta: metav1.ObjectMeta{ + Name: name, + Namespace: params.OtelCol.Namespace, + Annotations: params.OtelCol.Spec.Ingress.Annotations, // can the spec annotations be used? + Labels: labels, + }, + Spec: networkingv1.IngressSpec{ + TLS: params.OtelCol.Spec.Ingress.TLS, + Rules: rules, + IngressClassName: params.OtelCol.Spec.Ingress.IngressClassName, + }, + }, nil +} + func createPathIngressRules(otelcol string, hostname string, ports []corev1.ServicePort) networkingv1.IngressRule { pathType := networkingv1.PathTypePrefix paths := make([]networkingv1.HTTPIngressPath, len(ports)) @@ -163,6 +195,15 @@ func servicePortsFromCfg(logger logr.Logger, otelcol v1beta1.OpenTelemetryCollec return ports, nil } +func extensionServicePortsFromCfg(logger logr.Logger, otelcol v1beta1.OpenTelemetryCollector) ([]corev1.ServicePort, error) { + ports, err := otelcol.Spec.Config.GetExtensionPorts(logger) + if err != nil { + return nil, err + } + + return ports, nil +} + func toServicePorts(spec []v1beta1.PortsSpec) []corev1.ServicePort { var ports []corev1.ServicePort for _, p := range spec {