Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
Signed-off-by: Pavol Loffay <[email protected]>
  • Loading branch information
pavolloffay committed Aug 4, 2023
1 parent 4f00da7 commit bf08205
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 14 deletions.
5 changes: 3 additions & 2 deletions .chloggen/1967-ingress-path.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ issues: [1967]
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext: |
The ingress and route now uses only root path `/` for all exposed collector receivers.
Each receiver is exposed on a subdomain that matches the port name of the receiver.
The ingress can be configured to create a single host with multiple paths or
multiple hosts with subdomains (one per receiver port).
The path from OpenShift route was removed.
23 changes: 22 additions & 1 deletion apis/v1alpha1/opentelemetrycollector_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ const (
ManagementStateUnmanaged ManagementStateType = "Unmanaged"
)

// IngressRuleType defines how the collector receivers will be exposed in the Ingress.
//
// +kubebuilder:validation:Enum=path;subdomain
type IngressRuleType string

const (
// IngressRuleTypePath configures Ingress to use single host with multiple paths.
// This configuration might require additional ingress setting to rewrite paths.
IngressRuleTypePath IngressRuleType = "path"

// IngressRuleTypeSubdomain configures Ingress to use multiple hosts - one for each exposed
// receiver port. The port name is used as a subdomain for the host defined in the Ingress e.g. otlp-http.example.com.
IngressRuleTypeSubdomain IngressRuleType = "subdomain"
)

// Ingress 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.
Expand All @@ -48,9 +63,15 @@ const (
// SEE: OpenTelemetryCollector.spec.ports[index].
type Ingress struct {
// Type default value is: ""
// Supported types are: ingress
// Supported types are: ingress, route
Type IngressType `json:"type,omitempty"`

// RuleType defines how Ingress exposes collector receivers.
// Either multiple hosts with subdomain per receiver port are created or
// a single host with multiple paths.
// Default is path.
RuleType IngressRuleType `json:"ruleType,omitempty"`

// Hostname by which the ingress proxy can be reached.
// +optional
Hostname string `json:"hostname,omitempty"`
Expand Down
3 changes: 3 additions & 0 deletions apis/v1alpha1/opentelemetrycollector_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ func (r *OpenTelemetryCollector) Default() {
if r.Spec.Ingress.Type == IngressTypeRoute && r.Spec.Ingress.Route.Termination == "" {
r.Spec.Ingress.Route.Termination = TLSRouteTerminationTypeEdge
}
if r.Spec.Ingress.Type == IngressTypeNginx && r.Spec.Ingress.RuleType == "" {
r.Spec.Ingress.RuleType = IngressRuleTypePath
}
}

// +kubebuilder:webhook:verbs=create;update,path=/validate-opentelemetry-io-v1alpha1-opentelemetrycollector,mutating=false,failurePolicy=fail,groups=opentelemetry.io,resources=opentelemetrycollectors,versions=v1alpha1,name=vopentelemetrycollectorcreateupdate.kb.io,sideEffects=none,admissionReviewVersions=v1
Expand Down
11 changes: 10 additions & 1 deletion bundle/manifests/opentelemetry.io_opentelemetrycollectors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1373,6 +1373,14 @@ spec:
- reencrypt
type: string
type: object
ruleType:
description: RuleType defines how Ingress exposes collector receivers.
Either multiple hosts with subdomain per receiver port are created
or a single host with multiple paths. Default is path.
enum:
- path
- subdomain
type: string
tls:
description: TLS configuration.
items:
Expand Down Expand Up @@ -1401,7 +1409,8 @@ spec:
type: object
type: array
type:
description: 'Type default value is: "" Supported types are: ingress'
description: 'Type default value is: "" Supported types are: ingress,
route'
enum:
- ingress
- route
Expand Down
11 changes: 10 additions & 1 deletion config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1370,6 +1370,14 @@ spec:
- reencrypt
type: string
type: object
ruleType:
description: RuleType defines how Ingress exposes collector receivers.
Either multiple hosts with subdomain per receiver port are created
or a single host with multiple paths. Default is path.
enum:
- path
- subdomain
type: string
tls:
description: TLS configuration.
items:
Expand Down Expand Up @@ -1398,7 +1406,8 @@ spec:
type: object
type: array
type:
description: 'Type default value is: "" Supported types are: ingress'
description: 'Type default value is: "" Supported types are: ingress,
route'
enum:
- ingress
- route
Expand Down
11 changes: 10 additions & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -6083,6 +6083,15 @@ Ingress is used to specify how OpenTelemetry Collector is exposed. This function
Route is an OpenShift specific section that is only considered when type "route" is used.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>ruleType</b></td>
<td>enum</td>
<td>
RuleType defines how Ingress exposes collector receivers. Either multiple hosts with subdomain per receiver port are created or a single host with multiple paths. Default is path.<br/>
<br/>
<i>Enum</i>: path, subdomain<br/>
</td>
<td>false</td>
</tr><tr>
<td><b><a href="#opentelemetrycollectorspecingresstlsindex">tls</a></b></td>
<td>[]object</td>
Expand All @@ -6094,7 +6103,7 @@ Ingress is used to specify how OpenTelemetry Collector is exposed. This function
<td><b>type</b></td>
<td>enum</td>
<td>
Type default value is: "" Supported types are: ingress<br/>
Type default value is: "" Supported types are: ingress, route<br/>
<br/>
<i>Enum</i>: ingress, route<br/>
</td>
Expand Down
43 changes: 40 additions & 3 deletions internal/manifests/collector/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ func Ingress(cfg config.Config, logger logr.Logger, otelcol v1alpha1.OpenTelemet
return nil
}

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

createSubdomainIngressRules(otelcol.Name, otelcol.Spec.Ingress.Hostname, ports)
return &networkingv1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Name: naming.Ingress(otelcol.Name),
Expand All @@ -58,15 +67,43 @@ func Ingress(cfg config.Config, logger logr.Logger, otelcol v1alpha1.OpenTelemet
},
Spec: networkingv1.IngressSpec{
TLS: otelcol.Spec.Ingress.TLS,
Rules: createIngressRules(otelcol.Name, otelcol.Spec.Ingress.Hostname, ports),
Rules: rules,
IngressClassName: otelcol.Spec.Ingress.IngressClassName,
},
}
}

