Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Ingress for extensions #3441

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .chloggen/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action)
component: collector

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: support for creating ingress for extensions that consumes the service.

# One or more tracking issues related to the change
issues: [3438]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
5 changes: 5 additions & 0 deletions apis/v1beta1/opentelemetrycollector_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ type OpenTelemetryCollectorSpec struct {
// Valid modes are: deployment, daemonset and statefulset.
// +optional
Ingress Ingress `json:"ingress,omitempty"`
// ExtensionIngress is used to specify how OpenTelemetry Collector is exposed. This
// functionality is only available if one of the valid modes is set.
// Valid modes are: deployment, daemonset and statefulset.
// +optional
ExtensionIngress Ingress `json:"extensionIngress,omitempty"`
// Liveness config for the OpenTelemetry Collector except the probe handler which is auto generated from the health extension of the collector.
// It is only effective when healthcheckextension is configured in the OpenTelemetry Collector pipeline.
// +optional
Expand Down
1 change: 1 addition & 0 deletions apis/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6042,6 +6042,49 @@ spec:
x-kubernetes-map-type: atomic
type: object
type: array
extensionIngress:
properties:
annotations:
additionalProperties:
type: string
type: object
hostname:
type: string
ingressClassName:
type: string
route:
properties:
termination:
enum:
- insecure
- edge
- passthrough
- reencrypt
type: string
type: object
ruleType:
enum:
- path
- subdomain
type: string
tls:
items:
properties:
hosts:
items:
type: string
type: array
x-kubernetes-list-type: atomic
secretName:
type: string
type: object
type: array
type:
enum:
- ingress
- route
type: string
type: object
hostNetwork:
type: boolean
image:
Expand Down
1 change: 1 addition & 0 deletions internal/manifests/collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func Build(params manifests.Params) ([]client.Object, error) {
manifests.Factory(MonitoringService),
manifests.Factory(ExtensionService),
manifests.Factory(Ingress),
manifests.Factory(ExtensionIngress),
}...)

if featuregate.CollectorUsesTargetAllocatorCR.IsEnabled() {
Expand Down
59 changes: 55 additions & 4 deletions internal/manifests/collector/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@ func Ingress(params manifests.Params) (*networkingv1.Ingress, error) {
return nil, err
}

otelcol := naming.Service(params.OtelCol.Name)

var rules []networkingv1.IngressRule
switch params.OtelCol.Spec.Ingress.RuleType {
case v1beta1.IngressRuleTypePath, "":
rules = []networkingv1.IngressRule{createPathIngressRules(params.OtelCol.Name, params.OtelCol.Spec.Ingress.Hostname, ports)}
rules = []networkingv1.IngressRule{createPathIngressRules(otelcol, params.OtelCol.Spec.Ingress.Hostname, ports)}
case v1beta1.IngressRuleTypeSubdomain:
rules = createSubdomainIngressRules(params.OtelCol.Name, params.OtelCol.Spec.Ingress.Hostname, ports)
rules = createSubdomainIngressRules(otelcol, params.OtelCol.Spec.Ingress.Hostname, ports)
}

return &networkingv1.Ingress{
Expand All @@ -70,17 +72,56 @@ func Ingress(params manifests.Params) (*networkingv1.Ingress, error) {
}, nil
}

func ExtensionIngress(params manifests.Params) (*networkingv1.Ingress, error) {
name := naming.ExtensionIngress(params.OtelCol.Name)
labels := manifestutils.Labels(params.OtelCol.ObjectMeta, name, params.OtelCol.Spec.Image, ComponentOpenTelemetryCollector, params.Config.LabelsFilter())

if params.OtelCol.Spec.ExtensionIngress.Type != v1beta1.IngressTypeIngress {
return nil, nil
}

ports, err := extensionServicePortsFromCfg(params.Log, params.OtelCol)
if err != nil || len(ports) == 0 {
return nil, err
}

otelcol := naming.ExtensionService(params.OtelCol.Name)

var rules []networkingv1.IngressRule
switch params.OtelCol.Spec.Ingress.RuleType {
case v1beta1.IngressRuleTypePath, "":
rules = []networkingv1.IngressRule{createPathIngressRules(otelcol, params.OtelCol.Spec.ExtensionIngress.Hostname, ports)}
case v1beta1.IngressRuleTypeSubdomain:
rules = createSubdomainIngressRules(otelcol, params.OtelCol.Spec.ExtensionIngress.Hostname, ports)
}

return &networkingv1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: params.OtelCol.Namespace,
Annotations: params.OtelCol.Spec.ExtensionIngress.Annotations,
Labels: labels,
},
Spec: networkingv1.IngressSpec{
TLS: params.OtelCol.Spec.ExtensionIngress.TLS,
Rules: rules,
IngressClassName: params.OtelCol.Spec.ExtensionIngress.IngressClassName,
},
}, nil
}

func createPathIngressRules(otelcol string, hostname string, ports []corev1.ServicePort) networkingv1.IngressRule {
pathType := networkingv1.PathTypePrefix
paths := make([]networkingv1.HTTPIngressPath, len(ports))

for i, port := range ports {
portName := naming.PortName(port.Name, port.Port)
paths[i] = networkingv1.HTTPIngressPath{
Path: "/" + port.Name,
PathType: &pathType,
Backend: networkingv1.IngressBackend{
Service: &networkingv1.IngressServiceBackend{
Name: naming.Service(otelcol),
Name: otelcol,
Port: networkingv1.ServiceBackendPort{
Name: portName,
},
Expand All @@ -101,6 +142,7 @@ func createPathIngressRules(otelcol string, hostname string, ports []corev1.Serv
func createSubdomainIngressRules(otelcol string, hostname string, ports []corev1.ServicePort) []networkingv1.IngressRule {
var rules []networkingv1.IngressRule
pathType := networkingv1.PathTypePrefix

for _, port := range ports {
portName := naming.PortName(port.Name, port.Port)

Expand All @@ -119,7 +161,7 @@ func createSubdomainIngressRules(otelcol string, hostname string, ports []corev1
PathType: &pathType,
Backend: networkingv1.IngressBackend{
Service: &networkingv1.IngressServiceBackend{
Name: naming.Service(otelcol),
Name: otelcol,
Port: networkingv1.ServiceBackendPort{
Name: portName,
},
Expand Down Expand Up @@ -163,6 +205,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
Loading
Loading