Skip to content

Commit

Permalink
chore: implemented ingress for extensions
Browse files Browse the repository at this point in the history
Signed-off-by: Ankit152 <[email protected]>
  • Loading branch information
Ankit152 committed Nov 18, 2024
1 parent 4f27a6b commit 5b080db
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions internal/manifests/collector/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 5b080db

Please sign in to comment.