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

Support openshift routes #1206

Merged
merged 16 commits into from
Dec 12, 2022
Merged
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
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ e2e-log-operator:
kubectl get deploy -A

.PHONY: prepare-e2e
prepare-e2e: kuttl set-test-image-vars set-image-controller container container-target-allocator start-kind install-metrics-server load-image-all
prepare-e2e: kuttl set-test-image-vars set-image-controller container container-target-allocator start-kind install-metrics-server install-openshift-routes load-image-all
mkdir -p tests/_build/crds tests/_build/manifests
$(KUSTOMIZE) build config/default -o tests/_build/manifests/01-opentelemetry-operator.yaml
$(KUSTOMIZE) build config/crd -o tests/_build/crds/
Expand Down Expand Up @@ -208,6 +208,10 @@ start-kind:
install-metrics-server:
./hack/install-metrics-server.sh

.PHONY: install-openshift-routes
install-openshift-routes:
./hack/install-openshift-routes.sh

.PHONY: load-image-all
load-image-all: load-image-operator load-image-target-allocator

Expand Down
24 changes: 23 additions & 1 deletion apis/v1alpha1/ingress_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,33 @@ package v1alpha1

type (
// IngressType represents how a collector should be exposed (ingress vs route).
// +kubebuilder:validation:Enum=ingress
// +kubebuilder:validation:Enum=ingress;route
IngressType string
)

const (
// IngressTypeNginx specifies that an ingress entry should be created.
IngressTypeNginx IngressType = "ingress"
// IngressTypeOpenshiftRoute specifies that an route entry should be created.
IngressTypeRoute IngressType = "route"
)

type (
// TLSRouteTerminationType is used to indicate which tls settings should be used.
// +kubebuilder:validation:Enum=insecure;edge;passthrough;reencrypt
TLSRouteTerminationType string
)

const (
// TLSRouteTerminationTypeInsecure indicates that insecure connections are allowed.
TLSRouteTerminationTypeInsecure TLSRouteTerminationType = "insecure"
// TLSRouteTerminationTypeEdge indicates that encryption should be terminated
// at the edge router.
TLSRouteTerminationTypeEdge TLSRouteTerminationType = "edge"
// TLSTerminationPassthrough indicates that the destination service is
// responsible for decrypting traffic.
TLSRouteTerminationTypePassthrough TLSRouteTerminationType = "passthrough"
// TLSTerminationReencrypt indicates that traffic will be decrypted on the edge
// and re-encrypt using a new certificate.
TLSRouteTerminationTypeReencrypt TLSRouteTerminationType = "reencrypt"
)
18 changes: 18 additions & 0 deletions apis/v1alpha1/opentelemetrycollector_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ import (
// 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.
// NOTE: If this feature is activated, all specified receivers are exposed.
// Currently this has a few limitations. Depending on the ingress controller
// there are problems with TLS and gRPC.
// SEE: https://github.com/open-telemetry/opentelemetry-operator/issues/1306.
// NOTE: As a workaround, port name and appProtocol could be specified directly
// in the CR.
// SEE: OpenTelemetryCollector.spec.ports[index].
type Ingress struct {
// Type default value is: ""
// Supported types are: ingress
Expand All @@ -47,6 +54,17 @@ type Ingress struct {
// serving this Ingress resource.
// +optional
IngressClassName *string `json:"ingressClassName,omitempty"`

// Route is an OpenShift specific section that is only considered when
// type "route" is used.
// +optional
Route OpenShiftRoute `json:"route,omitempty"`
}

// OpenShiftRoute defines openshift route specific settings.
type OpenShiftRoute struct {
// Termination indicates termination type. By default "edge" is used.
Termination TLSRouteTerminationType `json:"termination,omitempty"`
}

// OpenTelemetryCollectorSpec defines the desired state of OpenTelemetryCollector.
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 @@ -77,6 +77,9 @@ func (r *OpenTelemetryCollector) Default() {
r.Spec.Autoscaler.TargetCPUUtilization = &defaultCPUTarget
}
}
if r.Spec.Ingress.Type == IngressTypeRoute && r.Spec.Ingress.Route.Termination == "" {
r.Spec.Ingress.Route.Termination = TLSRouteTerminationTypeEdge
}
}

