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

Add ingress options #1128

Merged
merged 10 commits into from
Oct 11, 2022
26 changes: 26 additions & 0 deletions apis/v1alpha1/ingress_type.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package v1alpha1

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

const (
// IngressTypeNginx specifies that an ingress entry should be created.
IngressTypeNginx IngressType = "ingress"
frzifus marked this conversation as resolved.
Show resolved Hide resolved
)
28 changes: 28 additions & 0 deletions apis/v1alpha1/opentelemetrycollector_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,32 @@ package v1alpha1
import (
autoscalingv2 "k8s.io/api/autoscaling/v2"
v1 "k8s.io/api/core/v1"
networkingv1 "k8s.io/api/networking/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// 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.
frzifus marked this conversation as resolved.
Show resolved Hide resolved
type Ingress struct {
// Type default value is: ""
// Supported types are: ingress
Type IngressType `json:"type,omitempty"`

// Hostname by which the ingress proxy can be reached.
// +optional
Hostname string `json:"hostname,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please explain this configuration? Why is it needed?

https://kubernetes.io/docs/concepts/services-networking/ingress/

PS: I don't have much experience with ingress so I might ask something stupid here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the ingress entry we want to direct incoming traffic on port 80 or 443 to our service. Without a set hostname, this applies to all domains, which can not be intentional. For example if traffic with the same path but from another domain should be directed to another service.

It could look like this:

NAMESPACE  NAME            HOST/PORT            PATH     SERVICES                  PORT
test123    jaeger-skupper  example.com          /traces  jaeger-skupper-collector  https-collector
test456    jaeger-ingress  another-example.com  /traces  jaeger-ingress-collector  grpc-collector


// Annotations to add to ingress.
// e.g. 'cert-manager.io/cluster-issuer: "letsencrypt"'
// +optional
Annotations map[string]string `json:"annotations,omitempty"`

// TLS configuration.
// +optional
TLS []networkingv1.IngressTLS `json:"tls,omitempty"`
}

// OpenTelemetryCollectorSpec defines the desired state of OpenTelemetryCollector.
type OpenTelemetryCollectorSpec struct {
// Resources to set on the OpenTelemetry Collector pods.
Expand Down Expand Up @@ -107,6 +130,11 @@ type OpenTelemetryCollectorSpec struct {
// +optional
// +listType=atomic
Volumes []v1.Volume `json:"volumes,omitempty"`
// 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.
// +optional
Ingress Ingress `json:"ingress,omitempty"`
// HostNetwork indicates if the pod should run in the host networking namespace.
// +optional
HostNetwork bool `json:"hostNetwork,omitempty"`
Expand Down
6 changes: 6 additions & 0 deletions apis/v1alpha1/opentelemetrycollector_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,5 +166,11 @@ func (r *OpenTelemetryCollector) validateCRDSpec() error {

}

if r.Spec.Ingress.Type == IngressTypeNginx && r.Spec.Mode == ModeSidecar {
return fmt.Errorf("the OptenTelemetry Spec Ingress configuiration is incorrect. Ingress can only be used in combination with the modes: %s, %s, %s",
ModeDeployment, ModeDaemonSet, ModeStatefulSet,
)
}

return nil
}
15 changes: 15 additions & 0 deletions apis/v1alpha1/opentelemetrycollector_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package v1alpha1

import (
"fmt"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -317,6 +318,20 @@ func TestOTELColValidatingWebhook(t *testing.T) {
},
expectedErr: "targetCPUUtilization should be greater than 0 and less than 100",
},
{
name: "invalid deployment mode incompabible with ingress settings",
otelcol: OpenTelemetryCollector{
Spec: OpenTelemetryCollectorSpec{
Mode: ModeSidecar,
Ingress: Ingress{
Type: IngressTypeNginx,
},
},
},
expectedErr: fmt.Sprintf("Ingress can only be used in combination with the modes: %s, %s, %s",
ModeDeployment, ModeDaemonSet, ModeStatefulSet,
),
},
}

for _, test := range tests {
Expand Down
31 changes: 31 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 @@ -209,6 +209,18 @@ spec:
- get
- list
- update
- apiGroups:
- networking.k8s.io
resources:
- ingresses
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- opentelemetry.io
resources:
Expand Down
46 changes: 46 additions & 0 deletions bundle/manifests/opentelemetry.io_opentelemetrycollectors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,52 @@ spec:
description: ImagePullPolicy indicates the pull policy to be used
for retrieving the container image (Always, Never, IfNotPresent)
type: string
ingress:
description: '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.'
properties:
annotations:
additionalProperties:
type: string
description: 'Annotations to add to ingress. e.g. ''cert-manager.io/cluster-issuer:
"letsencrypt"'''
type: object
hostname:
description: Hostname by which the ingress proxy can be reached.
type: string
tls:
description: TLS configuration.
items:
description: IngressTLS describes the transport layer security
associated with an Ingress.
properties:
hosts:
description: Hosts are a list of hosts included in the TLS
certificate. The values in this list must match the name/s
used in the tlsSecret. Defaults to the wildcard host setting
for the loadbalancer controller fulfilling this Ingress,
if left unspecified.
items:
type: string
type: array
x-kubernetes-list-type: atomic
secretName:
description: SecretName is the name of the secret used to
terminate TLS traffic on port 443. Field is left optional
to allow TLS routing based on SNI hostname alone. If the
SNI host in a listener conflicts with the "Host" header
field used by an IngressRule, the SNI host is used for
termination and value of the Host header is used for routing.
type: string
type: object
type: array
type:
description: 'Type default value is: "" Supported types are: ingress'
enum:
- ingress
type: string
type: object
maxReplicas:
description: MaxReplicas sets an upper bound to the autoscaling feature.
If MaxReplicas is set autoscaling is enabled.
Expand Down
46 changes: 46 additions & 0 deletions config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,52 @@ spec:
description: ImagePullPolicy indicates the pull policy to be used
for retrieving the container image (Always, Never, IfNotPresent)
type: string
ingress:
description: '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.'
properties:
annotations:
additionalProperties:
type: string
description: 'Annotations to add to ingress. e.g. ''cert-manager.io/cluster-issuer:
"letsencrypt"'''
type: object
hostname:
description: Hostname by which the ingress proxy can be reached.
type: string
tls:
description: TLS configuration.
items:
description: IngressTLS describes the transport layer security
associated with an Ingress.
properties:
hosts:
description: Hosts are a list of hosts included in the TLS
certificate. The values in this list must match the name/s
used in the tlsSecret. Defaults to the wildcard host setting
for the loadbalancer controller fulfilling this Ingress,
if left unspecified.
items:
type: string
type: array
x-kubernetes-list-type: atomic
secretName:
description: SecretName is the name of the secret used to
terminate TLS traffic on port 443. Field is left optional
to allow TLS routing based on SNI hostname alone. If the
SNI host in a listener conflicts with the "Host" header
field used by an IngressRule, the SNI host is used for
termination and value of the Host header is used for routing.
type: string
type: object
type: array
type:
description: 'Type default value is: "" Supported types are: ingress'
enum:
- ingress
type: string
type: object
maxReplicas:
description: MaxReplicas sets an upper bound to the autoscaling feature.
If MaxReplicas is set autoscaling is enabled.
Expand Down
12 changes: 12 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,18 @@ rules:
- get
- list
- update
- apiGroups:
- networking.k8s.io
resources:
- ingresses
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- opentelemetry.io
resources:
Expand Down
6 changes: 6 additions & 0 deletions controllers/opentelemetrycollector_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ func NewReconciler(p Params) *OpenTelemetryCollectorReconciler {
"stateful sets",
true,
},
{
reconcile.Ingresses,
"ingresses",
true,
},
{
reconcile.Self,
"opentelemetry",
Expand All @@ -123,6 +128,7 @@ func NewReconciler(p Params) *OpenTelemetryCollectorReconciler {
// +kubebuilder:rbac:groups=opentelemetry.io,resources=opentelemetrycollectors,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=opentelemetry.io,resources=opentelemetrycollectors/status,verbs=get;update;patch
// +kubebuilder:rbac:groups=opentelemetry.io,resources=opentelemetrycollectors/finalizers,verbs=get;update;patch
// +kubebuilder:rbac:groups=networking.k8s.io,resources=ingresses,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=coordination.k8s.io,resources=leases,verbs=get;list;create;update
// +kubebuilder:rbac:groups="",resources=events,verbs=create;patch

Expand Down