func createIngressRules(otelcol string, hostname string, ports []corev1.ServicePort) []networkingv1.IngressRule {
var rules []networkingv1.IngressRule
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),
Port: networkingv1.ServiceBackendPort{
Name: portName,
},
},
},
}
}
return networkingv1.IngressRule{
Host: hostname,
IngressRuleValue: networkingv1.IngressRuleValue{
HTTP: &networkingv1.HTTPIngressRuleValue{
Paths: paths,
},
},
}
}

func createSubdomainIngressRules(otelcol string, hostname string, ports []corev1.ServicePort) []networkingv1.IngressRule {
var rules []networkingv1.IngressRule
pathType := networkingv1.PathTypeExact
for _, port := range ports {
portName := naming.PortName(port.Name, port.Port)

Expand Down
3 changes: 1 addition & 2 deletions internal/manifests/collector/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ func Routes(cfg config.Config, logger logr.Logger, otelcol v1alpha1.OpenTelemetr
Name: naming.Service(otelcol.Name),
},
Port: &routev1.RoutePort{
// Valid names must be non-empty and no more than 15 characters long.
TargetPort: intstr.FromString(naming.Truncate(p.Name, 15)),
TargetPort: intstr.FromString(portName),
},
WildcardPolicy: routev1.WildcardPolicyNone,
TLS: tlsCfg,
Expand Down
2 changes: 1 addition & 1 deletion pkg/collector/reconcile/ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestExpectedIngresses(t *testing.T) {
err = params.Client.Get(ctx, nns, got)
assert.NoError(t, err)

assert.Equal(t, "web.something-else.com", got.Spec.Rules[0].Host)
assert.Equal(t, "something-else.com", got.Spec.Rules[0].Host)

if v, ok := got.Annotations["blub"]; !ok || v != "blob" {
t.Error("annotations are not up-to-date. Missing entry or value is invalid.")
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/ingress/00-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ spec:
port:
name: otlp-grpc
path: /
pathType: Prefix
pathType: Exact
- host: otlp-http.test.otel
http:
paths:
Expand All @@ -42,4 +42,4 @@ spec:
port:
name: otlp-http
path: /
pathType: Prefix
pathType: Exact
1 change: 1 addition & 0 deletions tests/e2e/ingress/00-install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ spec:
mode: "deployment"
ingress:
type: ingress
ruleType: subdomain
hostname: "test.otel"
annotations:
something.com: "true"
Expand Down

0 comments on commit bf08205

Please sign in to comment.