Skip to content

Commit

Permalink
Add ingress options (open-telemetry#1128)
Browse files Browse the repository at this point in the history
* add ingress name generation function

Signed-off-by: Benedikt Bongartz <[email protected]>

* extend otelcol crd with minimalistic ingress options

Signed-off-by: Benedikt Bongartz <[email protected]>

* support collector ingress reconciling

Signed-off-by: Benedikt Bongartz <[email protected]>

* register ingress reconciler

Signed-off-by: Benedikt Bongartz <[email protected]>

* grant permission to create, modify and delete ingress entries

Signed-off-by: Benedikt Bongartz <[email protected]>

* add ingress integration tests

Signed-off-by: Benedikt Bongartz <[email protected]>

* verify if collector mode is compatible with ingress settings

Signed-off-by: Benedikt Bongartz <[email protected]>

* create dedicated ingress type

Signed-off-by: Benedikt Bongartz <[email protected]>

* follow recommendations

Signed-off-by: Benedikt Bongartz <[email protected]>

* regenerate

Signed-off-by: Benedikt Bongartz <[email protected]>

Signed-off-by: Benedikt Bongartz <[email protected]>
  • Loading branch information
frzifus authored Oct 11, 2022
1 parent 38ab35d commit d907f7f
Show file tree
Hide file tree
Showing 17 changed files with 925 additions and 0 deletions.
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"
)
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.
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"`

// 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.

12 changes: 12 additions & 0 deletions bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml
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
Loading

0 comments on commit d907f7f

Please sign in to comment.