diff --git a/internal/manifests/collector/ingress.go b/internal/manifests/collector/ingress.go index aaddac4181..fb9e32633b 100644 --- a/internal/manifests/collector/ingress.go +++ b/internal/manifests/collector/ingress.go @@ -70,6 +70,35 @@ 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, + Labels: labels, + }, + Spec: networkingv1.IngressSpec{ + Rules: rules, + }, + }, nil +} + func createPathIngressRules(otelcol string, hostname string, ports []corev1.ServicePort) networkingv1.IngressRule { pathType := networkingv1.PathTypePrefix paths := make([]networkingv1.HTTPIngressPath, len(ports)) @@ -163,6 +192,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 {