// +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
29 changes: 29 additions & 0 deletions apis/v1alpha1/opentelemetrycollector_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,35 @@ func TestOTELColDefaultingWebhook(t *testing.T) {
},
},
},
{
name: "Missing route termination",
otelcol: OpenTelemetryCollector{
Spec: OpenTelemetryCollectorSpec{
Mode: ModeDeployment,
Ingress: Ingress{
Type: IngressTypeRoute,
},
},
},
expected: OpenTelemetryCollector{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"app.kubernetes.io/managed-by": "opentelemetry-operator",
},
},
Spec: OpenTelemetryCollectorSpec{
Mode: ModeDeployment,
Ingress: Ingress{
Type: IngressTypeRoute,
Route: OpenShiftRoute{
Termination: TLSRouteTerminationTypeEdge,
},
},
Replicas: &one,
UpgradeStrategy: UpgradeStrategyAutomatic,
},
},
},
}

for _, test := range tests {
Expand Down
16 changes: 16 additions & 0 deletions apis/v1alpha1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,18 @@ spec:
- get
- patch
- update
- apiGroups:
- route.openshift.io
resources:
- routes
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- authentication.k8s.io
resources:
Expand Down
15 changes: 15 additions & 0 deletions bundle/manifests/opentelemetry.io_opentelemetrycollectors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1206,6 +1206,20 @@ spec:
resource. Ingress controller implementations use this field
to know whether they should be serving this Ingress resource.
type: string
route:
description: Route is an OpenShift specific section that is only
considered when type "route" is used.
properties:
termination:
description: Termination indicates termination type. By default
"edge" is used.
enum:
- insecure
- edge
- passthrough
- reencrypt
type: string
type: object
tls:
description: TLS configuration.
items:
Expand Down Expand Up @@ -1236,6 +1250,7 @@ spec:
description: 'Type default value is: "" Supported types are: ingress'
enum:
- ingress
- route
type: string
type: object
maxReplicas:
Expand Down
6 changes: 4 additions & 2 deletions cmd/otel-allocator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,14 @@ func (s *server) ScrapeConfigsHandler(w http.ResponseWriter, r *http.Request) {
}
// if the hashes are different, we need to recompute the scrape config
if hash != s.compareHash {
configBytes, err := yaml.Marshal(configs)
var configBytes []byte
configBytes, err = yaml.Marshal(configs)
if err != nil {
s.errorHandler(w, err)
return
}
jsonConfig, err := yaml2.YAMLToJSON(configBytes)
var jsonConfig []byte
jsonConfig, err = yaml2.YAMLToJSON(configBytes)
if err != nil {
s.errorHandler(w, err)
return
Expand Down
15 changes: 15 additions & 0 deletions config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1204,6 +1204,20 @@ spec:
resource. Ingress controller implementations use this field
to know whether they should be serving this Ingress resource.
type: string
route:
description: Route is an OpenShift specific section that is only
considered when type "route" is used.
properties:
termination:
description: Termination indicates termination type. By default
"edge" is used.
enum:
- insecure
- edge
- passthrough
- reencrypt
type: string
type: object
tls:
description: TLS configuration.
items:
Expand Down Expand Up @@ -1234,6 +1248,7 @@ spec:
description: 'Type default value is: "" Supported types are: ingress'
enum:
- ingress
- route
type: string
type: object
maxReplicas:
Expand Down
12 changes: 12 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,15 @@ rules:
- get
- patch
- update
- apiGroups:
- route.openshift.io
resources:
- routes
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
Loading